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

1406 lines
67 KiB

using MESClassLibrary.BLL.Log;
using MESClassLibrary.DAL.Check;
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.Check
{
public class InspectResultBLL
{
InspectResultDAL dal = new InspectResultDAL();
BBMPTEntities ef = new BBMPTEntities();
BasicBLL<tb_InspectResult> db = new BasicBLL<tb_InspectResult>();
/// <summary>
/// 查询信息
/// </summary>
/// <returns></returns>
public string SearchInfo(string page, string pagesize, string StartTime, string EndTime, string position, string inspectResult,string barCode)
{
try
{
string jsonStr = "[]";
int total = dal.SearchCount(StartTime, EndTime, position, inspectResult);//总行数
DataTable dt = dal.SearchByPage(Convert.ToInt32(page), Convert.ToInt32(pagesize), StartTime, EndTime, position, inspectResult, barCode);
if (dt != null && dt.Rows.Count > 0)
{
var list = Tool.ConvertTo<tb_InspectResult>(dt);
List<InspectResultGroup> groupList = new List<InspectResultGroup>();
List<string> barcodeList = list.GroupBy(p => p.barcode).Select(p => p.Key).ToList();
foreach (var item in barcodeList)
{
var info = list.Where(p => p.barcode.Equals(item)).OrderBy(p => p.InspectTimes).ToList();
if (info.Count > 0)
{
InspectResultGroup md = new InspectResultGroup();
if (info.Count >= 3)
{
md.barcode = info[0].barcode;
md.side = info[0].side;
md.position = info[0].position;
md.stationNo = info[0].stationNo;
md.workClass = info[0].workClass;
md.productInfo = info[0].productInfo;
md.productOption = info[0].productOption;
md.inspectResult_1 = info[0].inspectResult;
md.damnPosition_1 = info[0].damnPosition;
md.reason_1 = info[0].reason;
md.createTime_1 = Convert.ToDateTime(info[0].createTime.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
md.inspectResult_2 = info[1].inspectResult;
md.damnPosition_2 = info[1].damnPosition;
md.reason_2 = info[1].reason;
md.createTime_2 = Convert.ToDateTime(info[1].createTime.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
md.inspectResult_3 = info[2].inspectResult;
md.damnPosition_3 = info[2].damnPosition;
md.reason_3 = info[2].reason;
md.createTime_3 = Convert.ToDateTime(info[2].createTime.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
groupList.Add(md);
}
if (info.Count == 2)
{
md.barcode = info[0].barcode;
md.side = info[0].side;
md.position = info[0].position;
md.stationNo = info[0].stationNo;
md.workClass = info[0].workClass;
md.productInfo = info[0].productInfo;
md.productOption = info[0].productOption;
md.inspectResult_1 = info[0].inspectResult;
md.damnPosition_1 = info[0].damnPosition;
md.reason_1 = info[0].reason;
md.createTime_1 = Convert.ToDateTime(info[0].createTime.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
md.inspectResult_2 = info[1].inspectResult;
md.damnPosition_2 = info[1].damnPosition;
md.reason_2 = info[1].reason;
md.createTime_2 = Convert.ToDateTime(info[1].createTime.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
groupList.Add(md);
}
if (info.Count == 1)
{
md.barcode = info[0].barcode;
md.side = info[0].side;
md.position = info[0].position;
md.stationNo = info[0].stationNo;
md.workClass = info[0].workClass;
md.productInfo = info[0].productInfo;
md.productOption = info[0].productOption;
md.inspectResult_1 = info[0].inspectResult;
md.damnPosition_1 = info[0].damnPosition;
md.reason_1 = info[0].reason;
md.createTime_1 = Convert.ToDateTime(info[0].createTime.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
groupList.Add(md);
}
}
}
if (groupList.Count > 0)
{
JsonDataModel<InspectResultGroup> md = new JsonDataModel<InspectResultGroup>();
md.total = total.ToString();
md.rows = groupList;
jsonStr = JSONTools.ScriptSerialize(md);
}
}
return jsonStr;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return "";
}
}
/// <summary>
/// 点修补记录
/// </summary>
/// <param name="page"></param>
/// <param name="pagesize"></param>
/// <param name="StartTime"></param>
/// <param name="EndTime"></param>
/// <param name="inspectResult"></param>
/// <returns></returns>
public string SearchInfoByRepair(string page, string pagesize, string StartTime, string EndTime,
string inspectResult)
{
try
{
string jsonStr = "[]";
int total = dal.SearchCountByRepair(StartTime, EndTime, inspectResult);//总行数
DataTable dt = dal.SearchRepairByPage(Convert.ToInt32(page), Convert.ToInt32(pagesize), StartTime, EndTime, inspectResult);
if (dt != null && dt.Rows.Count > 0)
{
var list = Tool.ConvertTo<tb_InspectResult>(dt);
List<tb_InspectResult> groupList = new List<tb_InspectResult>();
if (list.Count > 0)
{
for (int i = 0; i < list.Count; i++)
{
tb_InspectResult md = new tb_InspectResult();
md.barcode = list[i].barcode;
md.side = list[i].side;
md.position = list[i].position;
md.stationNo = list[i].stationNo;
md.workClass = list[i].workClass;
md.productInfo = list[i].productInfo;
md.productOption = list[i].productOption;
md.inspectResult = list[i].inspectResult;
md.damnPosition = list[i].damnPosition;
md.reason = list[i].reason;
if (list[i].createTime != null)
{
md.createTime = Convert.ToDateTime(list[i].createTime.ToString());
}
groupList.Add(md);
}
}
if (groupList.Count > 0)
{
JsonDataModel<tb_InspectResult> md = new JsonDataModel<tb_InspectResult>();
md.total = total.ToString();
md.rows = groupList;
jsonStr = JSONTools.ScriptSerialize(md);
}
}
return jsonStr;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return "";
}
}
public List<List<string>> SearchInfoByRepairForExcel(string StartTime, string EndTime, string inspectResult)
{
try
{
List<List<string>> list_excel = new List<List<string>>();
List<string> title_list = new List<string>();
title_list.Add("条码");
title_list.Add("A/B侧");
title_list.Add("位置");
//title_list.Add("机台");
title_list.Add("班次");
title_list.Add("产品信息");
title_list.Add("生产模式");
title_list.Add("结果");
title_list.Add("缺陷位置");
title_list.Add("原因");
title_list.Add("时间");
list_excel.Add(title_list);
DataTable dt = dal.SearchByRepair(StartTime, EndTime, inspectResult);
if (dt != null && dt.Rows.Count > 0)
{
var list = Tool.ConvertTo<tb_InspectResult>(dt);
List<tb_InspectResult> groupList = new List<tb_InspectResult>();
if (list.Count > 0)
{
for (int i = 0; i < list.Count; i++)
{
List<string> row_list = new List<string>();
row_list.Add(list[i].barcode);
row_list.Add(list[i].side);
row_list.Add(list[i].position);
//row_list.Add(list[i].stationNo);
row_list.Add(list[i].workClass);
row_list.Add(list[i].productInfo);
row_list.Add(list[i].productOption);
row_list.Add(list[i].inspectResult);
row_list.Add(list[i].damnPosition);
row_list.Add(list[i].reason);
row_list.Add(list[i].createTime.ToString());
list_excel.Add(row_list);
}
}
}
return list_excel;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 查询信息
/// </summary>
/// <returns></returns>
public List<InspectResultGroup> SearchInfoAll(string StartTime, string EndTime, string position, string inspectResult,string barCode)
{
try
{
List<InspectResultGroup> groupList = new List<InspectResultGroup>();
DataTable dt = dal.Search(StartTime, EndTime, position, inspectResult,barCode);
if (dt != null && dt.Rows.Count > 0)
{
IEnumerable<IGrouping<string, DataRow>> result = dt.Rows.Cast<DataRow>().GroupBy<DataRow, string>(dr => dr["barcode"].ToString());//按A分组
foreach (IGrouping<string, DataRow> info in result)
{
if (info.Count() > 0)
{
InspectResultGroup md = new InspectResultGroup();
if (info.Count() >= 3)
{
md.barcode = info.ToArray()[0]["barcode"].ToString();
md.side = info.ToArray()[0]["side"].ToString();
md.position = info.ToArray()[0]["position"].ToString();
md.stationNo = info.ToArray()[0]["stationNo"].ToString();
md.workClass = info.ToArray()[0]["workClass"].ToString();
md.productInfo = info.ToArray()[0]["productInfo"].ToString();
md.productOption = info.ToArray()[0]["productOption"].ToString();
md.inspectResult_1 = info.ToArray()[0]["inspectResult"].ToString();
md.damnPosition_1 = info.ToArray()[0]["damnPosition"].ToString();
md.reason_1 = info.ToArray()[0]["reason"].ToString();
md.createTime_1 = Convert.ToDateTime(info.ToArray()[0]["createTime"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
md.inspectResult_2 = info.ToArray()[1]["inspectResult"].ToString();
md.damnPosition_2 = info.ToArray()[1]["damnPosition"].ToString();
md.reason_2 = info.ToArray()[1]["reason"].ToString();
md.createTime_2 = Convert.ToDateTime(info.ToArray()[1]["createTime"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
md.inspectResult_3 = info.ToArray()[2]["inspectResult"].ToString();
md.damnPosition_3 = info.ToArray()[2]["damnPosition"].ToString();
md.reason_3 = info.ToArray()[2]["reason"].ToString();
md.createTime_3 = Convert.ToDateTime(info.ToArray()[2]["createTime"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
groupList.Add(md);
}
if (info.Count() == 2)
{
md.barcode = info.ToArray()[0]["barcode"].ToString();
md.side = info.ToArray()[0]["side"].ToString();
md.position = info.ToArray()[0]["position"].ToString();
md.stationNo = info.ToArray()[0]["stationNo"].ToString();
md.workClass = info.ToArray()[0]["workClass"].ToString();
md.productInfo = info.ToArray()[0]["productInfo"].ToString();
md.productOption = info.ToArray()[0]["productOption"].ToString();
md.inspectResult_1 = info.ToArray()[0]["inspectResult"].ToString();
md.damnPosition_1 = info.ToArray()[0]["damnPosition"].ToString();
md.reason_1 = info.ToArray()[0]["reason"].ToString();
md.createTime_1 = Convert.ToDateTime(info.ToArray()[0]["createTime"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
md.inspectResult_2 = info.ToArray()[1]["inspectResult"].ToString();
md.damnPosition_2 = info.ToArray()[1]["damnPosition"].ToString();
md.reason_2 = info.ToArray()[1]["reason"].ToString();
md.createTime_2 = Convert.ToDateTime(info.ToArray()[1]["createTime"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
groupList.Add(md);
}
if (info.Count() == 1)
{
md.barcode = info.ToArray()[0]["barcode"].ToString();
md.side = info.ToArray()[0]["side"].ToString();
md.position = info.ToArray()[0]["position"].ToString();
md.stationNo = info.ToArray()[0]["stationNo"].ToString();
md.workClass = info.ToArray()[0]["workClass"].ToString();
md.productInfo = info.ToArray()[0]["productInfo"].ToString();
md.productOption = info.ToArray()[0]["productOption"].ToString();
md.inspectResult_1 = info.ToArray()[0]["inspectResult"].ToString();
md.damnPosition_1 = info.ToArray()[0]["damnPosition"].ToString();
md.reason_1 = info.ToArray()[0]["reason"].ToString();
md.createTime_1 = Convert.ToDateTime(info.ToArray()[0]["createTime"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
groupList.Add(md);
}
}
}
//var list = Tool.ConvertTo<tb_InspectResult>(dt);
//List<string> barcodeList = list.GroupBy(p => p.barcode).Select(p => p.Key).ToList();
//foreach (var item in barcodeList)
//{
// var info = list.Where(p => p.barcode.Equals(item)).OrderBy(p => p.InspectTimes).ToList();
// if (info.Count > 0)
// {
// InspectResultGroup md = new InspectResultGroup();
// if (info.Count >= 3)
// {
// md.barcode = info[0].barcode;
// md.side = info[0].side;
// md.position = info[0].position;
// md.stationNo = info[0].stationNo;
// md.workClass = info[0].workClass;
// md.productInfo = info[0].productInfo;
// md.productOption = info[0].productOption;
// md.inspectResult_1 = info[0].inspectResult;
// md.damnPosition_1 = info[0].damnPosition;
// md.reason_1 = info[0].reason;
// md.createTime_1 = Convert.ToDateTime(info[0].createTime.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
// md.inspectResult_2 = info[1].inspectResult;
// md.damnPosition_2 = info[1].damnPosition;
// md.reason_2 = info[1].reason;
// md.createTime_2 = Convert.ToDateTime(info[1].createTime.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
// md.inspectResult_3 = info[2].inspectResult;
// md.damnPosition_3 = info[2].damnPosition;
// md.reason_3 = info[2].reason;
// md.createTime_3 = Convert.ToDateTime(info[2].createTime.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
// groupList.Add(md);
// }
// if (info.Count == 2)
// {
// md.barcode = info[0].barcode;
// md.side = info[0].side;
// md.position = info[0].position;
// md.stationNo = info[0].stationNo;
// md.workClass = info[0].workClass;
// md.productInfo = info[0].productInfo;
// md.productOption = info[0].productOption;
// md.inspectResult_1 = info[0].inspectResult;
// md.damnPosition_1 = info[0].damnPosition;
// md.reason_1 = info[0].reason;
// md.createTime_1 = Convert.ToDateTime(info[0].createTime.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
// md.inspectResult_2 = info[1].inspectResult;
// md.damnPosition_2 = info[1].damnPosition;
// md.reason_2 = info[1].reason;
// md.createTime_2 = Convert.ToDateTime(info[1].createTime.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
// groupList.Add(md);
// }
// if (info.Count == 1)
// {
// md.barcode = info[0].barcode;
// md.side = info[0].side;
// md.position = info[0].position;
// md.stationNo = info[0].stationNo;
// md.workClass = info[0].workClass;
// md.productInfo = info[0].productInfo;
// md.productOption = info[0].productOption;
// md.inspectResult_1 = info[0].inspectResult;
// md.damnPosition_1 = info[0].damnPosition;
// md.reason_1 = info[0].reason;
// md.createTime_1 = Convert.ToDateTime(info[0].createTime.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
// groupList.Add(md);
// }
// }
//}
}
return groupList;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
//public List<tb_InspectResult> SearchInfoAllByRepair(string StartTime, string EndTime, string inspectResult)
//{
// try
// {
// List<tb_InspectResult> groupList = new List<tb_InspectResult>();
// DataTable dt = dal.SearchByRepair(StartTime, EndTime, inspectResult);
// if (dt != null && dt.Rows.Count > 0)
// {
// IEnumerable<IGrouping<string, DataRow>> result = dt.Rows.Cast<DataRow>().GroupBy<DataRow, string>(dr => dr["barcode"].ToString());
// foreach (IGrouping<string, DataRow> info in result)
// {
// if (info.Count() > 0)
// {
// }
// }
// }
// }
// catch (Exception ex)
// {
// LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
// return null;
// }
//}
#region 合格率趋势统计
public string SearchQualifiedTrend(string StartTime, string EndTime, string side, string product)
{
try
{
StringBuilder sb = new StringBuilder(100);
sb.Append("<table border='1' width='1000'>");
sb.Append("<tr>");
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>");
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>");
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>");
sb.Append("</tr>");
//DataTable dt = dal.SearchByPosition(StartTime + " 08:00:00.000", Convert.ToDateTime(EndTime + " 07:59:59.999").AddDays(1).ToString("yyyy-MM-dd HH:mm:ss.fff"), side, product);
DataTable dt = dal.SearchByPosition(StartTime + ".000", Convert.ToDateTime(EndTime + ".999").AddDays(1).ToString("yyyy-MM-dd HH:mm:ss.fff"), side, product);
if (dt != null && dt.Rows.Count > 0)
{
List<int> numList = new List<int>();
for (int i = 0; i < 13; i++)
{
numList.Add(0);
}
TimeSpan ts1 = new TimeSpan(Convert.ToDateTime(StartTime).Ticks);
TimeSpan ts2 = new TimeSpan(Convert.ToDateTime(EndTime).Ticks);
TimeSpan ts3 = ts2.Subtract(ts1); //ts
for (int i = 0; i < ts3.Days + 1; i++)
{
DateTime dtime = Convert.ToDateTime(StartTime).AddDays(i);
string strTime = dtime.ToString("M/d");
//白班
var DayList = from myRow in dt.AsEnumerable()
where myRow.Field<DateTime>(12) >= Convert.ToDateTime(dtime.ToString("yyyy-MM-dd") + " 08:00:00.000") &&
myRow.Field<DateTime>(12) <= Convert.ToDateTime(dtime.ToString("yyyy-MM-dd") + " 19:59:59.999")
select myRow;
sb.Append("<tr>");
sb.Append("<td width='50'rowspan='2'>" + strTime + "</td>");
sb.Append("<td width='50'>白班</td>");
QualifiedTrendBuilindData(DayList, ref sb, numList);
var NightList = from myRowNight in dt.AsEnumerable()
where myRowNight.Field<DateTime>(12) >= Convert.ToDateTime(dtime.ToString("yyyy-MM-dd") + " 20:00:00.000") &&
myRowNight.Field<DateTime>(12) <= Convert.ToDateTime(dtime.AddDays(1).ToString("yyyy-MM-dd") + " 07:59:59.999")
select myRowNight;
sb.Append("<tr>");
sb.Append("<td width='50'>夜班</td>");
QualifiedTrendBuilindData(NightList, ref sb, numList);
}
sb.Append("<tr>");
sb.Append("<td width='50'>合计</td>");
sb.Append("<td width='50'></td>");
sb.Append("<td width='50'>" + numList[0] + "</td>");
sb.Append("<td width='50'>" + numList[1] + "</td>");
sb.Append("<td width='50'>" + numList[2] + "</td>");
sb.Append("<td width='50'>" + numList[3] + "</td>");
sb.Append("<td width='50'>" + numList[4] + "</td>");
sb.Append("<td width='50'>0</td>");
sb.Append("<td width='50'>" + numList[6] + "</td>");
sb.Append("<td width='50'>" + numList[7] + "</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'>" + numList[12] + "</td>");
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public List<List<string>> SearchQualifiedTrendForExcel(string StartTime, string EndTime, string side, string product)
{
try
{
List<List<string>> list = new List<List<string>>();
List<string> sonList = new List<string>();
sonList.Add("日期");
sonList.Add("班别");
sonList.Add("下线数");
sonList.Add("系统抛光数");
sonList.Add("一次合格数");
sonList.Add("抛光合格数");
sonList.Add("合格数");
sonList.Add("返修合格数");
sonList.Add("报废数");
sonList.Add("点修补数");
sonList.Add("一次合格率");
sonList.Add("抛光合格率");
sonList.Add("总合格率");
sonList.Add("报废率");
sonList.Add("抛光结余");
list.Add(sonList);
//DataTable dt = dal.SearchByPosition(StartTime + " 00:00:00.000", EndTime + " 23:59:59.000", side, product);
DataTable dt = dal.SearchByPosition(StartTime + ".000", EndTime + ".000", side, product);
if (dt != null && dt.Rows.Count > 0)
{
List<int> numList = new List<int>();
for (int i = 0; i < 13; i++)
{
numList.Add(0);
}
TimeSpan ts1 = new TimeSpan(Convert.ToDateTime(StartTime).Ticks);
TimeSpan ts2 = new TimeSpan(Convert.ToDateTime(EndTime).Ticks);
TimeSpan ts3 = ts2.Subtract(ts1); //ts
for (int i = 0; i < ts3.Days + 1; i++)
{
DateTime dtime = Convert.ToDateTime(StartTime).AddDays(i);
string strTime = dtime.ToString("M/d");
//白班
var DayList = from myRow in dt.AsEnumerable()
where myRow.Field<DateTime>(12) >= Convert.ToDateTime(dtime.ToString("yyyy-MM-dd") + " 08:00:00.000") &&
myRow.Field<DateTime>(12) <= Convert.ToDateTime(dtime.ToString("yyyy-MM-dd") + " 19:59:59.999")
select myRow;
List<string> sonDay = new List<string>();
sonDay.Add(strTime);
sonDay.Add("白班");
QualifiedTrendBuilindData(DayList, ref sonDay, numList);
list.Add(sonDay);
var NightList = from myRow in dt.AsEnumerable()
where myRow.Field<DateTime>(12) >= Convert.ToDateTime(dtime.ToString("yyyy-MM-dd") + " 20:00:00.000") &&
myRow.Field<DateTime>(12) <= Convert.ToDateTime(dtime.AddDays(1).ToString("yyyy-MM-dd") + " 07:59:59.999")
select myRow;
List<string> sonNight = new List<string>();
sonNight.Add(strTime);
sonNight.Add("夜班");
QualifiedTrendBuilindData(NightList, ref sonNight, numList);
list.Add(sonNight);
}
List<string> sonCount = new List<string>();
sonCount.Add("合计");
sonCount.Add("");
sonCount.Add(numList[0].ToString());
sonCount.Add(numList[1].ToString());
sonCount.Add(numList[2].ToString());
sonCount.Add(numList[3].ToString());
sonCount.Add(numList[4].ToString());
sonCount.Add(numList[5].ToString());
sonCount.Add(numList[6].ToString());
sonCount.Add(numList[7].ToString());
sonCount.Add("");
sonCount.Add("");
sonCount.Add("");
sonCount.Add("");
sonCount.Add(numList[12].ToString());
list.Add(sonCount);
}
return list;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
private void QualifiedTrendBuilindData(EnumerableRowCollection<DataRow> DayList, ref StringBuilder sb, List<int> numList)
{
//下线数
int XX_num = DayList.Where(p => "1".Equals(p.ItemArray[13])).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).Count();
//抛光数
//int PG_num = DayList.Where(p => p.ItemArray[6] != null && p.ItemArray[6].ToString().Contains("抛光") && "1".Equals(p.ItemArray[13])).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).Count();
var pg_1 = DayList.Where(p => p.ItemArray[6] != null && p.ItemArray[6].ToString().Contains("抛光") && "1".Equals(p.ItemArray[13])).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).ToList();
var pg_2 = DayList.Where(p => p.ItemArray[6] != null && "2".Equals(p.ItemArray[13])).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).ToList();
IEnumerable<object> pg_List = pg_1.Intersect(pg_2);
int PG_num = pg_List.Count();
//一次合格数
int YCHG_num = DayList.Where(p => p.ItemArray[6] != null && p.ItemArray[6].ToString().Contains("合格") && "1".Equals(p.ItemArray[13])).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).Count();
//抛光合格
var pghg_1 = DayList.Where(p => p.ItemArray[6] != null && p.ItemArray[6].ToString().Contains("抛光") && "1".Equals(p.ItemArray[13])).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).ToList();
var pghg_2 = DayList.Where(p => p.ItemArray[6] != null && p.ItemArray[6].ToString().Contains("合格") && "2".Equals(p.ItemArray[13])).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).ToList();
IEnumerable<object> pghg_List = pghg_1.Intersect(pghg_2);
int pghg = pghg_List.Count();
//var pghg = DayList.Where(t => t.ItemArray[3].ToString() == "下线二检 抛光区")
// .GroupBy(p => p.ItemArray[1])
// .Select(s => s.OrderByDescending(x => x.ItemArray[12]).FirstOrDefault())
// .Where(p => p.ItemArray[6].ToString().Contains("合格")).Count();
//返修合格数
var fx = DayList.Where(t => t.ItemArray[6] != null && t.ItemArray[3].ToString().Contains("点修补") && t.ItemArray[6].ToString().Contains("合格")).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).Count();
//合格数
var hg = YCHG_num + pghg + fx;
//var hg = DayList.GroupBy(p => p.ItemArray[1])
// .Select(s => s.OrderByDescending(x => x.ItemArray[12]).FirstOrDefault())
// .Where(p => p.ItemArray[6].ToString().Contains("合格")).Count();
//报废数
//var bf = DayList.GroupBy(p => p.ItemArray[1])
// .Select(s => s.OrderByDescending(x => x.ItemArray[12]).FirstOrDefault())
// .Where(p => p.ItemArray[6].ToString().Contains("报废")).Count();
var bf = DayList.Where(t => t.ItemArray[6] != null && t.ItemArray[6].ToString().Contains("报废")).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).Count();
var YC_bf = DayList.Where(t => t.ItemArray[6] != null && t.ItemArray[6].ToString().Contains("报废") && "1".Equals(t.ItemArray[13])).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).Count();
//点修补数
//var dxb = DayList.Where(t => t.ItemArray[3].ToString() == "点修补 抛光区").GroupBy(p => p.ItemArray[1]).Select(p => p.Key).Count();
var dxb = DayList.Where(p => p.ItemArray[6] != null && p.ItemArray[6].ToString().Contains("抛光") && "2".Equals(p.ItemArray[13])).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).Count();
//一次合格率
var yc_hg_L = Math.Round(((double)YCHG_num / (double)XX_num) * 100, 2);
//抛光合格率
var pg_hg_L = Math.Round(((double)pghg / (double)PG_num) * 100, 2);
//总合格率
var all_hg_L = Math.Round(((double)hg / (double)XX_num) * 100, 2);
//报废率
var pf_L = Math.Round(((double)bf / (double)XX_num) * 100, 2);
//抛光结余
//var pgjy = XX_num - hg - bf - dxb;
var pgjy = XX_num - YCHG_num - YC_bf - PG_num;
sb.Append("<td width='50'>" + XX_num + "</td>");
sb.Append("<td width='50'>" + PG_num + "</td>");
sb.Append("<td width='50'>" + YCHG_num + "</td>");
sb.Append("<td width='50'>" + pghg + "</td>");
sb.Append("<td width='50'>" + hg + "</td>");
sb.Append("<td width='50'>" + fx + "</td>");
sb.Append("<td width='50'>" + bf + "</td>");
sb.Append("<td width='50'>" + dxb + "</td>");
sb.Append("<td width='50'>" + yc_hg_L + "%</td>");
sb.Append("<td width='50'>" + pg_hg_L + "%</td>");
sb.Append("<td width='50'>" + all_hg_L + "%</td>");
sb.Append("<td width='50'>" + pf_L + "%</td>");
sb.Append("<td width='50'>" + pgjy + "</td>");
sb.Append("</tr>");
numList[0] = numList[0] + XX_num;
numList[1] = numList[1] + PG_num;
numList[2] = numList[2] + YCHG_num;
numList[3] = numList[3] + pghg;
numList[4] = numList[4] + hg;
//numList[5] = numList[5] + XX_num;
numList[6] = numList[6] + bf;
numList[7] = numList[7] + dxb;
//numList[8] = numList[8] + XX_num;
//numList[9] = numList[9] + XX_num;
//numList[10] = numList[10] + XX_num;
//numList[11] = numList[11] + XX_num;
numList[12] = numList[12] + pgjy;
}
private void QualifiedTrendBuilindData(EnumerableRowCollection<DataRow> DayList, ref List<string> list, List<int> numList)
{
//下线数
int XX_num = DayList.Where(p => "1".Equals(p.ItemArray[13])).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).Count();
//抛光数
//int PG_num = DayList.Where(p => p.ItemArray[6] != null && p.ItemArray[6].ToString().Contains("抛光") && "1".Equals(p.ItemArray[13])).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).Count();
var pg_1 = DayList.Where(p => p.ItemArray[6] != null && p.ItemArray[6].ToString().Contains("抛光") && "1".Equals(p.ItemArray[13])).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).ToList();
var pg_2 = DayList.Where(p => p.ItemArray[6] != null && "2".Equals(p.ItemArray[13])).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).ToList();
IEnumerable<object> pg_List = pg_1.Intersect(pg_2);
int PG_num = pg_List.Count();
//一次合格数
int YCHG_num = DayList.Where(p => p.ItemArray[6] != null && p.ItemArray[6].ToString().Contains("合格") && "1".Equals(p.ItemArray[13])).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).Count();
//抛光合格
var pghg_1 = DayList.Where(p => p.ItemArray[6] != null && p.ItemArray[6].ToString().Contains("抛光") && "1".Equals(p.ItemArray[13])).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).ToList();
var pghg_2 = DayList.Where(p => p.ItemArray[6] != null && p.ItemArray[6].ToString().Contains("合格") && "2".Equals(p.ItemArray[13])).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).ToList();
IEnumerable<object> pghg_List = pghg_1.Intersect(pghg_2);
int pghg = pghg_List.Count();
//var pghg = DayList.Where(t => t.ItemArray[3].ToString() == "下线二检 抛光区")
// .GroupBy(p => p.ItemArray[1])
// .Select(s => s.OrderByDescending(x => x.ItemArray[12]).FirstOrDefault())
// .Where(p => p.ItemArray[6].ToString().Contains("合格")).Count();
//返修合格数
var fx = DayList.Where(t => t.ItemArray[6] != null && t.ItemArray[3].ToString().Contains("点修补") && t.ItemArray[6].ToString().Contains("合格")).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).Count();
//合格数
var hg = YCHG_num + pghg + fx;
//var hg = DayList.GroupBy(p => p.ItemArray[1])
// .Select(s => s.OrderByDescending(x => x.ItemArray[12]).FirstOrDefault())
// .Where(p => p.ItemArray[6].ToString().Contains("合格")).Count();
//报废数
//var bf = DayList.GroupBy(p => p.ItemArray[1])
// .Select(s => s.OrderByDescending(x => x.ItemArray[12]).FirstOrDefault())
// .Where(p => p.ItemArray[6].ToString().Contains("报废")).Count();
var bf = DayList.Where(t => t.ItemArray[6] != null && t.ItemArray[6].ToString().Contains("报废")).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).Count();
var YC_bf = DayList.Where(t => t.ItemArray[6] != null && t.ItemArray[6].ToString().Contains("报废") && "1".Equals(t.ItemArray[13])).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).Count();
//点修补数
//var dxb = DayList.Where(t => t.ItemArray[3].ToString() == "点修补 抛光区").GroupBy(p => p.ItemArray[1]).Select(p => p.Key).Count();
var dxb = DayList.Where(p => p.ItemArray[6] != null && p.ItemArray[6].ToString().Contains("抛光") && "2".Equals(p.ItemArray[13])).GroupBy(p => p.ItemArray[1]).Select(p => p.Key).Count();
//一次合格率
var yc_hg_L = Math.Round(((double)YCHG_num / (double)XX_num) * 100, 2);
//抛光合格率
var pg_hg_L = Math.Round(((double)pghg / (double)PG_num) * 100, 2);
//总合格率
var all_hg_L = Math.Round(((double)hg / (double)XX_num) * 100, 2);
//报废率
var pf_L = Math.Round(((double)bf / (double)XX_num) * 100, 2);
//抛光结余
//var pgjy = XX_num - hg - bf - dxb;
var pgjy = XX_num - YCHG_num - YC_bf - PG_num;
list.Add(XX_num.ToString());
list.Add(PG_num.ToString());
list.Add(YCHG_num.ToString());
list.Add(pghg.ToString());
list.Add(hg.ToString());
list.Add(fx.ToString());
list.Add(bf.ToString());
list.Add(dxb.ToString());
list.Add(yc_hg_L.ToString() + "%");
list.Add(pg_hg_L.ToString() + "%");
list.Add(all_hg_L.ToString() + "%");
list.Add(pf_L.ToString() + "%");
list.Add(pgjy.ToString());
numList[0] = numList[0] + XX_num;
numList[1] = numList[1] + PG_num;
numList[2] = numList[2] + YCHG_num;
numList[3] = numList[3] + pghg;
numList[4] = numList[4] + hg;
//numList[5] = numList[5] + XX_num;
numList[6] = numList[6] + bf;
numList[7] = numList[7] + dxb;
//numList[8] = numList[8] + XX_num;
//numList[9] = numList[9] + XX_num;
//numList[10] = numList[10] + XX_num;
//numList[11] = numList[11] + XX_num;
numList[12] = numList[12] + pgjy;
}
#endregion
#region 喷涂报废统计
public string SearchPlatingScrap(string StartTime, string EndTime, string side)
{
try
{
StringBuilder sb = new StringBuilder(100);
sb.Append("<table border='1' width='1000'>");
DataTable dt = dal.SearchByResult(StartTime, EndTime, side);
if (dt != null && dt.Rows.Count > 0)
{
var infoAll = dt.AsEnumerable().GroupBy(p => p.ItemArray[1])
.Select(s => s.OrderByDescending(x => x.ItemArray[12]).FirstOrDefault())
.Where(p => p.ItemArray[6].ToString().Contains("报废")).ToList();
//获取全部产品+对应的颜色
Dictionary<string, List<string>> col_Dictionary = new Dictionary<string, List<string>>();
var info_product = infoAll.GroupBy(p => p.ItemArray[15]).Select(p => p.Key).ToList();
foreach (var item in info_product)
{
col_Dictionary.Add(item.ToString(),
infoAll.Where(p => p.ItemArray[15].ToString().Equals(item))
.GroupBy(p => p.ItemArray[14])
.Select(p => (string)p.Key).ToList());
}
//获取全部缺陷
List<string> damnPositionList = new List<string>();
foreach (var item in infoAll)
{
if (item.ItemArray[9] == null || String.IsNullOrWhiteSpace(item.ItemArray[9].ToString()))
{
continue;
}
string[] sArray = item.ItemArray[9].ToString().Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
if (sArray.Length > 0)
{
foreach (var damn in sArray)
{
if (!damnPositionList.Contains(damn))
{
damnPositionList.Add(damn);
}
}
}
}
Dictionary<string, int> total_Dictionary = new Dictionary<string, int>();
foreach (var item in damnPositionList)
{
total_Dictionary.Add(item, infoAll.Where(p => p.ItemArray[9].ToString().Contains(item)).Count());
}
var info_d = total_Dictionary.OrderByDescending(p => p.Value).ToList();
sb.Append("<tr>");
sb.Append("<td width='50'></td>");
sb.Append("<td width='50'>总数</td>");
foreach (var item in info_d)
{
sb.Append("<td width='50'>" + item.Key + "</td>");
}
sb.Append("</tr>");
foreach (var item in col_Dictionary)
{
sb.Append("<tr>");
sb.Append("<td width='50'><strong>" + item.Key + "</strong></td>");
var p_all = infoAll.Where(p => p.ItemArray[15].ToString().Equals(item.Key)).Count();
sb.Append("<td width='50'>" + p_all + "</td>");//总数
foreach (var item2 in info_d)
{
var c_num = infoAll.Where(p => p.ItemArray[15].ToString().Equals(item.Key) && p.ItemArray[9].ToString().Contains(item2.Key)).Count();
var pf_L = Math.Round(((double)c_num / (double)p_all) * 100, 2);
sb.Append("<td width='50'>" + c_num + "(" + pf_L + "%)</td>");//各缺陷总数
}
sb.Append("</tr>");
foreach (var item3 in item.Value)
{
sb.Append("<tr>");
sb.Append("<td width='50' style='text-align:center;'>" + item3 + "</td>");//颜色
var c_all = infoAll.Where(p => p.ItemArray[15].ToString().Equals(item.Key) && p.ItemArray[14].ToString().Equals(item3)).Count();
sb.Append("<td width='50'>" + c_all + "</td>");//总数
foreach (var item2 in info_d)
{
var c_num = infoAll.Where(p => p.ItemArray[15].ToString().Equals(item.Key) && p.ItemArray[14].ToString().Equals(item3) && p.ItemArray[9].ToString().Contains(item2.Key)).Count();
var pf_L = Math.Round(((double)c_num / (double)c_all) * 100, 2);
sb.Append("<td width='50'>" + c_num + "(" + pf_L + "%)</td>");//各缺陷
}
sb.Append("</tr>");
}
}
sb.Append("<tr>");
sb.Append("<td width='50'><strong>总计</strong></td>");
sb.Append("<td width='50'>" + infoAll.Count + "</td>");
foreach (var item in info_d)
{
var pf_L = Math.Round(((double)item.Value / (double)infoAll.Count) * 100, 2);
sb.Append("<td width='50'>" + item.Value + "(" + pf_L + "%)</td>");
}
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public List<List<string>> SearchPlatingScrapForExcel(string StartTime, string EndTime, string side)
{
try
{
List<List<string>> list = new List<List<string>>();
DataTable dt = dal.SearchByResult(StartTime, EndTime, side);
if (dt != null && dt.Rows.Count > 0)
{
var infoAll = dt.AsEnumerable().GroupBy(p => p.ItemArray[1])
.Select(s => s.OrderByDescending(x => x.ItemArray[12]).FirstOrDefault())
.Where(p => p.ItemArray[6].ToString().Contains("报废")).ToList();
//获取全部产品+对应的颜色
Dictionary<string, List<string>> col_Dictionary = new Dictionary<string, List<string>>();
var info_product = infoAll.GroupBy(p => p.ItemArray[15]).Select(p => p.Key).ToList();
foreach (var item in info_product)
{
col_Dictionary.Add(item.ToString(),
infoAll.Where(p => p.ItemArray[15].ToString().Equals(item))
.GroupBy(p => p.ItemArray[14])
.Select(p => (string)p.Key).ToList());
}
//获取全部缺陷
List<string> damnPositionList = new List<string>();
foreach (var item in infoAll)
{
if (item.ItemArray[9] == null || String.IsNullOrWhiteSpace(item.ItemArray[9].ToString()))
{
continue;
}
string[] sArray = item.ItemArray[9].ToString().Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
if (sArray.Length > 0)
{
foreach (var damn in sArray)
{
if (!damnPositionList.Contains(damn))
{
damnPositionList.Add(damn);
}
}
}
}
Dictionary<string, int> total_Dictionary = new Dictionary<string, int>();
foreach (var item in damnPositionList)
{
total_Dictionary.Add(item, infoAll.Where(p => p.ItemArray[9].ToString().Contains(item)).Count());
}
var info_d = total_Dictionary.OrderByDescending(p => p.Value).ToList();
List<string> sonList = new List<string>();
sonList.Add("");
sonList.Add("总数");
foreach (var item in info_d)
{
sonList.Add(item.Key);
}
list.Add(sonList);
foreach (var item in col_Dictionary)
{
List<string> colorList = new List<string>();
colorList.Add(item.Key);
var p_all = infoAll.Where(p => p.ItemArray[15].ToString().Equals(item.Key)).Count();
colorList.Add(p_all.ToString());
foreach (var item2 in info_d)
{
var c_num = infoAll.Where(p => p.ItemArray[15].ToString().Equals(item.Key) && p.ItemArray[9].ToString().Contains(item2.Key)).Count();
var pf_L = Math.Round(((double)c_num / (double)p_all) * 100, 2);
colorList.Add(c_num + "(" + pf_L + "%)");
}
list.Add(colorList);
foreach (var item3 in item.Value)
{
List<string> colorList2 = new List<string>();
colorList2.Add(item3);
//sb.Append("<tr>");
//sb.Append("<td width='50' style='text-align:center;'>" + item3 + "</td>");//颜色
var c_all = infoAll.Where(p => p.ItemArray[15].ToString().Equals(item.Key) && p.ItemArray[14].ToString().Equals(item3)).Count();
colorList2.Add(c_all.ToString());
//sb.Append("<td width='50'>" + c_all + "</td>");//总数
foreach (var item2 in info_d)
{
var c_num = infoAll.Where(p => p.ItemArray[15].ToString().Equals(item.Key) && p.ItemArray[14].ToString().Equals(item3) && p.ItemArray[9].ToString().Contains(item2.Key)).Count();
var pf_L = Math.Round(((double)c_num / (double)c_all) * 100, 2);
//sb.Append("<td width='50'>" + c_num + "(" + pf_L + "%)</td>");//各缺陷
colorList2.Add(c_num + "(" + pf_L + "%)");
}
list.Add(colorList2);
}
}
List<string> sonList2 = new List<string>();
sonList2.Add("总计");
sonList2.Add(infoAll.Count.ToString());
//sb.Append("<tr>");
//sb.Append("<td width='50'><strong>总计</strong></td>");
//sb.Append("<td width='50'>" + infoAll.Count + "</td>");
foreach (var item in info_d)
{
var pf_L = Math.Round(((double)item.Value / (double)infoAll.Count) * 100, 2);
//sb.Append("<td width='50'>" + item.Value + "(" + pf_L + "%)</td>");
sonList2.Add(item.Value + "(" + pf_L + "%)");
}
//sb.Append("</tr>");
list.Add(sonList2);
}
return list;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
#endregion
#region 喷涂抛光统计
public string SearchPlatingPolish(string StartTime, string EndTime, string side)
{
try
{
StringBuilder sb = new StringBuilder(100);
sb.Append("<table border='1' width='1000'>");
DataTable dt = dal.SearchByResult(StartTime, EndTime, side);
if (dt != null && dt.Rows.Count > 0)
{
var infoAll = dt.AsEnumerable().GroupBy(p => p.ItemArray[1])
.Select(s => s.OrderByDescending(x => x.ItemArray[12]).FirstOrDefault())
.Where(p => p.ItemArray[6].ToString().Contains("抛光")).ToList();
//获取全部产品+对应的颜色
Dictionary<string, List<string>> col_Dictionary = new Dictionary<string, List<string>>();
var info_product = infoAll.GroupBy(p => p.ItemArray[15]).Select(p => p.Key).ToList();
foreach (var item in info_product)
{
col_Dictionary.Add(item.ToString(),
infoAll.Where(p => p.ItemArray[15].ToString().Equals(item))
.GroupBy(p => p.ItemArray[14])
.Select(p => (string)p.Key).ToList());
}
//获取全部缺陷
List<string> damnPositionList = new List<string>();
foreach (var item in infoAll)
{
if (item.ItemArray[9] == null || String.IsNullOrWhiteSpace(item.ItemArray[9].ToString()))
{
continue;
}
string[] sArray = item.ItemArray[9].ToString().Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
if (sArray.Length > 0)
{
foreach (var damn in sArray)
{
if (!damnPositionList.Contains(damn))
{
damnPositionList.Add(damn);
}
}
}
}
Dictionary<string, int> total_Dictionary = new Dictionary<string, int>();
foreach (var item in damnPositionList)
{
total_Dictionary.Add(item, infoAll.Where(p => p.ItemArray[9].ToString().Contains(item)).Count());
}
var info_d = total_Dictionary.OrderByDescending(p => p.Value).ToList();
sb.Append("<tr>");
sb.Append("<td width='50'></td>");
sb.Append("<td width='50'>总数</td>");
foreach (var item in info_d)
{
sb.Append("<td width='50'>" + item.Key + "</td>");
}
sb.Append("</tr>");
foreach (var item in col_Dictionary)
{
sb.Append("<tr>");
sb.Append("<td width='50'><strong>" + item.Key + "</strong></td>");//产品
var p_all = infoAll.Where(p => p.ItemArray[15].ToString().Equals(item.Key)).Count();
sb.Append("<td width='50'>" + p_all + "</td>");//总数
foreach (var item2 in info_d)
{
var c_num = infoAll.Where(p => p.ItemArray[15].ToString().Equals(item.Key) && p.ItemArray[9].ToString().Contains(item2.Key)).Count();
var pf_L = Math.Round(((double)c_num / (double)p_all) * 100, 2);
sb.Append("<td width='50'>" + c_num + "(" + pf_L + "%)</td>");//各缺陷总数
}
sb.Append("</tr>");
foreach (var item3 in item.Value)
{
sb.Append("<tr>");
sb.Append("<td width='50' style='text-align:center;'>" + item3 + "</td>");//颜色
var c_all = infoAll.Where(p => p.ItemArray[15].ToString().Equals(item.Key) && p.ItemArray[14].ToString().Equals(item3)).Count();
sb.Append("<td width='50'>" + c_all + "</td>");//总数
foreach (var item2 in info_d)
{
var c_num = infoAll.Where(p => p.ItemArray[15].ToString().Equals(item.Key) && p.ItemArray[14].ToString().Equals(item3) && p.ItemArray[9].ToString().Contains(item2.Key)).Count();
var pf_L = Math.Round(((double)c_num / (double)c_all) * 100, 2);
sb.Append("<td width='50'>" + c_num + "(" + pf_L + "%)</td>");//各缺陷
}
sb.Append("</tr>");
}
}
sb.Append("<tr>");
sb.Append("<td width='50'><strong>总计</strong></td>");
sb.Append("<td width='50'>" + infoAll.Count + "</td>");
foreach (var item in info_d)
{
var pf_L = Math.Round(((double)item.Value / (double)infoAll.Count) * 100, 2);
sb.Append("<td width='50'>" + item.Value + "(" + pf_L + "%)</td>");
}
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public List<List<string>> SearchPlatingPolishForExcel(string StartTime, string EndTime, string side)
{
try
{
List<List<string>> list = new List<List<string>>();
DataTable dt = dal.SearchByResult(StartTime, EndTime, side);
if (dt != null && dt.Rows.Count > 0)
{
var infoAll = dt.AsEnumerable().GroupBy(p => p.ItemArray[1])
.Select(s => s.OrderByDescending(x => x.ItemArray[12]).FirstOrDefault())
.Where(p => p.ItemArray[6].ToString().Contains("抛光")).ToList();
//获取全部产品+对应的颜色
Dictionary<string, List<string>> col_Dictionary = new Dictionary<string, List<string>>();
var info_product = infoAll.GroupBy(p => p.ItemArray[15]).Select(p => p.Key).ToList();
foreach (var item in info_product)
{
col_Dictionary.Add(item.ToString(),
infoAll.Where(p => p.ItemArray[15].ToString().Equals(item))
.GroupBy(p => p.ItemArray[14])
.Select(p => (string)p.Key).ToList());
}
//获取全部缺陷
List<string> damnPositionList = new List<string>();
foreach (var item in infoAll)
{
if (item.ItemArray[9] == null || String.IsNullOrWhiteSpace(item.ItemArray[9].ToString()))
{
continue;
}
string[] sArray = item.ItemArray[9].ToString().Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
if (sArray.Length > 0)
{
foreach (var damn in sArray)
{
if (!damnPositionList.Contains(damn))
{
damnPositionList.Add(damn);
}
}
}
}
Dictionary<string, int> total_Dictionary = new Dictionary<string, int>();
foreach (var item in damnPositionList)
{
total_Dictionary.Add(item, infoAll.Where(p => p.ItemArray[9].ToString().Contains(item)).Count());
}
var info_d = total_Dictionary.OrderByDescending(p => p.Value).ToList();
List<string> sonList = new List<string>();
sonList.Add("");
sonList.Add("总数");
foreach (var item in info_d)
{
sonList.Add(item.Key);
}
list.Add(sonList);
foreach (var item in col_Dictionary)
{
List<string> colorList = new List<string>();
colorList.Add(item.Key);
var p_all = infoAll.Where(p => p.ItemArray[15].ToString().Equals(item.Key)).Count();
colorList.Add(p_all.ToString());
foreach (var item2 in info_d)
{
var c_num = infoAll.Where(p => p.ItemArray[15].ToString().Equals(item.Key) && p.ItemArray[9].ToString().Contains(item2.Key)).Count();
var pf_L = Math.Round(((double)c_num / (double)p_all) * 100, 2);
colorList.Add(c_num + "(" + pf_L + "%)");
}
list.Add(colorList);
foreach (var item3 in item.Value)
{
List<string> colorList2 = new List<string>();
colorList2.Add(item3);
//sb.Append("<tr>");
//sb.Append("<td width='50' style='text-align:center;'>" + item3 + "</td>");//颜色
var c_all = infoAll.Where(p => p.ItemArray[15].ToString().Equals(item.Key) && p.ItemArray[14].ToString().Equals(item3)).Count();
colorList2.Add(c_all.ToString());
//sb.Append("<td width='50'>" + c_all + "</td>");//总数
foreach (var item2 in info_d)
{
var c_num = infoAll.Where(p => p.ItemArray[15].ToString().Equals(item.Key) && p.ItemArray[14].ToString().Equals(item3) && p.ItemArray[9].ToString().Contains(item2.Key)).Count();
var pf_L = Math.Round(((double)c_num / (double)c_all) * 100, 2);
//sb.Append("<td width='50'>" + c_num + "(" + pf_L + "%)</td>");//各缺陷
colorList2.Add(c_num + "(" + pf_L + "%)");
}
list.Add(colorList2);
}
}
List<string> sonList2 = new List<string>();
sonList2.Add("总计");
sonList2.Add(infoAll.Count.ToString());
//sb.Append("<tr>");
//sb.Append("<td width='50'><strong>总计</strong></td>");
//sb.Append("<td width='50'>" + infoAll.Count + "</td>");
foreach (var item in info_d)
{
var pf_L = Math.Round(((double)item.Value / (double)infoAll.Count) * 100, 2);
//sb.Append("<td width='50'>" + item.Value + "(" + pf_L + "%)</td>");
sonList2.Add(item.Value + "(" + pf_L + "%)");
}
//sb.Append("</tr>");
list.Add(sonList2);
}
return list;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
#endregion
}
}