private void btnPreview_Click(object sender, EventArgs e) { try { string vWhere = string.Empty; string criteria = string.Empty; Reports.RptReportViewer vForm = new Reports.RptReportViewer(); if (!chkReturn.Checked) { if (!string.IsNullOrEmpty(this.txtVendorID.Text)) { vWhere += " AND Sale.CustomerID=" + this.txtVendorID.Text; } if (Int32.Parse(cboSalesman.SelectedValue.ToString()) > 0) { vWhere += " AND Sale.SalesmanID=" + cboSalesman.SelectedValue.ToString(); //criteria += " Salesman: " + cboSalesman.SelectedText; } //if (!string.IsNullOrEmpty(this.txt_ProductID.Text)) //{ // vWhere += " AND SaleBody.ProductID=" + this.txt_ProductID.Text; //} if (optCash.Checked) { vWhere += " AND (ISNULL(Sale.CashReceived, 0) = Sale.GrossValue - ISNULL(Sale.SpecialDisc, 0) )"; criteria += " CASH Sale "; } else if (optCredit.Checked) { vWhere += " AND (ISNULL(Sale.CashReceived, 0) <> Sale.GrossValue - ISNULL(Sale.SpecialDisc, 0) )"; criteria += " CREDIT Sale "; } if (optRange.Checked == true) { vWhere += " AND convert(datetime,Convert(varchar,Sale.EntryDate,1)) Between Convert(Datetime,(convert(varchar,convert(Datetime,'" + this.dt_From.Text + " 00:00:00',102),1))) AND Convert(Datetime,(convert(varchar,convert(Datetime,'" + this.dt_ToDate.Text + " 00:00:00',102),1)))"; criteria += "From: " + dt_From.Value.ToString("dd-MMM-yyyy") + " To: " + dt_ToDate.Value.ToString("dd-MMM-yyyy"); } else { criteria += " Till Date: " + dt_ToDate.Value.ToString("dd-MMM-yyyy"); } DataTable dt = objDAL.getPrtyWiseSale(vWhere); if (dt.Rows.Count == 0) { MessageBox.Show("No Data To Display", "No Data"); return; } vForm.SalesmanSale(criteria, dt, chkLetterPad.Checked, chkShowSummary.Checked); vForm.ShowDialog(); } else { if (!string.IsNullOrEmpty(this.txtVendorID.Text)) { vWhere = " AND SaleReturn.CustomerID=" + this.txtVendorID.Text; } if (Int32.Parse(cboSalesman.SelectedValue.ToString()) > 0) { vWhere += " AND SaleReturn.SaleID IN (Select SaleID From Sale Where SalesmanID=" + cboSalesman.SelectedValue.ToString() + ")"; criteria += " Salesman: " + cboSalesman.SelectedText; } //if (!string.IsNullOrEmpty(this.txt_ProductID.Text)) //{ // vWhere += " AND SaleRetBody.ProductID=" + this.txt_ProductID.Text; //} if (optRange.Checked == true) { vWhere += " AND convert(datetime,Convert(varchar,SaleReturn.EntryDate,1)) Between Convert(Datetime,(convert(varchar,convert(Datetime,'" + this.dt_From.Text + " 00:00:00',102),1))) AND Convert(Datetime,(convert(varchar,convert(Datetime,'" + this.dt_ToDate.Text + " 00:00:00',102),1)))"; criteria = "From: " + dt_From.Value.ToString("dd-MMM-yyyy") + " To: " + dt_ToDate.Value.ToString("dd-MMM-yyyy"); } else { criteria = " Till Date: " + dt_ToDate.Value.ToString("dd-MMM-yyyy"); } DataTable dt = objDAL.getPrtyWiseSaleRet(vWhere); if (dt.Rows.Count == 0) { MessageBox.Show("No Data To Display", "No Data"); return; } vForm.PartyWiseSaleRet(criteria, dt, chkLetterPad.Checked); vForm.ShowDialog(); } } catch (Exception exc) { MessageBox.Show(exc.Message, "Error"); } }