Browse Source

vnc功能实现

master
sc 7 months ago
parent
commit
2cf6b0ab6a
  1. 3
      ConvertMoels/StatenClassConvert.cs
  2. 3
      ConvertMoels/StatenConvert.cs
  3. 2
      EX/VNC.xaml
  4. 48
      EX/VNC.xaml.cs
  5. 27
      Properties/Resources.Designer.cs
  6. 9
      Properties/Resources.en-US.resx
  7. 9
      Properties/Resources.resx
  8. 9
      Properties/Resources.zh-CN.resx
  9. 9
      Properties/Resources.zh-TW.resx
  10. 12
      UserControls/DispenseMacInfo.xaml
  11. 94
      View/DispenseView.xaml.cs

3
ConvertMoels/StatenClassConvert.cs

@ -37,6 +37,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.ConvertMoels
else if (i == "801") Staten = Properties.Resources.Implementation;//连接成功
else if (i == "802") Staten = Properties.Resources.Online;//在线
else if (i == "899") Staten = Properties.Resources.CloseTheConnection;//关闭连接
else if (i == "1") Staten = Properties.Resources.dye;//染料
else if (i == "2") Staten = Properties.Resources.chemicals;//助剂
else if (i == "3") Staten = Properties.Resources.powder;//粉体
else Staten = "null";
return Staten;

3
ConvertMoels/StatenConvert.cs

@ -38,6 +38,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.ConvertMoels
else if (i == "801") Staten = Properties.Resources.Implementation;//连接成功
else if (i == "801") Staten = Properties.Resources.Online;//在线
else if (i == "899") Staten = Properties.Resources.CloseTheConnection;//关闭连接
else if (i == "1") Staten = Properties.Resources.dye;//染料
else if (i == "2") Staten = Properties.Resources.chemicals;//助剂
else if (i == "3") Staten = Properties.Resources.powder;//粉体
else Staten = "";
return Staten;

2
EX/VNC.xaml

@ -8,7 +8,7 @@
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns:rdp="clr-namespace:VncSharpWpf;assembly=VncSharpWpf"
mc:Ignorable="d" Loaded="Window_Loaded"
Title="VNC" Height="450" Width="800">
Title="VNC" Height="1140" Width="1920">
<Grid Margin="0,0,0,0">
<Button x:Name="Save" Content="{x:Static lang:Resources.Cancel}" HorizontalAlignment="Right" Height="35" Margin="450,0,50,10" VerticalAlignment="Bottom" Width="80" Click="Save_Click"/>
<TextBlock x:Name="log" VerticalAlignment="Bottom" Text="LINK-------" Margin="0,0,0,10" HorizontalAlignment="Left" Width="600" Height="35" FontSize="24" FontWeight="Bold" FontStyle="Italic" />

48
EX/VNC.xaml.cs

