private void load() { try { List <User> _users = new List <User>(); DataAccess db = new DataAccess(); _users = db.GetUsers(); DataSet dsUsers = new DataSet(); dsUsers = ListToDataSet.ToDataSet(_users); if (dsUsers.Tables[0].Rows.Count > 0) { DataView viewUserNames = new DataView(dsUsers.Tables[0]); DataTable dtUserNames = viewUserNames.ToTable(true, "UserId", "UserName"); cboUserName.ValueMember = "UserId"; cboUserName.DisplayMember = "UserName"; cboUserName.DataSource = dtUserNames; } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void load() { try { List <Projects> _projects = new List <Projects>(); DataAccess db = new DataAccess(); _projects = db.GetProject(); DataSet dsProjects = new DataSet(); dsProjects = ListToDataSet.ToDataSet(_projects); if (dsProjects.Tables[0].Rows.Count > 0) { DataView viewProjectNames = new DataView(dsProjects.Tables[0]); DataTable dtProjectNames = viewProjectNames.ToTable(true, "ProjectId", "ProjectName"); cboProjectName.ValueMember = "ProjectId"; cboProjectName.DisplayMember = "ProjectName"; cboProjectName.DataSource = dtProjectNames; cboProjectPhase.SelectedIndex = 0; if (System.Windows.Forms.Application.OpenForms["frmMainAdmin"] != null) { (System.Windows.Forms.Application.OpenForms["frmMainAdmin"] as frmMainAdmin).refreshProjects(); } } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Register a new user /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnRegister_Click(object sender, EventArgs e) { try { DataAccess db = new DataAccess(); _users = db.GetUser(txtSUser.Text); _admins = db.GetAdmin(txtSUser.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); bool validationFine = false; bool validationPasswordFine = false; bool validationPasswordMatchFine = false; //Validate password if (validatePassword(txtSPass.Text) && validatePassword(txtSCPass.Text)) { validationPasswordFine = true; } else if (!(validatePassword(txtSPass.Text)) || !(validatePassword(txtSCPass.Text))) { MessageBox.Show("Invalid Password"); } if (txtSPass.Text == txtSCPass.Text) { validationPasswordMatchFine = true; } else if (txtSPass.Text != txtSCPass.Text) { MessageBox.Show("Passwords don't match"); } if (validationPasswordFine == true && validationPasswordMatchFine == true) { validationFine = true; if (validationFine == true) { //Checks if user name exists where returned data set is filtered by entered username, will always be Row[0] becaus of this if (chckBoxAdmin.Checked == false) { if (dsUser.Tables[0].Rows.Count == 0) { //Inserts a new user when register is clicked db.InsertUser(txtSUser.Text, txtSPass.Text, txtFirst.Text, txtLast.Text, txtEmail.Text); txtUsername.Text = ""; txtPassword.Text = ""; txtFirst.Text = ""; txtLast.Text = ""; txtEmail.Text = ""; pnlLogin.Visible = true; pnlLogin.Enabled = true; timer3.Start(); //MessageBox.Show("Your account has been registered successfully.", "Registration Success.", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (dsUser.Tables[0].Rows.Count > 0) { if (dsUser.Tables[0].Rows[0]["UserName"].ToString() == txtSUser.Text) { MessageBox.Show("The username already exists.", "Registration Failed.", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } else if (chckBoxAdmin.Checked == true) { masterPassword = Interaction.InputBox("", "Enter master password", "Enter master password here...", -1, -1); if (masterPassword == "TGA79135#") { if (dsAdmin.Tables[0].Rows.Count == 0) { //Inserts a new user when register is clicked db.InsertAdmin(txtSUser.Text, txtSPass.Text, txtFirst.Text, txtLast.Text, txtEmail.Text); txtUsername.Text = ""; txtPassword.Text = ""; txtFirst.Text = ""; txtLast.Text = ""; txtEmail.Text = ""; pnlLogin.Visible = true; pnlLogin.Enabled = true; timer3.Start(); //MessageBox.Show("Your account has been registered successfully.", "Registration Success.", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (dsAdmin.Tables[0].Rows.Count > 0) { if (dsAdmin.Tables[0].Rows[0]["AdminName"].ToString() == txtSUser.Text) { MessageBox.Show("The username already exists.", "Registration Failed.", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } else { MessageBox.Show("Incorrect master password, cannot add an admin account.", "Registration Failed.", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } //////send email //Random random = new Random(); // validationCode = random.Next(0, 1000).ToString(); // using (MailMessage mail = new MailMessage()) // { // try // { // //MailMessage mail = new MailMessage(); // SmtpClient smpt = new SmtpClient("smtp.gmail.com", 587); // mail.From = new MailAddress(emailAddress); // mail.To.Add(new MailAddress(txtEmail.Text)); // mail.Subject = emailSubject; // mail.Body = "Hello " + userFirstName + ", \n\n" + "Please enter the following code before proceeding to Login." + "\n" + validationCode; // smpt.Port = 587; // smpt.Credentials = new System.Net.NetworkCredential(emailAddress, emailPassword); // smpt.EnableSsl = true; // smpt.Send(mail); // pnlLogin.Enabled = true; // } // catch (Exception ex) // { // MessageBox.Show(ex.Message); // } // //inputBox for email validate // string userCode = Interaction.InputBox("Enter Code", "Validation"); // if (userCode == validationCode) // { // pnlLogin.Enabled = true; // } // } } } } catch (Exception ex) { MessageBox.Show("An error has occurred while trying to register." + ex.Message); } }
/// <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); } }
private void load() { try { List <ProjectTasks> _tasks = new List <ProjectTasks>(); DataAccess db = new DataAccess(); _tasks = db.GetAllTasks(); DataSet dsTasks = new DataSet(); dsTasks = ListToDataSet.ToDataSet(_tasks); if (dsTasks.Tables[0].Rows.Count > 0) { DataView viewAssigned = new DataView(dsTasks.Tables[0]); DataTable dtAssigened = viewAssigned.ToTable(true, "TaskId", "TaskName"); cboTaskName.ValueMember = "TaskId"; cboTaskName.DisplayMember = "TaskName"; cboTaskName.DataSource = dtAssigened; } List <User> _users = new List <User>(); _users = db.GetUsers(); DataSet dsUsers = new DataSet(); dsUsers = ListToDataSet.ToDataSet(_users); if (dsUsers.Tables[0].Rows.Count > 0) { DataView viewUsers = new DataView(dsUsers.Tables[0]); DataTable dtUsers = viewUsers.ToTable(true, "UserId", "UserName"); cboTaskAssigned.ValueMember = "UserId"; cboTaskAssigned.DisplayMember = "UserName"; cboTaskAssigned.DataSource = dtUsers; } List <Projects> _projects = new List <Projects>(); _projects = db.GetProject(); DataSet dsProjects = new DataSet(); dsProjects = ListToDataSet.ToDataSet(_projects); if (dsProjects.Tables[0].Rows.Count > 0) { DataView viewProjectName = new DataView(dsProjects.Tables[0]); DataTable dtProjectName = viewProjectName.ToTable(true, "ProjectId", "ProjectName"); cboProjectName.ValueMember = "ProjectId"; cboProjectName.DisplayMember = "ProjectName"; cboProjectName.DataSource = dtProjectName; } cboTaskStatus.SelectedIndex = 0; if (System.Windows.Forms.Application.OpenForms["frmMainAdmin"] != null) { (System.Windows.Forms.Application.OpenForms["frmMainAdmin"] as frmMainAdmin).refreshProjects(); } if (System.Windows.Forms.Application.OpenForms["frmMainAdmin"] != null) { (System.Windows.Forms.Application.OpenForms["frmMainAdmin"] as frmMainAdmin).refreshTasks(); } } catch (Exception e) { MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }