Exemple #1
0
        private void ButtonSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxNumber.Text) ||
                string.IsNullOrEmpty(textBoxModel.Text) ||
                string.IsNullOrEmpty(textBoxLabel.Text) ||
                string.IsNullOrEmpty(textBoxColor.Text) ||
                string.IsNullOrEmpty(textBoxYear.Text) ||
                comboBoxClient.SelectedValue == null)
            {
                MessageBox.Show("Заполните все поля", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                transportLogic.CreateOrUpdate(new TransportBindingModel
                {
                    Id       = idForUpd,
                    Number   = textBoxNumber.Text,
                    Model    = textBoxModel.Text,
                    Label    = textBoxLabel.Text,
                    Color    = textBoxColor.Text,
                    Year     = textBoxYear.Text,
                    ClientId = Convert.ToInt32(comboBoxClient.SelectedValue)
                });
                MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ClearForms();
            LoadData();
        }
 private void buttonSave_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(textBoxViewTransport.Text) || string.IsNullOrEmpty(textBoxPrice.Text))
     {
         MessageBox.Show("Заполните все поля", "Ошибка", MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
         return;
     }
     try
     {
         if (dataGridView.SelectedRows.Count != 1)
         {
             return;
         }
         var route = _logicR.Read(new RouteBindingModel {
             Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)
         })?[0];
         TransportBindingModel model = new TransportBindingModel
         {
             Routefrom     = route.Cityfrom,
             Routeto       = route.Cityto,
             Routeid       = route.Id,
             Viewtransport = textBoxViewTransport.Text,
             Priceticket   = Convert.ToInt32(textBoxPrice.Text)
         };
         if (Id.HasValue)
         {
             model.Id = Id;
         }
         _logicT.CreateOrUpdate(model);
         MessageBox.Show("Успешно", "Сохранено",
                         MessageBoxButtons.OK, MessageBoxIcon.Information);
         DialogResult = DialogResult.OK;
         Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.InnerException?.Message + "\n" + ex.Message, "Ошибка",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
 }