public static string CnnVal(string name) { SettingsConstructor settings = new SettingsConstructor(); if (settings.UseManualConString == false) { //Gets local server instance and replaces PLACEHOLDER in app.config with local server info string svrInstance = ""; RegistryView registryView = Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32; using (RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView)) { RegistryKey instanceKey = hklm.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL", false); if (instanceKey != null) { foreach (var instanceName in instanceKey.GetValueNames()) { svrInstance += /*Environment.MachineName + @"\" + */ instanceName; } } } conString = ConfigurationManager.ConnectionStrings[name].ConnectionString; conString = conString.Replace("PLACEHOLDER", svrInstance); } else if (settings.UseManualConString == true) { //Sets connection string manually if option is chosen in settings menu conString = settings.ManualConString; } return(conString); }
private void label3_Click(object sender, EventArgs e) { SettingsConstructor settings = new SettingsConstructor(); settings.ByPassLogin = true; this.Hide(); this.Enabled = false; admin.Show(); //System.Diagnostics.Process.Start("https://www.google.com"); }
private void btnSaveSettings_Click(object sender, EventArgs e) { if (radBtnAutoConString.Checked == true) { SettingsConstructor settings = new SettingsConstructor(); settings.UseManualConString = false; } if (radBtnManualConString.Checked == true) { //Example con string Data Source=DESKTOP-7GT4A2S\SQLEXPRESS;Initial Catalog=TGDB;Integrated Security=True manualConstring = Interaction.InputBox("", "Manual connection string", "Enter manual connection string here...", -1, -1); SettingsConstructor settings = new SettingsConstructor(); settings.ManualConString = manualConstring; settings.UseManualConString = true; } this.Dispose(); }
/// <summary> /// All control event handlers /// </summary> #region Event Handlers /// <summary> /// All On_Click event handlers /// </summary> #region On Click /// <summary> /// Logs in an existing user /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLogin_Click(object sender, EventArgs e) { try { bool loginFailed = false; //Finds entries in list where username = txtUsername.Text DataAccess db = new DataAccess(); _users = db.GetUser(txtUsername.Text); //Finds entries in list where adminname = txtUsername.Text _admins = db.GetAdmin(txtUsername.Text); //Converts list to dataset using the ListToDataSet Class and ToDataSet method inside because lists<T> are a pain to work with DataSet dsUser = new DataSet(); dsUser = ListToDataSet.ToDataSet(_users); DataSet dsAdmin = new DataSet(); dsAdmin = ListToDataSet.ToDataSet(_admins); if (dsUser.Tables[0].Rows.Count > 0) { //Checks if user name and password combination exists where returned data set is filtered by entered username, will always be Row[0] becaus of this if (dsUser.Tables[0].Rows[0]["UserName"].ToString() != txtUsername.Text || dsUser.Tables[0].Rows[0]["UserPassword"].ToString() != txtPassword.Text) { loginFailed = true; } else if (dsUser.Tables[0].Rows[0]["UserName"].ToString() == txtUsername.Text && dsUser.Tables[0].Rows[0]["UserPassword"].ToString() == txtPassword.Text) { //MessageBox.Show("Loged in Successfully.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); SettingsConstructor settings = new SettingsConstructor(); settings.CurrentUser = txtUsername.Text; settings.IsAdmin = false; loginFailed = false; this.Hide(); this.Enabled = false; loadScreen.Show(); } } else if (dsAdmin.Tables[0].Rows.Count > 0) { //Checks if user name and password combination exists where returned data set is filtered by entered username, will always be Row[0] becaus of this if (dsAdmin.Tables[0].Rows[0]["AdminName"].ToString() != txtUsername.Text || dsAdmin.Tables[0].Rows[0]["AdminPassword"].ToString() != txtPassword.Text) { loginFailed = true; } else if (dsAdmin.Tables[0].Rows[0]["AdminName"].ToString() == txtUsername.Text && dsAdmin.Tables[0].Rows[0]["AdminPassword"].ToString() == txtPassword.Text) { //MessageBox.Show("Loged in Successfully.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); SettingsConstructor settings = new SettingsConstructor(); settings.CurrentUser = txtUsername.Text; settings.IsAdmin = true; loginFailed = false; this.Hide(); this.Enabled = false; loadScreen.Show(); } } if (loginFailed == true) { MessageBox.Show("The username or password is incorrect.", "Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning); } //Can also use List<T> in this case "user" as a datasource for anything //cmbTest.Refresh(); //cmbTest.DataSource = _users; //cmbTest.DisplayMember = "FullInfo"; //cmbTest.ValueMember = "UserId"; } catch (Exception ex) { MessageBox.Show("An errors has occurred while trying to login." + ex.Message); } }