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.
472 lines
15 KiB
472 lines
15 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
|
||
|
{
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 修改信息
|
||
|
/// </summary>
|
||
|
/// <param name="md"></param>
|
||
|
/// <returns></returns>
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
/// <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();
|
||
|
|
||
|
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();
|
||
|
}
|
||
|
|
||
|
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().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;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|