public DataTable OverStockedItems(int storeId, int year, int month, string selectedType, BackgroundWorker bw) { DataTable dtBal = new DataTable(); GeneralInfo pipline = new GeneralInfo(); Items itm = new Items(); Balance bal = new Balance(); IssueDoc iss = new IssueDoc(); ReceiveDoc rec = new ReceiveDoc(); string[] str = { "FullItemName", "SOH", "AMC", "MOS", "Min", "Max", "ExcessQty", "ExcessAmount", "CategoryId", "SubCategoryID", "ID" }; foreach (string s in str) { dtBal.Columns.Add(s); } pipline.LoadAll(); int min = pipline.Min; int max = pipline.Max; double eop = pipline.EOP; DataTable dtItem = new DataTable(); dtItem = ((selectedType == "Drug") ? itm.GetAllItems(1) : itm.GetAllSupply()); int i = 1; foreach (DataRow dr in dtItem.Rows) { string itemName = dr["FullItemName"].ToString(); int yer = (month < 11) ? year : year - 1; Int64 AMC = bal.CalculateAMC(Convert.ToInt32(dr["ID"]), storeId, month, yer); Int64 MinCon = AMC * min; Int64 maxCon = AMC * max; Int64 SOH = bal.GetSOH(Convert.ToInt32(dr["ID"]), storeId, month, yer); if (SOH > maxCon) { decimal MOS = (AMC != 0) ? (Convert.ToDecimal(SOH) / Convert.ToDecimal(AMC)) : 0; MOS = Decimal.Round(MOS, 1); Int64 excessQty = SOH - maxCon; double price = rec.GetLastReceivedCost(Convert.ToInt32(dr["ID"]), storeId); double excessAmount = price * excessQty; object[] obj = { itemName, SOH, AMC, MOS, MinCon, maxCon, excessQty, excessAmount, Convert.ToInt32(dr["CategoryId"]), Convert.ToInt32(dr["SubCategoryID"]), Convert.ToInt32(dr["ID"]) }; dtBal.Rows.Add(obj); } bw.ReportProgress(Convert.ToInt32((Convert.ToDouble(i++) / dtItem.Rows.Count) * 100)); } return dtBal; }