fix - 稳定性提升

master
SoulStar 1 week ago
parent 7bf8791f4d
commit 61fb0b2000

@ -127,24 +127,31 @@ namespace HighWayIot.Winform.Business
/// <returns></returns> /// <returns></returns>
public static string DateTimeToString(DateTime? dateTimeStart, DateTime? dateTimeEnd) public static string DateTimeToString(DateTime? dateTimeStart, DateTime? dateTimeEnd)
{ {
if (dateTimeEnd == null || dateTimeStart == null) try
{ {
return string.Empty; if (dateTimeEnd == null || dateTimeStart == null)
{
return string.Empty;
}
TimeSpan span = (TimeSpan)(dateTimeEnd - dateTimeStart);
string result;
if (span > TimeSpan.FromSeconds(60))
{
int spanMinutes = (int)span.TotalMinutes;
int spanSeconds = (int)span.TotalSeconds % 60;
result = $"{spanMinutes} 分 {spanSeconds} 秒";
}
else
{
int spanSeconds = (int)span.TotalSeconds % 60;
result = $"{spanSeconds} 秒";
}
return result;
} }
TimeSpan span = (TimeSpan)(dateTimeEnd - dateTimeStart); catch (Exception ex)
string result;
if (span > TimeSpan.FromSeconds(60))
{ {
int spanMinutes = (int)span.TotalMinutes; return "";
int spanSeconds = (int)span.TotalSeconds % 60;
result = $"{spanMinutes} 分 {spanSeconds} 秒";
} }
else
{
int spanSeconds = (int)span.TotalSeconds % 60;
result = $"{spanSeconds} 秒";
}
return result;
} }

