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

374 lines
13 KiB

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using MESClassLibrary.BLL.Injection;
using MESClassLibrary.BLL.Inspection;
using MESClassLibrary.BLL.Log;
using MESClassLibrary.DAL;
using MESClassLibrary.DAL.BasicInfo;
using MESClassLibrary.EFModel;
using MESClassLibrary.Model;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace MESClassLibrary.BLL.BasicInfo
{
public class BadInjectionBLL
{
BadInjectionDAL db=new BadInjectionDAL();
BasicBLL<tb_Bad_Injection> da=new BasicBLL<tb_Bad_Injection>();
private InjectionBoxBLL _injectionBoxBLL = new InjectionBoxBLL();
private BarCodeBLL barCodeBll = new BarCodeBLL();
private WmsBLL _wmsBll = new WmsBLL();
public bool Add_Info(BadInjectionModel md)
{
try
{
return db.AddInfo(md);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
public DataTable SearchByCode(string code)
{
try
{
return db.SearchByCode(code);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public string SearchInfoAll(string page, string pagesize, string barcode,string starttime,string endtime)
{
try
{
string jsonStr = "[]";
int total = 0;//总行数
List<BadInjectionModel> list = null;
DataTable dt = db.SearchInfoAll(barcode, starttime, endtime);
if (dt != null && dt.Rows.Count > 0)
{
list = CommonTools.ConvertTo<BadInjectionModel>(dt).ToList();
}
if (list != null && list.Count > 0)
{
total = list.Count;
int Skipcount = (Convert.ToInt32(page) - 1) * Convert.ToInt32(pagesize);
list = list.Skip(Skipcount).Take(Convert.ToInt32(pagesize)).ToList();
JsonDataModel<BadInjectionModel> md = new JsonDataModel<BadInjectionModel>();
md.total = total.ToString();
md.rows = list;
IsoDateTimeConverter timeConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" };
jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(md, Formatting.Indented, timeConverter);
}
return jsonStr;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public List<List<string>> SearchForExcel(string barcode, string starttime, string endtime)
{
try
{
List<List<string>> list = new List<List<string>>();
string jsonStr = "[]";
int total = 0;//总行数
List<BadInjectionModel> modelList = null;
DataTable dt = db.SearchInfoAll(barcode, starttime, endtime);
if (dt != null && dt.Rows.Count > 0)
{
modelList = CommonTools.ConvertTo<BadInjectionModel>(dt).ToList();
}
if (modelList != null && modelList.Count() > 0)
{
List<string> title_ = new List<string>();
title_.Add("条码");
title_.Add("缺陷区域");
title_.Add("缺陷原因");
title_.Add("报废时间");
list.Add(title_);
foreach (var item in modelList)
{
List<string> rowList = new List<string>();
rowList.Add(item.code == null ? "" : item.code);
rowList.Add(item.BadPosition == null ? "" : item.BadPosition);
rowList.Add(item.BadReason == null ? "" : item.BadReason);
rowList.Add(item.CreateTime == null ? "" : item.CreateTime.ToString());
list.Add(rowList);
}
}
return list;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public string SearchZpInfoAll(string page, string pageSize, string barCode, string startTime, string endTime)
{
try
{
string jsonStr = "[]";
int total = 0;//总行数
List<BadInjectionModel> list = null;
DataTable dt = db.SearchZpInfoAll(barCode, startTime, endTime);
if (dt != null && dt.Rows.Count > 0)
{
list = CommonTools.ConvertTo<BadInjectionModel>(dt).ToList();
}
if (list != null && list.Count > 0)
{
total = list.Count;
int skipCount = (Convert.ToInt32(page) - 1) * Convert.ToInt32(pageSize);
list = list.Skip(skipCount).Take(Convert.ToInt32(pageSize)).ToList();
JsonDataModel<BadInjectionModel> md = new JsonDataModel<BadInjectionModel>();
md.total = total.ToString();
md.rows = list;
IsoDateTimeConverter timeConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" };
jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(md, Formatting.Indented, timeConverter);
}
return jsonStr;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public List<List<string>> SearchZpForExcel(string barCode, string startTime, string endTime)
{
try
{
List<List<string>> list = new List<List<string>>();
string jsonStr = "[]";
int total = 0;//总行数
List<BadInjectionModel> modelList = null;
DataTable dt = db.SearchZpInfoAll(barCode, startTime, endTime);
if (dt != null && dt.Rows.Count > 0)
{
modelList = CommonTools.ConvertTo<BadInjectionModel>(dt).ToList();
}
if (modelList != null && modelList.Any())
{
List<string> title_ = new List<string>();
title_.Add("条码");
title_.Add("缺陷区域");
title_.Add("缺陷原因");
title_.Add("报废时间");
list.Add(title_);
foreach (var item in modelList)
{
List<string> rowList = new List<string>();
rowList.Add(item.code == null ? "" : item.code);
rowList.Add(item.BadPosition == null ? "" : item.BadPosition);
rowList.Add(item.BadReason == null ? "" : item.BadReason);
rowList.Add(item.CreateTime == null ? "" : item.CreateTime.ToString());
list.Add(rowList);
}
}
return list;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public string BadCount(string startTime, string endTime, string stationId)
{
try
{
return db.BadCount(startTime, endTime, stationId);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
return "0";
}
}
/// <summary>
/// 单根报废
/// </summary>
/// <param name="md"></param>
/// <param name="boxCode"></param>
/// <param name="tableName"></param>
/// <returns></returns>
public string SaveBad(BadInjectionModel md, string boxCode, string tableName,string station)
{
LocalDBService localDB = new LocalDBService(SqlHelper.GetConnSting());
try
{
localDB.BeginTrans();
db.AddInfo(localDB, md);
if (!string.IsNullOrEmpty(boxCode))
{
_injectionBoxBLL.UpdateBoxCount(localDB, boxCode, -1);
}
barCodeBll.UpdateIsBad(localDB, tableName, md.OneBarCode, md.BarCode);
BarCodeModel bcm = new BarCodeModel();
bcm.IsBad = 1;
bcm.OneBarCode = md.OneBarCode;
bcm.BarCode = md.BarCode;
bcm.BoxNo = boxCode;
bcm.Des1 = md.Desc;
bcm.PartNo = md.code;
bcm.StationID = md.StationID;
_wmsBll.DeleteInterface(localDB, md.OneBarCode);
_wmsBll.SaveInterface(localDB, bcm, md.BadReason, station);
localDB.Commit();
return "";
}
catch (Exception ex)
{
if (localDB != null)
{
localDB.Rollback();
}
return ex.Message;
}
finally
{
if (localDB != null)
{
localDB.EndTrans();
}
}
}
/// <summary>
/// 整箱报废
/// </summary>
/// <param name="boxDetailTable"></param>
/// <param name="stationId"></param>
/// <param name="position"></param>
/// <param name="reason"></param>
/// <param name="boxCode"></param>
/// <param name="tableName"></param>
/// <param name="partNo"></param>
/// <returns></returns>
public string SaveBadByBatch(DataTable boxDetailTable,string stationId,string position,string reason, string boxCode,string tableName,string partName,string station)
{
LocalDBService localDB = new LocalDBService(SqlHelper.GetConnSting());
try
{
localDB.BeginTrans();
bool isDel = _wmsBll.DelRecordByBox(localDB,boxCode);
if (isDel)
{
_injectionBoxBLL.UpdateBoxCount(localDB, boxCode, 100, true);
}
else
{
localDB.Rollback();
return $"整箱报废失败,可能箱码[{boxCode}]在操作时已被wms接收";
}
foreach (DataRow dr in boxDetailTable.Rows)
{
string barCode = dr["BarCode"].ToString();
string oneBarCode = dr["OneBarCode"].ToString();
BadInjectionModel badmd = new BadInjectionModel();
badmd.ID = Guid.NewGuid().ToString();
badmd.BarCode = barCode;
badmd.OneBarCode = oneBarCode;
badmd.StationID = stationId;
badmd.BadPosition = position;
badmd.BadReason = reason.Trim();
db.AddInfo(localDB, badmd);
BarCodeModel bcm = new BarCodeModel();
bcm.IsBad = 1;
bcm.OneBarCode = oneBarCode;
bcm.BarCode = barCode;
bcm.BoxNo = boxCode;
bcm.Des1 = partName ;
bcm.PartNo = dr["PartNo"].ToString();
bcm.StationID = stationId;
_wmsBll.SaveInterface(localDB, bcm, reason, station);
}
barCodeBll.UpdateIsBadByBoxCode(localDB,tableName, boxCode);
localDB.Commit();
return "";
}
catch (Exception ex)
{
if (localDB != null)
{
localDB.Rollback();
}
return ex.Message;
}
finally
{
if (localDB != null)
{
localDB.EndTrans();
}
}
return "";
}
}
}