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

2039 lines
88 KiB

3 months ago
using MESClassLibrary.BLL.Log;
using MESClassLibrary.DAL.Injection;
using MESClassLibrary.EFModel;
using MESClassLibrary.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace MESClassLibrary.BLL.Injection
{
public class InjectionRecordBLL
{
BBMPTEntities ef = new BBMPTEntities();
BasicBLL<tb_Injection_Record> db = new BasicBLL<tb_Injection_Record>();
BasicBLL<tb_Product_Injection_w> db_w = new BasicBLL<tb_Product_Injection_w>();
InjectionRecordDAL dal = new InjectionRecordDAL();
/// <summary>
/// 新增信息
/// </summary>
/// <param name="md"></param>
/// <returns></returns>
public bool AddInfo(tb_Injection_Record md)
{
try
{
var list = db.SearchInfoByKey("RecordDate", md.RecordDate);//判断是否有重复数据
if (list != null && list.Count > 0)
{
if (list.Where(p => p.StationID.Equals(md.StationID) && p.workClass.Equals(md.workClass)).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_Injection_Record md)
{
try
{
//初始化要更新的字段
string[] proNames = new string[7];
proNames[0] = "workClass";
proNames[1] = "StationID";
proNames[2] = "JK_Weight";
proNames[3] = "Waste_Weight";
proNames[4] = "RecordDate";
proNames[5] = "StockNo";
proNames[6] = "PartNo";
//必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化
//如果没有初始化必填字段,更新会报错
return db.UpdateInfo(md, proNames);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
/// <summary>
/// 删除信息
/// </summary>
/// <param name="md"></param>
/// <param name="flag"></param>
/// <returns></returns>
public bool DeleteInfo(tb_Injection_Record md)
{
try
{
return db.DelInfo(md);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
/// <summary>
/// 查询全部信息分页
/// </summary>
/// <returns></returns>
public string SearchInfoAll(string page, string pagesize, string StartTime, string EndTime, string StationID)
{
try
{
string jsonStr = "[]";
int total = 0;//总行数
DateTime stime = Convert.ToDateTime(StartTime);
DateTime etime = Convert.ToDateTime(EndTime);
List<tb_Injection_Record> list = ef.tb_Injection_Record.Where(p => p.RecordDate >= stime && p.RecordDate <= etime).ToList();
if (!String.IsNullOrEmpty(StationID))
{
list = list.Where(p => p.StationID.Equals(StationID)).ToList();
}
List<Injection_RecordModel> modelList = new List<Injection_RecordModel>();
if (list.Count > 0)
{
#region 联查
BasicBLL<tb_Station> machine_db = new BasicBLL<tb_Station>();
var machine_list = machine_db.SearchAllInfo();
foreach (var item in list)
{
Injection_RecordModel dm = Tool.Mapper<Injection_RecordModel, tb_Injection_Record>(item);
var machine_info = machine_list.FirstOrDefault(p => p.StationID == item.StationID);
if (machine_info != null)
{
dm.StationNo = machine_info.StationNo;
}
modelList.Add(dm);
}
#endregion
total = modelList.Count;
int Skipcount = (Convert.ToInt32(page) - 1) * Convert.ToInt32(pagesize);
modelList = modelList.Skip(Skipcount).Take(Convert.ToInt32(pagesize)).ToList();
JsonDataModel<Injection_RecordModel> md = new JsonDataModel<Injection_RecordModel>();
md.total = total.ToString();
md.rows = modelList;
jsonStr = JSONTools.ScriptSerialize<JsonDataModel<Injection_RecordModel>>(md);
}
return jsonStr;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
#region 废料信息录入
public string SearchInfo(string page, string pagesize, string StartTime, string EndTime, string StationID)
{
try
{
string jsonStr = "[]";
int total = 0;//总行数
DateTime stime = Convert.ToDateTime(StartTime);
DateTime etime = Convert.ToDateTime(EndTime);
DataTable dt = dal.SearchRecordByPage(Convert.ToInt32(page), Convert.ToInt32(pagesize), StartTime, EndTime, StationID);
IList<ProductInjectionModel> list = Tool.ConvertTo<ProductInjectionModel>(dt);
if (list.Count > 0)
{
total = list.Count;
JsonDataModel<ProductInjectionModel> md = new JsonDataModel<ProductInjectionModel>();
md.total = total.ToString();
md.rows = list.ToList();
jsonStr = JSONTools.ScriptSerialize(md);
}
return jsonStr;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public bool UpdateWasteInfo(tb_Product_Injection_w md)
{
try
{
var info = ef.tb_Product_Injection_w.Where(p => p.ID.Equals(md.ID)).FirstOrDefault();//判断是否有重复数据
if (info != null)
{
//初始化要更新的字段
string[] proNames = new string[3];
proNames[0] = "RealCycle";
proNames[1] = "JK_Weight";
proNames[2] = "Waste_Weight";
//必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化
//如果没有初始化必填字段,更新会报错
db_w.UpdateInfo(md, proNames);
}
else
{
db_w.AddInfo(md);
}
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
#endregion
/// <summary>
/// 查询全部信息
/// </summary>
/// <returns></returns>
public List<tb_Injection_Record> SearchAll()
{
try
{
var s_list = db.SearchAllInfo().ToList();
return s_list;
}
catch (Exception)
{
return null;
}
}
/// <summary>
/// 根据ID查询信息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public tb_Injection_Record SearchInfoByID(string id)
{
try
{
return db.SearchInfoByID(id);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
#region 日合格趋势
//表格
public string SearchQualifiedDay(string StartTime)
{
try
{
DateTime sTime = Convert.ToDateTime(StartTime);
int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(sTime.Year, sTime.Month);
StringBuilder sb = new StringBuilder(100);
DataTable dt = dal.SearchByTime(Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-01").ToString("yyyy-MM-dd"), Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + days.ToString()).ToString("yyyy-MM-dd"));
if (dt != null && dt.Rows.Count > 0)
{
List<string> titleList = new List<string>();
List<double> totalList = new List<double>();
List<double> No_totalList = new List<double>();
List<double> OK_L_List = new List<double>();
for (int i = 0; i < days; i++)
{
titleList.Add((i + 1) + "日");
string nowTime = Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + (i + 1)).ToString("yyyy-MM-dd");
var DayList = from myRow in dt.AsEnumerable()
where myRow.Field<string>(3) == nowTime
select myRow;
double total_OK = DayList.Sum(p => (int)p.ItemArray[7]);
double total_NO = DayList.Sum(p => (int)p.ItemArray[8]);
double total_all = total_OK + total_NO;
totalList.Add(total_OK);
No_totalList.Add(total_NO);
if (total_all > 0)
{
OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2));
}
else
{
OK_L_List.Add(0);
}
}
sb.Append("<table border='1'>");
sb.Append("<tr>");
sb.Append("<td width='50'></td>");
foreach (var item in titleList)
{
sb.Append("<td width='50'>" + item + "</td>");
}
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td width='100'>总合格数量</td>");
foreach (var item in totalList)
{
sb.Append("<td width='50'>" + item + "</td>");
}
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td width='100'>不良数量</td>");
foreach (var item in No_totalList)
{
sb.Append("<td width='50'>" + item + "</td>");
}
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td width='100'>合格率</td>");
foreach (var item in OK_L_List)
{
sb.Append("<td width='50'>" + item + "%</td>");
}
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td width='100'>目标值</td>");
foreach (var item in OK_L_List)
{
sb.Append("<td width='50'>99.6%</td>");
}
sb.Append("</tr>");
sb.Append("</table>");
}
return sb.ToString();
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
//柱状图
public EcharBarModel SearchQualifiedDayBar(string StartTime)
{
try
{
EcharBarModel md = new EcharBarModel();
DateTime sTime = Convert.ToDateTime(StartTime);
int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(sTime.Year, sTime.Month);
StringBuilder sb = new StringBuilder(100);
DataTable dt = dal.SearchByTime(Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-01").ToString("yyyy-MM-dd"), Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + days.ToString()).ToString("yyyy-MM-dd"));
if (dt != null && dt.Rows.Count > 0)
{
List<string> titleList = new List<string>();
List<double> totalList = new List<double>();
List<double> No_totalList = new List<double>();
List<double> OK_L_List = new List<double>();
List<double> T_L_List = new List<double>();
for (int i = 0; i < days; i++)
{
titleList.Add((i + 1) + "日");
string nowTime = Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + (i + 1)).ToString("yyyy-MM-dd");
var DayList = from myRow in dt.AsEnumerable()
where myRow.Field<string>(3) == nowTime
select myRow;
double total_OK = DayList.Sum(p => (int)p.ItemArray[7]);
double total_NO = DayList.Sum(p => (int)p.ItemArray[8]);
double total_all = total_OK + total_NO;
totalList.Add(total_OK);
No_totalList.Add(total_NO);
if (total_all > 0)
{
OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2));
}
else
{
OK_L_List.Add(0);
}
}
foreach (var item in OK_L_List)
{
T_L_List.Add(99.6);
}
md.categories = titleList;
md.QualifiedData = OK_L_List;
md.TargetData = T_L_List;
}
return md;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public List<List<string>> SearchQualifiedDayForExcel(string StartTime)
{
try
{
List<List<string>> list = new List<List<string>>();
DateTime sTime = Convert.ToDateTime(StartTime);
int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(sTime.Year, sTime.Month);
StringBuilder sb = new StringBuilder(100);
DataTable dt = dal.SearchByTime(Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-01").ToString("yyyy-MM-dd"), Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + days.ToString()).ToString("yyyy-MM-dd"));
if (dt != null && dt.Rows.Count > 0)
{
List<string> titleList = new List<string>();
List<double> totalList = new List<double>();
List<double> No_totalList = new List<double>();
List<double> OK_L_List = new List<double>();
for (int i = 0; i < days; i++)
{
titleList.Add((i + 1) + "日");
string nowTime = Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + (i + 1)).ToString("yyyy-MM-dd");
var DayList = from myRow in dt.AsEnumerable()
where myRow.Field<string>(3) == nowTime
select myRow;
double total_OK = DayList.Sum(p => (int)p.ItemArray[7]);
double total_NO = DayList.Sum(p => (int)p.ItemArray[8]);
double total_all = total_OK + total_NO;
totalList.Add(total_OK);
No_totalList.Add(total_NO);
if (total_all > 0)
{
OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2));
}
else
{
OK_L_List.Add(0);
}
}
List<string> title_ = new List<string>();
title_.Add("");
title_.AddRange(titleList);
list.Add(title_);
List<string> total_ = new List<string>();
total_.Add("总合格数量");
foreach (var item in totalList)
{
total_.Add(item.ToString());
}
list.Add(total_);
List<string> No_total_ = new List<string>();
No_total_.Add("不良数量");
foreach (var item in No_totalList)
{
No_total_.Add(item.ToString());
}
list.Add(No_total_);
List<string> OK_L_ = new List<string>();
OK_L_.Add("合格率");
foreach (var item in OK_L_List)
{
OK_L_.Add(item.ToString() + "%");
}
list.Add(OK_L_);
List<string> tag_L_ = new List<string>();
tag_L_.Add("目标值");
foreach (var item in OK_L_List)
{
tag_L_.Add("99.6%");
}
list.Add(tag_L_);
}
return list;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
#endregion
#region 月合格趋势
//表格
public string SearchQualifiedMonth(string StartTime)
{
try
{
DateTime sTime = Convert.ToDateTime(StartTime);
StringBuilder sb = new StringBuilder(100);
DataTable dt = dal.SearchByTime(sTime.Year + "-01-01", sTime.Year + "-12-31");
if (dt != null && dt.Rows.Count > 0)
{
DateTime startT = Convert.ToDateTime(sTime.Year + "-01-01");
List<string> titleList = new List<string>();
List<double> totalList = new List<double>();
List<double> No_totalList = new List<double>();
List<double> OK_L_List = new List<double>();
for (int i = 0; i < 12; i++)
{
titleList.Add((i + 1) + "月");
int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(startT.Year, (i + 1));
string starTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd");
string entTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd");
var DayList = from myRow in dt.AsEnumerable()
where myRow.Field<string>(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd")) >= 0 &&
myRow.Field<string>(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd")) <= 0
select myRow;
double total_OK = DayList.Sum(p => (int)p.ItemArray[7]);
double total_NO = DayList.Sum(p => (int)p.ItemArray[8]);
double total_all = total_OK + total_NO;
totalList.Add(total_OK);
No_totalList.Add(total_NO);
if (total_all > 0)
{
OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2));
}
else
{
OK_L_List.Add(0);
}
}
sb.Append("<table border='1' width='1000'>");
sb.Append("<tr>");
sb.Append("<td width='50'></td>");
foreach (var item in titleList)
{
sb.Append("<td width='50'>" + item + "</td>");
}
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td width='50'>总合格数量</td>");
foreach (var item in totalList)
{
sb.Append("<td width='50'>" + item + "</td>");
}
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td width='50'>不良数量</td>");
foreach (var item in No_totalList)
{
sb.Append("<td width='50'>" + item + "</td>");
}
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td width='50'>合格率</td>");
foreach (var item in OK_L_List)
{
sb.Append("<td width='50'>" + item + "%</td>");
}
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td width='50'>目标值</td>");
foreach (var item in OK_L_List)
{
sb.Append("<td width='50'>99.6%</td>");
}
sb.Append("</tr>");
sb.Append("</table>");
}
return sb.ToString();
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
//柱状图
public EcharBarModel SearchQualifiedMonthBar(string StartTime)
{
try
{
EcharBarModel md = new EcharBarModel();
DateTime sTime = Convert.ToDateTime(StartTime);
DataTable dt = dal.SearchByTime(sTime.Year + "-01-01", sTime.Year + "-12-31");
if (dt != null && dt.Rows.Count > 0)
{
DateTime startT = Convert.ToDateTime(sTime.Year + "-01-01");
List<string> titleList = new List<string>();
List<double> totalList = new List<double>();
List<double> No_totalList = new List<double>();
List<double> OK_L_List = new List<double>();
List<double> T_L_List = new List<double>();
for (int i = 0; i < 12; i++)
{
titleList.Add((i + 1) + "月");
int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(startT.Year, (i + 1));
string starTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd");
string entTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd");
var DayList = from myRow in dt.AsEnumerable()
where myRow.Field<string>(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd")) >= 0 &&
myRow.Field<string>(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd")) <= 0
select myRow;
double total_OK = DayList.Sum(p => (int)p.ItemArray[7]);
double total_NO = DayList.Sum(p => (int)p.ItemArray[8]);
double total_all = total_OK + total_NO;
totalList.Add(total_OK);
No_totalList.Add(total_NO);
if (total_all > 0)
{
OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2));
}
else
{
OK_L_List.Add(0);
}
}
foreach (var item in OK_L_List)
{
T_L_List.Add(99.6);
}
md.categories = titleList;
md.QualifiedData = OK_L_List;
md.TargetData = T_L_List;
}
return md;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public List<List<string>> SearchQualifiedMonthForExcel(string StartTime)
{
try
{
List<List<string>> list = new List<List<string>>();
DateTime sTime = Convert.ToDateTime(StartTime);
StringBuilder sb = new StringBuilder(100);
DataTable dt = dal.SearchByTime(sTime.Year + "-01-01", sTime.Year + "-12-31");
if (dt != null && dt.Rows.Count > 0)
{
DateTime startT = Convert.ToDateTime(sTime.Year + "-01-01");
List<string> titleList = new List<string>();
List<double> totalList = new List<double>();
List<double> No_totalList = new List<double>();
List<double> OK_L_List = new List<double>();
for (int i = 0; i < 12; i++)
{
titleList.Add((i + 1) + "月");
int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(startT.Year, (i + 1));
string starTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd");
string entTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd");
var DayList = from myRow in dt.AsEnumerable()
where myRow.Field<string>(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd")) >= 0 &&
myRow.Field<string>(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd")) <= 0
select myRow;
double total_OK = DayList.Sum(p => (int)p.ItemArray[7]);
double total_NO = DayList.Sum(p => (int)p.ItemArray[8]);
double total_all = total_OK + total_NO;
totalList.Add(total_OK);
No_totalList.Add(total_NO);
if (total_all > 0)
{
OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2));
}
else
{
OK_L_List.Add(0);
}
}
List<string> title_ = new List<string>();
title_.Add("");
title_.AddRange(titleList);
list.Add(title_);
List<string> total_ = new List<string>();
total_.Add("总合格数量");
foreach (var item in totalList)
{
total_.Add(item.ToString());
}
list.Add(total_);
List<string> No_total_ = new List<string>();
No_total_.Add("不良数量");
foreach (var item in No_totalList)
{
No_total_.Add(item.ToString());
}
list.Add(No_total_);
List<string> OK_L_ = new List<string>();
OK_L_.Add("合格率");
foreach (var item in OK_L_List)
{
OK_L_.Add(item.ToString() + "%");
}
list.Add(OK_L_);
List<string> tag_L_ = new List<string>();
tag_L_.Add("目标值");
foreach (var item in OK_L_List)
{
tag_L_.Add("99.6%");
}
list.Add(tag_L_);
}
return list;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
#endregion
#region 日原料利用率
public string SearchMaterialAvailabilityDay(string StartTime)
{
try
{
var p_info = ef.tb_Plastic.Where(p => p.Weight != null);
DateTime sTime = Convert.ToDateTime(StartTime);
int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(sTime.Year, sTime.Month);
StringBuilder sb = new StringBuilder(100);
DataTable dt = dal.SearchByTime(Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-01").ToString("yyyy-MM-dd"), Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + days.ToString()).ToString("yyyy-MM-dd"));
if (dt != null && dt.Rows.Count > 0)
{
List<string> titleList = new List<string>();
List<double> totalList = new List<double>();
List<double> No_totalList = new List<double>();
List<double> All_totalList = new List<double>();
List<double> OK_L_List = new List<double>();
for (int i = 0; i < days; i++)
{
titleList.Add((i + 1) + "日");
string nowTime = Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + (i + 1)).ToString("yyyy-MM-dd");
var listAddress = (from myRow in dt.AsEnumerable()
where myRow.Field<string>(3) == nowTime
group myRow by new { StockNo = myRow.ItemArray[5] } into g
//orderby new ComparerItem() { OrderIndex = b.Key., Id = b.Key.Id } descending
select new
{
StockNo = (string)g.Key.StockNo,
total_ok = g.Sum(c => (int)c.ItemArray[7]),
total_no = g.Sum(c => (int)c.ItemArray[8])
});
double total_OK = 0;
double total_NO = 0;
foreach (var item in listAddress)
{
string stockNo = item.StockNo;
var w_info = p_info.FirstOrDefault(p => p.StockNo.Equals(stockNo));
if (w_info != null)
{
total_OK += (double)(w_info.Weight * item.total_ok);
total_NO += (double)(w_info.Weight * item.total_no);
}
}
totalList.Add(Math.Round(total_OK / 1000, 2));
No_totalList.Add(Math.Round(total_NO / 1000, 2));
DateTime nsTime = Convert.ToDateTime(nowTime + " 00:00:00");
DateTime neTime = Convert.ToDateTime(nowTime + " 23:59:59");
var Waste_Num = ef.tb_Injection_Record.Where(p => p.RecordDate >= nsTime && p.RecordDate <= neTime).Sum(p => p.Waste_Weight);
double total_Waste = 0;
if (Waste_Num == null)
{
total_Waste = 0;
}
else
{
total_Waste = (double)Waste_Num;
}
double total_all = total_OK + total_NO + total_Waste;
All_totalList.Add(Math.Round(total_all / 1000, 2));
if (total_all > 0)
{
OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2));
}
else
{
OK_L_List.Add(0);
}
}
sb.Append("<table border='1'>");
sb.Append("<tr>");
sb.Append("<td width='50'></td>");
foreach (var item in titleList)
{
sb.Append("<td width='50'>" + item + "</td>");
}
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td width='50'>目标值</td>");
foreach (var item in OK_L_List)
{
sb.Append("<td width='50'>98%</td>");
}
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td width='50'>合格件耗用原料</td>");
foreach (var item in totalList)
{
sb.Append("<td width='50'>" + item + "</td>");
}
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td width='50'>总耗用原料</td>");
foreach (var item in All_totalList)
{
sb.Append("<td width='50'>" + item + "</td>");
}
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td width='50'>原料利用率</td>");
foreach (var item in OK_L_List)
{
sb.Append("<td width='50'>" + item + "%</td>");
}
sb.Append("</tr>");
sb.Append("</table>");
}
return sb.ToString();
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
//柱状图
public EcharBarModel SearchMaterialAvailabilityDayBar(string StartTime)
{
try
{
EcharBarModel md = new EcharBarModel();
var p_info = ef.tb_Plastic.Where(p => p.Weight != null);
DateTime sTime = Convert.ToDateTime(StartTime);
int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(sTime.Year, sTime.Month);
StringBuilder sb = new StringBuilder(100);
DataTable dt = dal.SearchByTime(Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-01").ToString("yyyy-MM-dd"), Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + days.ToString()).ToString("yyyy-MM-dd"));
if (dt != null && dt.Rows.Count > 0)
{
List<string> titleList = new List<string>();
List<double> totalList = new List<double>();
List<double> No_totalList = new List<double>();
List<double> OK_L_List = new List<double>();
List<double> T_L_List = new List<double>();
for (int i = 0; i < days; i++)
{
titleList.Add((i + 1) + "日");
string nowTime = Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + (i + 1)).ToString("yyyy-MM-dd");
var listAddress = (from myRow in dt.AsEnumerable()
where myRow.Field<string>(3) == nowTime
group myRow by new { StockNo = myRow.ItemArray[5] } into g
//orderby new ComparerItem() { OrderIndex = b.Key., Id = b.Key.Id } descending
select new
{
StockNo = (string)g.Key.StockNo,
total_ok = g.Sum(c => (int)c.ItemArray[7]),
total_no = g.Sum(c => (int)c.ItemArray[8])
});
double total_OK = 0;
double total_NO = 0;
foreach (var item in listAddress)
{
string stockNo = item.StockNo;
var w_info = p_info.FirstOrDefault(p => p.StockNo.Equals(stockNo));
if (w_info != null)
{
total_OK += (double)(w_info.Weight * item.total_ok);
total_NO += (double)(w_info.Weight * item.total_no);
}
}
totalList.Add(Math.Round(total_OK / 1000, 2));
No_totalList.Add(Math.Round(total_NO / 1000, 2));
DateTime nsTime = Convert.ToDateTime(nowTime + " 00:00:00");
DateTime neTime = Convert.ToDateTime(nowTime + " 23:59:59");
var Waste_Num = ef.tb_Injection_Record.Where(p => p.RecordDate >= nsTime && p.RecordDate <= neTime).Sum(p => p.Waste_Weight);
double total_Waste = 0;
if (Waste_Num == null)
{
total_Waste = 0;
}
else
{
total_Waste = (double)Waste_Num;
}
double total_all = total_OK + total_NO + total_Waste;
if (total_all > 0)
{
OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2));
}
else
{
OK_L_List.Add(0);
}
}
foreach (var item in OK_L_List)
{
T_L_List.Add(98);
}
md.categories = titleList;
md.QualifiedData = OK_L_List;
md.TargetData = T_L_List;
}
return md;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public List<List<string>> SearchMaterialAvailabilityDayForExcel(string StartTime)
{
try
{
List<List<string>> list = new List<List<string>>();
var p_info = ef.tb_Plastic.Where(p => p.Weight != null);
DateTime sTime = Convert.ToDateTime(StartTime);
int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(sTime.Year, sTime.Month);
StringBuilder sb = new StringBuilder(100);
DataTable dt = dal.SearchByTime(Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-01").ToString("yyyy-MM-dd"), Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + days.ToString()).ToString("yyyy-MM-dd"));
if (dt != null && dt.Rows.Count > 0)
{
List<string> titleList = new List<string>();
List<double> totalList = new List<double>();
List<double> No_totalList = new List<double>();
List<double> All_totalList = new List<double>();
List<double> OK_L_List = new List<double>();
for (int i = 0; i < days; i++)
{
titleList.Add((i + 1) + "日");
string nowTime = Convert.ToDateTime(sTime.Year + "-" + sTime.Month + "-" + (i + 1)).ToString("yyyy-MM-dd");
var listAddress = (from myRow in dt.AsEnumerable()
where myRow.Field<string>(3) == nowTime
group myRow by new { StockNo = myRow.ItemArray[5] } into g
//orderby new ComparerItem() { OrderIndex = b.Key., Id = b.Key.Id } descending
select new
{
StockNo = (string)g.Key.StockNo,
total_ok = g.Sum(c => (int)c.ItemArray[7]),
total_no = g.Sum(c => (int)c.ItemArray[8])
});
double total_OK = 0;
double total_NO = 0;
foreach (var item in listAddress)
{
string stockNo = item.StockNo;
var w_info = p_info.FirstOrDefault(p => p.StockNo.Equals(stockNo));
if (w_info != null)
{
total_OK += (double)(w_info.Weight * item.total_ok);
total_NO += (double)(w_info.Weight * item.total_no);
}
}
totalList.Add(Math.Round(total_OK / 1000, 2));
No_totalList.Add(Math.Round(total_NO / 1000, 2));
DateTime nsTime = Convert.ToDateTime(nowTime + " 00:00:00");
DateTime neTime = Convert.ToDateTime(nowTime + " 23:59:59");
var Waste_Num = ef.tb_Injection_Record.Where(p => p.RecordDate >= nsTime && p.RecordDate <= neTime).Sum(p => p.Waste_Weight);
double total_Waste = 0;
if (Waste_Num == null)
{
total_Waste = 0;
}
else
{
total_Waste = (double)Waste_Num;
}
double total_all = total_OK + total_NO + total_Waste;
All_totalList.Add(Math.Round(total_all / 1000, 2));
if (total_all > 0)
{
OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2));
}
else
{
OK_L_List.Add(0);
}
}
List<string> title_ = new List<string>();
title_.Add("");
title_.AddRange(titleList);
list.Add(title_);
List<string> tag_L_ = new List<string>();
tag_L_.Add("目标值");
foreach (var item in OK_L_List)
{
tag_L_.Add("98%");
}
list.Add(tag_L_);
List<string> total_ = new List<string>();
total_.Add("合格件耗用原料");
foreach (var item in totalList)
{
total_.Add(item.ToString());
}
list.Add(total_);
List<string> No_total_ = new List<string>();
No_total_.Add("总耗用原料");
foreach (var item in All_totalList)
{
No_total_.Add(item.ToString());
}
list.Add(No_total_);
List<string> OK_L_ = new List<string>();
OK_L_.Add("原料利用率");
foreach (var item in OK_L_List)
{
OK_L_.Add(item.ToString() + "%");
}
list.Add(OK_L_);
}
return list;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
#endregion
#region 月原料利用率
public string SearchMaterialAvailabilityMonth(string StartTime)
{
try
{
StringBuilder sb = new StringBuilder(100);
var p_info = ef.tb_Plastic.Where(p => p.Weight != null);
DateTime sTime = Convert.ToDateTime(StartTime);
DataTable dt = dal.SearchByTime(sTime.Year + "-01-01", sTime.Year + "-12-31");
if (dt != null && dt.Rows.Count > 0)
{
List<string> titleList = new List<string>();
List<double> totalList = new List<double>();
List<double> No_totalList = new List<double>();
List<double> All_totalList = new List<double>();
List<double> OK_L_List = new List<double>();
for (int i = 0; i < 12; i++)
{
DateTime startT = Convert.ToDateTime(sTime.Year + "-01-01");
titleList.Add((i + 1) + "月");
int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(startT.Year, (i + 1));
string starTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd");
string entTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd");
var listAddress = (from myRow in dt.AsEnumerable()
where myRow.Field<string>(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd")) >= 0 &&
myRow.Field<string>(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd")) <= 0
group myRow by new { StockNo = myRow.ItemArray[5] } into g
select new
{
StockNo = (string)g.Key.StockNo,
total_ok = g.Sum(c => (int)c.ItemArray[7]),
total_no = g.Sum(c => (int)c.ItemArray[8])
});
double total_OK = 0;
double total_NO = 0;
foreach (var item in listAddress)
{
string stockNo = item.StockNo;
var w_info = p_info.FirstOrDefault(p => p.StockNo.Equals(stockNo));
if (w_info != null)
{
total_OK += (double)(w_info.Weight * item.total_ok);
total_NO += (double)(w_info.Weight * item.total_no);
}
}
totalList.Add(Math.Round(total_OK / 1000, 2));
No_totalList.Add(Math.Round(total_NO / 1000, 2));
DateTime nsTime = Convert.ToDateTime(starTime + " 00:00:00");
DateTime neTime = Convert.ToDateTime(entTime + " 23:59:59");
var Waste_Num = ef.tb_Injection_Record.Where(p => p.RecordDate >= nsTime && p.RecordDate <= neTime).Sum(p => p.Waste_Weight);
double total_Waste = 0;
if (Waste_Num == null)
{
total_Waste = 0;
}
else
{
total_Waste = (double)Waste_Num;
}
double total_all = total_OK + total_NO + total_Waste;
All_totalList.Add(Math.Round(total_all / 1000, 2));
if (total_all > 0)
{
OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2));
}
else
{
OK_L_List.Add(0);
}
}
sb.Append("<table border='1' width='1000'>");
sb.Append("<tr>");
sb.Append("<td width='50'></td>");
foreach (var item in titleList)
{
sb.Append("<td width='50'>" + item + "</td>");
}
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td width='50'>目标值</td>");
foreach (var item in OK_L_List)
{
sb.Append("<td width='50'>98%</td>");
}
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td width='50'>合格件耗用原料</td>");
foreach (var item in totalList)
{
sb.Append("<td width='50'>" + item + "</td>");
}
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td width='50'>总耗用原料</td>");
foreach (var item in All_totalList)
{
sb.Append("<td width='50'>" + item + "</td>");
}
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td width='50'>原料利用率</td>");
foreach (var item in OK_L_List)
{
sb.Append("<td width='50'>" + item + "%</td>");
}
sb.Append("</tr>");
sb.Append("</table>");
}
return sb.ToString();
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public EcharBarModel SearchMaterialAvailabilityMonthBar(string StartTime)
{
try
{
EcharBarModel md = new EcharBarModel();
var p_info = ef.tb_Plastic.Where(p => p.Weight != null);
DateTime sTime = Convert.ToDateTime(StartTime);
DataTable dt = dal.SearchByTime(sTime.Year + "-01-01", sTime.Year + "-12-31");
if (dt != null && dt.Rows.Count > 0)
{
List<string> titleList = new List<string>();
List<double> totalList = new List<double>();
List<double> No_totalList = new List<double>();
List<double> OK_L_List = new List<double>();
List<double> T_L_List = new List<double>();
for (int i = 0; i < 12; i++)
{
DateTime startT = Convert.ToDateTime(sTime.Year + "-01-01");
titleList.Add((i + 1) + "月");
int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(startT.Year, (i + 1));
string starTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd");
string entTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd");
var listAddress = (from myRow in dt.AsEnumerable()
where myRow.Field<string>(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd")) >= 0 &&
myRow.Field<string>(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd")) <= 0
group myRow by new { StockNo = myRow.ItemArray[5] } into g
select new
{
StockNo = (string)g.Key.StockNo,
total_ok = g.Sum(c => (int)c.ItemArray[7]),
total_no = g.Sum(c => (int)c.ItemArray[8])
});
double total_OK = 0;
double total_NO = 0;
foreach (var item in listAddress)
{
string stockNo = item.StockNo;
var w_info = p_info.FirstOrDefault(p => p.StockNo.Equals(stockNo));
if (w_info != null)
{
total_OK += (double)(w_info.Weight * item.total_ok);
total_NO += (double)(w_info.Weight * item.total_no);
}
}
totalList.Add(Math.Round(total_OK / 1000, 2));
No_totalList.Add(Math.Round(total_NO / 1000, 2));
DateTime nsTime = Convert.ToDateTime(starTime + " 00:00:00");
DateTime neTime = Convert.ToDateTime(entTime + " 23:59:59");
var Waste_Num = ef.tb_Injection_Record.Where(p => p.RecordDate >= nsTime && p.RecordDate <= neTime).Sum(p => p.Waste_Weight);
double total_Waste = 0;
if (Waste_Num == null)
{
total_Waste = 0;
}
else
{
total_Waste = (double)Waste_Num;
}
double total_all = total_OK + total_NO + total_Waste;
if (total_all > 0)
{
OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2));
}
else
{
OK_L_List.Add(0);
}
}
foreach (var item in OK_L_List)
{
T_L_List.Add(98);
}
md.categories = titleList;
md.QualifiedData = OK_L_List;
md.TargetData = T_L_List;
}
return md;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public List<List<string>> SearchMaterialAvailabilityMonthForExcel(string StartTime)
{
try
{
List<List<string>> list = new List<List<string>>();
var p_info = ef.tb_Plastic.Where(p => p.Weight != null);
DateTime sTime = Convert.ToDateTime(StartTime);
DataTable dt = dal.SearchByTime(sTime.Year + "-01-01", sTime.Year + "-12-31");
if (dt != null && dt.Rows.Count > 0)
{
List<string> titleList = new List<string>();
List<double> totalList = new List<double>();
List<double> No_totalList = new List<double>();
List<double> All_totalList = new List<double>();
List<double> OK_L_List = new List<double>();
for (int i = 0; i < 12; i++)
{
DateTime startT = Convert.ToDateTime(sTime.Year + "-01-01");
titleList.Add((i + 1) + "月");
int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(startT.Year, (i + 1));
string starTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd");
string entTime = Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd");
var listAddress = (from myRow in dt.AsEnumerable()
where myRow.Field<string>(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-01").ToString("yyyy-MM-dd")) >= 0 &&
myRow.Field<string>(3).CompareTo(Convert.ToDateTime(sTime.Year + "-" + (i + 1) + "-" + days).ToString("yyyy-MM-dd")) <= 0
group myRow by new { StockNo = myRow.ItemArray[5] } into g
select new
{
StockNo = (string)g.Key.StockNo,
total_ok = g.Sum(c => (int)c.ItemArray[7]),
total_no = g.Sum(c => (int)c.ItemArray[8])
});
double total_OK = 0;
double total_NO = 0;
foreach (var item in listAddress)
{
string stockNo = item.StockNo;
var w_info = p_info.FirstOrDefault(p => p.StockNo.Equals(stockNo));
if (w_info != null)
{
total_OK += (double)(w_info.Weight * item.total_ok);
total_NO += (double)(w_info.Weight * item.total_no);
}
}
totalList.Add(Math.Round(total_OK / 1000, 2));
No_totalList.Add(Math.Round(total_NO / 1000, 2));
DateTime nsTime = Convert.ToDateTime(starTime + " 00:00:00");
DateTime neTime = Convert.ToDateTime(entTime + " 23:59:59");
var Waste_Num = ef.tb_Injection_Record.Where(p => p.RecordDate >= nsTime && p.RecordDate <= neTime).Sum(p => p.Waste_Weight);
double total_Waste = 0;
if (Waste_Num == null)
{
total_Waste = 0;
}
else
{
total_Waste = (double)Waste_Num;
}
double total_all = total_OK + total_NO + total_Waste;
All_totalList.Add(Math.Round(total_all / 1000, 2));
if (total_all > 0)
{
OK_L_List.Add(Math.Round((total_OK / total_all) * 100, 2));
}
else
{
OK_L_List.Add(0);
}
}
List<string> title_ = new List<string>();
title_.Add("");
title_.AddRange(titleList);
list.Add(title_);
List<string> tag_L_ = new List<string>();
tag_L_.Add("目标值");
foreach (var item in OK_L_List)
{
tag_L_.Add("98%");
}
list.Add(tag_L_);
List<string> total_ = new List<string>();
total_.Add("合格件耗用原料");
foreach (var item in totalList)
{
total_.Add(item.ToString());
}
list.Add(total_);
List<string> No_total_ = new List<string>();
No_total_.Add("总耗用原料");
foreach (var item in All_totalList)
{
No_total_.Add(item.ToString());
}
list.Add(No_total_);
List<string> OK_L_ = new List<string>();
OK_L_.Add("原料利用率");
foreach (var item in OK_L_List)
{
OK_L_.Add(item.ToString() + "%");
}
list.Add(OK_L_);
}
return list;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
#endregion
#region 注塑生产记录表
public string SearchProductInjectionRecord(string StartTime, string EndTime)
{
var defectList = ef.tb_Defect.ToList();
var defectInfo = defectList.Where(p => p.LineID.Equals(defectList.FirstOrDefault().LineID)).OrderBy(p => p.DefectName).Select(p => p.DefectName).ToList();
var DownReasonList = ef.tb_Inhection_DownReason.OrderBy(p => p.Reason).Select(p => p.Reason).ToList();
DataTable dt = dal.SearchProductInjectionRecord(Convert.ToDateTime(StartTime).ToString("yyyy-MM-dd"), Convert.ToDateTime(EndTime).ToString("yyyy-MM-dd"));
DataTable dt2 = dal.SearchProductInjectionRecordBadReason(Convert.ToDateTime(StartTime).ToString("yyyy-MM-dd"), Convert.ToDateTime(EndTime).ToString("yyyy-MM-dd"));
List<InjectionBadReasonModel> list = Tool.ConvertTo<InjectionBadReasonModel>(dt2).ToList();
DataTable dt3 = dal.SearchProductInjectionRecordDownReason(Convert.ToDateTime(StartTime).ToString("yyyy-MM-dd"), Convert.ToDateTime(EndTime).ToString("yyyy-MM-dd"));
List<InjectionRecordDownReasonModel> list3 = Tool.ConvertTo<InjectionRecordDownReasonModel>(dt3).ToList();
StringBuilder sb = new StringBuilder(100);
sb.Append("<table border='1' style='text-align:center;vertical-align:middle;'>");
sb.Append("<tr>");
sb.Append("<td width='50' rowspan='2'>生产日期</td>");
sb.Append("<td width='50' rowspan='2'>班别</td>");
sb.Append("<td width='50' rowspan='2'>机台</td>");
sb.Append("<td width='50' rowspan='2'>模取</td>");
sb.Append("<td width='50' rowspan='2'>厂商</td>");
sb.Append("<td width='50' rowspan='2'>周期(S)</td>");
sb.Append("<td width='50' rowspan='2'>物料号</td>");
sb.Append("<td width='50' rowspan='2'>新零件号编码</td>");
sb.Append("<td width='50' rowspan='2'>产品性质</td>");
sb.Append("<td width='50' rowspan='2'>物料名称</td>");
sb.Append("<td width='50' rowspan='2'>生产数量</td>");
sb.Append("<td width='50' rowspan='2'>合格数量</td>");
sb.Append("<td width='50' rowspan='2'>市场件数量</td>");
sb.Append("<td width='50' rowspan='2'>调试不良</td>");
sb.Append("<td width='50' rowspan='2'>生产不良</td>");
sb.Append("<td width='50' rowspan='2'>开机不良</td>");
sb.Append("<td width='50' rowspan='2'>奔驰前十模报废</td>");
sb.Append("<td width='50' rowspan='2'>不良总数量</td>");
sb.Append("<td width='50' rowspan='2'>前十模+不良总数量之和</td>");
sb.Append("<td width='50' rowspan='2'>合格率</td>");
sb.Append("<td width='50' rowspan='2'>不良率</td>");
sb.Append("<td width='50' rowspan='2'>生产时间(min)</td>");
sb.Append("<td width='50' rowspan='2'>机台利用率</td>");
sb.Append("<td width='50' rowspan='2'>OEE</td>");
sb.Append("<td width='50' rowspan='2'>原料物料号</td>");
sb.Append("<td width='50' rowspan='2'>原料名称</td>");
sb.Append("<td width='50' rowspan='2'>单品净重(kg)</td>");
sb.Append("<td width='50' rowspan='2'>塑件毛重(kg)</td>");
sb.Append("<td width='50' rowspan='2'>料棒重量(kg)</td>");
sb.Append("<td width='50' rowspan='2'>物料使用(kg)</td>");
sb.Append("<td width='50' rowspan='2'>机头料(kg)</td>");
sb.Append("<td width='50' rowspan='2'>料棒/浇口(kg)</td>");
sb.Append("<td width='50' rowspan='2'>不良品(kg)</td>");
sb.Append("<td width='50' rowspan='2'>奔驰前十模使用原料</td>");
sb.Append("<td width='50' rowspan='2'>回料(kg)</td>");
//sb.Append("<td width='50' colspan='" + defectInfo.Count + "'>不良原因</td>");
//sb.Append("<td width='50' rowspan='2'>产品毛重</td>");
//sb.Append("<td width='50' rowspan='2'>废料块</td>");
//sb.Append("<td width='50' rowspan='2'>浇口重量</td>");
//sb.Append("<td width='50' rowspan='2'>产品耗用原料</td>");
//sb.Append("<td width='50' rowspan='2'>合格率</td>");
//sb.Append("<td width='50' rowspan='2'>完成率</td>");
//sb.Append("<td width='50' rowspan='2'>计划工时</td>");
//sb.Append("<td width='50' rowspan='2'>产出工时</td>");
//sb.Append("<td width='50' colspan='2'>停机时间</td>");
//sb.Append("<td width='50' colspan='3'>换膜</td>");
//sb.Append("<td width='50' rowspan='2'>计划停机</td>");
//sb.Append("<td width='50' colspan='" + DownReasonList.Count + "'>停机原因</td>");
sb.Append("</tr>");
//sb.Append("<tr>");
//foreach (var item in defectInfo)
//{
// sb.Append("<td width='50'>" + item + "</td>");
//}
//sb.Append("<td width='50'>计划停机+换模时间</td>");
//sb.Append("<td width='50'>非计划停机</td>");
//sb.Append("<td width='50'>换膜</td>");
//sb.Append("<td width='50'>交班</td>");
//sb.Append("<td width='50'>接班</td>");
//foreach (var item in DownReasonList)
//{
// sb.Append("<td width='50'>" + item + "</td>");
//}
//sb.Append("</tr>");
try
{
if (dt != null && dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
sb.Append("<tr>");
sb.Append("<td width='50'>" + dt.Rows[i]["ProductDate"] + "</td>");//生产日期
sb.Append("<td width='50'>" + dt.Rows[i]["ClassName"].ToString() + "</td>");//班次
sb.Append("<td width='50'>" + dt.Rows[i]["StationNo"] + "</td>");//注塑机台
sb.Append("<td width='50'>" + dt.Rows[i]["IsOneMore"] + "</td>");//取模
sb.Append("<td width='50'>" + dt.Rows[i]["ManufacturerName"] + "</td>");//厂商
decimal cycle_Time = dt.Rows[i]["CycleTime"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["CycleTime"]);
sb.Append("<td width='50'>" + cycle_Time + "</td>");//周期
sb.Append("<td width='50'>" + dt.Rows[i]["BatchNo"] + "</td>");//原料号
sb.Append("<td width='50'>" + dt.Rows[i]["PartNo"] + "</td>");//新零件号编码
sb.Append("<td width='50'>正常</td>");//产品性质
sb.Append("<td width='50'>" + dt.Rows[i]["MaterialName"] + "</td>");//原料名称
decimal real_Cycle = dt.Rows[i]["RealCycle"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["RealCycle"]);
decimal product_count = dt.Rows[i]["ProductCount"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["ProductCount"]);
decimal market_count = dt.Rows[i]["MarketCount"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["MarketCount"]);
decimal bad_count = dt.Rows[i]["BadCount"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["BadCount"]);
decimal weight = dt.Rows[i]["Weight"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["Weight"]);
decimal plan_count = dt.Rows[i]["PlanCount"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["PlanCount"]);
sb.Append("<td width='50'>" + (product_count + market_count + bad_count) + "</td>");//生产数量(合格数量+市场件数+不良总数)
sb.Append("<td width='50'>" + product_count + "</td>");//合格数量
sb.Append("<td width='50'>" + market_count + "</td>");//市场件数
sb.Append("<td width='50'></td>");//调试不良
sb.Append("<td width='50'></td>");//生产不良
sb.Append("<td width='50'></td>");//开机不良
sb.Append("<td width='50'></td>");//奔驰前十模报废
sb.Append("<td width='50'>" + bad_count + "</td>");//不良总数
sb.Append("<td width='50'></td>");//前十模 + 不良总数量之和
decimal ok_num = 0;
if ((product_count + bad_count) == 0)
{
sb.Append("<td width='50'>0%</td>");//合格率(总合格数/(总合格数+不良数))
sb.Append("<td width='50'>0%</td>");//不良率
}
else
{
ok_num = Math.Round((product_count + market_count / (product_count + market_count + bad_count)) * 100, 2);
sb.Append("<td width='50'>" + ok_num + "%</td>");//合格率(总合格数/(总合格数+不良数))
sb.Append("<td width='50'>" + (100 - ok_num) + "%</td>");//不良率
}
var listR = list3.Where(p => p.DownTypeName != null && p.PlanID.Equals(dt.Rows[i]["PlanID"])).ToList();
long x = listR.Where(p => p.DownTypeName.Contains("计划停机")).Sum(p => p.DownTime);
long x1 = listR.Where(p => p.DownTypeName.Contains("换模时间")).Sum(p => p.DownTime);
//TODO 要合并单元格
//sb.Append("<td width='50'>" + listR.Where(p => p.DownTypeName.Contains("非计划停机")).Sum(p => p.DownTime) + "</td>");
//sb.Append("<td width='50'>" + listR.Where(p => p.DownTypeName.Contains("计划停机")).Sum(p => p.DownTime) + "</td>");
//sb.Append("<td width='50'>" + Math.Round((plan_count * real_Cycle) / 60, 2) + "</td>");//产出工时(计划数量*实际周期/60)
var stopTime = (listR.Where(p => p.DownTypeName.Contains("非计划停机")).Sum(p => p.DownTime) + listR.Where(p => p.DownTypeName.Contains("计划停机")).Sum(p => p.DownTime));
decimal pTime = (24 * 60 - stopTime);
sb.Append("<td width='50'>" + pTime + "</td>");//生产时间
sb.Append("<td width='50'>" + stopTime + "</td>");//停机时间
sb.Append("<td width='50' >" + Math.Round((pTime / 1440) * 100, 2) + "</td>");//机台利用率
sb.Append("<td width='50' >" + (pTime / 1440) * ok_num + "</td>");//OEE
sb.Append("<td width='50' >原料物料号</td>");
sb.Append("<td width='50' >原料名称</td>");
decimal OneWeight = dt.Rows[i]["OneWeight"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["OneWeight"]);
decimal Weight = dt.Rows[i]["Weight"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["Weight"]);
sb.Append("<td width='50' >" + OneWeight + "</td>");//单品净重
sb.Append("<td width='50' >" + Weight + "</td>");//塑件毛重
sb.Append("<td width='50' >" + (Weight - OneWeight) + "</td>");//料棒重量
sb.Append("<td width='50' >" + (Weight * (product_count + market_count + bad_count)) + "</td>");//物料使用 还要减去机头料
sb.Append("<td width='50' >机头料(kg)</td>");//机头料(kg)
sb.Append("<td width='50' >" + (Weight - OneWeight) * (product_count + market_count + bad_count) + "</td>");//料棒/浇口(kg)
sb.Append("<td width='50' >" + (OneWeight * bad_count) + "</td>");//不良品(kg)
sb.Append("<td width='50' >奔驰前十模使用原料</td>");//奔驰前十模使用原料
sb.Append("<td width='50' >回料(kg)</td>");//回料(kg)
//sb.Append("<td width='50'>" + dt.Rows[i]["BeginTime"] + "</td>");//开机时间
//sb.Append("<td width='50'>" + dt.Rows[i]["EndTime"] + "</td>");//关机时间
//sb.Append("<td width='50'>" + dt.Rows[i]["ProductName"] + "</td>");//产品名称
//sb.Append("<td width='50'>" + dt.Rows[i]["OpenDebugTime"] + "</td>");//标准开机时间
//sb.Append("<td width='50'>" + real_Cycle + "</td>");//实际周期
//sb.Append("<td width='50'>" + dt.Rows[i]["PlanCount"] + "</td>");//计划数量
//sb.Append("<td width='50'>" + (product_count + bad_count + list.Where(p => "开机报废;".Equals(p.BadReason)).Count()) + "</td>");//总合格数量
//sb.Append("<td width='50'>" + dt.Rows[i]["BadCount"] + "</td>");//不良数量
//for (int k = 0; k < defectInfo.Count; k++)
//{
// sb.Append("<td width='50'>" + list.Where(p => p.BadReason.Equals(defectInfo[k] + ";")).Count() + "</td>");
//}
//sb.Append("<td width='50'>" + dt.Rows[i]["Weight"] + "</td>");//产品毛重(总合格数量+不良数量)*产品毛重
//sb.Append("<td width='50'>" + dt.Rows[i]["Waste_Weight"] + "</td>");//废料块
//sb.Append("<td width='50'>" + dt.Rows[i]["JK_Weight"] + "</td>");//浇口重量
//sb.Append("<td width='50'>" + (product_count + bad_count) * weight + "</td>");//产品耗用原料
//if (plan_count == 0)
//{
// sb.Append("<td width='50'>0%</td>");//完成率
//}
//else
//{
// sb.Append("<td width='50'>" + Math.Round((product_count / plan_count) * 100, 2) + "%</td>");//完成率(总合格数/计划数)
//}
//sb.Append("<td width='50'>" + Math.Round((plan_count * cycle_Time) / 60, 2) + "</td>");//计划工时(计划数量*标准周期/60)
//sb.Append("<td width='50'>" + (x + x1) + "</td>");//计划停机+换模时间
//sb.Append("<td width='50'>" + listR.Where(p => p.DownTypeName.Contains("非计划停机")).Sum(p => p.DownTime) + "</td>");
//sb.Append("<td width='50'>" + listR.Where(p => p.DownTypeName.Contains("换模")).Sum(p => p.DownTime) + "</td>");
//sb.Append("<td width='50'>" + listR.Where(p => p.DownTypeName.Contains("交班")).Sum(p => p.DownTime) + "</td>");
//sb.Append("<td width='50'>" + listR.Where(p => p.DownTypeName.Contains("接班")).Sum(p => p.DownTime) + "</td>");
//sb.Append("<td width='50'>" + listR.Where(p => p.DownTypeName.Contains("计划停机")).Sum(p => p.DownTime) + "</td>");
//for (int k = 0; k < DownReasonList.Count; k++)
//{
// sb.Append("<td width='50'>" + list3.Where(p => p.Reason != null && p.PlanID.Equals(dt.Rows[i]["PlanID"]) && p.Reason.Contains(DownReasonList[k])).Sum(p => p.DownTime) + "</td>");
//}
sb.Append("</tr>");
}
}
}
catch (Exception ex)
{
throw;
}
sb.Append("</table>");
return sb.ToString();
}
private string CheckWorkClass(string StartTime)
{
try
{
if (true)
{
string time = StartTime.Substring(0, StartTime.IndexOf(" "));
if (DateTime.Compare(Convert.ToDateTime(StartTime), Convert.ToDateTime(time + " 08:00:00")) > 0 && DateTime.Compare(Convert.ToDateTime(time + " 19:59:59"), Convert.ToDateTime(StartTime)) > 0)
{
return "A";
}
return "B";
}
}
catch (Exception ex)
{
}
return "";
}
public List<List<string>> SearchProductInjectionRecordForExcel(string StartTime, string EndTime)
{
List<List<string>> listExcel = new List<List<string>>();
var defectList = ef.tb_Defect.ToList();
var defectInfo = defectList.Where(p => p.LineID.Equals(defectList.FirstOrDefault().LineID)).OrderBy(p => p.DefectName).Select(p => p.DefectName).ToList();
var DownReasonList = ef.tb_Inhection_DownReason.OrderBy(p => p.Reason).Select(p => p.Reason).ToList();
DataTable dt = dal.SearchProductInjectionRecord(Convert.ToDateTime(StartTime).ToString("yyyy-MM-dd"), Convert.ToDateTime(EndTime).ToString("yyyy-MM-dd"));
DataTable dt2 = dal.SearchProductInjectionRecordBadReason(Convert.ToDateTime(StartTime).ToString("yyyy-MM-dd"), Convert.ToDateTime(EndTime).ToString("yyyy-MM-dd"));
List<InjectionBadReasonModel> list = Tool.ConvertTo<InjectionBadReasonModel>(dt2).ToList();
DataTable dt3 = dal.SearchProductInjectionRecordDownReason(Convert.ToDateTime(StartTime).ToString("yyyy-MM-dd"), Convert.ToDateTime(EndTime).ToString("yyyy-MM-dd"));
List<InjectionRecordDownReasonModel> list3 = Tool.ConvertTo<InjectionRecordDownReasonModel>(dt3).ToList();
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("");
titleList.Add("");
titleList.Add("");
titleList.Add("");
titleList.Add("");
titleList.Add("");
titleList.Add("");
foreach (var item in defectInfo)
{
titleList.Add("不良原因");
}
titleList.Add("");
titleList.Add("");
titleList.Add("");
titleList.Add("");
titleList.Add("");
titleList.Add("");
titleList.Add("");
titleList.Add("");
titleList.Add("停机时间");
titleList.Add("停机时间");
titleList.Add("换膜");
titleList.Add("换膜");
titleList.Add("换膜");
titleList.Add("");
foreach (var item in DownReasonList)
{
titleList.Add("停机原因");
}
listExcel.Add(titleList);
List<string> titleList2 = new List<string>();
titleList2.Add("日期");
titleList2.Add("班次");
titleList2.Add("注塑机台");
titleList2.Add("开机时间");
titleList2.Add("关机时间");
titleList2.Add("产品性质");
titleList2.Add("产品名称");
titleList2.Add("原料名称");
titleList2.Add("原料批次号");
titleList2.Add("标准开机时间");
titleList2.Add("标准周期");
titleList2.Add("实际周期");
titleList2.Add("计划数量");
titleList2.Add("合格数量");
titleList2.Add("总合格数量");
titleList2.Add("不良数量");
foreach (var item in defectInfo)
{
titleList2.Add(item);
}
titleList2.Add("产品毛重");
titleList2.Add("废料块");
titleList2.Add("浇口重量");
titleList2.Add("产品耗用原料");
titleList2.Add("合格率");
titleList2.Add("完成率");
titleList2.Add("计划工时");
titleList2.Add("产出工时");
titleList2.Add("计划停机+换模时间");
titleList2.Add("非计划停机");
titleList2.Add("换膜");
titleList2.Add("交班");
titleList2.Add("接班");
titleList2.Add("计划停机");
foreach (var item in DownReasonList)
{
titleList2.Add(item);
}
listExcel.Add(titleList2);
if (dt != null && dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
List<string> conList = new List<string>();
conList.Add(dt.Rows[i]["ProductDate"].ToString());
conList.Add(dt.Rows[i]["ClassName"].ToString());
conList.Add(dt.Rows[i]["StationNo"].ToString());
conList.Add(dt.Rows[i]["BeginTime"].ToString());
conList.Add(dt.Rows[i]["EndTime"].ToString());
conList.Add("正常");
conList.Add(dt.Rows[i]["ProductName"].ToString());
conList.Add(dt.Rows[i]["MaterialName"].ToString());
conList.Add(dt.Rows[i]["BatchNo"].ToString());
conList.Add(dt.Rows[i]["OpenDebugTime"].ToString());
decimal cycle_Time = dt.Rows[i]["CycleTime"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["CycleTime"]);
conList.Add(cycle_Time.ToString());
decimal real_Cycle = dt.Rows[i]["RealCycle"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["RealCycle"]);
decimal product_count = dt.Rows[i]["ProductCount"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["ProductCount"]);
decimal bad_count = dt.Rows[i]["BadCount"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["BadCount"]);
decimal weight = dt.Rows[i]["Weight"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["Weight"]);
decimal plan_count = dt.Rows[i]["PlanCount"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["PlanCount"]);
decimal openFailCount = 0;
conList.Add(real_Cycle.ToString());
conList.Add(dt.Rows[i]["PlanCount"].ToString());
conList.Add(product_count.ToString());
conList.Add((product_count + bad_count + defectInfo.Where(p => "开机报废".Equals(p)).Count()).ToString());
conList.Add(dt.Rows[i]["BadCount"].ToString());
for (int k = 0; k < defectInfo.Count; k++)
{
conList.Add(list.Where(p => p.BadReason.Equals(defectInfo[k] + ";")).Count().ToString());
}
conList.Add(dt.Rows[i]["Weight"].ToString());
conList.Add(dt.Rows[i]["Waste_Weight"].ToString());
conList.Add(dt.Rows[i]["JK_Weight"].ToString());
conList.Add(((product_count + bad_count) * weight).ToString());
if ((product_count + bad_count) == 0)
{
conList.Add("0%");
}
else
{
conList.Add((Math.Round((product_count / (product_count + bad_count)) * 100, 2)).ToString());
}
if (plan_count == 0)
{
conList.Add("0%");
}
else
{
conList.Add((Math.Round((product_count / plan_count) * 100, 2)).ToString());
}
conList.Add((Math.Round((plan_count * cycle_Time) / 60, 2)).ToString());
conList.Add((Math.Round((plan_count * real_Cycle) / 60, 2)).ToString());
var listR = list3.Where(p => p.DownTypeName != null && p.PlanID.Equals(dt.Rows[i]["PlanID"])).ToList();
long x = listR.Where(p => p.DownTypeName.Contains("计划停机")).Sum(p => p.DownTime);
long x1 = listR.Where(p => p.DownTypeName.Contains("换模时间")).Sum(p => p.DownTime);
conList.Add((x + x1).ToString());
conList.Add((listR.Where(p => p.DownTypeName.Contains("非计划停机")).Sum(p => p.DownTime)).ToString());
conList.Add((listR.Where(p => p.DownTypeName.Contains("换模")).Sum(p => p.DownTime)).ToString());
conList.Add((listR.Where(p => p.DownTypeName.Contains("交班")).Sum(p => p.DownTime)).ToString());
conList.Add((listR.Where(p => p.DownTypeName.Contains("接班")).Sum(p => p.DownTime)).ToString());
conList.Add((listR.Where(p => p.DownTypeName.Contains("计划停机")).Sum(p => p.DownTime)).ToString());
for (int k = 0; k < DownReasonList.Count; k++)
{
conList.Add((list3.Where(p => p.Reason != null && p.PlanID.Equals(dt.Rows[i]["PlanID"]) && p.Reason.Contains(DownReasonList[k])).Sum(p => p.DownTime)).ToString());
}
listExcel.Add(conList);
}
}
return listExcel;
}
#endregion
}
}