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.
417 lines
14 KiB
417 lines
14 KiB
6 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.Mistake247;
|
||
|
using MESClassLibrary.DAL.Plan243;
|
||
|
using MESClassLibrary.EFModel;
|
||
|
using MESClassLibrary.Model;
|
||
|
|
||
|
namespace MESClassLibrary.BLL.Plan243
|
||
|
{
|
||
|
public class Plan243BLL
|
||
|
{
|
||
|
BBMPTEntities ef = new BBMPTEntities();
|
||
|
BasicBLL<tb_Plan_243> db = new BasicBLL<tb_Plan_243>();
|
||
|
|
||
|
public string SearchOrderNo(string StartTime)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
|
||
|
string jsonStr = "";
|
||
|
string orderNo = Convert.ToDateTime(StartTime).ToString("yyyyMMdd");
|
||
|
var info = ef.tb_Plan_243.Where(p => p.OrderNo.Contains(orderNo)).OrderByDescending(p => p.OrderNo).FirstOrDefault();
|
||
|
|
||
|
if (info != null)
|
||
|
{
|
||
|
return (Convert.ToInt64(info.OrderNo) + 1).ToString();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return orderNo + "0001";
|
||
|
}
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
return "";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public string GetComboboxData()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
string jsonStr = "[]";
|
||
|
var list = ef.tb_Mistake_243.ToList();//判断是否有重复数据
|
||
|
jsonStr = JSONTools.ScriptSerialize(list);
|
||
|
return jsonStr;
|
||
|
}
|
||
|
catch (Exception)
|
||
|
{
|
||
|
return "";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public string GetMistake(string id)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
string jsonStr = "[]";
|
||
|
var list = ef.tb_Mistake_243.Where(p => p.ID.Equals(id)).FirstOrDefault();//判断是否有重复数据
|
||
|
jsonStr = JSONTools.ScriptSerialize(list);
|
||
|
return jsonStr;
|
||
|
}
|
||
|
catch (Exception)
|
||
|
{
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public string QueryForComboboxOrderNo(string StartTime)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
string jsonStr = "[]";
|
||
|
List<SelectModel> list = new List<SelectModel>();
|
||
|
string orderNo = Convert.ToDateTime(StartTime).ToString("yyyyMMdd");
|
||
|
var info = ef.tb_Plan_243.Where(p => p.OrderNo.Contains(orderNo)).GroupBy(p => p.OrderNo).Select(p => p.Key).ToList();//判断是否有重复数据
|
||
|
foreach (var item in info)
|
||
|
{
|
||
|
SelectModel md = new SelectModel();
|
||
|
md.textField = item;
|
||
|
md.valueField = item;
|
||
|
list.Add(md);
|
||
|
}
|
||
|
jsonStr = JSONTools.ScriptSerialize(list);
|
||
|
return jsonStr;
|
||
|
}
|
||
|
catch (Exception)
|
||
|
{
|
||
|
return "";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public string QueryForItem(string OrderNo)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
var info = ef.tb_Plan_243.Where(p => p.OrderNo.Equals(OrderNo)).OrderByDescending(p => p.Item).FirstOrDefault();//判断是否有重复数据
|
||
|
return (info.Item + 1).ToString();
|
||
|
}
|
||
|
catch (Exception)
|
||
|
{
|
||
|
return "";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 查询全部信息分页
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
public string SearchInfoAll(string page, string pagesize, string StartTime, string EndTime, string OrderNo)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
|
||
|
string jsonStr = "[]";
|
||
|
int total = 0;//总行数
|
||
|
|
||
|
DateTime stime = Convert.ToDateTime(StartTime + " 00:00:00");
|
||
|
DateTime etime = Convert.ToDateTime(EndTime + " 23:59:59");
|
||
|
|
||
|
List<tb_Plan_243> list = ef.tb_Plan_243.Where(p => p.CreateTime >= stime && p.CreateTime <= etime).OrderBy(p => p.CreateTime).ToList();
|
||
|
|
||
|
if (!String.IsNullOrEmpty(OrderNo))
|
||
|
{
|
||
|
list = list.Where(p => p.OrderNo.Contains(OrderNo)).OrderBy(p => p.CreateTime).ToList();
|
||
|
}
|
||
|
|
||
|
|
||
|
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();
|
||
|
|
||
|
List<tb_Plan_243Model> modelList = new List<tb_Plan_243Model>();
|
||
|
|
||
|
#region 联查
|
||
|
|
||
|
var listModel = ef.tb_Mistake_243.ToList();
|
||
|
|
||
|
foreach (var item in list)
|
||
|
{
|
||
|
tb_Plan_243Model dm = Tool.Mapper<tb_Plan_243Model, tb_Plan_243>(item);
|
||
|
|
||
|
var machine_info = listModel.FirstOrDefault(p => p.PartNo2 == item.PartNo);
|
||
|
if (machine_info != null)
|
||
|
{
|
||
|
dm.PartName = machine_info.PartName2;
|
||
|
}
|
||
|
|
||
|
modelList.Add(dm);
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
JsonDataModel<tb_Plan_243Model> md = new JsonDataModel<tb_Plan_243Model>();
|
||
|
md.total = total.ToString();
|
||
|
md.rows = modelList;
|
||
|
jsonStr = JSONTools.ScriptSerialize(md);
|
||
|
}
|
||
|
return jsonStr;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 新增信息
|
||
|
/// </summary>
|
||
|
/// <param name="md"></param>
|
||
|
/// <returns></returns>
|
||
|
public bool AddInfo(tb_Plan_243 md)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
var list = ef.tb_Plan_243.Where(p => p.OrderNo == md.OrderNo).ToList();
|
||
|
if (list != null && list.Count > 0)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
return db.AddInfo(md);
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
public bool UpdateAddInfo(tb_Plan_243 md)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
var list = ef.tb_Plan_243.Where(p => p.OrderNo == md.OrderNo && p.PartNo == md.PartNo).ToList();
|
||
|
if (list != null && 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_Plan_243 md)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
//初始化要更新的字段
|
||
|
string[] proNames = new string[1];
|
||
|
proNames[0] = "OrderCount";
|
||
|
|
||
|
//必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化
|
||
|
//如果没有初始化必填字段,更新会报错
|
||
|
|
||
|
return db.UpdateInfo(md, proNames);
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public List<List<string>> SearchForExcel(string StartTime, string EndTime, string OrderNo)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
List<List<string>> list = new List<List<string>>();
|
||
|
|
||
|
DateTime stime = Convert.ToDateTime(StartTime + " 00:00:00");
|
||
|
DateTime etime = Convert.ToDateTime(EndTime + " 23:59:59");
|
||
|
|
||
|
List<string> titleList = new List<string>();
|
||
|
titleList.Add("生产计划单号");
|
||
|
titleList.Add("序号");
|
||
|
titleList.Add("零件号");
|
||
|
titleList.Add("零件名称");
|
||
|
titleList.Add("数量");
|
||
|
titleList.Add("领用数量");
|
||
|
titleList.Add("完成数量");
|
||
|
titleList.Add("返修数量");
|
||
|
titleList.Add("成品报废");
|
||
|
titleList.Add("半成品报废");
|
||
|
titleList.Add("备注");
|
||
|
titleList.Add("创建时间");
|
||
|
list.Add(titleList);
|
||
|
|
||
|
List<tb_Plan_243> Plan_243_list = ef.tb_Plan_243.Where(p => p.CreateTime >= stime && p.CreateTime <= etime).OrderBy(p => p.CreateTime).ToList();
|
||
|
|
||
|
if (!String.IsNullOrEmpty(OrderNo))
|
||
|
{
|
||
|
Plan_243_list = Plan_243_list.Where(p => p.OrderNo.Contains(OrderNo)).OrderBy(p => p.CreateTime).ToList();
|
||
|
}
|
||
|
|
||
|
if (Plan_243_list.Count > 0)
|
||
|
{
|
||
|
List<tb_Plan_243Model> modelList = new List<tb_Plan_243Model>();
|
||
|
var listModel = ef.tb_Mistake_243.ToList();
|
||
|
|
||
|
foreach (var item in Plan_243_list)
|
||
|
{
|
||
|
tb_Plan_243Model dm = Tool.Mapper<tb_Plan_243Model, tb_Plan_243>(item);
|
||
|
|
||
|
var machine_info = listModel.FirstOrDefault(p => p.PartNo2 == item.PartNo);
|
||
|
if (machine_info != null)
|
||
|
{
|
||
|
dm.PartName = machine_info.PartName2;
|
||
|
}
|
||
|
|
||
|
modelList.Add(dm);
|
||
|
}
|
||
|
|
||
|
for (int i = 0; i < modelList.Count; i++)
|
||
|
{
|
||
|
List<string> rowList = new List<string>();
|
||
|
rowList.Add(modelList[i].OrderNo);
|
||
|
rowList.Add(modelList[i].Item == null ? "" : modelList[i].Item.ToString());
|
||
|
rowList.Add(modelList[i].PartNo);
|
||
|
rowList.Add(modelList[i].PartName == null ? "" : modelList[i].PartName.ToString());
|
||
|
rowList.Add(modelList[i].OrderCount == null ? "" : modelList[i].OrderCount.ToString());
|
||
|
rowList.Add(modelList[i].LyCount == null ? "" : modelList[i].LyCount.ToString());
|
||
|
rowList.Add(modelList[i].CompleteCount == null ? "" : modelList[i].CompleteCount.ToString());
|
||
|
rowList.Add(modelList[i].RepairCount == null ? "" : modelList[i].RepairCount.ToString());
|
||
|
rowList.Add(modelList[i].ScrapCount1 == null ? "" : modelList[i].ScrapCount1.ToString());
|
||
|
rowList.Add(modelList[i].ScrapCount2 == null ? "" : modelList[i].ScrapCount2.ToString());
|
||
|
rowList.Add(modelList[i].Des);
|
||
|
rowList.Add(modelList[i].CreateTime == null ? "" : modelList[i].CreateTime.ToString());
|
||
|
list.Add(rowList);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return list;
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 删除信息
|
||
|
/// </summary>
|
||
|
/// <param name="md"></param>
|
||
|
/// <param name="flag"></param>
|
||
|
/// <returns></returns>
|
||
|
public bool DeleteInfo(tb_Plan_243 md)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
if (ef.tb_Plan_243.Where(p => p.ID == md.ID && p.CompleteCount > 0).Count() > 0)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
return db.DelInfo(md);
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
//校验是否生成计划单号日期部分+零件号有相同的计划
|
||
|
public bool QueryByOrderNo(string OrderNo, string PartNo)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
var info = ef.tb_Plan_243.Where(p => p.OrderNo.Contains(OrderNo) && p.PartNo.Equals(PartNo));
|
||
|
if (info.Count() > 0)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
catch (Exception)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//校验是否同一个生成计划单号下有相同序号的计划
|
||
|
public bool QueryByOrderNoAndItem(string OrderNo, int Item)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
var info = ef.tb_Plan_243.Where(p => p.OrderNo.Equals(OrderNo) && p.Item == Item);
|
||
|
if (info.Count() > 0)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
catch (Exception)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public DataTable SearhByOrderNo(string OrderNo)
|
||
|
{
|
||
|
Plan243DAL da = new Plan243DAL();
|
||
|
try
|
||
|
{
|
||
|
return da.SearhByOrderNo(OrderNo);
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public DataTable DetailOrderNo(string OrderNo)
|
||
|
{
|
||
|
Plan243DAL da = new Plan243DAL();
|
||
|
try
|
||
|
{
|
||
|
return da.DetailOrderNo(OrderNo);
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|