/// Выбор водителя
        private void cb_drivers_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var current = cb_drivers.SelectedItem as Drivers;

            if (current != null)
            {
                try
                {
                    using RegistrantCoreContext ef = new RegistrantCoreContext();
                    var driver = ef.Drivers.FirstOrDefault(x => x.IdDriver == current.IdDriver);

                    if (driver != null)
                    {
                        tb_phone.Text    = driver.Phone;
                        tb_autonum.Text  = driver.AutoNumber;
                        tb_attorney.Text = driver.Attorney;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Программное исключене", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                tb_contragent.Text = "";
                tb_phone.Text      = "";
                tb_autonum.Text    = "";
            }
        }
        public List <KppShipments> GetShipments()
        {
            DriverShipments.Clear();

            try
            {
                using RegistrantCoreContext ef = new RegistrantCoreContext();
                var shipments = ef.Shipments.Where(x => (x.IdTimeNavigation.DateTimeLeft == null && x.IdTimeNavigation.DateTimeFactRegist != null && x.Active != "0")).OrderBy(x => x.IdDriverNavigation.Family);
                foreach (var item in shipments)
                {
                    KppShipments shipment = new KppShipments(item);
                    DriverShipments.Add(shipment);
                }
            }
            catch (Exception ex)
            {
                MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
                if (mainWindow != null)
                {
                    mainWindow.ContentErrorText.ShowAsync();
                    mainWindow.text_debuger.Text = ex.ToString();
                }
            }
            return(DriverShipments);
        }
Esempio n. 3
0
        /// <summary>
        /// Кнопка редактиировать из таблицы
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_edit_Click(object sender, RoutedEventArgs e)
        {
            var bt      = e.OriginalSource as Button;
            var current = bt?.DataContext as Contragent;

            if (current != null)
            {
                try
                {
                    text_editnamecontragent.Text   = $"Редактирование элемента {current.Name}";
                    using RegistrantCoreContext ef = new RegistrantCoreContext();
                    var contragent = ef.Contragents.FirstOrDefault(x => x.IdContragent == current.IdContragent);
                    if (contragent != null)
                    {
                        tb_idcontragent.Text = contragent.IdContragent.ToString();
                        tb_edit_name.Text    = contragent.Name;
                    }
                    ContentEdit.ShowAsync();
                }
                catch (Exception ex)
                {
                    MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
                    if (mainWindow != null)
                    {
                        mainWindow.ContentErrorText.ShowAsync();
                        mainWindow.text_debuger.Text = ex.ToString();
                    }
                }
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Кнопка сохранить изменения
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btn_save_edit_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using RegistrantCoreContext ef = new RegistrantCoreContext();
         var contragent = ef.Contragents.FirstOrDefault(x => x.IdContragent == Convert.ToInt32(tb_idcontragent.Text));
         if (contragent != null)
         {
             contragent.Name        = tb_edit_name.Text;
             contragent.ServiceInfo =
                 $"{contragent.ServiceInfo}\n {DateTime.Now} {App.ActiveUser} изменил название контрагента";
         }
         ef.SaveChanges();
         btn_refresh_Click(sender, e);
         ContentEdit.Hide();
     }
     catch (Exception ex)
     {
         MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
         if (mainWindow != null)
         {
             mainWindow.ContentErrorText.ShowAsync();
             mainWindow.text_debuger.Text = ex.ToString();
         }
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Покинули
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public List <Shipments> GetShipmentsLeft(DateTime date)
        {
            Shipments.Clear();

            try
            {
                using RegistrantCoreContext ef = new RegistrantCoreContext();
                var shipments = ef.Shipments.Where(x =>
                                                   (x.IdTimeNavigation.DateTimePlanRegist.Value.Date == date.Date ||
                                                    x.IdTimeNavigation.DateTimeFactRegist.Value.Date == date.Date) &&
                                                   x.IdTimeNavigation.DateTimeLeft != null && x.Active != "0")
                                .OrderBy(x => x.IdTimeNavigation.DateTimePlanRegist);

                foreach (var item in shipments)
                {
                    Shipments shipment = new Shipments(item);
                    Shipments.Add(shipment);
                }
            }
            catch (Exception ex)
            {
                MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
                if (mainWindow != null)
                {
                    mainWindow.ContentErrorText.ShowAsync();
                    mainWindow.text_debuger.Text = ex.ToString();
                }
            }
            return(Shipments);
        }
Esempio n. 6
0
        /// <summary>
        /// Показать инфу о контр агенте
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_info_Click(object sender, RoutedEventArgs e)
        {
            ContentInfo.ShowAsync();
            var bt      = e.OriginalSource as Button;
            var current = bt?.DataContext as Contragent;

            if (current != null)
            {
                try
                {
                    using RegistrantCoreContext ef = new RegistrantCoreContext();
                    var contragent = ef.Contragents.FirstOrDefault(x => x.IdContragent == current.IdContragent);
                    if (contragent != null)
                    {
                        text_namecontragent.Text = contragent.Name;
                        text_infocontragent.Text = contragent.ServiceInfo;
                    }
                }
                catch (Exception ex)
                {
                    MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
                    if (mainWindow != null)
                    {
                        mainWindow.ContentErrorText.ShowAsync();
                        mainWindow.text_debuger.Text = ex.ToString();
                    }
                }
            }
        }
        void LoadDrvAndContragents()
        {
            using RegistrantCoreContext ef = new RegistrantCoreContext();
            DriversController driver = new DriversController();

            cb_drivers.ItemsSource = driver.GetDriversCurrent();
        }
        /// Кнопка удалить
        private void btn_delete_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using RegistrantCoreContext ef = new RegistrantCoreContext();
                var driver = ef.Drivers.FirstOrDefault(x => x.IdDriver == Convert.ToInt32(tb_id.Text));
                if (driver != null)
                {
                    driver.Active      = "0";
                    driver.ServiceInfo = driver.ServiceInfo + "\n" + DateTime.Now + " " + App.ActiveUser + " удалил водителя";
                }

                ef.SaveChanges();
                ContentAddEdit.Hide();
                btn_refresh_Click(sender, e);
            }
            catch (Exception ex)
            {
                MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
                if (mainWindow != null)
                {
                    mainWindow.ContentErrorText.ShowAsync();
                    mainWindow.text_debuger.Text = ex.ToString();
                }
            }
        }
Esempio n. 9
0
        /// Действие на нажатие на кнопку Войти
        private void btn_enter_Click(object sender, RoutedEventArgs e)
        {
            Settings.User.Default.login = tb_login.Text;
            Settings.User.Default.Save();

            try
            {
                using RegistrantCoreContext ef = new RegistrantCoreContext();
                var user = ef.Users.FirstOrDefault(x => tb_login.Text == x.Login && tb_password.Password == x.Password);

                if (user != null)
                {
                    ContentAuth.Hide();
                    App.SetActiveUser(user.Name);
                    App.SetLevelAccess(user.LevelAccess);
                    NavUI.PaneTitle     = "РЕГИСТРАНТ (" + user.Name + ")";
                    nav_userset.Content = user.Name;
                    _pageUser           = new PageUser(user.IdUser);

                    Thread thread = new Thread(Verify);
                    thread.Start();
                }
                else
                {
                    MessageBox.Show("Логин и/или пароль неверный", "Ошибка входа", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            catch (Exception ex)
            {
                Dispatcher.Invoke(() => ContentWait.Hide());
                Dispatcher.Invoke(() => ContentError.ShowAsync());
                Dispatcher.Invoke(() => text_error.Text = ex.ToString());
            }
        }
        //Только активные для чекбокса
        public List <Drivers> GetDriversCurrent()
        {
            Driver.Clear();
            try
            {
                using RegistrantCoreContext ef = new RegistrantCoreContext();
                var drivers = ef.Drivers.Where(x => x.Active != "0").OrderBy(x => x.Family);

                foreach (var item in drivers)
                {
                    Drivers driver = new Drivers(item);
                    Driver.Add(driver);
                }
            }
            catch (Exception ex)
            {
                MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
                if (mainWindow != null)
                {
                    mainWindow.ContentErrorText.ShowAsync();
                    mainWindow.text_debuger.Text = ex.ToString();
                }
            }
            return(Driver);
        }
Esempio n. 11
0
        /// <summary>
        /// Получение всего
        /// </summary>
        /// <returns></returns>
        public List <Shipments> GetShipmentsAll()
        {
            Shipments.Clear();

            try
            {
                using RegistrantCoreContext ef = new RegistrantCoreContext();
                var shipments = ef.Shipments.OrderBy(x => x.IdTimeNavigation.DateTimePlanRegist);
                foreach (var item in shipments)
                {
                    Shipments shipment = new Shipments(item);
                    Shipments.Add(shipment);
                }
            }
            catch (Exception ex)
            {
                MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
                if (mainWindow != null)
                {
                    mainWindow.ContentErrorText.ShowAsync();
                    mainWindow.text_debuger.Text = ex.ToString();
                }
            }
            return(Shipments);
        }
 private void btn_add_add_Click(object sender, RoutedEventArgs e)
 {
     ContentAddUser.Hide();
     if (tb_login.Text != "")
     {
         try
         {
             using RegistrantCoreContext ef = new RegistrantCoreContext();
             User user = new User
             {
                 Name     = tb_name.Text,
                 Login    = tb_login.Text,
                 Password = tb_pass.Text
             };
             user.LevelAccess = cb_access.SelectedIndex switch
             {
                 0 => "kpp",
                 1 => "reader",
                 2 => "warehouse",
                 3 => "shipment",
                 4 => "admin",
                 _ => user.LevelAccess
             };
             ef.Add(user);
             ef.SaveChanges();
             LoadUser();
         }
         catch (Exception ex)
         {
             ((MainWindow)Application.Current.MainWindow).ContentErrorText.ShowAsync();
             ((MainWindow)Application.Current.MainWindow).text_debuger.Text = ex.ToString();
         }
         ContentSave.ShowAsync();
     }
 }
Esempio n. 13
0
 /// <summary>
 /// Кнопка добавление, реального добавления
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btn_add_add_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using RegistrantCoreContext ef = new RegistrantCoreContext();
         Contragent contragent = new Contragent
         {
             Name        = tb_namecontragent.Text,
             ServiceInfo = $"{DateTime.Now} {App.ActiveUser} добавил контрагента",
             Active      = "1"
         };
         ef.Add(contragent);
         ef.SaveChanges();
         ContentAdd.Hide();
     }
     catch (Exception ex)
     {
         MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
         if (mainWindow != null)
         {
             mainWindow.ContentErrorText.ShowAsync();
             mainWindow.text_debuger.Text = ex.ToString();
         }
     }
 }
Esempio n. 14
0
 /// <summary>
 /// Обновление в потоке
 /// </summary>
 void RefreshThread()
 {
     while (true)
     {
         Thread.Sleep(Settings.App.Default.RefreshContent);
         try
         {
             using RegistrantCoreContext ef = new RegistrantCoreContext();
             var contragents = ef.Contragents.Where(x => x.Active != "0")
                               .OrderBy(x => x.Name).ToList();
             Dispatcher.Invoke(() => DataGrid_Contragents.ItemsSource = contragents);
             Dispatcher.Invoke(() => DataGrid_Contragents.Items.Refresh());
         }
         catch (Exception ex)
         {
             Dispatcher.Invoke(() =>
             {
                 MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
                 if (mainWindow != null)
                 {
                     mainWindow.ContentErrorText.ShowAsync();
                     mainWindow.text_debuger.Text = ex.ToString();
                 }
             });
         }
     }
 }
Esempio n. 15
0
        private void btn_load_Click(object sender, RoutedEventArgs e)
        {
            var bt      = e.OriginalSource as Button;
            var current = bt?.DataContext as Shipments;

            if (current != null)
            {
                MessageBoxResult?result = MessageBox.Show("Сменить статус водителя " + current.Fio + " на Загрузка начата?", "Внимание", MessageBoxButton.YesNo, MessageBoxImage.Information);
                if (result == MessageBoxResult.Yes)
                {
                    try
                    {
                        using RegistrantCoreContext ef = new RegistrantCoreContext();
                        var shipment = ef.Shipments.FirstOrDefault(x => x.IdShipment == current.IdShipment);
                        if (shipment != null)
                        {
                            shipment.IdTimeNavigation.DateTimeLoad = DateTime.Now;
                        }
                        ef.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
                        if (mainWindow != null)
                        {
                            mainWindow.ContentErrorText.ShowAsync();
                            mainWindow.text_debuger.Text = ex.ToString();
                        }
                        ;
                    }
                }
            }

            btn_refresh_Click(sender, e);
        }
        /// <summary>
        /// Открыть окно с расширенной информацией
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_info_Click(object sender, RoutedEventArgs e)
        {
            var bt      = e.OriginalSource as Button;
            var current = bt?.DataContext as Drivers;

            if (current != null)
            {
                try
                {
                    using RegistrantCoreContext ef = new RegistrantCoreContext();
                    ContentInfo.ShowAsync();
                    ContentInfoGrid.DataContext = ef.Drivers.FirstOrDefault(x => x.IdDriver == current.IdDriver);
                    text_info_namedriver.Text   = current.Fio;
                }
                catch (Exception ex)
                {
                    MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
                    if (mainWindow != null)
                    {
                        mainWindow.ContentErrorText.ShowAsync();
                        mainWindow.text_debuger.Text = ex.ToString();
                    }
                }
            }
        }
Esempio n. 17
0
        private void btn_add_add_Click(object sender, RoutedEventArgs e)
        {
            if (cb_drivers.Text == "")
            {
                return;
            }

            try
            {
                using RegistrantCoreContext ef = new RegistrantCoreContext();
                Shipment shipment = new Shipment();

                if (cb_drivers.SelectedItem != null)
                {
                    var current = cb_drivers.SelectedItem as Drivers;
                    shipment.IdDriver = current?.IdDriver;
                }
                else
                {
                    //Если водителя нет в списках
                    var    splitNames = SplitNames(cb_drivers.Text + " ");
                    Driver driver     = new Driver
                    {
                        Name        = splitNames.name.Replace(" ", ""),
                        Family      = splitNames.family.Replace(" ", ""),
                        Patronymic  = splitNames.patronomyc.Replace(" ", ""),
                        AutoNumber  = tb_autonum.Text,
                        Attorney    = tb_attorney.Text,
                        Phone       = tb_phone.Text,
                        Passport    = tb_passport.Text,
                        Active      = "1",
                        ServiceInfo = DateTime.Now + " " + App.ActiveUser + " добавил водителя"
                    };
                    shipment.IdDriverNavigation = driver;
                }

                Time time = new Time
                {
                    DateTimeFactRegist = DateTime.Now
                };
                shipment.IdTimeNavigation = time;

                shipment.Description = tb_info.Text;
                shipment.Active      = "1";
                shipment.ServiceInfo = DateTime.Now + " " + App.ActiveUser + " добавил отгрузку";

                ef.Add(shipment);
                ef.SaveChanges();
                ContentAdd.Hide();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Программное исключене", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
 void LoadUser()
 {
     try
     {
         using RegistrantCoreContext ef = new RegistrantCoreContext();
         DataGrid_Users.ItemsSource     = ef.Users.OrderBy(x => x.IdUser).ToList();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString(), "Программное исключене", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Esempio n. 19
0
        //Кнопка удалить
        private void btn_delete_Click(object sender, RoutedEventArgs e)
        {
            if (tb_idcontragent != null)
            {
                try
                {
                    using RegistrantCoreContext ef = new RegistrantCoreContext();
                    var temp = ef.Contragents.FirstOrDefault(x => x.IdContragent == Convert.ToInt32(tb_idcontragent.Text));
                    if (temp != null)
                    {
                        temp.Active = "0";
                    }
                    ef.SaveChanges();
                    ContentEdit.Hide();
                }
                catch (Exception ex)
                {
                    MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
                    if (mainWindow != null)
                    {
                        mainWindow.ContentErrorText.ShowAsync();
                        mainWindow.text_debuger.Text = ex.ToString();
                    }
                }
            }
            //Кнопа перенесена в другоме место,

            /*var bt = e.OriginalSource as Button;
             * var current = bt.DataContext as DB.Contragent;
             *
             * try
             * {
             *  using RegistrantCoreContext ef = new RegistrantCoreContext();
             *  var contragent = ef.Contragents.FirstOrDefault(x => x.IdContragent == current.IdContragent);
             *  if (contragent != null)
             *  {
             *      contragent.Active = "0";
             *      contragent.ServiceInfo = $"{contragent.ServiceInfo}\n{DateTime.Now} {App.ActiveUser} изменил удалил";
             *  }
             *  ef.SaveChanges();
             *  btn_refresh_Click(sender, e);
             * }
             * catch (Exception ex)
             * {
             *  MainWindow mainWindow = (MainWindow) Application.Current.MainWindow;
             *  if (mainWindow != null)
             *  {
             *      mainWindow.ContentErrorText.ShowAsync();
             *      mainWindow.text_debuger.Text = ex.ToString();
             *  }
             * }
             * }*/
        }
        /// Подгрузка водителей
        void LoadDrvAndContragents()
        {
            try
            {
                using RegistrantCoreContext ef = new RegistrantCoreContext();
                Controllers.DriversController driver = new Controllers.DriversController();

                cb_drivers.ItemsSource    = driver.GetDriversCurrent();
                cb_contragent.ItemsSource = ef.Contragents.Where(x => x.Active != "0").OrderBy(x => x.Name).ToList();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Программное исключене", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        /// Кнопка открыть окно редактирования
        private void btn_edit_Click(object sender, RoutedEventArgs e)
        {
            var bt      = e.OriginalSource as Button;
            var current = bt?.DataContext as Models.Drivers;

            ClearTextbox();

            btn_edit.Visibility   = Visibility.Visible;
            btn_add.Visibility    = Visibility.Collapsed;
            btn_delete.Visibility = Visibility.Visible;
            if (current == null)
            {
                return;
            }
            try
            {
                using RegistrantCoreContext ef = new RegistrantCoreContext();
                var driver = ef.Drivers.FirstOrDefault(x => x.IdDriver == current.IdDriver);

                if (driver != null)
                {
                    text_namedriver.Text = driver.Family + " " + driver.Name + " " + driver.Patronymic;

                    tb_id.Text         = driver.IdDriver.ToString();
                    tb_Family.Text     = driver.Family;
                    tb_name.Text       = driver.Name;
                    tb_patronomyc.Text = driver.Patronymic;
                    tb_phone.Text      = driver.Phone;

                    tb_attorney.Text = driver.Attorney;
                    tb_auto.Text     = driver.Auto;
                    tb_autonum.Text  = driver.AutoNumber;
                    tb_passport.Text = driver.Passport;
                    tb_info.Text     = driver.Info;
                }
                ContentAddEdit.ShowAsync();
            }
            catch (Exception ex)
            {
                MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
                if (mainWindow != null)
                {
                    mainWindow.ContentErrorText.ShowAsync();
                    mainWindow.text_debuger.Text = ex.ToString();
                }
            }
        }
 private void btn_30d_delete_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using RegistrantCoreContext ef = new RegistrantCoreContext();
         DateTime last30       = DateTime.Now.Date.AddDays(-30);
         DateTime currentMonth = DateTime.Now.Date;
         //var temp = ef.Shipments.Where(x => (x.IdTimeNavigation.DateTimeLeft > last30) && x.IdDriverNavigation.Active != "0" && x.IdTimeNavigation.DateTimeFactRegist.Value.Month == currentMonth.Month);
     }
     catch (Exception ex)
     {
         MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
         if (mainWindow != null)
         {
             mainWindow.ContentErrorText.ShowAsync();
             mainWindow.text_debuger.Text = ex.ToString();
         }
     }
 }
Esempio n. 23
0
        /// Проверка существует ли вообще подключение к серверу
        void TestConnect()
        {
            //Thread.Sleep(2000);
            Dispatcher.Invoke(() => ContentWait.ShowAsync());

            try
            {
                using RegistrantCoreContext ef = new RegistrantCoreContext();
                var engines = ef.Engines.ToList();
                Dispatcher.Invoke(() => ContentWait.Hide());
                Dispatcher.Invoke(() => ContentAuth.ShowAsync());
            }
            catch (Exception ex)
            {
                Dispatcher.Invoke(() => ContentWait.Hide());
                Dispatcher.Invoke(() => ContentError.ShowAsync());
                Dispatcher.Invoke(() => text_error.Text = ex.ToString());
            }
        }
Esempio n. 24
0
 /// <summary>
 /// Первый старт, подгрузка данных
 /// </summary>
 void FirstLoad()
 {
     try
     {
         using RegistrantCoreContext ef = new RegistrantCoreContext();
         var contragents = ef.Contragents
                           .Where(x => x.Active != "0")
                           .OrderByDescending(x => x.IdContragent).ToList();
         DataGrid_Contragents.ItemsSource = contragents;
     }
     catch (Exception ex)
     {
         MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
         if (mainWindow != null)
         {
             mainWindow.ContentErrorText.ShowAsync();
             mainWindow.text_debuger.Text = ex.ToString();
         }
     }
 }
        /// Кнопка добавления водителя
        private void btn_add_Click(object sender, RoutedEventArgs e)
        {
            if (tb_Family.Text == "")
            {
                MessageBox.Show("Введите хотя бы фамилию водителя!", "Внимание!", MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }

            try
            {
                using RegistrantCoreContext ef = new RegistrantCoreContext();
                Driver driver = new Driver
                {
                    Family      = tb_Family.Text,
                    Name        = tb_name.Text,
                    Patronymic  = tb_patronomyc.Text,
                    Phone       = tb_phone.Text,
                    Attorney    = tb_attorney.Text,
                    Auto        = tb_auto.Text,
                    AutoNumber  = tb_autonum.Text,
                    Passport    = tb_passport.Text,
                    Info        = tb_info.Text,
                    Active      = "1",
                    ServiceInfo = DateTime.Now + " " + App.ActiveUser + " добавил водителя"
                };

                ef.Add(driver);
                ef.SaveChanges();
                btn_close_Click(sender, e);
            }
            catch (Exception ex)
            {
                MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
                if (mainWindow != null)
                {
                    mainWindow.ContentErrorText.ShowAsync();
                    mainWindow.text_debuger.Text = ex.ToString();
                }
            }
        }
Esempio n. 26
0
 //Обновить
 private void btn_refresh_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using RegistrantCoreContext ef = new RegistrantCoreContext();
         var contragents = ef.Contragents
                           .Where(x => x.Active != "0")
                           .OrderByDescending(x => x.IdContragent).ToList();
         DataGrid_Contragents.ItemsSource = null;
         DataGrid_Contragents.ItemsSource = contragents;
     }
     catch (Exception ex)
     {
         MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
         if (mainWindow != null)
         {
             mainWindow.ContentErrorText.ShowAsync();
             mainWindow.text_debuger.Text = ex.ToString();
         }
     }
 }
        private void btn_del_yes_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using RegistrantCoreContext ef = new RegistrantCoreContext();
                var shipment = ef.Shipments.FirstOrDefault(x => x.IdShipment == Convert.ToInt32(idcont.Text));
                if (shipment != null)
                {
                    shipment.Active      = "0";
                    shipment.Description = shipment.Description + " " + tb_reasofordel.Text;
                    shipment.ServiceInfo = shipment.ServiceInfo + "\n" + DateTime.Now + " " + App.ActiveUser +
                                           " удалил отгрузку";
                }

                ef.SaveChanges();
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void btn_deluser_Click(object sender, RoutedEventArgs e)
        {
            var bt      = e.OriginalSource as Button;
            var current = bt?.DataContext as User;

            if (current != null)
            {
                try
                {
                    using RegistrantCoreContext ef = new RegistrantCoreContext();
                    ef.Remove(current);
                    ef.SaveChanges();
                    LoadUser();
                    ContentSave.ShowAsync();
                }
                catch (Exception ex)
                {
                    ((MainWindow)Application.Current.MainWindow).ContentErrorText.ShowAsync();
                    ((MainWindow)Application.Current.MainWindow).text_debuger.Text = ex.ToString();
                }
            }
        }
        /// Кнопка добавить водителя
        private void btn_add_driver_Click(object sender, RoutedEventArgs e)
        {
            ContentAddEdit.ShowAsync();
            ClearTextbox();
            text_namedriver.Text = "Добавить нового водителя";

            try
            {
                using RegistrantCoreContext ef = new RegistrantCoreContext();
                btn_add.Visibility             = Visibility.Visible;
                btn_delete.Visibility          = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
                if (mainWindow != null)
                {
                    mainWindow.ContentErrorText.ShowAsync();
                    mainWindow.text_debuger.Text = ex.ToString();
                }
            }
        }
        /// Непосредственное редактирование
        private void btn_edit_Click1(object sender, RoutedEventArgs e)
        {
            try
            {
                using RegistrantCoreContext ef = new RegistrantCoreContext();
                var driver = ef.Drivers.FirstOrDefault(x => x.IdDriver == Convert.ToInt32(tb_id.Text));
                if (driver != null)
                {
                    driver.Family     = tb_Family.Text;
                    driver.Name       = tb_name.Text;
                    driver.Patronymic = tb_patronomyc.Text;
                    driver.Phone      = tb_phone.Text;

                    driver.Attorney    = tb_attorney.Text;
                    driver.Auto        = tb_auto.Text;
                    driver.AutoNumber  = tb_autonum.Text;
                    driver.Passport    = tb_passport.Text;
                    driver.Info        = tb_info.Text;
                    driver.ServiceInfo = driver.ServiceInfo + "\n" + DateTime.Now + " " + App.ActiveUser + " внес изменения";
                    ef.SaveChanges();
                    btn_close_Click(sender, e);
                    ContentAddEdit.Hide();
                }

                ef.SaveChanges();
                btn_close_Click(sender, e);
                ContentAddEdit.Hide();
                btn_refresh_Click(sender, e);
            }
            catch (Exception ex)
            {
                MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
                if (mainWindow != null)
                {
                    mainWindow.ContentErrorText.ShowAsync();
                    mainWindow.text_debuger.Text = ex.ToString();
                }
            }
        }