void AddUpdatePurchase(bool IsPrint, bool IsPackingSlip) { try { ep1.Clear(); if (string.IsNullOrEmpty(cmbName.Text.Trim())) { ep1.SetError(cmbName, "This field is required."); cmbName.Focus(); return; } if (string.IsNullOrEmpty(txtNetAmount.Text.Trim())) { ep1.SetError(txtNetAmount, "This field is required."); txtNetAmount.Focus(); return; } int T007_SALEID = Datalayer.iT012_CHALLENID; // int TM01_CUSTOMERID = 0; string T007_NO = "", T007_DETAILS = ""; int T001_ACCOUNTID = 0; decimal T007_TOTAL_AMT = 0, T007_DISCOUNT = 0, T007_TAX1RATE = 0, T007_TAX1AMOUNT = 0, T007_TAX2RATE = 0, T007_TAX2AMOUNT = 0, T007_NETAMOUNT = 0, T007_TAX; DateTime T003_DATE = dtpDate.Value; // int.TryParse(cmbCustomerName.SelectedValue.ToString(), out TM01_CUSTOMERID); T007_NO = txtBillNo.Text.Trim(); int.TryParse(cmbName.SelectedValue.ToString(), out T001_ACCOUNTID); decimal.TryParse(txtTotalAmt.Text.Trim(), out T007_TOTAL_AMT); decimal.TryParse(txtDiscount.Text.Trim(), out T007_DISCOUNT); decimal.TryParse(txtTotalTaxAmount.Text.Trim(), out T007_TAX); decimal.TryParse(txtNetAmount.Text.Trim(), out T007_NETAMOUNT); T007_DETAILS = txtDetails.Text.Trim(); if (T007_SALEID > 0) { int?Iout = 0; MyDa = new MyDabaseDataContext(Properties.Settings.Default.Style_King_Dev); MyDa.USP_VP_DELETE_CHALLENITEM(T007_SALEID, ref Iout); //MyDa = new MyDabaseDataContext(Properties.Settings.Default.Style_King_Dev); //string sSql = "DELETE FROM T003_PURCHASEITEM WHERE T002_PURCHASEID =" + T007_SALEID; //dl.ExecuteMethod(sSql); } decimal dT007_PACKING = 0, dT007_FREIGHT = 0, dT007_OTHER_EXPENSE = 0; decimal.TryParse(txtPacking.Text.Trim(), out dT007_PACKING); decimal.TryParse(txtFreight.Text.Trim(), out dT007_FREIGHT); decimal.TryParse(txtExpense.Text.Trim(), out dT007_OTHER_EXPENSE); int?T007_SALEID_out = 0; Cursor.Current = Cursors.WaitCursor; MyDa = new MyDabaseDataContext(Properties.Settings.Default.Style_King_Dev); MyDa.USP_VP_ADDUPATE_CHALLEN(T007_SALEID, T001_ACCOUNTID, T007_NO, T003_DATE, txtTransport1.Text.Trim(), txtLR1.Text.Trim(), txtTransport2.Text.Trim(), txtLR2.Text.Trim(), T007_TOTAL_AMT, dT007_PACKING, dT007_FREIGHT, dT007_OTHER_EXPENSE, T007_DISCOUNT, T007_TAX, T007_NETAMOUNT, T007_DETAILS, Datalayer.iT001_COMPANYID, ref T007_SALEID_out); if (T007_SALEID_out > 0) { T007_SALEID = int.Parse(T007_SALEID_out.Value.ToString()); int?T002_PURCHASEITEMID_OUT = 0; for (int i = 0; i < dgDisplayData.Rows.Count; i++) { if (!string.IsNullOrEmpty(Convert.ToString(dgDisplayData.Rows[i].Cells["TM01_NAME"].Value))) { int TM01_PRODUCTID = 0, TM02_PRODUCTSIZEID = 0, T008_QTY = 0; decimal T008_RATE = 0, T008_NET_AMOUNT = 0; int.TryParse(Convert.ToString(dgDisplayData.Rows[i].Cells["TM01_PRODUCTID"].Value), out TM01_PRODUCTID); int.TryParse(Convert.ToString(dgDisplayData.Rows[i].Cells["TM02_PRODUCTSIZEID"].Value), out TM02_PRODUCTSIZEID); int.TryParse(Convert.ToString(dgDisplayData.Rows[i].Cells["T008_QTY"].Value), out T008_QTY); decimal.TryParse(Convert.ToString(dgDisplayData.Rows[i].Cells["T008_RATE"].Value), out T008_RATE); decimal.TryParse(Convert.ToString(dgDisplayData.Rows[i].Cells["T008_NET_AMOUNT"].Value), out T008_NET_AMOUNT); decimal T008_TOTAL_AMT = 0, T008_DISCOUNT_PER = 0, T008_DISCOUNT_AMT = 0, T008_TAX_RATE = 0, T008_TAX_AMT = 0; decimal.TryParse(Convert.ToString(dgDisplayData.Rows[i].Cells["T008_TOTAL_AMT"].Value), out T008_TOTAL_AMT); decimal.TryParse(Convert.ToString(dgDisplayData.Rows[i].Cells["T008_DISCOUNT_PER"].Value), out T008_DISCOUNT_PER); decimal.TryParse(Convert.ToString(dgDisplayData.Rows[i].Cells["T008_DISCOUNT_AMT"].Value), out T008_DISCOUNT_AMT); decimal.TryParse(Convert.ToString(dgDisplayData.Rows[i].Cells["T008_TAX_RATE"].Value), out T008_TAX_RATE); decimal.TryParse(Convert.ToString(dgDisplayData.Rows[i].Cells["T008_TAX_AMT"].Value), out T008_TAX_AMT); int?T008_SALEITEMID_Out = 0; MyDa = new MyDabaseDataContext(Properties.Settings.Default.Style_King_Dev); MyDa.USP_VP_ADDUPDATE_CHALLEN_ITEM(0, T007_SALEID, TM01_PRODUCTID, TM02_PRODUCTSIZEID, T008_QTY, T008_RATE, T008_TOTAL_AMT, T008_DISCOUNT_PER, T008_DISCOUNT_AMT, T008_TAX_RATE, T008_TAX_AMT, T008_NET_AMOUNT, Datalayer.iT001_COMPANYID, ref T008_SALEITEMID_Out); } } if (Datalayer.iT012_CHALLENID == 0) { Datalayer.InsertMessageBox(sPageName); ResteData(); if (IsPrint) { Datalayer.iPrintableChallenId = T007_SALEID; frmPrintBill fmPrnt = new frmPrintBill(); fmPrnt.Show(); } if (IsPackingSlip) { DAL dl = new DAL(); DataTable dt = new DataTable(); dt = dl.SelectMethod("exec USP_VP_PRINT_CHALLEN_BILL '" + T007_SALEID + "'"); if (dt.Rows.Count > 0) { ReportDocument RptDoc = new ReportDocument(); RptDoc.Load(Application.StartupPath + @"\Report\rptPackingSlipsOnInvoice.rpt"); RptDoc.SetDataSource(dt); crystalReportViewer1.ReportSource = RptDoc; crystalReportViewer1.Refresh(); crystalReportViewer1.PrintReport(); //Datalayer.RptReport = RptDoc; //Datalayer.sReportName = "Packing Slip"; //Report.frmReportViwer fmReport = new Report.frmReportViwer(); //fmReport.Show(); } else { Datalayer.InformationMessageBox("No Record.."); } } //DataTable dt = new DataTable(); //dt = dl.SelectMethod("exec USP_VP_GET_FULLSALEBILL '" + T003_SALEID + "'"); //if (dt.Rows.Count > 0) //{ // ReportDocument RptDoc = new ReportDocument(); // RptDoc.Load(Application.StartupPath + @"\Report\rptRetailInvoice.rpt"); // RptDoc.SetDataSource(dt); // Datalayer.RptReport = RptDoc; // Datalayer.sReportName = "Invoice"; // frmReportViewer fmReport = new frmReportViewer(); // fmReport.Show(); //} } else { Datalayer.UpdateMessageBox(sPageName); if (IsPrint) { Datalayer.iPrintableChallenId = T007_SALEID; frmPrintBill fmPrnt = new frmPrintBill(); fmPrnt.Show(); } if (IsPackingSlip) { DAL dl = new DAL(); DataTable dt = new DataTable(); dt = dl.SelectMethod("exec USP_VP_PRINT_CHALLEN_BILL '" + T007_SALEID + "'"); if (dt.Rows.Count > 0) { ReportDocument RptDoc = new ReportDocument(); RptDoc.Load(Application.StartupPath + @"\Report\rptPackingSlipsOnInvoice.rpt"); RptDoc.SetDataSource(dt); crystalReportViewer1.ReportSource = RptDoc; crystalReportViewer1.Refresh(); crystalReportViewer1.PrintReport(); //Datalayer.RptReport = RptDoc; //Datalayer.sReportName = "Packing Slip"; //Report.frmReportViwer fmReport = new Report.frmReportViwer(); //fmReport.Show(); } else { Datalayer.InformationMessageBox("No Record.."); } } } } else { if (Datalayer.iT012_CHALLENID == 0) { Datalayer.DosenotInsertMessageBox(sPageName); } else { Datalayer.DosenotUpdateMessageBox(sPageName); } return; } ResteData(); } catch (Exception ex) { Datalayer.WorningMessageBox(ex.Message.ToString(), "Error"); } }