Esempio n. 1
0
        public void save()
        {
            string sname = textSupplierName.Text;

            if (comboPurchaseType.Text != "")
            {
                if (sname != "")
                {
                    if (dgvAddedProducts.Rows.Count != 0)
                    {
                        if (comboReturnReson.Text != "")
                        {
                            SupplierMasterBLL c = sDAL.getSuplierIdFromName(sname);

                            decimal subTotal, totalDiscount, totalSgst, totalCgst, totalIgst, grandTotal;

                            int Purchase_ID;
                            int.TryParse(comboPurchaseID.Text, out Purchase_ID);


                            string type = comboPurchaseType.Text;
                            decimal.TryParse(textSubTotal.Text, out subTotal);
                            decimal.TryParse(textSubDiscount.Text, out totalDiscount);
                            decimal.TryParse(textSgst.Text, out totalSgst);
                            decimal.TryParse(textCgst.Text, out totalCgst);
                            decimal.TryParse(textIgst.Text, out totalIgst);
                            decimal.TryParse(textGrandTotal.Text, out grandTotal);

                            string reson = comboReturnReson.Text;

                            PurchaseReturnBLL.Purchase_ID      = Purchase_ID;
                            PurchaseReturnBLL.Transaction_Type = type;
                            PurchaseReturnBLL.Sup_ID           = c.SupplierID;
                            PurchaseReturnBLL.Sub_Total        = subTotal;
                            PurchaseReturnBLL.TDiscount        = totalDiscount;
                            PurchaseReturnBLL.TSGST            = totalSgst;
                            PurchaseReturnBLL.TCGST            = totalCgst;
                            PurchaseReturnBLL.TIGST            = totalIgst;
                            PurchaseReturnBLL.Grand_Total      = grandTotal;
                            PurchaseReturnBLL.Reson            = reson;

                            PurchaseReturnBLL.PurchaseDetails = PurchaseReturnDT;
                            bool isSuccess = false;

                            // using (TransactionScope scope = new TransactionScope())

                            //int Invoice_No = -1; alredy declared on top
                            bool b = PurchaseReturnDAL.insertPurchaseReturn(PurchaseReturnBLL, out RInvoice_No);

                            for (int i = 0; i < PurchaseReturnDT.Rows.Count; i++)
                            {
                                PurchaseReturnDetailsBLL prdBLL = new PurchaseReturnDetailsBLL();

                                stockBLL         stockBLL    = new stockBLL();
                                string           productName = PurchaseReturnDT.Rows[i][1].ToString();
                                ProductMasterBLL p           = ProductMasterDAL.GetProductIDFromName(productName);

                                prdBLL.Product_ID   = p.Product_ID;
                                prdBLL.Invoice_No   = RInvoice_No;
                                prdBLL.Sup_ID       = c.SupplierID;
                                prdBLL.Product_Name = PurchaseReturnDT.Rows[i][1].ToString();
                                prdBLL.Unit         = PurchaseReturnDT.Rows[i][2].ToString();
                                prdBLL.Qty          = Math.Round(decimal.Parse(PurchaseReturnDT.Rows[i][3].ToString()), 2);
                                prdBLL.Rate         = Math.Round(decimal.Parse(PurchaseReturnDT.Rows[i][4].ToString()), 2);
                                prdBLL.Discount_Per = Math.Round(decimal.Parse(PurchaseReturnDT.Rows[i][5].ToString()), 2);
                                prdBLL.GST_Type     = PurchaseReturnDT.Rows[i][6].ToString();
                                prdBLL.GST_Per      = Math.Round(decimal.Parse(PurchaseReturnDT.Rows[i][7].ToString()), 2);
                                prdBLL.Total        = Math.Round(decimal.Parse(PurchaseReturnDT.Rows[i][9].ToString()), 2);

                                int Product_id = p.Product_ID;
                                stockBLL.Product_Id = Product_id;
                                stockBLL.Quantity   = Math.Round(decimal.Parse(PurchaseReturnDT.Rows[i][3].ToString()), 2);
                                stockBLL.Unit       = PurchaseReturnDT.Rows[i][2].ToString();

                                bool y = PurchaseReturnDetailsDAL.insertPurchaseReturnDetails(prdBLL);

                                if (y == true)
                                {
                                    bool x = stockDAL.dereaseUpdate(stockBLL);
                                }

                                isSuccess = b && y;

                                isSuccess = true;
                            }
                            isSuccess = b;
                            if (isSuccess == true)
                            {
                                //scope.Complete();
                                MessageBox.Show("Transaction Completed");
                                //clear();
                            }
                            else
                            {
                                MessageBox.Show("Transaction Failed");
                            }
                        }
                        else
                        {
                            MessageBox.Show("Please Select Retrun Reson");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please Add product Details");
                    }
                }
                else
                {
                    MessageBox.Show("Please Select Customer Details");
                }
            }
            else
            {
                MessageBox.Show("Please Select Purchase Type GST OR NOGST");
            }
        }
        public void save()
        {
            purchaseBLL purchaseBLL = new purchaseBLL();

            string sname = textSupplierName.Text;

            if (comboPurchaseType.Text != "")
            {
                if (sname != "")
                {
                    if (dgvAddedProducts.Rows.Count != 0)
                    {
                        SupplierMasterBLL s = smDAL.getSuplierIdFromName(sname);

                        decimal subTotal, totalDiscount, totalSgst, totalCgst, totalIgst, grandTotal;

                        string type = comboPurchaseType.Text;
                        decimal.TryParse(textSubTotal.Text, out subTotal);
                        decimal.TryParse(textSubDiscount.Text, out totalDiscount);
                        decimal.TryParse(textSgst.Text, out totalSgst);
                        decimal.TryParse(textCgst.Text, out totalCgst);
                        decimal.TryParse(textIgst.Text, out totalIgst);
                        decimal.TryParse(textGrandTotal.Text, out grandTotal);

                        purchaseBLL.Transaction_Type = type;
                        purchaseBLL.Sup_ID           = s.SupplierID;
                        purchaseBLL.Sub_Total        = subTotal;
                        purchaseBLL.TDiscount        = totalDiscount;
                        purchaseBLL.TSGST            = totalSgst;
                        purchaseBLL.TCGST            = totalCgst;
                        purchaseBLL.TIGST            = totalIgst;
                        purchaseBLL.Grand_Total      = grandTotal;

                        purchaseBLL.PurchaseDetails = purchasedt;
                        bool isSuccess = false;

                        // using (TransactionScope scope = new TransactionScope())

                        //  int purchaseid = -1; already declaraed at the top as a global variable
                        bool b = purchaseDAL.insertpurchase(purchaseBLL, out purchaseid);
                        for (int i = 0; i < purchasedt.Rows.Count; i++)
                        {
                            purchasedetailsBLL pdBLL = new purchasedetailsBLL();

                            stockBLL stockBLL = new stockBLL();

                            string           productName = purchasedt.Rows[i][1].ToString();
                            ProductMasterBLL p           = ProductMasterDAL.GetProductIDFromName(productName);


                            pdBLL.Purchase_ID  = purchaseid;
                            pdBLL.Product_ID   = p.Product_ID;
                            pdBLL.Sup_ID       = s.SupplierID;
                            pdBLL.Product_Name = purchasedt.Rows[i][1].ToString();
                            pdBLL.Unit         = purchasedt.Rows[i][2].ToString();
                            pdBLL.Qty          = Math.Round(decimal.Parse(purchasedt.Rows[i][3].ToString()), 2);
                            pdBLL.Rate         = Math.Round(decimal.Parse(purchasedt.Rows[i][4].ToString()), 2);
                            pdBLL.Discount_Per = Math.Round(decimal.Parse(purchasedt.Rows[i][6].ToString()), 2);
                            pdBLL.GST_Type     = purchasedt.Rows[i][7].ToString();
                            pdBLL.GST_Per      = Math.Round(decimal.Parse(purchasedt.Rows[i][8].ToString()), 2);
                            pdBLL.Total        = Math.Round(decimal.Parse(purchasedt.Rows[i][9].ToString()), 2);



                            int Product_id = p.Product_ID;
                            stockBLL.Product_Id = Product_id;
                            stockBLL.Quantity   = Math.Round(decimal.Parse(purchasedt.Rows[i][3].ToString()), 2);
                            stockBLL.Unit       = purchasedt.Rows[i][2].ToString();

                            bool y = pdetailsDAL.insertpurchasedetails(pdBLL);

                            if (y == true)
                            {
                                stockBLL Padded = stockDAL.CheakeProductAddedOrNot(Product_id);
                                //MessageBox.Show("Product is added",Padded.Product_Id.ToString());
                                if (Product_id == Padded.Product_Id)
                                {
                                    bool x = stockDAL.Update(stockBLL);
                                }
                                else
                                {
                                    bool z = stockDAL.InsertStockNewProduct(stockBLL);
                                }
                            }

                            isSuccess = b && y;

                            isSuccess = true;
                        }
                        if (isSuccess == true)
                        {
                            //scope.Complete();
                            MessageBox.Show("Transaction Completed");
                            //clear();
                        }
                        else
                        {
                            MessageBox.Show("Transaction Failed");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please Add product Details");
                    }
                }
                else
                {
                    MessageBox.Show("Please Select Customer Details");
                }
            }
            else
            {
                MessageBox.Show("Please Select Purchase Type GST OR NOGST");
            }
        }
        public void save()
        {
            string sname = textCust_Name.Text;

            if (comboTransactionType.Text != "")
            {
                if (sname != "")
                {
                    if (dgvAddedProducts.Rows.Count != 0)
                    {
                        customerBLL c = cDAL.getCustomerIdFromName(sname);

                        decimal subTotal, totalDiscount, totalSgst, totalCgst, totalIgst, grandTotal;

                        string type = comboTransactionType.Text;
                        decimal.TryParse(textSubTotal.Text, out subTotal);
                        decimal.TryParse(textSubDiscount.Text, out totalDiscount);
                        decimal.TryParse(textSgst.Text, out totalSgst);
                        decimal.TryParse(textCgst.Text, out totalCgst);
                        decimal.TryParse(textIgst.Text, out totalIgst);
                        decimal.TryParse(textGrandTotal.Text, out grandTotal);

                        EstimateBLL.Transaction_Type = type;
                        EstimateBLL.Cust_ID          = c.Cust_ID;
                        EstimateBLL.Sub_Total        = subTotal;
                        EstimateBLL.TDiscount        = totalDiscount;
                        EstimateBLL.TSGST            = totalSgst;
                        EstimateBLL.TCGST            = totalCgst;
                        EstimateBLL.TIGST            = totalIgst;
                        EstimateBLL.Grand_Total      = grandTotal;

                        EstimateBLL.SalesDetails = salesDT;
                        bool isSuccess = false;

                        // using (TransactionScope scope = new TransactionScope())
                        //alredy declared on top
                        // int Invoice_No = -1;
                        bool b = EstimateDAL.insertChallan(EstimateBLL, out Invoice_No);



                        for (int i = 0; i < salesDT.Rows.Count; i++)
                        {
                            EstimateDetailsBLL cdBLL = new EstimateDetailsBLL();

                            stockBLL stockBLL    = new stockBLL();
                            string   productName = salesDT.Rows[i][1].ToString();

                            ProductMasterBLL p = ProductMasterDAL.GetProductIDFromName(productName);
                            cdBLL.Product_ID   = p.Product_ID;
                            cdBLL.Invoice_No   = Invoice_No;
                            cdBLL.Cust_ID      = c.Cust_ID;
                            cdBLL.Product_Name = salesDT.Rows[i][1].ToString();
                            cdBLL.Unit         = salesDT.Rows[i][2].ToString();
                            cdBLL.Qty          = Math.Round(decimal.Parse(salesDT.Rows[i][3].ToString()), 2);
                            cdBLL.Rate         = Math.Round(decimal.Parse(salesDT.Rows[i][4].ToString()), 2);
                            cdBLL.Discount_Per = Math.Round(decimal.Parse(salesDT.Rows[i][6].ToString()), 2);
                            cdBLL.GST_Type     = salesDT.Rows[i][7].ToString();
                            cdBLL.GST_Per      = Math.Round(decimal.Parse(salesDT.Rows[i][8].ToString()), 2);
                            cdBLL.Total        = Math.Round(decimal.Parse(salesDT.Rows[i][9].ToString()), 2);


                            int Product_id = p.Product_ID;
                            stockBLL.Product_Id = Product_id;
                            stockBLL.Quantity   = Math.Round(decimal.Parse(salesDT.Rows[i][3].ToString()), 2);
                            stockBLL.Unit       = salesDT.Rows[i][2].ToString();

                            bool y = EstimateDetailsDAL.insertchallandetails(cdBLL);

                            isSuccess = b && y;

                            isSuccess = true;
                        }
                        isSuccess = b;
                        if (isSuccess == true)
                        {
                            //scope.Complete();
                            MessageBox.Show("Transaction Completed");
                            //clear();
                        }
                        else
                        {
                            MessageBox.Show("Transaction Failed");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please Add product Details");
                    }
                }
                else
                {
                    MessageBox.Show("Please Select Customer Details");
                }
            }
            else
            {
                MessageBox.Show("Please Select Purchase Type GST OR NOGST");
            }
        }