Help & Advise (Effective way to execute query on selected Radio Button & Checkbox)
Hi All. I'm New here.
I need assistant from you all. I have situation here. I have 8 Radio Button & 3 Check box. Each radio button and check box has combination of mySQL query.
The question is, how do i make effective way to write code without putting a ton of code into? currently this is my code example:
this is my code & just 20% from actual code. Could anyone advise me how to make the code more effective and shorter then this...
Thanks
P/S: Urgent
Regards
Hi All. I'm New here.
I need assistant from you all. I have situation here. I have 8 Radio Button & 3 Check box. Each radio button and check box has combination of mySQL query.
The question is, how do i make effective way to write code without putting a ton of code into? currently this is my code example:
VB.NET:
Dim conString As String = (ConfigurationManager.ConnectionStrings.Item("ItemListing").ToString)
Dim objConnection As New MySqlConnection(conString)
Dim sSQL As String
If RBFE.Checked And RBA.Checked Then
sSQL = " SELECT i.masterefno,i.fulldescription,i.productcode,i.invoicerefno,a.suppcode, o.cloccode, i.approval_date,i.isapprove" & _
" FROM itemdetail i, account a, itemdetail_outletlist io,outlet o" & _
" WHERE CONCAT(SUBSTR(i.approval_date,7,4),'/',SUBSTR(i.approval_date,4,2),'/',SUBSTR(i.approval_date,1,2)) BETWEEN '" & txtbod.Text & "' AND '" & txtDL.Text & "'" & _
" AND io.pid = i.pid" & _
" AND i.isapprove LIKE '%Approve%'" & _
" AND io.outletcode = o.moutletcode " & _
" AND a.suppcode = i.suppcode " & _
" GROUP BY io.outletcode,i.productcode ASC"
ElseIf RBFE.Checked And RBPA.Checked Then
sSQL = " SELECT i.masterefno,i.fulldescription,i.productcode,i.invoicerefno,a.suppcode, o.cloccode, i.approval_date,i.isapprove" & _
" FROM itemdetail i, account a, itemdetail_outletlist io,outlet o" & _
" WHERE CONCAT(SUBSTR(i.approval_date,7,4),'/',SUBSTR(i.approval_date,4,2),'/',SUBSTR(i.approval_date,1,2)) BETWEEN '" & txtbod.Text & "' AND '" & txtDL.Text & "'" & _
" AND io.pid = i.pid" & _
" AND i.isapprove LIKE '%Pending Approval%'" & _
" AND io.outletcode = o.moutletcode " & _
" AND a.suppcode = i.suppcode " & _
" GROUP BY io.outletcode,i.productcode ASC"
ElseIf RBDay.Checked And RBA.Checked Then
sSQL = " SELECT i.masterefno,i.fulldescription,i.productcode,i.invoicerefno,a.suppcode, o.cloccode, i.approval_date,i.isapprove" & _
" FROM itemdetail i, account a, itemdetail_outletlist io,outlet o" & _
" WHERE i.approval_date = '" & txtDLl.Text & "'" & _
" AND io.pid = i.pid" & _
" AND i.isapprove LIKE '%Approve%'" & _
" AND io.outletcode = o.moutletcode " & _
" AND a.suppcode = i.suppcode " & _
" GROUP BY io.outletcode,i.productcode ASC"
ElseIf RBDay.Checked And RBPA.Checked Then
sSQL = " SELECT i.masterefno,i.fulldescription,i.productcode,i.invoicerefno,a.suppcode, o.cloccode, i.approval_date,i.isapprove" & _
" FROM itemdetail i, account a, itemdetail_outletlist io,outlet o" & _
" WHERE i.approval_date = '" & txtDLl.Text & "'" & _
" AND io.pid = i.pid" & _
" AND i.isapprove LIKE '%Pending Approval%'" & _
" AND io.outletcode = o.moutletcode " & _
" AND a.suppcode = i.suppcode " & _
" GROUP BY io.outletcode,i.productcode ASC"
ElseIf RBDes.Checked And RBA.Checked Then
sSQL = " SELECT i.masterefno,i.fulldescription,i.productcode,i.invoicerefno,a.suppcode, o.cloccode, i.approval_date,i.isapprove" & _
" FROM itemdetail i, account a, itemdetail_outletlist io,outlet o" & _
" WHERE i.fullDescription LIKE '%" & TxtDescription.Text & "%'" & _
" AND io.pid = i.pid" & _
" AND i.isapprove LIKE '%Approve%'" & _
" AND io.outletcode = o.moutletcode " & _
" AND a.suppcode = i.suppcode " & _
" GROUP BY io.outletcode,i.productcode ASC"
ElseIf RBDes.Checked And RBPA.Checked Then
sSQL = " SELECT i.masterefno,i.fulldescription,i.productcode,i.invoicerefno,a.suppcode, o.cloccode, i.approval_date,i.isapprove" & _
" FROM itemdetail i, account a, itemdetail_outletlist io,outlet o" & _
" WHERE i.fullDescription LIKE '%" & TxtDescription.Text & "%'" & _
" AND io.pid = i.pid" & _
" AND i.isapprove LIKE '%Pending Approval%'" & _
" AND io.outletcode = o.moutletcode " & _
" AND a.suppcode = i.suppcode " & _
" GROUP BY io.outletcode,i.productcode ASC"
ElseIf RBMas.Checked And RBA.Checked Then
sSQL = " SELECT i.masterefno,i.fulldescription,i.productcode,i.invoicerefno,a.suppcode, o.cloccode, i.approval_date,i.isapprove" & _
" FROM itemdetail i, account a, itemdetail_outletlist io,outlet o" & _
" WHERE i.masterefno = '" & txtMRef.Text & "'" & _
" AND io.pid = i.pid" & _
" AND i.isapprove LIKE '%Approve%'" & _
" AND io.outletcode = o.moutletcode " & _
" AND a.suppcode = i.suppcode " & _
" GROUP BY io.outletcode,i.productcode ASC"
ElseIf RBMas.Checked And RBPA.Checked Then
sSQL = " SELECT i.masterefno,i.fulldescription,i.productcode,i.invoicerefno,a.suppcode, o.cloccode, i.approval_date,i.isapprove" & _
" FROM itemdetail i, account a, itemdetail_outletlist io,outlet o" & _
" WHERE i.fullDescription = '" & txtMRef.Text & "'" & _
" AND io.pid = i.pid" & _
" AND i.isapprove LIKE '%Pending Approval%'" & _
" AND io.outletcode = o.moutletcode " & _
" AND a.suppcode = i.suppcode " & _
" GROUP BY io.outletcode,i.productcode ASC"
ElseIf RBMonth.Checked And RBA.Checked Then
sSQL = " SELECT i.masterefno,i.fulldescription,i.productcode,i.invoicerefno,a.suppcode, o.cloccode, i.approval_date,i.isapprove" & _
" FROM itemdetail i, account a, itemdetail_outletlist io,outlet o" & _
" WHERE i.approval_date LIKE '%" & txtDDL.Text & "%'" & _
" AND io.pid = i.pid" & _
" AND i.isapprove LIKE '%Approve%'" & _
" AND io.outletcode = o.moutletcode " & _
" AND a.suppcode = i.suppcode " & _
" GROUP BY io.outletcode,i.productcode ASC"
ElseIf RBMonth.Checked And RBPA.Checked Then
sSQL = " SELECT i.masterefno,i.fulldescription,i.productcode,i.invoicerefno,a.suppcode, o.cloccode, i.approval_date,i.isapprove" & _
" FROM itemdetail i, account a, itemdetail_outletlist io,outlet o" & _
" WHERE i.Approval_date LIKE '%" & txtDDL.Text & "%'" & _
" AND io.pid = i.pid" & _
" AND i.isapprove LIKE '%Pending Approval%'" & _
" AND io.outletcode = o.moutletcode " & _
" AND a.suppcode = i.suppcode " & _
" GROUP BY io.outletcode,i.productcode ASC"
End If
objConnection.Open()
Dim objCommandGrid As New MySqlCommand(sSQL, objConnection)
Dim da As New MySqlDataAdapter(sSQL, objConnection)
Dim dt As New DataSet
da.Fill(dt, "data")
Dim dv As New DataView
dv = dt.Tables("data").DefaultView
GridItem.DataSource = dv
GridItem.DataBind()
objConnection.Close()
this is my code & just 20% from actual code. Could anyone advise me how to make the code more effective and shorter then this...
Thanks
P/S: Urgent
Regards