示例#1
0
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Label   id    = GridView1.Rows[e.RowIndex].FindControl("lblDepOrdId") as Label;
        TextBox rtQty = GridView1.Rows[e.RowIndex].FindControl("txt_rtQty") as TextBox;

        int depOrdId   = Int32.Parse(id.Text);
        int qtyUpdated = Int32.Parse(rtQty.Text);

        Department_Orders depOrd = ent.Department_Orders.Where(x => x.Department_Orders_ID == depOrdId).First();

        depOrd.Return_Quantity = qtyUpdated;
        ent.SaveChanges();

        GridView1.EditIndex = -1;
        bindData();
    }
    protected void btnApprove_Click(object sender, EventArgs e)
    {
        Department_Orders      depOrder;
        string                 itemID;
        SSISEntities           model    = new SSISEntities();
        Stationery_Requisition reqToAdd = model.Stationery_Requisition.Where(x => x.Requisition_ID == id).First();
        Employee               emp      = model.Employees.Where(x => x.Id == reqToAdd.User_ID).First();
        string                 depId    = model.Departments.Where(x => x.Department_ID == emp.Department_ID).Select(x => x.Department_ID).First();

        foreach (Requisition_Items req in reqToAdd.Requisition_Items)
        {
            itemID = req.Item_ID;
            var result = model.Department_Orders.Where(x => x.Item_ID == itemID && x.Department_ID == depId).SingleOrDefault();

            if (result == null)
            {
                Department_Orders deptOrder = new Department_Orders();
                deptOrder.Department_ID        = depId;
                deptOrder.Item_ID              = itemID;
                deptOrder.Requisition_Date     = reqToAdd.Requisition_Date;
                deptOrder.Requisition_Quantity = req.Quantity;
                deptOrder.Fulfilled_Quantity   = 0;
                deptOrder.IOU_Quantity         = 0;
                deptOrder.Return_Quantity      = 0;
                model.Department_Orders.Add(deptOrder);

                //reqToAdd.Status = "Processed";
                model.SaveChanges();
                //string script = "alert('Successfully Added to Retriveal List');";
                //ClientScript.RegisterClientScriptBlock(this.GetType(), "Successfully Added to Retriveal List", script, true);
            }
            else
            {
                depOrder = result;
                depOrder.Requisition_Quantity = depOrder.Requisition_Quantity + req.Quantity;
                model.SaveChanges();
            }


            Response.Redirect("~/com.ssis.storeclerk/Store_ListofRequisitionForms.aspx");
        }
    }
    protected void GridView2_AddRetrievalList(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "addRetrievalList")
        {
            String      rowindex = e.CommandArgument.ToString();
            GridViewRow row      = GridView2.Rows[Convert.ToInt32(rowindex)];



            // int rowindex = ((sender as Button).namingcontainer as gridviewrow).rowindex;
            string description    = row.Cells[0].Text;
            string departmentname = row.Cells[1].Text;
            int    iouquantity    = Int32.Parse(row.Cells[2].Text);


            DateTime now  = DateTime.Now;
            DateTime date = now.Date;


            string itemNumber = ssis.Stationery_Catalogue.Where(x => x.Description == description).Select(x => x.Item_Number).FirstOrDefault().ToString();

            string depID = ssis.IOUs.Where(x => x.Item_Number == itemNumber).Select(x => x.Department_ID).FirstOrDefault();

            Department_Orders depOrdSelected = ssis.Department_Orders.Where(x => x.Department_ID == depID && x.Item_ID == itemNumber).FirstOrDefault();

            //string iouID = ssis.IOUs.Where(p => p.Item_Number == itemNumber && p.Department_ID == depID && p.Status == "'Processed'").Select(x=>x.IOU_ID).FirstOrDefault();

            IOU iou = ssis.IOUs.Where(p => p.Item_Number == itemNumber && p.Department_ID == depID && p.Status == "Unprocess").First <IOU>();
            if (depOrdSelected != null)
            {
                string   deptOrderID          = depOrdSelected.Department_ID;
                string   deptOrderIouNum      = depOrdSelected.Item_ID;
                int      deptOrderIouQuantity = (int)depOrdSelected.IOU_Quantity;
                DateTime deptDate             = (DateTime)depOrdSelected.Requisition_Date;
                //  int different = Int32.Parse( date - deptDate).ToString();
                int dateDept = (date - deptDate).Days;
                //DateTime deD= DateTime.Now.Date.AddDays(-7);
                if (depID == deptOrderID && deptOrderIouNum == itemNumber && dateDept < 3)
                {
                    iouquantity += deptOrderIouQuantity;
                    Department_Orders selectedDepOrd = ssis.Department_Orders.Where(x => x.Department_ID == depID && x.Item_ID == itemNumber).First <Department_Orders>();
                    selectedDepOrd.IOU_Quantity = iouquantity;
                    ssis.SaveChanges();
                }
                else
                {
                    Department_Orders deptOrder = new Department_Orders
                    {
                        Department_ID        = depID,
                        Item_ID              = itemNumber,
                        Requisition_Date     = date,
                        Requisition_Quantity = 0,
                        Fulfilled_Quantity   = 0,
                        IOU_Quantity         = iouquantity,
                        Return_Quantity      = 0
                    };

                    ssis.Department_Orders.Add(deptOrder);
                    ssis.SaveChanges();
                }
            }
            else
            {
                Department_Orders deptOrder = new Department_Orders
                {
                    Department_ID        = depID,
                    Item_ID              = itemNumber,
                    Requisition_Date     = date,
                    Requisition_Quantity = 0,
                    Fulfilled_Quantity   = 0,
                    IOU_Quantity         = iouquantity,
                    Return_Quantity      = 0
                };

                ssis.Department_Orders.Add(deptOrder);
                ssis.SaveChanges();
            }

            iou.Status = "Processed";
            ssis.SaveChanges();

            Response.Redirect("~/com.ssis.storeclerk/Store_ListofRequisitionForms.aspx");
        }
    }