Exemplo n.º 1
0
    protected void BtnAddItem_Click(object sender, EventArgs e)
    {
        //To add an item that is not under reorderLevel and append it to the gvPurchaseItems List
        String itemCode = ddlAddNewItem.SelectedItem.Value;

        int count = 1;

        if (Session["ReorderItem"] != null)
        {
            List <ItemPrice> itemPriceList;
            ritems = (List <ReorderItem>)Session["ReorderItem"];
            if (ritems.Exists(x => x.ItemCode == itemCode))
            {
                itemPriceList = pCtrlr.GetItemPriceList().Where(x => x.ItemCode == itemCode).ToList();
                for (int i = 0; i < GvreorderItems.Rows.Count; i++)
                {
                    GridViewRow gvRow = GvreorderItems.Rows[i];

                    Label  codeLbl = (Label)gvRow.FindControl("lblItemCode");
                    string codeNo  = codeLbl.Text;
                    //To check if an item with same supplier is already added. if exist,then item with 2nd supplier will be added .
                    if (codeNo == itemCode)
                    {
                        DropDownList splrControl = (DropDownList)gvRow.FindControl("ddlSupplierList");
                        //ListItem item = splrControl.SelectedItem;
                        count++;
                        //exisitingItemsupplrName = item.Value;

                        //break;
                    }
                    else
                    {
                        continue;
                    }
                }
                if (itemPriceList.Count >= count)
                {
                    ritems.Add(pCtrlr.AddPurchaseItem(itemCode));
                    GvreorderItems.DataSource = ritems;
                    Session["ReorderItem"]    = ritems;
                    GvreorderItems.DataBind();
                    ClientScript.RegisterStartupScript(Page.GetType(), "MessageBox",
                                                       "<script language='javascript'>alert('" + "Item Added!" + "');</script>");
                }
                else
                {
                    ClientScript.RegisterStartupScript(Page.GetType(), "MessageBox",
                                                       "<script language='javascript'>alert('" + "Item already added with all existing suppliers!" + "');</script>");
                }
            }
            else
            {
                ritems.Add(pCtrlr.AddPurchaseItem(itemCode));
                GvreorderItems.DataSource = ritems;
                Session["ReorderItem"]    = ritems;
                GvreorderItems.DataBind();
                ClientScript.RegisterStartupScript(Page.GetType(), "MessageBox",
                                                   "<script language='javascript'>alert('" + "Item Added!" + "');</script>");
            }
        }
    }