You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

302 lines
10 KiB
C#

using CommonFunc.Tools;
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.Navigation;
using System.Windows.Shapes;
using XGL.Data.DBService;
using XGL.Tools;
using System.Timers;
namespace XGL.Views
{
/// <summary>
/// DryingRoomUC.xaml 的交互逻辑
/// </summary>
public partial class DryingRoomUC : UserControl
{
DringRoomService dringRoomService = new DringRoomService();
Timer timerDeciveState = new Timer();
string deviceCode = "";
public DryingRoomUC()
{
InitializeComponent();
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
timerDeciveState.Interval = Utils.GetAppSetting("GetDeviceStateInterval") == "" ? 15000 : Convert.ToInt32(Utils.GetAppSetting("GetDeviceStateInterval"));
timerDeciveState.Elapsed += TimerDeciveState_Elapsed;
timerDeciveState.Start();
InitComBoboxData();
GetDringRoomData();
GetOutDringRoomData();
GetDeviceInfo();
}
private void GetDeviceInfo()
{
TimerDeciveState_Elapsed(null,null);
}
private void TimerDeciveState_Elapsed(object sender, ElapsedEventArgs e)
{
if (Utils.isAnyBodyPerating) return;
DataTable dt = dringRoomService.GetTemperAndHumilly(deviceCode);
if (dt == null)
{
//使用Dispatcher来在UI线程上更新UI
this.Dispatcher.Invoke(
new Action(() =>
{
lbCurrTemperature.Content = "0";
lbCurrHumilly.Content = "0";
}
),
System.Windows.Threading.DispatcherPriority.Render);
}
else
{
//使用Dispatcher来在UI线程上更新UI
this.Dispatcher.Invoke(
new Action(() =>
{
lbCurrTemperature.Content = dt.Rows[0][0].ToString();
lbCurrHumilly.Content = dt.Rows[1][0].ToString();
}
),
System.Windows.Threading.DispatcherPriority.Render);
}
DataTable dtDringRoomData = dringRoomService.GetDringRoomData(deviceCode, 1);
if (dtDringRoomData != null)
{
//使用Dispatcher来在UI线程上更新UI
this.Dispatcher.Invoke(
new Action(() =>
{
DringRoomListBox.ItemsSource = null;
DringRoomListBox.Items.Clear();
DringRoomListBox.ItemsSource = dtDringRoomData.DefaultView;
}
),
System.Windows.Threading.DispatcherPriority.Render);
}
else
{
//使用Dispatcher来在UI线程上更新UI
this.Dispatcher.Invoke(
new Action(() =>
{
DringRoomListBox.ItemsSource = null;
DringRoomListBox.Items.Clear();
}
),
System.Windows.Threading.DispatcherPriority.Render);
}
DataTable dtDringRoomOuter = dringRoomService.GetDringRoomData(deviceCode, 0);
if (dtDringRoomOuter != null)
{
//使用Dispatcher来在UI线程上更新UI
this.Dispatcher.Invoke(
new Action(() =>
{
DringRoomOuterListBox.ItemsSource = null;
DringRoomOuterListBox.Items.Clear();
DringRoomOuterListBox.ItemsSource = dtDringRoomOuter.DefaultView;
}
),
System.Windows.Threading.DispatcherPriority.Render);
}
else
{
//使用Dispatcher来在UI线程上更新UI
this.Dispatcher.Invoke(
new Action(() =>
{
DringRoomOuterListBox.ItemsSource = null;
DringRoomOuterListBox.Items.Clear();
}
),
System.Windows.Threading.DispatcherPriority.Render);
}
//if (dt.Rows[0][0].ToString() == "1")
//{
// this.Dispatcher.Invoke(
// new Action(() => { LbDeviceState.Background = Brushes.Green; }
// ),
// System.Windows.Threading.DispatcherPriority.Render);
//}
//else
//{
// this.Dispatcher.Invoke(
// new Action(() => { LbDeviceState.Background = Brushes.Red; }
// ),
// System.Windows.Threading.DispatcherPriority.Render);
//}
}
private void GetDringRoomData()
{
//DringRoomListBox.ItemsSource = null;
//DringRoomListBox.Items.Clear();
DataTable dt = dringRoomService.GetDringRoomData(deviceCode, 1);
if (dt == null)
{
DringRoomListBox.ItemsSource = null;
DringRoomListBox.Items.Clear();
return;
}
//int index = 0;
//int i = 0;
//foreach (DataRow item in dt.Rows)
//{
// index = i++;
// string rfid = item["rfid_no"].ToString();
// string workorder_code = item["workorder_code"].ToString();
// string materialCode = item["material_code"].ToString();
// string inTime = item["update_time"].ToString();
// TimeSpan ts;
// ts = DateTime.Now - Convert.ToDateTime(inTime);
// int minuteDiff = Convert.ToInt32(ts.TotalMinutes);
// //string workorder_code = item["workorder_code"].ToString();
// ModuleUC uc = new ModuleUC(index.ToString(), rfid, workorder_code, materialCode, minuteDiff);
// DringRoomListBox.Items.Add(uc);
//}
DringRoomListBox.ItemsSource = null;
DringRoomListBox.Items.Clear();
DringRoomListBox.ItemsSource = dt.DefaultView;
}
private void GetOutDringRoomData()
{
//DringRoomOuterListBox.ItemsSource = null;
//DringRoomOuterListBox.Items.Clear();
DataTable dt = dringRoomService.GetDringRoomData(deviceCode, 0);
if (dt == null)
{
DringRoomOuterListBox.ItemsSource = null;
DringRoomOuterListBox.Items.Clear();
return;
}
//int index = 0;
//int i = 0;
//foreach (DataRow item in dt.Rows)
//{
// index = i++;
// string rfid = item["rfid_no"].ToString();
// string workorder_code = item["workorder_code"].ToString();
// string materialCode = item["material_code"].ToString();
// string inTime = item["update_time"].ToString();
// TimeSpan ts;
// ts = DateTime.Now - Convert.ToDateTime(inTime);
// int minuteDiff = Convert.ToInt32(ts.TotalMinutes);
// //string workorder_code = item["workorder_code"].ToString();
// ModuleUC uc = new ModuleUC(index.ToString(), rfid, workorder_code, materialCode, minuteDiff);
// DringRoomOuterListBox.Items.Add(uc);
//}
DringRoomOuterListBox.ItemsSource = null;
DringRoomOuterListBox.Items.Clear();
DringRoomOuterListBox.ItemsSource = dt.DefaultView;
}
private void InitComBoboxData()
{
DataTable dt = dringRoomService.GetDringRoomInfo(Utils.GetAppSetting("DryingHouseList"));
if (dt == null)
{
CustomMessageBox.Show("没有维护设备信息,请维护设备后重试!", CustomMessageBoxIcon.Warning);
return;
}
List<EquipmentMode> listEquip = Utils.ToDataList<EquipmentMode>(dt);
//comboDryRoomInfo.SelectedValuePath = "quipName";
//comboDryRoomInfo.DisplayMemberPath = "quipCode";
//comboDryRoomInfo.ItemsSource = listEquip;
//绑定
comboDryRoomInfo.ItemsSource = listEquip;
comboDryRoomInfo.SelectedValuePath = "quipCode";
comboDryRoomInfo.DisplayMemberPath = "quipName";
comboDryRoomInfo.SelectedIndex = 0;
}
private void comboDryRoomInfo_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string hfCode = comboDryRoomInfo.SelectedValue.ToString();//.Text;
deviceCode = hfCode;
GetDringRoomData();
GetOutDringRoomData();
GetDeviceInfo();
}
private void btnRefrsh_Click(object sender, RoutedEventArgs e)
{
GetDringRoomData();
GetOutDringRoomData();
}
private void btnCheckLog_Click(object sender, RoutedEventArgs e)
{
ViewLogWin viewLogWin = new ViewLogWin();
viewLogWin.ShowDialog();
}
private void btnViewPlcvalue_Click(object sender, RoutedEventArgs e)
{
ViewPlcInfoWin viewPlcWin = new ViewPlcInfoWin();
viewPlcWin.ShowDialog();
}
private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
ScrollViewer scrollViewer = sender as ScrollViewer;
if (scrollViewer != null)
{
if (e.Delta > 0)
{
scrollViewer.LineUp();
}
else
{
scrollViewer.LineDown();
}
e.Handled = true;
}
}
}
public class EquipmentMode
{
public int type { get; set; }
public string quipCode { get; set; }
public string quipName { get; set; }
}
}