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.

215 lines
7.1 KiB
C#

2 years ago
using CentralControl.DBDAO;
using CommonFunc;
using CommonFunc.Tools;
using System;
2 years ago
using System.Collections.Generic;
2 years ago
using System.ComponentModel;
2 years ago
using System.Data;
2 years ago
using System.Linq;
2 years ago
using System.Net.NetworkInformation;
2 years ago
using System.Text;
using System.Threading.Tasks;
2 years ago
using System.Timers;
2 years ago
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;
2 years ago
using XGL.Views;
2 years ago
namespace XGL.FormItem
{
/// <summary>
/// Main.xaml 的交互逻辑
/// </summary>
public partial class Main : Window
{
public static Main main;
Frame frame1 = new Frame() { Content = new Views.LanJu_Index()};
2 years ago
Timer timer = new Timer();
2 years ago
2 years ago
2 years ago
System.Threading.Timer Time { get; set; }
private string _PingSeconds;
public string PingSeconds
{
get { return _PingSeconds; }
set
{
OnPropertyChanged("PingSeconds");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string info)
{
var handler = PropertyChanged;
handler?.Invoke(this, new PropertyChangedEventArgs(info));
}
2 years ago
public enum WindowID
{
frame1
}
public Main()
{
InitializeComponent();
main = this;
2 years ago
//WindowChange(WindowID.frame1);
2 years ago
CommonFunc.Common.ReadConfig();//读取配置文件
2 years ago
timer.Interval = 1000;
timer.Elapsed += Timer_Elapsed;
timer.Start();
2 years ago
2 years ago
//实例化绑定对象
Binding textBinding = new Binding();
//设置要绑定源
textBinding.Source = this;//绑定MainWindow类
//设置要绑定属性
textBinding.Path = new PropertyPath("PingSeconds");//绑定MainWindow类下的TxtValue属性。
textBinding.Mode = BindingMode.TwoWay;//绑定模式双向绑定
//设置绑定到要绑定的控件
this.myTb.SetBinding(TextBlock.TextProperty, textBinding);
2 years ago
InitPage();
2 years ago
GetServiceDelay(Utils.GetServerIP());
2 years ago
}
private void InitPage()
2 years ago
{
2 years ago
if (Utils.GetAppSetting("ClientMode").Equals("0"))
{
2 years ago
LanJu_Prepare prepare = new LanJu_Prepare();
2 years ago
this.Index.Content = prepare;
}
else if (Utils.GetAppSetting("ClientMode").Equals("1"))
{
2 years ago
LanJu_Operator op = new LanJu_Operator();
2 years ago
this.Index.Content = op;
}
else
{
2 years ago
DryingRoomUC dryingRoomUC = new DryingRoomUC();
2 years ago
this.Index.Content = dryingRoomUC;
}
2 years ago
}
private void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
this.Dispatcher.Invoke(
new Action(() => { LabDate.Content = DateTime.Now.ToString("yyyy-MM-dd"); LabTime.Content = DateTime.Now.ToString("HH:mm:ss"); }
),
System.Windows.Threading.DispatcherPriority.Render) ;
2 years ago
}
public void WindowChange(WindowID windowID)
{
2 years ago
this.Index.Content = frame1;
2 years ago
}
private void Close(object sender, EventArgs e)
{
System.Environment.Exit(System.Environment.ExitCode);
}
private void btnExit_Click(object sender, RoutedEventArgs e)
{
if (MessageBox.Show("是否确认关闭程序", "提示信息", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.No)
{
}
else
{
System.Environment.Exit(System.Environment.ExitCode);
}
}
2 years ago
private void btnZXH_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.tbOperator.Text = LoginUser.UserName;
this.tbDevice.Text = Utils.GetAppSetting("DeviceCode");
string sitecode = Utils.GetAppSetting("SiteCode");
DBService userDbWareHouse = new DBService();
DataTable dt = userDbWareHouse.GetFactoryInfo(sitecode);
string name = dt == null?"": dt.Rows[0][0].ToString();
this.tbFactory.Text = name;
}
2 years ago
public void GetServiceDelay(string serviceIp)
{
Ping p1 = new Ping();
Time = new System.Threading.Timer((s) =>
{
try
{
p1.SendAsyncCancel();
p1.SendPingAsync(serviceIp, 2000).ContinueWith(result =>
{
try
{
string time = result?.Result?.RoundtripTime.ToString();
Application.Current.Dispatcher.Invoke(() =>
{
if (!string.IsNullOrEmpty(time) && time != "0")
{
_PingSeconds = time;
PingSeconds = time;
this.btnText.Text = time;
}
else
{
_PingSeconds = time;
PingSeconds = "--";
this.btnText.Text = "--";
}
int second = 0;
if (int.TryParse(time, out second))
{
if (second > 0 && second <= 20)
{
this.btnText.Foreground = Brushes.Green;
//System.Windows.Media.ColorConverter.ConvertFromString("#FF4FEE4F");
}
else if (second > 20 && second <= 40)
{
this.btnText.Foreground = Brushes.Orange;
}
else
{
this.btnText.Foreground = Brushes.Red;
}
}
else { this.btnText.Foreground = Brushes.Red; }
});
}
catch (Exception ex)
{
result?.Dispose();
}
});
}
catch (Exception)
{
p1.SendAsyncCancel();
}
}, 1, 0, 2000);
}
2 years ago
}
}