private void btnsaveDB_Click(object sender, System.EventArgs e) { if (!this.DBparaCheck()) { return; } if (!this.checkBoxUseMySQL.Checked) { DialogResult dialogResult = EcoMessageBox.ShowWarning(EcoLanguage.getMsg(LangRes.DB_ChangeCrm, new string[0]), MessageBoxButtons.OKCancel); if (dialogResult == DialogResult.Cancel) { return; } AccessDBUpdate.InitAccessDataDB(); DBUtil.ChangeDBSetting2Access(); base.DialogResult = DialogResult.OK; return; } else { string text = this.tbDBIP.Text; int num = System.Convert.ToInt32(this.tbDBPort.Text); string text2 = this.tbDBUsrnm.Text; string text3 = this.tbDBPsw.Text; string[] param = new string[] { text, this.tbDBPort.Text, text2, text3 }; progressPopup progressPopup = new progressPopup("Information", 1, EcoLanguage.getMsg(LangRes.PopProgressMsg_Checkdbconnect, new string[0]), null, new progressPopup.ProcessInThread(this.dbCheckParameter), param, 0); progressPopup.ShowDialog(); object return_V = progressPopup.Return_V; int? num2 = return_V as int?; if (!num2.HasValue) { num2 = new int?(DebugCenter.ST_Unknown); } if (num2 == DebugCenter.ST_Success) { DBUtil.ChangeDBSetting2MySQL(text, num, text2, text3, false); base.DialogResult = DialogResult.OK; return; } if (num2 == DebugCenter.ST_MYSQLCONNECT_ERROR || num2 == DebugCenter.ST_MYSQLAUTH_ERROR || num2 == DebugCenter.ST_Unknown) { EcoMessageBox.ShowError(this, EcoLanguage.getMsg(LangRes.DB_Connectfail, new string[0])); return; } DialogResult dialogResult2 = EcoMessageBox.ShowWarning(EcoLanguage.getMsg(LangRes.DBinitcrm_Master, new string[0]), MessageBoxButtons.OKCancel); if (dialogResult2 == DialogResult.Cancel) { return; } string dbname = ""; int num3 = DBMaintain.InitMySQLDatabase4Master(text, num, text2, text3, ref dbname); if (num3 > 0) { num3 = DBUtil.ChangeDBSetting2MySQL(dbname, text, num, text2, text3); if (num3 == 1) { num3 = DebugCenter.ST_Success; } } if (num3 == DebugCenter.ST_Success) { base.DialogResult = DialogResult.OK; return; } EcoMessageBox.ShowError(this, EcoLanguage.getMsg(LangRes.OPfail, new string[0])); return; } }
private int updatesetting(bool b_mysqlenable, string str_dbip, int i_port, string str_usr, string str_pwd) { this.setbar(1); string arg_11_0 = System.AppDomain.CurrentDomain.BaseDirectory; if (!b_mysqlenable) { this.setbar(1); AccessDBUpdate.showOnDBChg = new AccessDBUpdate.Delegateshowbar(this.setbar2); if (this.m_opt == 2) { ControlAccess.ConfigControl config = delegate(Control control, object param) { dbchangeDlg dbchangeDlg = control as dbchangeDlg; dbchangeDlg.butCancel.Enabled = true; }; ControlAccess controlAccess = new ControlAccess(this, config); controlAccess.Access(this, null); this.b_timer_start = true; AccessDBUpdate.InitAccessDataDB(); ExpiryCheck.SyncExpiredDate(); DebugCenter.GetInstance().appendToFile("DBChange History MySQL->Access start..."); System.DateTime now = System.DateTime.Now; int num = AccessDBUpdate.ExportDataDB2Access(); System.DateTime now2 = System.DateTime.Now; System.TimeSpan timeSpan = now2 - now; DebugCenter.GetInstance().appendToFile("DBChange History MySQL->Access spend:" + timeSpan.TotalMilliseconds); this.b_timer_start = false; try { this.setbarTimer.Stop(); this.setbarTimer.Dispose(); } catch { } config = delegate(Control control, object param) { dbchangeDlg dbchangeDlg = control as dbchangeDlg; dbchangeDlg.butCancel.Enabled = false; }; controlAccess = new ControlAccess(this, config); controlAccess.Access(this, null); if (num < 0) { return(-4); } } else { AccessDBUpdate.InitAccessDataDB(); if (DBUrl.DB_CURRENT_TYPE.ToUpper().Equals("MYSQL")) { DBTools.DropMySQLDatabase(DBUrl.DB_CURRENT_NAME, DBUrl.CURRENT_HOST_PATH, DBUrl.CURRENT_PORT, DBUrl.CURRENT_USER_NAME, DBUrl.CURRENT_PWD); } } string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.AppDomain.CurrentDomain.BaseDirectory + "sysdb.mdb;Jet OLEDB:Database Password=^tenec0Sensor"; OleDbCommand oleDbCommand = new OleDbCommand(); using (OleDbConnection oleDbConnection = new OleDbConnection(connectionString)) { try { oleDbConnection.Open(); oleDbCommand.Connection = oleDbConnection; oleDbCommand.CommandType = CommandType.Text; oleDbCommand.CommandText = "update dbsource set db_type='ACCESS',db_name='datadb',host_path='datadb.mdb',port= 0,user_name = 'root',pwd='root' where active_flag = 2 "; int num2 = oleDbCommand.ExecuteNonQuery(); if (num2 < 0) { int result = -5; return(result); } } catch (System.Exception) { int result = -5; return(result); } finally { oleDbCommand.Dispose(); } } DBUrl.initconfig(); this.setbar(100); return(DebugCenter.ST_Success); } int num3 = DBTools.InitMySQLDatabase("127.0.0.1", i_port, str_usr, str_pwd); if (num3 < 0) { return(-2); } if (this.m_opt == 2) { ControlAccess.ConfigControl config2 = delegate(Control control, object param) { dbchangeDlg dbchangeDlg = control as dbchangeDlg; dbchangeDlg.butCancel.Enabled = true; }; ControlAccess controlAccess2 = new ControlAccess(this, config2); controlAccess2.Access(this, null); this.b_timer_start = true; ExpiryCheck.SyncExpiredDate(); DebugCenter.GetInstance().appendToFile("DBChange History Access->MySQL start..."); System.DateTime now3 = System.DateTime.Now; int num4 = AccessDBUpdate.ExportDataDB2MySQL("eco", "127.0.0.1", i_port, str_usr, str_pwd); System.DateTime now4 = System.DateTime.Now; System.TimeSpan timeSpan2 = now4 - now3; DebugCenter.GetInstance().appendToFile("DBChange History Access->MySQL spend:" + timeSpan2.TotalMilliseconds); this.b_timer_start = false; try { this.setbarTimer.Stop(); this.setbarTimer.Dispose(); } catch { } config2 = delegate(Control control, object param) { dbchangeDlg dbchangeDlg = control as dbchangeDlg; dbchangeDlg.butCancel.Enabled = false; }; controlAccess2 = new ControlAccess(this, config2); controlAccess2.Access(this, null); if (num4 < 0) { return(-4); } } string connectionString2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.AppDomain.CurrentDomain.BaseDirectory + "sysdb.mdb;Jet OLEDB:Database Password=^tenec0Sensor"; OleDbCommand oleDbCommand2 = new OleDbCommand(); using (OleDbConnection oleDbConnection2 = new OleDbConnection(connectionString2)) { try { oleDbConnection2.Open(); oleDbCommand2.Connection = oleDbConnection2; oleDbCommand2.CommandType = CommandType.Text; oleDbCommand2.CommandText = string.Concat(new object[] { "update dbsource set db_type='MYSQL',db_name='eco',host_path='127.0.0.1',port= ", i_port, ",user_name = '", str_usr, "',pwd='", str_pwd, "' where active_flag = 2 " }); int num5 = oleDbCommand2.ExecuteNonQuery(); if (num5 < 0) { int result = -5; return(result); } } catch (System.Exception) { int result = -5; return(result); } finally { oleDbCommand2.Dispose(); } } DBUrl.initconfig(); this.setbar(100); return(DebugCenter.ST_Success); }