private void ConnectionDetails_Load(object sender, EventArgs e) { //checks if already connected to database if (File.Exists("C:\\dbWizard\\dbWizardConnectionStrings.txt")) { DialogResult dialogResult = MessageBox.Show("Connection strings already setup, reset?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dialogResult == DialogResult.Yes) { File.Delete(@"C:\\dbWizard\\dbWizardConnectionStrings.txt"); } else if (dialogResult == DialogResult.No) { //closes this form, opens home Home home = new Home(); home.Show(); } } //gets connection to main form Home frm = new Home(); //sets colour scheme if (frm.ColourScheme == 0) { var skinManager = MaterialSkin.MaterialSkinManager.Instance; skinManager.AddFormToManage(this); skinManager.Theme = MaterialSkin.MaterialSkinManager.Themes.LIGHT; skinManager.ColorScheme = new MaterialSkin.ColorScheme (MaterialSkin.Primary.Grey800, MaterialSkin.Primary.Grey700, MaterialSkin.Primary.Grey500, MaterialSkin.Accent.Green100, MaterialSkin.TextShade.WHITE ); } else if (frm.ColourScheme == 1) { var skinManager = MaterialSkin.MaterialSkinManager.Instance; skinManager.AddFormToManage(this); skinManager.Theme = MaterialSkin.MaterialSkinManager.Themes.LIGHT; skinManager.ColorScheme = new MaterialSkin.ColorScheme (MaterialSkin.Primary.Grey800, MaterialSkin.Primary.Grey700, MaterialSkin.Primary.Grey500, MaterialSkin.Accent.Green100, MaterialSkin.TextShade.WHITE ); } }
private void btnConfirm_Click(object sender, EventArgs e) { //checks user credentials SqlConnection sqlConnection1 = new SqlConnection(connstr); SqlCommand cmd = new SqlCommand(); Object returnValue; cmd.CommandText = "USE [dbWizard] SELECT COUNT(*) FROM dbUsers WHERE dbUsername = '******' AND dbPassword = '******'"; cmd.CommandType = CommandType.Text; cmd.Connection = sqlConnection1; sqlConnection1.Open(); returnValue = cmd.ExecuteScalar(); sqlConnection1.Close(); //if creds are correct then logs in, sets intActive to 1 to show user is online if (returnValue.ToString() != "") { //logs user in and sets their session id cmd.CommandText = "USE [dbWizard] SELECT dbUserID FROM dbUsers WHERE dbUsername = '******' AND dbPassword = '******'"; cmd.CommandType = CommandType.Text; cmd.Connection = sqlConnection1; sqlConnection1.Open(); returnValue = cmd.ExecuteScalar(); sqlConnection1.Close(); //sets user id userId = Convert.ToInt32(returnValue.ToString()); //sets user to be active cmd.CommandText = "USE [dbWizard] UPDATE dbUsers SET intActive = 1 WHERE dbUserID = " + userId; cmd.CommandType = CommandType.Text; cmd.Connection = sqlConnection1; sqlConnection1.Open(); cmd.ExecuteScalar(); sqlConnection1.Close(); pbSuccess.Visible = true; cmd.CommandText = "USE [dbWizard] SELECT dbUsername FROM dbUsers WHERE dbUserID = " + userId; cmd.CommandType = CommandType.Text; cmd.Connection = sqlConnection1; sqlConnection1.Open(); returnValue = cmd.ExecuteScalar(); sqlConnection1.Close(); //saves credentials if checked if (chkRemember.Checked == true) { //saves connstrings to file on C:\ string path = @"C:\dbWizard\"; if (!File.Exists(path)) { using (var tw = new StreamWriter(path + "credentials.txt", true)) { tw.WriteLine("The next line!"); tw.Close(); System.IO.File.WriteAllText(@"C:\\dbWizard\\credentials.txt", "USE [dbWizard] SELECT dbUserID FROM dbUsers WHERE dbUsername = '******' AND dbPassword = '******'"); } } } //closes this form sets userId Home home = new Home(); home.userId = userId; home.lbl_User.Text = "Logged in as: " + returnValue.ToString(); //gives higher access once logged in home.viewsToolStripMenuItem.Visible = true; home.GroupBoxTools.Visible = true; home.Show(); this.Hide(); } else { //tells user that creds are incorrect MessageBox.Show("Credentials incorrect", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }