public void PopulateItemListByMonth(DataTable dtItem,int month,int year) { progressBar1.Visible = true; progressBar1.Minimum = 1; progressBar1.Value = 1; progressBar1.Maximum = dtItem.Rows.Count; GeneralInfo pipline = new GeneralInfo(); pipline.LoadAll(); int min = pipline.Min; int max = pipline.Max; double eop = pipline.EOP; int storeId = (cboStores.SelectedValue != null)?Convert.ToInt32(cboStores.SelectedValue):1; lstItem.Items.Clear(); dtDate.Value = DateTime.Now; dtDate.CustomFormat = "MM/dd/yyyy"; DateTime dtCurrent = new DateTime();// Convert.ToDateTime(dtDate.Text); try { dtCurrent = Convert.ToDateTime(dtDate.Text); } catch { string dtValid = ""; string yer = ""; if (Convert.ToInt32(dtDate.Text.Substring(0, 2)) == 13) { dtValid = dtDate.Text; yer = dtValid.Substring(dtValid.Length - 4, 4); dtCurrent = Convert.ToDateTime("12/30/" + yer); } else if (Convert.ToInt32(dtDate.Text.Substring(0, 2)) == 2) { dtValid = dtDate.Text; yer = dtValid.Substring(dtValid.Length - 4, 4); dtCurrent = Convert.ToDateTime("2/28/" + yer); } } month = (month < 11)? month +2: ((month ==11)?1:2); int yyr = (month < 11)? dtCurrent.Year: dtCurrent.Year -1; int count = 1; Balance bal = new Balance(); IssueDoc iss = new IssueDoc(); foreach (DataRow dr in dtItem.Rows) { string itemName = dr["ItemName"].ToString() + " - " + dr["DosageForm"].ToString() + " - " + dr["Strength"].ToString(); int yer = (month < 11) ? year : year - 1; double AMC = Builder.CalculateAverageConsumption(Convert.ToInt32(dr["ID"]), storeId,dtCurrent.Subtract(TimeSpan.FromDays(180)),dtCurrent,CalculationOptions.Monthly);//bal.CalculateAMC(Convert.ToInt32(dr["ID"]), storeId, month, yer); double MinCon = AMC * min; double maxCon = AMC * max; double eopCon = AMC * (eop + 0.25); Int64 SOH = bal.GetSOH(Convert.ToInt32(dr["ID"]), storeId, month, yer); decimal MOS = (AMC != 0) ? (Convert.ToDecimal(SOH) / Convert.ToDecimal(AMC)) : 0; MOS = Decimal.Round(MOS, 1); double reorder = (maxCon > SOH) ? maxCon - SOH : 0; string status = (SOH <= eopCon && SOH > 0) ? "Near EOP" : ((SOH > maxCon && maxCon != 0) ? "Excess Stock" : ((SOH <= 0) ? "Stock Out" : "Normal")); //Int64 issuedQuant = iss.GetIssuedQuantityByMonth(Convert.ToInt32(dr["ID"]),storeId, month,yer); Int64 issuedQuant = iss.GetIssuedQuantity(Convert.ToInt32(dr["ID"]), storeId, yer); string[] str = { count.ToString(), itemName, ((SOH != 0)?SOH.ToString("#,###"): "0"), ((AMC != 0)?AMC.ToString("#,###"):"0"), MOS.ToString(), ((MinCon != 0)?MinCon.ToString("#,###"): "0"), ((maxCon != 0)?maxCon.ToString("#,###"):"0"), ((issuedQuant!= 0)?issuedQuant.ToString("#,###"):"0"), status, ((reorder!= 0)?reorder.ToString("#,###"):"0") }; ListViewItem listItem = new ListViewItem(str); listItem.Tag = dr["ID"]; //if (col != 0) //{ // listItem.BackColor = Color.FromArgb(233, 247, 248); // col = 0; //} //else //{ // col++; //} string stat = ""; if(cboStatus.SelectedItem != null) stat = cboStatus.SelectedItem.ToString(); switch (stat) { case "Near EOP": if (SOH <= eopCon && SOH > 0) { listItem.BackColor = Color.FromArgb(255, 255, 153); lstItem.Items.Add(listItem); count++; } break; case "Normal": if (SOH > eopCon && SOH < maxCon) { lstItem.Items.Add(listItem); count++; } break; case "Stock Out": if (SOH <= 0) { listItem.BackColor = Color.FromArgb(246, 168, 168); lstItem.Items.Add(listItem); count++; } break; case "Excess Stock": if (SOH > maxCon && maxCon != 0) { listItem.BackColor = Color.FromArgb(163, 209, 255); lstItem.Items.Add(listItem); count++; } break; default: if (SOH <= eopCon && SOH > 0) listItem.BackColor = Color.FromArgb(255, 255, 153); else if (SOH > maxCon && maxCon != 0) listItem.BackColor = Color.FromArgb(163, 209, 255); else if (SOH <= 0) listItem.BackColor = Color.FromArgb(246, 168, 168); lstItem.Items.Add(listItem); count++; break; } progressBar1.PerformStep(); } progressBar1.Visible = false; }