private void LoadData()
    {
        //To populate Items dropDown List
        ddlAddNewItem.DataSource     = EFBroker_Item.GetActiveItemWithPrice();
        ddlAddNewItem.DataTextField  = "Description";
        ddlAddNewItem.DataValueField = "ItemCode";
        ddlAddNewItem.DataBind();

        //To populate Supervisor Name dropdown List
        ddlsupervisorNames.DataSource     = pCtrlr.GetSupervisorList();
        ddlsupervisorNames.DataTextField  = "EmpName";
        ddlsupervisorNames.DataValueField = "EmpID";
        ddlsupervisorNames.DataBind();


        if (Session["ReorderItem"] != null)
        {
            ritems = (List <ReorderItem>)Session["ReorderItem"];
            GvreorderItems.DataSource = ritems;
            GvreorderItems.DataBind();
        }
        else
        {
            //To add PurchaseItems to session if session is empty
            ritems = pCtrlr.GetReorderItemList();
            Session["ReorderItem"]    = ritems;
            GvreorderItems.DataSource = ritems;
            GvreorderItems.DataBind();
        }
    }
 protected void BtnReset_Click(object sender, EventArgs e)
 {
     //Update reorderItemList ie. gvPurchaseItems
     ritems = pCtrlr.GetReorderItemList();
     Session["ReorderItem"]    = ritems;
     GvreorderItems.DataSource = ritems;
     GvreorderItems.DataBind();
     txtDate.Text = "";
     ddlsupervisorNames.SelectedIndex = 0;
     ddlAddNewItem.SelectedIndex      = 0;
     ClientScript.RegisterStartupScript(Page.GetType(), "MessageBox",
                                        "<script language='javascript'>alert('" + "Reset done" + "');</script>");
 }
    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>");
            }
        }
    }