using CentralControl.DBDAO; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using XGL.Models.Model; using System.Windows.Threading; using XGL.Tools; namespace XGL { /// /// Window1.xaml 的交互逻辑 /// public partial class HFstatus : Window { private DispatcherTimer timer; public static int menqian = 20000; public static int shifouchaxun18 = 1; public static int shifouchaxun17 = 1; public static int shifouchaxun16 = 1; public static int shifouchaxun15 = 1; public static int shifouchaxun14 = 1; public static int shifouchaxun13 = 1; public static int shifouchaxun12 = 1; public static int shifouchaxun11 = 1; public static int shifouchaxun10 = 1; SerialHelper serialHelper = new SerialHelper(); public HFstatus() { InitializeComponent(); // 创建并配置定时器 fenzhong.Text = menqian.ToString(); timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(3); // 设置定时器间隔(3秒) timer.Tick += new EventHandler(selectHFvalue); // 每次定时器触发时执行 UpdateUI 方法 timer.Start(); // 启动定时器 } DBService userDbWareHouse = new DBService(); public void selectHFvalue(object sender, EventArgs e) { var dt = userDbWareHouse.GetHFStatusInfo(); foreach (var item in dt) { if (item.device_code == "H18") { if (item.property == "Intheoven") { shuliang18.Text = item.isvalue; } else if (item.property == "dollyNumber") { if (item.isvalue.ToString() != "0") { menqian18.Text = "有车:" + item.isvalue.ToString(); menqian18.Foreground = new SolidColorBrush(Colors.Red); } else { menqian18.Text = "无"; menqian18.Foreground = new SolidColorBrush(Colors.Green); } // 获取当前时间 DateTime currentTime = DateTime.Now; // 将查询到的时间字符串转换为 DateTime 对象 if (DateTime.TryParse(item.last_update_time, out DateTime lastUpdateTime)) { // 计算时间差 TimeSpan timeDifference = currentTime - lastUpdateTime; daojishi18.Text = timeDifference.TotalMinutes.ToString("F2"); if (timeDifference.TotalMinutes > menqian) { if (xuanze18.IsChecked == true) { serialHelper.ComOn(); serialHelper.redLightOn(); serialHelper.buzzerOn(); serialHelper.ComOff(); MessageBox.Show("烘房18门前小车数量值保持超过" + menqian + "分钟请查看!!!"); bianhao18.Background = new SolidColorBrush(Colors.Wheat); } } else { bianhao18.Background = new SolidColorBrush(Colors.White); } } else { // 如果解析失败,处理异常情况 Console.WriteLine("Failed to parse last_update_time"); } } else { if (item.isvalue.ToString() == "5") { zhuangtai18.Text = "自动"; zhuangtai18.Foreground = new SolidColorBrush(Colors.Green); } else { zhuangtai18.Foreground = new SolidColorBrush(Colors.Red); zhuangtai18.Text = "手动或异常"; } } } else if (item.device_code == "H17") { if (item.property == "Intheoven") { shuliang17.Text = item.isvalue; } else if (item.property == "dollyNumber") { if (item.isvalue.ToString() != "0") { menqian17.Text = "有车:" + item.isvalue.ToString(); menqian17.Foreground = new SolidColorBrush(Colors.Red); } else { menqian17.Text = "无"; menqian17.Foreground = new SolidColorBrush(Colors.Green); } // 获取当前时间 DateTime currentTime = DateTime.Now; // 将查询到的时间字符串转换为 DateTime 对象 if (DateTime.TryParse(item.last_update_time, out DateTime lastUpdateTime)) { // 计算时间差 TimeSpan timeDifference = currentTime - lastUpdateTime; daojishi17.Text = timeDifference.TotalMinutes.ToString("F2"); if (timeDifference.TotalMinutes > menqian) { if (xuanze17.IsChecked == true) { serialHelper.ComOn(); serialHelper.redLightOn(); serialHelper.buzzerOn(); serialHelper.ComOff(); MessageBox.Show("烘房17门前小车数量值保持超过" + menqian + "分钟请查看!!!"); bianhao17.Background = new SolidColorBrush(Colors.Wheat); } } else { bianhao17.Background = new SolidColorBrush(Colors.White); } } else { // 如果解析失败,处理异常情况 Console.WriteLine("Failed to parse last_update_time"); } } else { if (item.isvalue.ToString() == "5") { zhuangtai17.Text = "自动"; zhuangtai17.Foreground = new SolidColorBrush(Colors.Green); } else { zhuangtai17.Text = "手动或异常"; zhuangtai17.Foreground = new SolidColorBrush(Colors.Red); } } } else if (item.device_code == "H16") { if (item.property == "Intheoven") { shuliang16.Text = item.isvalue; } else if (item.property == "dollyNumber") { if (item.isvalue.ToString() != "0") { menqian16.Text = "有车:" + item.isvalue.ToString(); menqian16.Foreground = new SolidColorBrush(Colors.Red); } else { menqian16.Text = "无"; menqian16.Foreground = new SolidColorBrush(Colors.Green); } // 获取当前时间 DateTime currentTime = DateTime.Now; // 将查询到的时间字符串转换为 DateTime 对象 if (DateTime.TryParse(item.last_update_time, out DateTime lastUpdateTime)) { // 计算时间差 TimeSpan timeDifference = currentTime - lastUpdateTime; daojishi16.Text = timeDifference.TotalMinutes.ToString("F2"); if (timeDifference.TotalMinutes > menqian) { if (xuanze16.IsChecked == true) { serialHelper.ComOn(); serialHelper.redLightOn(); serialHelper.buzzerOn(); serialHelper.ComOff(); MessageBox.Show("烘房16门前小车数量值保持超过" + menqian + "分钟请查看!!!"); bianhao16.Background = new SolidColorBrush(Colors.Wheat); } } else { bianhao16.Background = new SolidColorBrush(Colors.White); } } else { // 如果解析失败,处理异常情况 Console.WriteLine("Failed to parse last_update_time"); } } else { if (item.isvalue.ToString() == "5") { zhuangtai16.Text = "自动"; zhuangtai16.Foreground = new SolidColorBrush(Colors.Green); } else { zhuangtai16.Text = "手动或异常"; zhuangtai16.Foreground = new SolidColorBrush(Colors.Red); } } } else if (item.device_code == "H15") { if (item.property == "Intheoven") { shuliang15.Text = item.isvalue; } else if (item.property == "dollyNumber") { if (item.isvalue.ToString() != "0") { menqian15.Text = "有车:" + item.isvalue.ToString(); menqian15.Foreground = new SolidColorBrush(Colors.Red); } else { menqian15.Text = "无"; menqian15.Foreground = new SolidColorBrush(Colors.Green); } // 获取当前时间 DateTime currentTime = DateTime.Now; // 将查询到的时间字符串转换为 DateTime 对象 if (DateTime.TryParse(item.last_update_time, out DateTime lastUpdateTime)) { // 计算时间差 TimeSpan timeDifference = currentTime - lastUpdateTime; daojishi15.Text = timeDifference.TotalMinutes.ToString("F2"); if (timeDifference.TotalMinutes > menqian) { if (xuanze15.IsChecked == true) { serialHelper.ComOn(); serialHelper.redLightOn(); serialHelper.buzzerOn(); serialHelper.ComOff(); MessageBox.Show("烘房15门前小车数量值保持超过" + menqian + "分钟请查看!!!"); bianhao15.Background = new SolidColorBrush(Colors.Wheat); } } else { bianhao15.Background = new SolidColorBrush(Colors.White); } } else { // 如果解析失败,处理异常情况 Console.WriteLine("Failed to parse last_update_time"); } } else { if (item.isvalue.ToString() == "5") { zhuangtai15.Text = "自动"; zhuangtai15.Foreground = new SolidColorBrush(Colors.Green); } else { zhuangtai15.Text = "手动或异常"; zhuangtai15.Foreground = new SolidColorBrush(Colors.Red); } } } else if (item.device_code == "H14") { if (item.property == "Intheoven") { shuliang14.Text = item.isvalue; } else if (item.property == "dollyNumber") { if (item.isvalue.ToString() != "0") { menqian14.Text = "有车:" + item.isvalue.ToString(); menqian14.Foreground = new SolidColorBrush(Colors.Red); } else { menqian14.Text = "无"; menqian14.Foreground = new SolidColorBrush(Colors.Green); } // 获取当前时间 DateTime currentTime = DateTime.Now; // 将查询到的时间字符串转换为 DateTime 对象 if (DateTime.TryParse(item.last_update_time, out DateTime lastUpdateTime)) { // 计算时间差 TimeSpan timeDifference = currentTime - lastUpdateTime; daojishi14.Text = timeDifference.TotalMinutes.ToString("F2"); if (timeDifference.TotalMinutes > menqian) { if (xuanze14.IsChecked == true) { serialHelper.ComOn(); serialHelper.redLightOn(); serialHelper.buzzerOn(); serialHelper.ComOff(); MessageBox.Show("烘房14门前小车数量值保持超过" + menqian + "分钟请查看!!!"); bianhao14.Background = new SolidColorBrush(Colors.Wheat); } } else { bianhao14.Background = new SolidColorBrush(Colors.White); } } else { // 如果解析失败,处理异常情况 Console.WriteLine("Failed to parse last_update_time"); } } else { if (item.isvalue.ToString() == "5") { zhuangtai14.Text = "自动"; zhuangtai14.Foreground = new SolidColorBrush(Colors.Green); } else { zhuangtai14.Text = "手动或异常"; zhuangtai14.Foreground = new SolidColorBrush(Colors.Red); } } } else if (item.device_code == "H13") { if (item.property == "Intheoven") { shuliang13.Text = item.isvalue; } else if (item.property == "dollyNumber") { if (item.isvalue.ToString() != "0") { menqian13.Text = "有车:" + item.isvalue.ToString(); menqian13.Foreground = new SolidColorBrush(Colors.Red); } else { menqian13.Text = "无"; menqian13.Foreground = new SolidColorBrush(Colors.Green); } // 获取当前时间 DateTime currentTime = DateTime.Now; // 将查询到的时间字符串转换为 DateTime 对象 if (DateTime.TryParse(item.last_update_time, out DateTime lastUpdateTime)) { // 计算时间差 TimeSpan timeDifference = currentTime - lastUpdateTime; daojishi13.Text = timeDifference.TotalMinutes.ToString("F2"); if (timeDifference.TotalMinutes > menqian) { if (xuanze13.IsChecked == true) { serialHelper.ComOn(); serialHelper.redLightOn(); serialHelper.buzzerOn(); serialHelper.ComOff(); MessageBox.Show("烘房13门前小车数量值保持超过" + menqian + "分钟请查看!!!"); bianhao13.Background = new SolidColorBrush(Colors.Wheat); } } else { bianhao13.Background = new SolidColorBrush(Colors.White); } } else { // 如果解析失败,处理异常情况 Console.WriteLine("Failed to parse last_update_time"); } } else { if (item.isvalue.ToString() == "5") { zhuangtai13.Text = "自动"; zhuangtai13.Foreground = new SolidColorBrush(Colors.Green); } else { zhuangtai13.Text = "手动或异常"; zhuangtai13.Foreground = new SolidColorBrush(Colors.Red); } } } else if (item.device_code == "H12") { if (item.property == "Intheoven") { shuliang12.Text = item.isvalue; } else if (item.property == "dollyNumber") { if (item.isvalue.ToString() != "0") { menqian12.Text = "有车:" + item.isvalue.ToString(); menqian12.Foreground = new SolidColorBrush(Colors.Red); } else { menqian12.Text = "无"; menqian12.Foreground = new SolidColorBrush(Colors.Green); } // 获取当前时间 DateTime currentTime = DateTime.Now; // 将查询到的时间字符串转换为 DateTime 对象 if (DateTime.TryParse(item.last_update_time, out DateTime lastUpdateTime)) { // 计算时间差 TimeSpan timeDifference = currentTime - lastUpdateTime; daojishi12.Text = timeDifference.TotalMinutes.ToString("F2"); if (timeDifference.TotalMinutes > menqian) { if (xuanze12.IsChecked == true) { serialHelper.ComOn(); serialHelper.redLightOn(); serialHelper.buzzerOn(); serialHelper.ComOff(); MessageBox.Show("烘房12门前小车数量值保持超过" + menqian + "分钟请查看!!!"); bianhao12.Background = new SolidColorBrush(Colors.Wheat); } } else { bianhao12.Background = new SolidColorBrush(Colors.White); } } else { // 如果解析失败,处理异常情况 Console.WriteLine("Failed to parse last_update_time"); } } else { if (item.isvalue.ToString() == "5") { zhuangtai12.Text = "自动"; zhuangtai12.Foreground = new SolidColorBrush(Colors.Green); } else { zhuangtai12.Text = "手动或异常"; zhuangtai12.Foreground = new SolidColorBrush(Colors.Red); } } } else if (item.device_code == "H11") { if (item.property == "Intheoven") { shuliang11.Text = item.isvalue; } else if (item.property == "dollyNumber") { if (item.isvalue.ToString() != "0") { menqian11.Text = "有车:" + item.isvalue.ToString(); menqian11.Foreground = new SolidColorBrush(Colors.Red); } else { menqian11.Text = "无"; menqian11.Foreground = new SolidColorBrush(Colors.Green); } // 获取当前时间 DateTime currentTime = DateTime.Now; // 将查询到的时间字符串转换为 DateTime 对象 if (DateTime.TryParse(item.last_update_time, out DateTime lastUpdateTime)) { // 计算时间差 TimeSpan timeDifference = currentTime - lastUpdateTime; daojishi11.Text = timeDifference.TotalMinutes.ToString("F2"); if (timeDifference.TotalMinutes > menqian) { if (xuanze11.IsChecked == true) { serialHelper.ComOn(); serialHelper.redLightOn(); serialHelper.buzzerOn(); serialHelper.ComOff(); MessageBox.Show("烘房11门前小车数量值保持超过" + menqian + "分钟请查看!!!"); bianhao11.Background = new SolidColorBrush(Colors.Wheat); } } else { bianhao11.Background = new SolidColorBrush(Colors.White); } } else { // 如果解析失败,处理异常情况 Console.WriteLine("Failed to parse last_update_time"); } } else { if (item.isvalue.ToString() == "5") { zhuangtai11.Text = "自动"; zhuangtai11.Foreground = new SolidColorBrush(Colors.Green); } else { zhuangtai11.Text = "手动或异常"; zhuangtai11.Foreground = new SolidColorBrush(Colors.Red); } } } else if (item.device_code == "H10") { if (item.property == "Intheoven") { shuliang10.Text = item.isvalue; } else if (item.property == "dollyNumber") { if (item.isvalue.ToString() != "0") { menqian10.Text = "有车:" + item.isvalue.ToString(); menqian10.Foreground = new SolidColorBrush(Colors.Red); } else { menqian10.Text = "无"; menqian10.Foreground = new SolidColorBrush(Colors.Green); } // 获取当前时间 DateTime currentTime = DateTime.Now; // 将查询到的时间字符串转换为 DateTime 对象 if (DateTime.TryParse(item.last_update_time, out DateTime lastUpdateTime)) { // 计算时间差 TimeSpan timeDifference = currentTime - lastUpdateTime; daojishi10.Text = timeDifference.TotalMinutes.ToString("F2"); if (timeDifference.TotalMinutes > menqian) { if (xuanze10.IsChecked == true) { serialHelper.ComOn(); serialHelper.redLightOn(); serialHelper.buzzerOn(); serialHelper.ComOff(); MessageBox.Show("烘房10门前小车数量值保持超过" + menqian + "分钟请查看!!!"); bianhao10.Background = new SolidColorBrush(Colors.Wheat); } } else { bianhao10.Background = new SolidColorBrush(Colors.White); } } else { // 如果解析失败,处理异常情况 Console.WriteLine("Failed to parse last_update_time"); } } else { if (item.isvalue.ToString() == "5") { zhuangtai10.Text = "自动"; zhuangtai10.Foreground = new SolidColorBrush(Colors.Green); } else { zhuangtai10.Text = "手动或异常"; zhuangtai10.Foreground = new SolidColorBrush(Colors.Red); } } } else if (item.device_code == "H61") { if (item.property == "Intheoven") { shuliang61.Text = item.isvalue; } else if (item.property == "dollyNumber") { if (item.isvalue.ToString() != "0") { menqian61.Text = "有车:" + item.isvalue.ToString(); menqian61.Foreground = new SolidColorBrush(Colors.Red); } else { menqian61.Text = "无"; menqian61.Foreground = new SolidColorBrush(Colors.Green); } // 获取当前时间 DateTime currentTime = DateTime.Now; // 将查询到的时间字符串转换为 DateTime 对象 if (DateTime.TryParse(item.last_update_time, out DateTime lastUpdateTime)) { // 计算时间差 TimeSpan timeDifference = currentTime - lastUpdateTime; daojishi61.Text = timeDifference.TotalMinutes.ToString("F2"); if (timeDifference.TotalMinutes > menqian) { if (xuanze61.IsChecked == true) { serialHelper.ComOn(); serialHelper.redLightOn(); serialHelper.buzzerOn(); serialHelper.ComOff(); MessageBox.Show("烘房61门前小车数量值保持超过" + menqian + "分钟请查看!!!"); bianhao61.Background = new SolidColorBrush(Colors.Wheat); } } else { bianhao61.Background = new SolidColorBrush(Colors.White); } } else { // 如果解析失败,处理异常情况 Console.WriteLine("Failed to parse last_update_time"); } } else { if (item.isvalue.ToString() == "5") { zhuangtai61.Text = "自动"; zhuangtai61.Foreground = new SolidColorBrush(Colors.Green); } else { zhuangtai61.Text = "手动或异常"; zhuangtai61.Foreground = new SolidColorBrush(Colors.Red); } } } else if (item.device_code == "H62") { if (item.property == "Intheoven") { shuliang62.Text = item.isvalue; } else if (item.property == "dollyNumber") { if (item.isvalue.ToString() != "0") { menqian62.Text = "有车:" + item.isvalue.ToString(); menqian62.Foreground = new SolidColorBrush(Colors.Red); } else { menqian62.Text = "无"; menqian62.Foreground = new SolidColorBrush(Colors.Green); } // 获取当前时间 DateTime currentTime = DateTime.Now; // 将查询到的时间字符串转换为 DateTime 对象 if (DateTime.TryParse(item.last_update_time, out DateTime lastUpdateTime)) { // 计算时间差 TimeSpan timeDifference = currentTime - lastUpdateTime; daojishi62.Text = timeDifference.TotalMinutes.ToString("F2"); if (timeDifference.TotalMinutes > menqian) { if (xuanze62.IsChecked == true) { serialHelper.ComOn(); serialHelper.redLightOn(); serialHelper.buzzerOn(); serialHelper.ComOff(); MessageBox.Show("烘房62门前小车数量值保持超过" + menqian + "分钟请查看!!!"); bianhao62.Background = new SolidColorBrush(Colors.Wheat); } } else { bianhao62.Background = new SolidColorBrush(Colors.White); } } else { // 如果解析失败,处理异常情况 Console.WriteLine("Failed to parse last_update_time"); } } else { if (item.isvalue.ToString() == "5") { zhuangtai62.Text = "自动"; zhuangtai62.Foreground = new SolidColorBrush(Colors.Green); } else { zhuangtai62.Text = "手动或异常"; zhuangtai62.Foreground = new SolidColorBrush(Colors.Red); } } } else if (item.device_code == "H63") { if (item.property == "Intheoven") { shuliang63.Text = item.isvalue; } else if (item.property == "dollyNumber") { if (item.isvalue.ToString() != "0") { menqian63.Text = "有车:" + item.isvalue.ToString(); menqian63.Foreground = new SolidColorBrush(Colors.Red); } else { menqian63.Text = "无"; menqian63.Foreground = new SolidColorBrush(Colors.Green); } // 获取当前时间 DateTime currentTime = DateTime.Now; // 将查询到的时间字符串转换为 DateTime 对象 if (DateTime.TryParse(item.last_update_time, out DateTime lastUpdateTime)) { // 计算时间差 TimeSpan timeDifference = currentTime - lastUpdateTime; daojishi63.Text = timeDifference.TotalMinutes.ToString("F2"); if (timeDifference.TotalMinutes > menqian) { if (xuanze63.IsChecked == true) { serialHelper.ComOn(); serialHelper.redLightOn(); serialHelper.buzzerOn(); serialHelper.ComOff(); MessageBox.Show("烘房63门前小车数量值保持超过" + menqian + "分钟请查看!!!"); bianhao63.Background = new SolidColorBrush(Colors.Wheat); } } else { bianhao63.Background = new SolidColorBrush(Colors.White); } } else { // 如果解析失败,处理异常情况 Console.WriteLine("Failed to parse last_update_time"); } } else { if (item.isvalue.ToString() == "5") { zhuangtai63.Text = "自动"; zhuangtai63.Foreground = new SolidColorBrush(Colors.Green); } else { zhuangtai63.Text = "手动或异常"; zhuangtai63.Foreground = new SolidColorBrush(Colors.Red); } } } else if (item.device_code == "H9") { if (item.property == "Intheoven") { shuliang9.Text = item.isvalue; } else if (item.property == "dollyNumber") { if (item.isvalue.ToString() != "0") { menqian9.Text = "有车:" + item.isvalue.ToString(); menqian9.Foreground = new SolidColorBrush(Colors.Red); } else { menqian9.Text = "无"; menqian9.Foreground = new SolidColorBrush(Colors.Green); } // 获取当前时间 DateTime currentTime = DateTime.Now; // 将查询到的时间字符串转换为 DateTime 对象 if (DateTime.TryParse(item.last_update_time, out DateTime lastUpdateTime)) { // 计算时间差 TimeSpan timeDifference = currentTime - lastUpdateTime; daojishi9.Text = timeDifference.TotalMinutes.ToString("F2"); if (timeDifference.TotalMinutes > menqian) { if (xuanze9.IsChecked == true) { serialHelper.ComOn(); serialHelper.redLightOn(); serialHelper.buzzerOn(); serialHelper.ComOff(); MessageBox.Show("烘房9门前小车数量值保持超过" + menqian + "分钟请查看!!!"); bianhao9.Background = new SolidColorBrush(Colors.Wheat); } } else { bianhao10.Background = new SolidColorBrush(Colors.White); } } else { // 如果解析失败,处理异常情况 Console.WriteLine("Failed to parse last_update_time"); } } else { if (item.isvalue.ToString() == "5") { zhuangtai9.Text = "自动"; zhuangtai9.Foreground = new SolidColorBrush(Colors.Green); } else { zhuangtai9.Text = "手动或异常"; zhuangtai9.Foreground = new SolidColorBrush(Colors.Red); } } } else if (item.device_code == "H8") { if (item.property == "Intheoven") { shuliang8.Text = item.isvalue; } else if (item.property == "dollyNumber") { if (item.isvalue.ToString() != "0") { menqian8.Text = "有车:" + item.isvalue.ToString(); menqian8.Foreground = new SolidColorBrush(Colors.Red); } else { menqian8.Text = "无"; menqian8.Foreground = new SolidColorBrush(Colors.Green); } // 获取当前时间 DateTime currentTime = DateTime.Now; // 将查询到的时间字符串转换为 DateTime 对象 if (DateTime.TryParse(item.last_update_time, out DateTime lastUpdateTime)) { // 计算时间差 TimeSpan timeDifference = currentTime - lastUpdateTime; daojishi8.Text = timeDifference.TotalMinutes.ToString("F2"); if (timeDifference.TotalMinutes > menqian) { if (xuanze8.IsChecked == true) { serialHelper.ComOn(); serialHelper.redLightOn(); serialHelper.buzzerOn(); serialHelper.ComOff(); MessageBox.Show("烘房8门前小车数量值保持超过" + menqian + "分钟请查看!!!"); bianhao8.Background = new SolidColorBrush(Colors.Wheat); } } else { bianhao8.Background = new SolidColorBrush(Colors.White); } } else { // 如果解析失败,处理异常情况 Console.WriteLine("Failed to parse last_update_time"); } } else { if (item.isvalue.ToString() == "5") { zhuangtai8.Text = "自动"; zhuangtai8.Foreground = new SolidColorBrush(Colors.Green); } else { zhuangtai8.Text = "手动或异常"; zhuangtai8.Foreground = new SolidColorBrush(Colors.Red); } } } else if (item.device_code == "H7") { if (item.property == "Intheoven") { shuliang7.Text = item.isvalue; } else if (item.property == "dollyNumber") { if (item.isvalue.ToString() != "0") { menqian7.Text = "有车:" + item.isvalue.ToString(); menqian7.Foreground = new SolidColorBrush(Colors.Red); } else { menqian7.Text = "无"; menqian7.Foreground = new SolidColorBrush(Colors.Green); } // 获取当前时间 DateTime currentTime = DateTime.Now; // 将查询到的时间字符串转换为 DateTime 对象 if (DateTime.TryParse(item.last_update_time, out DateTime lastUpdateTime)) { // 计算时间差 TimeSpan timeDifference = currentTime - lastUpdateTime; daojishi7.Text = timeDifference.TotalMinutes.ToString("F2"); if (timeDifference.TotalMinutes > menqian) { if (xuanze7.IsChecked == true) { serialHelper.ComOn(); serialHelper.redLightOn(); serialHelper.buzzerOn(); serialHelper.ComOff(); MessageBox.Show("烘房7门前小车数量值保持超过" + menqian + "分钟请查看!!!"); bianhao7.Background = new SolidColorBrush(Colors.Wheat); } } else { bianhao7.Background = new SolidColorBrush(Colors.White); } } else { // 如果解析失败,处理异常情况 Console.WriteLine("Failed to parse last_update_time"); } } else { if (item.isvalue.ToString() == "5") { zhuangtai7.Text = "自动"; zhuangtai7.Foreground = new SolidColorBrush(Colors.Green); } else { zhuangtai7.Text = "手动或异常"; zhuangtai7.Foreground = new SolidColorBrush(Colors.Red); } } } else if (item.device_code == "H6") { if (item.property == "Intheoven") { shuliang6.Text = item.isvalue; } else if (item.property == "dollyNumber") { if (item.isvalue.ToString() != "0") { menqian6.Text = "有车:" + item.isvalue.ToString(); menqian6.Foreground = new SolidColorBrush(Colors.Red); } else { menqian6.Text = "无"; menqian6.Foreground = new SolidColorBrush(Colors.Green); } // 获取当前时间 DateTime currentTime = DateTime.Now; // 将查询到的时间字符串转换为 DateTime 对象 if (DateTime.TryParse(item.last_update_time, out DateTime lastUpdateTime)) { // 计算时间差 TimeSpan timeDifference = currentTime - lastUpdateTime; daojishi6.Text = timeDifference.TotalMinutes.ToString("F2"); if (timeDifference.TotalMinutes > menqian) { if (xuanze6.IsChecked == true) { serialHelper.ComOn(); serialHelper.redLightOn(); serialHelper.buzzerOn(); serialHelper.ComOff(); MessageBox.Show("烘房6门前小车数量值保持超过" + menqian + "分钟请查看!!!"); bianhao6.Background = new SolidColorBrush(Colors.Wheat); } } else { bianhao6.Background = new SolidColorBrush(Colors.White); } } else { // 如果解析失败,处理异常情况 Console.WriteLine("Failed to parse last_update_time"); } } else { if (item.isvalue.ToString() == "5") { zhuangtai6.Text = "自动"; zhuangtai6.Foreground = new SolidColorBrush(Colors.Green); } else { zhuangtai6.Text = "手动或异常"; zhuangtai6.Foreground = new SolidColorBrush(Colors.Red); } } } else if (item.device_code == "H5") { if (item.property == "Intheoven") { shuliang5.Text = item.isvalue; } else if (item.property == "dollyNumber") { if (item.isvalue.ToString() != "0") { menqian5.Text = "有车:" + item.isvalue.ToString(); menqian5.Foreground = new SolidColorBrush(Colors.Red); } else { menqian5.Text = "无"; menqian5.Foreground = new SolidColorBrush(Colors.Green); } // 获取当前时间 DateTime currentTime = DateTime.Now; // 将查询到的时间字符串转换为 DateTime 对象 if (DateTime.TryParse(item.last_update_time, out DateTime lastUpdateTime)) { // 计算时间差 TimeSpan timeDifference = currentTime - lastUpdateTime; daojishi5.Text = timeDifference.TotalMinutes.ToString("F2"); if (timeDifference.TotalMinutes > menqian) { if (xuanze5.IsChecked == true) { serialHelper.ComOn(); serialHelper.redLightOn(); serialHelper.buzzerOn(); serialHelper.ComOff(); MessageBox.Show("烘房5门前小车数量值保持超过" + menqian + "分钟请查看!!!"); bianhao5.Background = new SolidColorBrush(Colors.Wheat); } } else { bianhao5.Background = new SolidColorBrush(Colors.White); } } else { // 如果解析失败,处理异常情况 Console.WriteLine("Failed to parse last_update_time"); } } else { if (item.isvalue.ToString() == "5") { zhuangtai5.Text = "自动"; zhuangtai5.Foreground = new SolidColorBrush(Colors.Green); } else { zhuangtai5.Text = "手动或异常"; zhuangtai5.Foreground = new SolidColorBrush(Colors.Red); } } } else if (item.device_code == "H4") { if (item.property == "Intheoven") { shuliang4.Text = item.isvalue; } else if (item.property == "dollyNumber") { if (item.isvalue.ToString() != "0") { menqian4.Text = "有车:" + item.isvalue.ToString(); menqian4.Foreground = new SolidColorBrush(Colors.Red); } else { menqian4.Text = "无"; menqian4.Foreground = new SolidColorBrush(Colors.Green); } // 获取当前时间 DateTime currentTime = DateTime.Now; // 将查询到的时间字符串转换为 DateTime 对象 if (DateTime.TryParse(item.last_update_time, out DateTime lastUpdateTime)) { // 计算时间差 TimeSpan timeDifference = currentTime - lastUpdateTime; daojishi4.Text = timeDifference.TotalMinutes.ToString("F2"); if (timeDifference.TotalMinutes > menqian) { if (xuanze4.IsChecked == true) { serialHelper.ComOn(); serialHelper.redLightOn(); serialHelper.buzzerOn(); serialHelper.ComOff(); MessageBox.Show("烘房4门前小车数量值保持超过" + menqian + "分钟请查看!!!"); bianhao4.Background = new SolidColorBrush(Colors.Wheat); } } else { bianhao4.Background = new SolidColorBrush(Colors.White); } } else { // 如果解析失败,处理异常情况 Console.WriteLine("Failed to parse last_update_time"); } } else { if (item.isvalue.ToString() == "5") { zhuangtai4.Text = "自动"; zhuangtai4.Foreground = new SolidColorBrush(Colors.Green); } else { zhuangtai4.Text = "手动或异常"; zhuangtai4.Foreground = new SolidColorBrush(Colors.Red); } } } else if (item.device_code == "H3") { if (item.property == "Intheoven") { shuliang3.Text = item.isvalue; } else if (item.property == "dollyNumber") { if (item.isvalue.ToString() != "0") { menqian3.Text = "有车:" + item.isvalue.ToString(); menqian3.Foreground = new SolidColorBrush(Colors.Red); } else { menqian3.Text = "无"; menqian3.Foreground = new SolidColorBrush(Colors.Green); } // 获取当前时间 DateTime currentTime = DateTime.Now; // 将查询到的时间字符串转换为 DateTime 对象 if (DateTime.TryParse(item.last_update_time, out DateTime lastUpdateTime)) { // 计算时间差 TimeSpan timeDifference = currentTime - lastUpdateTime; daojishi3.Text = timeDifference.TotalMinutes.ToString("F2"); if (timeDifference.TotalMinutes > menqian) { if (xuanze3.IsChecked == true) { serialHelper.ComOn(); serialHelper.redLightOn(); serialHelper.buzzerOn(); serialHelper.ComOff(); MessageBox.Show("烘房3门前小车数量值保持超过" + menqian + "分钟请查看!!!"); bianhao3.Background = new SolidColorBrush(Colors.Wheat); } } else { bianhao3.Background = new SolidColorBrush(Colors.White); } } else { // 如果解析失败,处理异常情况 Console.WriteLine("Failed to parse last_update_time"); } } else { if (item.isvalue.ToString() == "5") { zhuangtai3.Text = "自动"; zhuangtai3.Foreground = new SolidColorBrush(Colors.Green); } else { zhuangtai3.Text = "手动或异常"; zhuangtai3.Foreground = new SolidColorBrush(Colors.Red); } } } else if (item.device_code == "H2") { if (item.property == "Intheoven") { shuliang2.Text = item.isvalue; } else if (item.property == "dollyNumber") { if (item.isvalue.ToString() != "0") { menqian2.Text = "有车:" + item.isvalue.ToString(); menqian2.Foreground = new SolidColorBrush(Colors.Red); } else { menqian2.Text = "无"; menqian2.Foreground = new SolidColorBrush(Colors.Green); } // 获取当前时间 DateTime currentTime = DateTime.Now; // 将查询到的时间字符串转换为 DateTime 对象 if (DateTime.TryParse(item.last_update_time, out DateTime lastUpdateTime)) { // 计算时间差 TimeSpan timeDifference = currentTime - lastUpdateTime; daojishi2.Text = timeDifference.TotalMinutes.ToString("F2"); if (timeDifference.TotalMinutes > menqian) { if (xuanze2.IsChecked == true) { serialHelper.ComOn(); serialHelper.redLightOn(); serialHelper.buzzerOn(); serialHelper.ComOff(); MessageBox.Show("烘房2门前小车数量值保持超过" + menqian + "分钟请查看!!!"); bianhao2.Background = new SolidColorBrush(Colors.Wheat); } } else { bianhao2.Background = new SolidColorBrush(Colors.White); } } else { // 如果解析失败,处理异常情况 Console.WriteLine("Failed to parse last_update_time"); } } else { if (item.isvalue.ToString() == "5") { zhuangtai2.Text = "自动"; zhuangtai2.Foreground = new SolidColorBrush(Colors.Green); } else { zhuangtai2.Text = "手动或异常"; zhuangtai2.Foreground = new SolidColorBrush(Colors.Red); } } } else if (item.device_code == "H1") { if (item.property == "Intheoven") { shuliang1.Text = item.isvalue; } else if (item.property == "dollyNumber") { if (item.isvalue.ToString() != "0") { menqian1.Text = "有车:" + item.isvalue.ToString(); menqian1.Foreground = new SolidColorBrush(Colors.Red); } else { menqian1.Text = "无"; menqian1.Foreground = new SolidColorBrush(Colors.Green); } // 获取当前时间 DateTime currentTime = DateTime.Now; // 将查询到的时间字符串转换为 DateTime 对象 if (DateTime.TryParse(item.last_update_time, out DateTime lastUpdateTime)) { // 计算时间差 TimeSpan timeDifference = currentTime - lastUpdateTime; daojishi1.Text = timeDifference.TotalMinutes.ToString("F2"); if (timeDifference.TotalMinutes > menqian) { if (xuanze1.IsChecked == true) { serialHelper.ComOn(); serialHelper.redLightOn(); serialHelper.buzzerOn(); serialHelper.ComOff(); MessageBox.Show("烘房1门前小车数量值保持超过" + menqian + "分钟请查看!!!"); bianhao1.Background = new SolidColorBrush(Colors.Wheat); } } else { bianhao1.Background = new SolidColorBrush(Colors.White); } } else { // 如果解析失败,处理异常情况 Console.WriteLine("Failed to parse last_update_time"); } } else { if (item.isvalue.ToString() == "5") { zhuangtai1.Text = "自动"; zhuangtai1.Foreground = new SolidColorBrush(Colors.Green); } else { zhuangtai1.Text = "手动或异常"; zhuangtai1.Foreground = new SolidColorBrush(Colors.Red); } } } } } private void sos_Click(object sender, RoutedEventArgs e) { menqian = Convert.ToInt32(fenzhong.Text); MessageBox.Show("设置成功!当前分钟数为" + menqian); } private void cloce_Click(object sender, RoutedEventArgs e) { serialHelper.ComOn(); serialHelper.redLightOff(); serialHelper.buzzerOff(); serialHelper.ComOff(); } private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { timer.Stop(); } } }