using MESClassLibrary.BLL.Log; using MESClassLibrary.DAL.BasicInfo; using MESClassLibrary.EFModel; using MESClassLibrary.Model; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; namespace MESClassLibrary.BLL.BasicInfo { public class ProductBLL { BasicBLL db = new BasicBLL(); /// /// 新增信息 /// /// /// public bool AddInfo(tb_Product md) { try { var list = db.SearchInfoByKey("StockNo", md.StockNo);//判断是否有重复数据 if (list != null) { if (list.Where(p => p.ProductID != md.ProductID).Count() > 0) { return false; } } return db.AddInfo(md); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 修改信息 /// /// /// public bool UpdateInfo(tb_Product md) { try { var list = db.SearchAllInfo().Where(p => p.StockNo == md.StockNo && p.ProductID != md.ProductID).ToList();//判断是否有重复数据 if (list.Count > 0) { return false; } //初始化要更新的字段 string[] proNames = new string[] { "StockNo", "ProductTypeID", "CarTypeID", "PartName", "ProductName", "ColorName", "PartNo", "Rows", "Cols", "Layers", "Des", "isImport", "PackCount", "OpenFailNum", "QLevel", "IsPrintOneTag", "IsPrintPackList", "IsSupply", "IsOneMore", "BackPlatingNum", "IsPlating", "IsSame" }; //必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化 //如果没有初始化必填字段,更新会报错 md.PicturePath = ""; return db.UpdateInfo(md, proNames); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 删除信息 /// /// /// /// public bool DeleteInfo(tb_Product 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 productTypeID, string productName, string partNo) { 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(productTypeID)) { list = list.Where(p => p.ProductTypeID.Equals(productTypeID)).ToList(); } if (!String.IsNullOrEmpty(productName)) { list = list.Where(p => p.ProductName != null && p.ProductName.Contains(productName)).ToList(); } if (!String.IsNullOrEmpty(partNo)) { list = list.Where(p => p.PartNo != null && p.PartNo.Contains(partNo)).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 s_db = new BasicBLL(); BasicBLL carTypeDB = new BasicBLL(); var s_list = s_db.SearchAllInfo(); var carTypeList = carTypeDB.SearchAllInfo(); foreach (var item in list) { ProductModel dm = Tool.Mapper(item); var info = s_list.FirstOrDefault(p => p.ProductTypeID == item.ProductTypeID); var cartype = carTypeList.FirstOrDefault(p => p.ID == item.CarTypeID); if (info != null) { dm.ProductTypeName = info.ProductTypeName; } if (cartype != null) { dm.CarTypeName = cartype.CarTypeName; } 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 List SearchAll() { try { var s_list = db.SearchAllInfo().ToList(); return s_list; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public string SearchInfoByIsOneMore(string isOneMore) { try { return db.Search(q => q.IsOneMore == isOneMore).ToList().ToSerializer(); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } /// /// 根据ID查询信息 /// /// /// public tb_Product SearchInfoByID(string id) { try { return db.SearchInfoByID(id); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public string GetComboboxProductAll() { return SearchAll().ToSerializer(); } public string GetComboboxData(string productTypeNo) { try { BasicBLL productTypeDB = new BasicBLL(); var info = from m in db.SearchAllInfo().ToList() join s in productTypeDB.SearchAllInfo().ToList() on m.ProductTypeID equals s.ProductTypeID into val2Grp from grp in val2Grp.DefaultIfEmpty() where grp.ProductTypeNo == productTypeNo select new { m.PartNo, PartName = m.PartNo + "----" + m.ProductName }; string jsonStr = "[]"; jsonStr = JSONTools.ScriptSerialize(info); return jsonStr; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return ""; } } public string GetComboboxProduct(string productTypeNo) { try { BasicBLL productTypeDB = new BasicBLL(); var info = from m in db.SearchAllInfo().ToList() join s in productTypeDB.SearchAllInfo().ToList() on m.ProductTypeID equals s.ProductTypeID into val2Grp from grp in val2Grp.DefaultIfEmpty() where grp.ProductTypeNo == productTypeNo select new { m.ProductID, m.ProductName }; string jsonStr = "[]"; jsonStr = JSONTools.ScriptSerialize(info); return jsonStr; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return ""; } } public string GetComboboxDataForStockNo(string productTypeNo) { try { BasicBLL productTypeDB = new BasicBLL(); var info = from m in db.SearchAllInfo().ToList() join s in productTypeDB.SearchAllInfo().ToList() on m.ProductTypeID equals s.ProductTypeID into val2Grp from grp in val2Grp.DefaultIfEmpty() where grp.ProductTypeNo == productTypeNo select new { c_id = m.StockNo, c_text = m.PartNo + "--" + m.ProductName, c_name = m.StockNo + "--" + m.ProductName,c_name2 = m.PartNo }; string jsonStr = "[]"; jsonStr = JSONTools.ScriptSerialize(info); return jsonStr; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return ""; } } public DataTable SearchInfoByType(string type, string stationNo) { ProductDAL da = new ProductDAL(); try { return da.SearchInfoByType(type, stationNo); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public DataTable SearchInfoAllByType(string type) { ProductDAL da = new ProductDAL(); try { return da.SearchInfoAllByType(type); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public DataTable SearchInfoByName(string productName, string ProductTypeNo) { ProductDAL da = new ProductDAL(); try { return da.SearchInfoByName(productName, ProductTypeNo); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public DataTable SearchInfoByPartNo(string partNo) { ProductDAL da = new ProductDAL(); try { return da.SearchInfoByPartNo(partNo); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public DataTable SearchIsImportByStockNo(string stockNo) { ProductDAL da = new ProductDAL(); try { return da.SearchIsImportByStockNo(stockNo); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public DataTable SearchIsImportByPartNo(string partNo) { ProductDAL da = new ProductDAL(); try { return da.SearchIsImportByPartNo(partNo); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public DataTable SearchInfoByProductName(string ProductName) { ProductDAL da = new ProductDAL(); try { return da.SearchInfoByProductName(ProductName); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public bool UpdatePDF(string id, string fileName) { try { tb_Product md = new tb_Product(); md.ProductID = id; md.PicturePath = fileName; //初始化要更新的字段 string[] proNames = new string[1]; proNames[0] = "PicturePath"; //必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化 //如果没有初始化必填字段,更新会报错 return db.UpdateInfo(md, proNames); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } public DataTable SearchInfoAll() { ProductDAL da = new ProductDAL(); try { return da.SearchInfoAll(); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public DataTable SearchInfoByStock(string StockNo) { ProductDAL da = new ProductDAL(); try { return da.SearchInfoByStock(StockNo); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } } }