protected void lnkBtnSaveDS_Click(object sender, EventArgs e)
    {
      
        PurchasedProduct objPurchasedProduct = new PurchasedProduct();
        objPurchasedProduct.ProductID = Convert.ToInt32(htnProductID.Value);
        objPurchasedProduct.ProductName = lblProduct.Text;
        objPurchasedProduct.BarCode = lblBarCode.Text;
        objPurchasedProduct.BuyingPrice = Convert.ToDecimal(txtBuyingPrice.Text);
        objPurchasedProduct.Margin = Convert.ToDecimal(txtMargin.Text);
        objPurchasedProduct.Tax = Convert.ToDecimal(txtTax.Text);
        objPurchasedProduct.SellingPrice = Convert.ToDecimal(txtSellingPrice.Text);
        objPurchasedProduct.SizeQty = "";

        ProductSize objProductSize;
        List<Size> lstSizeIDs = (List<Size>)Session["ProductSizeIDs"];
        List<ProductSize> lstProductSizes = new List<ProductSize>();
        int intTotalQty = 0;
        decimal dblTotalAmount = Convert.ToDecimal(lblTotalAmount.Text);

        for (int i = 0; i < lstSizeIDs.Count; i++)
        {
            if (!String.IsNullOrEmpty(Request.Form["txtSize_" + lstSizeIDs[i].SizeID.ToString()]))
            {
                objProductSize = new ProductSize();
                objProductSize.ProductID = objPurchasedProduct.ProductID;
                objProductSize.SizeID = lstSizeIDs[i].SizeID;
                objProductSize.Quantity = Convert.ToInt32(Request.Form["txtSize_" + lstSizeIDs[i].SizeID.ToString()].ToString());
                lstProductSizes.Add(objProductSize);

                intTotalQty += objProductSize.Quantity;

                if (i > 0)
                    objPurchasedProduct.SizeQty += "<br/>";

                objPurchasedProduct.SizeQty += lstSizeIDs[i].SizeName + ": " + objProductSize.Quantity;
            }
        }

        if (intTotalQty > 0)
        {
            objPurchasedProduct.PurchasedQty = lstProductSizes;

            if (Session["PurchasedProduct"] != null)
                gobjProduct = (List<PurchasedProduct>)Session["PurchasedProduct"];

            gobjProduct.Add(objPurchasedProduct);
            Session["PurchasedProduct"] = gobjProduct;

            // lblMsg.Text = 
            PopulateGrid();

            lblTotalQuantity.Text = Convert.ToString(intTotalQty + Convert.ToInt32(lblTotalQuantity.Text));
            lblTotalAmount.Text = Math.Round((dblTotalAmount + (intTotalQty * objPurchasedProduct.BuyingPrice)), 2).ToString();

            ScriptManager.RegisterStartupScript(this, this.GetType(), "PopulateType", "Populate('2')", true);
        }
        else
        {
            System.Web.UI.HtmlControls.HtmlGenericControl containerDiv;
            System.Web.UI.HtmlControls.HtmlGenericControl textBoxDiv;

            for (int i = 0; i < lstSizeIDs.Count; i++)
            {
                for (int j = 0; j < lstProductSizes.Count; j++)
                {
                    if (lstSizeIDs[i].SizeID == lstProductSizes[j].SizeID)
                    {
                        containerDiv = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
                        containerDiv.Controls.Add(CreateLabel(lstProductSizes[j].SizeID, lstSizeIDs[i].SizeName));
                        plhQty.Controls.Add(containerDiv);
                        textBoxDiv = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
                        textBoxDiv.Controls.Add(CreateTextBox(lstProductSizes[j].SizeID, 0));
                        plhQty.Controls.Add(textBoxDiv);
                        break;
                    }
                }
            }
            

            Span3.InnerHtml = "Total Quantity cannot be zero";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "AddEditPurchase", "ShowModalDiv('ModalWindow1','dvInnerWindow',0);", true);
        }

    }
