private void button1_Click(object sender, EventArgs e) { string sql = "select user_name, user_code from tbl_user where user_email = " + "'" + EmailBox.Text + "'" + " and " + "user_pw = " + "'" + PasswordBox.Text + "'"; DataTable dt = db.GetDBTable(sql); if (dt.Rows.Count == 0) { MessageBox.Show("회원정보가 없습니다."); EmailBox.Text = ""; PasswordBox.Text = ""; EmailBox.Focus(); return; } foreach (DataRow dr in dt.Rows) { username = dr["USER_NAME"].ToString(); user_code = Int32.Parse(dr["USER_CODE"].ToString()); MessageBox.Show(username + "님 환영합니다."); } this.Visible = false; Form3 f3 = new Form3(); f3.passvalue = username; f3.User_code = user_code; f3.ShowDialog(); //textBox1.Text = sql; db.CloseDB(); }
private void InputBox_OnKeyUp(object sender, KeyRoutedEventArgs e) { if (sender == PhoneNumberBox) { if (PhoneNumberBox.Text.Length == 10) { EmailBox.Focus(FocusState.Programmatic); return; } } if (e.Key == VirtualKey.Enter) { if (sender == NameBox) { SurnameBox.Focus(FocusState.Programmatic); } if (sender == SurnameBox) { CommandBar.Focus(FocusState.Programmatic); } else if (sender == EmailBox) { PasswordBox.Focus(FocusState.Programmatic); } else if (sender == PasswordBox) { PasswordRepeatBox.Focus(FocusState.Programmatic); } else if (sender == PasswordRepeatBox) { CommandBar.Focus(FocusState.Programmatic); } } }
// Validacia udajov v textovych poliach private bool StudentBoxesValidator() { if (!OnlyLetters(this.NameBox.Text, 2, 30)) { MessageBox.Show("Meno nemôže mať viac ako 30 znakov a menej ako 2 nemôže obsahovať špeciálne znaky ani čísla", "Chyba"); NameBox.SelectAll(); NameBox.Focus(); return(false); } else if (!OnlyLetters(this.SurnameBox.Text, 2, 35)) { MessageBox.Show("Priezvisko nemôže mať viac ako 35 znakov a menej ako 2 nemôže obsahovať špeciálne znaky ani čísla", "Chyba"); SurnameBox.SelectAll(); SurnameBox.Focus(); return(false); } else if (!ContainsSpecialCharacters(this.EmailBox.Text, 7, 55)) { MessageBox.Show("Uistite sa, že email obsahuje @ a dĺžka nepresiahla 55 znakov.", "Chyba"); EmailBox.SelectAll(); EmailBox.Focus(); return(false); } else if (!string.IsNullOrEmpty(EmailUcmBox.Text) || !string.IsNullOrWhiteSpace(EmailUcmBox.Text)) { if (!ContainsSpecialCharacters(this.EmailUcmBox.Text, 7, 55)) { MessageBox.Show("Uistite sa, že email obsahuje @ a dĺžka nepresiahla 55 znakov.", "Chyba"); EmailUcmBox.SelectAll(); EmailUcmBox.Focus(); return(false); } } else if (!string.IsNullOrWhiteSpace(this.IsicBox.Text) || !string.IsNullOrEmpty(this.IsicBox.Text)) { if (!OnlyNumericCharacters(this.IsicBox.Text, 17, 17)) { MessageBox.Show("Uistite sa, že ISIC obsahuje iba čísla a dĺžka nepresiahla 17 znakov.", "Chyba"); return(false); } } if (!OnlyNumericCharacters(this.GradeBox.Text, 1, 3)) { MessageBox.Show("Uistite sa, že ročník obsahuje čísla a dĺžka nepresiahla 3 znaky.", "Chyba"); return(false); } return(true); }
private void ResetButton_Click(object sender, RoutedEventArgs e) { if (new ValidationClass().CheckIfNotEmpty(EmailBox.Text)) { PasskeeperModelContext db = new PasskeeperModelContext(); try { var users = from u in db.Users select u; var findUser = db.Users.FirstOrDefault(u => u.Email == EmailBox.Text); if (findUser != null) { byte[] ba = new byte[8]; new RNGCryptoServiceProvider().GetBytes(ba); var hexString = BitConverter.ToString(ba); string newPassword = hexString.Replace("-", ""); findUser.MasterPassword = PasswordProtect.CreateHash(newPassword); db.SaveChanges(); new EmailingClass().SendEmail(EmailBox.Text, "Your password for PassKeeper is reset", newPassword); DialogResult = true; } else { MessageBox.Show("This e-mail is not registered!"); EmailBox.Focus(); } } catch (Exception err) { MessageBox.Show(err.ToString()); } } else { MessageBox.Show("Please populate all fields!"); } }
/// <summary> /// Clicking button checks if all fields have plausible entires (not empty or wrong format). Then /// updates currently selected customer with new information. Uses email as unique identifier, but /// does not check if email already exists. (Not sure how...) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveButton_Click(object sender, EventArgs e) { bool valid = true; // Boolean will be set to false if any tests fail, used to check if customer should be saved. if (FirstNameBox.Text == "" || !Regex.IsMatch(FirstNameBox.Text, name)) { MessageBox.Show("Please enter your first name", "First name is a required field"); FirstNameBox.Focus(); valid = false; } if (LastNameBox.Text == "" || !Regex.IsMatch(LastNameBox.Text, name)) { MessageBox.Show("Please enter your last name", "Last name is a required field"); LastNameBox.Focus(); valid = false; } if (AddressBox.Text == "" || !Regex.IsMatch(AddressBox.Text, address)) { MessageBox.Show("Please enter your address", "Address is a required field"); AddressBox.Focus(); valid = false; } if (CityBox.Text == "" || !Regex.IsMatch(CityBox.Text, city)) { MessageBox.Show("Please enter your city", "City is a required field"); CityBox.Focus(); valid = false; } if (StateBox.Text == "" || !Regex.IsMatch(StateBox.Text, name)) { MessageBox.Show("Please enter your state", "State is a required field"); StateBox.Focus(); valid = false; } if (ZipBox.Text == "" || !Regex.IsMatch(ZipBox.Text, zip)) { MessageBox.Show("Please enter your zip code", "Zip Code is a required field"); ZipBox.Focus(); valid = false; } if (PhoneBox.Text == "" || !Regex.IsMatch(PhoneBox.Text, phone)) { MessageBox.Show("Please enter your phone number", "Phone number is a required field"); PhoneBox.Focus(); valid = false; } if (EmailBox.Text == "" || !Regex.IsMatch(EmailBox.Text, email)) { MessageBox.Show("Please enter your email address", "Email is a required field"); EmailBox.Focus(); valid = false; } // If invalid entry, do not save. if (!valid) { return; } // Else string ConnectionString = "server=localhost;user=root;database=book store;password="******"Insert into customer values" + $"('null','{FirstNameBox.Text}'," + $"'{LastNameBox.Text}'," + $"'{AddressBox.Text}'," + $"'{CityBox.Text}'," + $"'{StateBox.Text}'," + $"'{ZipBox.Text}'," + $"'{PhoneBox.Text}'," + $"'{EmailBox.Text}')"; cmd.Connection = DBConnect; cmd.ExecuteNonQuery(); DBConnect.Close(); FirstNameBox.Clear(); LastNameBox.Clear(); AddressBox.Clear(); CityBox.Clear(); StateBox.Clear(); ZipBox.Clear(); PhoneBox.Clear(); EmailBox.Clear(); // Call function to update the combobox with new customer added. CustomerSelectBox_Click(sender, e); CustomerSelectBox.Enabled = true; SaveButton.Enabled = false; MessageBox.Show("Customer added to database."); return; } // Else update the currently selected customer with textbox info // Extract first and last name into string array. string[] custName = new string[2]; custName = CustomerSelectBox.Text.Split(); cmd.CommandText = $"Update customer set" + $" first='{FirstNameBox.Text}'," + $"last='{LastNameBox.Text}'," + $"address='{AddressBox.Text}'," + $"city='{CityBox.Text}'," + $"state='{StateBox.Text}'," + $"zip='{ZipBox.Text}'," + $"phone='{PhoneBox.Text}'," + $"email='{EmailBox.Text}'" + $" where first='{custName[0]}' AND last ='{custName[1]}'"; cmd.Connection = DBConnect; cmd.ExecuteNonQuery(); DBConnect.Close(); MessageBox.Show("Customer successfully updated."); return; /* * SaveButton.Enabled = false; // Disable the save button again until new customer is selected from the comboBox. * * // Rewrite the entire file, omitting the line with the email of the customer that is being updated, since email is unique. * // SRC: https://stackoverflow.com/questions/10371630/c-sharp-text-file-search-for-specific-word-and-delete-whole-line-of-text-that-co * Customer tempCustomer = (Customer)(CustomerSelectBox.SelectedItem); * var oldLines = File.ReadAllLines("customers.txt"); * var newLines = oldLines.Where(line => !line.Contains(tempCustomer.email)); * File.WriteAllLines("customers.txt", newLines); * * customers.Remove((Customer)CustomerSelectBox.SelectedItem); // Remove old customer info from customer list. * * // Add new info to list. * tempCustomer = new Customer(FirstNameBox.Text, LastNameBox.Text, AddressBox.Text, CityBox.Text, StateBox.Text, ZipBox.Text, PhoneBox.Text, EmailBox.Text); * customers.Add(tempCustomer); * * // Close reader and inFile even if exception is thrown. * // SRC:https://stackoverflow.com/questions/86766/how-to-properly-handle-exceptions-when-performing-file-io * try * { * using (FileStream outFile = new FileStream("customers.txt", FileMode.Append, FileAccess.Write)) * using (StreamWriter writer = new StreamWriter(outFile)) * { * // Write info to file. * writer.WriteLine($"{FirstNameBox.Text},{LastNameBox.Text},{AddressBox.Text},{CityBox.Text},{StateBox.Text},{ZipBox.Text},{PhoneBox.Text},{EmailBox.Text}"); * } * * // Clear Text Boxes. * FirstNameBox.Clear(); * LastNameBox.Clear(); * AddressBox.Clear(); * CityBox.Clear(); * StateBox.Clear(); * ZipBox.Clear(); * PhoneBox.Clear(); * EmailBox.Clear(); * * // Update comboBox with new info. * CustomerSelectBox.Items.Remove(CustomerSelectBox.SelectedItem); * CustomerSelectBox.Items.Add(tempCustomer); * } * catch (FileNotFoundException) * { * MessageBox.Show("File 'customers.txt' not found to write.", "File Write Error"); * } * // Catch generic I/O exceptions. * catch (IOException ex) * { * MessageBox.Show(ex.ToString(), "Error"); * } */ }
private bool BoxValidation() { int upperCount = 0; if (NameBox.Text.Length < 8 || NameBox.Text.Length > 15) { MessageBox.Show("Meno nemôže mať menej než 8 znakov a viac ako 15"); return(false); } string name = NameBox.Text; foreach (var c in name) { if (char.IsUpper(c)) { upperCount++; } } if (upperCount <= 0) { MessageBox.Show("Meno musí obsahovať aspoň jedno veľké písmeno"); return(false); } if (!ContainsSpecialCharacters(this.EmailBox.Text, 7, 55)) { MessageBox.Show("Uistite sa, že email obsahuje @ a dĺžka nepresiahla 55 znakov.", "Chyba"); EmailBox.SelectAll(); EmailBox.Focus(); return(false); } if (FirstPssBox.Text.Length < 8 || FirstPssBox.Text.Length > 30) { MessageBox.Show("Heslo musí obsahovať minimálne 8 znakov a maximálne 30 znakov"); return(false); } string pss = FirstPssBox.Text; int numCount = 0; int uppCount = 0; foreach (var x in pss) { if (char.IsUpper(x)) { uppCount++; } if (char.IsNumber(x)) { numCount++; } } if (numCount <= 0 || uppCount <= 0) { MessageBox.Show("Heslo musí obsahovať aspoň jedno veľké písmeno a jedno číslo"); return(false); } string secPss = SecondPssBox.Text; if (pss != secPss) { MessageBox.Show("Heslá sa nezhodujú"); return(false); } return(true); }
private void BtnSauver_Click(object sender, RoutedEventArgs e) { if (Modification) { try { mainWindow.Liste.SupprimerContact(Index); mainWindow.Liste.InsererContact(new Contact(NomBox.Text, PrenomBox.Text, AdresseBox.Text, CPBox.Text, VilleBox.Text, NoTelBox.Text, EmailBox.Text, ProvinceComboBox.Text), Index); EntreeSortie.Ecriture(mainWindow.Liste); this.Close(); } catch (EmailInvalideException exception) { EmailBox.Focus(); MBPerso mBPerso = new MBPerso(exception.Message, MessageButtons.Ok); } catch (CodePostalException exception) { CPBox.Focus(); MBPerso mBPerso = new MBPerso(exception.Message, MessageButtons.Ok); } catch (TelephoneInvalideException exception) { NoTelBox.Focus(); MBPerso mBPerso = new MBPerso(exception.Message, MessageButtons.Ok); } } else { try { mainWindow.Liste.AjouterContact(new Contact(NomBox.Text, PrenomBox.Text, AdresseBox.Text, CPBox.Text, VilleBox.Text, NoTelBox.Text, EmailBox.Text, ProvinceComboBox.Text)); EntreeSortie.Ecriture(mainWindow.Liste); this.Close(); } catch (EmailInvalideException exception) { EmailBox.Focus(); MBPerso mBPerso = new MBPerso(exception.Message, MessageButtons.Ok); } catch (CodePostalException exception) { CPBox.Focus(); MBPerso mBPerso = new MBPerso(exception.Message, MessageButtons.Ok); } catch (TelephoneInvalideException exception) { NoTelBox.Focus(); MBPerso mBPerso = new MBPerso(exception.Message, MessageButtons.Ok); } catch (ContactDejaPresentException exception) { bool?result = new MBPerso(exception.Message, MessageButtons.YesNo).ShowDialog(); if (result.Value) { mainWindow.Liste.SupprimerContact(exception.Contact); mainWindow.Liste.InsererContact(new Contact(NomBox.Text, PrenomBox.Text, AdresseBox.Text, CPBox.Text, VilleBox.Text, NoTelBox.Text, EmailBox.Text, ProvinceComboBox.Text), exception.Index); EntreeSortie.Ecriture(mainWindow.Liste); } else { NomBox.Focus(); } } } }