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; namespace MESClassLibrary.BLL.Keep { public class KeepVersionBLL { BasicBLL db = new BasicBLL(); /// /// 新增信息 /// /// /// public bool AddInfo(tb_KeepVersion 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 KeepItemsVersion_db = new BasicBLL(); string[] arry = s.Split(','); for (int i = 0; i < arry.Length; i++) { tb_KeepItemsVersion m = new tb_KeepItemsVersion(); m.ID = Guid.NewGuid().ToString(); m.VersionID = md.ID; m.KeepItemsID = arry[i]; m.CreateUserID = md.CreateUserID; m.CreateTime = md.CreateTime; m.IsUseing = 1; KeepItemsVersion_db.AddInfo(m); } return true; } return false; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 修改信息 /// /// /// public bool UpdateInfo(tb_KeepVersion md) { try { return false; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 删除信息 /// /// /// /// public bool DeleteInfo(tb_KeepVersion md) { try { return db.DelInfo(md); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 查询全部信息分页 /// /// public string SearchInfoAll(string page, string pagesize) { try { string jsonStr = "[]"; int total = 0;//总行数 List list = db.SearchAllInfo(); total = list.Count; int Skipcount = (Convert.ToInt32(page) - 1) * Convert.ToInt32(pagesize); list = list.Skip(Skipcount).Take(Convert.ToInt32(pagesize)).ToList(); JsonDataModel md = new JsonDataModel(); md.total = total.ToString(); md.rows = list; return JSONTools.ScriptSerialize(md); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } /// /// 根据ID查询信息 /// /// /// public tb_KeepVersion SearchInfoByID(string id) { try { return db.SearchInfoByID(id); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } 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 KeepVersionList = 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) { KeepVersionModel 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 = "启用"; } KeepVersionList.Add(dm); } #endregion JsonDataModel md = new JsonDataModel(); md.total = total.ToString(); md.rows = KeepVersionList; jsonStr = JSONTools.ScriptSerialize(md); } return jsonStr; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return ""; } } 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)).OrderByDescending(p=>p.Version).ToList(); } jsonStr = JSONTools.ScriptSerialize(list); return jsonStr; } catch (Exception) { return ""; } } } }