@ -15,6 +15,8 @@ using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Net.NetworkInformation;
using VncSharpWpf;
using System.Net.Sockets;
using SunlightCentralizedControlManagement_SCCM_.UserClass;
namespace SunlightCentralizedControlManagement_SCCM_.EX
@ -30,28 +32,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.EX
public VNC()
{
InitializeComponent();
// vnc.Cursor = Cursors;
// vnc.MouseMove += Vnc_MouseMove;
// vnc.MouseDown += Vnc_MouseDown ;
// vnc.MouseUp += Vnc_MouseUp;
// vnc.MouseLeave += Vnc_MouseLeave;
// vnc.MouseWheel += Vnc_MouseWheel;
// vnc.PreviewKeyDown += Vnc_PreviewKeyDown;
// rdp.ConnectComplete += new ConnectCompleteHandler(ConnectCompleteEventHandler);
// rdp.ConnectionLost += new EventHandler(ConnectionLostEventHandler);
// rdp.StoppedListen += new EventHandler(ConnectionLostEventHandler);
rdp.SetScalingMode(false);//自动缩放全屏
}
InitializeComponent();
}
private void Save_Click(object sender, RoutedEventArgs e)
{
@ -67,26 +49,33 @@ namespace SunlightCentralizedControlManagement_SCCM_.EX
}
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
{
if (await PingTest(host))
{
if (!rdp.IsConnected)
{
log.Text = host + " OK";
try
{
rdp.VncPort = port;
rdp.Passwd = password;
rdp.Connect(host, true, true);
rdp.Connect(host, false, false);
//rdp.SetScalingMode(false);//自动缩放全屏
// rdp.SetInputMode(false);//可交互
}
catch (Exception ex)
{
LogGing.ERRDATA(ex);
}
}
}
}
private async Task<bool> PingTest(string ip)
{
bool result = false;
@ -99,18 +88,11 @@ namespace SunlightCentralizedControlManagement_SCCM_.EX
if (reply.Status == IPStatus.Success)
{
result = true;
log.Text = ip + " Connected";
}
else
{
log.Text = ip + " Timeout";
}
}
catch (PingException e)
catch (PingException)
{
result = false;
log.Text = ip + " Not Connected";
}
return result;
}

27
Properties/Resources.Designer.cs

@ -276,6 +276,15 @@ namespace SunlightCentralizedControlManagement_SCCM_.Properties {
}
}
/// <summary>
/// 查找类似 chemicals 的本地化字符串。
/// </summary>
public static string chemicals {
get {
return ResourceManager.GetString("chemicals", resourceCulture);
}
}
/// <summary>
/// 查找类似 Client 的本地化字符串。
/// </summary>
@ -744,6 +753,15 @@ namespace SunlightCentralizedControlManagement_SCCM_.Properties {
}
}
/// <summary>
/// 查找类似 dye 的本地化字符串。
/// </summary>
public static string dye {
get {
return ResourceManager.GetString("dye", resourceCulture);
}
}
/// <summary>
/// 查找类似 DyeingMachine 的本地化字符串。
/// </summary>
@ -1779,6 +1797,15 @@ namespace SunlightCentralizedControlManagement_SCCM_.Properties {
}
}
/// <summary>
/// 查找类似 powder 的本地化字符串。
/// </summary>
public static string powder {
get {
return ResourceManager.GetString("powder", resourceCulture);
}
}
/// <summary>
/// 查找类似 PrepareMedications 的本地化字符串。
/// </summary>

9
Properties/Resources.en-US.resx

@ -1038,4 +1038,13 @@
<data name="Not_M" xml:space="preserve">
<value>Machine does not exist</value>
</data>
<data name="dye" xml:space="preserve">
<value>Dye</value>
</data>
<data name="chemicals" xml:space="preserve">
<value>Chemicals</value>
</data>
<data name="powder" xml:space="preserve">
<value>Powder</value>
</data>
</root>

9
Properties/Resources.resx

@ -1038,4 +1038,13 @@
<data name="Not_M" xml:space="preserve">
<value>NOT Machine</value>
</data>
<data name="dye" xml:space="preserve">
<value>dye</value>
</data>
<data name="chemicals" xml:space="preserve">
<value>chemicals</value>
</data>
<data name="powder" xml:space="preserve">
<value>powder</value>
</data>
</root>

9
Properties/Resources.zh-CN.resx

@ -1038,4 +1038,13 @@
<data name="Not_M" xml:space="preserve">
<value>机台不存在</value>
</data>
<data name="dye" xml:space="preserve">
<value>染料</value>
</data>
<data name="chemicals" xml:space="preserve">
<value>助剂</value>
</data>
<data name="powder" xml:space="preserve">
<value>粉体</value>
</data>
</root>

9
Properties/Resources.zh-TW.resx

@ -1038,4 +1038,13 @@
<data name="Not_M" xml:space="preserve">
<value>機台不存在</value>
</data>
<data name="dye" xml:space="preserve">
<value />
</data>
<data name="chemicals" xml:space="preserve">
<value />
</data>
<data name="powder" xml:space="preserve">
<value />
</data>
</root>

