You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
180 lines
7.8 KiB
180 lines
7.8 KiB
using LiveChartsCore.Geo;
|
|
using SkiaSharp;
|
|
using SunlightCentralizedControlManagement_SCCM_.UserClass;
|
|
using SunlightCentralizedControlManagement_SCCM_.UserControls;
|
|
using SunlightCentralizedControlManagement_SCCM_.ViewModel;
|
|
using SunlightCentralizedControlManagement_SCCM_.ConvertMoels;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.NetworkInformation;
|
|
using System.Net.Sockets;
|
|
using System.Numerics;
|
|
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 static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper;
|
|
using System.Windows.Threading;
|
|
using Newtonsoft.Json.Linq;
|
|
using System.Xml.Linq;
|
|
using static System.Windows.Forms.AxHost;
|
|
|
|
namespace SunlightCentralizedControlManagement_SCCM_.View
|
|
{
|
|
/// <summary>
|
|
/// MachinesSet.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class DispenseView : UserControl
|
|
{
|
|
public DispenseView()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private readonly UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "SCCM.ini");
|
|
DataTable DispenseMac = new DataTable();
|
|
UserControls.DispenseMacInfo[] dispenseMacInfo = new UserControls.DispenseMacInfo[99]; //定义总览信息卡
|
|
//private string SYS_machines = null;
|
|
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
DispenseMac = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet("select * from MachinesDispense ", null).Tables[0];//缓存
|
|
/// <summary>
|
|
/// 生成总览信息卡
|
|
/// </summary>
|
|
for (int i = 0; i < DispenseMac.Rows.Count; i++)
|
|
{
|
|
string x = DispenseMac.AsEnumerable().Select(row => row.Field<string>("State")).ElementAt(i);
|
|
bool y = DispenseMac.AsEnumerable().Select(row => row.Field<bool>("LOCK")).ElementAt(i);
|
|
|
|
dispenseMacInfo[i] = new UserControls.DispenseMacInfo();
|
|
dispenseMacInfo[i].Margin = new Thickness(5, 5, 0, 5);
|
|
dispenseMacInfo[i].Width = 400;
|
|
dispenseMacInfo[i].Height = 600;
|
|
dispenseMacInfo[i].IP.Text = DispenseMac.AsEnumerable().Select(row => row.Field<string>("IP")).ElementAt(i);
|
|
dispenseMacInfo[i].USER.Text = DispenseMac.AsEnumerable().Select(row => row.Field<string>("User")).ElementAt(i);
|
|
dispenseMacInfo[i].PORT.Text = DispenseMac.AsEnumerable().Select(row => row.Field<int>("PORT")).ElementAt(i).ToString();
|
|
dispenseMacInfo[i].PASSWD.Text = DispenseMac.AsEnumerable().Select(row => row.Field<string>("Password")).ElementAt(i);
|
|
dispenseMacInfo[i].type_.Text = DispenseMac.AsEnumerable().Select(row => row.Field<int>("type")).ElementAt(i).ToString();
|
|
dispenseMacInfo[i].type_N.Text = StatenClassConvert.Convert(DispenseMac.AsEnumerable().Select(row => row.Field<int>("type")).ElementAt(i));
|
|
dispenseMacInfo[i].mac.Text = DispenseMac.AsEnumerable().Select(row => row.Field<string>("name")).ElementAt(i);
|
|
dispenseMacInfo[i].macg.Text = DispenseMac.AsEnumerable().Select(row => row.Field<string>("Groups")).ElementAt(i);
|
|
dispenseMacInfo[i].state.Text = StatenClassConvert.Convert(x);
|
|
if (x == "899")
|
|
{
|
|
dispenseMacInfo[i].state.Background = new SolidColorBrush(Color.FromRgb(255, 0, 0));
|
|
}
|
|
else
|
|
{
|
|
dispenseMacInfo[i].state.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
|
|
}
|
|
dispenseMacInfo[i].WorkingStatus.Text = DispenseMac.AsEnumerable().Select(row => row.Field<string>("WorkingStatus")).ElementAt(i);
|
|
if (y)
|
|
{
|
|
dispenseMacInfo[i].mlock.Visibility = Visibility.Visible;
|
|
}
|
|
else
|
|
{
|
|
dispenseMacInfo[i].mlock.Visibility = Visibility.Collapsed;
|
|
}
|
|
|
|
//dispenseMacInfo[i].name.Text = Selet_Machines(MainWindowViewModel.Machines, "name", i).ToString();
|
|
// dispenseMacInfo[i].IMAGE = ;
|
|
|
|
MemoryStream memoryStream = new MemoryStream(DispenseMac.AsEnumerable().Select(row => row.Field<byte[]>("DATA")).ElementAt(i));
|
|
//数据流生成图片显示
|
|
BitmapImage bitmapImage = new BitmapImage();
|
|
bitmapImage.BeginInit();
|
|
bitmapImage.StreamSource = memoryStream;
|
|
bitmapImage.EndInit();
|
|
dispenseMacInfo[i].IMAGE.Source = bitmapImage;
|
|
DispenseMacView.Children.Add(dispenseMacInfo[i]);
|
|
|
|
CountDown();
|
|
}
|
|
}
|
|
|
|
private void CountDown()
|
|
{
|
|
DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每10秒调用一次Tick
|
|
{
|
|
Interval = TimeSpan.FromSeconds(10)//秒
|
|
};
|
|
timer1s.Tick += Tick_Event_1S;
|
|
timer1s.Start();
|
|
}//时间周期初始化
|
|
async void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S
|
|
{
|
|
for (int i = 0; i < DispenseMac.Rows.Count; i++)
|
|
{
|
|
if (await PingTest(dispenseMacInfo[i].IP.Text))
|
|
{
|
|
DataRow drEmployee = DispenseMac.Select("IP='" + dispenseMacInfo[i].IP.Text + "'").First();
|
|
drEmployee.BeginEdit();
|
|
drEmployee["State"] = "802";
|
|
drEmployee.EndEdit();
|
|
drEmployee.AcceptChanges();
|
|
drEmployee.ClearErrors();
|
|
}
|
|
|
|
string x = DispenseMac.AsEnumerable().Select(row => row.Field<string>("State")).ElementAt(i);
|
|
bool y = DispenseMac.AsEnumerable().Select(row => row.Field<bool>("LOCK")).ElementAt(i);
|
|
|
|
dispenseMacInfo[i].state.Text = StatenClassConvert.Convert(x);
|
|
dispenseMacInfo[i].WorkingStatus.Text = DispenseMac.AsEnumerable().Select(row => row.Field<string>("WorkingStatus")).ElementAt(i);
|
|
if (x == "899")
|
|
{
|
|
dispenseMacInfo[i].state.Background = new SolidColorBrush(Color.FromRgb(255, 0, 0));
|
|
dispenseMacInfo[i].Disconnect.Visibility = Visibility.Visible;
|
|
}
|
|
else
|
|
{
|
|
dispenseMacInfo[i].state.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
|
|
dispenseMacInfo[i].Disconnect.Visibility = Visibility.Collapsed;
|
|
}
|
|
if (y)
|
|
{
|
|
dispenseMacInfo[i].mlock.Visibility = Visibility.Visible;
|
|
}
|
|
else
|
|
{
|
|
dispenseMacInfo[i].mlock.Visibility = Visibility.Collapsed;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private async Task<bool> PingTest(string ip)
|
|
{
|
|
bool result = false;
|
|
Ping pingSender = new Ping();
|
|
|
|
try
|
|
{
|
|
PingReply reply = await pingSender.SendPingAsync(ip, 3000);
|
|
|
|
if (reply.Status == IPStatus.Success)
|
|
{
|
|
result = true;
|
|
}
|
|
}
|
|
catch (PingException )
|
|
{
|
|
result = false;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
}
|
|
}
|
|
|