/// <summary> /// 设置到饼状图上 /// </summary> /// <param name="pane"></param> private void SetChart(DayReprot report, ZedGraphControl zgc) { GraphPane pane = zgc.GraphPane; pane.CurveList.Clear(); pane.GraphObjList.Clear(); pane.Title.Text = report.Date.ToString($"yyyy-MM-dd 生产情况"); pane.Title.FontSpec.IsItalic = true; pane.Title.FontSpec.Size = 12; pane.Title.FontSpec.Family = "微软雅黑"; //pane.Fill = new Fill(Color.White, Color.Goldenrod, 45.0f); //pane.Chart.Fill.Type = FillType.None; //pane.Legend.Position = LegendPos.Float; //pane.Legend.Location = new Location() addPie("生产时间", report.Times[TimeDefine.ProductTime].TotalMin, pane, Color.Navy); addPie("暂停时间", report.Times[TimeDefine.PauseTime].TotalMin, pane, Color.Yellow); addPie("DT时间", report.Times[TimeDefine.DTTime].TotalMin, pane, Color.Red); addPie("换线时间", report.Times[TimeDefine.ChangeLineTime].TotalMin, pane, Color.DarkRed); addPie("待板时间", report.Times[TimeDefine.WaitInputTime].TotalMin, pane, Color.Blue); addPie("进板时间", report.Times[TimeDefine.WaitOuputTime].TotalMin, pane, Color.Blue); pane.AxisChange(); zgc.Refresh(); zgc.Invalidate(); }
/// <summary> /// 保存今日数据 /// </summary> public void Refresh() { if (this.Reoprt != null) { var now = DateTime.Now; if (this.Reoprt.Date.Day != now.Day) { // 保存上一天的 this.Reoprt.Stop(); Common.SerializableHelper <DayReprot> helper = new Common.SerializableHelper <DayReprot>(this.Reoprt); helper.JsonSerialize(RecordPath); DayChange(now); TimeDefine temp = this.Reoprt.CurRecordTime; this.Reoprt = new DayReprot(); this.Reoprt.Date = now; this.Reoprt.Start(temp, "日期更换"); } else { if (this.Reoprt.Date.Hour != now.Hour) { this.Reoprt.HourChange(this.Reoprt.Date, now); } Common.SerializableHelper <DayReprot> helper = new Common.SerializableHelper <DayReprot>(this.Reoprt); helper.JsonSerialize(RecordPath + "today.json"); this.SaveTotal(this.Reoprt.Total, RecordPath, this.Reoprt.Date.Hour); this.Reoprt.Date = now; } } }
/// <summary> /// 将数据设置到树上显示 /// </summary> /// <param name="view"></param> private void SetTree(DayReprot report, TreeView view) { view.Nodes.Clear(); foreach (TimeDefine define in Enum.GetValues(typeof(TimeDefine))) { if (TimeDefine.NULL != define) { this.SetTree(report.Times[define], view); } } TreeNode pcbCount = view.Nodes.Add($"生产大板数 [{report.Total.TotalPCB}]"); foreach (string pcbName in report.Total.PCBCount.Keys) { pcbCount.Nodes.Add($"生产:[{pcbName}] [{report.Total.PCBCount[pcbName]}] 大板"); } TreeNode pcsCount = view.Nodes.Add($"生产总小板数 [{report.Total.TotalPCS}]"); foreach (string pcbName in report.Total.PCSCount.Keys) { pcsCount.Nodes.Add($"生产:[{pcbName}] [{report.Total.PCSCount[pcbName]}] 小片"); } TreeNode drop = view.Nodes.Add(""); double rate = 0; int count = 0; for (uint nz = 0; nz < Variable.NOZZLE_NUM; ++nz) { count = report.Total.ZDrop[nz]; rate = 0; if ((report.Total.TotalPCS + count) != 0) { rate = (double)count / (report.Total.TotalPCS + count) * 100; } drop.Nodes.Add($"吸嘴{nz + 1} 抛料数[{count}] 抛料率[{rate:N2}%]"); } if ((report.Total.TotalPCS + report.Total.TotalDrop) != 0) { rate = (double)report.Total.TotalDrop / (report.Total.TotalPCS + report.Total.TotalDrop) * 100; } else { rate = 0; } drop.Text = $"总抛料数[{report.Total.TotalDrop}] 总抛料率[{rate:N2}%]"; }
/// <summary> /// 获得 某天 某时的数据 /// </summary> /// <param name="day"></param> public DayReprot GetData(DateTime day, int startTime, int endTime, TreeView view = null, ZedGraphControl zgc = null, DataGridView gridView = null) { try { string path = $"{StatisticsPath}//{day.Year}年//{day.Month}月//{day.Day}号"; if (Directory.Exists(path)) { DayReprot report = new DayReprot(); Common.SerializableHelper <DayReprot> helper = new Common.SerializableHelper <DayReprot>(); // 拿到当天记录 report = helper.DeJsonSerialize(path + "//today.json"); // 根据时间进行筛选 report = report.GetTimeTotal(startTime, endTime); // 获得对应时间的统计 report.Total = this.GetCount(path, startTime, endTime); if (view != null) { this.SetTree(report, view); } if (zgc != null) { this.SetChart(report, zgc); } if (gridView != null) { this.SetGridView(report, gridView); } return(report); } else { if (view != null) { view.Nodes.Clear(); } return(null); } } catch (Exception ex) { return(null); } }
public DayReprot GetTimeTotal(int startTime, int endTime) { DayReprot reprot = new DayReprot(); // 各个时间段的时间报告 reprot.Times = new Dictionary <TimeDefine, TimeClassification> { { TimeDefine.ProductTime, GetRecord("机器生产时间", TimeDefine.ProductTime, startTime, endTime) }, { TimeDefine.PauseTime, GetRecord("机器暂停时间", TimeDefine.PauseTime, startTime, endTime) }, { TimeDefine.DTTime, GetRecord("机器DownTime时间", TimeDefine.DTTime, startTime, endTime) }, { TimeDefine.WaitInputTime, GetRecord("等待进板时间", TimeDefine.WaitInputTime, startTime, endTime) }, { TimeDefine.WaitOuputTime, GetRecord("等待出板时间", TimeDefine.WaitOuputTime, startTime, endTime) }, { TimeDefine.ChangeLineTime, GetRecord("换线时间", TimeDefine.ChangeLineTime, startTime, endTime) }, }; return(reprot); }
/// <summary> /// 设置到表格表上 /// </summary> /// <param name="reprot"></param> /// <param name="view"></param> public void SetGridView(DayReprot reprot, DataGridView view, bool showCT = false) { int adjust = 0; #if !SHOW_PANEL adjust = -1; #endif // 初始化 if (view.Rows.Count <= 1) { view.Rows.Add(); view.Rows[0].Cells[0].Value = "生产大板数"; view.Rows[0].Cells[2].Value = "板"; view.Rows.Add(); view.Rows[1].Cells[0].Value = "生产小板数"; view.Rows[1].Cells[2].Value = "片"; view.Rows.Add(); view.Rows[2].Cells[0].Value = "抛料率"; view.Rows[2].Cells[2].Value = "%"; view.Rows.Add(); view.Rows[3].Cells[0].Value = "报警率(Pcs)"; view.Rows[3].Cells[2].Value = "%"; #if SHOW_PANEL view.Rows.Add(); view.Rows[4].Cells[0].Value = "报警率(Panel)"; view.Rows[4].Cells[2].Value = "%"; #endif view.Rows.Add(); view.Rows[5 + adjust].Cells[0].Value = "生产时间"; view.Rows[5 + adjust].Cells[2].Value = "时:分"; view.Rows.Add(); view.Rows[6 + adjust].Cells[0].Value = "暂停时间"; view.Rows[6 + adjust].Cells[2].Value = "时:分"; view.Rows.Add(); view.Rows[7 + adjust].Cells[0].Value = "待板时间"; view.Rows[7 + adjust].Cells[2].Value = "时:分"; view.Rows.Add(); view.Rows[8 + adjust].Cells[0].Value = "DownTime"; view.Rows[8 + adjust].Cells[2].Value = "时:分"; if (showCT) { view.Rows.Add(); view.Rows[9 + adjust].Cells[0].Value = "CT"; view.Rows[9 + adjust].Cells[2].Value = "s/板"; } } view.Rows[0].Cells[1].Value = reprot.Total.TotalPCB.ToString(); view.Rows[1].Cells[1].Value = reprot.Total.TotalPCS.ToString(); if ((reprot.Total.TotalPCS + reprot.Total.TotalDrop) == 0) { view.Rows[2].Cells[1].Value = 0.ToString(); } else { view.Rows[2].Cells[1].Value = ((double)(reprot.Total.TotalDrop) / (reprot.Total.TotalPCS + reprot.Total.TotalDrop) * 100).ToString("F2"); } if ((reprot.Total.AlarmPcsCount + reprot.Total.TotalPCS) == 0) { view.Rows[3].Cells[1].Value = 0.ToString(); } else { view.Rows[3].Cells[1].Value = ((double)(reprot.Total.AlarmPcsCount) / (reprot.Total.AlarmPcsCount + reprot.Total.TotalPCS) * 100).ToString("F2"); } #if SHOW_PANEL if ((reprot.Total.AlaramPanelCount + reprot.Total.TotalPCB) == 0) { view.Rows[4].Cells[1].Value = 0.ToString(); } else { view.Rows[4].Cells[1].Value = ((double)(reprot.Total.AlaramPanelCount) / (reprot.Total.AlaramPanelCount + reprot.Total.TotalPCB) * 100).ToString("F2"); } #endif view.Rows[5 + adjust].Cells[1].Value = reprot.Times[TimeDefine.ProductTime].Total; view.Rows[6 + adjust].Cells[1].Value = reprot.Times[TimeDefine.PauseTime].Total; TimeSpan wait = reprot.Times[TimeDefine.WaitInputTime].Time + reprot.Times[TimeDefine.WaitOuputTime].Time; view.Rows[7 + adjust].Cells[1].Value = wait.ToString(@"hh\:mm\:ss"); view.Rows[8 + adjust].Cells[1].Value = reprot.Times[TimeDefine.DTTime].Total; if (showCT) { view.Rows[9 + adjust].Cells[1].Value = (Form_Main.Instance.Test.ElapsedMilliseconds / 1000.0).ToString("f2"); } }
private void button1_Click_1(object sender, EventArgs e) { Thread.Sleep(500); report = StatisticsHelper.Instance.GetData(this.dateTimePicker1.Value, (int)this.numericUpDown1.Value, (int)this.numericUpDown2.Value, this.treeView1, this.zedGraphControl1, this.dataGridView1); }