コード例 #1
0
ファイル: Driver.cs プロジェクト: maksim789456/RegistrantKPP
        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 btn_done_TimeArrive_Click(object sender, RoutedEventArgs e)
        {
            BlurEffect effect = new BlurEffect {
                Radius = 50
            };

            MainGrid.Effect = effect;

            MessageBoxResult result = MessageBox.Show("Вы действительно хотите обнвить статус водителя " + tb_firstname.Text + " " + tb_secondname.Text + " на ПРИБЫЛ?", "Внимание!", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                try
                {
                    using (DB.RegistrantEntities ef = new DB.RegistrantEntities())
                    {
                        var driver = ef.Registrants.FirstOrDefault(x => x.Id.ToString() == tb_id.Text);
                        if (driver != null)
                        {
                            driver.TimeArrive = DateTime.Now;
                            ef.SaveChanges();
                        }
                    }
                    Refresh();
                    btn_done_TimeArrive.Visibility = Visibility.Collapsed;

                    MessageBox.Show("Данные успешно обновлены", "Готово", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                catch (Exception)
                {
                    MessageBox.Show("Произошла ошибка при сохранении данных. Проверьте подключение к БД/правильность данных и еще что нибудь да проверьте", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            MainGrid.Effect = null;
        }
コード例 #5
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();
        }
コード例 #6
0
        private void btn_delete_Click(object sender, RoutedEventArgs e)
        {
            BlurEffect effect = new BlurEffect {
                Radius = 50
            };

            MainGrid.Effect = effect;

            MessageBoxResult result = MessageBox.Show("Вы действительно ходите удалить карточку №" + tb_id.Text + " на имя " + tb_firstname.Text + " " + tb_secondname.Text, "Внимание!", MessageBoxButton.YesNo, MessageBoxImage.Information);

            if (result == MessageBoxResult.Yes)
            {
                try
                {
                    using (DB.RegistrantEntities ef = new DB.RegistrantEntities())
                    {
                        var driver = ef.Registrants.FirstOrDefault(x => x.Id.ToString() == tb_id.Text);
                        if (driver != null)
                        {
                            driver.Deleted = "D";
                            driver.Info    =
                                $"{driver.Info}\n[I]{DateTime.Now}({Registrant.Default.LastLogin}) удалил карточку";
                        }
                        ef.SaveChanges();
                    }
                    Refresh();
                    Driver_Info.Visibility       = Visibility.Hidden;
                    Grid_ChooseDriver.Visibility = Visibility.Visible;

                    MessageBox.Show("Карточка успешно удалена", "Готово", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                catch (Exception)
                {
                    MessageBox.Show("Произошла ошибка при сохранении данных. Проверьте подключение к БД/правильность данных и еще что нибудь да проверьте", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            MainGrid.Effect = null;
        }