using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Text; using MESClassLibrary.BLL.Log; using MESClassLibrary.DAL.BasicInfo; using MESClassLibrary.EFModel; using MESClassLibrary.Model; namespace MESClassLibrary.BLL { public class PlasticBLL { BBMPTEntities ef = new BBMPTEntities(); BasicBLL db = new BasicBLL(); /// /// 新增信息 /// /// /// public bool AddInfo(tb_Plastic md) { try { var list = db.SearchInfoByKey("StationID", md.StationID);//判断是否有重复数据 if (list != null && list.Count > 0) { if (list.Where(p => p.StockNo.Equals(md.StockNo)).Count() > 0) { return false; } } return db.AddInfo(md); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 修改信息 /// /// /// public bool UpdateInfo(tb_Plastic md) { try { //初始化要更新的字段 string[] proNames = new string[7]; proNames[0] = "CycleTime"; proNames[1] = "StationID"; proNames[2] = "IsBackup"; proNames[3] = "Weight"; proNames[4] = "OpenDebugTime"; proNames[5] = "PrinterNo"; proNames[6] = "PartNo"; //必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化 //如果没有初始化必填字段,更新会报错 return db.UpdateInfo(md, proNames); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 删除信息 /// /// /// /// public bool DeleteInfo(tb_Plastic 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 stockNo, string partNo, string StationID) { try { string jsonStr = "[]"; int total = 0;//总行数 List list = db.SearchAllInfo(); if (!String.IsNullOrEmpty(stockNo)) { list = list.Where(p => p.StockNo != null && p.StockNo.Contains(stockNo)).ToList(); } if (!String.IsNullOrEmpty(StationID)) { list = list.Where(p => p.StationID.Equals(StationID)).ToList(); } if (!String.IsNullOrEmpty(partNo)) { list = list.Where(p => p.PartNo.Equals(partNo)).ToList(); } List modelList = new List(); if (list.Count > 0) { #region 联查 BasicBLL product_db = new BasicBLL(); var product_list = product_db.SearchAllInfo(); BasicBLL machine_db = new BasicBLL(); var machine_list = machine_db.SearchAllInfo(); foreach (var item in list) { PlasticModel dm = Tool.Mapper(item); var product_info = product_list.FirstOrDefault(p => p.StockNo == item.StockNo); if (product_info != null) { dm.PartNo = product_info.PartNo; } var machine_info = machine_list.FirstOrDefault(p => p.StationID == item.StationID); if (machine_info != null) { dm.StationNo = machine_info.StationNo; } modelList.Add(dm); } #endregion total = modelList.Count; int Skipcount = (Convert.ToInt32(page) - 1) * Convert.ToInt32(pagesize); modelList = modelList.Skip(Skipcount).Take(Convert.ToInt32(pagesize)).ToList(); 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 List SearchAll() { try { var s_list = db.SearchAllInfo().ToList(); return s_list; } catch (Exception) { return null; } } /// /// 根据ID查询信息 /// /// /// public tb_Plastic SearchInfoByID(string id) { try { return db.SearchInfoByID(id); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public string QueryForCombobox(string StationID) { try { var info = from m in ef.tb_Plastic join s in ef.tb_Product on m.StockNo equals s.StockNo into val2Grp from grp in val2Grp.DefaultIfEmpty() where m.StationID == StationID select new { c_id = grp.PartNo, c_text = grp.PartNo + "--" + grp.ProductName}; string jsonStr = "[]"; jsonStr = JSONTools.ScriptSerialize(info); return jsonStr; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return ""; } } public DataTable SearchInfo(string partNo,string stationID) { PlasticDAL da = new PlasticDAL(); try { return da.SearchInfo(partNo, stationID); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public DataTable SearchAllInfo(string stationID) { PlasticDAL da = new PlasticDAL(); try { return da.SearchAllInfo(stationID); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public DataTable SearchPartByStation(string stationNo) { PlasticDAL da = new PlasticDAL(); try { return da.SearchPartByStation(stationNo); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } } }