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; using MESClassLibrary.DAL.BasicInfo; 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);//判断是否有重复数据 list = db.SearchInfoByKey("PartNo", md.PartNo);//判断是否有重复数据 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 && p.ProductID != md.ProductID).ToList();//判断是否有重复数据 if (list.Count > 0) { return false; } //初始化要更新的字段 string[] proNames = new string[12]; proNames[0] = "ProductTypeID"; proNames[1] = "PartName"; proNames[2] = "ProductName"; proNames[3] = "ColorName"; proNames[4] = "PartNo"; proNames[5] = "Rows"; proNames[6] = "Cols"; proNames[7] = "Layers"; proNames[8] = "Des"; proNames[9] = "isImport"; proNames[10] = "ProjectID"; proNames[11] = "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(); var s_list = s_db.SearchAllInfo(); BasicBLL p_db = new BasicBLL(); var p_list = p_db.SearchAllInfo(); foreach (var item in list) { ProductModel dm = Tool.Mapper(item); var info = s_list.FirstOrDefault(p => p.ProductTypeID == item.ProductTypeID); if (info != null) { dm.ProductTypeName = info.ProductTypeName; } var info1 = p_list.FirstOrDefault(p => p.ID == item.ProjectID); if (info1 != null) { dm.Project = info1.Project; } 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; } } /// /// 根据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 GetComboboxData(string productTypeNo, string productTypeNo1) { try { string jsonStr = "[]"; BasicBLL productTypeDB = new BasicBLL(); if (!string.IsNullOrWhiteSpace(productTypeNo1)) { 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 || grp.ProductTypeNo == productTypeNo1 select new {m.PartNo, PartName = m.PartNo + "----" + m.ProductName}; jsonStr = JSONTools.ScriptSerialize(info); } else { 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 }; 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 GetComboboxProduct1(string productTypeNo) { try { List list=new List(); string sql = @"SELECT dbo.tb_Product.ProductID, dbo.tb_Product.ProductName, dbo.tb_ProductType.ProductTypeNo FROM dbo.tb_Product LEFT OUTER JOIN dbo.tb_ProductType ON dbo.tb_Product.ProductTypeID = dbo.tb_ProductType.ProductTypeID where dbo.tb_ProductType.ProductTypeNo='"+ productTypeNo+ @"'"; DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql).Tables[0]; if (dt != null && dt.Rows.Count > 0) { list = Tool.ConvertTo(dt).ToList(); } string jsonStr = "[]"; jsonStr = JSONTools.ScriptSerialize(list); 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).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 => p.ProductTypeID == "f3bbde11-7188-4910-855d-806d92d142b9" && p.StockNo != null) //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 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; } } } }