Beispiel #1
0
        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);
        }
Beispiel #2
0
        private void btnsavedb_Click(object sender, System.EventArgs e)
        {
            if (!DBMaintain.ConvertOldDataFinish)
            {
                EcoMessageBox.ShowError(EcoLanguage.getMsg(LangRes.DB_inSplitMySQLTable, new string[0]));
                return;
            }
            bool   @checked = this.checkBoxUseMySQL.Checked;
            string dbIP     = "127.0.0.1";
            int    port     = 3306;
            string usrnm    = "";
            string psw      = "";
            bool   flag     = false;

            if (@checked && DBUrl.DB_CURRENT_TYPE.ToUpper().Equals("MYSQL"))
            {
                return;
            }
            if (!this.paradbCheck())
            {
                return;
            }
            if (@checked)
            {
                dbIP  = this.tbIP.Text;
                port  = System.Convert.ToInt32(this.textBoxMySQLPort.Text);
                usrnm = this.textBoxMySQLUsername.Text;
                psw   = this.textBoxMySQLPassword.Text;
            }
            if (!DBUrl.DB_CURRENT_TYPE.ToUpper().Equals("MYSQL") && !@checked)
            {
                return;
            }
            if (DBUrl.DB_CURRENT_TYPE.ToUpper().Equals("MYSQL") && @checked)
            {
                return;
            }
            DialogResult dialogResult = EcoMessageBox.ShowWarning(EcoLanguage.getMsg(LangRes.DB_ChangeCrm, new string[0]), MessageBoxButtons.OKCancel);

            if (dialogResult == DialogResult.Cancel)
            {
                return;
            }
            int opt = 2;

            if (!flag)
            {
                long num = DBTools.EvaluateTime();
                if (num > 60L)
                {
                    dbchangeoptDlg dbchangeoptDlg = new dbchangeoptDlg();
                    DialogResult   dialogResult2  = dbchangeoptDlg.ShowDialog();
                    if (dialogResult2 != DialogResult.Yes)
                    {
                        opt = 1;
                    }
                }
            }
            dbchangeDlg dbchangeDlg = new dbchangeDlg(@checked, dbIP, port, usrnm, psw, opt);

            dbchangeDlg.ShowDialog();
            EcoMessageBox.ShowInfo(this, EcoLanguage.getMsg(LangRes.quitEco, new string[0]));
            Program.ExitApp();
        }