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; using System.Data; using System.Data.SqlClient; using MESClassLibrary.DAL.BasicInfo; namespace MESClassLibrary.BLL.BasicInfo { public class InjectionPlanBLL { BBMPTEntities ef = new BBMPTEntities(); BasicBLL db = new BasicBLL(); InjectionPlanDAL dal = new InjectionPlanDAL(); /// /// 新增信息 /// /// /// public bool AddInfo(tb_InjectionPlan md) { try { return db.AddInfo(md); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 修改信息 /// /// /// public bool UpdateInfo(tb_InjectionPlan md) { try { //初始化要更新的字段 string[] proNames = new string[9]; proNames[0] = "StationID"; proNames[1] = "BeginTime"; proNames[2] = "StockNo"; proNames[3] = "PlanCount"; proNames[4] = "EndTime"; proNames[5] = "PlanDate"; proNames[6] = "RealCycle"; proNames[7] = "PartNo"; proNames[8] = "ProductNature"; //必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化 //如果没有初始化必填字段,更新会报错 return db.UpdateInfo(md, proNames); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 删除信息 /// /// /// /// public bool DeleteInfo(tb_InjectionPlan 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 stationID, string stockNo) { try { string jsonStr = "[]"; int total = 0;//总行数 List list = db.SearchAllInfo().Where(p => p.IsFinish != 1).ToList(); if (!String.IsNullOrEmpty(stationID)) { list = list.Where(p => p.StationID.Equals(stationID)).ToList(); } if (!String.IsNullOrEmpty(stockNo)) { list = list.Where(p => p.StockNo.Contains(stockNo)).ToList(); } list = list.OrderBy(p => p.BeginTime).ToList(); List modelList = new List(); 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(); #region 联查 BasicBLL product_db = new BasicBLL(); var product_list = product_db.SearchAllInfo(); BasicBLL station_db = new BasicBLL(); var station_list = station_db.SearchAllInfo(); foreach (var item in list) { InjectionPlanModel dm = Tool.Mapper(item); dm.ProductName = ""; var station_info = station_list.FirstOrDefault(p => p.StationID == item.StationID); if (station_info != null) { dm.StationNo = station_info.StationNo; } if (item.PartNo != null && item.PartNo.IndexOf(",") > 0) { string[] arr_PartNo = item.PartNo.Split(','); foreach (var w in arr_PartNo) { var product_info = product_list.FirstOrDefault(p => p.PartNo == w); if (product_info != null) { dm.ProductName = dm.ProductName + product_info.ProductName + ","; } } dm.ProductName = dm.ProductName.Substring(0, dm.ProductName.Length - 1); } else { var product_info = product_list.FirstOrDefault(p => p.PartNo == item.PartNo); if (product_info != null) { dm.ProductName = product_info.ProductName; } } 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 SearchInfoAll2(string page, string pagesize, string stationID, string stockNo, string StartTime, string EndTime) { try { string jsonStr = "[]"; int total = 0;//总行数 total = dal.SearchByTimeCount(stationID, stockNo, StartTime, EndTime); DataTable dt = dal.SearchByTime(Convert.ToInt32(page), Convert.ToInt32(pagesize), stationID, stockNo, StartTime, EndTime); List list = Tool.ConvertTo(dt).ToList(); //List list = ef.tb_InjectionPlan.Where(p => DateTime.Parse(p.BeginTime) >= stime && DateTime.Parse(p.EndTime) <= etime).ToList(); if (!String.IsNullOrEmpty(stationID)) { list = list.Where(p => p.StationID.Equals(stationID)).ToList(); } if (!String.IsNullOrEmpty(stockNo)) { list = list.Where(p => p.StockNo.Contains(stockNo)).ToList(); } list = list.OrderBy(p => p.BeginTime).ToList(); List modelList = new List(); 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(); #region 联查 BasicBLL product_db = new BasicBLL(); var product_list = product_db.SearchAllInfo(); BasicBLL station_db = new BasicBLL(); var station_list = station_db.SearchAllInfo(); foreach (var item in list) { InjectionPlanModel dm = Tool.Mapper(item); var product_info = product_list.FirstOrDefault(p => p.StockNo == item.StockNo); if (product_info != null) { dm.PartNo = product_info.PartNo; dm.ProductName = product_info.ProductName; } var station_info = station_list.FirstOrDefault(p => p.StationID == item.StationID); if (station_info != null) { dm.StationNo = station_info.StationNo; } 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 bool UpdateInfo2(tb_InjectionPlan md) { try { //初始化要更新的字段 string[] proNames = new string[3]; proNames[0] = "workClass"; proNames[1] = "JK_Weight"; proNames[2] = "Waste_Weight"; //必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化 //如果没有初始化必填字段,更新会报错 return db.UpdateInfo(md, proNames); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 查询全部信息 /// /// public List SearchAll() { try { var s_list = db.SearchAllInfo().ToList(); return s_list; } catch (Exception) { return null; } } /// /// 根据ID查询信息 /// /// /// public tb_InjectionPlan SearchInfoByID(string id) { try { return db.SearchInfoByID(id); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public String GetEndTime(tb_InjectionPlan md) { try { BasicBLL Plastic_db = new BasicBLL(); var info = from c in Plastic_db.SearchAllInfo() where c.PartNo == md.PartNo && c.StationID == md.StationID && c.IsBackup == 1 select c.CycleTime; if (info.FirstOrDefault() != null) { double seconds = Convert.ToDouble(info.FirstOrDefault().Value) * Convert.ToDouble(md.PlanCount); return Convert.ToDateTime(md.BeginTime).AddSeconds(seconds).ToString("yyyy-MM-dd HH:mm:ss"); } return md.BeginTime; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public DataTable SearchInfoByName(string StationID) { try { return dal.SearchPlanByStation(StationID); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public DataTable NextSearchInfoByName(string StationID) { try { return dal.NextSearchPlanByStation(StationID); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public bool UpdateFinish(InjectionPlanModel md) { InjectionPlanDAL dal = new InjectionPlanDAL(); try { return dal.UpdateFinish(md); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } public string GetStartTime(string StationID) { var bf = db.SearchInfoByKey("StationID", StationID).OrderByDescending(p => p.EndTime).FirstOrDefault(); if (bf != null) { return bf.EndTime; } return ""; } } }