366 lines
13 KiB
C#
366 lines
13 KiB
C#
|
|||
|
|
using JinYuan.Models;
|
||
|
|
using JinYuan.VirtualDataLibrary;
|
||
|
|
using LargeSquareOne;
|
||
|
|
using LargeSquareOne.ViewModel;
|
||
|
|
using System;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using System.ComponentModel;
|
||
|
|
using System.Diagnostics;
|
||
|
|
using System.Drawing;
|
||
|
|
using System.Linq;
|
||
|
|
using System.Text;
|
||
|
|
using System.Threading.Tasks;
|
||
|
|
using System.Windows.Forms;
|
||
|
|
using static System.Net.Mime.MediaTypeNames;
|
||
|
|
|
||
|
|
|
||
|
|
#if Model_1
|
||
|
|
//TODO 入站数据展示类名引用
|
||
|
|
using IMData = JinYuan.Models.Loading.PreweldingEntity;
|
||
|
|
//TODO 出站数据展示类名引用
|
||
|
|
using OUData = JinYuan.Models.Product.ProductionMoveOut;
|
||
|
|
|
||
|
|
#elif Model_2
|
||
|
|
//TODO 入站数据展示类名引用
|
||
|
|
using IMData = JinYuan.Models.Loading.FMoveInEntity;
|
||
|
|
//TODO 出站数据展示类名引用
|
||
|
|
using OUData = JinYuan.Models.FinalWeldingGearEntity;
|
||
|
|
|
||
|
|
#elif Model_3
|
||
|
|
//TODO 入站数据展示类名引用
|
||
|
|
using IMData = JinYuan.Models.Loading.DMoveInEntity;
|
||
|
|
//TODO 出站数据展示类名引用
|
||
|
|
using OUData = JinYuan.Models.DiolameGearEntity;
|
||
|
|
|
||
|
|
#elif Model_4
|
||
|
|
//TODO 入站数据展示类名引用
|
||
|
|
using IMData = JinYuan.Models.Loading.PETLoadingEntity;
|
||
|
|
//TODO 出站数据展示类名引用
|
||
|
|
using OUData = JinYuan.Models.Product.DiolameMoveOut;
|
||
|
|
#else
|
||
|
|
//TODO 组盘数据展示类名引用
|
||
|
|
using IMData = JinYuan.Models.AGearEntity;
|
||
|
|
//TODO 叠盘数据展示类名引用
|
||
|
|
using OUData = JinYuan.Models.BGearEntity;
|
||
|
|
//TODO 抽检数据展示类名引用
|
||
|
|
using CData = JinYuan.Models.CGearEntity;
|
||
|
|
//TODO 底托卡板绑定数据展示类名引用
|
||
|
|
using DData = JinYuan.Models.DGearEntity;
|
||
|
|
//TODO 底托卡板打印数据展示类名引用
|
||
|
|
using EData = JinYuan.Models.EGearEntity;
|
||
|
|
#endif
|
||
|
|
|
||
|
|
namespace LargeSquareOne.ViewModel
|
||
|
|
{
|
||
|
|
public static class ViewModelBase
|
||
|
|
{
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 组盘工位电池数据显示
|
||
|
|
/// </summary>
|
||
|
|
public static BindingList<IMData> listTA = new BindingList<IMData>();
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 抽检工位数据显示
|
||
|
|
/// </summary>
|
||
|
|
public static BindingList<CData> listTC = new BindingList<CData>();
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 叠盘数据绑定委托
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="m"></param>
|
||
|
|
public static BindingList<OUData> listTB = new BindingList<OUData>();
|
||
|
|
/// <summary>
|
||
|
|
/// 箱唛打印绑定委托
|
||
|
|
/// </summary>
|
||
|
|
public static BindingList<DData> listD = new BindingList<DData>();
|
||
|
|
/// <summary>
|
||
|
|
/// 栈板打印绑定委托
|
||
|
|
/// </summary>
|
||
|
|
public static BindingList<EData> listE = new BindingList<EData>();
|
||
|
|
|
||
|
|
public static void initShowLowDataTable(this FrmMain frmMain)
|
||
|
|
{
|
||
|
|
|
||
|
|
//M_DBCtrl._MachineInSQLTable = typeof(IMData).Name;
|
||
|
|
//M_DBCtrl._MachineOutSQLTable = typeof(OUData).Name;
|
||
|
|
}
|
||
|
|
|
||
|
|
#region 显示上料数据
|
||
|
|
public static void ShowFeedingData(this FrmDataMonitor from, List<object> list)
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
if (from.dgvFeedingData.InvokeRequired)
|
||
|
|
{
|
||
|
|
from.dgvFeedingData.Invoke(new Action<List<object>>(from.ShowFeedingData), list);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
if (list != null && list.Count > 0)
|
||
|
|
{
|
||
|
|
foreach (object m in list)
|
||
|
|
{
|
||
|
|
listTA.Add((IMData)m);
|
||
|
|
}
|
||
|
|
if (listTA.Count >= 500)
|
||
|
|
{
|
||
|
|
listTA.Clear();
|
||
|
|
GC.Collect();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
// 设置最新行为活动行 (当前行)
|
||
|
|
from.dgvFeedingData.CurrentCell = from.dgvFeedingData.Rows[from.dgvFeedingData.Rows.Count - 1].Cells[0];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
//ShowLog("显示上料出现" + ex.Message, 1);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
#endregion
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 初始化组盘工位表格
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="from"></param>
|
||
|
|
public static void InitDgvFeedingData(this DataGridView dataGridView)
|
||
|
|
{
|
||
|
|
dataGridView.SetColumns<IMData>();
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 初始化包装出站表格
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="dataGridView"></param>
|
||
|
|
public static void InitDgvBlankingData(this DataGridView dataGridView)
|
||
|
|
{
|
||
|
|
dataGridView.SetColumns<OUData>();
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 初始化栈板打印绑定表格
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="dataGridView"></param>
|
||
|
|
//public static void InitDgvPrintPalletData(this DataGridView dataGridView)
|
||
|
|
//{
|
||
|
|
// dataGridView.SetColumns<EData>();
|
||
|
|
//}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 初始化箱唛打印表格
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="dataGridView"></param>
|
||
|
|
public static void InitDgvPrintContainerData(this DataGridView dataGridView)
|
||
|
|
{
|
||
|
|
dataGridView.SetColumns<DData>();
|
||
|
|
}
|
||
|
|
|
||
|
|
//#region 显示打印箱唛
|
||
|
|
///// <summary>
|
||
|
|
///// 显示打印箱唛
|
||
|
|
///// </summary>
|
||
|
|
///// <param name="list"></param>
|
||
|
|
//public static void ShowPrintContainerData(this FrmDataMonitor from, List<object> list)
|
||
|
|
//{
|
||
|
|
// try
|
||
|
|
// {
|
||
|
|
// if (from.dgvPrintContainerData.InvokeRequired)
|
||
|
|
// {
|
||
|
|
// from.dgvPrintContainerData.Invoke(new Action<List<object>>(from.ShowPrintContainerData), list);
|
||
|
|
// }
|
||
|
|
// else
|
||
|
|
// {
|
||
|
|
// //绑定数据到委托数据
|
||
|
|
// if (list != null && list.Count > 0)
|
||
|
|
// {
|
||
|
|
// foreach (object m in list)
|
||
|
|
// {
|
||
|
|
// listD.Add((DData)m);
|
||
|
|
// }
|
||
|
|
// if (listD.Count >= 500)
|
||
|
|
// {
|
||
|
|
// listD.Clear();
|
||
|
|
// GC.Collect();
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// int index = from.dgvPrintContainerData.Rows.Count - 1;
|
||
|
|
|
||
|
|
// // 设置最新行为活动行 (当前行)
|
||
|
|
// from.dgvPrintContainerData.CurrentCell = from.dgvPrintContainerData.Rows[index].Cells[1];
|
||
|
|
// from.dgvPrintContainerData.BeginEdit(true);
|
||
|
|
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// catch (Exception ex)
|
||
|
|
// {
|
||
|
|
// //ShowLog("显示上料出现" + ex.Message, 1);
|
||
|
|
// }
|
||
|
|
//}
|
||
|
|
|
||
|
|
//#endregion
|
||
|
|
|
||
|
|
//#region 显示打印栈板
|
||
|
|
///// <summary>
|
||
|
|
///// 显示打印栈板
|
||
|
|
///// </summary>
|
||
|
|
///// <param name="list"></param>
|
||
|
|
//public static void ShowPrintPalletData(this FrmDataMonitor from, List<object> list)
|
||
|
|
//{
|
||
|
|
// try
|
||
|
|
// {
|
||
|
|
// if (from.dgvPrintPalletData.InvokeRequired)
|
||
|
|
// {
|
||
|
|
// from.dgvPrintPalletData.Invoke(new Action<List<object>>(from.ShowPrintPalletData), list);
|
||
|
|
// }
|
||
|
|
// else
|
||
|
|
// {
|
||
|
|
// //绑定数据到委托数据
|
||
|
|
// if (list != null && list.Count > 0)
|
||
|
|
// {
|
||
|
|
// foreach (object m in list)
|
||
|
|
// {
|
||
|
|
// listE.Add((EData)m);
|
||
|
|
// }
|
||
|
|
// if (listE.Count >= 500)
|
||
|
|
// {
|
||
|
|
// listE.Clear();
|
||
|
|
// GC.Collect();
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// int index = from.dgvPrintPalletData.Rows.Count - 1;
|
||
|
|
// //this.dgvBlankingData.FirstDisplayedScrollingRowIndex = index;
|
||
|
|
|
||
|
|
// // 设置最新行为活动行 (当前行)
|
||
|
|
// from.dgvPrintPalletData.CurrentCell = from.dgvPrintPalletData.Rows[index].Cells[1];
|
||
|
|
// from.dgvPrintPalletData.BeginEdit(true);
|
||
|
|
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// catch (Exception ex)
|
||
|
|
// {
|
||
|
|
// //ShowLog("显示上料出现" + ex.Message, 1);
|
||
|
|
// }
|
||
|
|
//}
|
||
|
|
|
||
|
|
//#endregion
|
||
|
|
|
||
|
|
//#region 显示下料数据
|
||
|
|
///// <summary>
|
||
|
|
///// 显示下料数据
|
||
|
|
///// </summary>
|
||
|
|
///// <param name="list"></param>
|
||
|
|
//public static void ShowBlankingData(this FrmDataMonitor from, List<object> list)
|
||
|
|
//{
|
||
|
|
// try
|
||
|
|
// {
|
||
|
|
// if (from.dgvBlankingData.InvokeRequired)
|
||
|
|
// {
|
||
|
|
// from.dgvBlankingData.Invoke(new Action<List<object>>(from.ShowBlankingData), list);
|
||
|
|
// }
|
||
|
|
// else
|
||
|
|
// {
|
||
|
|
// //绑定数据到委托数据
|
||
|
|
// if (list != null && list.Count > 0)
|
||
|
|
// {
|
||
|
|
// foreach (object m in list)
|
||
|
|
// {
|
||
|
|
// listTB.Add((OUData)m);
|
||
|
|
// }
|
||
|
|
// if (listTB.Count >= 500)
|
||
|
|
// {
|
||
|
|
// listTB.Clear();
|
||
|
|
// GC.Collect();
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// int index = from.dgvBlankingData.Rows.Count - 1;
|
||
|
|
// //this.dgvBlankingData.FirstDisplayedScrollingRowIndex = index;
|
||
|
|
|
||
|
|
// // 设置最新行为活动行 (当前行)
|
||
|
|
// from.dgvBlankingData.CurrentCell = from.dgvBlankingData.Rows[index].Cells[1];
|
||
|
|
// from.dgvBlankingData.BeginEdit(true);
|
||
|
|
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// catch (Exception ex)
|
||
|
|
// {
|
||
|
|
// //ShowLog("显示上料出现" + ex.Message, 1);
|
||
|
|
// }
|
||
|
|
//}
|
||
|
|
|
||
|
|
//#endregion
|
||
|
|
|
||
|
|
public static void InitFrmDataMonitor(this FrmDataMonitor from)
|
||
|
|
{
|
||
|
|
from.InitDiolameFrm();
|
||
|
|
}
|
||
|
|
|
||
|
|
public static void setColumn(this DataGridView dataGridView, string HeaderText, string DataPropertyName, bool isFill = true)
|
||
|
|
{
|
||
|
|
dataGridView.Columns.Add(dataGridView.newColumn(HeaderText, DataPropertyName, isFill));
|
||
|
|
}
|
||
|
|
|
||
|
|
public static DataGridViewTextBoxColumn newColumn(this DataGridView dataGridView, string HeaderText, string DataPropertyName, bool isFill)
|
||
|
|
{
|
||
|
|
DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
|
||
|
|
column.HeaderText = HeaderText;
|
||
|
|
column.DataPropertyName = DataPropertyName;
|
||
|
|
if (isFill)
|
||
|
|
{
|
||
|
|
column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; ;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
column.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
|
||
|
|
}
|
||
|
|
return column;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 获取dgv计算宽度
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="dataGridView"></param>
|
||
|
|
/// <param name="text"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
private static int GetCalculatedWidth(this DataGridView dataGridView, string text)
|
||
|
|
{
|
||
|
|
Font font = dataGridView.DefaultCellStyle.Font; // 获取当前字体
|
||
|
|
SizeF textSize = new SizeF(0, 0);
|
||
|
|
textSize = TextRenderer.MeasureText(text, font);
|
||
|
|
return (int)Math.Ceiling(textSize.Width) + 10; // 计算宽度并考虑额外的边距(padding)
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 设置表头单元格宽度
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="dataGridView"></param>
|
||
|
|
/// <param name="HeaderText"></param>
|
||
|
|
/// <param name="DataPropertyName"></param>
|
||
|
|
/// <param name="name"></param>
|
||
|
|
/// <param name="Width"></param>
|
||
|
|
public static void SetColumnAutoWidth(this DataGridView dataGridView, string HeaderText, string DataPropertyName, string name, int Width = 20)
|
||
|
|
{
|
||
|
|
|
||
|
|
DataGridViewTextBoxColumn column = dataGridView.newColumn(HeaderText, DataPropertyName, false);
|
||
|
|
column.Name = name;
|
||
|
|
|
||
|
|
int calculatedWidth = dataGridView.GetCalculatedWidth(HeaderText);
|
||
|
|
column.Width = Math.Max(calculatedWidth, Width); // 添加一个最小宽度限制
|
||
|
|
dataGridView.Columns.Add(column);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public static void SetColumn(this DataGridView dataGridView, string HeaderText, string DataPropertyName, int Width)
|
||
|
|
{
|
||
|
|
|
||
|
|
DataGridViewTextBoxColumn column = dataGridView.newColumn(HeaderText, DataPropertyName, false);
|
||
|
|
column.Width = Width;
|
||
|
|
dataGridView.Columns.Add(column);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|