Пример #1
0
        public void LoadListAllWithDel()
        {
            driverVs = new ObservableCollection <DriverV>();

            //Временный лист из бд
            DB.RegistrantEntities ef = new DB.RegistrantEntities();

            //Пихаем в листы только у тех у кого не проставлено время ппокидания скалада
            List <DB.Registrants> drivers = ef.Registrants.ToList();

            //Перебор в листах данных
            foreach (var item in drivers)
            {
                DriverV driverV = new DriverV(item);
                driverVs.Add(driverV);
            }

            //Сортировка по последним записям
            var d = driverVs.OrderByDescending(x => x.Id).ToList();

            //Очистка шлаков и токсинов
            driverVs.Clear();

            //Тот же самый перебор данных только в уже в основной лист (который был очищен) типа как цикл foreach
            d.ForEach(x => driverVs.Add(x));

            ef.Dispose();
        }
Пример #2
0
        public EditDriver(int id)
        {
            InitializeComponent();

            try
            {
                DB.RegistrantEntities ef = new DB.RegistrantEntities();

                var temp = ef.Registrants.Where(x => x.Id == id).FirstOrDefault();
                tb_id.Text         = temp.Id.ToString();
                tb_firstname.Text  = temp.FirstName;
                tb_secondname.Text = temp.SecondName;
                tb_phone.Text      = temp.Phone;

                tb_DateTime.Text   = temp.DateTime.ToString();
                tb_TimeArrive.Text = temp.TimeArrive.ToString();
                tb_TimeLEft.Text   = temp.TimeLeft.ToString();

                ef.Dispose();
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #3
0
        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);
                    }
                }
            }
        }
Пример #4
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                DB.RegistrantEntities ef = new DB.RegistrantEntities();
                var temp = ef.Registrants.Where(x => x.Id.ToString() == tb_id.Text).FirstOrDefault();
                temp.FirstName  = tb_firstname.Text;
                temp.SecondName = tb_secondname.Text;
                temp.Phone      = tb_phone.Text;

                var info2 = temp.Info + "\n-----" + tb_info.Text + "\n[I]" + DateTime.Now + " (" + Registrant.Default.LastLogin + ") изменил данные. (" + temp.FirstName + " " + temp.SecondName + ", " + temp.Phone + ")";
                temp.Info = info2;

                ef.SaveChanges();
                ef.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            this.Close();
        }