Exemplo n.º 1
0
    protected void BtnProceed_Click(object sender, EventArgs e)

    {
        if (Page.IsValid)
        {
            Dictionary <PurchaseOrder, List <Item_PurchaseOrder> > purchaseItemList = new Dictionary <PurchaseOrder, List <Item_PurchaseOrder> >(pComparer);

            for (int i = 0; i < GvreorderItems.Rows.Count; i++)
            {
                PurchaseOrder pOrder = new PurchaseOrder();

                GridViewRow gvRow = GvreorderItems.Rows[i];
                if (((CheckBox)gvRow.FindControl("CbxItem")).Checked)
                {
                    DropDownList splrControl = (DropDownList)gvRow.FindControl("ddlSupplierList");
                    ListItem     suplierInfo = splrControl.SelectedItem;
                    pOrder.SupplierCode = suplierInfo.Value;
                    Label amntlbl = (Label)gvRow.FindControl("lblAmount");
                    if (!purchaseItemList.ContainsKey(pOrder))
                    {
                        pOrder.OrderDate    = DateTime.Now.Date;
                        pOrder.ApprovedBy   = Convert.ToInt32(ddlsupervisorNames.SelectedItem.Value);
                        pOrder.ExpectedDate = DateTime.ParseExact(txtDate.Text, "d", CultureInfo.InvariantCulture);
                        pOrder.Status       = "Pending";

                        pOrder.TotalAmount += decimal.Parse(amntlbl.Text, System.Globalization.NumberStyles.Currency);
                        pOrder.RequestedBy  = (int)Session["empID"];
                        purchaseItemList.Add(pOrder, null);
                    }

                    Item_PurchaseOrder pItems = new Item_PurchaseOrder();
                    Label itemlbl             = (Label)gvRow.FindControl("lblItemCode");
                    pItems.ItemCode        = itemlbl.Text;
                    pItems.PurchaseOrderID = pOrder.PurchaseOrderID;
                    TextBox qtyTxtBx = (TextBox)gvRow.FindControl("txtReorderQty");
                    pItems.OrderQty = Convert.ToInt32(qtyTxtBx.Text);
                    Label priceLbl = (Label)gvRow.FindControl("lblPrice");
                    pItems.ItemCode = itemlbl.Text;
                    pItems.Amount   = pItems.OrderQty * decimal.Parse(priceLbl.Text, System.Globalization.NumberStyles.Currency);

                    List <Item_PurchaseOrder> ItemList = null;
                    if (purchaseItemList[pOrder] != null)
                    {
                        ItemList = purchaseItemList[pOrder];
                        ItemList.Add(pItems);
                        purchaseItemList[pOrder] = ItemList;
                    }
                    else
                    {
                        ItemList = new List <Item_PurchaseOrder>();
                        ItemList.Add(pItems);
                        purchaseItemList[pOrder] = ItemList;
                    }
                }
            }
            if (purchaseItemList.Count == 0)
            {
                ClientScript.RegisterStartupScript(Page.GetType(), "MessageBox",
                                                   "<script language='javascript'>alert('" + "Please select items first!" + "');</script>");
            }
            else
            {
                pCtrlr.AddPurchaseOrder(purchaseItemList);
                Session["ReorderItem"] = null;
                ClientScript.RegisterStartupScript(Page.GetType(), "MessageBox",
                                                   "<script language='javascript'>alert('" + "Purchase Done, Awaiting Approval!" + "');</script>");
                Response.Redirect(LoginController.PurchaseOrderListURI);
            }
        }
    }