private void ButtonRegister_Click(object sender, RoutedEventArgs e) { if (!Regex.IsMatch(TextEmail.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$")) { MessageBox.Show("Please enter a valid Email address", "Invalid Email", MessageBoxButton.OK, MessageBoxImage.Error); TextEmail.Select(0, TextEmail.Text.Length); TextEmail.Focus(); TextEmail.Text = string.Empty; } else if (_stuManager.CheckDuplicateRecords(TextEmail.Text)) { MessageBox.Show("Already registered email address, Please use a new address", "Duplicate Email", MessageBoxButton.OK, MessageBoxImage.Error); TextEmail.Select(0, TextEmail.Text.Length); TextEmail.Focus(); } else { _stuManager.Create(TextFirstName.Text, TextLastName.Text, TextEmail.Text); MessageBox.Show($"Congratulations {TextFirstName.Text}!\n" + $"Your Student ID is: {_stuManager.SelectedStudent.StudentID}"); TextFirstName.Text = string.Empty; TextLastName.Text = string.Empty; TextEmail.Text = string.Empty; } }
private void btnSignIn_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(TextEmail.Text) || string.IsNullOrEmpty(TextPassword.Text)) { MetroFramework.MetroMessageBox.Show(this, "All field should be filled up.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); TextEmail.Focus(); return; } else { var user = UserServices.LogIn(TextEmail.Text, TextPassword.Text); if (user != null) { if (user.type == "admin") { StarterForm.isAdmin = true; StarterForm.loggedStatus = true; StarterForm.loggedInUser = user; if (BookStoreEvent != null) { BookStoreEvent(); UserInfoShowEvent(user); } } else { StarterForm.loggedStatus = true; StarterForm.loggedInUser = user; UserInfoShowEvent(user); } this.Hide(); } else { MetroFramework.MetroMessageBox.Show(this, "Wrong Email or Password.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); TextEmail.Focus(); return; } } }
private void CreateNewDoctor(object sender, EventArgs e) { Messages msg = new Messages(); if (TextLastName.Text == "") { msg.DataError("Введите фамилию!"); TextLastName.Focus(); } else if (TextFirstName.Text == "") { msg.DataError("Введите имя!"); TextFirstName.Focus(); } else if (TextIIN.Text.Length != 12) { msg.DataError("Введите корректный ИИН!"); TextIIN.Focus(); } else if (TextEmail.Text == "") { msg.DataError("Введите адрес электронной почты!"); TextEmail.Focus(); } else if (TextPhone.Text == "") { msg.DataError("Введите номер телефона!"); TextPhone.Focus(); } else if (TextPassword.Text == "") { msg.DataError("Введите пароль!"); TextPassword.Focus(); } else if (TextPassword.Text != TextRepPassword.Text) { msg.DataError("Пароли не совпадают!"); TextPassword.Focus(); } else if (CBSetSpec.Text == "") { msg.DataError("Выберите специализацию!"); CBSetSpec.Focus(); } else { conn.Open(); sql = "SELECT COUNT(*) FROM DOCTOR WHERE DOC_EMAIL = '" + TextEmail.Text + "'"; MySqlCommand checkEmail = new MySqlCommand(sql, conn); COUNT = Convert.ToInt32(checkEmail.ExecuteScalar()); if (COUNT == 0) { sql = "SELECT COUNT(*) FROM DOCTOR WHERE DOC_IIN = '" + TextIIN.Text + "'"; MySqlCommand checkIIN = new MySqlCommand(sql, conn); COUNT = Convert.ToInt32(checkIIN.ExecuteScalar()); if (COUNT == 0) { sql = "INSERT INTO DOCTOR (DOC_LASTNAME, " + "DOC_FIRSTNAME, " + "DOC_PATRONYMIC, " + "DOC_IIN, " + "DOC_EMAIL, " + "DOC_PHONE, " + "DOC_PASSWORD, " + "SPECIALISATION_ID_SPEC) " + "VALUES ('" + TextLastName.Text + "', " + "'" + TextFirstName.Text + "', " + "'" + TextPatronymic.Text + "', " + "'" + TextIIN.Text + "', " + "'" + TextEmail.Text + "', " + "'" + TextPhone.Text + "', " + "'" + TextPassword.Text + "', " + "" + idspec + ")"; MySqlCommand insdoc = new MySqlCommand(sql, conn); if (insdoc.ExecuteNonQuery() == 1) { msg.WriteSuccess(); this.Close(); AdminMainForm amf = new AdminMainForm(); amf.Show(); conn.Close(); } else { msg.WriteError(); conn.Close(); } } else { msg.DataError("ИИН уже существует в системе!"); conn.Close(); } } else { msg.DataError("Электронный адрес уже существует в системе!"); conn.Close(); } } }
private void CreateNewPerson(object sender, EventArgs e) { Messages msg = new Messages(); if (TextLastName.Text == "") { msg.DataError("Введите фамилию!"); TextLastName.Focus(); } else if (TextFirstName.Text == "") { msg.DataError("Введите имя!"); TextFirstName.Focus(); } else if (SexSet.Text == "") { msg.DataError("Выберите пол!"); SexSet.Focus(); } else if (TextIIN.Text.Length != 12) { msg.DataError("Введите корректный ИИН!"); TextIIN.Focus(); } else if (TextEmail.Text == "") { msg.DataError("Введите адрес электронной почты!"); TextEmail.Focus(); } else if (TextPhone.Text == "") { msg.DataError("Введите номер телефона!"); TextPhone.Focus(); } else if (TextPassword.Text == "") { msg.DataError("Введите пароль!"); TextPassword.Focus(); } else if (TextPassword.Text != TextRepPassword.Text) { msg.DataError("Пароли не совпадают!"); TextPassword.Focus(); } else { conn.Open(); sqlins = "INSERT INTO PERSON (PERSON_LASTNAME, " + "PERSON_FIRSTNAME, " + "PERSON_PATRONYMIC, " + "PERSON_BIRTHDAY, " + "PERSON_IIN, " + "PERSON_PASSWORD, " + "PERSON_EMAIL, " + "PERSON_SEX, " + "PERSON_PHONE) " + "VALUES ('" + TextLastName.Text + "', " + "'" + TextFirstName.Text + "', " + "'" + TextPatronymic.Text + "', " + "'" + this.BirthdaySet.Text + "', " + "'" + TextIIN.Text + "', " + "'" + TextPassword.Text + "', " + "'" + TextEmail.Text + "', " + "'" + SexSet.Text + "'," + "'" + TextPhone.Text + "')"; sql = "SELECT COUNT(*) FROM PERSON WHERE PERSON_EMAIL = '" + TextEmail.Text + "'"; MySqlCommand checkEmail = new MySqlCommand(sql, conn); COUNT = Convert.ToInt32(checkEmail.ExecuteScalar()); if (COUNT == 0) { sql = "SELECT COUNT(*) FROM PERSON WHERE PERSON_IIN = '" + TextIIN.Text + "'"; MySqlCommand checkIIN = new MySqlCommand(sql, conn); COUNT = Convert.ToInt32(checkIIN.ExecuteScalar()); if (COUNT == 0) { MySqlCommand cmd = new MySqlCommand(sqlins, conn); if (cmd.ExecuteNonQuery() == 1) { msg.WriteSuccess(); this.Close(); AdminMainForm amf = new AdminMainForm(); amf.Show(); conn.Close(); } else { msg.WriteError(); conn.Close(); } } else { msg.DataError("Номер документа уже существует в системе!"); conn.Close(); COUNT = 0; } } } }