add - 湿混等待统计添加报表导出功能 监控界面小改

wangsr
wangsr 1 year ago
parent 7d43083004
commit 2d2adbedf7

@ -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<Lj_RGVTimeRecord> list;
List<Lj_RGVTimeRecord> listMore;
DataTable dt;
DataTable MoreDataTable;
public Export(List<Lj_RGVTimeRecord> list, string address)
{
this.list = list;
FileName = address;
this.ExportTo();
}
public Export(List<Lj_RGVTimeRecord> 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);
}
/// <summary>
/// 数据和导出
/// </summary>
/// <param name="workbook"></param>
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);
}
}
/// <summary>
/// 数据和计算
/// </summary>
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);
}
/// <summary>
/// 详细数据计算
/// </summary>
/// <param name="num"></param>
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);
}
}
/// <summary>
/// 时间转换
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
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 + "秒";
}
}
}

@ -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<Lj_RGVTimeRecord>().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<Lj_RGVTimeRecord>().Where(x => x.MixReadyStartTime >= starttime && x.RGVLeaveTime <= endtime).ToList();
DataTableSum();
dataGridView.DataSource = null;
dataGridView.DataSource = dt;
}
/// <summary>
@ -166,9 +176,12 @@ namespace Mesnac.Action.ChemicalWeighing.LjReport
list = FreeSqlUnit.Instance.Select<Lj_RGVTimeRecord>().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<Lj_RGVTimeRecord>().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<Lj_RGVTimeRecord>().Where(x => x.MixReadyStartTime >= starttime && x.RGVLeaveTime <= endtime).ToList();
Export export = new Export(list);
}
}
}

@ -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;

@ -483,8 +483,9 @@
<Compile Include="LjReport\DayWhiteEmbryo\DayWhiteEmbryoEntity.cs" />
<Compile Include="LjReport\DayWhiteEmbryo\DayWhiteEmbryoInitDb.cs" />
<Compile Include="LjReport\DayWhiteEmbryo\GelBlackPowderCount.cs" />
<Compile Include="LjReport\WetWaitTime\ExportToPc.cs" />
<Compile Include="LjReport\OpenDoor\OpenDoorEntity.cs" />
<Compile Include="LjReport\WetTimeCounting.cs" />
<Compile Include="LjReport\WetWaitTime\WetTimeCounting.cs" />
<Compile Include="LjStock\FrmStock.cs">
<SubType>Form</SubType>
</Compile>

@ -34,7 +34,7 @@
<Import assembly = "Data/Action/ChemicalWeighing/Mesnac.Action.ChemicalWeighing.dll">
<Action action="6089449DEBD205A2C23C8116AF3DC876" class="Mesnac.Action.ChemicalWeighing.LjReport.DayWhiteEmbryo.DayWhiteEmbryoInitDb"/>
<Action action="258ECDDA26AC41DCB027080D0ED4BE65" class="Mesnac.Action.ChemicalWeighing.LjReport.DayWhiteEmbryo.GelBlackPowderCount"/>
<Action action="2962C182D6A34253A23671D8224BB3C2" class="Mesnac.Action.ChemicalWeighing.LjReport.WetTimeCounting"/>
<Action action="2962C182D6A34253A23671D8224BB3C2" class="Mesnac.Action.ChemicalWeighing.LjReport.WetWaitTime.WetTimeCounting"/>
</Import>
</Runtime>
</ActionService>

@ -28,10 +28,34 @@
<Property name="MultiSelect">False</Property>
<Property name="Location">348, 12</Property>
<Property name="Name">MoreData</Property>
<Property name="Size">530, 623</Property>
<Property name="Size">530, 622</Property>
<Property name="TabIndex">7</Property>
</Object>
<Object type="System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="GroupBox1" children="Controls">
<Object type="Mesnac.Controls.Default.MCButton, Mesnac.Controls.Default, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="DataExport" children="Controls">
<Property name="ClickActionList">
<Binary>AAEAAAD/////AQAAAAAAAAAMAgAAAEtNZXNuYWMuQ29udHJvbHMuQmFzZSwgVmVyc2lvbj0xLjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPW51bGwEAQAAAJMBU3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWMuTGlzdGAxW1tNZXNuYWMuQ29udHJvbHMuQmFzZS5EZXNpZ25BY3Rpb24sIE1lc25hYy5Db250cm9scy5CYXNlLCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbF1dAwAAAAZfaXRlbXMFX3NpemUIX3ZlcnNpb24EAAAjTWVzbmFjLkNvbnRyb2xzLkJhc2UuRGVzaWduQWN0aW9uW10CAAAACAgJAwAAAAAAAAAAAAAABwMAAAAAAQAAAAAAAAAEIU1lc25hYy5Db250cm9scy5CYXNlLkRlc2lnbkFjdGlvbgIAAAAL</Binary>
</Property>
<Property name="MCKey" />
<Property name="MCDataSourceID" />
<Property name="IsDbControl">False</Property>
<Property name="InitDataSource" />
<Property name="ActionDataSource" />
<Property name="BindDataSource" />
<Property name="DbOptionType">None</Property>
<Property name="MCVisible">True</Property>
<Property name="MCEnabled">True</Property>
<Property name="MCPurview">False</Property>
<Property name="Format" />
<Property name="TextName" />
<Property name="NewFillColor">Red</Property>
<Property name="OldFillColor">DarkGray</Property>
<Property name="Text">报表导出</Property>
<Property name="Location">205, 104</Property>
<Property name="Name">DataExport</Property>
<Property name="Size">103, 21</Property>
<Property name="TabIndex">16</Property>
</Object>
<Object type="Mesnac.Controls.Default.MCButton, Mesnac.Controls.Default, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="NightWork" children="Controls">
<Property name="ClickActionList">
<Binary>AAEAAAD/////AQAAAAAAAAAMAgAAAEtNZXNuYWMuQ29udHJvbHMuQmFzZSwgVmVyc2lvbj0xLjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPW51bGwEAQAAAJMBU3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWMuTGlzdGAxW1tNZXNuYWMuQ29udHJvbHMuQmFzZS5EZXNpZ25BY3Rpb24sIE1lc25hYy5Db250cm9scy5CYXNlLCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbF1dAwAAAAZfaXRlbXMFX3NpemUIX3ZlcnNpb24EAAAjTWVzbmFjLkNvbnRyb2xzLkJhc2UuRGVzaWduQWN0aW9uW10CAAAACAgJAwAAAAAAAAAAAAAABwMAAAAAAQAAAAAAAAAEIU1lc25hYy5Db250cm9scy5CYXNlLkRlc2lnbkFjdGlvbgIAAAAL</Binary>
@ -234,7 +258,7 @@
<Property name="Text">范围查询</Property>
<Property name="Location">206, 77</Property>
<Property name="Name">SelectButton</Property>
<Property name="Size">103, 48</Property>
<Property name="Size">103, 21</Property>
<Property name="TabIndex">2</Property>
</Object>
<Object type="Mesnac.Controls.Default.MCButton, Mesnac.Controls.Default, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="MCButton1" children="Controls">
@ -334,7 +358,7 @@
<Property name="MCPurview">False</Property>
<Property name="AllowOriginalSizeShow">False</Property>
<Property name="BackColor">Control</Property>
<Property name="Size">906, 686</Property>
<Property name="Size">906, 687</Property>
<Property name="StartPosition">WindowsDefaultLocation</Property>
<Property name="Text">湿混机等待时间统计</Property>
<Property name="WindowState">Normal</Property>

Loading…
Cancel
Save