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 CommonlyInspectionVersionBLL { BasicBLL db = new BasicBLL(); /// /// 查询信息 /// /// public string SearchInfo(string page, string pagesize,string deviceID) { try { BasicBLL station_db = new BasicBLL(); BasicBLL device_db = new BasicBLL(); var station_list = station_db.SearchAllInfo().ToList(); var device_list = device_db.SearchAllInfo().ToList(); string jsonStr = "[]"; int total = 0;//总行数 List list = null; list = db.SearchAllInfo().ToList(); if (deviceID != "") { list = list.Where(p => p.DeviceID.Equals(deviceID)).ToList(); } List CommonlyInspectionVersionList = new List(); if (list.Count > 0) { int Skipcount = (Convert.ToInt32(page) - 1) * Convert.ToInt32(pagesize); list = list.Skip(Skipcount).Take(Convert.ToInt32(pagesize)).ToList(); total = list.Count; #region 联查 foreach (var item in list) { CommonlyInspectionVersionModel dm = Tool.Mapper(item); var info = device_list.FirstOrDefault(p => p.DeviceID.Equals(item.DeviceID)); if (info != null) { dm.DeviceID = info.DeviceID; dm.DeviceName = info.DeviceNo + "----" + info.DeviceName; } if (item.IsUseing == 1) { dm.IsUseingName = "启用"; } CommonlyInspectionVersionList.Add(dm); } #endregion JsonDataModel md = new JsonDataModel(); md.total = total.ToString(); md.rows = CommonlyInspectionVersionList; jsonStr = JSONTools.ScriptSerialize>(md); } return jsonStr; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return ""; } } /// /// 添加信息 /// /// 模型对象 /// public bool AddInfo(tb_CommonlyInspectionVersion md, string s) { try { var list = db.SearchInfoByKey("DeviceID", md.DeviceID).Where(p => p.Version == md.Version).ToList();//判断是否有重复数据 if (list.Count > 0) { return false; } if (db.AddInfo(md)) { BasicBLL CommonlyInspection_db = new BasicBLL(); string[] arry = s.Split(','); for (int i = 0; i < arry.Length; i++) { tb_CommonlyInspection m = new tb_CommonlyInspection(); m.ID = Guid.NewGuid().ToString(); m.VersionID = md.ID; m.InspectionContentID = arry[i]; m.CreateUserID = md.CreateUserID; m.CreateTime = md.CreateTime; m.IsUseing = 1; CommonlyInspection_db.AddInfo(m); } return true; } return false; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 修改信息 /// /// 模型对象 /// public bool UpdateInfo(tb_CommonlyInspectionVersion md) { try { //var list = db.SearchInfoByKey("ProductionLineID", md.ProductionLineID).Where(p => p.DeviceNo == md.DeviceNo).ToList();//判断是否有重复数据 //if (list.Count > 0) //{ // return false; //} ////初始化要更新的字段 //string[] proNames = new string[6]; //proNames[0] = "ProductionLineID"; //proNames[1] = "DeviceNo"; //proNames[2] = "DeviceName"; //proNames[3] = "Description"; //proNames[4] = "UpdateUserID"; //proNames[5] = "UpdateTime"; ////必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化 ////如果没有初始化必填字段,更新会报错 //md.CreateUserID = ""; //return db.UpdateInfo(md, proNames); return false; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// 删除生产线信息 public bool DelInfo(tb_CommonlyInspectionVersion md) { try { ////初始化要更新的字段 //string[] proNames = new string[3]; //proNames[0] = "IsUseing"; //proNames[1] = "DisableTime"; //proNames[2] = "DisableUserID"; ////必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化 ////如果没有初始化必填字段,更新会报错 //md.ProductionLineID = 0; //md.DeviceNo = ""; //md.DeviceName = ""; //md.CreateUserID = ""; //return db.UpdateInfo(md, proNames); return false; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } public string GetComboboxData(string deviceID) { try { string jsonStr = "[]"; var list = db.SearchInfoByKey("IsUseing", 1).ToList();//判断是否有重复数据 if (deviceID != null && deviceID != "") { list = list.Where(p => p.DeviceID.Equals(deviceID)).ToList(); } jsonStr = JSONTools.ScriptSerialize>(list); return jsonStr; } catch (Exception) { return ""; } } } }