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.Log; 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(); 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"; } } } }