}//codeMaskedTextBox_MouseClick private void codeMaskedTextBox_Leave(object sender, EventArgs e) { if (codeMaskedTextBox.Text != String.Empty) { //Проверяем корректность ввода. if (codeMaskedTextBox.MaskCompleted == true && codeMaskedTextBox.Text.Length != 9) { //Проверяем существует ли уже такой code в базе. if ((_contragent.ContragentId != 0 && _contragent.Code == codeMaskedTextBox.Text) || PartsDAL.IsSupplierCodeExist(codeMaskedTextBox.Text) == false) { ControlValidation.CorrectValueInput(toolTip, codeMaskedTextBox); } else { ControlValidation.WrongValueInput(toolTip, codeMaskedTextBox, String.Format("Такой ИНН/ОКПО уже есть в базе!", _contragentType)); } }//if else { ControlValidation.WrongValueInput(toolTip, codeMaskedTextBox, String.Format("Введенный ИНН/ОКПО является некорректным!", _contragentType)); } //else } //if else { ControlValidation.CorrectValueInput(toolTip, codeMaskedTextBox); } }//codeMaskedTextBox_Leave
}//ManufacturerTextBox_Leave //Проверить вылеты. private void MeasureUnitComboBox_Leave(object sender, EventArgs e) { if (MeasureUnitComboBox.SelectedIndex == -1) ControlValidation.WrongValueInput(toolTip, MeasureUnitComboBox, "Выберите ед. изм."); else ControlValidation.CorrectValueInput(toolTip, MeasureUnitComboBox); }//MeasureUnitComboBox_Leave
}//ContragentTextBox_PreviewKeyDown private void ContragentTextBox_Leave(object sender, EventArgs e) { //Если такого клиента нет в базе, выдаём ошибку. string customer = ContragentTextBox.AutoCompleteCustomSource.Cast <string>().ToList().FirstOrDefault(c => c.ToLower() == ContragentTextBox.Text.Trim().ToLower()); if (customer != null) { ControlValidation.CorrectValueInput(toolTip, ContragentTextBox); ContragentTextBox.Text = customer; //Выводим корректное имя контрагента. }//if else { ControlValidation.WrongValueInput(toolTip, ContragentTextBox, "Поле \"Клиент\" заполнено некорректно"); } //else } //ContragentTextBox_Leave
}//Form1_Load #region Методы проверки корректности ввода. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Валидация ввода артикула. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ArticulTextBox_Leave(object sender, EventArgs e) { //если артикул введен. if (!String.IsNullOrWhiteSpace(ArticulTextBox.Text)) { string text = ArticulTextBox.Text.Trim(); //Если введенный артикул уже есть в базе, выдаём предупреждение, но позволяем дальнейший ввод. if ((_sparePart.SparePartId != 0 && _sparePart.Articul.ToLower() == text.ToLower()) || PartsDAL.FindSparePartsByArticul(text).Count == 0) ControlValidation.CorrectValueInput(toolTip, ArticulTextBox); else ControlValidation.WrongValueInput(toolTip, ArticulTextBox, "Такой артикул уже есть в базе", Color.Yellow); }//if else //Если артикул не введен. { ControlValidation.WrongValueInput(toolTip, ArticulTextBox); }//else //Если Title не пустой, проверяем уникальность заполнения связки Артикул-Название. if (String.IsNullOrWhiteSpace(TitleTextBox.Text) == false) TitleTextBox_Leave(null, null); }//ArticulTextBox_Leave
}//ArticulTextBox_Leave private void TitleTextBox_Leave(object sender, EventArgs e) { //Если Title введен. if (!String.IsNullOrWhiteSpace(TitleTextBox.Text)) { //Если в базе есть ещё объекты с таким Артикулом. if (ArticulBackPanel.BackColor == Color.Yellow) { //Если связка Артикул-Название не уникальны, выводим сообщение об ошибке. if (PartsDAL.FindSparePartsByArticul(ArticulTextBox.Text.Trim()).Any(sp => sp.Title.ToLower() == TitleTextBox.Text.Trim().ToLower())) ControlValidation.WrongValueInput(toolTip, TitleTextBox, "Такая связка Артикул-Название уже есть в базе"); else ControlValidation.CorrectValueInput(toolTip, TitleTextBox); }//if else //если tilte введен правильно ControlValidation.CorrectValueInput(toolTip, TitleTextBox); }//if else //если Title не введен { ControlValidation.WrongValueInput(toolTip, TitleTextBox); }//else }//TitleTextBox_Leave
}//addContactInfoButton_Click private void contragentNameTextBox_Leave(object sender, EventArgs e) { if (!String.IsNullOrWhiteSpace(contragentNameTextBox.Text)) { IContragent contragent = (_contragent is Customer) ? PartsDAL.FindCustomers(contragentNameTextBox.Text.Trim()) : PartsDAL.FindSuppliers(contragentNameTextBox.Text.Trim()); string text = contragentNameTextBox.Text.Trim().ToLower(); //Если контрагент с таким именем уже есть в базе и это не его редактирование, выдаём ошибку. if ((_contragent.ContragentId != 0 && _contragent.ContragentName.ToLower() == text) || contragent == null) { ControlValidation.CorrectValueInput(toolTip, contragentNameTextBox); } else { ControlValidation.WrongValueInput(toolTip, contragentNameTextBox, String.Format("Введите другое название или ФИО {0}а", _contragentType)); } } //if else //если название введено некорректно { ControlValidation.WrongValueInput(toolTip, contragentNameTextBox); } }//contragentNameTextBox_Leave