Ejemplo n.º 1
0
        public void LoadInfoFromLocalDb()
        {
            try
            {
                _db.getSqlServerInfo(out _initialConStr, out _bEnableSql);

                checkBoxEnableSQL.Checked = _bEnableSql == 1;

                if (string.IsNullOrEmpty(_initialConStr))
                {
                    return;
                }

                string[] strArray = _initialConStr.Split(';');
                foreach (string str2 in strArray)
                {
                    if (str2.Length == 0)
                    {
                        break;
                    }
                    string strSwitch = str2.Substring(0, str2.IndexOf('=')).ToUpper().Trim();
                    switch (strSwitch)
                    {
                    case "DATA SOURCE":
                        txtServerName.Text = str2.Substring(str2.IndexOf('=') + 1);
                        break;

                    case "INITIAL CATALOG":
                        txtDatabaseName.Text = str2.Substring(str2.IndexOf('=') + 1);
                        break;

                    case "USER ID":
                        txtLogin.Text = str2.Substring(str2.IndexOf('=') + 1);
                        break;

                    case "PASSWORD":
                    {
                        string str3 = UtilSqlServer.DencryptPassword(str2.Substring(str2.IndexOf('=') + 1));
                        txtPassword.Text = str3;
                        break;
                    }
                    }
                }
                CboAuthentication.SelectedIndex = txtLogin.Text.Trim().Length > 0 ? 1 : 0;
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                MessageBox.Show(exception.Message, ResStrings.Str_Key_Not_Found, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
            finally
            {
                CboAuthentication.SelectedIndex = txtLogin.Text.Trim().Length > 0 ? 1 : 0;
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtServerName.Text.Trim().Length == 0)
                {
                    MessageBox.Show(ResStrings.Str_Enter_the_Server_Name, ResStrings.str_Connect_Server, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                }
                else if (txtDatabaseName.Text.Trim().Length == 0)
                {
                    MessageBox.Show(ResStrings.str_Enter_the_Database_Name, ResStrings.str_Connect_Server, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                }
                else if (txtTableName.Text.Trim().Length == 0)
                {
                    MessageBox.Show(ResStrings.str_Enter_the_Table_Name, ResStrings.str_Connect_Server, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                }
                else
                {
                    // string str = null;
                    string str2 = null;
                    string str3 = UtilSqlServer.EncryptPassword(txtPassword.Text);

                    if (CboAuthentication.SelectedIndex == 0)
                    {
                        //str = "Data Source=" + txtServerName.Text.Trim() + ";Initial Catalog=" + txtDatabaseName.Text.Trim() + ";Integrated Security=SSPI";
                        str2 = "Data Source=" + txtServerName.Text.Trim() + ";Initial Catalog=" + txtDatabaseName.Text.Trim() + ";Integrated Security=SSPI;";
                    }
                    else
                    {
                        //str = "Data Source=" + txtServerName.Text.Trim() + ";Initial Catalog=" + txtDatabaseName.Text.Trim() + ";User ID=" + txtLogin.Text.Trim() + ";Password="******"Data Source=" + txtServerName.Text.Trim() + ";Initial Catalog=" + txtDatabaseName.Text.Trim() + ";User ID=" + txtLogin.Text.Trim() + ";Password="******";";
                    }
                    if (_db.AddExportInfo(1, str2, txtTableName.Text.Trim(), Convert.ToInt32(checkBoxEnableSQL.Checked)))
                    {
                        _bChange = true;
                        MessageBox.Show(ResStrings.str_Sql_Connection_Info_Saved, ResStrings.str_Info_SQL_Server, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                    }
                    else
                    {
                        MessageBox.Show(ResStrings.str_Error_While_Saving_Sql_Connection_Info_Saved, ResStrings.str_Info_SQL_Server, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    }
                }
            }
            catch (Exception exp)
            {
                ExceptionMessageBox.Show(exp);
            }
        }