@ -72,10 +72,6 @@ namespace HighWayIot.Winform.UserControlPages
this.label3 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.MonitorDataGridView = new System.Windows.Forms.DataGridView(); this.MonitorDataGridView = new System.Windows.Forms.DataGridView();
this.DataRefresh = new System.Windows.Forms.Timer(this.components);
this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
this.panel6 = new System.Windows.Forms.Panel();
this.panel3 = new System.Windows.Forms.Panel();
this.No = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.No = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.VulcanizationNo = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.VulcanizationNo = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.StartTime = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.StartTime = new System.Windows.Forms.DataGridViewTextBoxColumn();
@ -90,7 +86,11 @@ namespace HighWayIot.Winform.UserControlPages
this.TireWeight = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.TireWeight = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.RepeatWeight = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.RepeatWeight = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.IsDone = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.IsDone = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.DataRefresh = new System.Windows.Forms.Timer(this.components);
this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
this.panel6 = new System.Windows.Forms.Panel();
this.MoveText = new Mesnac.Controls.ChemicalWeighing.HslMoveText(); this.MoveText = new Mesnac.Controls.ChemicalWeighing.HslMoveText();
this.panel3 = new System.Windows.Forms.Panel();
this.panel1.SuspendLayout(); this.panel1.SuspendLayout();
this.tableLayoutPanel1.SuspendLayout(); this.tableLayoutPanel1.SuspendLayout();
this.tableLayoutPanel3.SuspendLayout(); this.tableLayoutPanel3.SuspendLayout();
@ -434,45 +434,7 @@ namespace HighWayIot.Winform.UserControlPages
this.MonitorDataGridView.RowTemplate.Height = 32; this.MonitorDataGridView.RowTemplate.Height = 32;
this.MonitorDataGridView.Size = new System.Drawing.Size(2169, 799); this.MonitorDataGridView.Size = new System.Drawing.Size(2169, 799);
this.MonitorDataGridView.TabIndex = 1; this.MonitorDataGridView.TabIndex = 1;
// this.MonitorDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.MonitorDataGridView_DataError);
// DataRefresh
//
this.DataRefresh.Enabled = true;
this.DataRefresh.Interval = 1000;
this.DataRefresh.Tick += new System.EventHandler(this.DataRefresh_Tick);
//
// tableLayoutPanel2
//
this.tableLayoutPanel2.ColumnCount = 1;
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel2.Controls.Add(this.panel1, 0, 1);
this.tableLayoutPanel2.Controls.Add(this.panel6, 0, 0);
this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel2.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel2.Name = "tableLayoutPanel2";
this.tableLayoutPanel2.RowCount = 2;
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel2.Size = new System.Drawing.Size(2169, 228);
this.tableLayoutPanel2.TabIndex = 2;
//
// panel6
//
this.panel6.Controls.Add(this.MoveText);
this.panel6.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel6.Location = new System.Drawing.Point(3, 3);
this.panel6.Name = "panel6";
this.panel6.Size = new System.Drawing.Size(2163, 108);
this.panel6.TabIndex = 1;
//
// panel3
//
this.panel3.Controls.Add(this.tableLayoutPanel2);
this.panel3.Dock = System.Windows.Forms.DockStyle.Top;
this.panel3.Location = new System.Drawing.Point(0, 0);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(2169, 228);
this.panel3.TabIndex = 3;
// //
// No // No
// //
@ -611,6 +573,36 @@ namespace HighWayIot.Winform.UserControlPages
this.IsDone.ReadOnly = true; this.IsDone.ReadOnly = true;
this.IsDone.Width = 80; this.IsDone.Width = 80;
// //
// DataRefresh
//
this.DataRefresh.Enabled = true;
this.DataRefresh.Interval = 1000;
this.DataRefresh.Tick += new System.EventHandler(this.DataRefresh_Tick);
//
// tableLayoutPanel2
//
this.tableLayoutPanel2.ColumnCount = 1;
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel2.Controls.Add(this.panel1, 0, 1);
this.tableLayoutPanel2.Controls.Add(this.panel6, 0, 0);
this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel2.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel2.Name = "tableLayoutPanel2";
this.tableLayoutPanel2.RowCount = 2;
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel2.Size = new System.Drawing.Size(2169, 228);
this.tableLayoutPanel2.TabIndex = 2;
//
// panel6
//
this.panel6.Controls.Add(this.MoveText);
this.panel6.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel6.Location = new System.Drawing.Point(3, 3);
this.panel6.Name = "panel6";
this.panel6.Size = new System.Drawing.Size(2163, 108);
this.panel6.TabIndex = 1;
//
// MoveText // MoveText
// //
this.MoveText.BackColor = System.Drawing.Color.Gold; this.MoveText.BackColor = System.Drawing.Color.Gold;
@ -624,6 +616,15 @@ namespace HighWayIot.Winform.UserControlPages
this.MoveText.Text = "欢迎各位领导莅临参观"; this.MoveText.Text = "欢迎各位领导莅临参观";
this.MoveText.DoubleClick += new System.EventHandler(this.MoveText_DoubleClick); this.MoveText.DoubleClick += new System.EventHandler(this.MoveText_DoubleClick);
// //
// panel3
//
this.panel3.Controls.Add(this.tableLayoutPanel2);
this.panel3.Dock = System.Windows.Forms.DockStyle.Top;
this.panel3.Location = new System.Drawing.Point(0, 0);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(2169, 228);
this.panel3.TabIndex = 3;
//
// MonitorMainPage // MonitorMainPage
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);

