private void textBoxLogin_TextChanged(object sender, EventArgs e)
{
labelErrorLogin.Visible = false;
errorLogin.Clear();
if (!string.IsNullOrEmpty(textBoxLogin.Text))
{
for (int i = 0; i < textBoxLogin.Text.Length; i++)
if (alphabet_login.IndexOf(textBoxLogin.Text[i]) == -1)
{
labelErrorLogin.Text = "Некорретное имя пользователя. Допустимо использовать только\nлатинские бувкы, цифры, знак подчеркивания и точку.";
labelErrorLogin.Visible = true;
errorLogin.SetIconAlignment(labelErrorLogin, ErrorIconAlignment.TopLeft);
errorLogin.SetIconPadding(labelErrorLogin, 3);
errorLogin.Icon = Properties.Resources.Error;
errorLogin.SetError(labelErrorLogin, "Error!");
return;
}
if (textBoxLogin.Text[textBoxLogin.Text.Length - 1] == '_' || textBoxLogin.Text[textBoxLogin.Text.Length - 1] == '.')
{
labelErrorLogin.Text = "Некорретное имя пользователя. Имя должно заканчиваться\nна латинскую букву или цифру.";
labelErrorLogin.Visible = true;
errorLogin.SetIconAlignment(labelErrorLogin, ErrorIconAlignment.TopLeft);
errorLogin.SetIconPadding(labelErrorLogin, 3);
errorLogin.Icon = Properties.Resources.Error;
errorLogin.SetError(labelErrorLogin, "Error!");
return;
}
foreach (DataRow row in users_labDataSet.user.Rows)
if (textBoxLogin.Text == (string)(row["login"]))
{
labelErrorLogin.Text = "Указанный логин уже существует.";
errorLogin.SetIconAlignment(labelErrorLogin, ErrorIconAlignment.TopLeft);
errorLogin.SetIconPadding(labelErrorLogin, 3);
errorLogin.Icon = Properties.Resources.Error;
errorLogin.SetError(labelErrorLogin, "Error!");
labelErrorLogin.Visible = true;
break;
}
}
}
private void textBoxLogin_Leave(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxLogin.Text))
{
labelErrorLogin.Text = "Заполните обязательное поле.";
labelErrorLogin.Visible = true;
errorLogin.SetIconAlignment(labelErrorLogin, ErrorIconAlignment.TopLeft);
errorLogin.SetIconPadding(labelErrorLogin, 3);
errorLogin.Icon = Properties.Resources.Error;
errorLogin.SetError(labelErrorLogin, "Error!");
}
else
if (!labelErrorLogin.Visible)
{
errorLogin.SetIconAlignment(textBoxLogin, ErrorIconAlignment.MiddleRight);
errorLogin.SetIconPadding(textBoxLogin, 3);
errorLogin.Icon = Properties.Resources.OK;
errorLogin.SetError(textBoxLogin, "OK");
}
}
private void textBoxPassword_Enter(object sender, EventArgs e)
{
labelErrorPassword.Visible = false;
errorPassword.Clear();
if (string.IsNullOrEmpty(textBoxPassword.Text))
{
labelErrorPassword.Text = "Задайте пароль, используя латинские буквы,\nцифры и специальные символы: ! @ # $ % ^ & * ( ) - _ + = ; : , . / ? |.";
labelErrorPassword.ForeColor = Color.Gray;
labelErrorPassword.Visible = true;
}
}
private void textBoxPassword_TextChanged(object sender, EventArgs e)
{
labelErrorPassword.Visible = false;
errorPassword.Clear();
if (string.IsNullOrEmpty(textBoxPassword.Text))
{
labelErrorPassword.Text = "Задайте пароль, используя латинские буквы,\nцифры и специальные символы: ! @ # $ % ^ & * ( ) - _ + = ; : , . / ? |.";
labelErrorPassword.ForeColor = Color.Gray;
labelErrorPassword.Visible = true;
}
else
for (int i = 0; i < textBoxPassword.Text.Length; i++)
if (alphabet_password.IndexOf(textBoxPassword.Text[i]) == -1)
{
labelErrorPassword.Text = "Запрещено использовать недопустимые символы.";
labelErrorPassword.ForeColor = Color.Red;
labelErrorPassword.Visible = true;
errorPassword.SetIconAlignment(labelErrorPassword, ErrorIconAlignment.TopLeft);
errorPassword.SetIconPadding(labelErrorPassword, 3);
errorPassword.Icon = Properties.Resources.Error;
errorPassword.SetError(labelErrorPassword, "Error!");
break;
}
if (!string.IsNullOrEmpty(textBoxRepeatPassword.Text))
{
labelErrorRepeatPassword.Visible = false;
errorRepeatPassword.Clear();
if (textBoxPassword.Text == textBoxRepeatPassword.Text)
{
errorRepeatPassword.SetIconAlignment(textBoxRepeatPassword, ErrorIconAlignment.MiddleRight);
errorRepeatPassword.SetIconPadding(textBoxRepeatPassword, 3);
errorRepeatPassword.Icon = Properties.Resources.OK;
errorRepeatPassword.SetError(textBoxRepeatPassword, "OK");
}
else
{
labelErrorRepeatPassword.Text = "Пароли не совпадают.";
labelErrorRepeatPassword.Visible = true;
errorRepeatPassword.SetIconAlignment(labelErrorRepeatPassword, ErrorIconAlignment.TopLeft);
errorRepeatPassword.SetIconPadding(labelErrorRepeatPassword, 3);
errorRepeatPassword.Icon = Properties.Resources.Error;
errorRepeatPassword.SetError(labelErrorRepeatPassword, "Error!");
}
}
}
private void textBoxPassword_Leave(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxPassword.Text))
{
labelErrorPassword.Text = "Заполните обязательное поле.";
labelErrorPassword.ForeColor = Color.Red;
labelErrorPassword.Visible = true;
errorPassword.SetIconAlignment(labelErrorPassword, ErrorIconAlignment.TopLeft);
errorPassword.SetIconPadding(labelErrorPassword, 3);
errorPassword.Icon = Properties.Resources.Error;
errorPassword.SetError(labelErrorPassword, "Error!");
}
else
if (!labelErrorPassword.Visible)
if (textBoxPassword.Text.Length < 6)
{
labelErrorPassword.Text = "Слишком короткий пароль.";
labelErrorPassword.ForeColor = Color.Red;
labelErrorPassword.Visible = true;
errorPassword.SetIconAlignment(labelErrorPassword, ErrorIconAlignment.TopLeft);
errorPassword.SetIconPadding(labelErrorPassword, 3);
errorPassword.Icon = Properties.Resources.Error;
errorPassword.SetError(labelErrorPassword, "Error!");
}
else
{
errorPassword.SetIconAlignment(textBoxPassword, ErrorIconAlignment.MiddleRight);
errorPassword.SetIconPadding(textBoxPassword, 3);
errorPassword.Icon = Properties.Resources.OK;
errorPassword.SetError(textBoxPassword, "OK");
}
}
private void textBoxRepeatPassword_TextChanged(object sender, EventArgs e)
{
labelErrorRepeatPassword.Visible = false;
errorRepeatPassword.Clear();
if (!string.IsNullOrEmpty(textBoxPassword.Text) && textBoxPassword.Text == textBoxRepeatPassword.Text)
{
errorRepeatPassword.SetIconAlignment(textBoxRepeatPassword, ErrorIconAlignment.MiddleRight);
errorRepeatPassword.SetIconPadding(textBoxRepeatPassword, 3);
errorRepeatPassword.Icon = Properties.Resources.OK;
errorRepeatPassword.SetError(textBoxRepeatPassword, "OK");
}
}
private void textBoxRepeatPassword_Leave(object sender, EventArgs e)
{
if (errorRepeatPassword.GetError(textBoxRepeatPassword) != "OK")
{
if (string.IsNullOrEmpty(textBoxRepeatPassword.Text))
{
labelErrorRepeatPassword.Text = "Заполните обязательное поле.";
labelErrorRepeatPassword.Visible = true;
errorRepeatPassword.SetIconAlignment(labelErrorRepeatPassword, ErrorIconAlignment.TopLeft);
errorRepeatPassword.SetIconPadding(labelErrorRepeatPassword, 3);
errorRepeatPassword.Icon = Properties.Resources.Error;
errorRepeatPassword.SetError(labelErrorRepeatPassword, "Error!");
}
else
if (!labelErrorRepeatPassword.Visible)
{
labelErrorRepeatPassword.Text = "Пароли не совпадают.";
labelErrorRepeatPassword.Visible = true;
errorRepeatPassword.SetIconAlignment(labelErrorRepeatPassword, ErrorIconAlignment.TopLeft);
errorRepeatPassword.SetIconPadding(labelErrorRepeatPassword, 3);
errorRepeatPassword.Icon = Properties.Resources.Error;
errorRepeatPassword.SetError(labelErrorRepeatPassword, "Error!");
}
}
}
private void button1_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxLogin.Text))
{
labelErrorLogin.Text = "Заполните обязательное поле.";
labelErrorLogin.Visible = true;
errorLogin.SetIconAlignment(labelErrorLogin, ErrorIconAlignment.TopLeft);
errorLogin.SetIconPadding(labelErrorLogin, 3);
errorLogin.Icon = Properties.Resources.Error;
errorLogin.SetError(labelErrorLogin, "Error!");
}
if (string.IsNullOrEmpty(textBoxPassword.Text))
{
labelErrorPassword.Text = "Заполните обязательное поле.";
labelErrorPassword.ForeColor = Color.Red;
labelErrorPassword.Visible = true;
errorPassword.SetIconAlignment(labelErrorPassword, ErrorIconAlignment.TopLeft);
errorPassword.SetIconPadding(labelErrorPassword, 3);
errorPassword.Icon = Properties.Resources.Error;
errorPassword.SetError(labelErrorPassword, "Error!");
}
if (string.IsNullOrEmpty(textBoxRepeatPassword.Text))
{
labelErrorRepeatPassword.Text = "Заполните обязательное поле.";
labelErrorRepeatPassword.Visible = true;
errorRepeatPassword.SetIconAlignment(labelErrorRepeatPassword, ErrorIconAlignment.TopLeft);
errorRepeatPassword.SetIconPadding(labelErrorRepeatPassword, 3);
errorRepeatPassword.Icon = Properties.Resources.Error;
errorRepeatPassword.SetError(labelErrorRepeatPassword, "Error!");
}
if (!(labelErrorLogin.Visible || labelErrorPassword.Visible || labelErrorRepeatPassword.Visible))
{
MD5 md5Hash = MD5.Create();
users_labDataSet.user.Rows.Add(textBoxLogin.Text, PMD5.GetMd5Hash(md5Hash, textBoxPassword.Text), "2");
userTableAdapter.Update(users_labDataSet);
MessageBox.Show("Регистрация прошла успешно.");
this.Close();
}
}
}