コード例 #1
0
        protected void btnAdd_OnClick(object sender, EventArgs e)
        {
            this.AlertNone(lblMsg);
            ProductProvider productProvider = new ProductProvider();
            string          measurementUnit = productProvider.GetMeasurementUnit(ddlFinishedProduct.SelectedValue.Toint());
            string          packSize        = productProvider.GetPackSizeName(ddlFinishedProduct.SelectedValue.Toint());
            string          code            = productProvider.GetFinishedProductCode(ddlFinishedProduct.SelectedValue.Toint());
            decimal         tradePrice      = productProvider.GetTradePrice(ddlFinishedProduct.SelectedValue.Toint());


            if (ddlFinishedProduct.SelectedValue == "")
            {
                MessageHelper.ShowAlertMessage("Select Product!");
                lblMsg.Focus();
                return;
            }
            List <FinishedProductProvider> purchaseLedgerDetailsProviderList = new List <FinishedProductProvider>();

            foreach (GridViewRow row in gvRequisition.Rows)
            {
                FinishedProductProvider obj = new FinishedProductProvider();

                HiddenField hfRowProductID = (HiddenField)row.FindControl("hfProductID");
                Label       lblProductName = (Label)row.FindControl("lblProduct");
                Label       lblPackSize    = (Label)row.FindControl("lblPackSize");

                Label       lblBatchNo         = (Label)row.FindControl("lblBatchNo");
                Label       lblUnit            = (Label)row.FindControl("lblUnit");
                Label       lblTradePrice      = (Label)row.FindControl("lblTradePrice");
                TextBox     txtBatchQuantity   = (TextBox)row.FindControl("txtBatchQuantity");
                Label       lblTotalTradePrice = (Label)row.FindControl("lblTotalTradePrice");
                ImageButton btnAddOrDelete     = (ImageButton)row.FindControl("btnDeleteSelectedRowLSE");

                if (hfRowProductID.Value == ddlFinishedProduct.SelectedValue)
                {
                    MessageHelper.ShowAlertMessage("This product already exists!");
                    return;
                }
                if (txtBatchQuantity.Text.ToDecimal() <= 0)
                {
                    MessageHelper.ShowAlertMessage("Enter Quantity!");
                    return;
                }
                obj.ProductID           = hfRowProductID.Value.Toint();
                obj.ProductName         = lblProductName.Text.ToString();
                obj.BatchQuantity       = txtBatchQuantity.Text.ToDecimal();
                obj.PackSize            = lblPackSize.Text;
                obj.BatchNo             = lblBatchNo.Text;
                obj.MeasurementUnitName = lblUnit.Text.ToString();
                obj.TradePrice          = lblTradePrice.Text.ToDecimal();
                obj.TotalTradePrice     = lblTotalTradePrice.Text.ToDecimal();

                purchaseLedgerDetailsProviderList.Add(obj);
            }
            string productName = ddlFinishedProduct.SelectedItem.Text;
            int    productID   = ddlFinishedProduct.SelectedValue.Toint();

            FinishedProductProvider obj2 = new FinishedProductProvider();
            DataTable dt = obj2.GetBatchWiseMFCExpDate(ddlBatchNo.SelectedItem.ToString());

            obj2.ProductID           = productID;
            obj2.ProductName         = productName;
            obj2.ProductCode         = code;
            obj2.MeasurementUnitName = measurementUnit;
            obj2.PackSize            = packSize;
            obj2.TradePrice          = tradePrice;
            obj2.BatchNo             = ddlBatchNo.SelectedItem.ToString();
            obj2.MfgDate             = DateTime.ParseExact(dt.Rows[0]["MfgDate"].ToString(), "dd/MM/yyyy", CultureInfo.InvariantCulture);
            obj2.MfgDate             = DateTime.ParseExact(dt.Rows[0]["ExpDate"].ToString(), "dd/MM/yyyy", CultureInfo.InvariantCulture);
            purchaseLedgerDetailsProviderList.Add(obj2);

            if (!divGridForLSE.Visible)
            {
                divGridForLSE.Visible = true;
            }
            gvRequisition.DataSource = purchaseLedgerDetailsProviderList;
            gvRequisition.DataBind();
            ddlDivision.Enabled = false;
        }