私はWindowsアプリケーションを開発しています。
私は、検索機能を実装しています。
5つのフィルター[検索カテゴリー]があります。
Partycode、branchId、Symbol、BuySell、TerminalId。
このためのすべてのテキストボックスが空の場合、すべてのデータが表示されます。
Partycodeが入力されている場合は、特定のパーティコードのデータのみが表示されます。
パーティコードとbranchIdテキストボックスが入力されている場合は、特定の端末IDを持つparticodeのデータを提供する必要があります。...そして、条件はすべての順列と組み合わせに対して続きます。
私はelseステートメントの場合は別の文を書いています。これらは多くのIf-Elseステートメントになりつつあります。
この状況のクエリを作成する特定の方法はありますか?または、.NETがそれを処理するために提供する機能はありますか?
または、私は正しい方向に進んでいます[If-Elseステートメントがたくさんあります]?
試しました>>
private void btnRefresh_Click_1(object sender, EventArgs e)
{
string SQL = "";
if ((txtSearchPartyCode.Text == "") && (txtSearchBranchId.Text == "") && (txtSearchSymbol.Text == "") && (txtSearchTerminalId.Text == "")&&(cmbBuySell.Text==""))
{
SQL = "select Party_Code,TradeNo,Scrip_Code,Inst_Type,Expirydate,Strike_price,Option_type,TerminalId,Branch_Id,Buy_Sell,Trade_Qty,Market_Rate,Sauda_Date,OrderNo from tradeFile";
}
else
if ((txtSearchPartyCode.Text != "") && (txtSearchBranchId.Text == "") && (txtSearchSymbol.Text == "") && (txtSearchTerminalId.Text == "")&&(cmbBuySell.Text==""))
{
SQL="select Party_Code,TradeNo,Scrip_Code,Inst_Type,Expirydate,Strike_price,Option_type,TerminalId,Branch_Id,Buy_Sell,Trade_Qty,Market_Rate,Sauda_Date,OrderNo from tradeFile where Party_Code='"+txtSearchPartyCode.Text+"'";
}
else
if ((txtSearchPartyCode.Text == "") && (txtSearchBranchId.Text != "") && (txtSearchSymbol.Text == "") && (txtSearchTerminalId.Text == "")&&(cmbBuySell.Text==""))
{
SQL="select Party_Code,TradeNo,Scrip_Code,Inst_Type,Expirydate,Strike_price,Option_type,TerminalId,Branch_Id,Buy_Sell,Trade_Qty,Market_Rate,Sauda_Date,OrderNo from tradeFile where Branch_Id='"+txtSearchBranchId.Text+"'";
}
else
if ((txtSearchPartyCode.Text == "") && (txtSearchBranchId.Text == "") && (txtSearchSymbol.Text != "") && (txtSearchTerminalId.Text == "")&&(cmbBuySell.Text==""))
{
SQL="select Party_Code,TradeNo,Scrip_Code,Inst_Type,Expirydate,Strike_price,Option_type,TerminalId,Branch_Id,Buy_Sell,Trade_Qty,Market_Rate,Sauda_Date,OrderNo from tradeFile where Scrip_Code='"+txtSearchSymbol.Text+"'";
}
else
if ((txtSearchPartyCode.Text == "") && (txtSearchBranchId.Text == "") && (txtSearchSymbol.Text == "") && (txtSearchTerminalId.Text != "")&&(cmbBuySell.Text==""))
{
SQL="select Party_Code,TradeNo,Scrip_Code,Inst_Type,Expirydate,Strike_price,Option_type,TerminalId,Branch_Id,Buy_Sell,Trade_Qty,Market_Rate,Sauda_Date,OrderNo from tradeFile where TerminalId='"+txtSearchTerminalId.Text+"'";
}
else
if((txtSearchPartyCode.Text == "") && (txtSearchBranchId.Text == "") && (txtSearchSymbol.Text == "") && (txtSearchTerminalId.Text == "")&&(cmbBuySell.Text!=""))
{
float buy_Sell=0;
if(cmbBuySell.Text=="Buy")
buy_Sell=1;
else
if(cmbBuySell.Text=="Sell")
buy_Sell=2;
SQL="select Party_Code,TradeNo,Scrip_Code,Inst_Type,Expirydate,Strike_price,Option_type,TerminalId,Branch_Id,Buy_Sell,Trade_Qty,Market_Rate,Sauda_Date,OrderNo from tradeFile where Buy_Sell='"+buy_Sell+"'";
}
try
{
da = new SqlDataAdapter(SQL, con);
DataSet ds = new DataSet();
da.Fill(ds);
gvTradeFile.DataSource = ds.Tables[0];
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
私を引き抜いてください。!!!!