diff --git a/HighWayIot.Winform/Business/GeneralUtils.cs b/HighWayIot.Winform/Business/GeneralUtils.cs index f5c8804..75a3ed5 100644 --- a/HighWayIot.Winform/Business/GeneralUtils.cs +++ b/HighWayIot.Winform/Business/GeneralUtils.cs @@ -127,24 +127,31 @@ namespace HighWayIot.Winform.Business /// 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); - string result; - if (span > TimeSpan.FromSeconds(60)) + catch (Exception ex) { - int spanMinutes = (int)span.TotalMinutes; - int spanSeconds = (int)span.TotalSeconds % 60; - result = $"{spanMinutes} 分 {spanSeconds} 秒"; + return ""; } - else - { - int spanSeconds = (int)span.TotalSeconds % 60; - result = $"{spanSeconds} 秒"; - } - return result; } diff --git a/HighWayIot.Winform/UserControlPages/MonitorMainPages/MonitorMainPage.Designer.cs b/HighWayIot.Winform/UserControlPages/MonitorMainPages/MonitorMainPage.Designer.cs index fd2c1dd..6baffb1 100644 --- a/HighWayIot.Winform/UserControlPages/MonitorMainPages/MonitorMainPage.Designer.cs +++ b/HighWayIot.Winform/UserControlPages/MonitorMainPages/MonitorMainPage.Designer.cs @@ -72,10 +72,6 @@ namespace HighWayIot.Winform.UserControlPages this.label3 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); 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.VulcanizationNo = 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.RepeatWeight = 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.panel3 = new System.Windows.Forms.Panel(); this.panel1.SuspendLayout(); this.tableLayoutPanel1.SuspendLayout(); this.tableLayoutPanel3.SuspendLayout(); @@ -434,45 +434,7 @@ namespace HighWayIot.Winform.UserControlPages this.MonitorDataGridView.RowTemplate.Height = 32; this.MonitorDataGridView.Size = new System.Drawing.Size(2169, 799); this.MonitorDataGridView.TabIndex = 1; - // - // 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; + this.MonitorDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.MonitorDataGridView_DataError); // // No // @@ -611,6 +573,36 @@ namespace HighWayIot.Winform.UserControlPages this.IsDone.ReadOnly = true; 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 // this.MoveText.BackColor = System.Drawing.Color.Gold; @@ -624,6 +616,15 @@ namespace HighWayIot.Winform.UserControlPages this.MoveText.Text = "欢迎各位领导莅临参观"; 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 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); diff --git a/HighWayIot.Winform/UserControlPages/MonitorMainPages/MonitorMainPage.cs b/HighWayIot.Winform/UserControlPages/MonitorMainPages/MonitorMainPage.cs index b8d5243..385716e 100644 --- a/HighWayIot.Winform/UserControlPages/MonitorMainPages/MonitorMainPage.cs +++ b/HighWayIot.Winform/UserControlPages/MonitorMainPages/MonitorMainPage.cs @@ -180,75 +180,82 @@ namespace HighWayIot.Winform.UserControlPages { lock (GridRefreshLocker) { - //取出近两日的报表数据 - List dailyEntity = _zxDailyReportService.GetDailyReportInfos(); - _monitorDataSources.Clear(); - if (dailyEntity == null) + try { - return; - } - - int showCount = 0; - if (dailyEntity.Count >= 50) - { - showCount = 50; - } - else - { - showCount = dailyEntity.Count; - } - - for (int i = 0; i < showCount; i++) - { - _monitorDataSources.Add(new MonitorDataSource() + //取出近两日的报表数据 + List dailyEntity = _zxDailyReportService.GetDailyReportInfos(); + _monitorDataSources.Clear(); + if (dailyEntity == null) { - 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.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(); + return; } + + 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) { // 确保是针对 "IsDone" 列的操作 - if (MonitorDataGridView.Columns[e.ColumnIndex].Name == "IsDone" && e.RowIndex >= 0) + try { - var cell = MonitorDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex]; - string status = cell.Value?.ToString(); + if (MonitorDataGridView.Columns[e.ColumnIndex].Name == "IsDone" && e.RowIndex >= 0) + { + var cell = MonitorDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex]; + string status = cell.Value?.ToString(); - if (status == "已完成") - { - cell.Style.BackColor = Color.LightGreen; // 绿色 - } - else if (status == "未完成") - { - cell.Style.BackColor = Color.Yellow; // 黄色 + if (status == "已完成") + { + cell.Style.BackColor = Color.LightGreen; // 绿色 + } + else if (status == "未完成") + { + cell.Style.BackColor = Color.Yellow; // 黄色 + } + else + { + cell.Style.BackColor = Color.Transparent; + } } } + catch + { + + } } /// @@ -289,5 +307,14 @@ namespace HighWayIot.Winform.UserControlPages MoveText.Text = form.OutValue; } } + + private void MonitorDataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e) + { + lock (GridRefreshLocker) + { + MonitorDataGridView.DataSource = null; + MonitorDataGridView.DataSource = _monitorDataSources; + } + } } }