|
|
using Module.Plc.ModbusTcp.Tool;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows.Forms;
|
|
|
using MorClient;
|
|
|
using MorClient.UserControls;
|
|
|
using RS.Common;
|
|
|
using Delta.DIAAuto.DIASECSGEM.Equipment;
|
|
|
using WindowsFormsApp1.UserControls.SECS_Clinet;
|
|
|
using MorCliemt.UserControls;
|
|
|
using WindowsFormsApp1.UserControls.SECSClient;
|
|
|
using System.IO;
|
|
|
|
|
|
namespace MorClient
|
|
|
{
|
|
|
internal static class Program
|
|
|
{
|
|
|
static System.Threading.Mutex mutex;
|
|
|
/// <summary>
|
|
|
/// 应用程序的主入口点。
|
|
|
/// </summary>
|
|
|
[STAThread]
|
|
|
static void Main()
|
|
|
{
|
|
|
|
|
|
try
|
|
|
{
|
|
|
/*//设置应用程序处理异常方式:ThreadException处理
|
|
|
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
|
|
|
//处理UI线程异常
|
|
|
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
|
|
|
//处理非UI线程异常
|
|
|
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);*/
|
|
|
|
|
|
//处理未捕获的异常
|
|
|
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
|
|
|
//处理UI线程异常
|
|
|
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
|
|
|
//处理非UI线程异常
|
|
|
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
|
|
|
|
|
|
|
|
|
//获取欲启动进程名
|
|
|
string strProcessName = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
|
|
|
//检查进程是否已经启动,已经启动则显示报错信息退出程序。
|
|
|
if (System.Diagnostics.Process.GetProcessesByName(strProcessName).Length > 1)
|
|
|
{
|
|
|
//程序强制关闭
|
|
|
Environment.Exit(0);
|
|
|
}
|
|
|
|
|
|
if (!HslCommunication.Authorization.SetAuthorizationCode("2c7c6c81-fdc5-4b5a-9e3e-0d8963860a60"))
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
mutex = new System.Threading.Mutex(true, "OnlyRun");
|
|
|
|
|
|
publicProgram.addCleanInfo();
|
|
|
Application.EnableVisualStyles();
|
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
|
|
PlcModbusTool.StartColDataThread();
|
|
|
//PlcModbusTool.StartPipeServer();
|
|
|
new PlcModbusTool().StartColDataThreadArm();
|
|
|
new PlcModbusTool().StartColDataThreadArm2();
|
|
|
// new PlcModbusTool().readModulbus();
|
|
|
|
|
|
#region 实例化需要主框架实例化对象的类
|
|
|
|
|
|
//主框架
|
|
|
FrmMainFrame frmMainFrame = new FrmMainFrame();
|
|
|
PublicPara publicPara = new PublicPara();
|
|
|
//底层操作-右侧按钮
|
|
|
UserControl_SecMenu userControl_SecMenu = new UserControl_SecMenu();
|
|
|
//userControl_SecMenu.Dock = DockStyle.Fill;
|
|
|
//操作左侧界面
|
|
|
//
|
|
|
secsClient secsClient = new secsClient();
|
|
|
|
|
|
DIASecsGemController _gemControler = new DIASecsGemController();
|
|
|
frmMainFrame.GetsecsClient(secsClient);
|
|
|
secsClient.GetDIASecsGemController(_gemControler);
|
|
|
secsClient.LoadMethod();
|
|
|
#endregion 实例化需要主框架实例化对象的类
|
|
|
|
|
|
#region 传递主框架实例化对象
|
|
|
//给FrmMainFrame类传递 实例化对象frmMainFrame
|
|
|
frmMainFrame.GetFrmCeShi(frmMainFrame);
|
|
|
|
|
|
//设置 展示当前所在页面
|
|
|
frmMainFrame.SetNowPage("[操作]", "[主页]");
|
|
|
//公共类中 得到初始化的 主框架对象
|
|
|
publicPara.GetMainFrameObject(frmMainFrame);
|
|
|
//公共类中 得到初始化的 一开始默认的二级按钮对象
|
|
|
publicPara.GetHomepageObject(userControl_SecMenu);
|
|
|
//公共类中 得到一级按钮 当前所在客户端页面
|
|
|
publicPara.GetFristFunctionButtons("[操作]");
|
|
|
//公共类中 得到二级按钮 当前所在客户端页面
|
|
|
publicPara.GetTwoFunctionButtons("[主页]");
|
|
|
|
|
|
//设置 高亮效果
|
|
|
frmMainFrame.SetButtonsLight();
|
|
|
//uiSymbolButton6 SetButtonHighlight
|
|
|
//设置 高亮效果
|
|
|
frmMainFrame.SetButtonHighlight();
|
|
|
|
|
|
#endregion 传递主框架实例化对象
|
|
|
|
|
|
#region 窗体展示内容
|
|
|
//Homepage homepage = new Homepage();
|
|
|
|
|
|
//homepage.Dock = DockStyle.Fill;
|
|
|
////设置窗体中间面板初始展示内容
|
|
|
//frmMainFrame.plMain.Controls.Clear();
|
|
|
//frmMainFrame.plMain.Controls.Add(homepage);
|
|
|
//frmMainFrame.plMain.Show();
|
|
|
////设置窗体右侧 二级功能按钮初始展示内容
|
|
|
//frmMainFrame.panel_SecMenu.Controls.Clear();
|
|
|
//frmMainFrame.panel_SecMenu.Controls.Add(userControl_SecMenu);
|
|
|
|
|
|
//frmMainFrame.panel_SecMenu.Show();
|
|
|
|
|
|
////homepage.DetectionRecipe();
|
|
|
////frmMainFrame.Show();
|
|
|
///
|
|
|
#region 窗体展示内容
|
|
|
//Homepage homepage = new Homepage();
|
|
|
|
|
|
//homepage.Dock = DockStyle.Fill;
|
|
|
//设置窗体中间面板初始展示内容
|
|
|
frmMainFrame.plMain.Controls.Clear();
|
|
|
//frmMainFrame.plMain.Controls.Add(homepage);
|
|
|
frmMainFrame.plMain.Show();
|
|
|
//设置窗体右侧 二级功能按钮初始展示内容
|
|
|
frmMainFrame.panel_SecMenu.Controls.Clear();
|
|
|
frmMainFrame.panel_SecMenu.Controls.Add(userControl_SecMenu);
|
|
|
|
|
|
frmMainFrame.panel_SecMenu.Show();
|
|
|
PubStaticClass.homepageLoad();
|
|
|
//homepage.DetectionRecipe();
|
|
|
//frmMainFrame.ShowDialog();
|
|
|
#endregion 窗体展示内容
|
|
|
|
|
|
#endregion 窗体展示内容
|
|
|
|
|
|
if (mutex.WaitOne(0, false))
|
|
|
{
|
|
|
Application.Run(frmMainFrame);
|
|
|
}
|
|
|
else
|
|
|
Application.Exit();
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
MessageBox.Show("打开异常:" + ex.ToString());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
///这就是我们要在发生未处理异常时处理的方法,我这是写出错详细信息到文本,如出错后弹出一个漂亮的出错提示窗体
|
|
|
///做法很多,可以是把出错详细信息记录到文本、数据库,发送出错邮件到作者信箱或出错后重新初始化等等
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
|
|
|
{
|
|
|
string str = "";
|
|
|
string strDateInfo = "出现应用程序未处理的异常:" + DateTime.Now.ToString() + "\r\n";
|
|
|
Exception error = e.Exception as Exception;
|
|
|
if (error != null)
|
|
|
{
|
|
|
str = string.Format(strDateInfo + "异常类型:{0}\r\n异常消息:{1}\r\n异常信息:{2}\r\n", error.GetType().Name, error.Message, error.StackTrace);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
str = string.Format("应用程序线程错误:{0}", e);
|
|
|
}
|
|
|
writeLog(str);
|
|
|
//frmBug f = new frmBug(str);//友好提示界面
|
|
|
//f.ShowDialog();
|
|
|
MessageBox.Show("发生致命错误,请及时联系作者!", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
}
|
|
|
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
|
|
{
|
|
|
string str = "";
|
|
|
Exception error = e.ExceptionObject as Exception;
|
|
|
string strDateInfo = "出现应用程序未处理的异常:" + DateTime.Now.ToString() + "\r\n";
|
|
|
if (error != null)
|
|
|
{
|
|
|
str = string.Format(strDateInfo + "Application UnhandledException:{0};\n\r堆栈信息:{1}", error.Message, error.StackTrace);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
str = string.Format("Application UnhandledError:{0}", e);
|
|
|
}
|
|
|
writeLog(str);
|
|
|
//frmBug f = new frmBug(str);//友好提示界面
|
|
|
//f.ShowDialog();
|
|
|
MessageBox.Show("发生致命错误,请停止当前操作并及时联系工程师!", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 写文件
|
|
|
/// </summary>
|
|
|
/// <param name="str"></param>
|
|
|
static void writeLog(string str)
|
|
|
{
|
|
|
if (!Directory.Exists("ErrLog"))
|
|
|
{
|
|
|
Directory.CreateDirectory("ErrLog");
|
|
|
}
|
|
|
using (StreamWriter sw = new StreamWriter(@"ErrLog\ErrLog.txt", true))
|
|
|
{
|
|
|
sw.WriteLine(str);
|
|
|
sw.WriteLine("---------------------------------------------------------");
|
|
|
sw.Close();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|