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 db = new BasicBLL(); /// /// 查询信息 /// /// public string SearchInfo(string page, string pagesize, string StartTime, string EndTime, string position, string inspectResult) { 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); if (dt != null && dt.Rows.Count > 0) { var list = Tool.ConvertTo(dt); List groupList = new List(); List 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 md = new JsonDataModel(); md.total = total.ToString(); md.rows = groupList; jsonStr = JSONTools.ScriptSerialize(md); } } return jsonStr; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return ""; } } /// /// 点修补记录 /// /// /// /// /// /// /// 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(dt); List groupList = new List(); 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 md = new JsonDataModel(); 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> SearchInfoByRepairForExcel(string StartTime, string EndTime, string inspectResult) { try { List> list_excel = new List>(); List title_list = new List(); 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(dt); List groupList = new List(); if (list.Count > 0) { for (int i = 0; i < list.Count; i++) { List row_list = new List(); 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; } } /// /// 查询信息 /// /// public List SearchInfoAll(string StartTime, string EndTime, string position, string inspectResult) { try { List groupList = new List(); DataTable dt = dal.Search(StartTime, EndTime, position, inspectResult); if (dt != null && dt.Rows.Count > 0) { IEnumerable> result = dt.Rows.Cast().GroupBy(dr => dr["barcode"].ToString());//按A分组 foreach (IGrouping 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(dt); //List 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 SearchInfoAllByRepair(string StartTime, string EndTime, string inspectResult) //{ // try // { // List groupList = new List(); // DataTable dt = dal.SearchByRepair(StartTime, EndTime, inspectResult); // if (dt != null && dt.Rows.Count > 0) // { // IEnumerable> result = dt.Rows.Cast().GroupBy(dr => dr["barcode"].ToString()); // foreach (IGrouping 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(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); //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 numList = new List(); 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(12) >= Convert.ToDateTime(dtime.ToString("yyyy-MM-dd") + " 08:00:00.000") && myRow.Field(12) <= Convert.ToDateTime(dtime.ToString("yyyy-MM-dd") + " 19:59:59.999") select myRow; sb.Append(""); sb.Append(""); sb.Append(""); QualifiedTrendBuilindData(DayList, ref sb, numList); var NightList = from myRowNight in dt.AsEnumerable() where myRowNight.Field(12) >= Convert.ToDateTime(dtime.ToString("yyyy-MM-dd") + " 20:00:00.000") && myRowNight.Field(12) <= Convert.ToDateTime(dtime.AddDays(1).ToString("yyyy-MM-dd") + " 07:59:59.999") select myRowNight; sb.Append(""); sb.Append(""); QualifiedTrendBuilindData(NightList, ref sb, numList); } sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); } sb.Append("
日期班别下线数系统抛光数一次合格数抛光合格数合格数返修合格数报废数点修补数一次合格率抛光合格率总合格率报废率抛光结余
" + strTime + "白班
夜班
合计" + numList[0] + "" + numList[1] + "" + numList[2] + "" + numList[3] + "" + numList[4] + "0" + numList[6] + "" + numList[7] + "" + numList[12] + "
"); return sb.ToString(); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public List> SearchQualifiedTrendForExcel(string StartTime, string EndTime, string side, string product) { try { List> list = new List>(); List sonList = new List(); 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 numList = new List(); 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(12) >= Convert.ToDateTime(dtime.ToString("yyyy-MM-dd") + " 08:00:00.000") && myRow.Field(12) <= Convert.ToDateTime(dtime.ToString("yyyy-MM-dd") + " 19:59:59.999") select myRow; List sonDay = new List(); sonDay.Add(strTime); sonDay.Add("白班"); QualifiedTrendBuilindData(DayList, ref sonDay, numList); list.Add(sonDay); var NightList = from myRow in dt.AsEnumerable() where myRow.Field(12) >= Convert.ToDateTime(dtime.ToString("yyyy-MM-dd") + " 20:00:00.000") && myRow.Field(12) <= Convert.ToDateTime(dtime.AddDays(1).ToString("yyyy-MM-dd") + " 07:59:59.999") select myRow; List sonNight = new List(); sonNight.Add(strTime); sonNight.Add("夜班"); QualifiedTrendBuilindData(NightList, ref sonNight, numList); list.Add(sonNight); } List sonCount = new List(); 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 DayList, ref StringBuilder sb, List 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 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 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("" + XX_num + ""); sb.Append("" + PG_num + ""); sb.Append("" + YCHG_num + ""); sb.Append("" + pghg + ""); sb.Append("" + hg + ""); sb.Append("" + fx + ""); sb.Append("" + bf + ""); sb.Append("" + dxb + ""); sb.Append("" + yc_hg_L + "%"); sb.Append("" + pg_hg_L + "%"); sb.Append("" + all_hg_L + "%"); sb.Append("" + pf_L + "%"); sb.Append("" + pgjy + ""); sb.Append(""); 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 DayList, ref List list, List 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 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 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(""); 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> col_Dictionary = new Dictionary>(); 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 damnPositionList = new List(); 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 total_Dictionary = new Dictionary(); 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(""); sb.Append(""); sb.Append(""); foreach (var item in info_d) { sb.Append(""); } sb.Append(""); foreach (var item in col_Dictionary) { sb.Append(""); sb.Append(""); var p_all = infoAll.Where(p => p.ItemArray[15].ToString().Equals(item.Key)).Count(); sb.Append("");//总数 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("");//各缺陷总数 } sb.Append(""); foreach (var item3 in item.Value) { sb.Append(""); sb.Append("");//颜色 var c_all = infoAll.Where(p => p.ItemArray[15].ToString().Equals(item.Key) && p.ItemArray[14].ToString().Equals(item3)).Count(); sb.Append("");//总数 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("");//各缺陷 } sb.Append(""); } } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in info_d) { var pf_L = Math.Round(((double)item.Value / (double)infoAll.Count) * 100, 2); sb.Append(""); } sb.Append(""); } sb.Append("
总数" + item.Key + "
" + item.Key + "" + p_all + "" + c_num + "(" + pf_L + "%)
" + item3 + "" + c_all + "" + c_num + "(" + pf_L + "%)
总计" + infoAll.Count + "" + item.Value + "(" + pf_L + "%)
"); return sb.ToString(); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public List> SearchPlatingScrapForExcel(string StartTime, string EndTime, string side) { try { List> list = new List>(); 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> col_Dictionary = new Dictionary>(); 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 damnPositionList = new List(); 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 total_Dictionary = new Dictionary(); 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 sonList = new List(); sonList.Add(""); sonList.Add("总数"); foreach (var item in info_d) { sonList.Add(item.Key); } list.Add(sonList); foreach (var item in col_Dictionary) { List colorList = new List(); 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 colorList2 = new List(); colorList2.Add(item3); //sb.Append(""); //sb.Append("" + item3 + "");//颜色 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("" + c_all + "");//总数 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("" + c_num + "(" + pf_L + "%)");//各缺陷 colorList2.Add(c_num + "(" + pf_L + "%)"); } list.Add(colorList2); } } List sonList2 = new List(); sonList2.Add("总计"); sonList2.Add(infoAll.Count.ToString()); //sb.Append(""); //sb.Append("总计"); //sb.Append("" + infoAll.Count + ""); foreach (var item in info_d) { var pf_L = Math.Round(((double)item.Value / (double)infoAll.Count) * 100, 2); //sb.Append("" + item.Value + "(" + pf_L + "%)"); sonList2.Add(item.Value + "(" + pf_L + "%)"); } //sb.Append(""); 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(""); 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> col_Dictionary = new Dictionary>(); 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 damnPositionList = new List(); 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 total_Dictionary = new Dictionary(); 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(""); sb.Append(""); sb.Append(""); foreach (var item in info_d) { sb.Append(""); } sb.Append(""); foreach (var item in col_Dictionary) { sb.Append(""); sb.Append("");//产品 var p_all = infoAll.Where(p => p.ItemArray[15].ToString().Equals(item.Key)).Count(); sb.Append("");//总数 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("");//各缺陷总数 } sb.Append(""); foreach (var item3 in item.Value) { sb.Append(""); sb.Append("");//颜色 var c_all = infoAll.Where(p => p.ItemArray[15].ToString().Equals(item.Key) && p.ItemArray[14].ToString().Equals(item3)).Count(); sb.Append("");//总数 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("");//各缺陷 } sb.Append(""); } } sb.Append(""); sb.Append(""); sb.Append(""); foreach (var item in info_d) { var pf_L = Math.Round(((double)item.Value / (double)infoAll.Count) * 100, 2); sb.Append(""); } sb.Append(""); } sb.Append("
总数" + item.Key + "
" + item.Key + "" + p_all + "" + c_num + "(" + pf_L + "%)
" + item3 + "" + c_all + "" + c_num + "(" + pf_L + "%)
总计" + infoAll.Count + "" + item.Value + "(" + pf_L + "%)
"); return sb.ToString(); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public List> SearchPlatingPolishForExcel(string StartTime, string EndTime, string side) { try { List> list = new List>(); 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> col_Dictionary = new Dictionary>(); 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 damnPositionList = new List(); 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 total_Dictionary = new Dictionary(); 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 sonList = new List(); sonList.Add(""); sonList.Add("总数"); foreach (var item in info_d) { sonList.Add(item.Key); } list.Add(sonList); foreach (var item in col_Dictionary) { List colorList = new List(); 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 colorList2 = new List(); colorList2.Add(item3); //sb.Append(""); //sb.Append("" + item3 + "");//颜色 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("" + c_all + "");//总数 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("" + c_num + "(" + pf_L + "%)");//各缺陷 colorList2.Add(c_num + "(" + pf_L + "%)"); } list.Add(colorList2); } } List sonList2 = new List(); sonList2.Add("总计"); sonList2.Add(infoAll.Count.ToString()); //sb.Append(""); //sb.Append("总计"); //sb.Append("" + infoAll.Count + ""); foreach (var item in info_d) { var pf_L = Math.Round(((double)item.Value / (double)infoAll.Count) * 100, 2); //sb.Append("" + item.Value + "(" + pf_L + "%)"); sonList2.Add(item.Value + "(" + pf_L + "%)"); } //sb.Append(""); list.Add(sonList2); } return list; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } #endregion } }