211 lines
6.5 KiB
C#
211 lines
6.5 KiB
C#
using _20230724_MBJC_upperpc.Common;
|
|
using _20230724_MBJC_upperpc.Models;
|
|
using _20230724_MBJC_upperpc.Views;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Runtime.Intrinsics.X86;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace _20230724_MBJC_upperpc.ViewModels
|
|
{
|
|
public class MainViewModel : NotifyBase
|
|
{
|
|
|
|
#region 事件
|
|
/// <summary>
|
|
/// 主界面标签切换事件
|
|
/// </summary>
|
|
public CommandBase NavChangedCommand { get; set; }
|
|
string Title_Name = ""; //设置当前显示的标题 1 浮标 2 接驳盒 3 系统控制 4 日志记录
|
|
#endregion
|
|
|
|
private FrameworkElement _pageContent;
|
|
|
|
public FrameworkElement PageContent
|
|
{
|
|
get { return _pageContent; }
|
|
set { _pageContent = value; this.DoNotify(); }
|
|
}
|
|
#region
|
|
private BeaconViewModel beacon1 = new BeaconViewModel();
|
|
|
|
public BeaconViewModel Beacon1
|
|
{
|
|
get { return beacon1; }
|
|
set { beacon1 = value; this.DoNotify(); }
|
|
}
|
|
private BeaconViewModel beacon2 = new BeaconViewModel();
|
|
|
|
public BeaconViewModel Beacon2
|
|
{
|
|
get { return beacon2; }
|
|
set { beacon2 = value; this.DoNotify(); }
|
|
}
|
|
private BeaconViewModel beacon3 = new BeaconViewModel();
|
|
|
|
public BeaconViewModel Beacon3
|
|
{
|
|
get { return beacon3; }
|
|
set { beacon3 = value; this.DoNotify(); }
|
|
}
|
|
private BeaconViewModel beacon4 = new BeaconViewModel();
|
|
|
|
public BeaconViewModel Beacon4
|
|
{
|
|
get { return beacon4; }
|
|
set { beacon4 = value; this.DoNotify(); }
|
|
}
|
|
private BeaconViewModel beacon5 = new BeaconViewModel();
|
|
|
|
public BeaconViewModel Beacon5
|
|
{
|
|
get { return beacon5; }
|
|
set { beacon5 = value; this.DoNotify(); }
|
|
}
|
|
private BeaconViewModel beacon6 = new BeaconViewModel();
|
|
|
|
public BeaconViewModel Beacon6
|
|
{
|
|
get { return beacon6; }
|
|
set { beacon6 = value; this.DoNotify(); }
|
|
}
|
|
|
|
private BeaconViewModel beacon7 = new BeaconViewModel() { Model_Visibility = 2 };
|
|
|
|
public BeaconViewModel Beacon7
|
|
{
|
|
get { return beacon7; }
|
|
set { beacon7 = value; this.DoNotify(); }
|
|
}
|
|
|
|
private BeaconViewModel beacon8 = new BeaconViewModel() { Model_Visibility = 2 };
|
|
|
|
public BeaconViewModel Beacon8
|
|
{
|
|
get { return beacon8; }
|
|
set { beacon8 = value; this.DoNotify(); }
|
|
}
|
|
#endregion
|
|
|
|
|
|
private ClientModel client = new ClientModel();
|
|
/// <summary>
|
|
/// 连接基阵上位机软件的客户端
|
|
/// </summary>
|
|
public ClientModel Client
|
|
{
|
|
get { return client; }
|
|
set { client = value; this.DoNotify(); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 连接基阵上位机软件客户端的ip和端口号
|
|
/// </summary>
|
|
public SocketInfo socketInfo = new SocketInfo()
|
|
{
|
|
IP = tools.GetAppSetting("BasicIP"),
|
|
Port = int.Parse(tools.GetAppSetting("BasicPort")),
|
|
};
|
|
//基阵客户端连接和断开的操作
|
|
public CommandBase ConnectCommand { get; set; }
|
|
|
|
|
|
public MainViewModel()
|
|
{
|
|
//进行与基阵上位机软件连接
|
|
Client.DoConnect(socketInfo);
|
|
|
|
this.NavChangedCommand = new CommandBase();
|
|
this.NavChangedCommand.DoExcute = new Action<object>(DoNavChanged);
|
|
this.NavChangedCommand.DoCanExcute = new Func<object, bool>((o) => true);
|
|
|
|
this.ConnectCommand = new CommandBase();
|
|
this.ConnectCommand.DoExcute = new Action<object>(DoConnect);
|
|
this.ConnectCommand.DoCanExcute = new Func<object, bool>((o) => { return true; });
|
|
|
|
DoNavChanged("FirstPageView");
|
|
}
|
|
|
|
public void DoNavChanged(object obj)
|
|
{
|
|
//如果重复点击 就禁止切换
|
|
if ((string)obj == "FirstPageView" || (string)obj == "BuoyPlatformView")
|
|
{
|
|
if (Title_Name == (string)obj)
|
|
return;
|
|
Title_Name = (string)obj;
|
|
}
|
|
else if (((string)obj).StartsWith("Point") || ((string)obj).StartsWith("Benchmark"))
|
|
{
|
|
if (Title_Name == "AnchorPointView")
|
|
return;
|
|
Title_Name = "AnchorPointView";
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
//切换页面之前清理一下内存
|
|
tools.ClearMemory(this);
|
|
|
|
|
|
////首先提示加载界面
|
|
//Type type = Type.GetType("_20230724_MBJC_upperpc.Views.ProgressView");
|
|
//ConstructorInfo cti = type.GetConstructor(System.Type.EmptyTypes);
|
|
//FrameworkElement page = (FrameworkElement)cti.Invoke(null);
|
|
//this.PageContent = page;
|
|
|
|
Type type = Type.GetType("_20230724_MBJC_upperpc.Views." + Title_Name);
|
|
ConstructorInfo cti = type.GetConstructor(System.Type.EmptyTypes);
|
|
FrameworkElement page = (FrameworkElement)cti.Invoke(null);
|
|
switch (obj.ToString())
|
|
{
|
|
case "Point1":
|
|
page.DataContext = Beacon1;
|
|
break;
|
|
case "Point2":
|
|
page.DataContext = Beacon2;
|
|
break;
|
|
case "Point3":
|
|
page.DataContext = Beacon3;
|
|
break;
|
|
case "Point4":
|
|
page.DataContext = Beacon4;
|
|
break;
|
|
case "Point5":
|
|
page.DataContext = Beacon5;
|
|
break;
|
|
case "Point6":
|
|
page.DataContext = Beacon6;
|
|
break;
|
|
case "Benchmark1":
|
|
page.DataContext = Beacon7;
|
|
break;
|
|
case "Benchmark2":
|
|
page.DataContext = Beacon8;
|
|
break;
|
|
default: break;
|
|
}
|
|
this.PageContent = page;
|
|
}
|
|
|
|
|
|
public void DoConnect(object o)
|
|
{
|
|
if ((bool)o)
|
|
{
|
|
Client = new ClientModel();
|
|
Client.DoConnect(socketInfo);
|
|
}
|
|
else
|
|
{
|
|
Client.DisConnect();
|
|
}
|
|
}
|
|
}
|
|
}
|