private void Button_Click(object sender, RoutedEventArgs e) { if (tb_firstname.Text == "" && tb_secondname.Text == "" && tb_phone.Text == "") { MessageBox.Show("Не все требуемые поля заполнены", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Exclamation); } else { MessageBoxResult result = MessageBox.Show("Будет произведена регистрация водителя: " + tb_firstname.Text + " " + tb_secondname.Text + " " + tb_phone.Text, "Внимание!", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { try { DB.RegistrantEntities ef = new DB.RegistrantEntities(); registrants = new DB.Registrants(); registrants.FirstName = tb_firstname.Text; registrants.SecondName = tb_secondname.Text; registrants.Phone = tb_phone.Text; registrants.DateTime = DateTime.Now; registrants.Info = tb_info.Text + "\n-----" + "\n[I]" + DateTime.Now + " (" + Registrant.Default.LastLogin + ") создал карточку (" + tb_secondname.Text + " " + tb_secondname.Text + ", " + tb_secondname.Text + ")"; ef.Registrants.Add(registrants); ef.SaveChanges(); MessageBox.Show("Водитель зарегистрирован", "Готово", MessageBoxButton.OK, MessageBoxImage.Information); ef.Dispose(); this.Close(); } catch (Exception) { MessageBox.Show("Произошла ошибка при регистрации. Пожалуйста обратитесь к персоналу. Проверьте подключение к БД/интернет или еще что нибудь", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } } } }
public DriverV(DB.Registrants registrants) { Id = registrants.Id; FirstName = registrants.FirstName; SecondName = registrants.SecondName; DateTime = registrants.DateTime.ToString(); Phone = registrants.Phone; Info = registrants.Info; TimeArrive = registrants.TimeArrive.ToString(); TimeLeft = registrants.TimeLeft.ToString(); Deleted = registrants.Deleted; if (registrants.DateTime != null) { Status = "Зарегистрирован"; if (registrants.TimeArrive != null) { Status = "Прибыл на территорию склада"; if (registrants.TimeLeft != null) { Status = "Покинул территорию склада"; } } } if (registrants.TimeArrive == null) { btn_Left = "Collapsed"; btn_Arrive = "Visible"; } else { btn_Left = "Visible"; btn_Arrive = "Collapsed"; } }