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 da=new BasicBLL(); 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 list = null; DataTable dt = db.SearchInfoAll(barcode, starttime, endtime); if (dt != null && dt.Rows.Count > 0) { list = CommonTools.ConvertTo(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 md = new JsonDataModel(); 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> SearchForExcel(string barcode, string starttime, string endtime) { try { List> list = new List>(); string jsonStr = "[]"; int total = 0;//总行数 List modelList = null; DataTable dt = db.SearchInfoAll(barcode, starttime, endtime); if (dt != null && dt.Rows.Count > 0) { modelList = CommonTools.ConvertTo(dt).ToList(); } if (modelList != null && modelList.Count() > 0) { List title_ = new List(); title_.Add("条码"); title_.Add("缺陷区域"); title_.Add("缺陷原因"); title_.Add("报废时间"); list.Add(title_); foreach (var item in modelList) { List rowList = new List(); 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 list = null; DataTable dt = db.SearchZpInfoAll(barCode, startTime, endTime); if (dt != null && dt.Rows.Count > 0) { list = CommonTools.ConvertTo(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 md = new JsonDataModel(); 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> SearchZpForExcel(string barCode, string startTime, string endTime) { try { List> list = new List>(); string jsonStr = "[]"; int total = 0;//总行数 List modelList = null; DataTable dt = db.SearchZpInfoAll(barCode, startTime, endTime); if (dt != null && dt.Rows.Count > 0) { modelList = CommonTools.ConvertTo(dt).ToList(); } if (modelList != null && modelList.Any()) { List title_ = new List(); title_.Add("条码"); title_.Add("缺陷区域"); title_.Add("缺陷原因"); title_.Add("报废时间"); list.Add(title_); foreach (var item in modelList) { List rowList = new List(); 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"; } } /// /// 单根报废 /// /// /// /// /// 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(); } } } /// /// 整箱报废 /// /// /// /// /// /// /// /// /// 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 ""; } } }