Exemplo n.º 1
0
        public override bool OnSave()
        {
            DBConnection dbCon = null;
            try
            {
                // make new connection object:
                dbCon = new DBConnection();
                if (dbCon.saveConnectionInfo(txeServer.Text, txeDatabase.Text, txeUsername.Text, txePassword.Text, DBConnection.ENCRYPTED))
                {
                    MessageBox.Show(this, "Connection setting has saved successfully. Changes will be applied for the next log on.", "Paradise", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    isNewConnection = true;
                }
                else
                    MessageBox.Show(this, "Connection setting can not saved. Please re-install Paradise if you can.", "Paradise", MessageBoxButtons.OK, MessageBoxIcon.Error);

                btnFWSave.Enabled = false;
                dbCon = null;

                // return Good:
                return true;

            }
            catch(Exception exc)
            {
                MessageBox.Show(exc.Message,"Paradise",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return false;
            }
        }
Exemplo n.º 2
0
        private void SetConnection_Load(object sender, EventArgs e)
        {
            string strConnection = "";
            SqlConnection connection;
            SqlCommand cmd;
            string strCreateUser = "";
            string strAttachDB = "";

            string strServer, strDatabase, strUser, strPassword, strEncrypted;
            DBConnection dbCon = null;
            try
            {
                //Connect to Master Database
                //strConnection = @"Data Source=.\SQLExpress;Initial Catalog=master;User Id=sa;Password=123;";
                // register dll for zk SDK
                if (!System.IO.File.Exists("Paradise.ini"))
                {
                    Process.Start(@"C:\windows\system32\RegiszkDll.bat");
                    strConnection = @"Data Source=.\SQLEXPRESS;Initial Catalog=master;Integrated Security=True";
                    connection = new SqlConnection(strConnection);
                    connection.Open();
                    //Attach Database file
                    cmd = new SqlCommand("if exists (select 1 from sys.databases where Name = 'Att_VTS') EXEC master.dbo.sp_detach_db N'Att_VTS','true'", connection);
                    cmd.ExecuteNonQuery();

                    strAttachDB = @"if not exists (select 1 from sys.databases  where name = 'Att_VTS') CREATE DATABASE [Att_VTS] ON ( FILENAME = N'C:\Windows\Att_VTS.mdf' ),( FILENAME = N'C:\Windows\Att_VTS_log.ldf' ) FOR ATTACH ";
                    cmd = new SqlCommand(strAttachDB, connection);
                    cmd.ExecuteNonQuery();
                    //Create new login name saFree, Pass:LuaThiengFree
                    //Retry to connect new SQL String again
                    strCreateUser = @"if not exists (select 1 from master.dbo.syslogins where name = 'SaFree') CREATE LOGIN saFree WITH PASSWORD=N'LuaThiengFree', DEFAULT_DATABASE=[Att_VTS], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF;";
                    cmd = new SqlCommand(strCreateUser, connection);
                    cmd.ExecuteNonQuery();
                    cmd = new SqlCommand("EXEC master..sp_addsrvrolemember @loginame = N'saFree', @rolename = N'sysadmin'", connection);
                    cmd.ExecuteNonQuery();
                    try
                    {
                        cmd = new SqlCommand(@"xp_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\Microsoft SQL Server\MSSQL.1\MSSQLServer', N'LoginMode', REG_DWORD, 2", connection);
                        cmd.ExecuteNonQuery();
                    }
                    catch { }
                    try
                    {
                        cmd = new SqlCommand(@"xp_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\Microsoft SQL Server\MSSQL.2\MSSQLServer', N'LoginMode', REG_DWORD, 2", connection);
                        cmd.ExecuteNonQuery();
                    }
                    catch { }
                    try
                    {
                        cmd = new SqlCommand(@"xp_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\Microsoft SQL Server\MSSQL.3\MSSQLServer', N'LoginMode', REG_DWORD, 2", connection);
                        cmd.ExecuteNonQuery();
                    }
                    catch { }
                    connection.Close();
                    strServer = @".\SQLEXPRESS";
                    strDatabase = "Att_VTS";
                    strUser = "******";
                    strPassword = "******";
                    strEncrypted = DBConnection.NO_ENCRYPTED;
                    dbCon = new DBConnection();
                    dbCon.saveConnectionInfo(strServer, strDatabase, strUser, strPassword, DBConnection.ENCRYPTED);
                    //Reset computer
                    if (MessageBox.Show("Need restart compurter to complete the First configuration. Do you want to restart your computer?", "Vietinsoft", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                        Process.Start("ShutDown", "/r /t 000");
                    else
                        Application.Exit();
                }
                dbCon = new DBConnection();
                dbCon.getDBConnectionInfo(out strServer, out strDatabase, out strUser, out strPassword, out strEncrypted);
            }
            catch
            {
                strServer = @".\SQLEXPRESS";
                strDatabase = "Att_VTS";
                strUser = "******";
                strPassword = "******";
                strEncrypted = DBConnection.NO_ENCRYPTED;
                dbCon = new DBConnection();
                dbCon.saveConnectionInfo(strServer, strDatabase, strUser, strPassword, DBConnection.ENCRYPTED);
            }

            //			ConnectionString cs = new ConnectionString();
            //			cs.GetConnectParam();
            //			cs.GetParam(out strServer, out strDatabase, out strUser, out strPassword, out strEncrypted);
            //
            txeServer.Text = strServer;
            txeDatabase.Text = strDatabase;
            txeUsername.Text = strUser;
            txePassword.Text = strPassword;
            if (strEncrypted.Trim() == DBConnection.ENCRYPTED)
                chkEncrypt.Checked = true;
            else
                chkEncrypt.Checked = false;

            dbCon = null;
            // load language interface
            if ((strServer != null) && (!string.Empty.Equals(strServer)))
            {
                Control.ControlCollection ctrls = this.Controls;
                UIMessage.LoadLableName(ref ctrls);
            }
        }