@ -180,75 +180,82 @@ namespace HighWayIot.Winform.UserControlPages
{ {
lock (GridRefreshLocker) lock (GridRefreshLocker)
{ {
//取出近两日的报表数据 try
List<ZxDailyReportEntity> dailyEntity = _zxDailyReportService.GetDailyReportInfos();
_monitorDataSources.Clear();
if (dailyEntity == null)
{ {
return; //取出近两日的报表数据
} List<ZxDailyReportEntity> dailyEntity = _zxDailyReportService.GetDailyReportInfos();
_monitorDataSources.Clear();
int showCount = 0; if (dailyEntity == null)
if (dailyEntity.Count >= 50)
{
showCount = 50;
}
else
{
showCount = dailyEntity.Count;
}
for (int i = 0; i < showCount; i++)
{
_monitorDataSources.Add(new MonitorDataSource()
{ {
No = i + 1, return;
VulcanizationNo = dailyEntity[i].VulcanizationNo,
StartTime = dailyEntity[i].StartTime.ToString("HH:mm:ss"),
RecipeName = dailyEntity[i].RecipeName,
RecipeCode = dailyEntity[i].RecipeCode,
SpecCode = dailyEntity[i].SpecCode,
DeviceNo = dailyEntity[i].DeviceNo.ToString(),
StandardWeight = dailyEntity[i].StandardWeight ?? 0,
RawTireWeight = dailyEntity[i].RawTireWeight ?? 0,
BaseRubTimeSpan = GeneralUtils.DateTimeToString(dailyEntity[i].StartTime, dailyEntity[i].BaseEndTime),
MidRubTimeSpan = GeneralUtils.DateTimeToString(dailyEntity[i].StartTime, dailyEntity[i].MidEndTime),
FaceRubTimeSpan = GeneralUtils.DateTimeToString(dailyEntity[i].StartTime, dailyEntity[i].FaceEndTime),
RepeatWeight = dailyEntity[i].RepeatWeight ?? 0,
IsDone = dailyEntity[i].IsDone == 1 ? "已完成" : "未完成"
});
}
MonitorDataGridView.DataSource = null;
MonitorDataGridView.DataSource = _monitorDataSources;
MonitorDataGridView.CellFormatting += MonitorDataGridView_CellFormatting;
int daycount = dailyEntity.Count(x => x.StartTime >= DayStartTime && x.StartTime <= DayEndTine && x.IsDone == 1);
DayProductNumTextBox.Text = daycount.ToString();
int nightcount = dailyEntity.Count(x => x.StartTime >= NightStartTime && x.StartTime <= NightEndTime && x.IsDone == 1);
NightProductNumTextBox.Text = nightcount.ToString();
NowDateProductNumTextBox.Text = dailyEntity.Count(x => x.StartTime >= LastDayStartTime && x.StartTime <= LastNightEndTime).ToString();
ZxDailyReportEntity first = dailyEntity.FirstOrDefault();
if (first == null)
{
return;
}
RecipeCodeLabel.Text = first.RecipeCode;
SpecCodeLabel.Text = first.SpecCode;
RecipeNameLabel.Text = first.RecipeName;
ZxRecipeEntity recipeEntity = ZxRecipeService.Instance.GetRecipeInfosByRecipeCode(first.RecipeCode).FirstOrDefault();
if (recipeEntity != null)
{
//SpecNameLabel.Text = recipeEntity.RecipeName;
ZxRecipeParaEntity paraEntity = ZxRecipeParaService.Instance.GetRecipeParaInfoByRecipeCode(recipeEntity.RecipeCode).FirstOrDefault();
if (paraEntity != null)
{
RawTireWeightLabel.Text = paraEntity.TireWeight.ToString();
} }
int showCount = 0;
if (dailyEntity.Count >= 50)
{
showCount = 50;
}
else
{
showCount = dailyEntity.Count;
}
for (int i = 0; i < showCount; i++)
{
_monitorDataSources.Add(new MonitorDataSource()
{
No = i + 1,
VulcanizationNo = dailyEntity[i].VulcanizationNo ?? "",
StartTime = dailyEntity[i].StartTime.ToString("HH:mm:ss"),
RecipeName = dailyEntity[i].RecipeName ?? "",
RecipeCode = dailyEntity[i].RecipeCode ?? "",
SpecCode = dailyEntity[i].SpecCode ?? "",
DeviceNo = (dailyEntity[i].DeviceNo ?? 0).ToString(),
StandardWeight = dailyEntity[i].StandardWeight ?? 0,
RawTireWeight = dailyEntity[i].RawTireWeight ?? 0,
BaseRubTimeSpan = GeneralUtils.DateTimeToString(dailyEntity[i].StartTime, dailyEntity[i].BaseEndTime),
MidRubTimeSpan = GeneralUtils.DateTimeToString(dailyEntity[i].StartTime, dailyEntity[i].MidEndTime),
FaceRubTimeSpan = GeneralUtils.DateTimeToString(dailyEntity[i].StartTime, dailyEntity[i].FaceEndTime),
RepeatWeight = dailyEntity[i].RepeatWeight ?? 0,
IsDone = dailyEntity[i].IsDone == 1 ? "已完成" : "未完成"
});
}
MonitorDataGridView.DataSource = null;
MonitorDataGridView.DataSource = _monitorDataSources;
MonitorDataGridView.CellFormatting += MonitorDataGridView_CellFormatting;
int daycount = dailyEntity.Count(x => x.StartTime >= DayStartTime && x.StartTime <= DayEndTine && x.IsDone == 1);
DayProductNumTextBox.Text = daycount.ToString();
int nightcount = dailyEntity.Count(x => x.StartTime >= NightStartTime && x.StartTime <= NightEndTime && x.IsDone == 1);
NightProductNumTextBox.Text = nightcount.ToString();
NowDateProductNumTextBox.Text = dailyEntity.Count(x => x.StartTime >= LastDayStartTime && x.StartTime <= LastNightEndTime).ToString();
ZxDailyReportEntity first = dailyEntity.FirstOrDefault();
if (first == null)
{
return;
}
RecipeCodeLabel.Text = first.RecipeCode;
SpecCodeLabel.Text = first.SpecCode;
RecipeNameLabel.Text = first.RecipeName;
ZxRecipeEntity recipeEntity = ZxRecipeService.Instance.GetRecipeInfosByRecipeCode(first.RecipeCode).FirstOrDefault();
if (recipeEntity != null)
{
//SpecNameLabel.Text = recipeEntity.RecipeName;
ZxRecipeParaEntity paraEntity = ZxRecipeParaService.Instance.GetRecipeParaInfoByRecipeCode(recipeEntity.RecipeCode).FirstOrDefault();
if (paraEntity != null)
{
RawTireWeightLabel.Text = paraEntity.TireWeight.ToString();
}
}
RgvNoLabel.Text = first.DeviceNo.ToString();
}
catch(Exception ex)
{
} }
RgvNoLabel.Text = first.DeviceNo.ToString();
} }
} }
@ -260,20 +267,31 @@ namespace HighWayIot.Winform.UserControlPages
private void MonitorDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) private void MonitorDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{ {
// 确保是针对 "IsDone" 列的操作 // 确保是针对 "IsDone" 列的操作
if (MonitorDataGridView.Columns[e.ColumnIndex].Name == "IsDone" && e.RowIndex >= 0) try
{ {
var cell = MonitorDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex]; if (MonitorDataGridView.Columns[e.ColumnIndex].Name == "IsDone" && e.RowIndex >= 0)
string status = cell.Value?.ToString(); {
var cell = MonitorDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex];
string status = cell.Value?.ToString();
if (status == "已完成") if (status == "已完成")
{ {
cell.Style.BackColor = Color.LightGreen; // 绿色 cell.Style.BackColor = Color.LightGreen; // 绿色
} }
else if (status == "未完成") else if (status == "未完成")
{ {
cell.Style.BackColor = Color.Yellow; // 黄色 cell.Style.BackColor = Color.Yellow; // 黄色
}
else
{
cell.Style.BackColor = Color.Transparent;
}
} }
} }
catch
{
}
} }
/// <summary> /// <summary>
@ -289,5 +307,14 @@ namespace HighWayIot.Winform.UserControlPages
MoveText.Text = form.OutValue; MoveText.Text = form.OutValue;
} }
} }
private void MonitorDataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
lock (GridRefreshLocker)
{
MonitorDataGridView.DataSource = null;
MonitorDataGridView.DataSource = _monitorDataSources;
}
}
} }
} }

Loading…
Cancel
Save