一厂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.

336 lines
10 KiB

3 months ago
using MESClassLibrary.BLL.Log;
using MESClassLibrary.EFModel;
using MESClassLibrary.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace MESClassLibrary.BLL.BasicInfo
{
public class PaintInfoBLL
{
BasicBLL<tb_Paint_Bucket> dbPB = new BasicBLL<tb_Paint_Bucket>();
BasicBLL<tb_PaintInfo> db = new BasicBLL<tb_PaintInfo>();
/// <summary>
/// 新增信息
/// </summary>
/// <param name="md"></param>
/// <returns></returns>
public bool AddInfo(tb_PaintInfo md)
{
try
{
var list = db.SearchInfoByKey("PaintCode", md.PaintCode);//判断是否有重复数据
if (list != null)
{
if (list.Where(p => p.ID != md.ID && p.IsUsing == 1).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_PaintInfo md)
{
try
{
var list = db.SearchAllInfo().Where(p => p.PaintCode == md.PaintCode && p.ID != md.ID && p.IsUsing == 1).ToList();//判断是否有重复数据
if (list.Count > 0)
{
return false;
}
//初始化要更新的字段
string[] proNames = new string[5];
proNames[0] = "PaintCode";
proNames[1] = "PaintName";
proNames[2] = "PaintModel";
//proNames[3] = "UnitCode";
proNames[3] = "CarModelCode";
proNames[4] = "IsUsing";
//必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化
//如果没有初始化必填字段,更新会报错
//md.Des = "";
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_PaintInfo 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 PaintCode)
{
try
{
string jsonStr = "[]";
int total = 0;//总行数
List<tb_PaintInfo> list = db.SearchAllInfo();
if (!String.IsNullOrEmpty(PaintCode))
{
list = list.Where(p => p.PaintCode.Contains(PaintCode)).ToList();
}
total = list.Count;
int Skipcount = (Convert.ToInt32(page) - 1) * Convert.ToInt32(pagesize);
list = list.Skip(Skipcount).Take(Convert.ToInt32(pagesize)).ToList();
JsonDataModel<tb_PaintInfo> md = new JsonDataModel<tb_PaintInfo>();
md.total = total.ToString();
md.rows = list;
return JSONTools.ScriptSerialize(md);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 根据ID查询信息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public tb_PaintInfo SearchInfoByID(string id)
{
try
{
return db.SearchInfoByID(id);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public string GetComboboxData()
{
try
{
string jsonStr = "[]";
var list = db.SearchAllInfo().ToList();//判断是否有重复数据
List<SelectModel> sl = new List<SelectModel>();
foreach (var item in list)
{
SelectModel md = new SelectModel();
md.textField = item.PaintCode + "--" + item.PaintName;
md.valueField = item.ID;
sl.Add(md);
}
jsonStr = JSONTools.ScriptSerialize(sl);
return jsonStr;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return "";
}
}
public string SearchRelation(string page, string pagesize, string PaintID, string BucketID)
{
try
{
string jsonStr = "[]";
int total = 0;//总行数
List<tb_Paint_Bucket> list = dbPB.SearchAllInfo();
if (!String.IsNullOrEmpty(PaintID))
{
list = list.Where(p => p.PaintID == PaintID).ToList();
}
if (!String.IsNullOrEmpty(BucketID))
{
list = list.Where(p => p.BucketID == BucketID).ToList();
}
total = list.Count;
int Skipcount = (Convert.ToInt32(page) - 1) * Convert.ToInt32(pagesize);
list = list.Skip(Skipcount).Take(Convert.ToInt32(pagesize)).ToList();
List<Paint_BucketModel> modelList = new List<Paint_BucketModel>();
#region 联查
BasicBLL<tb_PaintInfo> PaintInfo_db = new BasicBLL<tb_PaintInfo>();
var PaintInfo_list = PaintInfo_db.SearchAllInfo();
BasicBLL<tb_BucketInfo> BucketInfo_db = new BasicBLL<tb_BucketInfo>();
var BucketInfo_list = BucketInfo_db.SearchAllInfo();
foreach (var item in list)
{
Paint_BucketModel dm = Tool.Mapper<Paint_BucketModel, tb_Paint_Bucket>(item);
var PaintInfo_info = PaintInfo_list.FirstOrDefault(p => p.ID == item.PaintID);
if (PaintInfo_info != null)
{
dm.PaintCode = PaintInfo_info.PaintCode;
dm.PaintName = PaintInfo_info.PaintName;
}
var BucketInfo_info = BucketInfo_list.FirstOrDefault(p => p.ID == item.BucketID);
if (BucketInfo_info != null)
{
dm.BucketCode = BucketInfo_info.BucketCode;
dm.BucketName = BucketInfo_info.BucketName;
}
modelList.Add(dm);
}
#endregion
JsonDataModel<Paint_BucketModel> md = new JsonDataModel<Paint_BucketModel>();
md.total = total.ToString();
md.rows = modelList;
return JSONTools.ScriptSerialize(md);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 新增信息
/// </summary>
/// <param name="md"></param>
/// <returns></returns>
public bool AddRelation(tb_Paint_Bucket md)
{
try
{
var list = dbPB.SearchAllInfo().Where(p => p.PaintID == md.PaintID && p.BucketID == md.BucketID).ToList();//判断是否有重复数据
if (list.Count > 0)
{
return false;
}
return dbPB.AddInfo(md);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
/// <summary>
/// 修改信息
/// </summary>
/// <param name="md"></param>
/// <returns></returns>
public bool UpdateRelation(tb_Paint_Bucket md)
{
try
{
var list = dbPB.SearchAllInfo().Where(p => p.PaintID == md.PaintID && p.ID != md.ID && p.BucketID == md.BucketID).ToList();//判断是否有重复数据
if (list.Count > 0)
{
return false;
}
//初始化要更新的字段
string[] proNames = new string[2];
proNames[0] = "PaintID";
proNames[1] = "BucketID";
//必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化
//如果没有初始化必填字段,更新会报错
//md.Des = "";
return dbPB.UpdateInfo(md, proNames);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
public bool DeleteRelation(tb_Paint_Bucket md)
{
try
{
List<tb_Paint_Bucket> ef = dbPB.SearchInfoByKey("ID", md.ID);
if (ef!=null && ef.Count>0)
{
return dbPB.DelInfo(ef.First());
}
return false;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
}
}