private void cboReceivingUnits_SelectedValueChanged(object sender, EventArgs e) { DataTable issGrid = (DataTable)issueGrid.DataSource; if (issGrid != null) { if (cboReceivingUnits.EditValue != null && issGrid.Rows.Count > 0) { DateTime xx = dtIssueDate.Value; dtIssueDate.Value = DateTime.Now; dtIssueDate.CustomFormat = "MM/dd/yyyy"; DateTime dtCurrent = ConvertDate.DateConverter(dtIssueDate.Text); dtIssueDate.Value = xx; var iss = new IssueDoc(); var bal = new Balance(); int receivingUnit = Convert.ToInt32(cboReceivingUnits.EditValue); var DUs = new ReceivingUnits(); DUs.LoadByPrimaryKey(receivingUnit); double dumax = 0.5; try { dumax = DUs.Max; } catch(Exception EX) { } for (int i = 0; i < issGrid.Rows.Count; i++) { int itmId = Convert.ToInt32(issGrid.Rows[i]["ID"]); int lastIssueQty = iss.GetDULastIssueQty(itmId, receivingUnit); int lastDUSOH = iss.GetDULastSOH(itmId, receivingUnit); issGrid.Rows[i]["MR Issue Qty"] = lastIssueQty; issGrid.Rows[i]["MR DU SOH"] = lastDUSOH; const int lstSOH = 0; issGrid.Rows[i]["DU Remaining SOH"] = 0; int yer = (dtCurrent.Month < 11) ? dtCurrent.Year : dtCurrent.Year - 1; Int64 duAmc = bal.CalculateDUAMC(itmId, receivingUnit, dtCurrent.Month, dtCurrent.Year, lstSOH); issGrid.Rows[i]["DU AMC"] = duAmc; double recQty = (duAmc * dumax) - Convert.ToInt32(issGrid.Rows[i]["DU Remaining SOH"]); issGrid.Rows[i]["Recommended Qty"] = ((recQty > 0) ? Convert.ToInt64(recQty) : 0); } } } }