一厂MES,含注塑,喷涂,冲孔
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

670 lines
24 KiB

3 months ago
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<tb_Product> db = new BasicBLL<tb_Product>();
/// <summary>
/// 新增信息
/// </summary>
/// <param name="md"></param>
/// <returns></returns>
public bool AddInfo(tb_Product md)
{
try
{
List<tb_Product>list=new List<tb_Product>();
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;
}
}
/// <summary>
/// 修改信息
/// </summary>
/// <param name="md"></param>
/// <returns></returns>
public bool UpdateInfo(tb_Product md)
{
try
{
List<tb_Product> list = new List<tb_Product>();
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",
3 months ago
"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;
}
}
/// <summary>
/// 删除信息
/// </summary>
/// <param name="md"></param>
/// <param name="flag"></param>
/// <returns></returns>
public bool DeleteInfo(tb_Product md)
{
try
{
return db.DelInfo(md);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
/// <summary>
/// 查询全部信息分页
/// </summary>
/// <returns></returns>
public string SearchInfoAll(string page, string pagesize, string stockNo, string productTypeID, string productName, string partNo)
{
try
{
string jsonStr = "[]";
int total = 0;//总行数
List<tb_Product> list = db.SearchAllInfo();
3 months ago
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<ProductModel> modelList = new List<ProductModel>();
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<tb_ProductType> s_db = new BasicBLL<tb_ProductType>();
BasicBLL<tb_CarType> carTypeDB = new BasicBLL<tb_CarType>();
var s_list = s_db.SearchAllInfo();
var carTypeList = carTypeDB.SearchAllInfo();
foreach (var item in list)
{
ProductModel dm = Tool.Mapper<ProductModel, tb_Product>(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<ProductModel> md = new JsonDataModel<ProductModel>();
md.total = total.ToString();
md.rows = modelList;
jsonStr = JSONTools.ScriptSerialize<JsonDataModel<ProductModel>>(md);
}
return jsonStr;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 查询全部信息
/// </summary>
/// <returns></returns>
public List<tb_Product> 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<tb_Product>(q => q.IsOneMore == isOneMore).ToList().ToSerializer();
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 根据ID查询信息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
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();
}
/// <summary>
/// 2000
/// </summary>
/// <returns></returns>
public string GetComboboxProduct2()
{
return SearchAll().Where(p => p.ProductTypeID == "f3bbde11-7188-4910-855d-806d92d142b9").ToList().ToSerializer();
}
/// <summary>
/// 5000
/// </summary>
/// <returns></returns>
public string GetComboboxProduct3()
{
return SearchAll().Where(p => p.ProductTypeID == "3a8545ee-5979-4780-a5ca-6c5e75685ae2").ToList().ToSerializer();
}
/// <summary>
/// 6000
/// </summary>
/// <returns></returns>
public string GetComboboxProduct4()
{
return SearchAll().Where(p => p.ProductTypeID == "69ec20f1-dab5-4caf-b81e-1c65b38b9e34").ToList().ToSerializer();
}
public string GetComboboxData(string productTypeNo)
{
try
{
BasicBLL<tb_ProductType> productTypeDB = new BasicBLL<tb_ProductType>();
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<tb_ProductType> productTypeDB = new BasicBLL<tb_ProductType>();
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<tb_ProductType> productTypeDB = new BasicBLL<tb_ProductType>();
//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<List<string>> SearchForExcel(string page, string pagesize, string stockNo, string productTypeID, string productName, string partNo)
{
try
{
List<List<string>> list = new List<List<string>>();
string jsonStr = "[]";
int total = 0;//总行数
List<tb_Product> 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<ProductModel> modelList = new List<ProductModel>();
#region 联查
BasicBLL<tb_ProductType> s_db = new BasicBLL<tb_ProductType>();
BasicBLL<tb_CarType> carTypeDB = new BasicBLL<tb_CarType>();
var s_list = s_db.SearchAllInfo();
var carTypeList = carTypeDB.SearchAllInfo();
foreach (var item in listProduct)
{
ProductModel dm = Tool.Mapper<ProductModel, tb_Product>(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<string> title_ = new List<string>();
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<string> titleList = new List<string>();
foreach (var item in modelList)
{
List<string> rowList = new List<string>();
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;
}
}
}
}