private void MainForm_FormClosed(object sender, FormClosedEventArgs e) { dt_bo01.Dispose(); //断开数据库 SqlAssist.DisConnect(); //如果连接博思则断开 //if (Envior.FIN_READY) FinInvoice.DisConnect(); //关闭关联的打印进程 if (!printprocess.HasExited) { printprocess.Kill(); } //关闭打印服务对象 //if (Envior.prtserv != null) Envior.prtserv.Dispose(); }
static void Main() { try { bool bCreate; System.Threading.Mutex mutex = new System.Threading.Mutex(false, "SINGILE_INSTANCE_MUTEX", out bCreate); if (!bCreate) { MessageBox.Show("程序已经启动!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Application.Exit(); return; } //设置应用程序处理异常方式:ThreadException处理 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); //处理UI线程异常 Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); //处理非UI线程异常 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); #region 应用程序的主入口点 Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); BonusSkins.Register(); SkinManager.EnableFormSkins(); UserLookAndFeel.Default.SetSkinStyle("DevExpress Style"); ///// 连接数据库 ////// SqlAssist.ConnectDb(); ///// 检查版本 /////// //MessageBox.Show(AppInfo.AppVersion,"当前版本"); string curNewestVersion = Tools.getNewVersion(); //MessageBox.Show(curNewestVersion, "服务器版本"); if (string.Compare(curNewestVersion, AppInfo.AppVersion) > 0) { MessageBox.Show("服务器发现更新的版本!系统需要升级", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); Tools.DownloadNew(curNewestVersion); SqlAssist.DisConnect(); //启动升级拷贝 ////// try { Process.Start("Upgrade.exe", curNewestVersion); } catch (Exception e) { Console.WriteLine(e.Message); } Application.Exit(); return; } /// 检查 工作站是否进行登记 Envior.WORKSTATIONID = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath).AppSettings.Settings["workstationID"].Value.ToString(); string hostname = string.Empty; string ipaddress = string.Empty; Tools.GetIpAddress(out hostname, out ipaddress); if (!string.IsNullOrEmpty(Envior.WORKSTATIONID)) { switch (AppAction.WorkStationIsRegistered(Envior.WORKSTATIONID, hostname, ipaddress)) { case 0: //未登记 MessageBox.Show("此工作站尚未登记!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); return; case 2: //主机名不符 MessageBox.Show("此工作站【计算机名称】与登记不符!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); return; case 3: //ip地址不符 MessageBox.Show("此工作站【IP地址】与登记不符!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); return; default: break; } } else { MessageBox.Show("未设置工作站ID!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Stop); Application.Exit(); return; } Application.Run(new MainForm()); #endregion } catch (Exception ex) { string str = GetExceptionMsg(ex, string.Empty); LogUtils.Error(str); MessageBox.Show(str, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }