private void btnCreateWayBill_Click(object sender, EventArgs e) { if (textBoxClient.Text == "" || textBoxTrip.Text == "" || comboBoxCar.Text == "" || comboBoxDriver.Text == "" || !pickerStart.Checked) { MessageBox.Show("Вы ввели не все данные!"); return; } if (pickerEnd.Checked && pickerEnd.Value < pickerStart.Value) { MessageBox.Show("Дата выгрузки не может быть меньше даты закрузки!"); } WayBillMapper wm = new WayBillMapper(); if (wayBill == null) { insWayBill.Car = new CarMapper().Get(comboBoxCar.SelectedValue.ToString()); insWayBill.Driver = new EmployeeMapper().Get(comboBoxDriver.SelectedValue.ToString()); insWayBill.LoadDate = pickerStart.Value; if (!pickerEnd.Checked) { insWayBill.UnloadDate = null; } else { insWayBill.UnloadDate = pickerEnd.Value; } insWayBill.BaseDocument = textBoxBaseDoc.Text; insWayBill.Kilometers = (textBoxKm.Text == "") ? default : int.Parse(textBoxKm.Text); insWayBill.Cost = (txtBoxCost.Text == "") ? default : double.Parse(txtBoxCost.Text); insWayBill.Fuel = (textBoxFuel.Text == "") ? default : float.Parse(textBoxFuel.Text); insWayBill.Notes = textBoxNotes.Text; try { wm.Insert(insWayBill); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } else { wayBill.Car = new CarMapper().Get(comboBoxCar.SelectedValue.ToString()); wayBill.Driver = new EmployeeMapper().Get(comboBoxDriver.SelectedValue.ToString()); wayBill.LoadDate = pickerStart.Value; if (!pickerEnd.Checked) { wayBill.UnloadDate = null; } else { wayBill.UnloadDate = pickerEnd.Value; } wayBill.BaseDocument = textBoxBaseDoc.Text; wayBill.Kilometers = int.Parse(textBoxKm.Text); wayBill.Cost = double.Parse(txtBoxCost.Text); wayBill.Fuel = float.Parse(textBoxFuel.Text); wayBill.Notes = textBoxNotes.Text; try { wm.Update(wayBill); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } Form1.WindowIndex = WindowsStruct.ActiveWayBills; DataSets.CreateDSForDataGrid(Form1.WindowIndex, mainForm.dataGridView); this.Close(); }