Esempio n. 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            #region Variables
            this.btnSave.Enabled = false;

            string strConnTest = string.Empty;
            bool   isAuthenticated;
            #endregion

            #region Database Settings
            string FilePath = string.Empty;
            FilePath = Application.StartupPath + System.IO.Path.DirectorySeparatorChar + "DBConfig.HelpMe";
            if (File.Exists(FilePath))
            {
                File.Delete(FilePath);
            }

            #region Local DB
            isAuthenticated = false;
            if (!string.IsNullOrEmpty(ddlDatabase.Text))
            {
                if (ddlAuthentication.Text == "Windows Authentication")
                {
                    strConnTest = "Server=" + txtServer.Text + ";Database=" + ddlDatabase.Text + ";integrated security=true;";
                }
                else
                {
                    strConnTest = "Server=" + txtServer.Text + ";Database=" + ddlDatabase.Text + ";UID=" + txtUserId.Text.Trim() + ";Password="******";";
                }

                try
                {
                    SqlConnection cnTemp = new SqlConnection(strConnTest);
                    cnTemp.Open();
                    cnTemp.Close();
                    isAuthenticated = true;
                }
                catch { }
            }
            if (!isAuthenticated)
            {
                lblMessageBar.Text = "Quick Doc Database Settings are not Authenticated. Please verify the database information provided.";
                return;
            }
            #endregion

            string strConn_local = string.Empty;
            if (ddlAuthentication.Text == "Windows Authentication")
            {
                strConn_local = "Authentication:windows#Server:" + txtServer.Text + "#Database:" + ddlDatabase.Text;
            }
            else
            {
                strConn_local = "Authentication:server#Server:" + txtServer.Text + "#Database:" + ddlDatabase.Text + "#UserID:" + txtUserId.Text + "#Password:"******"~Provider:System.Data.SqlClient";

            HelpMeDatabaseConfiguration.Configurations.DatabaseSecurity dbs = new HelpMeDatabaseConfiguration.Configurations.DatabaseSecurity();
            FilePath = Application.StartupPath + System.IO.Path.DirectorySeparatorChar + "DBConfig.HelpMe";
            dbs.EncryptStringtoFile(strConn, FilePath);
            lblMessageBar.Text = "Quick Doc Database Settings Saved Successfully.";

            SetScheduler();

            this.btnSave.Enabled = true;
            #endregion
        }