public ProductMasterBLL GetProductIDFromName(string ProductName)
        {
            ProductMasterBLL p   = new ProductMasterBLL();
            SqlConnection    con = new SqlConnection(myconnstrng);
            DataTable        dt  = new DataTable();

            try
            {
                // GETID FROM PRODUCT TABLE
                string         sql     = "SELECT Product_ID FROM Product_Master WHERE Product_Name='" + ProductName + "'";
                SqlDataAdapter adapter = new SqlDataAdapter(sql, con);
                con.Open();

                adapter.Fill(dt);
                if (dt.Rows.Count > 0)
                {
                    p.Product_ID = int.Parse(dt.Rows[0]["Product_ID"].ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }

            return(p);
        }
        public bool Delete(ProductMasterBLL pBLL)
        {
            bool          isSuccess = false;
            SqlConnection con       = new SqlConnection(myconnstrng);

            try
            {
                string     sql = "DELETE FROM Product_Master WHERE Product_ID =@Product_ID";
                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Parameters.AddWithValue("@Product_ID", pBLL.Product_ID);
                con.Open();
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }

            return(isSuccess);
        }
        public ProductMasterBLL GetProductsForTransaction(string keyword)
        {
            ProductMasterBLL p    = new ProductMasterBLL();
            SqlConnection    conn = new SqlConnection(myconnstrng);
            DataTable        dt   = new DataTable();

            try
            {
                string         sql     = "SELECT Item_Code, Quantity,Purchase_Price, Product_Name, Product_Master.Unit , Sales_Price FROM Product_Master,Stock_Master where Product_Master.Product_Id=Stock_Master.Product_Id AND Product_Master.Product_ID LIKE '%" + keyword + "%' OR Product_Name LIKE '%" + keyword + "%'";
                SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);

                conn.Open();

                adapter.Fill(dt);
                if (dt.Rows.Count > 0)
                {
                    p.Item_Code      = dt.Rows[0]["Item_Code"].ToString();
                    p.Quantity       = decimal.Parse(dt.Rows[0]["Quantity"].ToString());
                    p.Product_Name   = dt.Rows[0]["Product_Name"].ToString();
                    p.Unit           = dt.Rows[0]["Unit"].ToString();
                    p.Purchase_Price = decimal.Parse(dt.Rows[0]["Purchase_Price"].ToString());
                    p.Sales_Price    = decimal.Parse(dt.Rows[0]["Sales_Price"].ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }

            return(p);
        }
        private void textBox13_TextChanged(object sender, EventArgs e)
        {
            string keyword = textItemSearch.Text;


            if (keyword == "")
            {
                textItemCode.Text    = "";
                textItemName.Text    = "";
                comboBoxUnit.Text    = "";
                textInventory.Text   = "0";
                textRate.Text        = "0";
                textDiscount.Text    = "0";
                textQuantity.Text    = "0";
                comboGstType.Text    = "";
                textGST.Text         = "0";
                textTotalAmount.Text = "";
                return;
            }

            ProductMasterBLL p = ProductMasterDAL.GetProductsForTransaction(keyword);

            textItemCode.Text  = p.Item_Code;
            textItemName.Text  = p.Product_Name;
            comboBoxUnit.Text  = p.Unit;
            textRate.Text      = p.Sales_Price.ToString();
            textInventory.Text = p.Quantity.ToString();
        }
Ejemplo n.º 5
0
        public void BindGdvDetails()
        {
            DataSet      ds2        = new DataSet();
            OrderDetails objDetails = new OrderDetails();

            if (Session["OrderID"] == null)
            {
                Session["OrderID"] = Convert.ToInt32(ds.Tables[0].Rows[0]["OrderID"]);
            }
            objDetails.OrderID = Convert.ToInt32(Session["OrderID"]);

            ds2 = PlaceOrderBLL.GetOrderDetailsById(objDetails);

            gdvOrderDetail.DataSource = ds2;
            gdvOrderDetail.DataBind();


            if (Session["OrderID"] != null)
            {
                DataSet dspro = new DataSet();
                dspro = ProductMasterBLL.GetAllProductMaster();

                DropDownList drpOrderDetail = (DropDownList)gdvOrderDetail.FooterRow.FindControl("drpAddOrderDetail");


                drpOrderDetail.DataSource = dspro;

                drpOrderDetail.DataTextField  = "ProductName";
                drpOrderDetail.DataValueField = "ProductID";

                drpOrderDetail.DataBind();
            }
        }
        private void textQuantity_TextChanged(object sender, EventArgs e)
        {
            string           pname = textItemSearch.Text;
            ProductMasterBLL p     = ProductMasterDAL.GetProductsForTransaction(pname);
            decimal          inv;

            decimal.TryParse(textQuantity.Text, out inv);
            decimal qunt = p.Quantity - inv;

            if (qunt < 0)
            {
                MessageBox.Show("No Inventory Please add Inventory First");
                textQuantity.Text = "";
            }
            else
            {
                if (textQuantity.Text == "")
                {
                    textTotalAmount.Text = "";
                }
                else
                {
                    decimal Qty, Rate, discount, gst;
                    decimal.TryParse(textQuantity.Text, out Qty);
                    decimal.TryParse(textRate.Text, out Rate);
                    decimal.TryParse(textDiscount.Text, out discount);
                    decimal.TryParse(textGST.Text, out gst);

                    decimal TotalAmount = Math.Round(((100 + gst) / 100) * (((100 - discount) / 100) * (Rate * Qty)), 2);

                    textTotalAmount.Text = TotalAmount.ToString();
                }
            }
        }
Ejemplo n.º 7
0
        protected void gdvOrderDetail_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if ((e.Row.RowState & DataControlRowState.Edit) > 0)
                {
                    try
                    {
                        DataSet dspro = new DataSet();
                        dspro = ProductMasterBLL.GetAllProductMaster();
                        DropDownList depList = (DropDownList)e.Row.FindControl("drpOrderDetail");
                        depList.DataSource = dspro;

                        depList.DataTextField  = "ProductName";
                        depList.DataValueField = "ProductID";
                        depList.DataBind();
                        depList.Items.FindByValue((e.Row.FindControl("lblProductName_Id") as Label).Text).Selected = true;

                        DataRowView dr = e.Row.DataItem as DataRowView;
                        depList.SelectedValue = (string)e.Row.DataItem; // you can use e.Row.DataItem to get the value
                    }
                    catch (Exception exo)
                    { }
                }
            }
        }
        public ProductMasterBLL checkProductHSNAvailableOrNot(string keyword)
        {
            ProductMasterBLL p = new ProductMasterBLL();

            SqlConnection con = new SqlConnection(myconnstrng);

            DataTable dt = new DataTable();

            //fdfd
            try
            {
                string sql = "SELECT HSN_Code from Product_Master WHERE HSN_Code LIKE '%" + keyword + "%'";

                SqlDataAdapter adapter = new SqlDataAdapter(sql, con);

                con.Open();

                adapter.Fill(dt);

                if (dt.Rows.Count > 0)
                {
                    p.Product_Name = dt.Rows[0]["HSN_Code"].ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
            }
            return(p);
        }
        public bool Insert(ProductMasterBLL pBLL, out int Product_ID)
        {
            //Creating Boolean Variable and set its default value to false
            bool isSuccess = false;

            Product_ID = -1;
            //Sql Connection for DAtabase
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //SQL Query to insert product into database
                String sql = "INSERT INTO Product_Master (Product_Group,Brand,Item_Code,Product_Name,HSN_Code,Purchase_Price,Sales_Price,Min_Sales_Price,Unit,Opening_Stock) VALUES (@Product_Group, @Brand, @Item_Code, @Product_Name, @HSN_Code, @Purchase_Price, @Sales_Price,@Min_Sales_Price,@Unit,@Opening_Stock);select @@IDENTITY;";

                //Creating SQL Command to pass the values
                SqlCommand cmd = new SqlCommand(sql, conn);

                //Passign the values through parameters
                cmd.Parameters.AddWithValue("@Product_Group", pBLL.Product_Group);
                cmd.Parameters.AddWithValue("@Brand", pBLL.Brand);
                cmd.Parameters.AddWithValue("@Item_Code", pBLL.Item_Code);
                cmd.Parameters.AddWithValue("@Product_Name", pBLL.Product_Name);
                cmd.Parameters.AddWithValue("@HSN_Code", pBLL.HSN_Code);
                cmd.Parameters.AddWithValue("@Purchase_Price", pBLL.Purchase_Price);
                cmd.Parameters.AddWithValue("@Sales_Price", pBLL.Sales_Price);
                cmd.Parameters.AddWithValue("@Min_Sales_Price", pBLL.Min_Sales_Price);
                cmd.Parameters.AddWithValue("@Unit", pBLL.Unit);
                cmd.Parameters.AddWithValue("@Opening_Stock", pBLL.Opening_Stock);

                //Opening the Database connection
                conn.Open();

                object o = cmd.ExecuteScalar();
                //int rows = cmd.ExecuteNonQuery();

                //If the query is executed successfully then the value of rows will be greater than 0 else it will be less than 0
                if (o != null)
                {
                    //Query Executed Successfully
                    isSuccess  = true;
                    Product_ID = int.Parse(o.ToString());
                }
                else
                {
                    //FAiled to Execute Query
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }
Ejemplo n.º 10
0
        public void BindDrpSearch()
        {
            ds = ProductMasterBLL.GetAllProductMaster();
            drpSerchUser.DataSource = ds;
            drpSerchUser.Items.Insert(0, new ListItem("Select Product", ""));
            drpSerchUser.DataTextField  = "ProductName";
            drpSerchUser.DataValueField = "ProductID";

            drpSerchUser.DataBind();
        }
Ejemplo n.º 11
0
        public void BindDrpProduct()
        {
            DataSet dspro = new DataSet();

            dspro = ProductMasterBLL.GetAllProductMaster();


            drpSerchProduct.DataSource = dspro;

            drpSerchProduct.DataTextField  = "ProductName";
            drpSerchProduct.DataValueField = "ProductID";

            drpSerchProduct.DataBind();
        }
Ejemplo n.º 12
0
 public void BinddrpCatogory()
 {
     try
     {
         DataSet ds2 = new DataSet();
         ds2 = ProductMasterBLL.GetAllProductMaster();
         drpProductMaster.Items.Insert(0, new ListItem("Select Product", " ab"));
         drpProductMaster.DataSource     = ds2;
         drpProductMaster.DataValueField = "ProductID";
         drpProductMaster.DataTextField  = "ProductName";
         drpProductMaster.DataBind();
     }
     catch (Exception)
     {
         throw;
     }
 }
        public bool Update(ProductMasterBLL pBLL)
        {
            bool          isSuccess = false;
            SqlConnection con       = new SqlConnection(myconnstrng);

            try
            {
                String     sql = "UPDATE Product_Master SET Product_Group=@Product_Group,Brand=@Brand,Item_Code=@Item_Code,Product_Name=@Product_Name,HSN_Code=@HSN_Code,Purchase_Price=@Purchase_Price,Sales_Price=@Sales_Price,Min_Sales_Price=@Min_Sales_Price,Unit=@Unit,Opening_Stock=@Opening_Stock WHERE Product_ID = @Product_ID";
                SqlCommand cmd = new SqlCommand(sql, con);

                cmd.Parameters.AddWithValue("@Product_ID", pBLL.Product_ID);
                cmd.Parameters.AddWithValue("@Product_Group", pBLL.Product_Group);
                cmd.Parameters.AddWithValue("@Brand", pBLL.Brand);
                cmd.Parameters.AddWithValue("@Item_Code", pBLL.Item_Code);
                cmd.Parameters.AddWithValue("@Product_Name", pBLL.Product_Name);
                cmd.Parameters.AddWithValue("@HSN_Code", pBLL.HSN_Code);
                cmd.Parameters.AddWithValue("@Purchase_Price", pBLL.Purchase_Price);
                cmd.Parameters.AddWithValue("@Sales_Price", pBLL.Sales_Price);
                cmd.Parameters.AddWithValue("@Min_Sales_Price", pBLL.Min_Sales_Price);
                cmd.Parameters.AddWithValue("@Unit", pBLL.Unit);
                cmd.Parameters.AddWithValue("@Opening_Stock", pBLL.Opening_Stock);


                con.Open();
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }

            return(isSuccess);
        }
Ejemplo n.º 14
0
 protected void ProdDisplayGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     try
     {
         ProductMasterBLL prodManager = new ProductMasterBLL();
         Label            ID          = (Label)ProdDisplayGrid.Rows[e.RowIndex].FindControl("lblProd_id");
         int           selectedId     = int.Parse(ID.Text);
         ProductMaster prodToDelete   = new ProductMaster();//= empid.Text;
         prodToDelete.ProductID = selectedId;
         prodManager.Delete(prodToDelete);
     }
     catch (Exception exp) { }
     finally
     {
         ProdDisplayGrid.EditIndex = -1;
         BindGrid(false);
     }
 }
Ejemplo n.º 15
0
        private void BindGrid(bool isDrpSelection)
        {
            ProductMaster obj = new ProductMaster();

            if (drpSerchProduct.SelectedValue != "" && isDrpSelection)
            {
                obj.ProductID = Convert.ToInt32(drpSerchProduct.SelectedValue);
                ds            = ProductMasterBLL.GetProductMasterByID(obj);
                ProdDisplayGrid.DataSource = ds;
                ProdDisplayGrid.DataBind();
            }
            else
            {
                ds = ProductMasterBLL.GetAllProductMaster();
                ProdDisplayGrid.DataSource = ds;
                ProdDisplayGrid.DataBind();
            }
        }
        private void textItemSearch_TextChanged(object sender, EventArgs e)
        {
            string keyword = textItemSearch.Text;


            if (keyword == "")
            {
                textItemName.Text  = "";
                textInventory.Text = "0";
                textRate.Text      = "0";
                textQuantity.Text  = "0";
                return;
            }

            ProductMasterBLL p = ProductMasterDAL.GetProductsForTransaction(keyword);

            textItemName.Text  = p.Product_Name;
            comboBoxUnit.Text  = p.Unit;
            textInventory.Text = p.Quantity.ToString();
            textRate.Text      = p.Purchase_Price.ToString();
        }
Ejemplo n.º 17
0
        protected void ProdDisplayGrid_Sorting(object sender, GridViewSortEventArgs e)
        {
            DataView sortedView;
            string   sortingDirection = string.Empty;

            if (direction == SortDirection.Ascending)
            {
                direction        = SortDirection.Descending;
                sortingDirection = "Desc";
            }
            else
            {
                direction        = SortDirection.Ascending;
                sortingDirection = "Asc";
            }

            ds = ProductMasterBLL.GetAllProductMaster();
            ProdDisplayGrid.DataSource = ds;
            sortedView                 = new DataView(ds.Tables[0]);
            sortedView.Sort            = e.SortExpression + " " + sortingDirection;
            Session["SortedView"]      = sortedView;
            ProdDisplayGrid.DataSource = sortedView;
            ProdDisplayGrid.DataBind();
        }
        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");
            }
        }
