803 lines
30 KiB
C#
803 lines
30 KiB
C#
using Google.Protobuf.Collections;
|
||||
|
|
using JinYuan.Helper;
|
|||
|
|
using JinYuan.MES.Enums;
|
|||
|
|
using JinYuan.Models;
|
|||
|
|
using JinYuan.VirtualDataLibrary;
|
|||
|
|
using Language;
|
|||
|
|
using MathNet.Numerics.LinearAlgebra.Factorization;
|
|||
|
|
using MiniExcelLibs;
|
|||
|
|
using PLCCommunication.Common.DataConvert;
|
|||
|
|
using PrintSocket;
|
|||
|
|
using SqlSugar;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Diagnostics;
|
|||
|
|
using System.Drawing;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Threading;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using System.Windows.Forms;
|
|||
|
|
|
|||
|
|
namespace LargeSquareOne
|
|||
|
|
{
|
|||
|
|
public partial class FrmHistory : MultiLanguageForm
|
|||
|
|
{
|
|||
|
|
public static FrmHistory _Form;// 单例模式
|
|||
|
|
|
|||
|
|
public FrmHistory()
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
|
|||
|
|
this.cmb_SelectType.Items.AddRange(new string[] { "包装箱进站".Translated(), /*"箱唛标签打印".Translated(),*/ "包装箱出站".Translated(),/*"栈板标签打印".Translated(),*/ "箱唛信息".Translated(), "栈板信息".Translated(), "箱唛码与栈板码绑定关系".Translated() });
|
|||
|
|
this.cmb_SelectType.SelectedIndex = 0;
|
|||
|
|
|
|||
|
|
this.dtp_Start.Value = DateTime.Now.AddHours(-2.0f);
|
|||
|
|
this.dtp_End.Value = DateTime.Now;
|
|||
|
|
|
|||
|
|
this.cmb_AlarmType.Items.AddRange(new string[] { "全天".Translated(), "白班".Translated(), "夜班".Translated() });
|
|||
|
|
this.cmb_AlarmType.SelectedIndex = 0;
|
|||
|
|
|
|||
|
|
this.cmbClass.Items.AddRange(new string[] { "白班".Translated(), "夜班".Translated() });
|
|||
|
|
this.cmbClass.SelectedIndex = 0;
|
|||
|
|
|
|||
|
|
_Form = this;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 查询
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void btn_Query_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
string str = this.cmb_SelectType.Text;
|
|||
|
|
|
|||
|
|
if (string.Compare(str, "包装箱进站".Translated()) == 0)
|
|||
|
|
{
|
|||
|
|
this.cmb_SelectType.SelectedIndex = 0;
|
|||
|
|
}
|
|||
|
|
//else if (string.Compare(str, "箱唛标签打印".Translated()) == 0)
|
|||
|
|
//{
|
|||
|
|
// this.cmb_SelectType.SelectedIndex = 1;
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
else if (string.Compare(str, "包装箱出站".Translated()) == 0)
|
|||
|
|
{
|
|||
|
|
this.cmb_SelectType.SelectedIndex = 1;
|
|||
|
|
}
|
|||
|
|
else if (string.Compare(str, "箱唛信息".Translated()) == 0)
|
|||
|
|
{
|
|||
|
|
this.cmb_SelectType.SelectedIndex = 2;
|
|||
|
|
}
|
|||
|
|
else if (string.Compare(str, "栈板信息".Translated()) == 0)
|
|||
|
|
{
|
|||
|
|
this.cmb_SelectType.SelectedIndex = 3;
|
|||
|
|
}
|
|||
|
|
else if (string.Compare(str, "箱唛码与栈板码绑定关系".Translated()) == 0)
|
|||
|
|
{
|
|||
|
|
this.cmb_SelectType.SelectedIndex = 4;
|
|||
|
|
}
|
|||
|
|
//else if (string.Compare(str, "栈板标签打印".Translated()) == 0)
|
|||
|
|
//{
|
|||
|
|
// this.cmb_SelectType.SelectedIndex = 6;
|
|||
|
|
//}
|
|||
|
|
string rfid = this.txtBarCodeORRfid.Text.Trim();
|
|||
|
|
//string barCode = this.txtSteelShellCode.Text.Trim();
|
|||
|
|
string start = this.dtp_Start.Text;
|
|||
|
|
string end = this.dtp_End.Text;
|
|||
|
|
int selectType = this.cmb_SelectType.SelectedIndex;
|
|||
|
|
|
|||
|
|
Task<DataResult<DataTable>> task1 = Task.Run(() =>
|
|||
|
|
{
|
|||
|
|
return QueryProcess(selectType, rfid, "", start, end);
|
|||
|
|
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
var task2 = task1.ContinueWith(task =>
|
|||
|
|
{
|
|||
|
|
this.BeginInvoke(new Action(() =>
|
|||
|
|
{
|
|||
|
|
if (task.Result.IsSuccess)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
this.dgv_Main.DataSource = null;
|
|||
|
|
|
|||
|
|
this.dgv_Main.DataSource = task.Result.Content;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
new FrmMsgBoxOutWithAck(2, "查询失败:".Translated() + task.Result.Message, "错误提示".Translated()).Show();
|
|||
|
|
}
|
|||
|
|
}));
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
public List<AGearEntity> queryProcessListA;
|
|||
|
|
public List<BGearEntity> queryProcessListB;
|
|||
|
|
public List<DGearEntity> queryProcessListD;
|
|||
|
|
public List<EGearEntity> queryProcessListE;
|
|||
|
|
public List<ContainerKVDetail> queryProcessListF;
|
|||
|
|
public List<PalletKVDetail> queryProcessListG;
|
|||
|
|
public List<PalletEntity> queryProcessListH;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// DataTable-->List
|
|||
|
|
/// 获取三语切换的DataTable.ColumnName
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="selectType"></param>
|
|||
|
|
/// <param name="dataTable"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public DataTable GetHistoryOutData(int selectType, DataTable dataTable)
|
|||
|
|
{
|
|||
|
|
string selectTypeStr = "";
|
|||
|
|
//查询数据保存成List
|
|||
|
|
switch (selectType)
|
|||
|
|
{
|
|||
|
|
case 0:
|
|||
|
|
queryProcessListA = dataTable.ToList<AGearEntity>();
|
|||
|
|
selectTypeStr = "FrmHistory_dgv_Main_";
|
|||
|
|
break;
|
|||
|
|
//case 1:
|
|||
|
|
// queryProcessListD = dataTable.ToList<DGearEntity>();
|
|||
|
|
// selectTypeStr = "FrmHistory_dgv_Main_";
|
|||
|
|
// break;
|
|||
|
|
case 1:
|
|||
|
|
queryProcessListE = dataTable.ToList<EGearEntity>();
|
|||
|
|
selectTypeStr = "FrmHistory_dgv_Main_";
|
|||
|
|
break;
|
|||
|
|
case 2:
|
|||
|
|
queryProcessListB = dataTable.ToList<BGearEntity>();
|
|||
|
|
selectTypeStr = "FrmHistory_dgv_Main_";
|
|||
|
|
break;
|
|||
|
|
case 3:
|
|||
|
|
queryProcessListF = dataTable.ToList<ContainerKVDetail>();
|
|||
|
|
selectTypeStr = "FrmHistory_dgv_Main_";
|
|||
|
|
break;
|
|||
|
|
case 4:
|
|||
|
|
queryProcessListG = dataTable.ToList<PalletKVDetail>();
|
|||
|
|
selectTypeStr = "FrmHistory_dgv_Main_";
|
|||
|
|
break;
|
|||
|
|
case 5:
|
|||
|
|
queryProcessListH = dataTable.ToList<PalletEntity>();
|
|||
|
|
selectTypeStr = "FrmHistory_dgv_Main_";
|
|||
|
|
break;
|
|||
|
|
case 7:
|
|||
|
|
selectTypeStr = "FrmHistory_dgvClass_";
|
|||
|
|
break;
|
|||
|
|
case 8:
|
|||
|
|
selectTypeStr = "FrmHistory_dgvDays_";
|
|||
|
|
break;
|
|||
|
|
case 9:
|
|||
|
|
selectTypeStr = "FrmHistory_dgvMonth_";
|
|||
|
|
break;
|
|||
|
|
case 10:
|
|||
|
|
selectTypeStr = "FrmHistory_dgvWeek_";
|
|||
|
|
break;
|
|||
|
|
case 11:
|
|||
|
|
selectTypeStr = "FrmHistory_dgv_AlarmData_";
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 自定义获取新列名的方法 钩子函数
|
|||
|
|
Func<string, string> GetNewColumnName = originalName =>
|
|||
|
|
{
|
|||
|
|
// 这里可以根据具体需求实现自定义逻辑
|
|||
|
|
return LanguageManager.GetString($"{selectTypeStr + originalName}"); ;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// 使用自定义方法替换列名
|
|||
|
|
dataTable = dataTable.ReplaceColumnNamesWithCustomMethod(GetNewColumnName);
|
|||
|
|
|
|||
|
|
return dataTable;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private PLCCommunication.Common.DataConvert.DataResult<DataTable> QueryProcess(int selectType, string rfid, string barCode, string start, string end)
|
|||
|
|
{
|
|||
|
|
//判断时间
|
|||
|
|
DateTime startTime = Convert.ToDateTime(start);
|
|||
|
|
DateTime endTime = Convert.ToDateTime(end);
|
|||
|
|
if (startTime > endTime)
|
|||
|
|
{
|
|||
|
|
return DataResult.CreateFailResult<DataTable>("开始时间不能大于结束时间".Translated());
|
|||
|
|
}
|
|||
|
|
TimeSpan timeSpan = endTime - startTime;
|
|||
|
|
if (timeSpan.TotalDays > 7.0)
|
|||
|
|
{
|
|||
|
|
return DataResult.CreateFailResult<DataTable>("查询时间不能超过7天".Translated());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
DataTable dataTable = CommonMethods.db.QueryDataTable(CommonMethods.dBSQL.SelectHostData(selectType, rfid, barCode, start, end));
|
|||
|
|
if (dataTable != null)
|
|||
|
|
{
|
|||
|
|
dataTable = GetHistoryOutData(selectType, dataTable);
|
|||
|
|
return DataResult.CreateSuccessResult<DataTable>(dataTable);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
return DataResult.CreateFailResult<DataTable>("未能查到数据,请检测".Translated());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void btn_ExPort_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
SaveFileDialog saveFileDialog = new SaveFileDialog();
|
|||
|
|
|
|||
|
|
saveFileDialog.Filter = "XLSX文件(*.xlsx)|*.xlsx|所有文件|*.*";
|
|||
|
|
saveFileDialog.Title = "导出历史数据";
|
|||
|
|
saveFileDialog.FileName = "历史数据".Translated() + DateTime.Now.ToString("yyyyMMddHHmmss");
|
|||
|
|
saveFileDialog.DefaultExt = "xlsx";
|
|||
|
|
saveFileDialog.AddExtension = true;
|
|||
|
|
|
|||
|
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
MiniExcel.SaveAs(saveFileDialog.FileName, this.dgv_Main.DataSource);
|
|||
|
|
|
|||
|
|
if (new FrmMsgBoxWithAck("导出报表成功,是否立即打开?".Translated(), "打开报表记录".Translated()).ShowDialog() == DialogResult.OK)
|
|||
|
|
{
|
|||
|
|
Process.Start(saveFileDialog.FileName);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
new FrmMsgBoxOutWithAck(2, "导出报表失败".Translated(), "数据报表导出".Translated()).ShowDialog();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 显示序列号
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void dgv_Main_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
|
|||
|
|
{
|
|||
|
|
DataGridViewHelper.DgvRowPostPaint((DataGridView)sender, e);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 给DataGridView绘制边框
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void dgv_Main_Paint(object sender, PaintEventArgs e)
|
|||
|
|
{
|
|||
|
|
DataGridViewHelper.DgvRowPaint((DataGridView)sender, e, Color.FromArgb(1, 146, 235));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
///
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void dgv_Main_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
|
|||
|
|
{
|
|||
|
|
if (e.RowIndex != -1 && e.ColumnIndex >= 5)
|
|||
|
|
{
|
|||
|
|
object value = this.dgv_Main.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
|
|||
|
|
|
|||
|
|
if (value == null || value?.ToString().Length == 0)
|
|||
|
|
{
|
|||
|
|
e.Value = "--";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#region 减少闪烁
|
|||
|
|
protected override CreateParams CreateParams
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
CreateParams parss = base.CreateParams;
|
|||
|
|
parss.ExStyle |= 0x02000000;
|
|||
|
|
return parss;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
|
|||
|
|
#region 统计查询
|
|||
|
|
/// <summary>
|
|||
|
|
/// 班次
|
|||
|
|
/// </summary>
|
|||
|
|
private DataTable dtClasses = null;
|
|||
|
|
/// <summary>
|
|||
|
|
/// 日
|
|||
|
|
/// </summary>
|
|||
|
|
private DataTable dtDays = null;
|
|||
|
|
/// <summary>
|
|||
|
|
/// 周
|
|||
|
|
/// </summary>
|
|||
|
|
private DataTable dtWeeks = null;
|
|||
|
|
/// <summary>
|
|||
|
|
/// 月
|
|||
|
|
/// </summary>
|
|||
|
|
private DataTable dtMonths = null;
|
|||
|
|
|
|||
|
|
#region 1、按班次查询
|
|||
|
|
/// <summary>
|
|||
|
|
/// 按班次查询
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void btn_ClassQuery_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
dtClasses = null;
|
|||
|
|
DateTime strDate = dtClass.Value;
|
|||
|
|
int strClass = cmbClass.SelectedIndex;
|
|||
|
|
dtClasses = CommonMethods.db.QueryDataTable(CommonMethods.dBSQL.GetStaticByShift(strDate, strClass, CommonMethods.ChangeClassTime));
|
|||
|
|
//if (dtClasses != null)//&& dtClasses.Rows.Count > 0
|
|||
|
|
//{
|
|||
|
|
// this.dgvClass.DataSource = null;
|
|||
|
|
// this.dgvClass.DataSource = dtClasses;
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
if (dtClasses != null)
|
|||
|
|
{
|
|||
|
|
dtClasses = GetHistoryOutData(7, dtClasses);
|
|||
|
|
this.dgvClass.DataSource = null;
|
|||
|
|
this.dgvClass.DataSource = dtClasses;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 按班次导出
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void btn_ClassExPort_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
if (dgvClass.Columns.Count <= 0)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("导出失败,无查询结果");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
SaveFileDialog saveFileDialog = new SaveFileDialog();
|
|||
|
|
saveFileDialog.FileName = $"产能统计_按班次统计_{DateTime.Now.ToString("yyyyMMddHHmmss")}";
|
|||
|
|
saveFileDialog.Filter = "*|*.csv";
|
|||
|
|
if (saveFileDialog.ShowDialog() == DialogResult.Cancel)
|
|||
|
|
return;
|
|||
|
|
|
|||
|
|
string msg = "";
|
|||
|
|
if (CSVHelper<object>.ExportDataTableToCSV(dtClasses, saveFileDialog.FileName, out msg))
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("导出成功!");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
# region 2、按日查询
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 按日查询
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void btn_DaysQuery_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
dtDays = null;
|
|||
|
|
string startDateTime = dtpDays.Value.ToString("yyyy-MM-dd 00:00:00");
|
|||
|
|
string endDateTime = dtpDays.Value.ToString("yyyy-MM-dd 23:59:59");
|
|||
|
|
dtDays = CommonMethods.db.QueryDataTable(CommonMethods.dBSQL.GetStaticByDay(startDateTime, endDateTime));
|
|||
|
|
//if (dtDays != null )//&& dtDays.Rows.Count > 0
|
|||
|
|
//{
|
|||
|
|
// this.dgvDays.DataSource = null;
|
|||
|
|
// this.dgvDays.DataSource = dtDays;
|
|||
|
|
//}
|
|||
|
|
if (dtDays != null)
|
|||
|
|
{
|
|||
|
|
dtDays = GetHistoryOutData(8, dtDays);
|
|||
|
|
this.dgvDays.DataSource = null;
|
|||
|
|
this.dgvDays.DataSource = dtDays;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 按日导出
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void btn_DaysExPort_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
if (dgvDays.Columns.Count <= 0)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("导出失败,无查询结果");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
SaveFileDialog saveFileDialog = new SaveFileDialog();
|
|||
|
|
saveFileDialog.FileName = $"产能统计_按日统计_{DateTime.Now.ToString("yyyyMMddHHmmss")}";
|
|||
|
|
saveFileDialog.Filter = "*|*.csv";
|
|||
|
|
if (saveFileDialog.ShowDialog() == DialogResult.Cancel)
|
|||
|
|
return;
|
|||
|
|
|
|||
|
|
string msg = "";
|
|||
|
|
if (CSVHelper<object>.ExportDataTableToCSV(dtDays, saveFileDialog.FileName, out msg))
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("导出成功!");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 3、按周查询
|
|||
|
|
/// <summary>
|
|||
|
|
/// 按周查询
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void btn_WeekQuery_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
dtWeeks = null;
|
|||
|
|
//确定星期几
|
|||
|
|
var index = (int)dtpWeek.Value.DayOfWeek;
|
|||
|
|
index = index == 0 ? 7 : index;
|
|||
|
|
//当前周的范围
|
|||
|
|
string retStartDay = dtpWeek.Value.AddDays(-(index - 1)).ToString();
|
|||
|
|
string retEndDay = dtpWeek.Value.AddDays(7 - index).ToString();
|
|||
|
|
|
|||
|
|
dtWeeks = CommonMethods.db.QueryDataTable(CommonMethods.dBSQL.GetStaticByWeek(retStartDay, retEndDay));
|
|||
|
|
//if (dtWeeks != null)//&& dtWeeks.Rows.Count > 0
|
|||
|
|
//{
|
|||
|
|
// this.dgvWeek.DataSource = null;
|
|||
|
|
// this.dgvWeek.DataSource = dtWeeks;
|
|||
|
|
//}
|
|||
|
|
if (dtWeeks != null)
|
|||
|
|
{
|
|||
|
|
dtWeeks = GetHistoryOutData(10, dtWeeks);
|
|||
|
|
this.dgvWeek.DataSource = null;
|
|||
|
|
this.dgvWeek.DataSource = dtWeeks;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 按周导出
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void btn_WeekExPort_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
if (dgvWeek.Columns.Count <= 0)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("导出失败,无查询结果");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
SaveFileDialog saveFileDialog = new SaveFileDialog();
|
|||
|
|
saveFileDialog.FileName = $"产能统计_按周统计_{DateTime.Now.ToString("yyyyMMddHHmmss")}";
|
|||
|
|
saveFileDialog.Filter = "*|*.csv";
|
|||
|
|
if (saveFileDialog.ShowDialog() == DialogResult.Cancel)
|
|||
|
|
return;
|
|||
|
|
|
|||
|
|
string msg = "";
|
|||
|
|
if (CSVHelper<object>.ExportDataTableToCSV(dtWeeks, saveFileDialog.FileName, out msg))
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("导出成功!");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 4、按月查询
|
|||
|
|
/// <summary>
|
|||
|
|
/// 按月查询
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void btn_MonthQuery_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
dtMonths = null;
|
|||
|
|
string startDateTime = dtMonth.Value.ToString("yyyy-MM-01 00:00:00");
|
|||
|
|
|
|||
|
|
string endDateTime = new DateTime(dtMonth.Value.Year, dtMonth.Value.Month, DateTime.DaysInMonth(dtMonth.Value.Year, dtMonth.Value.Month)).ToString("yyyy-MM-dd 23:59:59");//通过指定日期计算当月最后一天
|
|||
|
|
dtMonths = CommonMethods.db.QueryDataTable(CommonMethods.dBSQL.GetStaticByMonth(startDateTime, endDateTime));
|
|||
|
|
//if (dtMonths != null)// && dtMonths.Rows.Count > 0
|
|||
|
|
//{
|
|||
|
|
// this.dgvMonth.DataSource = null;
|
|||
|
|
// this.dgvMonth.DataSource = dtMonths;
|
|||
|
|
//}
|
|||
|
|
if (dtMonths != null)
|
|||
|
|
{
|
|||
|
|
dtMonths = GetHistoryOutData(9, dtMonths);
|
|||
|
|
this.dgvMonth.DataSource = null;
|
|||
|
|
this.dgvMonth.DataSource = dtMonths;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 按月导出
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void btn_MonthExPort_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
if (dgvMonth.Columns.Count <= 0)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("导出失败,无查询结果");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
SaveFileDialog saveFileDialog = new SaveFileDialog();
|
|||
|
|
saveFileDialog.FileName = $"产能统计_按月统计_{DateTime.Now.ToString("yyyyMMddHHmmss")}";
|
|||
|
|
saveFileDialog.Filter = "*|*.csv";
|
|||
|
|
if (saveFileDialog.ShowDialog() == DialogResult.Cancel)
|
|||
|
|
return;
|
|||
|
|
|
|||
|
|
string msg = "";
|
|||
|
|
if (CSVHelper<object>.ExportDataTableToCSV(dtMonths, saveFileDialog.FileName, out msg))
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("导出成功!");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 选择班次时间变更
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void cmb_AlarmType_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
if (cmb_AlarmType.SelectedIndex == 1) //白班
|
|||
|
|
{
|
|||
|
|
DateTime baiClassStart = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 8:30:00"));
|
|||
|
|
DateTime baiClassEnd = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 20:29:59"));
|
|||
|
|
|
|||
|
|
dtp_AlarmTimeStart.Value = baiClassStart;
|
|||
|
|
dtp_AlarmTimeEnd.Value = baiClassEnd;
|
|||
|
|
}
|
|||
|
|
else if (cmb_AlarmType.SelectedIndex == 2) //夜班
|
|||
|
|
{
|
|||
|
|
DateTime yeClassStart = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 20:30:00"));
|
|||
|
|
DateTime yeClassEnd = Convert.ToDateTime(DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 8:29:59"));
|
|||
|
|
|
|||
|
|
dtp_AlarmTimeStart.Value = yeClassStart;
|
|||
|
|
dtp_AlarmTimeEnd.Value = yeClassEnd;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
DateTime baiClassStart = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
|
|||
|
|
DateTime baiClassEnd = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));
|
|||
|
|
|
|||
|
|
dtp_AlarmTimeStart.Value = baiClassStart;
|
|||
|
|
dtp_AlarmTimeEnd.Value = baiClassEnd;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#region 报警查询
|
|||
|
|
/// <summary>
|
|||
|
|
/// 查询数据
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="start"></param>
|
|||
|
|
/// <param name="end"></param>
|
|||
|
|
/// <param name="alarmType"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
private DataResult<DataTable> QueryProcess(string start, string end, int alarmType)
|
|||
|
|
{
|
|||
|
|
DateTime startDateTime = Convert.ToDateTime(start);
|
|||
|
|
DateTime endDateTime = Convert.ToDateTime(end);
|
|||
|
|
|
|||
|
|
if (startDateTime >= endDateTime)
|
|||
|
|
{
|
|||
|
|
return DataResult.CreateFailResult<DataTable>("开始时间不能大于结束时间".Translated());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
TimeSpan timeSpan = endDateTime - startDateTime;
|
|||
|
|
|
|||
|
|
if (timeSpan.TotalDays > 1.0)
|
|||
|
|
{
|
|||
|
|
return DataResult.CreateFailResult<DataTable>("查询范围不能超过1天".Translated());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
DataTable dataTable = CommonMethods.db.QueryDataTable(CommonMethods.dBSQL.SelectHostAlarmData(start, end, alarmType));
|
|||
|
|
if (dataTable != null)
|
|||
|
|
{
|
|||
|
|
dataTable = GetHistoryOutData(11, dataTable);
|
|||
|
|
return DataResult.CreateSuccessResult<DataTable>(dataTable);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
return DataResult.CreateFailResult<DataTable>("未能查到数据,请检测".Translated());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 报警信息查询
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void btn_AlarmQuery_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
string start = this.dtp_AlarmTimeStart.Text;
|
|||
|
|
string end = this.dtp_AlarmTimeEnd.Text;
|
|||
|
|
|
|||
|
|
int alarmType = this.cmb_AlarmType.SelectedIndex;
|
|||
|
|
|
|||
|
|
Task<DataResult<DataTable>> task1 = Task.Run(() =>
|
|||
|
|
{
|
|||
|
|
return QueryProcess(start, end, alarmType);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
var task2 = task1.ContinueWith(task =>
|
|||
|
|
{
|
|||
|
|
this.BeginInvoke(new Action(() =>
|
|||
|
|
{
|
|||
|
|
if (task.Result.IsSuccess)
|
|||
|
|
{
|
|||
|
|
this.dgv_AlarmData.DataSource = null;
|
|||
|
|
this.dgv_AlarmData.DataSource = task.Result.Content;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
new FrmMsgBoxOutWithAck(2, "查询失败:".Translated() + task.Result.Message, "报警查询".Translated()).Show();
|
|||
|
|
}
|
|||
|
|
}));
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 报警信息导出
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void btn_AlarmExport_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
SaveFileDialog saveFileDialog = new SaveFileDialog();
|
|||
|
|
saveFileDialog.Filter = "XLSX文件(*.xlsx)|*.xlsx|所有文件|*.*";
|
|||
|
|
saveFileDialog.Title = "导出历史报警";
|
|||
|
|
saveFileDialog.FileName = "历史报警".Translated() + DateTime.Now.ToString("yyyyMMddHHmmss");
|
|||
|
|
saveFileDialog.DefaultExt = "xlsx";
|
|||
|
|
saveFileDialog.AddExtension = true;
|
|||
|
|
|
|||
|
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
|||
|
|
{
|
|||
|
|
MiniExcel.SaveAs(saveFileDialog.FileName, this.dgv_AlarmData.DataSource);
|
|||
|
|
|
|||
|
|
if (new FrmMsgBoxWithAck("导出报警成功,是否立即打开?".Translated(), "打开报警记录".Translated()).ShowDialog() == DialogResult.OK)
|
|||
|
|
{
|
|||
|
|
Process.Start(saveFileDialog.FileName);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void dgv_AlarmData_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
|
|||
|
|
{
|
|||
|
|
DataGridViewHelper.DgvRowPostPaint((DataGridView)sender, e);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
private void button1_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
string containercode = "test_111";
|
|||
|
|
if (CommonMethods.containerPrint == null)
|
|||
|
|
{
|
|||
|
|
CommonMethods.containerPrint = new JinYuan.VirtualDataLibrary.Utlis.BartenderPrinter(CommonMethods.btwConfig.printerName);
|
|||
|
|
}
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
// 初始化目标字典
|
|||
|
|
Dictionary<string, string> vdaPrintValues = new Dictionary<string, string>();
|
|||
|
|
|
|||
|
|
vdaPrintValues["customer"] = "57";
|
|||
|
|
vdaPrintValues["supplier"] = "EVE";
|
|||
|
|
vdaPrintValues["orderNumber"] = "19999";
|
|||
|
|
vdaPrintValues["materialCode"] = "1";
|
|||
|
|
//vdaPrintValues["产品描述"] = "方形铁锂";
|
|||
|
|
vdaPrintValues["productModel"] = "123";
|
|||
|
|
vdaPrintValues["productionDate"] = "2026-01-15";
|
|||
|
|
vdaPrintValues["batchQuantity"] = "240 PCS";
|
|||
|
|
vdaPrintValues["packingQuantity"] = "10 PCS";
|
|||
|
|
vdaPrintValues["boxNumber"] = "10001";
|
|||
|
|
vdaPrintValues["level"] = "A";
|
|||
|
|
vdaPrintValues["voltage"] = "100";
|
|||
|
|
vdaPrintValues["resistance"] = "1000";
|
|||
|
|
vdaPrintValues["capacity"] = "99";
|
|||
|
|
vdaPrintValues["boxNumber"] = "test111";
|
|||
|
|
vdaPrintValues["groupNumber"] = "88";
|
|||
|
|
vdaPrintValues["remark"] = "测试";
|
|||
|
|
|
|||
|
|
|
|||
|
|
//使用打印机
|
|||
|
|
bool b = CommonMethods.containerPrint.write(CommonMethods.btwConfig.containerBTWPath, "label print", vdaPrintValues);
|
|||
|
|
if (b)
|
|||
|
|
{
|
|||
|
|
Debug.WriteLine($"箱唛码{containercode}:打印发送成功");
|
|||
|
|
//CommonMethods.AddDataMonitorLog(0, $"箱唛码{containercode}:打印发送成功".Translated());
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
Debug.WriteLine($"箱唛码{containercode}:打印发送失败");
|
|||
|
|
//CommonMethods.AddDataMonitorLog(0, $"箱唛码{containercode}:打印发送失败".Translated());
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
Debug.WriteLine($"箱唛码{containercode}:打印发送失败{ex}");
|
|||
|
|
//CommonMethods.AddDataMonitorLog(0, $"箱唛码{containercode}:打印发送失败{ex }");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void button2_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
//if (CommonMethods.btwConfig.IsConnectPrinter && CommonMethods.tcpClient == null)
|
|||
|
|
if ( CommonMethods.tcpClient == null)
|
|||
|
|
{
|
|||
|
|
CommonMethods.tcpClient = new PrintSocket.TCPClient();
|
|||
|
|
CommonMethods.tcpClient.InitClient("127.0.0.1", 8000);
|
|||
|
|
System.Threading.Thread.Sleep(100);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 构建打印数据
|
|||
|
|
|
|||
|
|
Dictionary<string, string> printData = new Dictionary<string, string>
|
|||
|
|
{
|
|||
|
|
{ "siteCode", "SZ-001" },
|
|||
|
|
{ "lineCode", "LINE-05" },
|
|||
|
|
{ "equipName", "打印" },
|
|||
|
|
{ "ContainerCode", "CONT-20260119001" },
|
|||
|
|
{ "weight", "12.5" },
|
|||
|
|
{ "palletCode", "PAL-20260119001" },
|
|||
|
|
{ "containerTypeCode", "TYPE-02" },
|
|||
|
|
{ "virtualContainerCode", "VCONT-20260119001" },
|
|||
|
|
{ "groupNum", "5" },
|
|||
|
|
{ "supplierCode", "SUPP-003" },
|
|||
|
|
{ "customerCode", "CUST-108" },
|
|||
|
|
{ "customerName", "有限公司" },
|
|||
|
|
{ "packQty", "24" },
|
|||
|
|
{ "batchQty", "1000" },
|
|||
|
|
{ "soNum", "SO-20260119001" },
|
|||
|
|
{ "customerOrder", "CO-20260119001" },
|
|||
|
|
{ "soLineNum", "SOL-20260119001-01" },
|
|||
|
|
{ "materialCode", "MAT-18650-002" },
|
|||
|
|
{ "materialName", "锂电池电芯" },
|
|||
|
|
{ "model", "2500mAh" },
|
|||
|
|
{ "grade", "A" }, // 等级
|
|||
|
|
{ "voltage", "3.7" }, // 电压(V)
|
|||
|
|
{ "inresistance", "0.012-1.00" },
|
|||
|
|
{ "capacity", "2500" },
|
|||
|
|
{ "productDate", "2026-01-19" },
|
|||
|
|
{ "rohs", "true" },
|
|||
|
|
{ "locatorCode", "LOC-02-03-05" },
|
|||
|
|
{ "locatorName", "电芯组盘区02库位" },
|
|||
|
|
{ "enableFlag", "true" },
|
|||
|
|
{ "actualLoadQty", "24" },
|
|||
|
|
{ "poNum", "PO-20260119001" },
|
|||
|
|
{ "autoFlag", "true" }
|
|||
|
|
|
|||
|
|
};
|
|||
|
|
if(CommonMethods.tcpClient != null)
|
|||
|
|
{
|
|||
|
|
// 发送打印任务
|
|||
|
|
CommonMethods.tcpClient.Send(printData);
|
|||
|
|
MessageBox.Show("打印数据发送完成");
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("打印服务器连不上");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show($"发送失败:{ex.Message}");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|