using MESClassLibrary.BLL.Log; using MESClassLibrary.EFModel; using MESClassLibrary.Model; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace MESClassLibrary.BLL.BasicInfo { public class PaintInfoBLL { BasicBLL dbPB = new BasicBLL(); BasicBLL db = new BasicBLL(); /// /// 新增信息 /// /// /// public bool AddInfo(tb_PaintInfo md) { try { var list = db.SearchInfoByKey("PaintCode", md.PaintCode);//判断是否有重复数据 if (list != null) { if (list.Where(p => p.ID != md.ID && p.IsUsing == 1).Count() > 0) { return false; } } return db.AddInfo(md); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 修改信息 /// /// /// public bool UpdateInfo(tb_PaintInfo md) { try { var list = db.SearchAllInfo().Where(p => p.PaintCode == md.PaintCode && p.ID != md.ID && p.IsUsing == 1).ToList();//判断是否有重复数据 if (list.Count > 0) { return false; } //初始化要更新的字段 string[] proNames = new string[5]; proNames[0] = "PaintCode"; proNames[1] = "PaintName"; proNames[2] = "PaintModel"; //proNames[3] = "UnitCode"; proNames[3] = "CarModelCode"; proNames[4] = "IsUsing"; //必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化 //如果没有初始化必填字段,更新会报错 //md.Des = ""; return db.UpdateInfo(md, proNames); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 删除信息 /// /// /// /// public bool DeleteInfo(tb_PaintInfo md) { try { return db.DelInfo(md); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 查询全部信息分页 /// /// public string SearchInfoAll(string page, string pagesize, string PaintCode) { try { string jsonStr = "[]"; int total = 0;//总行数 List list = db.SearchAllInfo(); if (!String.IsNullOrEmpty(PaintCode)) { list = list.Where(p => p.PaintCode.Contains(PaintCode)).ToList(); } 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_PaintInfo SearchInfoByID(string id) { try { return db.SearchInfoByID(id); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public string GetComboboxData() { try { string jsonStr = "[]"; var list = db.SearchAllInfo().ToList();//判断是否有重复数据 List sl = new List(); foreach (var item in list) { SelectModel md = new SelectModel(); md.textField = item.PaintCode + "--" + item.PaintName; md.valueField = item.ID; sl.Add(md); } jsonStr = JSONTools.ScriptSerialize(sl); return jsonStr; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return ""; } } public string SearchRelation(string page, string pagesize, string PaintID, string BucketID) { try { string jsonStr = "[]"; int total = 0;//总行数 List list = dbPB.SearchAllInfo(); if (!String.IsNullOrEmpty(PaintID)) { list = list.Where(p => p.PaintID == PaintID).ToList(); } if (!String.IsNullOrEmpty(BucketID)) { list = list.Where(p => p.BucketID == BucketID).ToList(); } total = list.Count; int Skipcount = (Convert.ToInt32(page) - 1) * Convert.ToInt32(pagesize); list = list.Skip(Skipcount).Take(Convert.ToInt32(pagesize)).ToList(); List modelList = new List(); #region 联查 BasicBLL PaintInfo_db = new BasicBLL(); var PaintInfo_list = PaintInfo_db.SearchAllInfo(); BasicBLL BucketInfo_db = new BasicBLL(); var BucketInfo_list = BucketInfo_db.SearchAllInfo(); foreach (var item in list) { Paint_BucketModel dm = Tool.Mapper(item); var PaintInfo_info = PaintInfo_list.FirstOrDefault(p => p.ID == item.PaintID); if (PaintInfo_info != null) { dm.PaintCode = PaintInfo_info.PaintCode; dm.PaintName = PaintInfo_info.PaintName; } var BucketInfo_info = BucketInfo_list.FirstOrDefault(p => p.ID == item.BucketID); if (BucketInfo_info != null) { dm.BucketCode = BucketInfo_info.BucketCode; dm.BucketName = BucketInfo_info.BucketName; } modelList.Add(dm); } #endregion JsonDataModel md = new JsonDataModel(); md.total = total.ToString(); md.rows = modelList; return JSONTools.ScriptSerialize(md); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } /// /// 新增信息 /// /// /// public bool AddRelation(tb_Paint_Bucket md) { try { var list = dbPB.SearchAllInfo().Where(p => p.PaintID == md.PaintID && p.BucketID == md.BucketID).ToList();//判断是否有重复数据 if (list.Count > 0) { return false; } return dbPB.AddInfo(md); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 修改信息 /// /// /// public bool UpdateRelation(tb_Paint_Bucket md) { try { var list = dbPB.SearchAllInfo().Where(p => p.PaintID == md.PaintID && p.ID != md.ID && p.BucketID == md.BucketID).ToList();//判断是否有重复数据 if (list.Count > 0) { return false; } //初始化要更新的字段 string[] proNames = new string[2]; proNames[0] = "PaintID"; proNames[1] = "BucketID"; //必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化 //如果没有初始化必填字段,更新会报错 //md.Des = ""; return dbPB.UpdateInfo(md, proNames); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } public bool DeleteRelation(tb_Paint_Bucket md) { try { List ef = dbPB.SearchInfoByKey("ID", md.ID); if (ef!=null && ef.Count>0) { return dbPB.DelInfo(ef.First()); } return false; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } } }