using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using MESClassLibrary.BLL.Log; using MESClassLibrary.DAL.Injection; using MESClassLibrary.DAL.painting; using MESClassLibrary.EFModel; using MESClassLibrary.Model; namespace MESClassLibrary.BLL.Injection { public class InjectionDownRecordBLL { BBMPTEntities ef = new BBMPTEntities(); BasicBLL db = new BasicBLL(); InjectionDownRecordDAL dal = new InjectionDownRecordDAL(); public bool AddInfo(InjectionDownRecordModel md) { InjectionDownRecordDAL da = new InjectionDownRecordDAL(); try { return da.AddInfo(md); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } public bool UpdateInfo(InjectionDownRecordModel md) { InjectionDownRecordDAL da = new InjectionDownRecordDAL(); try { return da.UpdateInfo(md); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } #region web用方法 /// /// 查询全部信息分页 /// /// 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_DownRecord.Where(p => p.StartTime >= stime && p.EndTime <= etime && p.DownTime >= 60).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(); BasicBLL DownReason_db = new BasicBLL(); var DownReason_list = DownReason_db.SearchAllInfo(); BasicBLL DownType_db = new BasicBLL(); var DownType_list = DownType_db.SearchAllInfo(); foreach (var item in list) { Injection_DownRecordModel dm = Tool.Mapper(item); var machine_info = machine_list.FirstOrDefault(p => p.StationID == item.StationID); if (machine_info != null) { dm.StationNo = machine_info.StationNo; } var DownReason = DownReason_list.FirstOrDefault(p => p.ID == item.DownReason); if (DownReason != null) { dm.DownReasonName = DownReason.Reason; } var DownType = DownType_list.FirstOrDefault(p => p.ID == item.DownType); if (DownType != null) { dm.DownTypeName = DownType.DownTypeName; } 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; } } public bool UpdateInfo(tb_Injection_DownRecord md) { try { //初始化要更新的字段 string[] proNames = new string[8]; proNames[0] = "StationID"; proNames[1] = "DownType"; proNames[2] = "DownReason"; proNames[3] = "Des"; proNames[4] = "StartTime"; proNames[5] = "EndTime"; proNames[6] = "DownTime"; proNames[7] = "Remark1"; //必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化 //如果没有初始化必填字段,更新会报错 //md.Des = ""; return db.UpdateInfo(md, proNames); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } public string GetComboboxDataByDownType() { try { string jsonStr = "[]"; var list = ef.tb_Injection_DownType.ToList();//判断是否有重复数据 jsonStr = JSONTools.ScriptSerialize(list); return jsonStr; } catch (Exception) { return ""; } } public string GetComboboxDataByDownReason() { try { string jsonStr = "[]"; var list = ef.tb_Inhection_DownReason.ToList();//判断是否有重复数据 jsonStr = JSONTools.ScriptSerialize(list); return jsonStr; } catch (Exception) { return ""; } } public bool UpdateData(List list, string DownRecordID) { try { foreach (var item in list) { tb_Injection_DownRecord md = new tb_Injection_DownRecord(); md.ID = Guid.NewGuid().ToString(); md.StationID = item.StationID; md.PlanID = item.PlanID; md.StartTime = Convert.ToDateTime(item.StartTime); md.EndTime = Convert.ToDateTime(item.EndTime); TimeSpan ts = md.EndTime.Value.Subtract(md.StartTime.Value); md.DownTime = (int)ts.TotalSeconds; md.DownType = item.DownType; md.DownReason = item.DownReason; md.Des = ""; md.Remark1 = item.Remark1; md.Remark2 = "2"; db.AddInfo(md); } var info = ef.tb_Injection_DownRecord.FirstOrDefault(p => p.ID == DownRecordID); info.Remark2 = "1"; ef.SaveChanges(); return true; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } #endregion #region 报表 //每日平均换膜次数 public string SearchDay(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 08:00:00").ToString("yyyy-MM-dd HH:mm:ss"), Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + days.ToString() + " 07:59:59").AddDays(1).ToString("yyyy-MM-dd HH:mm:ss")); if (dt != null && dt.Rows.Count > 0) { List titleList = new List(); List Day_totalList = new List(); List Night_totalList = new List(); for (int i = 0; i < days; i++) { titleList.Add((i + 1).ToString()); DateTime dtime = Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + (i + 1)); //白班 var DayList = from myRow in dt.AsEnumerable() where myRow.Field(5) >= Convert.ToDateTime(dtime.ToString("yyyy-MM-dd") + " 08:00:00.000") && myRow.Field(6) <= Convert.ToDateTime(dtime.ToString("yyyy-MM-dd") + " 19:59:59.999") select myRow; if (DayList.Count() > 0) { int Day_int = DayList.Sum(p => Convert.ToInt32(p.ItemArray[7])); Day_totalList.Add(Math.Round((Day_int / (double)DayList.Count()) / 60, 2)); } else { Day_totalList.Add(0); } //夜班 var NightList = from myRowNight in dt.AsEnumerable() where myRowNight.Field(5) >= Convert.ToDateTime(dtime.ToString("yyyy-MM-dd") + " 20:00:00.000") && myRowNight.Field(6) <= Convert.ToDateTime(dtime.AddDays(1).ToString("yyyy-MM-dd") + " 07:59:59.999") select myRowNight; if (NightList.Count() > 0) { int Night_int = NightList.Sum(p => Convert.ToInt32(p.ItemArray[7])); Night_totalList.Add(Math.Round((Night_int / (double)NightList.Count()) / 60, 2)); } else { Night_totalList.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 Day_totalList) { sb.Append(""); } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in Night_totalList) { sb.Append(""); } sb.Append(""); sb.Append("
班次/日期" + item + "
白班" + item + "
夜班" + item + "
"); } return sb.ToString(); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } //每日平均换膜次数导出excel public List> SearchDayForExcel(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 08:00:00").ToString("yyyy-MM-dd HH:mm:ss"), Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + days.ToString() + " 07:59:59").AddDays(1).ToString("yyyy-MM-dd HH:mm:ss")); if (dt != null && dt.Rows.Count > 0) { List titleList = new List(); List Day_totalList = new List(); List Night_totalList = new List(); for (int i = 0; i < days; i++) { titleList.Add((i + 1).ToString()); DateTime dtime = Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + (i + 1)); //白班 var DayList = from myRow in dt.AsEnumerable() where myRow.Field(5) >= Convert.ToDateTime(dtime.ToString("yyyy-MM-dd") + " 08:00:00.000") && myRow.Field(6) <= Convert.ToDateTime(dtime.ToString("yyyy-MM-dd") + " 19:59:59.999") select myRow; if (DayList.Count() > 0) { int Day_int = DayList.Sum(p => Convert.ToInt32(p.ItemArray[7])); Day_totalList.Add(Math.Round((Day_int / (double)DayList.Count()) / 60, 2)); } else { Day_totalList.Add(0); } //夜班 var NightList = from myRowNight in dt.AsEnumerable() where myRowNight.Field(5) >= Convert.ToDateTime(dtime.ToString("yyyy-MM-dd") + " 20:00:00.000") && myRowNight.Field(6) <= Convert.ToDateTime(dtime.AddDays(1).ToString("yyyy-MM-dd") + " 07:59:59.999") select myRowNight; if (NightList.Count() > 0) { int Night_int = NightList.Sum(p => Convert.ToInt32(p.ItemArray[7])); Night_totalList.Add(Math.Round((Night_int / (double)NightList.Count()) / 60, 2)); } else { Night_totalList.Add(0); } } List title_ = new List(); title_.Add("班次/日期"); title_.AddRange(titleList); list.Add(title_); List total_ = new List(); total_.Add("白班"); foreach (var item in Day_totalList) { total_.Add(item.ToString()); } list.Add(total_); List No_total_ = new List(); No_total_.Add("夜班"); foreach (var item in Night_totalList) { No_total_.Add(item.ToString()); } list.Add(No_total_); } return list; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } //每月平均换膜次数 public string SearchMonth(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 Day_totalList = 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)); var DayList = from myRow in dt.AsEnumerable() where myRow.Field(5) >= Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01") && myRow.Field(6) <= Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days) select myRow; if (DayList.Count() > 0) { int Day_int = DayList.Sum(p => Convert.ToInt32(p.ItemArray[7])); Day_totalList.Add(Math.Round((Day_int / (double)DayList.Count()) / 60, 2)); } else { Day_totalList.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 Day_totalList) { sb.Append(""); } sb.Append(""); sb.Append("
月份" + item + "
平均换膜时间" + item + "
"); } return sb.ToString(); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public List> SearchMonthForExcel(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 Day_totalList = 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)); var DayList = from myRow in dt.AsEnumerable() where myRow.Field(5) >= Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01") && myRow.Field(6) <= Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days) select myRow; if (DayList.Count() > 0) { int Day_int = DayList.Sum(p => Convert.ToInt32(p.ItemArray[7])); Day_totalList.Add(Math.Round((Day_int / (double)DayList.Count()) / 60, 2)); } else { Day_totalList.Add(0); } } List title_ = new List(); title_.Add("月份"); title_.AddRange(titleList); list.Add(title_); List total_ = new List(); total_.Add("平均换膜时间"); foreach (var item in Day_totalList) { total_.Add(item.ToString()); } list.Add(total_); } return list; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } //每月换膜次数 public string SearchMonthTimes(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 Day_totalList = 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)); var DayList = from myRow in dt.AsEnumerable() where myRow.Field(5) >= Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01") && myRow.Field(6) <= Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days) select myRow; Day_totalList.Add(DayList.Count()); } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in titleList) { sb.Append(""); } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in Day_totalList) { sb.Append(""); } sb.Append(""); sb.Append("
月份" + item + "
换模次数" + item + "
"); } return sb.ToString(); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public List> SearchMonthTimesForExcel(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 Day_totalList = 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)); var DayList = from myRow in dt.AsEnumerable() where myRow.Field(5) >= Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01") && myRow.Field(6) <= Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days) select myRow; Day_totalList.Add(DayList.Count()); } List title_ = new List(); title_.Add("月份"); title_.AddRange(titleList); list.Add(title_); List total_ = new List(); total_.Add("换模次数"); foreach (var item in Day_totalList) { total_.Add(item.ToString()); } list.Add(total_); } return list; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } //换膜记录单 public string SearchChangeRecord(string StartTime, string EndTime, string ModelId) { StringBuilder sb = new StringBuilder(100); DataTable dt = dal.SearchChangeRecord(StartTime, EndTime, ModelId); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); for (int i = 0; i < dt.Rows.Count; i++) { sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); } sb.Append("
机台号日期起始时间总计时间累计合模数生产合模数日期章换膜人
" + dt.Rows[i]["StationNo"] + "" + Convert.ToDateTime(dt.Rows[i]["PrintDate"]).ToString("yyyy-MM-dd") + "" + dt.Rows[i]["StartTime"] + "" + Math.Round((Convert.ToDouble(dt.Rows[i]["DownTime"]) / 60), 2) + "" + dt.Rows[i]["ModelSumCount"] + "" + dt.Rows[i]["ModelPrintCount"] + "" + Convert.ToDateTime(dt.Rows[i]["PrintDate"]).Month + "月" + dt.Rows[i]["remark1"] + "
"); return sb.ToString(); } public List> SearchChangeRecordForExcel(string StartTime, string EndTime, string ModelId) { try { List> list = new List>(); DataTable dt = dal.SearchChangeRecord(StartTime, EndTime, ModelId); List titleList = new List(); titleList.Add("机台号"); titleList.Add("日期"); titleList.Add("起始时间"); titleList.Add("总计时间"); titleList.Add("累计合模数"); titleList.Add("生产合模数"); titleList.Add("日期章"); titleList.Add("换膜人"); list.Add(titleList); for (int i = 0; i < dt.Rows.Count; i++) { List total_ = new List(); total_.Add(dt.Rows[i]["StationNo"].ToString()); total_.Add(Convert.ToDateTime(dt.Rows[i]["PrintDate"]).ToString("yyyy-MM-dd")); total_.Add(dt.Rows[i]["StartTime"].ToString()); total_.Add(Math.Round((Convert.ToDouble(dt.Rows[i]["DownTime"]) / 60), 2).ToString()); total_.Add(dt.Rows[i]["ModelSumCount"].ToString()); total_.Add(dt.Rows[i]["ModelPrintCount"].ToString()); total_.Add(Convert.ToDateTime(dt.Rows[i]["PrintDate"]).Month + "月"); total_.Add(dt.Rows[i]["remark1"].ToString()); list.Add(total_); } return list; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } //维修记录 public string SearchRepairRecord(string StartTime, string EndTime) { try { DateTime sTime = Convert.ToDateTime(StartTime); StringBuilder sb = new StringBuilder(100); DataTable dt = dal.SearchRepaorByTime(StartTime, EndTime); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); 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(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); } } sb.Append("
序号日期班次设备名称故障现象维修时间故障原因维修内容及更换配件维修人
" + (i + 1) + "" + Convert.ToDateTime(dt.Rows[i]["StartTime"]).ToString("yyyy-MM-dd") + "" + CheckWorkClass(dt.Rows[i]["StartTime"].ToString()) + "" + dt.Rows[i]["StationNo"] + "" + dt.Rows[i]["Des"] + "" + dt.Rows[i]["DownTime"] + "" + dt.Rows[i]["Remark2"] + "" + dt.Rows[i]["Remark3"] + "" + dt.Rows[i]["Remark1"] + "
"); return sb.ToString(); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public List> SearchRepairRecordForExcel(string StartTime, string EndTime) { try { List> list = new List>(); DataTable dt = dal.SearchRepaorByTime(StartTime, EndTime); List titleList = new List(); titleList.Add("序号"); titleList.Add("日期"); titleList.Add("班次"); titleList.Add("设备名称"); titleList.Add("故障现象"); titleList.Add("维修时间"); titleList.Add("故障原因"); titleList.Add("维修内容及更换配件"); titleList.Add("维修人"); list.Add(titleList); for (int i = 0; i < dt.Rows.Count; i++) { List total_ = new List(); total_.Add((i + 1).ToString()); total_.Add(Convert.ToDateTime(dt.Rows[i]["StartTime"]).ToString("yyyy-MM-dd")); total_.Add(CheckWorkClass(dt.Rows[i]["StartTime"].ToString())); total_.Add(dt.Rows[i]["StationNo"].ToString()); total_.Add(dt.Rows[i]["Des"].ToString()); total_.Add(dt.Rows[i]["DownTime"].ToString()); total_.Add(dt.Rows[i]["Remark2"].ToString()); total_.Add(dt.Rows[i]["Remark3"].ToString()); total_.Add(dt.Rows[i]["Remark1"].ToString()); list.Add(total_); } return list; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } 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 ""; } #endregion } }