Пример #1
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();
         }
     }
 }
Пример #2
0
 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();
     }
 }
Пример #3
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);
            }
        }
        /// Кнопка добавления водителя
        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();
                }
            }
        }
        /// Добавить соответственно
        private void btn_add_Click(object sender, RoutedEventArgs e)
        {
            if (cb_drivers.Text == "")
            {
                MessageBox.Show("Водитель не выбран", "Внимание!", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (cb_contragent.Text == "")
            {
                MessageBox.Show("Контрагент не выбран", "Внимание!", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (dt_plan.Value == null)
            {
                MessageBox.Show("Дата плановой загрузки не заполнена!", "Внимание!", MessageBoxButton.OK,
                                MessageBoxImage.Error);
                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,
                        Auto        = tb_auto.Text,
                        Active      = "1",
                        ServiceInfo = DateTime.Now + " " + App.ActiveUser + " добавил водителя"
                    };

                    shipment.IdDriverNavigation = driver;
                }

                if (cb_contragent.SelectedItem != null)
                {
                    var current = cb_contragent.SelectedItem as Contragent;
                    shipment.IdContragent = current?.IdContragent;
                }
                else
                {
                    Contragent contragent = new Contragent
                    {
                        Name        = cb_contragent.Text,
                        Active      = "1",
                        ServiceInfo = DateTime.Now + " " + App.ActiveUser + " добавил контрагента"
                    };
                    shipment.IdContragentNavigation = contragent;
                }

                Time time = new Time
                {
                    //При добавлении можно сохранять прям DateTime? не боясь за null-ы
                    DateTimePlanRegist = dt_plan.Value,
                    DateTimeFactRegist = dt_fact.Value,
                    DateTimeArrive     = dt_arrive.Value,
                    DateTimeLoad       = dt_load.Value,
                    DateTimeEndLoad    = dt_endload.Value,
                    DateTimeLeft       = dt_left.Value
                };

                shipment.IdTimeNavigation = time;

                if (string.IsNullOrWhiteSpace(tb_numrealese.Text))
                {
                    shipment.NumRealese = tb_numrealese.Text;
                }

                if (string.IsNullOrWhiteSpace(tb_packetdoc.Text))
                {
                    shipment.PacketDocuments = tb_packetdoc.Text;
                }

                if (string.IsNullOrWhiteSpace(tb_tochkaload.Text))
                {
                    shipment.TochkaLoad = tb_tochkaload.Text;
                }

                if (string.IsNullOrWhiteSpace(tb_CountPodons.Text))
                {
                    shipment.CountPodons = tb_CountPodons.Text;
                }

                if (string.IsNullOrWhiteSpace(tb_nomencluture.Text))
                {
                    shipment.Nomenclature = tb_nomencluture.Text;
                }

                if (string.IsNullOrWhiteSpace(tb_size.Text))
                {
                    shipment.Size = tb_size.Text;
                }

                if (string.IsNullOrWhiteSpace(tb_Destination.Text))
                {
                    shipment.Destination = tb_Destination.Text;
                }

                if (string.IsNullOrWhiteSpace(tb_typeload.Text))
                {
                    shipment.TypeLoad = tb_typeload.Text;
                }

                if (string.IsNullOrWhiteSpace(tb_descript.Text))
                {
                    shipment.Description = tb_descript.Text;
                }

                if (string.IsNullOrWhiteSpace(tb_storekeeper.Text))
                {
                    shipment.StoreKeeper = tb_storekeeper.Text;
                }

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

                ef.Add(shipment);
                ef.SaveChanges();
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Программное исключене", MessageBoxButton.OK,
                                MessageBoxImage.Error);
            }
        }