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(); ///// 检查版本 /////// string curNewestVersion = Tools.getNewVersion(); 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; } Application.Run(new MainForm()); #endregion } catch (Exception ex) { string str = GetExceptionMsg(ex, string.Empty); MessageBox.Show(str, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error); LogUtils.Error(str); } }