12
UserControls/DispenseMacInfo.xaml

@ -4,9 +4,10 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SunlightCentralizedControlManagement_SCCM_.UserControls"
xmlns:lang="clr-namespace:SunlightCentralizedControlManagement_SCCM_.Properties"
xmlns:viewmodel="clr-namespace:SunlightCentralizedControlManagement_SCCM_.ViewModel"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:lang="clr-namespace:SunlightCentralizedControlManagement_SCCM_.Properties"
xmlns:viewmodel="clr-namespace:SunlightCentralizedControlManagement_SCCM_.ViewModel"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:ConvertMoels="clr-namespace:SunlightCentralizedControlManagement_SCCM_.ConvertMoels"
mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="400" Background="#FF828282">
<Grid Margin="5,5,5,5" Background="White" >
@ -22,13 +23,13 @@
<TextBlock x:Name="mac" TextWrapping="Wrap" Text="------" FontSize="16" />
</Border>
<Border BorderBrush="#FFE0E0E0" BorderThickness="1" Height="30" VerticalAlignment="Top" Margin="150,0,0,0" HorizontalAlignment="Right" Width="80">
<TextBlock x:Name="macg" TextWrapping="Wrap" Text="------" FontSize="16" />
<TextBlock x:Name="macg" TextWrapping="Wrap" Text="------" FontSize="16" />
</Border>
<Border BorderBrush="#FFE0E0E0" BorderThickness="1" Height="30" VerticalAlignment="Top" Margin="150,30,80,0">
<TextBlock x:Name="state" TextWrapping="Wrap" Text="------" FontSize="16" />
</Border>
<Border BorderBrush="#FFE0E0E0" BorderThickness="1" Height="30" VerticalAlignment="Top" Margin="150,30,0,0" HorizontalAlignment="Right" Width="80">
<TextBlock x:Name="type_" TextWrapping="Wrap" Text="------" FontSize="16" />
<TextBlock x:Name="type_N" TextWrapping="Wrap" Text="-------" FontSize="16" />
</Border>
<Border BorderBrush="#FFE0E0E0" BorderThickness="1" Height="30" VerticalAlignment="Top" Margin="150,60,0,0">
<TextBlock x:Name="WorkingStatus" TextWrapping="Wrap" Text="------" FontSize="16" />
@ -44,5 +45,6 @@
<TextBlock x:Name="PORT" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="{x:Null}" />
<TextBlock x:Name="USER" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="{x:Null}" />
<TextBlock x:Name="PASSWD" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="{x:Null}" />
<TextBlock x:Name="type_" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="{x:Null}" />
</Grid>
</UserControl>

94
View/DispenseView.xaml.cs

@ -26,6 +26,10 @@ 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
{
@ -36,13 +40,13 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
{
public DispenseView()
{
InitializeComponent();
InitializeComponent();
}
private SQLiteHelper SQLiteHelpers = null; //定义数据库
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SCCM.db"; //数据库路径
private readonly UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "SCCM.ini");
DataTable DispenseMac = new DataTable();
DataTable DispenseMac = new DataTable();
UserControls.DispenseMacInfo[] dispenseMacInfo = new UserControls.DispenseMacInfo[99]; //定义总览信息卡
//private string SYS_machines = null;
private void UserControl_Loaded(object sender, RoutedEventArgs e)
@ -67,7 +71,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
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_.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);
@ -89,21 +94,90 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
dispenseMacInfo[i].mlock.Visibility = Visibility.Collapsed;
}
//dispenseMacInfo[i].name.Text = Selet_Machines(MainWindowViewModel.Machines, "name", i).ToString();
// dispenseMacInfo[i].IMAGE = ;
//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.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));
}
else
{
dispenseMacInfo[i].state.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
}
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;
}
}
}

Loading…
Cancel
Save