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) { 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(); } } }