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

234 lines
8.0 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.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<tb_Bad_Injection> da=new BasicBLL<tb_Bad_Injection>();
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";
}
}
}
}