void ApplicationCloseDoEvent() { if (ComWithSqlServer != null) { FileService.SaveUserConfig(ComWithSqlServer); } FileService.SaveApplicationConfig(ToolStripMenuItemAuto.Checked); notifyIcon1.Visible = false; #region 释放所有资源 if (ComWithSqlServer != null) { ComWithSqlServer?.CloseDatabase(); ComWithSqlServer = null; } if (UpLoadThread != null) { UpLoadThread.Abort(); UpLoadThread = null; } if (InitThread != null) { InitThread.Abort(); InitThread = null; } #endregion }
public static void SaveUserConfig(ComWithSql pComWithSql) { string path = Application.StartupPath; string savePath = "C:\\Program Files\\dugu\\SmartHeatStation"; //try //{ if (Directory.Exists(savePath) == false) { Directory.CreateDirectory(savePath); } FileStream fs = new FileStream(savePath + "\\user.uni", FileMode.Create); BinaryWriter w = new BinaryWriter(fs); w.Write(pComWithSql.IsConnect); w.Write(pComWithSql.ServerName); w.Write(pComWithSql.DatabaseName); w.Write(pComWithSql.UidName); w.Write(pComWithSql.PwdName); w.Flush(); w.Close(); fs.Close(); //} //catch (Exception es) //{ // throw (es); //} }
public static void ReadUserConfig(ComWithSql pComWithSql) { string path = Application.StartupPath; string savePath = "C:\\Program Files\\dugu\\SmartHeatStation"; try { if (Directory.Exists(savePath) == false) { Directory.CreateDirectory(savePath); } FileStream fs = new FileStream(savePath + "\\user.uni", FileMode.Open); using (BinaryReader r = new BinaryReader(fs)) { pComWithSql.IsConnect = r.ReadBoolean(); pComWithSql.ServerName = r.ReadString(); pComWithSql.DatabaseName = r.ReadString(); pComWithSql.UidName = r.ReadString(); pComWithSql.PwdName = r.ReadString(); } fs.Close(); } catch (Exception es) { } }
public FormMain() { InitializeComponent(); this.Size = NormalSize; ComWithSqlServer = new ComWithSql(); ToolStripMenuItemAuto.Checked = FileService.ReadApplicationConfig(); FileService.ReadUserConfig(ComWithSqlServer); isConnect = ComWithSqlServer.IsConnect; labelServerName.Text = ComWithSqlServer.ServerName; labelDataBaseName.Text = ComWithSqlServer.DatabaseName; labelUidName.Text = ComWithSqlServer.UidName; labelPwdName.Text = ComWithSqlServer.PwdName; }
protected override void OnShown(EventArgs e) { base.OnShown(e); ComWithSqlServer = new ComWithSql(); if (ComWithSqlServer.OpenDatabase() == true) { MessageBox.Show("连接数据库成功!!"); GatherDatas = new List <GatherData>(); StationCodes = new List <StationCode>(); GatherErrors = new List <GatherError>(); //for (int i = 0; i < 50 - 7; ++i) //{ // GatherDatas.Add(new GatherData()); // StationCodes.Add(new StationCode()); // GatherErrors.Add(new GatherError()); //} timerGetDataFormDb.Enabled = true; } }
public void Form_Main_FormClosing(object sender, FormClosingEventArgs e) { if (ComWithSqlServer != null) { ComWithSqlServer?.CloseDatabase(); ComWithSqlServer = null; } if (UpLoadThread != null) { UpLoadThread.Abort(); UpLoadThread = null; } if (master != null) { master.Dispose(); master = null; } //FileSave.ClosingSaveAppInfo(demarcate, flowMeterStandard, flowMeterWork); }