示例#1
0
        void AddUpdatePurchase(bool IsPrint)
        {
            try
            {
                ep1.Clear();
                if (string.IsNullOrEmpty(cmbName.Text.Trim()))
                {
                    ep1.SetError(cmbName, "This field is required.");
                    cmbName.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(txtBillNo.Text.Trim()))
                {
                    ep1.SetError(txtBillNo, "This field is required.");
                    txtBillNo.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(cmbShippedTo.Text.Trim()))
                {
                    ep1.SetError(cmbShippedTo, "This field is required.");
                    cmbShippedTo.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(cmbState.Text.Trim()))
                {
                    ep1.SetError(cmbState, "This field is required.");
                    cmbState.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(cmbReverseCharges.Text.Trim()))
                {
                    ep1.SetError(cmbReverseCharges, "This field is required.");
                    cmbReverseCharges.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(txtBillNo.Text.Trim()))
                {
                    ep1.SetError(txtBillNo, "This field is required.");
                    txtBillNo.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(txtNetAmount.Text.Trim()))
                {
                    ep1.SetError(txtNetAmount, "This field is required.");
                    txtNetAmount.Focus();
                    return;
                }
                if (dgDisplayData.Rows.Count == 0)
                {
                    Datalayer.InformationMessageBox("Record is required.");
                    return;
                }

                int     T007_SALEID = Datalayer.iT007_SALEID;
                int     T001_ACCOUNTID = 0, T007_SHIPPED_TO_ID = 0, T007_PLACE_OF_SUPPLY = 0;
                string  T007_TYPE = "", T007_NO = "", T007_TRANSPORT1 = "", T007_LR1 = "", T007_TRANSPORT2 = "", T007_LR2 = "", T007_DETAILS = "", T007_VEHICLE_NO = "", T007_IS_REVERSE_CHARGES = "", T007_E_WAY_BILL = "";
                decimal T007_TOTAL_AMT = 0, T007_PACKING = 0, T007_FREIGHT = 0, T007_OTHER_EXPENSE = 0, T007_DISCOUNT = 0, T007_CGST = 0, T007_SGST = 0, T007_IGST = 0, T007_NETAMOUNT = 0, T007_REVERSE_CHARGE = 0;
                decimal T007_TAXABLE_AMT = 0;

                int.TryParse(cmbName.SelectedValue.ToString(), out T001_ACCOUNTID);
                T007_TYPE       = cmbInvoiceType.SelectedItem.ToString();
                T007_NO         = txtBillNo.Text.Trim();
                T007_TRANSPORT1 = txtTransport1.Text.Trim();
                T007_LR1        = txtLR1.Text.Trim();
                T007_TRANSPORT2 = txtTransport2.Text.Trim();
                decimal.TryParse(txtTotalAmt.Text.Trim(), out T007_TOTAL_AMT);
                decimal.TryParse(txtCGST.Text.Trim(), out T007_CGST);
                decimal.TryParse(txtSGST.Text.Trim(), out T007_SGST);
                decimal.TryParse(txtIGST.Text.Trim(), out T007_IGST);
                decimal.TryParse(txtNetAmount.Text.Trim(), out T007_NETAMOUNT);
                decimal.TryParse(txtPacking.Text.Trim(), out T007_PACKING);
                decimal.TryParse(txtDiscount.Text.Trim(), out T007_DISCOUNT);
                decimal.TryParse(txtTaxableAMT.Text.Trim(), out T007_TAXABLE_AMT);

                T007_DETAILS            = txtDetails.Text.Trim();
                T007_VEHICLE_NO         = txtVehicleNo.Text.Trim();
                T007_IS_REVERSE_CHARGES = cmbReverseCharges.SelectedItem.ToString();
                decimal.TryParse(txtReverseCharges.Text.Trim(), out T007_REVERSE_CHARGE);
                T007_E_WAY_BILL = txtEWayBill.Text.Trim();
                int.TryParse(cmbShippedTo.SelectedValue.ToString(), out T007_SHIPPED_TO_ID);
                int.TryParse(cmbState.SelectedValue.ToString(), out T007_PLACE_OF_SUPPLY);


                if (T007_NETAMOUNT <= 250000 && T007_PLACE_OF_SUPPLY == 22 && T007_TYPE == "B2CL")
                {
                    Datalayer.InformationMessageBox("please choose correct place of supply and provide bill value more than 2.5 lakhs");
                    return;
                }
                if (T007_TYPE == "B2CS" && T007_PLACE_OF_SUPPLY != 33)
                {
                    Datalayer.InformationMessageBox("please choose correct place of supply.");
                    return;
                }


                if (T007_SALEID > 0)
                {
                    int?Iout = 0;
                    MyDa = new MyDabaseDataContext(Properties.Settings.Default.Style_King_Dev);
                    MyDa.USP_VP_DELETE_SALEITEM(T007_SALEID, ref Iout);
                }

                int?T007_SALEID_out = 0;
                Cursor.Current = Cursors.WaitCursor;
                MyDa           = new MyDabaseDataContext(Properties.Settings.Default.Style_King_Dev);
                MyDa.USP_VP_ADDUPDATE_SALE(T007_SALEID, T001_ACCOUNTID, T007_TYPE, T007_NO, dtpDate.Value, T007_TRANSPORT1, T007_LR1, T007_TRANSPORT2, T007_LR2, T007_TOTAL_AMT, T007_PACKING, T007_DISCOUNT, T007_TAXABLE_AMT, T007_CGST, T007_SGST, T007_IGST, T007_NETAMOUNT, T007_DETAILS, Datalayer.iT001_COMPANYID, T007_VEHICLE_NO, T007_IS_REVERSE_CHARGES, T007_REVERSE_CHARGE, T007_E_WAY_BILL, T007_SHIPPED_TO_ID, T007_PLACE_OF_SUPPLY, dtpLRDate.Value, txtBillPrefix.Text.Trim(), txtTotalKG.Text.Trim(), 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_PRODUCTID"].Value)))
                        {
                            int     TM01_PRODUCTID = 0;
                            decimal T003_RATE = 0, T003_AMOUNT = 0;
                            int     T003_QTY  = 0;
                            string  T003_UNIT = "";

                            int.TryParse(Convert.ToString(dgDisplayData.Rows[i].Cells["TM01_PRODUCTID"].Value), out TM01_PRODUCTID);
                            int.TryParse(Convert.ToString(dgDisplayData.Rows[i].Cells["T003_QTY"].Value), out T003_QTY);
                            decimal.TryParse(Convert.ToString(dgDisplayData.Rows[i].Cells["T003_RATE"].Value), out T003_RATE);
                            decimal.TryParse(Convert.ToString(dgDisplayData.Rows[i].Cells["T003_AMOUNT"].Value), out T003_AMOUNT);
                            T003_UNIT = Convert.ToString(dgDisplayData.Rows[i].Cells["T003_UNIT"].Value);

                            int?T008_SALEITEMID_Out = 0;
                            MyDa = new MyDabaseDataContext(Properties.Settings.Default.Style_King_Dev);
                            MyDa.USP_VP_ADDPDATE_SALEITEM(0, T007_SALEID, TM01_PRODUCTID, T003_QTY, T003_RATE, T003_UNIT, T003_AMOUNT, Datalayer.iT001_COMPANYID, ref T008_SALEITEMID_Out);
                        }
                    }

                    if (Datalayer.iT007_SALEID == 0)
                    {
                        Datalayer.InsertMessageBox(sPageName);
                    }
                    else
                    {
                        Datalayer.UpdateMessageBox(sPageName);
                        Datalayer.iT007_SALEID = T007_SALEID;
                    }

                    if (IsPrint)
                    {
                        Datalayer.iT007_SALEID = T007_SALEID;

                        DAL       dl = new DAL();
                        DataTable dt = new DataTable();
                        dt = dl.SelectMethod("exec USP_VP_PRINT_SALE_BILL '" + Datalayer.iT007_SALEID + "'");
                        if (dt.Rows.Count > 0)
                        {
                            //DataTable dtQTY = new DataTable();
                            //dtQTY = dl.SelectMethod("SELECT TM01_HSNCODE,SUM(T008_QTY)AS QTY FROM T008_SALEITEM T008 INNER JOIN TM01_PRODUCT TM01 ON TM01.TM01_PRODUCTID = T008.TM01_PRODUCTID WHERE T007_SALEID=" + Datalayer.iT007_SALEID + " GROUP BY  TM01.TM01_HSNCODE ");
                            //if (dtQTY.Rows.Count > 0)
                            //{
                            //    for (int i = 0; i < dt.Rows.Count; i++)
                            //    {
                            //        if (dtQTY.Rows.Count == 1)
                            //        {
                            //            dt.Rows[i]["HSNCODE1"] = dtQTY.Rows[0][0].ToString();
                            //            dt.Rows[i]["HSNCODEQTY1"] = dtQTY.Rows[0][1].ToString();
                            //        }
                            //        if (dtQTY.Rows.Count == 2)
                            //        {
                            //            dt.Rows[i]["HSNCODE1"] = dtQTY.Rows[0][0].ToString();
                            //            dt.Rows[i]["HSNCODEQTY1"] = dtQTY.Rows[0][1].ToString();

                            //            dt.Rows[i]["HSNCODE2"] = dtQTY.Rows[1][0].ToString();
                            //            dt.Rows[i]["HSNCODEQTY2"] = dtQTY.Rows[1][1].ToString();
                            //        }

                            //        if (dtQTY.Rows.Count == 3)
                            //        {
                            //            dt.Rows[i]["HSNCODE1"] = dtQTY.Rows[0][0].ToString();
                            //            dt.Rows[i]["HSNCODEQTY1"] = dtQTY.Rows[0][1].ToString();

                            //            dt.Rows[i]["HSNCODE2"] = dtQTY.Rows[1][0].ToString();
                            //            dt.Rows[i]["HSNCODEQTY2"] = dtQTY.Rows[1][1].ToString();

                            //            dt.Rows[i]["HSNCODE2"] = dtQTY.Rows[2][0].ToString();
                            //            dt.Rows[i]["HSNCODEQTY2"] = dtQTY.Rows[2][1].ToString();
                            //        }
                            //    }
                            //}


                            //dt.Rows[0]["BILLTYPE"] = cmbPrintMode.SelectedItem.ToString(); ;

                            ReportDocument RptDoc = new ReportDocument();

                            RptDoc.Load(Application.StartupPath + @"\Report\rptInvoice.rpt");

                            RptDoc.SetDataSource(dt);

                            crystalReportViewer1.ReportSource = RptDoc;
                            crystalReportViewer1.Refresh();
                            crystalReportViewer1.PrintReport();

                            //Datalayer.RptReport = RptDoc;
                            //Datalayer.sReportName = "Invoice Bill";

                            //Report.frmReportViwer fmReport = new Report.frmReportViwer();
                            //fmReport.Show();
                        }
                        else
                        {
                            Datalayer.InformationMessageBox("No Record..");
                        }
                        //if (Datalayer.ShowQuestMsg("are you sure do you want to print this bill ?"))
                        //{
                        //    Datalayer.iPrintableBillId = T007_SALEID;
                        //    frmPrintBill fmPrnt = new frmPrintBill();
                        //    fmPrnt.Show();
                        //}
                    }

                    this.Close();
                }
                else
                {
                    if (Datalayer.iT007_SALEID == 0)
                    {
                        Datalayer.DosenotInsertMessageBox(sPageName);
                    }
                    else
                    {
                        Datalayer.DosenotUpdateMessageBox(sPageName);
                    }
                    return;
                }
            }
            catch (Exception ex)
            {
                Datalayer.WorningMessageBox(ex.Message.ToString(), "Error");
            }
        }