private void ButtonSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxMaterialName.Text) ||
                string.IsNullOrEmpty(textBoxMaterialInfo.Text) ||
                string.IsNullOrEmpty(textBoxMaterialPrice.Text) ||
                comboBoxWorktype.SelectedValue == null)
            {
                MessageBox.Show("Заполните все поля", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                materialLogic.CreateOrUpdate(new MaterialBindingModel
                {
                    Id         = idForUpd,
                    Name       = textBoxMaterialName.Text,
                    Info       = textBoxMaterialInfo.Text,
                    Price      = Convert.ToInt32(textBoxMaterialPrice.Text),
                    WorktypeId = Convert.ToInt32(comboBoxWorktype.SelectedValue)
                });
                MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ClearForms();
            LoadData();
        }
Пример #2
0
 private void btnAdd_Click(object sender, RoutedEventArgs e)
 {
     if (string.IsNullOrEmpty(tbName.Text))
     {
         MessageBox.Show("Заполните название", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
         return;
     }
     try
     {
         _logic.CreateOrUpdate(new MaterialBindingModel
         {
             Id    = id,
             Price = Convert.ToInt32(tbPrice.Text),
             Name  = tbName.Text,
         });
         MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButton.OK, MessageBoxImage.Information);
         this.DialogResult = true;
         Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }