using MESClassLibrary.BLL.Log; using MESClassLibrary.DAL.Injection; using MESClassLibrary.EFModel; using MESClassLibrary.Model; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace MESClassLibrary.BLL.Injection { public class InjectionRecordBLL { BBMPTEntities ef = new BBMPTEntities(); BasicBLL db = new BasicBLL(); BasicBLL db_w = new BasicBLL(); InjectionRecordDAL dal = new InjectionRecordDAL(); /// /// 新增信息 /// /// /// public bool AddInfo(tb_Injection_Record md) { try { var list = db.SearchInfoByKey("RecordDate", md.RecordDate);//判断是否有重复数据 if (list != null && list.Count > 0) { if (list.Where(p => p.StationID.Equals(md.StationID) && p.workClass.Equals(md.workClass)).Count() > 0) { return false; } } return db.AddInfo(md); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 修改信息 /// /// /// public bool UpdateInfo(tb_Injection_Record md) { try { //初始化要更新的字段 string[] proNames = new string[7]; proNames[0] = "workClass"; proNames[1] = "StationID"; proNames[2] = "JK_Weight"; proNames[3] = "Waste_Weight"; proNames[4] = "RecordDate"; proNames[5] = "StockNo"; proNames[6] = "PartNo"; //必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化 //如果没有初始化必填字段,更新会报错 return db.UpdateInfo(md, proNames); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 删除信息 /// /// /// /// public bool DeleteInfo(tb_Injection_Record md) { try { return db.DelInfo(md); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 查询全部信息分页 /// /// public string SearchInfoAll(string page, string pagesize, string StartTime, string EndTime, string StationID) { try { string jsonStr = "[]"; int total = 0;//总行数 DateTime stime = Convert.ToDateTime(StartTime); DateTime etime = Convert.ToDateTime(EndTime); List list = ef.tb_Injection_Record.Where(p => p.RecordDate >= stime && p.RecordDate <= etime).ToList(); if (!String.IsNullOrEmpty(StationID)) { list = list.Where(p => p.StationID.Equals(StationID)).ToList(); } List modelList = new List(); if (list.Count > 0) { #region 联查 BasicBLL machine_db = new BasicBLL(); var machine_list = machine_db.SearchAllInfo(); foreach (var item in list) { Injection_RecordModel dm = Tool.Mapper(item); var machine_info = machine_list.FirstOrDefault(p => p.StationID == item.StationID); if (machine_info != null) { dm.StationNo = machine_info.StationNo; } modelList.Add(dm); } #endregion total = modelList.Count; int Skipcount = (Convert.ToInt32(page) - 1) * Convert.ToInt32(pagesize); modelList = modelList.Skip(Skipcount).Take(Convert.ToInt32(pagesize)).ToList(); JsonDataModel md = new JsonDataModel(); md.total = total.ToString(); md.rows = modelList; jsonStr = JSONTools.ScriptSerialize>(md); } return jsonStr; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } #region 废料信息录入 public string SearchInfo(string page, string pagesize, string StartTime, string EndTime, string StationID) { try { string jsonStr = "[]"; int total = 0;//总行数 DateTime stime = Convert.ToDateTime(StartTime); DateTime etime = Convert.ToDateTime(EndTime); DataTable dt = dal.SearchRecordByPage(Convert.ToInt32(page), Convert.ToInt32(pagesize), StartTime, EndTime, StationID); IList list = Tool.ConvertTo(dt); if (list.Count > 0) { total = list.Count; JsonDataModel md = new JsonDataModel(); md.total = total.ToString(); md.rows = list.ToList(); jsonStr = JSONTools.ScriptSerialize(md); } return jsonStr; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public bool UpdateWasteInfo(tb_Product_Injection_w md) { try { var info = ef.tb_Product_Injection_w.Where(p => p.ID.Equals(md.ID)).FirstOrDefault();//判断是否有重复数据 if (info != null) { //初始化要更新的字段 string[] proNames = new string[3]; proNames[0] = "RealCycle"; proNames[1] = "JK_Weight"; proNames[2] = "Waste_Weight"; //必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化 //如果没有初始化必填字段,更新会报错 db_w.UpdateInfo(md, proNames); } else { db_w.AddInfo(md); } return true; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } #endregion /// /// 查询全部信息 /// /// public List SearchAll() { try { var s_list = db.SearchAllInfo().ToList(); return s_list; } catch (Exception) { return null; } } /// /// 根据ID查询信息 /// /// /// public tb_Injection_Record SearchInfoByID(string id) { try { return db.SearchInfoByID(id); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } #region 日合格趋势 //表格 public string SearchQualifiedDay(string StartTime) { try { DateTime sTime = Convert.ToDateTime(StartTime); int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(sTime.Year, sTime.Month); StringBuilder sb = new StringBuilder(100); DataTable dt = dal.SearchByTime(Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-01").ToString("yyyy-MM-dd"), Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + days.ToString()).ToString("yyyy-MM-dd")); if (dt != null && dt.Rows.Count > 0) { List titleList = new List(); List totalList = new List(); List No_totalList = new List(); List OK_L_List = new List(); for (int i = 0; i < days; i++) { titleList.Add((i + 1) + "日"); string nowTime = Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + (i + 1)).ToString("yyyy-MM-dd"); var DayList = from myRow in dt.AsEnumerable() where myRow.Field(3) == nowTime select myRow; double total_OK = DayList.Sum(p => (int)p.ItemArray[7]); double total_NO = DayList.Sum(p => (int)p.ItemArray[8]); double total_all = total_OK + total_NO; totalList.Add(total_OK); No_totalList.Add(total_NO); if (total_all > 0) { OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2)); } else { OK_L_List.Add(0); } } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in titleList) { sb.Append(""); } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in totalList) { sb.Append(""); } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in No_totalList) { sb.Append(""); } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in OK_L_List) { sb.Append(""); } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in OK_L_List) { sb.Append(""); } sb.Append(""); sb.Append("
" + item + "
总合格数量" + item + "
不良数量" + item + "
合格率" + item + "%
目标值99.6%
"); } return sb.ToString(); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } //柱状图 public EcharBarModel SearchQualifiedDayBar(string StartTime) { try { EcharBarModel md = new EcharBarModel(); DateTime sTime = Convert.ToDateTime(StartTime); int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(sTime.Year, sTime.Month); StringBuilder sb = new StringBuilder(100); DataTable dt = dal.SearchByTime(Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-01").ToString("yyyy-MM-dd"), Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + days.ToString()).ToString("yyyy-MM-dd")); if (dt != null && dt.Rows.Count > 0) { List titleList = new List(); List totalList = new List(); List No_totalList = new List(); List OK_L_List = new List(); List T_L_List = new List(); for (int i = 0; i < days; i++) { titleList.Add((i + 1) + "日"); string nowTime = Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + (i + 1)).ToString("yyyy-MM-dd"); var DayList = from myRow in dt.AsEnumerable() where myRow.Field(3) == nowTime select myRow; double total_OK = DayList.Sum(p => (int)p.ItemArray[7]); double total_NO = DayList.Sum(p => (int)p.ItemArray[8]); double total_all = total_OK + total_NO; totalList.Add(total_OK); No_totalList.Add(total_NO); if (total_all > 0) { OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2)); } else { OK_L_List.Add(0); } } foreach (var item in OK_L_List) { T_L_List.Add(99.6); } md.categories = titleList; md.QualifiedData = OK_L_List; md.TargetData = T_L_List; } return md; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public List> SearchQualifiedDayForExcel(string StartTime) { try { List> list = new List>(); DateTime sTime = Convert.ToDateTime(StartTime); int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(sTime.Year, sTime.Month); StringBuilder sb = new StringBuilder(100); DataTable dt = dal.SearchByTime(Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-01").ToString("yyyy-MM-dd"), Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + days.ToString()).ToString("yyyy-MM-dd")); if (dt != null && dt.Rows.Count > 0) { List titleList = new List(); List totalList = new List(); List No_totalList = new List(); List OK_L_List = new List(); for (int i = 0; i < days; i++) { titleList.Add((i + 1) + "日"); string nowTime = Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + (i + 1)).ToString("yyyy-MM-dd"); var DayList = from myRow in dt.AsEnumerable() where myRow.Field(3) == nowTime select myRow; double total_OK = DayList.Sum(p => (int)p.ItemArray[7]); double total_NO = DayList.Sum(p => (int)p.ItemArray[8]); double total_all = total_OK + total_NO; totalList.Add(total_OK); No_totalList.Add(total_NO); if (total_all > 0) { OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2)); } else { OK_L_List.Add(0); } } List title_ = new List(); title_.Add(""); title_.AddRange(titleList); list.Add(title_); List total_ = new List(); total_.Add("总合格数量"); foreach (var item in totalList) { total_.Add(item.ToString()); } list.Add(total_); List No_total_ = new List(); No_total_.Add("不良数量"); foreach (var item in No_totalList) { No_total_.Add(item.ToString()); } list.Add(No_total_); List OK_L_ = new List(); OK_L_.Add("合格率"); foreach (var item in OK_L_List) { OK_L_.Add(item.ToString() + "%"); } list.Add(OK_L_); List tag_L_ = new List(); tag_L_.Add("目标值"); foreach (var item in OK_L_List) { tag_L_.Add("99.6%"); } list.Add(tag_L_); } return list; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } #endregion #region 月合格趋势 //表格 public string SearchQualifiedMonth(string StartTime) { try { DateTime sTime = Convert.ToDateTime(StartTime); StringBuilder sb = new StringBuilder(100); DataTable dt = dal.SearchByTime(sTime.Year + "-01-01", sTime.Year + "-12-31"); if (dt != null && dt.Rows.Count > 0) { DateTime startT = Convert.ToDateTime(sTime.Year + "-01-01"); List titleList = new List(); List totalList = new List(); List No_totalList = new List(); List OK_L_List = new List(); for (int i = 0; i < 12; i++) { titleList.Add((i + 1) + "月"); int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(startT.Year, (i + 1)); string starTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd"); string entTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd"); var DayList = from myRow in dt.AsEnumerable() where myRow.Field(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd")) >= 0 && myRow.Field(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd")) <= 0 select myRow; double total_OK = DayList.Sum(p => (int)p.ItemArray[7]); double total_NO = DayList.Sum(p => (int)p.ItemArray[8]); double total_all = total_OK + total_NO; totalList.Add(total_OK); No_totalList.Add(total_NO); if (total_all > 0) { OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2)); } else { OK_L_List.Add(0); } } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in titleList) { sb.Append(""); } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in totalList) { sb.Append(""); } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in No_totalList) { sb.Append(""); } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in OK_L_List) { sb.Append(""); } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in OK_L_List) { sb.Append(""); } sb.Append(""); sb.Append("
" + item + "
总合格数量" + item + "
不良数量" + item + "
合格率" + item + "%
目标值99.6%
"); } return sb.ToString(); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } //柱状图 public EcharBarModel SearchQualifiedMonthBar(string StartTime) { try { EcharBarModel md = new EcharBarModel(); DateTime sTime = Convert.ToDateTime(StartTime); DataTable dt = dal.SearchByTime(sTime.Year + "-01-01", sTime.Year + "-12-31"); if (dt != null && dt.Rows.Count > 0) { DateTime startT = Convert.ToDateTime(sTime.Year + "-01-01"); List titleList = new List(); List totalList = new List(); List No_totalList = new List(); List OK_L_List = new List(); List T_L_List = new List(); for (int i = 0; i < 12; i++) { titleList.Add((i + 1) + "月"); int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(startT.Year, (i + 1)); string starTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd"); string entTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd"); var DayList = from myRow in dt.AsEnumerable() where myRow.Field(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd")) >= 0 && myRow.Field(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd")) <= 0 select myRow; double total_OK = DayList.Sum(p => (int)p.ItemArray[7]); double total_NO = DayList.Sum(p => (int)p.ItemArray[8]); double total_all = total_OK + total_NO; totalList.Add(total_OK); No_totalList.Add(total_NO); if (total_all > 0) { OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2)); } else { OK_L_List.Add(0); } } foreach (var item in OK_L_List) { T_L_List.Add(99.6); } md.categories = titleList; md.QualifiedData = OK_L_List; md.TargetData = T_L_List; } return md; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public List> SearchQualifiedMonthForExcel(string StartTime) { try { List> list = new List>(); DateTime sTime = Convert.ToDateTime(StartTime); StringBuilder sb = new StringBuilder(100); DataTable dt = dal.SearchByTime(sTime.Year + "-01-01", sTime.Year + "-12-31"); if (dt != null && dt.Rows.Count > 0) { DateTime startT = Convert.ToDateTime(sTime.Year + "-01-01"); List titleList = new List(); List totalList = new List(); List No_totalList = new List(); List OK_L_List = new List(); for (int i = 0; i < 12; i++) { titleList.Add((i + 1) + "月"); int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(startT.Year, (i + 1)); string starTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd"); string entTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd"); var DayList = from myRow in dt.AsEnumerable() where myRow.Field(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd")) >= 0 && myRow.Field(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd")) <= 0 select myRow; double total_OK = DayList.Sum(p => (int)p.ItemArray[7]); double total_NO = DayList.Sum(p => (int)p.ItemArray[8]); double total_all = total_OK + total_NO; totalList.Add(total_OK); No_totalList.Add(total_NO); if (total_all > 0) { OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2)); } else { OK_L_List.Add(0); } } List title_ = new List(); title_.Add(""); title_.AddRange(titleList); list.Add(title_); List total_ = new List(); total_.Add("总合格数量"); foreach (var item in totalList) { total_.Add(item.ToString()); } list.Add(total_); List No_total_ = new List(); No_total_.Add("不良数量"); foreach (var item in No_totalList) { No_total_.Add(item.ToString()); } list.Add(No_total_); List OK_L_ = new List(); OK_L_.Add("合格率"); foreach (var item in OK_L_List) { OK_L_.Add(item.ToString() + "%"); } list.Add(OK_L_); List tag_L_ = new List(); tag_L_.Add("目标值"); foreach (var item in OK_L_List) { tag_L_.Add("99.6%"); } list.Add(tag_L_); } return list; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } #endregion #region 日原料利用率 public string SearchMaterialAvailabilityDay(string StartTime) { try { var p_info = ef.tb_Plastic.Where(p => p.Weight != null); DateTime sTime = Convert.ToDateTime(StartTime); int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(sTime.Year, sTime.Month); StringBuilder sb = new StringBuilder(100); DataTable dt = dal.SearchByTime(Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-01").ToString("yyyy-MM-dd"), Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + days.ToString()).ToString("yyyy-MM-dd")); if (dt != null && dt.Rows.Count > 0) { List titleList = new List(); List totalList = new List(); List No_totalList = new List(); List All_totalList = new List(); List OK_L_List = new List(); for (int i = 0; i < days; i++) { titleList.Add((i + 1) + "日"); string nowTime = Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + (i + 1)).ToString("yyyy-MM-dd"); var listAddress = (from myRow in dt.AsEnumerable() where myRow.Field(3) == nowTime group myRow by new { StockNo = myRow.ItemArray[5] } into g //orderby new ComparerItem() { OrderIndex = b.Key., Id = b.Key.Id } descending select new { StockNo = (string)g.Key.StockNo, total_ok = g.Sum(c => (int)c.ItemArray[7]), total_no = g.Sum(c => (int)c.ItemArray[8]) }); double total_OK = 0; double total_NO = 0; foreach (var item in listAddress) { string stockNo = item.StockNo; var w_info = p_info.FirstOrDefault(p => p.StockNo.Equals(stockNo)); if (w_info != null) { total_OK += (double)(w_info.Weight * item.total_ok); total_NO += (double)(w_info.Weight * item.total_no); } } totalList.Add(Math.Round(total_OK / 1000, 2)); No_totalList.Add(Math.Round(total_NO / 1000, 2)); DateTime nsTime = Convert.ToDateTime(nowTime + " 00:00:00"); DateTime neTime = Convert.ToDateTime(nowTime + " 23:59:59"); var Waste_Num = ef.tb_Injection_Record.Where(p => p.RecordDate >= nsTime && p.RecordDate <= neTime).Sum(p => p.Waste_Weight); double total_Waste = 0; if (Waste_Num == null) { total_Waste = 0; } else { total_Waste = (double)Waste_Num; } double total_all = total_OK + total_NO + total_Waste; All_totalList.Add(Math.Round(total_all / 1000, 2)); if (total_all > 0) { OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2)); } else { OK_L_List.Add(0); } } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in titleList) { sb.Append(""); } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in OK_L_List) { sb.Append(""); } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in totalList) { sb.Append(""); } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in All_totalList) { sb.Append(""); } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in OK_L_List) { sb.Append(""); } sb.Append(""); sb.Append("
" + item + "
目标值98%
合格件耗用原料" + item + "
总耗用原料" + item + "
原料利用率" + item + "%
"); } return sb.ToString(); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } //柱状图 public EcharBarModel SearchMaterialAvailabilityDayBar(string StartTime) { try { EcharBarModel md = new EcharBarModel(); var p_info = ef.tb_Plastic.Where(p => p.Weight != null); DateTime sTime = Convert.ToDateTime(StartTime); int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(sTime.Year, sTime.Month); StringBuilder sb = new StringBuilder(100); DataTable dt = dal.SearchByTime(Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-01").ToString("yyyy-MM-dd"), Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + days.ToString()).ToString("yyyy-MM-dd")); if (dt != null && dt.Rows.Count > 0) { List titleList = new List(); List totalList = new List(); List No_totalList = new List(); List OK_L_List = new List(); List T_L_List = new List(); for (int i = 0; i < days; i++) { titleList.Add((i + 1) + "日"); string nowTime = Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + (i + 1)).ToString("yyyy-MM-dd"); var listAddress = (from myRow in dt.AsEnumerable() where myRow.Field(3) == nowTime group myRow by new { StockNo = myRow.ItemArray[5] } into g //orderby new ComparerItem() { OrderIndex = b.Key., Id = b.Key.Id } descending select new { StockNo = (string)g.Key.StockNo, total_ok = g.Sum(c => (int)c.ItemArray[7]), total_no = g.Sum(c => (int)c.ItemArray[8]) }); double total_OK = 0; double total_NO = 0; foreach (var item in listAddress) { string stockNo = item.StockNo; var w_info = p_info.FirstOrDefault(p => p.StockNo.Equals(stockNo)); if (w_info != null) { total_OK += (double)(w_info.Weight * item.total_ok); total_NO += (double)(w_info.Weight * item.total_no); } } totalList.Add(Math.Round(total_OK / 1000, 2)); No_totalList.Add(Math.Round(total_NO / 1000, 2)); DateTime nsTime = Convert.ToDateTime(nowTime + " 00:00:00"); DateTime neTime = Convert.ToDateTime(nowTime + " 23:59:59"); var Waste_Num = ef.tb_Injection_Record.Where(p => p.RecordDate >= nsTime && p.RecordDate <= neTime).Sum(p => p.Waste_Weight); double total_Waste = 0; if (Waste_Num == null) { total_Waste = 0; } else { total_Waste = (double)Waste_Num; } double total_all = total_OK + total_NO + total_Waste; if (total_all > 0) { OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2)); } else { OK_L_List.Add(0); } } foreach (var item in OK_L_List) { T_L_List.Add(98); } md.categories = titleList; md.QualifiedData = OK_L_List; md.TargetData = T_L_List; } return md; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public List> SearchMaterialAvailabilityDayForExcel(string StartTime) { try { List> list = new List>(); var p_info = ef.tb_Plastic.Where(p => p.Weight != null); DateTime sTime = Convert.ToDateTime(StartTime); int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(sTime.Year, sTime.Month); StringBuilder sb = new StringBuilder(100); DataTable dt = dal.SearchByTime(Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-01").ToString("yyyy-MM-dd"), Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + days.ToString()).ToString("yyyy-MM-dd")); if (dt != null && dt.Rows.Count > 0) { List titleList = new List(); List totalList = new List(); List No_totalList = new List(); List All_totalList = new List(); List OK_L_List = new List(); for (int i = 0; i < days; i++) { titleList.Add((i + 1) + "日"); string nowTime = Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + (i + 1)).ToString("yyyy-MM-dd"); var listAddress = (from myRow in dt.AsEnumerable() where myRow.Field(3) == nowTime group myRow by new { StockNo = myRow.ItemArray[5] } into g //orderby new ComparerItem() { OrderIndex = b.Key., Id = b.Key.Id } descending select new { StockNo = (string)g.Key.StockNo, total_ok = g.Sum(c => (int)c.ItemArray[7]), total_no = g.Sum(c => (int)c.ItemArray[8]) }); double total_OK = 0; double total_NO = 0; foreach (var item in listAddress) { string stockNo = item.StockNo; var w_info = p_info.FirstOrDefault(p => p.StockNo.Equals(stockNo)); if (w_info != null) { total_OK += (double)(w_info.Weight * item.total_ok); total_NO += (double)(w_info.Weight * item.total_no); } } totalList.Add(Math.Round(total_OK / 1000, 2)); No_totalList.Add(Math.Round(total_NO / 1000, 2)); DateTime nsTime = Convert.ToDateTime(nowTime + " 00:00:00"); DateTime neTime = Convert.ToDateTime(nowTime + " 23:59:59"); var Waste_Num = ef.tb_Injection_Record.Where(p => p.RecordDate >= nsTime && p.RecordDate <= neTime).Sum(p => p.Waste_Weight); double total_Waste = 0; if (Waste_Num == null) { total_Waste = 0; } else { total_Waste = (double)Waste_Num; } double total_all = total_OK + total_NO + total_Waste; All_totalList.Add(Math.Round(total_all / 1000, 2)); if (total_all > 0) { OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2)); } else { OK_L_List.Add(0); } } List title_ = new List(); title_.Add(""); title_.AddRange(titleList); list.Add(title_); List tag_L_ = new List(); tag_L_.Add("目标值"); foreach (var item in OK_L_List) { tag_L_.Add("98%"); } list.Add(tag_L_); List total_ = new List(); total_.Add("合格件耗用原料"); foreach (var item in totalList) { total_.Add(item.ToString()); } list.Add(total_); List No_total_ = new List(); No_total_.Add("总耗用原料"); foreach (var item in All_totalList) { No_total_.Add(item.ToString()); } list.Add(No_total_); List OK_L_ = new List(); OK_L_.Add("原料利用率"); foreach (var item in OK_L_List) { OK_L_.Add(item.ToString() + "%"); } list.Add(OK_L_); } return list; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } #endregion #region 月原料利用率 public string SearchMaterialAvailabilityMonth(string StartTime) { try { StringBuilder sb = new StringBuilder(100); var p_info = ef.tb_Plastic.Where(p => p.Weight != null); DateTime sTime = Convert.ToDateTime(StartTime); DataTable dt = dal.SearchByTime(sTime.Year + "-01-01", sTime.Year + "-12-31"); if (dt != null && dt.Rows.Count > 0) { List titleList = new List(); List totalList = new List(); List No_totalList = new List(); List All_totalList = new List(); List OK_L_List = new List(); for (int i = 0; i < 12; i++) { DateTime startT = Convert.ToDateTime(sTime.Year + "-01-01"); titleList.Add((i + 1) + "月"); int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(startT.Year, (i + 1)); string starTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd"); string entTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd"); var listAddress = (from myRow in dt.AsEnumerable() where myRow.Field(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd")) >= 0 && myRow.Field(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd")) <= 0 group myRow by new { StockNo = myRow.ItemArray[5] } into g select new { StockNo = (string)g.Key.StockNo, total_ok = g.Sum(c => (int)c.ItemArray[7]), total_no = g.Sum(c => (int)c.ItemArray[8]) }); double total_OK = 0; double total_NO = 0; foreach (var item in listAddress) { string stockNo = item.StockNo; var w_info = p_info.FirstOrDefault(p => p.StockNo.Equals(stockNo)); if (w_info != null) { total_OK += (double)(w_info.Weight * item.total_ok); total_NO += (double)(w_info.Weight * item.total_no); } } totalList.Add(Math.Round(total_OK / 1000, 2)); No_totalList.Add(Math.Round(total_NO / 1000, 2)); DateTime nsTime = Convert.ToDateTime(starTime + " 00:00:00"); DateTime neTime = Convert.ToDateTime(entTime + " 23:59:59"); var Waste_Num = ef.tb_Injection_Record.Where(p => p.RecordDate >= nsTime && p.RecordDate <= neTime).Sum(p => p.Waste_Weight); double total_Waste = 0; if (Waste_Num == null) { total_Waste = 0; } else { total_Waste = (double)Waste_Num; } double total_all = total_OK + total_NO + total_Waste; All_totalList.Add(Math.Round(total_all / 1000, 2)); if (total_all > 0) { OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2)); } else { OK_L_List.Add(0); } } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in titleList) { sb.Append(""); } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in OK_L_List) { sb.Append(""); } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in totalList) { sb.Append(""); } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in All_totalList) { sb.Append(""); } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in OK_L_List) { sb.Append(""); } sb.Append(""); sb.Append("
" + item + "
目标值98%
合格件耗用原料" + item + "
总耗用原料" + item + "
原料利用率" + item + "%
"); } return sb.ToString(); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public EcharBarModel SearchMaterialAvailabilityMonthBar(string StartTime) { try { EcharBarModel md = new EcharBarModel(); var p_info = ef.tb_Plastic.Where(p => p.Weight != null); DateTime sTime = Convert.ToDateTime(StartTime); DataTable dt = dal.SearchByTime(sTime.Year + "-01-01", sTime.Year + "-12-31"); if (dt != null && dt.Rows.Count > 0) { List titleList = new List(); List totalList = new List(); List No_totalList = new List(); List OK_L_List = new List(); List T_L_List = new List(); for (int i = 0; i < 12; i++) { DateTime startT = Convert.ToDateTime(sTime.Year + "-01-01"); titleList.Add((i + 1) + "月"); int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(startT.Year, (i + 1)); string starTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd"); string entTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd"); var listAddress = (from myRow in dt.AsEnumerable() where myRow.Field(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd")) >= 0 && myRow.Field(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd")) <= 0 group myRow by new { StockNo = myRow.ItemArray[5] } into g select new { StockNo = (string)g.Key.StockNo, total_ok = g.Sum(c => (int)c.ItemArray[7]), total_no = g.Sum(c => (int)c.ItemArray[8]) }); double total_OK = 0; double total_NO = 0; foreach (var item in listAddress) { string stockNo = item.StockNo; var w_info = p_info.FirstOrDefault(p => p.StockNo.Equals(stockNo)); if (w_info != null) { total_OK += (double)(w_info.Weight * item.total_ok); total_NO += (double)(w_info.Weight * item.total_no); } } totalList.Add(Math.Round(total_OK / 1000, 2)); No_totalList.Add(Math.Round(total_NO / 1000, 2)); DateTime nsTime = Convert.ToDateTime(starTime + " 00:00:00"); DateTime neTime = Convert.ToDateTime(entTime + " 23:59:59"); var Waste_Num = ef.tb_Injection_Record.Where(p => p.RecordDate >= nsTime && p.RecordDate <= neTime).Sum(p => p.Waste_Weight); double total_Waste = 0; if (Waste_Num == null) { total_Waste = 0; } else { total_Waste = (double)Waste_Num; } double total_all = total_OK + total_NO + total_Waste; if (total_all > 0) { OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2)); } else { OK_L_List.Add(0); } } foreach (var item in OK_L_List) { T_L_List.Add(98); } md.categories = titleList; md.QualifiedData = OK_L_List; md.TargetData = T_L_List; } return md; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public List> SearchMaterialAvailabilityMonthForExcel(string StartTime) { try { List> list = new List>(); var p_info = ef.tb_Plastic.Where(p => p.Weight != null); DateTime sTime = Convert.ToDateTime(StartTime); DataTable dt = dal.SearchByTime(sTime.Year + "-01-01", sTime.Year + "-12-31"); if (dt != null && dt.Rows.Count > 0) { List titleList = new List(); List totalList = new List(); List No_totalList = new List(); List All_totalList = new List(); List OK_L_List = new List(); for (int i = 0; i < 12; i++) { DateTime startT = Convert.ToDateTime(sTime.Year + "-01-01"); titleList.Add((i + 1) + "月"); int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(startT.Year, (i + 1)); string starTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd"); string entTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd"); var listAddress = (from myRow in dt.AsEnumerable() where myRow.Field(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd")) >= 0 && myRow.Field(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd")) <= 0 group myRow by new { StockNo = myRow.ItemArray[5] } into g select new { StockNo = (string)g.Key.StockNo, total_ok = g.Sum(c => (int)c.ItemArray[7]), total_no = g.Sum(c => (int)c.ItemArray[8]) }); double total_OK = 0; double total_NO = 0; foreach (var item in listAddress) { string stockNo = item.StockNo; var w_info = p_info.FirstOrDefault(p => p.StockNo.Equals(stockNo)); if (w_info != null) { total_OK += (double)(w_info.Weight * item.total_ok); total_NO += (double)(w_info.Weight * item.total_no); } } totalList.Add(Math.Round(total_OK / 1000, 2)); No_totalList.Add(Math.Round(total_NO / 1000, 2)); DateTime nsTime = Convert.ToDateTime(starTime + " 00:00:00"); DateTime neTime = Convert.ToDateTime(entTime + " 23:59:59"); var Waste_Num = ef.tb_Injection_Record.Where(p => p.RecordDate >= nsTime && p.RecordDate <= neTime).Sum(p => p.Waste_Weight); double total_Waste = 0; if (Waste_Num == null) { total_Waste = 0; } else { total_Waste = (double)Waste_Num; } double total_all = total_OK + total_NO + total_Waste; All_totalList.Add(Math.Round(total_all / 1000, 2)); if (total_all > 0) { OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2)); } else { OK_L_List.Add(0); } } List title_ = new List(); title_.Add(""); title_.AddRange(titleList); list.Add(title_); List tag_L_ = new List(); tag_L_.Add("目标值"); foreach (var item in OK_L_List) { tag_L_.Add("98%"); } list.Add(tag_L_); List total_ = new List(); total_.Add("合格件耗用原料"); foreach (var item in totalList) { total_.Add(item.ToString()); } list.Add(total_); List No_total_ = new List(); No_total_.Add("总耗用原料"); foreach (var item in All_totalList) { No_total_.Add(item.ToString()); } list.Add(No_total_); List OK_L_ = new List(); OK_L_.Add("原料利用率"); foreach (var item in OK_L_List) { OK_L_.Add(item.ToString() + "%"); } list.Add(OK_L_); } return list; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } #endregion #region 注塑生产记录表 public string SearchProductInjectionRecord(string StartTime, string EndTime) { var defectList = ef.tb_Defect.ToList(); var defectInfo = defectList.Where(p => p.LineID.Equals(defectList.FirstOrDefault().LineID)).OrderBy(p => p.DefectName).Select(p => p.DefectName).ToList(); var DownReasonList = ef.tb_Inhection_DownReason.OrderBy(p => p.Reason).Select(p => p.Reason).ToList(); DataTable dt = dal.SearchProductInjectionRecord(Convert.ToDateTime(StartTime).ToString("yyyy-MM-dd"), Convert.ToDateTime(EndTime).ToString("yyyy-MM-dd")); DataTable dt2 = dal.SearchProductInjectionRecordBadReason(Convert.ToDateTime(StartTime).ToString("yyyy-MM-dd"), Convert.ToDateTime(EndTime).ToString("yyyy-MM-dd")); List list = Tool.ConvertTo(dt2).ToList(); DataTable dt3 = dal.SearchProductInjectionRecordDownReason(Convert.ToDateTime(StartTime).ToString("yyyy-MM-dd"), Convert.ToDateTime(EndTime).ToString("yyyy-MM-dd")); List list3 = Tool.ConvertTo(dt3).ToList(); StringBuilder sb = new StringBuilder(100); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); //sb.Append(""); //sb.Append(""); //sb.Append(""); //sb.Append(""); //sb.Append(""); //sb.Append(""); //sb.Append(""); //sb.Append(""); //sb.Append(""); //sb.Append(""); //sb.Append(""); //sb.Append(""); //sb.Append(""); sb.Append(""); //sb.Append(""); //foreach (var item in defectInfo) //{ // sb.Append(""); //} //sb.Append(""); //sb.Append(""); //sb.Append(""); //sb.Append(""); //sb.Append(""); //foreach (var item in DownReasonList) //{ // sb.Append(""); //} //sb.Append(""); try { if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { sb.Append(""); sb.Append("");//生产日期 sb.Append("");//班次 sb.Append("");//注塑机台 sb.Append("");//取模 sb.Append("");//厂商 decimal cycle_Time = dt.Rows[i]["CycleTime"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["CycleTime"]); sb.Append("");//周期 sb.Append("");//原料号 sb.Append("");//新零件号编码 sb.Append("");//产品性质 sb.Append("");//原料名称 decimal real_Cycle = dt.Rows[i]["RealCycle"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["RealCycle"]); decimal product_count = dt.Rows[i]["ProductCount"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["ProductCount"]); decimal market_count = dt.Rows[i]["MarketCount"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["MarketCount"]); decimal bad_count = dt.Rows[i]["BadCount"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["BadCount"]); decimal weight = dt.Rows[i]["Weight"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["Weight"]); decimal plan_count = dt.Rows[i]["PlanCount"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["PlanCount"]); sb.Append("");//生产数量(合格数量+市场件数+不良总数) sb.Append("");//合格数量 sb.Append("");//市场件数 sb.Append("");//调试不良 sb.Append("");//生产不良 sb.Append("");//开机不良 sb.Append("");//奔驰前十模报废 sb.Append("");//不良总数 sb.Append("");//前十模 + 不良总数量之和 decimal ok_num = 0; if ((product_count + bad_count) == 0) { sb.Append("");//合格率(总合格数/(总合格数+不良数)) sb.Append("");//不良率 } else { ok_num = Math.Round((product_count + market_count / (product_count + market_count + bad_count)) * 100, 2); sb.Append("");//合格率(总合格数/(总合格数+不良数)) sb.Append("");//不良率 } var listR = list3.Where(p => p.DownTypeName != null && p.PlanID.Equals(dt.Rows[i]["PlanID"])).ToList(); long x = listR.Where(p => p.DownTypeName.Contains("计划停机")).Sum(p => p.DownTime); long x1 = listR.Where(p => p.DownTypeName.Contains("换模时间")).Sum(p => p.DownTime); //TODO 要合并单元格 //sb.Append(""); //sb.Append(""); //sb.Append("");//产出工时(计划数量*实际周期/60) var stopTime = (listR.Where(p => p.DownTypeName.Contains("非计划停机")).Sum(p => p.DownTime) + listR.Where(p => p.DownTypeName.Contains("计划停机")).Sum(p => p.DownTime)); decimal pTime = (24 * 60 - stopTime); sb.Append("");//生产时间 sb.Append("");//停机时间 sb.Append("");//机台利用率 sb.Append("");//OEE sb.Append(""); sb.Append(""); decimal OneWeight = dt.Rows[i]["OneWeight"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["OneWeight"]); decimal Weight = dt.Rows[i]["Weight"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["Weight"]); sb.Append("");//单品净重 sb.Append("");//塑件毛重 sb.Append("");//料棒重量 sb.Append("");//物料使用 还要减去机头料 sb.Append("");//机头料(kg) sb.Append("");//料棒/浇口(kg) sb.Append("");//不良品(kg) sb.Append("");//奔驰前十模使用原料 sb.Append("");//回料(kg) //sb.Append("");//开机时间 //sb.Append("");//关机时间 //sb.Append("");//产品名称 //sb.Append("");//标准开机时间 //sb.Append("");//实际周期 //sb.Append("");//计划数量 //sb.Append("");//总合格数量 //sb.Append("");//不良数量 //for (int k = 0; k < defectInfo.Count; k++) //{ // sb.Append(""); //} //sb.Append("");//产品毛重(总合格数量+不良数量)*产品毛重 //sb.Append("");//废料块 //sb.Append("");//浇口重量 //sb.Append("");//产品耗用原料 //if (plan_count == 0) //{ // sb.Append("");//完成率 //} //else //{ // sb.Append("");//完成率(总合格数/计划数) //} //sb.Append("");//计划工时(计划数量*标准周期/60) //sb.Append("");//计划停机+换模时间 //sb.Append(""); //sb.Append(""); //sb.Append(""); //sb.Append(""); //sb.Append(""); //for (int k = 0; k < DownReasonList.Count; k++) //{ // sb.Append(""); //} sb.Append(""); } } } catch (Exception ex) { throw; } sb.Append("
生产日期班别机台模取厂商周期(S)物料号新零件号编码产品性质物料名称生产数量合格数量市场件数量调试不良生产不良开机不良奔驰前十模报废不良总数量前十模+不良总数量之和合格率不良率生产时间(min)机台利用率OEE原料物料号原料名称单品净重(kg)塑件毛重(kg)料棒重量(kg)物料使用(kg)机头料(kg)料棒/浇口(kg)不良品(kg)奔驰前十模使用原料回料(kg)不良原因产品毛重废料块浇口重量产品耗用原料合格率完成率计划工时产出工时停机时间换膜计划停机停机原因
" + item + "计划停机+换模时间非计划停机换膜交班接班" + item + "
" + dt.Rows[i]["ProductDate"] + "" + dt.Rows[i]["ClassName"].ToString() + "" + dt.Rows[i]["StationNo"] + "" + dt.Rows[i]["IsOneMore"] + "" + dt.Rows[i]["ManufacturerName"] + "" + cycle_Time + "" + dt.Rows[i]["BatchNo"] + "" + dt.Rows[i]["PartNo"] + "正常" + dt.Rows[i]["MaterialName"] + "" + (product_count + market_count + bad_count) + "" + product_count + "" + market_count + "" + bad_count + "0%0%" + ok_num + "%" + (100 - ok_num) + "%" + listR.Where(p => p.DownTypeName.Contains("非计划停机")).Sum(p => p.DownTime) + "" + listR.Where(p => p.DownTypeName.Contains("计划停机")).Sum(p => p.DownTime) + "" + Math.Round((plan_count * real_Cycle) / 60, 2) + "" + pTime + "" + stopTime + "" + Math.Round((pTime / 1440) * 100, 2) + "" + (pTime / 1440) * ok_num + "原料物料号原料名称" + OneWeight + "" + Weight + "" + (Weight - OneWeight) + "" + (Weight * (product_count + market_count + bad_count)) + "机头料(kg)" + (Weight - OneWeight) * (product_count + market_count + bad_count) + "" + (OneWeight * bad_count) + "奔驰前十模使用原料回料(kg)" + dt.Rows[i]["BeginTime"] + "" + dt.Rows[i]["EndTime"] + "" + dt.Rows[i]["ProductName"] + "" + dt.Rows[i]["OpenDebugTime"] + "" + real_Cycle + "" + dt.Rows[i]["PlanCount"] + "" + (product_count + bad_count + list.Where(p => "开机报废;".Equals(p.BadReason)).Count()) + "" + dt.Rows[i]["BadCount"] + "" + list.Where(p => p.BadReason.Equals(defectInfo[k] + ";")).Count() + "" + dt.Rows[i]["Weight"] + "" + dt.Rows[i]["Waste_Weight"] + "" + dt.Rows[i]["JK_Weight"] + "" + (product_count + bad_count) * weight + "0%" + Math.Round((product_count / plan_count) * 100, 2) + "%" + Math.Round((plan_count * cycle_Time) / 60, 2) + "" + (x + x1) + "" + listR.Where(p => p.DownTypeName.Contains("非计划停机")).Sum(p => p.DownTime) + "" + listR.Where(p => p.DownTypeName.Contains("换模")).Sum(p => p.DownTime) + "" + listR.Where(p => p.DownTypeName.Contains("交班")).Sum(p => p.DownTime) + "" + listR.Where(p => p.DownTypeName.Contains("接班")).Sum(p => p.DownTime) + "" + listR.Where(p => p.DownTypeName.Contains("计划停机")).Sum(p => p.DownTime) + "" + list3.Where(p => p.Reason != null && p.PlanID.Equals(dt.Rows[i]["PlanID"]) && p.Reason.Contains(DownReasonList[k])).Sum(p => p.DownTime) + "
"); return sb.ToString(); } private string CheckWorkClass(string StartTime) { try { if (true) { string time = StartTime.Substring(0, StartTime.IndexOf(" ")); if (DateTime.Compare(Convert.ToDateTime(StartTime), Convert.ToDateTime(time + " 08:00:00")) > 0 && DateTime.Compare(Convert.ToDateTime(time + " 19:59:59"), Convert.ToDateTime(StartTime)) > 0) { return "A"; } return "B"; } } catch (Exception ex) { } return ""; } public List> SearchProductInjectionRecordForExcel(string StartTime, string EndTime) { List> listExcel = new List>(); var defectList = ef.tb_Defect.ToList(); var defectInfo = defectList.Where(p => p.LineID.Equals(defectList.FirstOrDefault().LineID)).OrderBy(p => p.DefectName).Select(p => p.DefectName).ToList(); var DownReasonList = ef.tb_Inhection_DownReason.OrderBy(p => p.Reason).Select(p => p.Reason).ToList(); DataTable dt = dal.SearchProductInjectionRecord(Convert.ToDateTime(StartTime).ToString("yyyy-MM-dd"), Convert.ToDateTime(EndTime).ToString("yyyy-MM-dd")); DataTable dt2 = dal.SearchProductInjectionRecordBadReason(Convert.ToDateTime(StartTime).ToString("yyyy-MM-dd"), Convert.ToDateTime(EndTime).ToString("yyyy-MM-dd")); List list = Tool.ConvertTo(dt2).ToList(); DataTable dt3 = dal.SearchProductInjectionRecordDownReason(Convert.ToDateTime(StartTime).ToString("yyyy-MM-dd"), Convert.ToDateTime(EndTime).ToString("yyyy-MM-dd")); List list3 = Tool.ConvertTo(dt3).ToList(); List titleList = new List(); titleList.Add(""); titleList.Add(""); titleList.Add(""); titleList.Add(""); titleList.Add(""); titleList.Add(""); titleList.Add(""); titleList.Add(""); titleList.Add(""); titleList.Add(""); titleList.Add(""); titleList.Add(""); titleList.Add(""); titleList.Add(""); titleList.Add(""); titleList.Add(""); foreach (var item in defectInfo) { titleList.Add("不良原因"); } titleList.Add(""); titleList.Add(""); titleList.Add(""); titleList.Add(""); titleList.Add(""); titleList.Add(""); titleList.Add(""); titleList.Add(""); titleList.Add("停机时间"); titleList.Add("停机时间"); titleList.Add("换膜"); titleList.Add("换膜"); titleList.Add("换膜"); titleList.Add(""); foreach (var item in DownReasonList) { titleList.Add("停机原因"); } listExcel.Add(titleList); List titleList2 = new List(); titleList2.Add("日期"); titleList2.Add("班次"); titleList2.Add("注塑机台"); titleList2.Add("开机时间"); titleList2.Add("关机时间"); titleList2.Add("产品性质"); titleList2.Add("产品名称"); titleList2.Add("原料名称"); titleList2.Add("原料批次号"); titleList2.Add("标准开机时间"); titleList2.Add("标准周期"); titleList2.Add("实际周期"); titleList2.Add("计划数量"); titleList2.Add("合格数量"); titleList2.Add("总合格数量"); titleList2.Add("不良数量"); foreach (var item in defectInfo) { titleList2.Add(item); } titleList2.Add("产品毛重"); titleList2.Add("废料块"); titleList2.Add("浇口重量"); titleList2.Add("产品耗用原料"); titleList2.Add("合格率"); titleList2.Add("完成率"); titleList2.Add("计划工时"); titleList2.Add("产出工时"); titleList2.Add("计划停机+换模时间"); titleList2.Add("非计划停机"); titleList2.Add("换膜"); titleList2.Add("交班"); titleList2.Add("接班"); titleList2.Add("计划停机"); foreach (var item in DownReasonList) { titleList2.Add(item); } listExcel.Add(titleList2); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { List conList = new List(); conList.Add(dt.Rows[i]["ProductDate"].ToString()); conList.Add(dt.Rows[i]["ClassName"].ToString()); conList.Add(dt.Rows[i]["StationNo"].ToString()); conList.Add(dt.Rows[i]["BeginTime"].ToString()); conList.Add(dt.Rows[i]["EndTime"].ToString()); conList.Add("正常"); conList.Add(dt.Rows[i]["ProductName"].ToString()); conList.Add(dt.Rows[i]["MaterialName"].ToString()); conList.Add(dt.Rows[i]["BatchNo"].ToString()); conList.Add(dt.Rows[i]["OpenDebugTime"].ToString()); decimal cycle_Time = dt.Rows[i]["CycleTime"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["CycleTime"]); conList.Add(cycle_Time.ToString()); decimal real_Cycle = dt.Rows[i]["RealCycle"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["RealCycle"]); decimal product_count = dt.Rows[i]["ProductCount"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["ProductCount"]); decimal bad_count = dt.Rows[i]["BadCount"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["BadCount"]); decimal weight = dt.Rows[i]["Weight"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["Weight"]); decimal plan_count = dt.Rows[i]["PlanCount"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["PlanCount"]); decimal openFailCount = 0; conList.Add(real_Cycle.ToString()); conList.Add(dt.Rows[i]["PlanCount"].ToString()); conList.Add(product_count.ToString()); conList.Add((product_count + bad_count + defectInfo.Where(p => "开机报废".Equals(p)).Count()).ToString()); conList.Add(dt.Rows[i]["BadCount"].ToString()); for (int k = 0; k < defectInfo.Count; k++) { conList.Add(list.Where(p => p.BadReason.Equals(defectInfo[k] + ";")).Count().ToString()); } conList.Add(dt.Rows[i]["Weight"].ToString()); conList.Add(dt.Rows[i]["Waste_Weight"].ToString()); conList.Add(dt.Rows[i]["JK_Weight"].ToString()); conList.Add(((product_count + bad_count) * weight).ToString()); if ((product_count + bad_count) == 0) { conList.Add("0%"); } else { conList.Add((Math.Round((product_count / (product_count + bad_count)) * 100, 2)).ToString()); } if (plan_count == 0) { conList.Add("0%"); } else { conList.Add((Math.Round((product_count / plan_count) * 100, 2)).ToString()); } conList.Add((Math.Round((plan_count * cycle_Time) / 60, 2)).ToString()); conList.Add((Math.Round((plan_count * real_Cycle) / 60, 2)).ToString()); var listR = list3.Where(p => p.DownTypeName != null && p.PlanID.Equals(dt.Rows[i]["PlanID"])).ToList(); long x = listR.Where(p => p.DownTypeName.Contains("计划停机")).Sum(p => p.DownTime); long x1 = listR.Where(p => p.DownTypeName.Contains("换模时间")).Sum(p => p.DownTime); conList.Add((x + x1).ToString()); conList.Add((listR.Where(p => p.DownTypeName.Contains("非计划停机")).Sum(p => p.DownTime)).ToString()); conList.Add((listR.Where(p => p.DownTypeName.Contains("换模")).Sum(p => p.DownTime)).ToString()); conList.Add((listR.Where(p => p.DownTypeName.Contains("交班")).Sum(p => p.DownTime)).ToString()); conList.Add((listR.Where(p => p.DownTypeName.Contains("接班")).Sum(p => p.DownTime)).ToString()); conList.Add((listR.Where(p => p.DownTypeName.Contains("计划停机")).Sum(p => p.DownTime)).ToString()); for (int k = 0; k < DownReasonList.Count; k++) { conList.Add((list3.Where(p => p.Reason != null && p.PlanID.Equals(dt.Rows[i]["PlanID"]) && p.Reason.Contains(DownReasonList[k])).Sum(p => p.DownTime)).ToString()); } listExcel.Add(conList); } } return listExcel; } #endregion } }