20230724_MBJC_upperpc/ViewModels/MainViewModel.cs

148 lines
4.7 KiB
C#
Raw Normal View History

2023-12-18 09:31:28 +00:00
using _20230724_MBJC_upperpc.Common;
using _20230724_MBJC_upperpc.Models;
2023-12-23 03:35:57 +00:00
using _20230724_MBJC_upperpc.Views;
2023-12-18 09:31:28 +00:00
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(); }
}
2024-01-17 01:24:32 +00:00
#region
2023-12-18 09:31:28 +00:00
2024-01-19 05:04:06 +00:00
private int myVar;
2023-12-18 09:31:28 +00:00
2024-01-19 05:04:06 +00:00
public int MyProperty
2024-01-17 01:24:32 +00:00
{
2024-01-19 05:04:06 +00:00
get { return myVar; }
set { myVar = value; }
2024-01-17 01:24:32 +00:00
}
2023-12-23 03:35:57 +00:00
2024-01-19 05:04:06 +00:00
private BeaconViewModel beacon1 = new BeaconViewModel();
2024-01-17 01:24:32 +00:00
2024-01-19 05:04:06 +00:00
public BeaconViewModel Beacon1
2023-12-18 09:31:28 +00:00
{
2024-01-19 05:04:06 +00:00
get { return beacon1; }
set { beacon1 = value; this.DoNotify(); }
2023-12-18 09:31:28 +00:00
}
2024-01-19 05:04:06 +00:00
public BeaconViewModel beacon2 = new BeaconViewModel();
public BeaconViewModel beacon3 = new BeaconViewModel();
public BeaconViewModel beacon4 = new BeaconViewModel();
public BeaconViewModel beacon5 = new BeaconViewModel();
public BeaconViewModel beacon6 = new BeaconViewModel();
public BeaconViewModel beacon7 = new BeaconViewModel() { Model_Visibility = 2 };
public BeaconViewModel beacon8 = new BeaconViewModel() { Model_Visibility = 2 };
2024-01-17 01:24:32 +00:00
#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")),
};
//基阵客户端连接和断开的操作
2024-01-19 05:04:06 +00:00
public CommandBase ConnectCommand { get; set; }
2024-01-17 01:24:32 +00:00
2023-12-18 09:31:28 +00:00
public MainViewModel()
{
2024-01-17 01:24:32 +00:00
//进行与基阵上位机软件连接
Client.DoConnect(socketInfo);
2023-12-18 09:31:28 +00:00
this.NavChangedCommand = new CommandBase();
this.NavChangedCommand.DoExcute = new Action<object>(DoNavChanged);
this.NavChangedCommand.DoCanExcute = new Func<object, bool>((o) => true);
2023-12-23 03:35:57 +00:00
2024-01-17 01:24:32 +00:00
this.ConnectCommand = new CommandBase();
this.ConnectCommand.DoExcute = new Action<object>(DoConnect);
this.ConnectCommand.DoCanExcute = new Func<object, bool>((o) => { return true; });
2023-12-23 03:35:57 +00:00
DoNavChanged("FirstPageView");
2023-12-18 09:31:28 +00:00
}
public void DoNavChanged(object obj)
{
2024-01-19 05:04:06 +00:00
//如果重复点击 就禁止切换
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"))
2023-12-23 03:35:57 +00:00
{
2024-01-19 05:04:06 +00:00
if (Title_Name == "AnchorPointView")
return;
2023-12-23 03:35:57 +00:00
Title_Name = "AnchorPointView";
}
2024-01-19 05:04:06 +00:00
else
{
return;
}
2023-12-18 09:31:28 +00:00
//切换页面之前清理一下内存
tools.ClearMemory(this);
2023-12-23 03:35:57 +00:00
2024-01-17 01:24:32 +00:00
////首先提示加载界面
//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);
2023-12-18 09:31:28 +00:00
ConstructorInfo cti = type.GetConstructor(System.Type.EmptyTypes);
FrameworkElement page = (FrameworkElement)cti.Invoke(null);
this.PageContent = page;
}
2024-01-17 01:24:32 +00:00
public void DoConnect(object o)
{
if ((bool)o)
{
Client = new ClientModel();
Client.DoConnect(socketInfo);
}
else
{
Client.DisConnect();
}
}
2023-12-18 09:31:28 +00:00
}
}