Exemplo n.º 1
0
        protected void addToGridView()
        {
            try
            { //adding under normal condition, wrote this method so that code will not repeat
                ArrayList        al  = (ArrayList)Session["AdjustmentDetails"];
                AdjustmentInfoBO abo = new AdjustmentInfoBO();
                abo.ItemNumber = ddlItemName.SelectedValue;
                abo.ItemName   = ddlItemName.SelectedItem.Text;
                abo.SupplierId = ddlSupplier.SelectedItem.Text;
                int qty = Convert.ToInt32(tbQuantity.Text);
                abo.QuantityAdjustment = qty;
                abo.Uom    = tbUOM.Text.Trim();
                abo.Reason = tbReason.Text.Trim();
                double price = Convert.ToInt32(ddlSupplier.SelectedValue) * qty;
                if (price < 0)
                {
                    price = price * -1;
                }
                abo.Price = price.ToString();

                al.Add(abo);

                gvInventoryAdjustmentList.DataSource = al;
                gvInventoryAdjustmentList.DataBind();
                //apply the footable settings
                footableSettings();
                btnSubmit.Visible = true;
            }
            catch (Exception x)
            {
                System.Diagnostics.Debug.WriteLine(x);
            }
        }
Exemplo n.º 2
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (gvInventoryAdjustmentList.Rows.Count == 0)      // check if gridview is empty
            {
                addToGridView();                                // call add to gridview
            }
            else if (gvInventoryAdjustmentList.Rows.Count == 1) //check if there is one item in gridview
            {
                Label lbItemNumber = (Label)gvInventoryAdjustmentList.Rows[0].FindControl("lbItemNumber");
                //get itemnumer from gridview hidden field
                if (lbItemNumber.Text.Equals(ddlItemName.SelectedValue))
                {
                    ArrayList        al  = (ArrayList)Session["AdjustmentDetails"];
                    AdjustmentInfoBO abo = new AdjustmentInfoBO();
                    abo.ItemNumber = ddlItemName.SelectedValue;
                    abo.ItemName   = ddlItemName.SelectedItem.Text;
                    abo.SupplierId = ddlSupplier.SelectedItem.Text;
                    int qty = Convert.ToInt32(tbQuantity.Text);
                    abo.QuantityAdjustment = qty;
                    abo.Uom    = tbUOM.Text.Trim();
                    abo.Reason = tbReason.Text.Trim();
                    double price = Convert.ToInt32(ddlSupplier.SelectedValue) * qty;
                    if (price < 0)
                    {
                        price = price * -1;
                    }
                    abo.Price = price.ToString();
                    //get all the item from fields

                    al.RemoveAt(0); //remove item from arraylist
                    al.Add(abo);    //add the changed item into arraylist

                    gvInventoryAdjustmentList.DataSource = al;
                    gvInventoryAdjustmentList.DataBind();

                    //apply the footable settings
                    footableSettings();
                }
                else
                {
                    addToGridView();
                }
            }
            else if (gvInventoryAdjustmentList.Rows.Count > 1) // if gridview has more than 1 item
            {
                for (int i = 1; i <= gvInventoryAdjustmentList.Rows.Count; i++)
                {
                    Label lbItemNumber = (Label)gvInventoryAdjustmentList.Rows[i].FindControl("lbItemNumber");
                    if (lbItemNumber.Text.Equals(ddlItemName.SelectedValue))
                    {
                        ArrayList        al  = (ArrayList)Session["AdjustmentDetails"];
                        AdjustmentInfoBO abo = new AdjustmentInfoBO();
                        abo.ItemNumber = ddlItemName.SelectedValue;
                        abo.ItemName   = ddlItemName.SelectedItem.Text;
                        abo.SupplierId = ddlSupplier.SelectedItem.Text;
                        int qty = Convert.ToInt32(tbQuantity.Text);
                        abo.QuantityAdjustment = qty;
                        abo.Uom    = tbUOM.Text.Trim();
                        abo.Reason = tbReason.Text.Trim();
                        double price = Convert.ToInt32(ddlSupplier.SelectedValue) * qty;
                        if (price < 0)
                        {
                            price = price * -1;
                        }
                        abo.Price = price.ToString();

                        al.RemoveAt(i);
                        al.Add(abo);
                        // process same as the condition above
                        gvInventoryAdjustmentList.DataSource = al;
                        gvInventoryAdjustmentList.DataBind();
                        //apply the footable settings
                        footableSettings();
                        break; // break the for loop if work is performed
                    }
                    else
                    {
                        addToGridView(); // at normal condition if no duplicate, do this
                    }
                }
            }
            ClearControls();
        }