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 UpdateButton_Click(object sender, EventArgs e)
        {
            try
            {
                AdjustmentVoucherTransaction adjustmentVoucher = new AdjustmentVoucherTransaction();
                for (int i = 0; i < DisbursementGridView.Rows.Count; i++)
                {
                    GridViewRow gridViewRow = DisbursementGridView.Rows[i];
                    int disbursementItemID = (int)DisbursementGridView.DataKeys[gridViewRow.RowIndex].Value;
                    DisbursementItem item = null;
                    using (DisbursementManager dm = new DisbursementManager())
                    {
                        item = dm.FindDisbursementItemByID(disbursementItemID);
                    }

                    if (item != null && item.QuantityDamaged > 0)
                    {
                        Stationery stationery = item.Stationery;

                        StockLogTransaction adj = new StockLogTransaction();
                        adj.Reason = item.Reason;
                        adj.Quantity = item.QuantityDamaged ?? 0;

                        if (item.StationeryID != null && item.StationeryID > 0)
                        {
                            adj.StationeryID = item.StationeryID;
                            StationeryPrice price = stationery.StationeryPrices.First();
                            adj.Price = price.Price;
                            adj.Balance = stationery.QuantityInHand;
                        }
                        else
                        {
                            adj.SpecialStationeryID = item.SpecialStationeryID;
                            adj.Price = 0.0m;
                            adj.Balance = 0;
                        }

                        adj.DateCreated = DateTime.Now;
                        adj.Type = (int)AdjustmentType.Damage;
                        adjustmentVoucher.StockLogTransactions.Add(adj);
                    }
                    if (adjustmentVoucher.StockLogTransactions.Count > 0)
                    {
                        using (TransactionScope ts = new TransactionScope())
                        {
                            using (AdjustmentVoucherManager avm = new AdjustmentVoucherManager())
                            {
                                adjustmentVoucher.VoucherNumber = avm.GenerateVoucherNumber();
                                adjustmentVoucher.DateIssued = DateTime.Now;
                                adjustmentVoucher.CreatedBy = Utilities.Membership.LoggedInuser.UserID;
                                avm.CreateAdjustmentVoucherTransaction(adjustmentVoucher);
                            }
                            using (DisbursementManager dm = new DisbursementManager())
                            {
                                DAL.Disbursement disbursement = dm.FindDisbursementByID(this.DisbursementId);
                                disbursement.IsDistributed = true;
                                dm.UpdateDisbursement(disbursement);
                            }
                            ts.Complete();
                        }
                        Response.Redirect("~/HandleRequest/Disbursements.aspx");
                    }
                    else
                    {
                        using (TransactionScope ts = new TransactionScope())
                        {
                            using (DisbursementManager dm = new DisbursementManager())
                            {
                                DAL.Disbursement disbursement = dm.FindDisbursementByID(this.DisbursementId);
                                disbursement.IsCompleted = true;
                                dm.UpdateDisbursement(disbursement);
                            }
                            ts.Complete();
                        }
                        Response.Redirect("~/HandleRequest/Disbursements.aspx");
                    }
                }
            }
            catch (Exception exception)
            {
                this.ErrorMessage.Text = exception.Message;
            }
        }