protected void Page_Load(object sender, EventArgs e)
        {
            requisitionManager = new RequisitionManager();

            currentUser = Utilities.Membership.GetCurrentLoggedInUser();
            requisitions = requisitionManager.GetAllUnApprovedRequisitionByDepartmentID(currentUser.DepartmentID);
            if (requisitions != null)
            {
                GridView1.DataSource = requisitions;
                DataBind();
            }
            if (requisitions.Count == 0)
            {
                ApproveAllButton.Visible = false;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            requisitionManager = new RequisitionManager();
            UserManager u = new UserManager();

            requisitions = requisitionManager.GetAllUnApprovedRequisitionByDepartmentID(1);
            if (requisitions != null)
            {
                GridView1.DataSource = requisitions;
                DataBind();
            }
            if(requisitions.Count == 0)
            {
                Button1.Visible = false;
                Response.Write("No pending requests for approval.");
            }

               // ApproveSingleRequest();
        }
        protected void UpdateButton_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid) return;
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    for (int i = 0; i < this.DistributionGridView.Rows.Count; i++)
                    {
                        GridViewRow gridViewRow = DistributionGridView.Rows[i];
                        HiddenField IsSpecialHiddenField = gridViewRow.FindControl("IsSpecialHiddenField") as HiddenField;
                        HiddenField RequisitionIDHiddenField = gridViewRow.FindControl("RequisitionIDHiddenField") as HiddenField;
                        HiddenField StationeryIDHiddenField = gridViewRow.FindControl("StationeryIDHiddenField") as HiddenField;
                        HiddenField SpecialStationeryIDHiddenField =
                            gridViewRow.FindControl("SpecialStationeryIDHiddenField") as HiddenField;

                        HiddenField QuantityDisbursedHiddenField = gridViewRow.FindControl("QuantityDisbursedHiddenField") as HiddenField;
                        TextBox QuantityTextBox = gridViewRow.FindControl("QuantityTextBox") as TextBox;

                        bool isSpecial = Convert.ToBoolean(IsSpecialHiddenField.Value);
                        int RequisitionID = Convert.ToInt32(RequisitionIDHiddenField.Value);
                        int StationeryID = Convert.ToInt32(StationeryIDHiddenField.Value);
                        int SpecialStationeryID = Convert.ToInt32(SpecialStationeryIDHiddenField.Value);
                        int QuantityDisbursed = Convert.ToInt32(QuantityDisbursedHiddenField.Value);
                        int QuantityDistributed = Convert.ToInt32(QuantityTextBox.Text.Trim());

                        using (RequisitionManager rm = new RequisitionManager())
                        {
                            Requisition rq = rm.GetRequisitionByID(RequisitionID);

                            if (!isSpecial)
                            {
                                List<RequisitionItem> rqItems = (from item in rq.RequisitionItems
                                                                 where item.StationeryID == StationeryID
                                                                 select item).ToList();
                                for (int j = 0; j < rqItems.Count && QuantityDisbursed > 0; j++)
                                {
                                    RequisitionItem rqItem = rqItems[j];
                                    if (QuantityDisbursed > rqItem.QuantityRequested)
                                    {
                                        rqItem.QuantityIssued = rqItem.QuantityRequested;
                                        QuantityDisbursed = QuantityDisbursed - rqItem.QuantityRequested;
                                    }
                                    else if (QuantityDisbursed > 0)
                                    {
                                        rqItem.QuantityIssued = QuantityDisbursed;
                                        QuantityDisbursed = 0;
                                    }
                                }

                            }
                            else
                            {
                                List<SpecialRequisitionItem> srqItems = (from sitem in rq.SpecialRequisitionItems
                                                                         where sitem.SpecialStationeryID == SpecialStationeryID
                                                                         select sitem).ToList();
                                for (int j = 0; j < srqItems.Count && QuantityDisbursed > 0; j++)
                                {
                                    SpecialRequisitionItem srqItem = srqItems[j];
                                    if (QuantityDisbursed > srqItem.QuantityRequested)
                                    {
                                        srqItem.QuantityIssued = srqItem.QuantityRequested;
                                        QuantityDisbursed = QuantityDisbursed - srqItem.QuantityRequested;
                                    }
                                    else if (QuantityDisbursed > 0)
                                    {
                                        srqItem.QuantityIssued = QuantityDisbursed;
                                        QuantityDisbursed = 0;
                                    }
                                }
                            }
                            Status status = rm.GetStatusByName(new StatusSearchDTO() { Name = "Fulfilled" });
                            rq.Status = status;
                            rm.UpdateRequisition(rq);
                        }
                    }
                    using (DisbursementManager dm = new DisbursementManager())
                    {
                        Disbursement disbursement = dm.FindDisbursementByID(this.DisbursementId);
                        disbursement.IsDistributed = true;
                        dm.UpdateDisbursement(disbursement);
                    }
                    ts.Complete();
                }
                Response.Redirect("~/Distribution/Disbursements.aspx");
            }
            catch (Exception exception)
            {
                this.ErrorMessage.Text = exception.Message;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //Create instance of new requisition
            Requisition r = new Requisition();

            UserDAO user = new UserDAO();
            RequisitionManager rq = new RequisitionManager();
            CatalogDAO cat = new CatalogDAO();

            //set the properties of requisition object
            r.DepartmentID = user.GetDepartmentByID(1).DepartmentID;
            r.CreatedBy = user.GetUserByID(1).UserID;
            r.StatusID = rq.GetStatusByID(new Status() { StatusID = 1}).StatusID;
            r.ApprovedBy = user.GetUserByID(2).UserID;
            r.UrgencyID = rq.GetUrgencyByID(new Urgency() { UrgencyID = 1 }).UrgencyID;
            r.RequisitionForm = "test";
            r.DateRequested = DateTime.Now;
            //r.DateApproved = DateTime.Now;

            //Create a new requisitionitem for the current requisition
            RequisitionItem rqi = new RequisitionItem()
            {
                RequisitionID = r.RequisitionID,
                StationeryID = cat.GetAllStationeries().FirstOrDefault<Stationery>().StationeryID,
                QuantityRequested = 10,
                QuantityIssued = 10,
                Price = 5

            };

            //Create a new specialrequisitionitem for the current requisition
            SpecialRequisitionItem spi = new SpecialRequisitionItem()
            {
                RequisitionID = r.RequisitionID,
                SpecialStationeryID = 1,
                QuantityRequested = 10,
                QuantityIssued = 10,
                Price = 5,
                Name = "arav",
                Description = "test"

            };

            //Add Child objects of the requisition objects
            //Add requisitionitem to requisition object
            r.RequisitionItems.Add(rqi);

            //Add specialitem to requisition object
            r.SpecialRequisitionItems.Add(spi);

            //Persist requisition to database
            //EF is very intelligent. It will also persist to requistionitem and specialrequistionitem
            rq.CreateRequisition(r);

            r = rq.GetAllRequisition().Last<Requisition>();
            r.RequisitionItems.Last<RequisitionItem>().QuantityIssued = 6;

            rq.UpdateRequisition(r);

            spi = rq.GetAllSpecialRequisitionItems(r).Last<SpecialRequisitionItem>();

            rq.DeleteSpecialRequisitionItem(spi);

            //Testing databinding after creation of requisitions
            if (!IsPostBack)
            {
                GridView1.DataSource = rq.GetAllRequisitionItems(r);
                GridView1.DataBind();

                if (r != null)
                {
                    GridView2.DataSource = rq.GetAllRequisition();
                    GridView2.DataBind();
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            requisitionManager = new RequisitionManager();
            cManager = new CatalogManager();
            CancelButton.Visible = false;
            if (!IsPostBack)
            {
                UrgencyDDL.DataSource = requisitionManager.GetAllUrgencies();
                UrgencyDDL.DataTextField = "Name";
                UrgencyDDL.DataValueField = "UrgencyID";
                DataBind();

                foreach (ListItem item in UrgencyDDL.Items)
                {
                    if (item.Text == "Normal")
                    {
                        item.Selected = true;
                    }
                }
                requisition = CreateRequisition();
                Session["Requisition"] = requisition;
            }

            if (Session["Requisition"] != null)
            {
                requisition = (Requisition)Session["Requisition"];
            }

            string key = string.Empty;
            int val = 0;
            NameValueCollection nv = Request.QueryString;
            if (nv.HasKeys())
            {
                key = nv.GetKey(0);
                try
                {
                    val = Convert.ToInt32(nv.Get(0));
                }
                catch (Exception)
                {

                }

            }
            if (key == "RequestID" && val > 0)
            {
                requisition = requisitionManager.GetRequisitionByID(val);

                if (requisition != null)
                {
                    Panel1.Visible = false;
                    Panel2.Visible = false;
                    RequestItemGridView.Columns[0].Visible = false;
                    RequestItemGridView.Columns[1].Visible = false;
                    SpecialRequestItemGridView.Columns[0].Visible = false;
                    Panel4.Visible = false;
                    SubmitButton.Visible = false;
                    if (requisition.Status.Name == "Pending")
                    {
                        CancelButton.Visible = true;
                    }
                    GridDataBind();
                }
            }
        }