public bool insertchallandetails(EstimateDetailsBLL cb)
        {
            bool isSuccess = false;

            SqlConnection con = new SqlConnection(myconnstrng);

            try
            {
                //inserting transaction details
                string     sql = "INSERT INTO Estimate_Transactions_Details (Invoice_No,Product_ID,Cust_ID,Product_Name,Unit,Qty,Rate,Dicount_Per,GST_Type,GST_Per,Total) VALUES(@Invoice_No,@Product_ID,@Cust_ID,@Product_Name,@Unit,@Qty,@Rate,@Discount_Per,@GST_Type,@GST_Per,@Total)";
                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Parameters.AddWithValue("@Invoice_No", cb.Invoice_No);
                cmd.Parameters.AddWithValue("@Product_ID", cb.Product_ID);
                cmd.Parameters.AddWithValue("@Cust_ID", cb.Cust_ID);
                cmd.Parameters.AddWithValue("@Product_Name", cb.Product_Name);
                cmd.Parameters.AddWithValue("@Unit", cb.Unit);
                cmd.Parameters.AddWithValue("@Qty", cb.Qty);
                cmd.Parameters.AddWithValue("@Rate", cb.Rate);
                cmd.Parameters.AddWithValue("@Discount_Per", cb.Discount_Per);
                cmd.Parameters.AddWithValue("@GST_Type", cb.GST_Type);
                cmd.Parameters.AddWithValue("@GST_Per", cb.GST_Per);
                cmd.Parameters.AddWithValue("@Total", cb.Total);
                //Unit,Qty,Rate,Discount_Per,GST_Type,GST_Per,Total
                con.Open();

                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
            }
            return(isSuccess);
        }
        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");
            }
        }