using MESClassLibrary.BLL.Log; using MESClassLibrary.DAL.Keep; using MESClassLibrary.EFModel; using MESClassLibrary.Model; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Text; namespace MESClassLibrary.BLL.Keep { public class KeepRecordBLL { KeepRecordDAL dal = new KeepRecordDAL(); BBMPTEntities ef = new BBMPTEntities(); BasicBLL db = new BasicBLL(); public string GetDate(string VersionID, string KeepTime, string DeviceID, string KeepLevelID) { 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 KeepLevel_db = new BasicBLL(); var KeepLevelList = KeepLevel_db.SearchAllInfo().ToList(); string level = KeepLevelList.FirstOrDefault(p => p.ID.Equals(KeepLevelID)).KeepLevel; BasicBLL CheckItem_db = new BasicBLL(); var CheckItemList = CheckItem_db.SearchAllInfo().ToList(); if (level.Contains("一")) { CheckItemList = CheckItem_db.SearchAllInfo().Where(p => p.KeepLevelID.Equals(KeepLevelID)).ToList(); string[] itemID = CheckItemList.Select(p => p.ID).ToArray(); list = list.Where(p => itemID.Contains(p.KeepItemsID)).ToList(); } if (level.Contains("二")) { CheckItemList = CheckItem_db.SearchAllInfo().ToList(); } //BasicBLL CheckItem_db = new BasicBLL(); //var CheckItemList = CheckItem_db.SearchAllInfo().ToList(); //BasicBLL KeepLevel_db = new BasicBLL(); //var KeepLevelList = KeepLevel_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(KeepTime)).Where(p => arr_id.Contains(p.KeepItemsVersionID)).ToList(); if (_info.Count > 0) { #region 修改 List CommonlyInspectionList = new List(); foreach (var item in list) { KeepItemsVersionModel dm = Tool.Mapper(item); dm.KeepItems = CheckItemList.FirstOrDefault(p => p.ID.Equals(item.KeepItemsID)).KeepItems; 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.KeepItemsVersionID == CommonlyInspectionList[j].ID); CheckUserID = R_info.CheckUser; ConfirmUserID = R_info.ConfirmUser; //ErrMes = R_info.ErrMes; switch (R_info.Result) { case "0": str += ""; break; case "1": str += ""; break; } str += ""; } //str += ""; //str += ""; //str += ""; //str += ""; str += "
保养内容检查结果
" + CommonlyInspectionList[j].KeepItems + "
异常情况描述
"; str += ""; str += ""; str += ""; #endregion } else { #region 新增 List CommonlyInspectionList = new List(); foreach (var item in list) { KeepItemsVersionModel dm = Tool.Mapper(item); dm.KeepItems = CheckItemList.FirstOrDefault(p => p.ID.Equals(item.KeepItemsID)).KeepItems; 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].KeepItems + "" + "
异常情况描述
"; str += ""; #endregion } } return str; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return ""; } } public bool AddInfo(string CommonlyInspection, string CheckUserID, string ConfirmUserID, string UserID, string CheckDate, string KeepPlanID) { 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_KeepRecord md = new tb_KeepRecord(); md.ID = Guid.NewGuid().ToString(); md.KeepPlanID = KeepPlanID; md.KeepItemsVersionID = arr[i].Substring(0, index); md.Result = 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 KeepPlanID) { try { string[] proNames = new string[6]; proNames[0] = "Result"; proNames[1] = "CheckUser"; proNames[2] = "CheckDate"; proNames[3] = "ConfirmUser"; proNames[4] = "ConfirmUserDate"; //proNames[5] = "UpdateUserID"; proNames[5] = "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_KeepRecord md = new tb_KeepRecord(); md.ID = arr[i].Substring(0, index); md.Result = 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.KeepItemsVersionID = ""; Recorddb.UpdateInfo(md, proNames); } return true; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } public string GetReportDate(string PlanID) { try { string str = ""; str = ""; str += ""; str += ""; str += ""; str += ""; str += ""; str += ""; DataTable dt = dal.SearhByKeepPlanID(PlanID); if (dt != null && dt.Rows.Count > 0) { IList list = Tool.ConvertTo(dt); List deviceNameList = list.GroupBy(p => p.DeviceName).Select(p => p.Key).ToList(); int n = 1; foreach (var item in deviceNameList) { List recordList = list.Where(p => p.DeviceName != null && p.DeviceName.Equals(item)).ToList(); List VersionList = recordList.GroupBy(p => p.Version).Select(p => p.Key).ToList(); if (VersionList.Count > 1) { string version = VersionList.OrderByDescending(p => p).FirstOrDefault(); recordList = recordList.Where(p => p.KeepLevel != null && p.Version.Equals(version)).ToList(); } int k = 1; foreach (var itemRecord in recordList) { if (k == 1) { str += ""; str += ""; str += ""; str += ""; string r = itemRecord.result == "1" ? "√" : "X"; str += ""; str += ""; } else { str += ""; str += ""; string r = itemRecord.result == "1" ? "√" : "X"; str += ""; str += ""; } k++; } n++; } } str += "
序号设备名称保养内容结果
" + n.ToString() + "" + item + "" + itemRecord.KeepItems + "" + r + "
" + itemRecord.KeepItems + "" + r + "
"; return str; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return ""; } } } }