public void LoadIt(string enumKey) { if (this.Full(enumKey) == false) { try { BP.DA.DBAccess.RunSQL("UPDATE Sys_Enum SET Lang='" + Web.WebUser.SysLang + "' WHERE LANG IS NULL "); BP.DA.DBAccess.RunSQL("UPDATE Sys_Enum SET MyPK=EnumKey+'_'+Lang+'_'+cast(IntKey as NVARCHAR )"); //增加数据库类型判断 DBUrl dbUrl = new DBUrl(); if (DBType.MSSQL == dbUrl.DBType) { BP.DA.DBAccess.RunSQL("UPDATE Sys_Enum SET MyPK=EnumKey+'_'+Lang+'_'+cast(IntKey as NVARCHAR )"); } else if (DBType.Oracle == dbUrl.DBType) { BP.DA.DBAccess.RunSQL("UPDATE Sys_Enum SET MyPK = EnumKey || '_' || Lang || '_' || cast(IntKey as VARCHAR(5))"); } else if (DBType.MySQL == dbUrl.DBType) { BP.DA.DBAccess.RunSQL("UPDATE Sys_Enum SET MyPK = CONCAT (EnumKey,'_', Lang,'_',CAST(IntKey AS CHAR(5)))"); } } catch { } try { BP.Sys.XML.EnumInfoXml xml = new BP.Sys.XML.EnumInfoXml(enumKey); this.RegIt(enumKey, xml.Vals); } catch (Exception ex) { throw new Exception("@你没有预制[" + enumKey + "]枚举值。@在修复枚举值出现错误:" + ex.Message); } } }
public registrySettings(int SrvStCode) { this.InitializeComponent(); this.m_oldSrvStCode = SrvStCode; this.tbDBIP.ContextMenuStrip = EcoGlobalVar.nullcontextMenuStrip; this.tbDBPort.ContextMenuStrip = EcoGlobalVar.nullcontextMenuStrip; this.tbDBUsrnm.ContextMenuStrip = EcoGlobalVar.nullcontextMenuStrip; this.tbDBPsw.ContextMenuStrip = EcoGlobalVar.nullcontextMenuStrip; this.tbManagerPort.ContextMenuStrip = EcoGlobalVar.nullcontextMenuStrip; this.tbTrapPort.ContextMenuStrip = EcoGlobalVar.nullcontextMenuStrip; this.tbBillingPort.ContextMenuStrip = EcoGlobalVar.nullcontextMenuStrip; this.tbGatewayPort.ContextMenuStrip = EcoGlobalVar.nullcontextMenuStrip; this.tcLoginSettings.Controls.Clear(); if ((SrvStCode & DebugCenter.ST_fatalMask) != 0) { string text = ""; if (SrvStCode == DebugCenter.ST_SevsPortNA) { this.tcLoginSettings.Controls.Add(this.tpPortsetting); this.lbManagerPort.Visible = true; this.tbManagerPort.Visible = true; this.lbTrapPort.Visible = false; this.tbTrapPort.Visible = false; this.lbBillingPort.Visible = false; this.tbBillingPort.Visible = false; this.lbGatewayPort.Visible = false; this.tbGatewayPort.Visible = false; this.tbManagerPort.Text = ValuePairs.getValuePair("ServicePort"); } DBUrl.initconfig(); if (SrvStCode == DebugCenter.ST_MYSQLCONNECT_ERROR) { text = "MySQL database connection failure (error code: " + SrvStCode.ToString("X4") + "). Please check your settings and try again."; } if (SrvStCode == DebugCenter.ST_MYSQLAUTH_ERROR) { text = "MySQL database authentication failure (error code: " + SrvStCode.ToString("X4") + "). Please check your settings and try again."; } if (SrvStCode == DebugCenter.ST_MYSQLNotExist || SrvStCode == DebugCenter.ST_MYSQLSIDNotMatch || SrvStCode == DebugCenter.ST_MYSQLREPAIR_ERROR) { text = "MySQL database fatal error (error code: " + SrvStCode.ToString("X4") + "). Please try either restore database, or use Access (by uncheck \"Use MySQL database\") instead."; } if (text.Length > 0) { this.tcLoginSettings.Controls.Add(this.tpdatabase); this.lbDBMsg.Text = text; this.checkBoxUseMySQL.Checked = true; this.tbDBIP.Text = "127.0.0.1"; this.tbDBPort.Text = DBUrl.CURRENT_PORT.ToString(); this.tbDBUsrnm.Text = DBUrl.CURRENT_USER_NAME; this.tbDBPsw.Text = DBUrl.CURRENT_PWD; } return; } this.tcLoginSettings.Controls.Add(this.tpPortsetting); this.lbManagerPort.Visible = false; this.tbManagerPort.Visible = false; this.m_pSyspara = new Sys_Para(); if ((SrvStCode & DebugCenter.ST_TrapPortNA) != 0) { this.lbTrapPort.Visible = true; this.tbTrapPort.Visible = true; this.tbTrapPort.Text = System.Convert.ToString(this.m_pSyspara.TrapPort); } else { this.lbTrapPort.Visible = false; this.tbTrapPort.Visible = false; } if ((SrvStCode & DebugCenter.ST_BillingPortNA) != 0) { this.lbBillingPort.Visible = true; this.tbBillingPort.Visible = true; this.tbBillingPort.Text = System.Convert.ToString(Sys_Para.GetBPPort()); } else { this.lbBillingPort.Visible = false; this.tbBillingPort.Visible = false; } if ((SrvStCode & DebugCenter.ST_GateWayPortNA) != 0) { this.lbGatewayPort.Visible = true; this.tbGatewayPort.Visible = true; this.tbGatewayPort.Text = System.Convert.ToString(Sys_Para.GetISGPort()); return; } this.lbGatewayPort.Visible = false; this.tbGatewayPort.Visible = false; }
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); }
private void startDBchange() { try { System.Threading.Thread.Sleep(500); EcoGlobalVar.ECOAppRunStatus = 2; Program.StopService(EcoGlobalVar.gl_ServiceName, 30000); System.Threading.Thread.Sleep(500); if (DBUrl.DB_CURRENT_TYPE.ToUpper().Equals("MYSQL") && this.m_usemysql) { this.m_retv = DBUrl.updatesetting(this.m_port, this.m_usrnm, this.m_psw); } else { this.m_retv = this.updatesetting(this.m_usemysql, this.m_dbIP, this.m_port, this.m_usrnm, this.m_psw); } string valuePair = ValuePairs.getValuePair("Username"); if (!string.IsNullOrEmpty(valuePair)) { LogAPI.writeEventLog("0130020", new string[] { valuePair }); } else { LogAPI.writeEventLog("0130020", new string[0]); } InterProcessShared <System.Collections.Generic.Dictionary <string, string> > .setInterProcessKeyValue("ServiceStDBMaintain", "DBMaintainFinish"); if (!this.b_cancel) { Program.StartService(null); } ControlAccess.ConfigControl config = delegate(Control control, object param) { if (!this.b_cancel) { if (this.m_retv != DebugCenter.ST_Success) { EcoMessageBox.ShowError(this, EcoLanguage.getMsg(LangRes.OPfail, new string[0])); } else { EcoMessageBox.ShowInfo(this, EcoLanguage.getMsg(LangRes.OPsucc, new string[0])); } this.m_normalclose = 2; } base.Close(); }; ControlAccess controlAccess = new ControlAccess(this, config); controlAccess.Access(this, null); } catch (System.Exception) { if (this.m_normalclose == 1) { ControlAccess.ConfigControl config2 = delegate(Control control, object param) { EcoMessageBox.ShowError(this, EcoLanguage.getMsg(LangRes.OPfail, new string[0])); this.m_normalclose = 2; base.Close(); }; ControlAccess controlAccess2 = new ControlAccess(this, config2); controlAccess2.Access(this, null); } } }