You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
4.0 KiB
C#

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