Esempio n. 2
0
        public void GetPurchaseByID(ref PurchaseRecord vobjPurchaseRecord)
        {
            try
            {
                object[] mParams = {
                                    new SqlParameter("@PurchaseID", SqlDbType.Int)
                                };

                mParams[0] = vobjPurchaseRecord.PurchaseID;

                PurchasedProduct objPurchasedProduct;
                ProductSize objProductSize = new ProductSize();
                List<PurchasedProduct> lstPurchasedProduct = new List<PurchasedProduct>();
                List<ProductSize> lstProductSize = new List<ProductSize>();
                int intTotalQty = 0;
                decimal dcmTotalBuyingPrice = 0;

                using (IDataReader reader = dBase.ExecuteReader("sprocCS_GetProductPurchaseByID", mParams))
                {
                    while (reader.Read())
                    {
                        objPurchasedProduct = new PurchasedProduct();
                        if (reader["ManufacturerID"] != DBNull.Value)
                            vobjPurchaseRecord.ManufacturerID = Convert.ToInt32(reader["ManufacturerID"]);
                        if (reader["PurchaseDate"] != DBNull.Value)
                            vobjPurchaseRecord.PurchaseDate = Convert.ToDateTime(reader["PurchaseDate"]).ToString("dd/MM/yyyy");
                        if (reader["ProductID"] != DBNull.Value)
                            objPurchasedProduct.ProductID = Convert.ToInt32(reader["ProductID"]);
                        if (reader["ProductName"] != DBNull.Value)
                            objPurchasedProduct.ProductName = Convert.ToString(reader["ProductName"]);
                        if (reader["BuyingPrice"] != DBNull.Value)
                            objPurchasedProduct.BuyingPrice = Convert.ToDecimal(reader["BuyingPrice"]);
                        if (reader["Tax"] != DBNull.Value)
                            objPurchasedProduct.Tax = Convert.ToDecimal(reader["Tax"]);
                        if (reader["Margin"] != DBNull.Value)
                            objPurchasedProduct.Margin = Convert.ToDecimal(reader["Margin"]);
                        if (reader["SellingPrice"] != DBNull.Value)
                            objPurchasedProduct.SellingPrice = Convert.ToDecimal(reader["SellingPrice"]);
                        if (reader["BarCode"] != DBNull.Value)
                            objPurchasedProduct.BarCode = Convert.ToString(reader["BarCode"]);
                        string[] sizes = Convert.ToString(reader["Sizes"]).Split(',');

                        lstProductSize = new List<ProductSize>();
                        intTotalQty  = 0;
                        for (int i = 0; i < sizes.Length; i++)
                        {
                            objProductSize = new ProductSize();
                            string[] sizeqty = sizes[i].Split('~');
                            objProductSize.SizeID = Convert.ToInt32(sizeqty[0]);
                            objProductSize.Quantity = Convert.ToInt32(sizeqty[2]);
                            objProductSize.ProductID = objPurchasedProduct.ProductID;
                            lstProductSize.Add(objProductSize);
                            if (i > 0)
                                objPurchasedProduct.SizeQty += "<br/>";
                            objPurchasedProduct.SizeQty += sizeqty[1] + ": " + objProductSize.Quantity;


                            intTotalQty += objProductSize.Quantity;
                        }
                        objPurchasedProduct.PurchasedQty = lstProductSize;

                        vobjPurchaseRecord.TotalQty += intTotalQty;
                        vobjPurchaseRecord.TotalBuyingPrice += objPurchasedProduct.BuyingPrice * intTotalQty;
                        lstPurchasedProduct.Add(objPurchasedProduct);
         
                    }
                    vobjPurchaseRecord.ProductsPurchased = lstPurchasedProduct;
                }
            }
            catch (Exception  ex)
            {
                
                Common.LogError("CSWeb > Error > " + (new StackTrace()).GetFrame(0).GetMethod().Name, ex.ToString());
            }
        }