Ejemplo n.º 19
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 AddEditMasterProduct(bool add)
        {
            try
            {
                ProductMaster obj = new ProductMaster();

                obj.ProductName        = txtProductName.Text;
                obj.ProductCode        = txtProdCode.Text;
                obj.Manufacturer       = txtBrndName.Text;
                obj.Status             = "1";
                obj.ProductDescription = txtDescription.Text;
                obj.GenericName        = txtGName.Text;
                obj.MeasureQuantity    = txtMeasQty.Text;
                obj.MeasureType        = txtMeasType.Text;
                obj.ProductOrgID       = txtProdOrgID.Text;
                obj.ProductType        = txtProdType.Text;
                float res1, res2;
                int   res3, res4;

                if (float.TryParse(txtCP.Text.ToString(), out res1))
                {
                    obj.CostPrice = res1;
                }
                else
                {
                    WebMessageBoxUtil.Show("Invalid input of Cost Price");
                    return;
                }

                if (float.TryParse(txtSP.Text.ToString(), out res2))
                {
                    obj.SalePrice = res2;
                }
                else
                {
                    WebMessageBoxUtil.Show("Invalid input of Sale Price");
                    return;
                }
                if (int.TryParse(TxtDisc.Text.ToString(), out res3))
                {
                    obj.MaxDiscount = res3;
                }
                else
                {
                    WebMessageBoxUtil.Show("Invalid input of Discount");
                    return;
                }


                if (int.TryParse(txtQUnit.Text.ToString(), out res4))
                {
                    obj.QuanityUnit = res4;
                }
                else
                {
                    WebMessageBoxUtil.Show("Invalid input of Quantity Unit");
                    return;
                }

                obj.SubCategoryID = Convert.ToInt32(drpcategory.SelectedValue);

                obj.ProductCode = txtProdCode.Text;
                int thd;
                if (int.TryParse(txtThreshold.Text, out thd))
                {
                    obj.ThreshHold = thd;
                }
                else
                {
                    WebMessageBoxUtil.Show("Invalid input of threshold");
                    return;
                }
                obj.LastUpdatedDate = DateTime.Now;
                ProductMasterBLL objupd = new ProductMasterBLL();
                if (add)
                {
                    obj.DateCreated = DateTime.Now;
                    objupd.Add(obj);
                }
                else
                {
                    obj.ProductID = int.Parse(txtProductID.Text);
                    objupd.Update(obj);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        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");
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (comboProduct_Group.Text != "")
            {
                if (comboBrand.Text != "")
                {
                    if (txtItem_Code.Text != "")
                    {
                        pBLL = pDAL.checkProductCodeAvailableOrNot(txtItem_Code.Text);
                        if (txtItem_Code.Text != pBLL.Item_Code)
                        {
                            if (txtProduct_Name.Text != "")
                            {
                                pBLL = pDAL.checkProductAvailableOrNot(txtProduct_Name.Text);
                                if (txtProduct_Name.Text != pBLL.Product_Name)
                                {
                                    if (textHSN_Code.Text != "")
                                    {
                                        pBLL = pDAL.checkProductHSNAvailableOrNot(textHSN_Code.Text);
                                        if (textHSN_Code.Text != pBLL.HSN_Code)
                                        {
                                            if (txtPurchase_Price.Text != "")
                                            {
                                                if (txtPurchase_Price.Text != "0")
                                                {
                                                    if (txtMin_Sales_Price.Text != "")
                                                    {
                                                        if (txtMin_Sales_Price.Text != "0")
                                                        {
                                                            if (comboUnit.Text != "")
                                                            {
                                                                if (txtOpening_Stock.Text != "")
                                                                {
                                                                    pBLL.Product_Group   = comboProduct_Group.Text;
                                                                    pBLL.Brand           = comboBrand.Text;
                                                                    pBLL.Item_Code       = txtItem_Code.Text;
                                                                    pBLL.Product_Name    = txtProduct_Name.Text;
                                                                    pBLL.HSN_Code        = textHSN_Code.Text;
                                                                    pBLL.Purchase_Price  = decimal.Parse(txtPurchase_Price.Text);
                                                                    pBLL.Sales_Price     = decimal.Parse(txtSales_Price.Text);
                                                                    pBLL.Min_Sales_Price = decimal.Parse(txtMin_Sales_Price.Text);
                                                                    pBLL.Unit            = comboUnit.Text;
                                                                    pBLL.Opening_Stock   = decimal.Parse(txtOpening_Stock.Text);


                                                                    bool a = pDAL.Insert(pBLL, out Product_ID);

                                                                    //adding Opening stock
                                                                    sBLL.Product_Id = Product_ID;
                                                                    sBLL.Quantity   = decimal.Parse(txtOpening_Stock.Text);
                                                                    sBLL.Unit       = comboUnit.Text;

                                                                    bool b = sDAL.InsertStockNewProduct(sBLL);

                                                                    bool Success = a && b;
                                                                    if (Success == true)
                                                                    {
                                                                        MessageBox.Show("Product Details Successfully Added");
                                                                        //MessageBox.Show(Product_ID.ToString());

                                                                        clear();
                                                                    }
                                                                    else
                                                                    {
                                                                        MessageBox.Show("Failed to Added Product Details");
                                                                    }
                                                                    DataTable dt = pDAL.Select();
                                                                    dgvProductMaster.DataSource = dt;
                                                                }
                                                                else
                                                                {
                                                                    MessageBox.Show("Please Enter the Product Opening Stock");
                                                                }
                                                            }
                                                            else
                                                            {
                                                                MessageBox.Show("Please Select Product Unit");
                                                            }
                                                        }
                                                        else
                                                        {
                                                            MessageBox.Show("Please Enter the Product Minimum Sales Prise Greater Than 0");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        MessageBox.Show("Please Enter the Product Minimum Sales Prise");
                                                    }
                                                }
                                                else
                                                {
                                                    MessageBox.Show("Please Enter the Product Purchase Prise Greater Than 0");
                                                }
                                            }
                                            else
                                            {
                                                MessageBox.Show("Please Enter the Product Purchase Prise");
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("HSN Code is Already Added in Database Please choose another HSN Code");
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Please Enter the Product HSN Code");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Product is Already Added in Database Please choose another Product");
                                }
                            }
                            else
                            {
                                MessageBox.Show("Please Enter the Product Name");
                            }
                        }
                        else
                        {
                            MessageBox.Show("Item Code is Already Added in Database Please choose another Item Code");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please Enter the Product Code");
                    }
                }
                else
                {
                    MessageBox.Show("Please Enter the Product Brand");
                }
            }
            else
            {
                MessageBox.Show("Please Select Product Group");
            }
        }