public UManage(Guid currentUser, List <User> GetUsers) { InitializeComponent(); CultureInfo culture = Thread.CurrentThread.CurrentCulture; TextInfo textInfo = culture.TextInfo; List <string> stateList = new List <string>(); users = GetUsers; CCErrorProvider.Clear(); UserLoginErrorProv.Clear(); UserMaintErrorProv.Clear(); if (currentUser != Guid.Empty) { UserIndexNo = users.FindIndex(a => a.guid == currentUser); LoggedInUser = users[UserIndexNo]; } stateList.Add(string.Empty); stateList.AddRange(Enum.GetNames(typeof(User.StateEnum))); for (int counter = 0; counter < stateList.Count(); counter++) { stateList[counter] = textInfo.ToTitleCase(stateList[counter].Replace("_", " ")); } StateBox.Items.AddRange(stateList.ToArray()); StateBox.SelectedIndex = 0; }
private void NewUserButton_Click(object sender, EventArgs e) { if (NewUserButton.Text == CreateUser) { //create new user button /*relative text box names * Username text box: Createusernamebox * Password text box: Createpasswordbox * First name text box: Firstnamebox * Last name text box: Lastnamebox * Address name text box: Addressbox * Phone number text box: Phonenumberbox * Credit Card text box: Creditcardbox * Security question text box: Questionbox * Security question answer text box: Questionanswerbox */ UserLoginErrorProv.Clear(); string NewUsrName = CreateUserNameBox.Text; string NewFName = Firstnamebox.Text; string NewLName = Lastnamebox.Text; string NewAddr0 = Address1box.Text; string NewAddr1 = Address2box.Text; string NewCity = Citybox.Text; string NewState = StateBox.SelectedItem.ToString(); int NewZip = int.Parse(Zipbox.Text); long NewPhone = long.Parse(Phonenumberbox.Text); byte[] NewPass = sHA.ComputeHash(ue.GetBytes(CreatePasswordBox.Text)); byte[] NewCCd = sHA.ComputeHash(ue.GetBytes(Creditcardbox.Text)); byte[] NewCCV = sHA.ComputeHash(ue.GetBytes(CCVbox.Text)); byte[] NewExpr = sHA.ComputeHash(ue.GetBytes(Expdatebox.Text)); string NewQuest = Questionbox.Text; byte[] NewAnswr = sHA.ComputeHash(ue.GetBytes(Questionanswerbox.Text)); int NewFour = Creditcardbox.Text.Length < 4 ? int.Parse(Creditcardbox.Text) : int.Parse(Creditcardbox.Text.Substring(Creditcardbox.Text.Length - 4)); User User1 = new User(NewUsrName, NewFName, NewLName, NewAddr0, NewAddr1, NewCity, NewState, NewZip, NewPhone, NewPass, NewCCd, NewCCV, NewExpr, NewQuest, NewAnswr, NewFour); if (!users.Where(a => a.UName == User1.UName).Any()) { users.Add(User1); MessageBox.Show(string.Format("User {0} has been created!", User1.UName), "User created", MessageBoxButtons.OK, MessageBoxIcon.Information); UNameEnterbox.Text = CreateUserNameBox.Text; CreateUserNameBox.Text = string.Empty; Firstnamebox.Text = string.Empty; Lastnamebox.Text = string.Empty; Address1box.Text = string.Empty; Address2box.Text = string.Empty; Citybox.Text = string.Empty; StateBox.Text = string.Empty; Zipbox.Text = string.Empty; CreatePasswordBox.Text = string.Empty; Creditcardbox.Text = string.Empty; CCImage.Visible = false; CCImage.Image = null; CCVbox.Text = string.Empty; Expdatebox.Text = string.Empty; Questionbox.Text = string.Empty; Questionanswerbox.Text = string.Empty; _ = UNameEnterbox.Focus(); } else { UserMaintErrorProv.SetError(CreateUserNameBox, UsrExists); } } else if (NewUserButton.Text == SaveUser) { LoggedInUser.UName = CreateUserNameBox.Text; CreatePasswordBox.Enabled = true; LoggedInUser.FName = Firstnamebox.Text; LoggedInUser.LName = Lastnamebox.Text; LoggedInUser.AddrZero = Address1box.Text; LoggedInUser.AddrOne = Address2box.Text; LoggedInUser.City = Citybox.Text; LoggedInUser.State = StateBox.Text; LoggedInUser.ZipCode = Zipbox.Text; LoggedInUser.PhoneNo = long.Parse(Phonenumberbox.Text); if (long.TryParse(Creditcardbox.Text, out _)) { LoggedInUser.NewCC( sHA.ComputeHash(ue.GetBytes(Creditcardbox.Text)), int.Parse(Creditcardbox.Text.Length > 3 ? Creditcardbox.Text.Substring(Creditcardbox.Text.Length - 4) : Creditcardbox.Text), sHA.ComputeHash(ue.GetBytes(CCVbox.Text)), sHA.ComputeHash(ue.GetBytes(Expdatebox.Text))); } if ((Questionbox.Text != LoggedInUser.SecretQ) && (Questionanswerbox.Text != FourStars)) { LoggedInUser.NewSecQ( Questionbox.Text, sHA.ComputeHash(ue.GetBytes(Questionanswerbox.Text))); } NewUserButton.Text = CreateUser; EditUserDataButton.Text = EditUser; if (!users.Remove(users.Where(a => a.guid == LoggedInUser.guid).Single())) { throw new Exception("Unable to remove the logged in user for updating."); } users.Add(LoggedInUser); MessageBox.Show("This user's information has been updated!", "User updated", MessageBoxButtons.OK, MessageBoxIcon.Information); UNameEnterbox.Text = CreateUserNameBox.Text; CreateUserNameBox.Text = string.Empty; CreatePasswordBox.Text = string.Empty; Firstnamebox.Text = string.Empty; Lastnamebox.Text = string.Empty; Address1box.Text = string.Empty; Address2box.Text = string.Empty; Citybox.Text = string.Empty; StateBox.SelectedIndex = 0; Zipbox.Text = string.Empty; Phonenumberbox.Text = string.Empty; Creditcardbox.Text = string.Empty; CCVbox.Text = string.Empty; Expdatebox.Text = string.Empty; Questionbox.Text = string.Empty; Questionanswerbox.Text = string.Empty; } }