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.Plan247 { public class Plan247BLL { BBMPTEntities ef = new BBMPTEntities(); BasicBLL db = new BasicBLL(); /// /// 新增信息 /// /// /// public bool AddInfo(tb_Plan_247 md) { try { var list = ef.tb_Plan_247.Where(p => p.OrderNo != null && p.OrderNo.Contains(md.OrderNo.Substring(0, 8)) && p.PartNo.Equals(md.PartNo)).ToList(); if (list != null && list.Count > 0) { return false; } return db.AddInfo(md); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 修改信息 /// /// /// public bool UpdateInfo(tb_Plan_247 md) { try { //初始化要更新的字段 string[] proNames = new string[1]; proNames[0] = "OrderCount"; //必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化 //如果没有初始化必填字段,更新会报错 return db.UpdateInfo(md, proNames); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 删除信息 /// /// /// /// public bool DeleteInfo(tb_Plan_247 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 StartTime, string EndTime, string OrderNo) { try { string jsonStr = "[]"; int total = 0;//总行数 DateTime stime = Convert.ToDateTime(StartTime + " 00:00:00"); DateTime etime = Convert.ToDateTime(EndTime + " 23:59:59"); List list = ef.tb_Plan_247.Where(p => p.CreateTime >= stime && p.CreateTime <= etime).OrderBy(p => p.CreateTime).ToList(); if (!String.IsNullOrEmpty(OrderNo)) { list = list.Where(p => p.OrderNo != null && p.OrderNo.Contains(OrderNo)).OrderBy(p => p.CreateTime).ToList(); } if (list.Count > 0) { 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 联查 var listModel = ef.tb_Mistake_247.ToList(); foreach (var item in list) { tb_Plan_247Model dm = Tool.Mapper(item); var machine_info = listModel.FirstOrDefault(p => p.PartNo2 == item.PartNo); if (machine_info != null) { dm.PartName = machine_info.PartName2; } modelList.Add(dm); } #endregion JsonDataModel md = new JsonDataModel(); md.total = total.ToString(); md.rows = modelList; jsonStr = JSONTools.ScriptSerialize(md); } return jsonStr; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public string SearchOrderNo(string StartTime) { try { string jsonStr = ""; string orderNo = Convert.ToDateTime(StartTime).ToString("yyyyMMdd"); var info = ef.tb_Plan_247.Where(p => p.OrderNo != null && p.OrderNo.Contains(orderNo)).OrderByDescending(p => p.OrderNo).FirstOrDefault(); if (info != null) { return (Convert.ToInt64(info.OrderNo) + 1).ToString(); } else { return orderNo + "0001"; } } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return ""; } } public string GetComboboxData() { try { string jsonStr = "[]"; var list = ef.tb_Mistake_247.ToList();//判断是否有重复数据 jsonStr = JSONTools.ScriptSerialize(list); return jsonStr; } catch (Exception) { return ""; } } public string GetMistake(string id) { try { string jsonStr = "[]"; var list = ef.tb_Mistake_247.Where(p => p.ID.Equals(id)).FirstOrDefault();//判断是否有重复数据 jsonStr = JSONTools.ScriptSerialize(list); return jsonStr; } catch (Exception) { return null; } } public string QueryForComboboxOrderNo(string StartTime) { try { string jsonStr = "[]"; List list = new List(); string orderNo = Convert.ToDateTime(StartTime).ToString("yyyyMMdd"); var info = ef.tb_Plan_247.Where(p => p.OrderNo != null && p.OrderNo.Contains(orderNo)).GroupBy(p => p.OrderNo).Select(p => p.Key).ToList();//判断是否有重复数据 foreach (var item in info) { SelectModel md = new SelectModel(); md.textField = item; md.valueField = item; list.Add(md); } jsonStr = JSONTools.ScriptSerialize(list); return jsonStr; } catch (Exception) { return ""; } } public string QueryForItem(string OrderNo) { try { var info = ef.tb_Plan_247.Where(p => p.OrderNo.Equals(OrderNo)).OrderByDescending(p => p.Item).FirstOrDefault();//判断是否有重复数据 return (info.Item + 1).ToString(); } catch (Exception) { return ""; } } //校验是否生成计划单号日期部分+零件号有相同的计划 public bool QueryByOrderNo(string OrderNo, string PartNo) { try { var info = ef.tb_Plan_247.Where(p => p.OrderNo != null && p.OrderNo.Contains(OrderNo) && p.PartNo.Equals(PartNo)); if (info.Count() > 0) { return true; } return false; } catch (Exception) { return false; } } //校验是否同一个生成计划单号下有相同序号的计划 public bool QueryByOrderNoAndItem(string OrderNo, int Item) { try { var info = ef.tb_Plan_247.Where(p => p.OrderNo.Equals(OrderNo) && p.Item == Item); if (info.Count() > 0) { return true; } return false; } catch (Exception) { return false; } } } }