using DevExpress.ClipboardSource.SpreadsheetML; using Mesnac.Action.ChemicalWeighing.MainDetailControl.Entity; 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; 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; } public Export(List list) { this.list = list; } /// /// 数据和导出 /// /// private void AllExport(Workbook workbook) { } //详细数据导出 private void MoreDataExport(Workbook workbook) { } /// /// 数据和计算 /// 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); } try { 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); } catch (OverflowException ex) { MessageBox.Show("算术值溢出!请检查数据是否有误"); } } /// /// 详细数据计算 /// /// 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 + "秒"; } } }