添加项目文件。
This commit is contained in:
140
SamplePreSystemApp/App.xaml.cs
Normal file
140
SamplePreSystemApp/App.xaml.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
using MaterialDesignColors;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Models;
|
||||
using Models.Const;
|
||||
using SamplePre.Common.Helper;
|
||||
using SamplePre.Communication;
|
||||
using SamplePre.ProcessBll.BLL;
|
||||
using SamplePre.UIWpf;
|
||||
using SamplePreSystem.UI;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace SamplePreSystemApp
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
|
||||
|
||||
base.OnStartup(e);
|
||||
|
||||
//Window1 frm = new Window1();
|
||||
//frm.ShowDialog();
|
||||
//return;
|
||||
|
||||
// 1. 禁止关闭第一个窗口就退出
|
||||
ShutdownMode = ShutdownMode.OnExplicitShutdown;
|
||||
|
||||
|
||||
SetSkinColor();
|
||||
|
||||
///初始化系统数据
|
||||
InitSystemData();
|
||||
|
||||
LoginWindow loginWindow = new LoginWindow();
|
||||
if (loginWindow.ShowDialog() != true)
|
||||
{
|
||||
//关闭应用
|
||||
Application.Current.Shutdown();
|
||||
return;
|
||||
}
|
||||
|
||||
loginWindow.Close();
|
||||
|
||||
AppMainView mainWindow;
|
||||
|
||||
|
||||
|
||||
///初始plc连接信息
|
||||
initPLC();
|
||||
|
||||
|
||||
|
||||
|
||||
mainWindow = new AppMainView();
|
||||
mainWindow.ShowDialog();
|
||||
|
||||
//关闭应用
|
||||
Application.Current.Shutdown();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void InitSystemData()
|
||||
{
|
||||
|
||||
// 获取XML配置文件路径
|
||||
string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemConfig.xml");
|
||||
// 反序列化为强类型对象
|
||||
SystemConst.SysConfigInfo = XmlSerializerHelper.DeserializeFromXml<SysConfigData>(configPath);
|
||||
|
||||
|
||||
SystemBll systemBll = new SystemBll();
|
||||
|
||||
//初始化字典数据
|
||||
SystemConst.dictDatas = systemBll.QueryDictData();
|
||||
}
|
||||
|
||||
public void initPLC()
|
||||
{
|
||||
//设置plc连接方式
|
||||
//SystemConst.ProtocolType = CommProtocolType.ModbusTcp;
|
||||
SystemConst.ProtocolType = CommProtocolType.S7;
|
||||
|
||||
|
||||
//初始化PLC
|
||||
var item = SystemConst.dictDatas.FirstOrDefault(p => p.id == "2");//主plc配置信息
|
||||
if (item != null)
|
||||
{
|
||||
if (SystemConst.ProtocolType == CommProtocolType.S7)
|
||||
{
|
||||
string connParam = item.data_value;//"192.168.10.2:0:1";
|
||||
SystemConst.MasterPLC = CommunicationFactory.CreateCommunication(CommProtocolType.S7, connParam);
|
||||
|
||||
}
|
||||
else if (SystemConst.ProtocolType == CommProtocolType.ModbusTcp)
|
||||
{
|
||||
string connParam = item.data_value;//"192.168.10.2:0:1";
|
||||
connParam = "127.0.0.1:502";
|
||||
SystemConst.MasterPLC = CommunicationFactory.CreateCommunication(CommProtocolType.ModbusTcp, connParam);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSkinColor()
|
||||
{
|
||||
// ========== 在这里自定义主题颜色 ==========
|
||||
var paletteHelper = new PaletteHelper();
|
||||
var theme = paletteHelper.GetTheme();
|
||||
|
||||
// 一、设置自定义 主颜色 Primary
|
||||
theme.PrimaryMid = new ColorPair(
|
||||
color: Color.FromRgb(0, 113, 203), // 你想要的RGB颜色
|
||||
foregroundColor: Colors.White); // 文字颜色
|
||||
|
||||
// 二、设置自定义 强调色 Secondary
|
||||
theme.SecondaryMid = new ColorPair(
|
||||
color: Color.FromRgb(33, 150, 243),
|
||||
foregroundColor: Colors.White);
|
||||
|
||||
// 三、设置浅色/深色
|
||||
theme.SetBaseTheme(BaseTheme.Light);
|
||||
|
||||
// 应用主题
|
||||
paletteHelper.SetTheme(theme);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user