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 { Listlist=new List(); if (!string.IsNullOrEmpty(md.StockNo)) { list = db.SearchAllInfo().Where(p => p.StockNo == md.StockNo || p.PartNo == md.PartNo) .ToList(); //判断是否有重复数据 } else { list = db.SearchAllInfo().Where(p => p.PartNo == md.PartNo) .ToList(); //判断是否有重复数据 } if (list.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 { List list = new List(); if (!string.IsNullOrEmpty(md.StockNo)) { list = db.SearchAllInfo().Where(p => p.StockNo == md.StockNo && p.ProductID != md.ProductID || p.PartNo == md.PartNo && p.ProductID != md.ProductID) .ToList(); //判断是否有重复数据 } else { list = db.SearchAllInfo().Where(p => p.PartNo == md.PartNo && p.ProductID != md.ProductID) .ToList(); //判断是否有重复数据 } //var list = db.SearchAllInfo().Where(p => p.StockNo == md.StockNo && p.ProductID != md.ProductID || p.PartNo == md.PartNo && 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", "PackCountSize", "OpenFailNum", "QLevel", "IsPrintOneTag", "IsPrintPackList", "IsSupply", "IsOneMore", "BackPlatingNum", "IsPlating", "IsSame", "CustomerNo", "CarModelCode", "ColorCodeB", "UserID", "IsHigh" }; //必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化 //如果没有初始化必填字段,更新会报错 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(); } /// /// 2000 /// /// public string GetComboboxProduct2() { return SearchAll().Where(p => p.ProductTypeID == "f3bbde11-7188-4910-855d-806d92d142b9").ToList().ToSerializer(); } /// /// 5000 /// /// public string GetComboboxProduct3() { return SearchAll().Where(p => p.ProductTypeID == "3a8545ee-5979-4780-a5ca-6c5e75685ae2").ToList().ToSerializer(); } /// /// 6000 /// /// public string GetComboboxProduct4() { return SearchAll().Where(p => p.ProductTypeID == "69ec20f1-dab5-4caf-b81e-1c65b38b9e34").ToList().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().Where(p => p.StockNo != null || p.StockNo != String.Empty).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 }; var info = from m in db.SearchAllInfo().Where(p => !String.IsNullOrEmpty(p.StockNo)).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; } } public List> SearchForExcel(string page, string pagesize, string stockNo, string productTypeID, string productName, string partNo) { try { List> list = new List>(); string jsonStr = "[]"; int total = 0;//总行数 List listProduct = db.SearchAllInfo(); if (!String.IsNullOrEmpty(stockNo)) { listProduct = listProduct.Where(p => p.StockNo != null && p.StockNo.Contains(stockNo)).ToList(); } if (!String.IsNullOrEmpty(productTypeID)) { listProduct = listProduct.Where(p => p.ProductTypeID.Equals(productTypeID)).ToList(); } if (!String.IsNullOrEmpty(productName)) { listProduct = listProduct.Where(p => p.ProductName != null && p.ProductName.Contains(productName)).ToList(); } if (!String.IsNullOrEmpty(partNo)) { listProduct = listProduct.Where(p => p.PartNo != null && p.PartNo.Contains(partNo)).ToList(); } List modelList = new List(); #region 联查 BasicBLL s_db = new BasicBLL(); BasicBLL carTypeDB = new BasicBLL(); var s_list = s_db.SearchAllInfo(); var carTypeList = carTypeDB.SearchAllInfo(); foreach (var item in listProduct) { 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 if (modelList != null && modelList.Count() > 0) { List title_ = new List(); title_.Add("类别名称"); title_.Add("存货代码"); title_.Add("车型"); title_.Add("是否进口"); title_.Add("产品名称"); title_.Add("颜色名称"); title_.Add("零件号"); title_.Add("行数"); title_.Add("列数"); title_.Add("层数"); title_.Add("描述"); title_.Add("标准包装量"); title_.Add("开机报废数"); title_.Add("Q等级"); title_.Add("可喷涂次数"); title_.Add("客户编号"); title_.Add("车型编号"); title_.Add("颜色编号"); title_.Add("打印单个标签"); title_.Add("直供件"); title_.Add("打印装箱单"); title_.Add("一模多具"); title_.Add("是否左右"); title_.Add("喷涂"); list.Add(title_); List titleList = new List(); foreach (var item in modelList) { List rowList = new List(); rowList.Add(item.ProductTypeName == null ? "" : item.ProductTypeName); rowList.Add(item.StockNo == null ? "" : item.StockNo); rowList.Add(item.CarTypeName == null ? "" : item.CarTypeName); rowList.Add(item.isImport == 0 ? "否" : "是"); rowList.Add(item.ProductName == null ? "" : item.ProductName); rowList.Add(item.ColorName == null ? "" : item.ColorName); rowList.Add(item.PartNo == null ? "" : item.PartNo); rowList.Add(item.Rows == null ? "0" : item.Rows.ToString()); rowList.Add(item.Cols == null ? "0" : item.Cols.ToString()); rowList.Add(item.Layers == null ? "0" : item.Layers.ToString()); rowList.Add(item.Des == null ? "" : item.Des); rowList.Add(item.PackCount == null ? "0" : item.PackCount.ToString()); rowList.Add(item.OpenFailNum == null ? "0" : item.OpenFailNum.ToString()); rowList.Add(item.QLevel == null ? "" : item.QLevel); rowList.Add(item.BackPlatingNum == null ? "0" : item.BackPlatingNum.ToString()); rowList.Add(item.CustomerNo == null ? "" : item.CustomerNo); rowList.Add(item.CarModelCode == null ? "" : item.CarModelCode); rowList.Add(item.ColorCodeB == null ? "" : item.ColorCodeB); rowList.Add(item.IsPrintOneTag == "0" ? "否" : "是"); rowList.Add(item.IsSupply == "0" ? "否" : "是"); rowList.Add(item.IsPrintPackList == "0" ? "否" : "是"); rowList.Add(item.IsOneMore == "0" ? "否" : "是"); rowList.Add(item.IsSame == 0 ? "否" : "是"); rowList.Add(item.IsPlating == "0" ? "否" : "是"); list.Add(rowList); } } return list; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public int SearchIntByStockNoAndPartNo(string stockNo, string partNo) { try { var list = db.SearchAllInfo().Where(p => p.StockNo == stockNo && p.PartNo == partNo).ToList();//判断是否有重复数据 return list.Count(); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return 0; } } } }