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

269 lines
8.1 KiB

3 months ago
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using MESClassLibrary.BLL.Log;
using MESClassLibrary.DAL.BasicInfo;
using MESClassLibrary.EFModel;
using MESClassLibrary.Model;
namespace MESClassLibrary.BLL
{
public class PlasticBLL
{
BBMPTEntities ef = new BBMPTEntities();
BasicBLL<tb_Plastic> db = new BasicBLL<tb_Plastic>();
/// <summary>
/// 新增信息
/// </summary>
/// <param name="md"></param>
/// <returns></returns>
public bool AddInfo(tb_Plastic md)
{
try
{
var list = db.SearchInfoByKey("StationID", md.StationID);//判断是否有重复数据
if (list != null && list.Count > 0)
{
if (list.Where(p => p.StockNo.Equals(md.StockNo)).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_Plastic md)
{
try
{
//初始化要更新的字段
string[] proNames = new string[7];
proNames[0] = "CycleTime";
proNames[1] = "StationID";
proNames[2] = "IsBackup";
proNames[3] = "Weight";
proNames[4] = "OpenDebugTime";
proNames[5] = "PrinterNo";
proNames[6] = "PartNo";
//必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化
//如果没有初始化必填字段,更新会报错
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_Plastic 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 partNo, string StationID)
{
try
{
string jsonStr = "[]";
int total = 0;//总行数
List<tb_Plastic> list = db.SearchAllInfo();
if (!String.IsNullOrEmpty(stockNo))
{
list = list.Where(p => p.StockNo != null && p.StockNo.Contains(stockNo)).ToList();
}
if (!String.IsNullOrEmpty(StationID))
{
list = list.Where(p => p.StationID.Equals(StationID)).ToList();
}
List<PlasticModel> modelList = new List<PlasticModel>();
if (list.Count > 0)
{
#region 联查
BasicBLL<tb_Product> product_db = new BasicBLL<tb_Product>();
var product_list = product_db.SearchAllInfo();
BasicBLL<tb_Station> machine_db = new BasicBLL<tb_Station>();
var machine_list = machine_db.SearchAllInfo();
foreach (var item in list)
{
PlasticModel dm = Tool.Mapper<PlasticModel, tb_Plastic>(item);
var product_info = product_list.FirstOrDefault(p => p.StockNo == item.StockNo);
if (product_info != null)
{
dm.PartNo = product_info.PartNo;
}
var machine_info = machine_list.FirstOrDefault(p => p.StationID == item.StationID);
if (machine_info != null)
{
dm.StationNo = machine_info.StationNo;
}
modelList.Add(dm);
}
#endregion
if (!String.IsNullOrEmpty(partNo))
{
modelList = modelList.Where(p => p.PartNo != null && p.PartNo.Contains(partNo)).ToList();
}
total = modelList.Count;
int Skipcount = (Convert.ToInt32(page) - 1) * Convert.ToInt32(pagesize);
modelList = modelList.Skip(Skipcount).Take(Convert.ToInt32(pagesize)).ToList();
JsonDataModel<PlasticModel> md = new JsonDataModel<PlasticModel>();
md.total = total.ToString();
md.rows = modelList;
jsonStr = JSONTools.ScriptSerialize<JsonDataModel<PlasticModel>>(md);
}
return jsonStr;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 查询全部信息
/// </summary>
/// <returns></returns>
public List<tb_Plastic> SearchAll()
{
try
{
var s_list = db.SearchAllInfo().ToList();
return s_list;
}
catch (Exception)
{
return null;
}
}
/// <summary>
/// 根据ID查询信息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public tb_Plastic SearchInfoByID(string id)
{
try
{
return db.SearchInfoByID(id);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public string QueryForCombobox(string StationID)
{
try
{
var info = from m in ef.tb_Plastic
join s in ef.tb_Product on m.PartNo equals s.PartNo into val2Grp
from grp in val2Grp.DefaultIfEmpty()
where m.StationID == StationID
select new { c_id = grp.PartNo, c_text = grp.PartNo + "--" + grp.ProductName};
string jsonStr = "[]";
jsonStr = JSONTools.ScriptSerialize(info);
return jsonStr;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return "";
}
}
public DataTable SearchInfo(string partNo,string stationID)
{
PlasticDAL da = new PlasticDAL();
try
{
return da.SearchInfo(partNo, stationID);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable SearchPartByStation(string stationNo)
{
PlasticDAL da = new PlasticDAL();
try
{
return da.SearchPartByStation(stationNo);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
}
}