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.
443 lines
15 KiB
443 lines
15 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using MESClassLibrary.BLL.Log;
|
|
using MESClassLibrary.DAL;
|
|
using MESClassLibrary.EFModel;
|
|
using MESClassLibrary.Model;
|
|
|
|
namespace MESClassLibrary.BLL.PunchAndWeld
|
|
{
|
|
public class PlanPunchBLL
|
|
{
|
|
BBMPTEntities ef = new BBMPTEntities();
|
|
BasicBLL<tb_Plan_Punch> db = new BasicBLL<tb_Plan_Punch>();
|
|
|
|
/// <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_Punch> list = ef.tb_Plan_Punch.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_PunchModel> modelList = new List<tb_Plan_PunchModel>();
|
|
|
|
#region 联查
|
|
|
|
var listModel = ef.tb_Product.ToList();
|
|
|
|
foreach (var item in list)
|
|
{
|
|
tb_Plan_PunchModel dm = Tool.Mapper<tb_Plan_PunchModel, tb_Plan_Punch>(item);
|
|
|
|
var machine_info = listModel.FirstOrDefault(p => p.PartNo == item.PartNo);
|
|
if (machine_info != null)
|
|
{
|
|
dm.PartName = machine_info.ProductName;
|
|
}
|
|
|
|
modelList.Add(dm);
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
JsonDataModel<tb_Plan_PunchModel> md = new JsonDataModel<tb_Plan_PunchModel>();
|
|
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_Punch md)
|
|
{
|
|
try
|
|
{
|
|
var list = ef.tb_Plan_Punch.Where(p => p.OrderNo == md.OrderNo && p.Item==md.Item && p.PartNo==md.PartNo).ToList();
|
|
if (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_Punch md)
|
|
{
|
|
try
|
|
{
|
|
var list = ef.tb_Plan_Punch.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_Punch md)
|
|
{
|
|
try
|
|
{
|
|
|
|
//初始化要更新的字段
|
|
string[] proNames = new string[1];
|
|
proNames[0] = "OrderCount";
|
|
|
|
string sql = "select * from tb_Plan_Punch where OrderNo='" + md.OrderNo + "' and PartNo='"+ md.PartNo+"'";
|
|
SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.GetConnSting(), CommandType.Text, sql);
|
|
if (dr.Read())
|
|
{
|
|
if (md.OrderCount < Convert.ToInt32(dr["CompleteCount"]))
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
return db.UpdateInfo(md, proNames);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
//必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化
|
|
//如果没有初始化必填字段,更新会报错
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
public string SearchOrderNo(string StartTime, string Banci)
|
|
{
|
|
try
|
|
{
|
|
|
|
string jsonStr = "";
|
|
string orderNo = Convert.ToDateTime(StartTime).ToString("yyyyMMdd");
|
|
|
|
var info = ef.tb_Plan_Punch.Where(p => p.OrderNo.Contains(Banci.Substring(0, 1) + orderNo)).OrderByDescending(p => p.OrderNo).FirstOrDefault();
|
|
|
|
if (info != null)
|
|
{
|
|
return info.OrderNo.Substring(0, info.OrderNo.Length - 4) + (Convert.ToInt32(info.OrderNo.Substring(info.OrderNo.Length - 4, 4)) + 1).ToString()
|
|
.PadLeft(4, '0');
|
|
}
|
|
else
|
|
{
|
|
if (Banci.Contains("A"))
|
|
{
|
|
return "A" + orderNo + "0001";
|
|
}
|
|
else
|
|
{
|
|
return "B" + orderNo + "0001";
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public string GetComboboxData()
|
|
{
|
|
try
|
|
{
|
|
string jsonStr = "[]";
|
|
var list = ef.tb_Product.Where(p => p.ProductTypeID == "3a8545ee-5979-4780-a5ca-6c5e75685ae2" || p.ProductTypeID == "69ec20f1-dab5-4caf-b81e-1c65b38b9e34").ToList();//判断是否有重复数据
|
|
jsonStr = JSONTools.ScriptSerialize(list);
|
|
return jsonStr;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public string GetMistake(string id)
|
|
{
|
|
try
|
|
{
|
|
string jsonStr = "[]";
|
|
var list = ef.tb_Product.Where(p => p.PartNo.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_Punch.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_Punch.Where(p => p.OrderNo.Equals(OrderNo)).OrderByDescending(p => p.Item).FirstOrDefault();//判断是否有重复数据
|
|
return (info.Item + 1).ToString();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除信息
|
|
/// </summary>
|
|
/// <param name="md"></param>
|
|
/// <param name="flag"></param>
|
|
/// <returns></returns>
|
|
public bool DeleteInfo(tb_Plan_Punch md)
|
|
{
|
|
try
|
|
{
|
|
if (ef.tb_Plan_Punch.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 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("创建时间");
|
|
list.Add(titleList);
|
|
|
|
List<tb_Plan_Punch> Plan_list = ef.tb_Plan_Punch.Where(p => p.CreateTime >= stime && p.CreateTime <= etime).OrderBy(p => p.CreateTime).ToList();
|
|
|
|
if (!String.IsNullOrEmpty(OrderNo))
|
|
{
|
|
Plan_list = Plan_list.Where(p => p.OrderNo.Contains(OrderNo)).OrderBy(p => p.CreateTime).ToList();
|
|
}
|
|
|
|
if (Plan_list.Count > 0)
|
|
{
|
|
List<tb_Plan_PunchModel> modelList = new List<tb_Plan_PunchModel>();
|
|
var listModel = ef.tb_Product.ToList();
|
|
|
|
foreach (var item in Plan_list)
|
|
{
|
|
tb_Plan_PunchModel dm = Tool.Mapper<tb_Plan_PunchModel, tb_Plan_Punch>(item);
|
|
|
|
var machine_info = listModel.FirstOrDefault(p => p.PartNo == item.PartNo);
|
|
if (machine_info != null)
|
|
{
|
|
dm.PartName = machine_info.ProductName;
|
|
}
|
|
|
|
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].BadCount == null ? "" : modelList[i].BadCount.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;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
//校验是否生成计划单号日期部分+零件号有相同的计划
|
|
public bool QueryByOrderNo(string OrderNo, string PartNo)
|
|
{
|
|
try
|
|
{
|
|
var info = ef.tb_Plan_Punch.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_Punch.Where(p => p.OrderNo.Equals(OrderNo) && p.Item == Item);
|
|
if (info.Count() > 0)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public string GetOrderNo(string banci,string date)
|
|
{
|
|
try
|
|
{
|
|
//string order = banci + DateTime.Now.ToString("yyyyMMdd");
|
|
string order = banci + date;
|
|
var info = ef.tb_Plan_Punch.Where(p => p.OrderNo.Contains(order)).OrderBy(p => p.CreateTime)
|
|
.FirstOrDefault();
|
|
if (info != null)
|
|
{
|
|
return order + (Convert.ToInt32(info.OrderNo.Substring(info.OrderNo.Length - 4, 4)) + 1).ToString()
|
|
.PadLeft(4, '0');
|
|
}
|
|
else
|
|
{
|
|
return order + "0001";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
|
return banci + date +"0001";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|