261 lines
9.2 KiB
C#
261 lines
9.2 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel;
|
|||
|
using System.Data;
|
|||
|
using System.Drawing;
|
|||
|
using System.IO;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Windows.Forms;
|
|||
|
using WeifenLuo.WinFormsUI.Docking;
|
|||
|
using XKRS.Common.Factory;
|
|||
|
using XKRS.Common.Interface;
|
|||
|
using XKRS.Common.Model.Helper;
|
|||
|
using XKRS.UI.Model.Winform;
|
|||
|
|
|||
|
namespace XKRS.UI.Main
|
|||
|
{
|
|||
|
public partial class MainFrm : Form
|
|||
|
{
|
|||
|
IProcess _process = null;
|
|||
|
System.Diagnostics.Process process = new System.Diagnostics.Process();
|
|||
|
System.Diagnostics.Process processB = new System.Diagnostics.Process();
|
|||
|
System.Diagnostics.Process processC = new System.Diagnostics.Process();
|
|||
|
public MainFrm()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.RealTime;
|
|||
|
var theme = new VS2015LightTheme();
|
|||
|
stsStripLayout.BackColor = ststripDevices.BackColor = Color.FromArgb(64, 64, 64);
|
|||
|
dockPanelMain.Theme = theme;
|
|||
|
VisualStudioToolStripExtender extender = new VisualStudioToolStripExtender();
|
|||
|
extender.SetStyle(menuMain, VisualStudioToolStripExtender.VsVersion.Vs2015, theme);
|
|||
|
InitialMenu()
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
readonly ManualResetEvent _allMenuLoadDoneHandle = new ManualResetEvent(false);
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
private void MainFrm_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
LoadLayoutFromXML(m_deserializeMenuFrm);
|
|||
|
_allMenuLoadDoneHandle.Set();
|
|||
|
|
|||
|
AdvancedPwdFrm.OnLoginOK = OnLoginOK;
|
|||
|
|
|||
|
LoadProcess();
|
|||
|
LoadLayoutFromXML(m_deserializeDeviceRunFrm);
|
|||
|
LoadProcess(false);
|
|||
|
Openexe();
|
|||
|
}
|
|||
|
|
|||
|
private void Openexe()
|
|||
|
{
|
|||
|
string strPathExe = Environment.CurrentDirectory + "\\BDebug2022110201_5" + "\\NJJ-ZK.exe";
|
|||
|
process.StartInfo.WorkingDirectory = Environment.CurrentDirectory + "\\BDebug2022110201_5";
|
|||
|
process.StartInfo.FileName = strPathExe;
|
|||
|
process.StartInfo.Arguments = null;//-s -t 可以用来关机或重启
|
|||
|
process.StartInfo.UseShellExecute = false;
|
|||
|
process.StartInfo.RedirectStandardInput = false;//true
|
|||
|
process.StartInfo.RedirectStandardOutput = false;
|
|||
|
process.StartInfo.RedirectStandardError = false;
|
|||
|
process.StartInfo.CreateNoWindow = false;
|
|||
|
process.Start();//启动
|
|||
|
|
|||
|
string strPathExe2 = Environment.CurrentDirectory + "\\CDebug2022110201_4" + "\\NJJ-ZK.exe";
|
|||
|
processB.StartInfo.WorkingDirectory = Environment.CurrentDirectory + "\\CDebug2022110201_4";
|
|||
|
processB.StartInfo.FileName = strPathExe2;
|
|||
|
processB.StartInfo.Arguments = null;//-s -t 可以用来关机、开机或重启
|
|||
|
processB.StartInfo.UseShellExecute = false;
|
|||
|
processB.StartInfo.RedirectStandardInput = false; //true
|
|||
|
processB.StartInfo.RedirectStandardOutput = false; //true
|
|||
|
processB.StartInfo.RedirectStandardError = false;
|
|||
|
processB.StartInfo.CreateNoWindow = false;
|
|||
|
processB.Start();//启动
|
|||
|
|
|||
|
string strPathExe3 = Environment.CurrentDirectory + "\\ADebug2022110201_2" + "\\NJJ-ZK.exe";
|
|||
|
processC.StartInfo.WorkingDirectory = Environment.CurrentDirectory + "\\ADebug2022110201_2";
|
|||
|
processC.StartInfo.FileName = strPathExe3;
|
|||
|
processC.StartInfo.Arguments = null;//-s -t 可以用来关机、开机或重启
|
|||
|
processC.StartInfo.UseShellExecute = false;
|
|||
|
processC.StartInfo.RedirectStandardInput = false; //true
|
|||
|
processC.StartInfo.RedirectStandardOutput = false; //true
|
|||
|
processC.StartInfo.RedirectStandardError = false;
|
|||
|
processC.StartInfo.CreateNoWindow = false;
|
|||
|
processC.Start();//启动
|
|||
|
}
|
|||
|
private void Killexe()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
process.CloseMainWindow();//通过向进程的主窗口发送关闭消息来关闭拥有用户界面的进程
|
|||
|
process.Close();//释放与此组件关联的所有资源
|
|||
|
processB.CloseMainWindow();//通过向进程的主窗口发送关闭消息来关闭拥有用户界面的进程
|
|||
|
processB.Close();//释放与此组件关联的所有资源
|
|||
|
processC.CloseMainWindow();//通过向进程的主窗口发送关闭消息来关闭拥有用户界面的进程
|
|||
|
processC.Close();//释放与此组件关联的所有资源
|
|||
|
}
|
|||
|
catch
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private List<string> LoadProcessCode()
|
|||
|
{
|
|||
|
var systemProcessCodes = ProcessFactory.GetProcessCodes();
|
|||
|
var avaiableProcessCodes = SettingHelper.GetProcessCodes();
|
|||
|
List<string> pCodes = new List<string>();
|
|||
|
if (avaiableProcessCodes.Count > 0)
|
|||
|
{
|
|||
|
pCodes = avaiableProcessCodes.Intersect(systemProcessCodes).ToList();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
pCodes = systemProcessCodes;
|
|||
|
}
|
|||
|
if (pCodes.Count > 1)
|
|||
|
{
|
|||
|
pCodes.RemoveAll(u => u == "");
|
|||
|
}
|
|||
|
return pCodes;
|
|||
|
}
|
|||
|
private List<string> LoadProductionCode()
|
|||
|
{
|
|||
|
return SettingHelper.GetProductionCodes();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 载入流程
|
|||
|
/// </summary>
|
|||
|
/// <param name="isInitialProcess">是否为初始化流程</param>
|
|||
|
private void LoadProcess(bool isInitialProcess = true)
|
|||
|
{
|
|||
|
if(isInitialProcess)//初次创建流程
|
|||
|
{
|
|||
|
var processCodes = LoadProcessCode();
|
|||
|
var productionCodes = LoadProductionCode();
|
|||
|
_process = ProcessFactory.CreateStationProcess(processCodes[0], productionCodes[0], out string msg);
|
|||
|
if (!string.IsNullOrWhiteSpace(msg))
|
|||
|
{
|
|||
|
_process = null;
|
|||
|
|
|||
|
throw new ProcessException($"创建失败,{msg}", null, ExceptionLevel.Fatal);
|
|||
|
}
|
|||
|
_process.InitialProcess("");
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
#region Login
|
|||
|
bool isLogin = false;
|
|||
|
bool IsLogin
|
|||
|
{
|
|||
|
get => isLogin;
|
|||
|
set
|
|||
|
{
|
|||
|
isLogin = value;
|
|||
|
tsslLoginStatus.Text = isLogin ? "已登录" : "未登录";
|
|||
|
foreach(var dock in dockPanelMain.Contents)
|
|||
|
{
|
|||
|
var menuFrm = dock as MenuFrmBase;
|
|||
|
if (menuFrm != null)
|
|||
|
{
|
|||
|
menuFrm.SetLoginStatus(isLogin);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnLoginOK(bool isLogin)
|
|||
|
{
|
|||
|
IsLogin = isLogin;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
|
|||
|
#region Layout布局
|
|||
|
|
|||
|
string _layoutFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{SettingHelper.GetSelectLayout()}.layout");//路径
|
|||
|
private DeserializeDockContent m_deserializeMenuFrm;
|
|||
|
private DeserializeDockContent m_deserializeDeviceRunFrm;
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
private void LoadLayoutFromXML(DeserializeDockContent dContent)
|
|||
|
{
|
|||
|
if (!File.Exists(_layoutFile))
|
|||
|
return;
|
|||
|
dockPanelMain.SuspendLayout(true);//悬挂式布局
|
|||
|
|
|||
|
CloseAllDeviceFrm();
|
|||
|
while (dockPanelMain.Contents.Count > 0)
|
|||
|
{
|
|||
|
dockPanelMain.Contents[0].DockHandler.DockPanel = null;
|
|||
|
}
|
|||
|
using (FileStream stream = new FileStream(_layoutFile, FileMode.Open))
|
|||
|
{
|
|||
|
dockPanelMain.LoadFromXml(stream, dContent);
|
|||
|
stream.Close();
|
|||
|
}
|
|||
|
dockPanelMain.ResumeLayout(true, true);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region CloseForm
|
|||
|
private void DeviceDisplayFrm_FormClosed(object sender,FormClosedEventArgs e)
|
|||
|
{
|
|||
|
string id = (sender as DeviceRunFrmBase).Device.Id;
|
|||
|
if(showedDeviceUIDict.ContainsKey(id))
|
|||
|
{
|
|||
|
showedDeviceUIDict.Remove(id);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void CloseAllDeviceFrm()
|
|||
|
{
|
|||
|
this.Invoke(new Action(() =>
|
|||
|
{
|
|||
|
this.SuspendLayout();
|
|||
|
dockPanelMain.Contents.Select(u =>
|
|||
|
{
|
|||
|
if (u is DeviceRunFrmBase runFrmBase)
|
|||
|
{
|
|||
|
return runFrmBase;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
}).ToList().ForEach(u =>
|
|||
|
{
|
|||
|
if (u == null)
|
|||
|
return;
|
|||
|
if (_process.DeviceCollection.Any(d => d.Id == u.Device.Id))
|
|||
|
return;
|
|||
|
u.DockPanel = null;
|
|||
|
u.Close();
|
|||
|
});
|
|||
|
this.ResumeLayout();
|
|||
|
}));
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Device Display 设备展示到底部状态栏
|
|||
|
readonly Dictionary<string, DeviceRunFrmBase> showedDeviceUIDict = new Dictionary<string, DeviceRunFrmBase>();
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|