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); } } } }
//DU Info public Int64 CalculateDUAMC(int itemId, int receivingUnit, int month, int year, int LastSOH) { GeneralInfo info = new GeneralInfo(); info.LoadAll(); int range = 3; try { range = info.DUAMCRange; } catch { } Int64 cons = 0; IssueDoc iss = new IssueDoc(); int yr = (month > 10) ? year + 1 : year; DateTime dt1 = new DateTime(yr, month, DateTime.DaysInMonth(yr, month)); DateTime dt2 = dt1.AddMonths(-range); int mon = dt2.Month; range = iss.GetAvailableNoOfMonthsDU(itemId, receivingUnit, dt2, dt1); yr = (mon > 10) ? year + 1 : year; cons = iss.GetDUConsumptionAfterMonth(itemId, receivingUnit, mon, yr); //for (int m = mon+1; m < month; m++ ) //{ // yr = (m > 10) ? year - 1 : year; // cons = cons + iss.GetDUConsumptionByMonth(itemId, receivingUnit, m, yr); //} yr = (month > 10) ? year + 1 : year; //yr = (month > 10) ? year : year + 1 ; //Int64 lastIss = iss.GetDUIssueByMonth(itemId, receivingUnit, month, yr); Int64 lastIss = iss.GetDULastIssueQty(itemId, receivingUnit); // lastIss = ((lastIss > 0)? (lastIss - LastSOH) : lastIss ); cons = cons + lastIss - LastSOH; //cons = cons - LastSOH; cons = ((cons > 0) ? cons : 0); Int64 AMC = cons / range; return AMC; }