using MESClassLibrary.BLL.Log; using MESClassLibrary.EFModel; using MESClassLibrary.Model; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace MESClassLibrary.BLL.Inspection { public class CommonlyInspectionBLL { BasicBLL db = new BasicBLL(); /// /// 查询信息 /// /// public string SearchInfo(string versionID, string checkDate) { try { string jsonStr = "[]"; int total = 0;//总行数 List list = null; list = db.SearchInfoByKey("IsUseing", 1).Where(p => p.VersionID.Equals(versionID)).ToList(); if (list.Count > 0) { BasicBLL CheckItem_db = new BasicBLL(); var CheckItemList = CheckItem_db.SearchAllInfo().ToList(); List CommonlyInspectionList = new List(); foreach (var item in list) { CommonlyInspectionModel dm = Tool.Mapper(item); dm.InspectionContent = CheckItemList.FirstOrDefault(p => p.ID == item.InspectionContentID).CheckContent; CommonlyInspectionList.Add(dm); } jsonStr = JSONTools.ScriptSerialize>(CommonlyInspectionList); } return jsonStr; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return ""; } } /// /// 添加信息 /// /// public bool AddInfo(string CommonlyInspection, string CheckUserID, string ConfirmUserID, string UserID, string CheckDate, string CheckType, string ErrMes) { try { BasicBLL Recorddb = new BasicBLL(); DateTime dtime = DateTime.Now; DateTime checktime = Convert.ToDateTime(CheckDate); string[] arr = CommonlyInspection.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < arr.Length - 1; i++) { int index = arr[i].IndexOf(":"); tb_CommonlyInspectionRecord md = new tb_CommonlyInspectionRecord(); md.ID = Guid.NewGuid().ToString(); md.CommonlyInspectionID = arr[i].Substring(0, index); md.CheckResult = arr[i].Substring(index + 1, arr[i].Length - index - 1); md.CheckUser = CheckUserID; md.ConfirmUser = CheckUserID; md.CreateUserID = UserID; md.CheckDate = checktime; md.CheckType = CheckType; md.ErrMes = ErrMes; md.ConfirmUserDate = dtime; md.CreateTime = dtime; md.IsUseing = 1; Recorddb.AddInfo(md); } return true; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } public bool UpdateInfo(string CommonlyInspection, string CheckUserID, string ConfirmUserID, string UserID, string CheckDate, string CheckType, string ErrMes) { try { string[] proNames = new string[9]; proNames[0] = "CheckResult"; proNames[1] = "CheckUser"; proNames[2] = "CheckDate"; proNames[3] = "ConfirmUser"; proNames[4] = "ConfirmUserDate"; proNames[5] = "UpdateUserID"; proNames[6] = "UpdateTime"; proNames[7] = "CheckType"; proNames[8] = "ErrMes"; BasicBLL Recorddb = new BasicBLL(); DateTime dtime = DateTime.Now; DateTime checktime = Convert.ToDateTime(CheckDate); string[] arr = CommonlyInspection.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < arr.Length - 3; i++) { int index = arr[i].IndexOf(":"); tb_CommonlyInspectionRecord md = new tb_CommonlyInspectionRecord(); md.ID = arr[i].Substring(0, index); md.CheckResult = arr[i].Substring(index + 1, arr[i].Length - index - 1); md.CheckUser = CheckUserID; md.CheckDate = checktime; md.CheckType = CheckType; md.ErrMes = ErrMes; md.ConfirmUser = ConfirmUserID; md.ConfirmUserDate = dtime; md.UpdateUserID = UserID; md.UpdateTime = dtime; //必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化 //如果没有初始化必填字段,更新会报错 md.CreateUserID = ""; md.CommonlyInspectionID = ""; Recorddb.UpdateInfo(md, proNames); } return true; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } public string GetDate(string VersionID, string CheckDate, string CheckType) { try { string str = ""; string CheckUserID = ""; string ConfirmUserID = ""; string ErrMes = ""; BasicBLL db = new BasicBLL(); string jsonStr = "[]"; List list = null; list = db.SearchInfoByKey("IsUseing", 1).Where(p => p.VersionID.Equals(VersionID)).ToList(); if (list.Count > 0) { BasicBLL CheckItem_db = new BasicBLL(); var CheckItemList = CheckItem_db.SearchAllInfo().ToList(); string[] arr_id = list.Select(s => s.ID).ToArray(); BasicBLL CommonlyInspectionRecord_db = new BasicBLL(); var _info = CommonlyInspectionRecord_db.SearchInfoByKey("CheckDate", Convert.ToDateTime(CheckDate)).Where(p => arr_id.Contains(p.CommonlyInspectionID) && p.CheckType.Equals(CheckType)).ToList(); if (_info.Count > 0) { #region 修改 List CommonlyInspectionList = new List(); foreach (var item in list) { CommonlyInspectionModel dm = Tool.Mapper(item); dm.InspectionContent = CheckItemList.FirstOrDefault(p => p.ID.Equals(item.InspectionContentID)).CheckContent; CommonlyInspectionList.Add(dm); } str = ""; str += ""; str += ""; str += ""; str += ""; for (int j = 0; j < CommonlyInspectionList.Count; j++) { str += ""; str += ""; var R_info = _info.FirstOrDefault(p => p.CommonlyInspectionID == CommonlyInspectionList[j].ID); CheckUserID = R_info.CheckUser; ConfirmUserID = R_info.ConfirmUser; ErrMes = R_info.ErrMes; switch (R_info.CheckResult) { case "0": str += ""; break; case "1": str += ""; break; case "2": str += ""; break; case "3": str += ""; break; case "4": str += ""; break; } str += ""; } str += ""; str += ""; str += ""; str += ""; str += "
点检内容检查结果
" + CommonlyInspectionList[j].InspectionContent + "
异常情况描述
"; str += ""; str += ""; str += ""; #endregion } else { #region 新增 List CommonlyInspectionList = new List(); foreach (var item in list) { CommonlyInspectionModel dm = Tool.Mapper(item); dm.InspectionContent = CheckItemList.FirstOrDefault(p => p.ID.Equals(item.InspectionContentID)).CheckContent; CommonlyInspectionList.Add(dm); } str = ""; str += ""; str += ""; str += ""; str += ""; for (int j = 0; j < CommonlyInspectionList.Count; j++) { str += ""; str += ""; str += ""; str += ""; } str += ""; str += ""; str += ""; str += ""; str += "
点检内容检查结果
" + CommonlyInspectionList[j].InspectionContent + "" + "
异常情况描述
"; str += ""; #endregion } } return str; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return ""; } } public string GetReportDate(string VersionID, string CheckDate) { try { string str = ""; List ErrMesList = new List(); BasicBLL dbUser = new BasicBLL(); BasicBLL db = new BasicBLL(); string jsonStr = "[]"; List list = null; list = db.SearchInfoByKey("IsUseing", 1).Where(p => p.VersionID.Equals(VersionID)).ToList(); if (list.Count > 0) { BasicBLL CheckItem_db = new BasicBLL(); var CheckItemList = CheckItem_db.SearchAllInfo().ToList(); string[] arr_id = list.Select(s => s.ID).ToArray(); BasicBLL CommonlyInspectionRecord_db = new BasicBLL(); DateTime StartTime = Convert.ToDateTime(CheckDate + "-01 00:00:00"); DateTime EndTime = StartTime.AddMonths(1); int daynum = GetDays(Convert.ToInt32(CheckDate.Substring(0, 4)), Convert.ToInt32(CheckDate.Substring(5, 2))); var _info = CommonlyInspectionRecord_db.SearchInfoByKey("IsUseing", 1).Where(p => p.CheckDate >= StartTime && p.CheckDate < EndTime && arr_id.Contains(p.CommonlyInspectionID)).ToList(); var userList = dbUser.SearchAllInfo().ToList(); if (_info.Count > 0) { #region 有记录 List CommonlyInspectionList = new List(); foreach (var item in list) { CommonlyInspectionModel dm = Tool.Mapper(item); var IC_info = CheckItemList.FirstOrDefault(p => p.ID.Equals(item.InspectionContentID)); if (IC_info != null) { dm.InspectionContent = IC_info.CheckContent; dm.Standard = IC_info.Standard; dm.Way = IC_info.Way; dm.Cycle = IC_info.Cycle; CommonlyInspectionList.Add(dm); } } str = ""; str += ""; str += ""; str += ""; str += ""; str += ""; str += ""; for (int i = 1; i <= daynum; i++) { str += ""; } str += ""; var info = CommonlyInspectionList.ToList(); for (int j = 0; j < info.Count; j++) { str += ""; str += ""; str += ""; str += ""; str += ""; str += ""; var R_info = _info.Where(p => p.CommonlyInspectionID == info[j].ID); for (int k = 1; k <= daynum; k++) { DateTime dtime = StartTime.AddDays(k - 1); var info_R = R_info.FirstOrDefault(p => p.CheckDate == dtime && p.CheckType.Equals("0")); string CheckResult = ""; if (info_R != null) { if (!String.IsNullOrEmpty(info_R.ErrMes) && !ErrMesList.Contains(dtime.ToString("yyyy-MM-dd") + ":" + info_R.ErrMes)) { ErrMesList.Add(dtime.ToString("yyyy-MM-dd") + ":" + info_R.ErrMes); } //select switch (info_R.CheckResult) { case "0": CheckResult = "▲"; break; case "1": CheckResult = "√"; break; case "2": CheckResult = "◎"; break; case "3": CheckResult = "X"; break; case "4": CheckResult = "☆"; break; } } str += ""; } str += ""; str += ""; for (int k = 1; k <= daynum; k++) { DateTime dtime = StartTime.AddDays(k - 1); var info_R = R_info.FirstOrDefault(p => p.CheckDate == dtime && p.CheckType.Equals("1")); string CheckResult = ""; if (info_R != null) { //是否有异常记录并且没有加入到列表中 if (!String.IsNullOrEmpty(info_R.ErrMes) && !ErrMesList.Contains(dtime.ToString("yyyy-MM-dd") + ":" + info_R.ErrMes)) { ErrMesList.Add(dtime.ToString("yyyy-MM-dd") + ":" + info_R.ErrMes); } switch (info_R.CheckResult) { case "0": CheckResult = "▲"; break; case "1": CheckResult = "√"; break; case "2": CheckResult = "◎"; break; case "3": CheckResult = "X"; break; case "4": CheckResult = "☆"; break; } } str += ""; } str += ""; } str += ""; str += ""; str += ""; for (int i = 1; i <= daynum; i++) { DateTime dtime = StartTime.AddDays(i - 1); var infoUser = _info.FirstOrDefault(p => p.CheckDate == dtime); if (infoUser != null) { str += ""; } else { str += ""; } } str += ""; str += ""; //str += ""; str += ""; for (int i = 1; i <= daynum; i++) { DateTime dtime = StartTime.AddDays(i - 1); var infoUser = _info.FirstOrDefault(p => p.CheckDate == dtime); if (infoUser != null) { str += ""; } else { str += ""; } } str += ""; str += ""; //str += ""; str += ""; for (int i = 1; i <= daynum; i++) { DateTime dtime = StartTime.AddDays(i - 1); var infoUser = _info.FirstOrDefault(p => p.CheckDate == dtime); if (infoUser != null) { str += ""; } else { str += ""; } } str += ""; str += ""; //str += ""; str += ""; for (int i = 1; i <= daynum; i++) { DateTime dtime = StartTime.AddDays(i - 1); var infoUser = _info.FirstOrDefault(p => p.CheckDate == dtime); if (infoUser != null) { str += ""; } else { str += ""; } } str += ""; str += "
序号点检内容点检标准点检方法点检周期" + i + "
" + (j + 1).ToString() + "" + info[j].InspectionContent + "" + info[j].Standard + "" + info[j].Way + "" + info[j].Cycle + "" + CheckResult + "
" + CheckResult + "
日点检确认点检人(白 班)确认签名" + userList.FirstOrDefault(p => p.UserID.ToString().ToUpper().Equals(infoUser.CheckUser.ToUpper())).RealName + "
日点检确认点检人(夜 班)确认签名" + userList.FirstOrDefault(p => p.UserID.ToString().ToUpper().Equals(infoUser.CheckUser.ToUpper())).RealName + "
日点检确认点检人(白班班长)确认签名" + userList.FirstOrDefault(p => p.UserID.ToString().ToUpper().Equals(infoUser.ConfirmUser.ToUpper())).RealName + "
日点检确认点检人(夜班班长)确认签名" + userList.FirstOrDefault(p => p.UserID.ToString().ToUpper().Equals(infoUser.ConfirmUser.ToUpper())).RealName + "
"; if (ErrMesList.Count > 0) { #region 异常情况描述 str += ""; str += ""; str += ""; str += ""; str += ""; str += ""; for (int i = 1; i < ErrMesList.Count; i++) { str += ""; str += ""; str += ""; } str += "
异常情况描述" + ErrMesList[0] + "
" + ErrMesList[i] + "
"; #endregion } #endregion } else { #region 无记录 List CommonlyInspectionList = new List(); foreach (var item in list) { CommonlyInspectionModel dm = Tool.Mapper(item); var IC_info = CheckItemList.FirstOrDefault(p => p.ID.Equals(item.InspectionContentID)); if (IC_info != null) { dm.InspectionContent = IC_info.CheckContent; CommonlyInspectionList.Add(dm); } } str = ""; str += ""; str += ""; str += ""; for (int i = 1; i <= daynum; i++) { str += ""; } str += ""; var info = CommonlyInspectionList.ToList(); for (int j = 0; j < info.Count; j++) { str += ""; str += ""; str += ""; for (int k = 1; k <= daynum; k++) { str += ""; } str += ""; str += ""; for (int k = 1; k <= daynum; k++) { str += ""; } str += ""; } #endregion } } return str; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return ""; } } public static int GetDays(int year, int month) { int days = 0; if (month != 2) { switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: days = 31; break; case 4: case 6: case 9: case 11: days = 30; break; } } else { // 闰年 if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) days = 29; else days = 28; } return days; } } }
序号点检内容" + i + "
" + (j + 1).ToString() + "" + info[j].InspectionContent + "