using MESClassLibrary.BLL.Log; using MESClassLibrary.DAL.ZPPlan; 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.BasicInfo { public class ZPPlanBLL { readonly BasicBLL db = new BasicBLL(); /// /// 新增信息 /// /// /// public bool AddInfo(tb_ZPPlan md) { try { var now = DateTime.Now; md.ID = Guid.NewGuid().ToString(); md.CreateTime = now; md.OrderNo = now.ToString("yyyyMMdd"); md.IsFinish = 0; md.ProductCount = 0; md.BadCount = 0; md.Item = GetItem(md.OrderNo); var result = db.AddInfo(md); return result; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } private int GetItem(string orderNo) { var lastItem = db.Search(q => q.OrderNo == orderNo, q => q.CreateTime).LastOrDefault(); return lastItem == null ? 1 : (lastItem.Item.Value + 1); } /// /// 修改信息 /// /// /// public bool UpdateInfo(tb_ZPPlan md, ref string msg) { try { var data = db.SearchInfoByID(md.ID); if (data.IsFinish == 3) { msg = "该计划已经完成"; return false; } if (data.ProductCount.GetValueOrDefault(0).CompareTo(md.OrderCount) > 0) { msg = "计划数量不能小于完成数量"; return false; } if (data.ProductCount.GetValueOrDefault(0) == 0) { //data.StationID = md.StationID; data.PartNo = md.PartNo; data.OrderDate = md.OrderDate; } //data.IsOneMore = md.IsOneMore; data.OrderCount = md.OrderCount; return db.UpdateInfo(data); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); msg = ex.ToString(); return false; } } /// /// 删除信息 /// /// /// /// public bool DeleteInfo(tb_ZPPlan md) { try { return db.DelInfo(md); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 查询全部信息分页 /// /// public string SearchInfoAll(int page, int pagesize, string startTime, string endTime, string partNo) { try { string jsonStr = "[]"; int total = 0;//总行数 IEnumerable list = SearchDB(startTime, endTime, partNo); if (list.Any()) { List modelList = new List(); total = list.Count(); int Skipcount = (Convert.ToInt32(page) - 1) * Convert.ToInt32(pagesize); list = list.Skip(Skipcount).Take(Convert.ToInt32(pagesize)); ProductBLL prodBll = new ProductBLL(); var prodList = prodBll.SearchAll(); //StationBLL stationBll = new StationBLL(); //var stationList = stationBll.SearchAll(); foreach (var item in list) { var prodInfo = prodList.Where(q => q.PartNo == item.PartNo).FirstOrDefault(); //var stationInfo = stationList.Where(q => q.StationID == item.StationID).FirstOrDefault(); ZPPlanModel zpm = Tool.Mapper(item); //zpm.StationNo = stationInfo == null ? "" : stationInfo.StationNo; zpm.ProductName = prodInfo == null ? "" : prodInfo.ProductName; modelList.Add(zpm); } JsonDataModel md = new JsonDataModel { total = total.ToString(), rows = modelList }; jsonStr = md.ToSerializer(); } return jsonStr; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public List SearchByCreateTime(string startTime, string endTime, string partNo) { IEnumerable list = SearchDB(startTime, endTime, partNo); List modelList = new List(); if (list.Any()) { ProductBLL prodBll = new ProductBLL(); var prodList = prodBll.SearchAll(); StationBLL stationBll = new StationBLL(); var stationList = stationBll.SearchAll(); foreach (var item in list) { var prodInfo = prodList.Where(q => q.PartNo == item.PartNo).FirstOrDefault(); //var stationInfo = stationList.Where(q => q.StationID == item.StationID).FirstOrDefault(); ZPPlanModel zpm = Tool.Mapper(item); //zpm.StationNo = stationInfo == null ? "" : stationInfo.StationNo; zpm.ProductName = prodInfo == null ? "" : prodInfo.ProductName; modelList.Add(zpm); } } return modelList; } public IEnumerable SearchDB(string startTime, string endTime, string partNo) { DateTime st, et; if (!DateTime.TryParse(startTime, out st)) st = DateTime.MinValue; if (!DateTime.TryParse(endTime, out et)) et = DateTime.MaxValue; IEnumerable list; if (string.IsNullOrEmpty(partNo)) { list = db.Search( q => (q.CreateTime >= st && q.CreateTime <= et) && q.IsFinish != 3, q => q.CreateTime); } else { list = db.Search(q => q.PartNo != null && q.PartNo.Contains(partNo) && q.IsFinish == 0, q => q.CreateTime); } return list; } /// /// 查询全部信息 /// /// public List SearchAll() { try { var s_list = db.SearchAllInfo(); return s_list; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } /// /// 根据ID查询信息 /// /// /// public tb_ZPPlan SearchInfoByID(string id) { try { return db.SearchInfoByID(id); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public DataTable GetProductingPlan(string station) { try { ZPPlanDAL dal=new ZPPlanDAL(); return dal.GetProductingPlan(station); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public DataTable GetProductingPlan1(string station,string orderNo) { try { ZPPlanDAL dal = new ZPPlanDAL(); return dal.GetProductingPlan1(station,orderNo); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public DataTable GetPlan(string station, int flag, string planTime) { try { ZPPlanDAL dal = new ZPPlanDAL(); return dal.GetPlan(station, flag,planTime); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public bool updateQty(ZPPlanModel md) { try { ZPPlanDAL dal = new ZPPlanDAL(); return dal.updateQty(md); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } public bool updateBad(ZPPlanModel md) { try { ZPPlanDAL dal = new ZPPlanDAL(); return dal.updateBad(md); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } public DataTable SearchPlanInfo(string planID) { try { ZPPlanDAL dal = new ZPPlanDAL(); return dal.SearchPlanInfo(planID); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public DataTable SearchOrderNo(string orderno) { try { ZPPlanDAL dal = new ZPPlanDAL(); return dal.SearchOrderNo(orderno); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod()); return null; } } } }