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

314 lines
9.8 KiB

3 months ago
using MESClassLibrary.BLL.Log;
using MESClassLibrary.DAL.ZPPlan;
using MESClassLibrary.EFModel;
using MESClassLibrary.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
namespace MESClassLibrary.BLL.BasicInfo
{
public class ZPPlanBLL
{
readonly BasicBLL<tb_ZPPlan> db = new BasicBLL<tb_ZPPlan>();
/// <summary>
/// 新增信息
/// </summary>
/// <param name="md"></param>
/// <returns></returns>
public bool AddInfo(tb_ZPPlan md)
{
try
{
var now = DateTime.Now;
md.ID = Guid.NewGuid().ToString();
md.CreateTime = now;
md.OrderNo = now.ToString("yyyMMdd");
md.IsFinish = 0;
md.ProductCount = 0;
md.BadCount = 0;
md.Item = GetItem(md.OrderNo);
var result = db.AddInfo(md);
return result;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
private int GetItem(string orderNo)
{
var lastItem = db.Search(q => q.OrderNo == orderNo, q => q.CreateTime).LastOrDefault();
return lastItem == null ? 1 : (lastItem.Item.Value + 1);
}
/// <summary>
/// 修改信息
/// </summary>
/// <param name="md"></param>
/// <returns></returns>
public bool UpdateInfo(tb_ZPPlan md, ref string msg)
{
try
{
var data = db.SearchInfoByID(md.ID);
if (data.IsFinish == 1)
{
msg = "该计划已经完成";
return false;
}
if (data.ProductCount.GetValueOrDefault(0).CompareTo(md.OrderCount) > 0)
{
msg = "计划数量不能小于完成数量";
return false;
}
if (data.ProductCount.GetValueOrDefault(0) == 0)
{
data.StationID = md.StationID;
data.PartNo = md.PartNo;
data.OrderDate = md.OrderDate;
}
data.IsOneMore = md.IsOneMore;
data.OrderCount = md.OrderCount;
return db.UpdateInfo(data);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
msg = ex.ToString();
return false;
}
}
/// <summary>
/// 删除信息
/// </summary>
/// <param name="md"></param>
/// <param name="flag"></param>
/// <returns></returns>
public bool DeleteInfo(tb_ZPPlan md)
{
try
{
return db.DelInfo(md);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
/// <summary>
/// 查询全部信息分页
/// </summary>
/// <returns></returns>
public string SearchInfoAll(int page,
int pagesize,
string startTime,
string endTime,
string partNo)
{
try
{
string jsonStr = "[]";
int total = 0;//总行数
IEnumerable<tb_ZPPlan> list = SearchDB(startTime, endTime, partNo);
if (list.Any())
{
List<ZPPlanModel> modelList = new List<ZPPlanModel>();
total = list.Count();
int Skipcount = (Convert.ToInt32(page) - 1) * Convert.ToInt32(pagesize);
list = list.Skip(Skipcount).Take(Convert.ToInt32(pagesize));
ProductBLL prodBll = new ProductBLL();
var prodList = prodBll.SearchAll();
StationBLL stationBll = new StationBLL();
var stationList = stationBll.SearchAll();
foreach (var item in list)
{
var prodInfo = prodList.Where(q => q.PartNo == item.PartNo).FirstOrDefault();
var stationInfo = stationList.Where(q => q.StationID == item.StationID).FirstOrDefault();
ZPPlanModel zpm = Tool.Mapper<ZPPlanModel, tb_ZPPlan>(item);
zpm.StationNo = stationInfo == null ? "" : stationInfo.StationNo;
zpm.ProductName = prodInfo == null ? "" : prodInfo.ProductName;
modelList.Add(zpm);
}
JsonDataModel<ZPPlanModel> md = new JsonDataModel<ZPPlanModel>
{
total = total.ToString(),
rows = modelList
};
jsonStr = md.ToSerializer();
}
return jsonStr;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public List<ZPPlanModel> SearchByCreateTime(string startTime, string endTime, string partNo)
{
IEnumerable<tb_ZPPlan> list = SearchDB(startTime, endTime, partNo);
List<ZPPlanModel> modelList = new List<ZPPlanModel>();
if (list.Any())
{
ProductBLL prodBll = new ProductBLL();
var prodList = prodBll.SearchAll();
StationBLL stationBll = new StationBLL();
var stationList = stationBll.SearchAll();
foreach (var item in list)
{
var prodInfo = prodList.Where(q => q.PartNo == item.PartNo).FirstOrDefault();
var stationInfo = stationList.Where(q => q.StationID == item.StationID).FirstOrDefault();
ZPPlanModel zpm = Tool.Mapper<ZPPlanModel, tb_ZPPlan>(item);
zpm.StationNo = stationInfo == null ? "" : stationInfo.StationNo;
zpm.ProductName = prodInfo == null ? "" : prodInfo.ProductName;
modelList.Add(zpm);
}
}
return modelList;
}
public IEnumerable<tb_ZPPlan> SearchDB(string startTime, string endTime, string partNo)
{
DateTime st, et;
if (!DateTime.TryParse(startTime, out st)) st = DateTime.MinValue;
if (!DateTime.TryParse(endTime, out et)) et = DateTime.MaxValue;
IEnumerable<tb_ZPPlan> list;
if (string.IsNullOrEmpty(partNo))
{
list = db.Search(
q => (q.CreateTime >= st &&
q.CreateTime <= et) &&
q.IsFinish == 0,
q => q.CreateTime);
}
else
{
list = db.Search(q => q.PartNo.Contains(partNo) && q.IsFinish == 0, q => q.CreateTime);
}
return list;
}
/// <summary>
/// 查询全部信息
/// </summary>
/// <returns></returns>
public List<tb_ZPPlan> SearchAll()
{
try
{
var s_list = db.SearchAllInfo();
return s_list;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 根据ID查询信息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public tb_ZPPlan SearchInfoByID(string id)
{
try
{
return db.SearchInfoByID(id);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable GetProductingPlan(string station)
{
try
{
ZPPlanDAL dal=new ZPPlanDAL();
return dal.GetProductingPlan(station);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable GetPlan(string station, int flag, string planTime)
{
try
{
ZPPlanDAL dal = new ZPPlanDAL();
return dal.GetPlan(station, flag,planTime);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public bool updateQty(ZPPlanModel md)
{
try
{
ZPPlanDAL dal = new ZPPlanDAL();
return dal.updateQty(md);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
public bool updateBad(ZPPlanModel md)
{
try
{
ZPPlanDAL dal = new ZPPlanDAL();
return dal.updateBad(md);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
}
}