From 2d2adbedf7489b44f01c647f48168a72786979e0 Mon Sep 17 00:00:00 2001 From: wangsr Date: Wed, 8 Nov 2023 10:45:32 +0800 Subject: [PATCH] =?UTF-8?q?add=20-=20=E6=B9=BF=E6=B7=B7=E7=AD=89=E5=BE=85?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=B7=BB=E5=8A=A0=E6=8A=A5=E8=A1=A8=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E5=8A=9F=E8=83=BD=20=E7=9B=91=E6=8E=A7=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E5=B0=8F=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LjReport/WetWaitTime/ExportToPc.cs | 208 ++++++++++++++++++ .../{ => WetWaitTime}/WetTimeCounting.cs | 31 ++- .../MainDetailControlAction.cs | 6 + .../Mesnac.Action.ChemicalWeighing.csproj | 3 +- .../EventConfig/小料称量/榄菊报表.xml | 2 +- .../MCProject/nodeForm/WeterTimeCount.xml | 30 ++- 6 files changed, 270 insertions(+), 10 deletions(-) create mode 100644 Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjReport/WetWaitTime/ExportToPc.cs rename Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjReport/{ => WetWaitTime}/WetTimeCounting.cs (88%) diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjReport/WetWaitTime/ExportToPc.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjReport/WetWaitTime/ExportToPc.cs new file mode 100644 index 0000000..4df9ccf --- /dev/null +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjReport/WetWaitTime/ExportToPc.cs @@ -0,0 +1,208 @@ +using DevExpress.ClipboardSource.SpreadsheetML; +using Mesnac.Action.ChemicalWeighing.MainDetailControl.Entity; +using Microsoft.Office.Interop.Excel; +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using DataTable = System.Data.DataTable; +using Workbook = Microsoft.Office.Interop.Excel.Workbook; +using Worksheet = Microsoft.Office.Interop.Excel.Worksheet; + +namespace Mesnac.Action.ChemicalWeighing.LjReport.WetWaitTime +{ + public class Export + { + string FileName = @"D:\WeightExportFile.xlsx"; + List list; + List listMore; + DataTable dt; + DataTable MoreDataTable; + public Export(List list, string address) + { + this.list = list; + FileName = address; + this.ExportTo(); + + } + + public Export(List list) + { + this.list = list; + this.ExportTo(); + } + + public void ExportTo() + { + dt = new DataTable(); + dt.Columns.Add("机台", typeof(string)); + dt.Columns.Add("湿混等待时间", typeof(string)); + dt.Columns.Add("RGV等待时间", typeof(string)); + dt.Columns.Add("总等待时间", typeof(string)); + + MoreDataTable = new DataTable(); + MoreDataTable.Columns.Add("湿混等待时间", typeof(string)); + MoreDataTable.Columns.Add("RGV等待时间", typeof(string)); + MoreDataTable.Columns.Add("总等待时间", typeof(string)); + MoreDataTable.Columns.Add("起始时间", typeof(string)); + MoreDataTable.Columns.Add("结束时间", typeof(string)); + + // 使用 Microsoft Office Interop Excel 组件导出 Excel 文件 + Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application(); + Workbook workbook = excelApp.Workbooks.Add(); + + AllExport(workbook); + MoreDataExport(workbook); + + // 将 Excel 文件保存到磁盘 + try + { + workbook.SaveAs(this.FileName); + MessageBox.Show("导出成功!"); + } + catch + { + MessageBox.Show("请重新选择导出路径!"); + } + + // 关闭 Excel 应用程序和工作簿对象,并释放资源 + workbook.Close(); + excelApp.Quit(); + System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook); + System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp); + + } + + /// + /// 数据和导出 + /// + /// + private void AllExport(Workbook workbook) + { + DataTableSum(); + Worksheet worksheet = (Worksheet)workbook.Worksheets[1]; + worksheet.Name = "总量统计"; + worksheet.Cells[1, 1] = "机台"; + worksheet.Cells[1, 2] = "湿混等待时间"; + worksheet.Cells[1, 3] = "RGV等待时间"; + worksheet.Cells[1, 4] = "总等待时间"; + int row = 2; + //读取数据 + foreach (DataRow item in dt.Rows) + { + worksheet.Cells[row, 1] = item[0]; + worksheet.Cells[row, 2] = item[1]; + worksheet.Cells[row, 3] = item[2]; + worksheet.Cells[row, 4] = item[3]; + row++; + } + System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet); + } + + //详细数据导出 + private void MoreDataExport(Workbook workbook) + { + for(int i = 1; i <= 8; i++) + { + MoreData(i); + Worksheet worksheet = (Worksheet)workbook.Worksheets.Add(); + worksheet.Name = "机台"+ i + "详细数据"; + worksheet.Cells[1, 1] = "湿混等待时间"; + worksheet.Cells[1, 2] = "RGV等待时间"; + worksheet.Cells[1, 3] = "总等待时间"; + worksheet.Cells[1, 4] = "发送接料信号时间"; + worksheet.Cells[1, 5] = "RGV离开时间"; + int row = 2; + foreach (DataRow item in MoreDataTable.Rows) + { + worksheet.Cells[row, 1] = item[0]; + worksheet.Cells[row, 2] = item[1]; + worksheet.Cells[row, 3] = item[2]; + worksheet.Cells[row, 4] = item[3]; + worksheet.Cells[row, 5] = item[4]; + row++; + } + System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet); + } + } + + /// + /// 数据和计算 + /// + private void DataTableSum() + { + dt.Clear(); + + for (int i = 1; i <= 8; i++) + { + var dr = dt.NewRow(); + dr[0] = "湿混机" + i; + var MixWaitTime = list.Where(x => x.DeviceNo == i).Sum(x => x.MixWaitTime); + dr[1] = TimeConvert(MixWaitTime); + var RGVWaitTime = list.Where(x => x.DeviceNo == i).Sum(x => x.RgvWaitTime); + dr[2] = TimeConvert(RGVWaitTime); + var totalTime = MixWaitTime + RGVWaitTime; + dr[3] = TimeConvert(totalTime); + + dt.Rows.Add(dr); + } + var edr = dt.NewRow(); + edr[0] = "湿混等待时间总和"; + edr[1] = TimeConvert(list.Sum(x => x.MixWaitTime)); + dt.Rows.Add(edr); + var edr1 = dt.NewRow(); + edr1[0] = "RGV等待时间总和"; + edr1[1] = TimeConvert(list.Sum(x => x.RgvWaitTime)); + dt.Rows.Add(edr1); + var edr2 = dt.NewRow(); + edr2[0] = "总等待时间总和"; + edr2[1] = TimeConvert(list.Sum(x => x.MixWaitTime + x.RgvWaitTime)); + dt.Rows.Add(edr2); + } + + /// + /// 详细数据计算 + /// + /// + private void MoreData(int num) + { + MoreDataTable.Clear(); + listMore = list.Where(x => x.DeviceNo == num).ToList(); + for (int i = 0; i < listMore.Count; i++) + { + var dr = MoreDataTable.NewRow(); + dr[0] = TimeConvert(listMore[i].MixWaitTime); + dr[1] = TimeConvert(listMore[i].RgvWaitTime); + dr[2] = TimeConvert(listMore[i].MixWaitTime + listMore[i].RgvWaitTime); + dr[3] = listMore[i].MixReadyStartTime; + dr[4] = listMore[i].RGVLeaveTime; + MoreDataTable.Rows.Add(dr); + } + } + + /// + /// 时间转换 + /// + /// + /// + private string TimeConvert(int t) + { + int h = t / 3600; + int m = (t / 60) % 60; + int s = t % 60; + if (h != 0) + { + return h + "时" + m + "分" + s + "秒"; + } + if (m != 0) + { + return m + "分" + s + "秒"; + } + return s + "秒"; + } + } +} diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjReport/WetTimeCounting.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjReport/WetWaitTime/WetTimeCounting.cs similarity index 88% rename from Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjReport/WetTimeCounting.cs rename to Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjReport/WetWaitTime/WetTimeCounting.cs index 5a249aa..cc33ec4 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjReport/WetTimeCounting.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjReport/WetWaitTime/WetTimeCounting.cs @@ -3,6 +3,7 @@ using Mesnac.Action.ChemicalWeighing.FreeDb; using Mesnac.Action.ChemicalWeighing.MainDetailControl.Entity; using Mesnac.Action.ChemicalWeighing.ManualControl; using Mesnac.Controls.Default; +using Steema.TeeChart.Export; using System; using System.Collections.Generic; using System.Data; @@ -10,7 +11,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Mesnac.Action.ChemicalWeighing.LjReport +namespace Mesnac.Action.ChemicalWeighing.LjReport.WetWaitTime { public class WetTimeCounting : ChemicalWeighingAction, IAction { @@ -20,6 +21,7 @@ namespace Mesnac.Action.ChemicalWeighing.LjReport MCButton selectButton; MCButton WhiteWork; MCButton NightWork; + MCButton DataExport; MCDateTimePicker mCDateTimePicker; MCDateTimePicker startDate; @@ -44,6 +46,7 @@ namespace Mesnac.Action.ChemicalWeighing.LjReport this._runtime = runtime; var control = GetAllControls(); + this.DataExport = control.FirstOrDefault(x => x.Name == "DataExport") as MCButton; mCDateTimePicker = control.FirstOrDefault(x => x.Name == "MCDateTimePicker1") as MCDateTimePicker; btnOk = control.FirstOrDefault(x => x.Name == "MCButton1") as MCButton; dataGridView = control.FirstOrDefault(x => x.Name == "MCDataGridView1") as MCDataGridView; @@ -82,6 +85,7 @@ namespace Mesnac.Action.ChemicalWeighing.LjReport dataGridView.CellValueChanged += MoreData_Click; WhiteWork.Click += WhiteWork_Click; NightWork.Click += NightWork_Click; + DataExport.Click += DataExport_Click; } private void BtnOk_Click(object sender, EventArgs e) @@ -93,6 +97,9 @@ namespace Mesnac.Action.ChemicalWeighing.LjReport list = FreeSqlUnit.Instance.Select().Where(x => x.MixReadyStartTime >= start && x.RGVLeaveTime <= end).ToList(); DataTableSum(); + + dataGridView.DataSource = null; + dataGridView.DataSource = dt; } private void SelectButton_Click(object sender, EventArgs e) @@ -104,6 +111,9 @@ namespace Mesnac.Action.ChemicalWeighing.LjReport list = FreeSqlUnit.Instance.Select().Where(x => x.MixReadyStartTime >= starttime && x.RGVLeaveTime <= endtime).ToList(); DataTableSum(); + + dataGridView.DataSource = null; + dataGridView.DataSource = dt; } /// @@ -166,9 +176,12 @@ namespace Mesnac.Action.ChemicalWeighing.LjReport list = FreeSqlUnit.Instance.Select().Where(x => x.MixReadyStartTime >= starttime && x.RGVLeaveTime <= endtime).ToList(); DataTableSum(); + + dataGridView.DataSource = null; + dataGridView.DataSource = dt; } - private void NightWork_Click(Object sender, EventArgs e) + private void NightWork_Click(object sender, EventArgs e) { dt.Rows.Clear(); @@ -192,6 +205,9 @@ namespace Mesnac.Action.ChemicalWeighing.LjReport list = FreeSqlUnit.Instance.Select().Where(x => x.MixReadyStartTime >= starttime && x.RGVLeaveTime <= endtime).ToList(); DataTableSum(); + + dataGridView.DataSource = null; + dataGridView.DataSource = dt; } private void DataTableSum() @@ -221,9 +237,6 @@ namespace Mesnac.Action.ChemicalWeighing.LjReport edr2[0] = "总等待时间总和"; edr2[1] = TimeConvert(list.Sum(x => x.MixWaitTime + x.RgvWaitTime)); dt.Rows.Add(edr2); - - dataGridView.DataSource = null; - dataGridView.DataSource = dt; } private string TimeConvert(int t) @@ -241,5 +254,13 @@ namespace Mesnac.Action.ChemicalWeighing.LjReport } return s + "秒"; } + + private void DataExport_Click(object sender, EventArgs e) + { + DateTime starttime = startDate.Value.Date.AddHours(startTime.Value.Hour).AddMinutes(startTime.Value.Minute).AddSeconds(startTime.Value.Second); + DateTime endtime = endDate.Value.Date.AddHours(endTime.Value.Hour).AddMinutes(endTime.Value.Minute).AddSeconds(endTime.Value.Second); + list = FreeSqlUnit.Instance.Select().Where(x => x.MixReadyStartTime >= starttime && x.RGVLeaveTime <= endtime).ToList(); + Export export = new Export(list); + } } } diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/MainDetailControl/MainDetailControlAction.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/MainDetailControl/MainDetailControlAction.cs index 273b943..2a2e917 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/MainDetailControl/MainDetailControlAction.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/MainDetailControl/MainDetailControlAction.cs @@ -357,21 +357,27 @@ namespace Mesnac.Action.ChemicalWeighing.MainDetailControl { case 1: LabelE.WetWait1.Text = MixWaitTime(record); + LabelE.RGVWait1.Text = "0"; break; case 2: LabelE.WetWait2.Text = MixWaitTime(record); + LabelE.RGVWait2.Text = "0"; break; case 3: LabelE.WetWait3.Text = MixWaitTime(record); + LabelE.RGVWait3.Text = "0"; break; case 4: LabelE.WetWait4.Text = MixWaitTime(record); + LabelE.RGVWait4.Text = "0"; break; case 5: LabelE.WetWait5.Text = MixWaitTime(record); + LabelE.RGVWait5.Text = "0"; break; case 6: LabelE.WetWait6.Text = MixWaitTime(record); + LabelE.RGVWait6.Text = "0"; break; default: break; diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj index 328ef3f..188bc5c 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Mesnac.Action.ChemicalWeighing.csproj @@ -483,8 +483,9 @@ + - + Form diff --git a/Main/MCEdit/Data/EventConfig/小料称量/榄菊报表.xml b/Main/MCEdit/Data/EventConfig/小料称量/榄菊报表.xml index b75285a..0ab8c59 100644 --- a/Main/MCEdit/Data/EventConfig/小料称量/榄菊报表.xml +++ b/Main/MCEdit/Data/EventConfig/小料称量/榄菊报表.xml @@ -34,7 +34,7 @@ - + \ No newline at end of file diff --git a/Main/MCEdit/Data/MCProject/nodeForm/WeterTimeCount.xml b/Main/MCEdit/Data/MCProject/nodeForm/WeterTimeCount.xml index c6f8433..a89e443 100644 --- a/Main/MCEdit/Data/MCProject/nodeForm/WeterTimeCount.xml +++ b/Main/MCEdit/Data/MCProject/nodeForm/WeterTimeCount.xml @@ -28,10 +28,34 @@ False 348, 12 MoreData - 530, 623 + 530, 622 7 + + + AAEAAAD/////AQAAAAAAAAAMAgAAAEtNZXNuYWMuQ29udHJvbHMuQmFzZSwgVmVyc2lvbj0xLjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPW51bGwEAQAAAJMBU3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWMuTGlzdGAxW1tNZXNuYWMuQ29udHJvbHMuQmFzZS5EZXNpZ25BY3Rpb24sIE1lc25hYy5Db250cm9scy5CYXNlLCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbF1dAwAAAAZfaXRlbXMFX3NpemUIX3ZlcnNpb24EAAAjTWVzbmFjLkNvbnRyb2xzLkJhc2UuRGVzaWduQWN0aW9uW10CAAAACAgJAwAAAAAAAAAAAAAABwMAAAAAAQAAAAAAAAAEIU1lc25hYy5Db250cm9scy5CYXNlLkRlc2lnbkFjdGlvbgIAAAAL + + + + False + + + + None + True + True + False + + + Red + DarkGray + 报表导出 + 205, 104 + DataExport + 103, 21 + 16 + AAEAAAD/////AQAAAAAAAAAMAgAAAEtNZXNuYWMuQ29udHJvbHMuQmFzZSwgVmVyc2lvbj0xLjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPW51bGwEAQAAAJMBU3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWMuTGlzdGAxW1tNZXNuYWMuQ29udHJvbHMuQmFzZS5EZXNpZ25BY3Rpb24sIE1lc25hYy5Db250cm9scy5CYXNlLCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbF1dAwAAAAZfaXRlbXMFX3NpemUIX3ZlcnNpb24EAAAjTWVzbmFjLkNvbnRyb2xzLkJhc2UuRGVzaWduQWN0aW9uW10CAAAACAgJAwAAAAAAAAAAAAAABwMAAAAAAQAAAAAAAAAEIU1lc25hYy5Db250cm9scy5CYXNlLkRlc2lnbkFjdGlvbgIAAAAL @@ -234,7 +258,7 @@ 范围查询 206, 77 SelectButton - 103, 48 + 103, 21 2 @@ -334,7 +358,7 @@ False False Control - 906, 686 + 906, 687 WindowsDefaultLocation 湿混机等待时间统计 Normal