Пример #1
0
        /// Добавить соответственно
        private void btn_add_Click(object sender, RoutedEventArgs e)
        {
            if (cb_drivers.Text != "")
            {
                if (cb_contragent.Text != "")
                {
                    if (dt_plan.Value != null)
                    {
                        try
                        {
                            using (DB.RegistrantCoreContext ef = new DB.RegistrantCoreContext())
                            {
                                DB.Shipment shipment = new DB.Shipment();

                                if (cb_drivers.SelectedItem != null)
                                {
                                    var test    = cb_drivers as ComboBox;
                                    var current = test.SelectedItem as Models.Drivers;
                                    shipment.IdDriver = current.IdDriver;
                                }
                                else
                                {
                                    //Если водителя нет в списках
                                    DB.Driver driver = new DB.Driver();
                                    shipment.IdDriverNavigation = driver;
                                    var temp = SplitNames(cb_drivers.Text + " ");

                                    driver.Name        = temp.name.Replace(" ", "");
                                    driver.Family      = temp.family.Replace(" ", "");
                                    driver.Patronymic  = temp.patronomyc.Replace(" ", "");
                                    driver.AutoNumber  = tb_autonum.Text;
                                    driver.Attorney    = tb_attorney.Text;
                                    driver.Phone       = tb_phone.Text;
                                    driver.Auto        = tb_auto.Text;
                                    driver.Active      = "1";
                                    driver.ServiceInfo = DateTime.Now + " " + App.ActiveUser + " добавил водителя";
                                }

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


                                DB.Time time = new DB.Time();
                                shipment.IdTimeNavigation = time;

                                if (dt_plan.Value != null)
                                {
                                    time.DateTimePlanRegist = dt_plan.Value;
                                }
                                if (dt_fact.Value != null)
                                {
                                    time.DateTimeFactRegist = dt_fact.Value;
                                }
                                if (dt_arrive.Value != null)
                                {
                                    time.DateTimeArrive = dt_arrive.Value;
                                }
                                if (dt_load.Value != null)
                                {
                                    time.DateTimeLoad = dt_load.Value;
                                }
                                if (dt_endload.Value != null)
                                {
                                    time.DateTimeEndLoad = dt_endload.Value;
                                }
                                if (dt_left.Value != null)
                                {
                                    time.DateTimeLeft = dt_left.Value;
                                }

                                if (tb_numrealese.Text != null)
                                {
                                    shipment.NumRealese = tb_numrealese.Text;
                                }
                                if (tb_packetdoc.Text != null)
                                {
                                    shipment.PacketDocuments = tb_packetdoc.Text;
                                }
                                if (tb_tochkaload.Text != null)
                                {
                                    shipment.TochkaLoad = tb_tochkaload.Text;
                                }
                                if (tb_CountPodons.Text != null)
                                {
                                    shipment.CountPodons = tb_CountPodons.Text;
                                }
                                if (tb_nomencluture.Text != null)
                                {
                                    shipment.Nomenclature = tb_nomencluture.Text;
                                }
                                if (tb_size.Text != null)
                                {
                                    shipment.Size = tb_size.Text;
                                }
                                if (tb_Destination.Text != null)
                                {
                                    shipment.Destination = tb_Destination.Text;
                                }
                                if (tb_typeload.Text != null)
                                {
                                    shipment.TypeLoad = tb_typeload.Text;
                                }
                                if (tb_descript.Text != null)
                                {
                                    shipment.Description = tb_descript.Text;
                                }
                                if (tb_storekeeper.Text != null)
                                {
                                    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);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Дата плановой загрузки не заполнена!", "Внимание!", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Контрагент не выбран", "Внимание!", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Водитель не выбран", "Внимание!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        /// Добавить соответственно
        private void btn_add_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (DB.RegistrantCoreContext ef = new DB.RegistrantCoreContext())
                {
                    DB.Shipment shipment = new DB.Shipment();

                    if (cb_drivers.SelectedItem != null)
                    {
                        var test    = cb_drivers as ComboBox;
                        var current = test.SelectedItem as Models.Drivers;
                        shipment.IdDriver = current.IdDriver;
                    }

                    DB.Time time = new DB.Time();
                    shipment.IdTimeNavigation = time;

                    if (dt_plan.Value != null)
                    {
                        time.DateTimePlanRegist = dt_plan.Value;
                    }
                    if (dt_fact.Value != null)
                    {
                        time.DateTimeFactRegist = dt_fact.Value;
                    }
                    if (dt_arrive.Value != null)
                    {
                        time.DateTimeArrive = dt_arrive.Value;
                    }
                    if (dt_load.Value != null)
                    {
                        time.DateTimeLoad = dt_load.Value;
                    }
                    if (dt_endload.Value != null)
                    {
                        time.DateTimeEndLoad = dt_endload.Value;
                    }
                    if (dt_left.Value != null)
                    {
                        time.DateTimeLeft = dt_left.Value;
                    }

                    if (tb_numrealese.Text != null)
                    {
                        shipment.NumRealese = tb_numrealese.Text;
                    }
                    if (tb_packetdoc.Text != null)
                    {
                        shipment.PacketDocuments = tb_packetdoc.Text;
                    }
                    if (tb_tochkaload.Text != null)
                    {
                        shipment.TochkaLoad = tb_tochkaload.Text;
                    }
                    if (tb_CountPodons.Text != null)
                    {
                        shipment.CountPodons = tb_CountPodons.Text;
                    }
                    if (tb_nomencluture.Text != null)
                    {
                        shipment.Nomenclature = tb_nomencluture.Text;
                    }
                    if (tb_size.Text != null)
                    {
                        shipment.Size = tb_size.Text;
                    }
                    if (tb_Destination.Text != null)
                    {
                        shipment.Destination = tb_Destination.Text;
                    }
                    if (tb_typeload.Text != null)
                    {
                        shipment.TypeLoad = tb_typeload.Text;
                    }
                    if (tb_descript.Text != null)
                    {
                        shipment.Description = tb_descript.Text;
                    }
                    if (tb_storekeeper.Text != null)
                    {
                        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);
            }
        }
Пример #3
0
        private void btn_add_add_Click(object sender, RoutedEventArgs e)
        {
            if (cb_drivers.Text == "")
            {
                return;
            }

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

                    if (cb_drivers.SelectedItem != null)
                    {
                        var test    = cb_drivers as ComboBox;
                        var current = test.SelectedItem as Models.Drivers;
                        shipment.IdDriver = current.IdDriver;
                    }
                    else
                    {
                        //Если водителя нет в списках
                        DB.Driver driver = new DB.Driver();
                        shipment.IdDriverNavigation = driver;
                        var temp = SplitNames(cb_drivers.Text + " ");

                        driver.Name        = temp.name.Replace(" ", "");
                        driver.Family      = temp.family.Replace(" ", "");
                        driver.Patronymic  = temp.patronomyc.Replace(" ", "");
                        driver.AutoNumber  = tb_autonum.Text;
                        driver.Attorney    = tb_attorney.Text;
                        driver.Phone       = tb_phone.Text;
                        driver.AutoNumber  = tb_autonum.Text;
                        driver.Passport    = tb_passport.Text;
                        driver.Active      = "1";
                        driver.ServiceInfo = DateTime.Now + " " + App.ActiveUser + " добавил водителя";
                    }

                    DB.Time time = new DB.Time();
                    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);
            }

            /*
             * if (tb_family.Text != "")
             * {
             *  try
             *  {
             *      using (DB.RegistrantCoreContext ef = new DB.RegistrantCoreContext())
             *      {
             *          DB.Shipment shipment = new DB.Shipment();
             *          shipment.IdDriverNavigation = new DB.Driver();
             *          shipment.IdTimeNavigation = new DB.Time();
             *          shipment.IdDriverNavigation.Family = tb_family.Text;
             *          shipment.IdDriverNavigation.Name = tb_name.Text;
             *          shipment.IdDriverNavigation.Patronymic = tb_patronymic.Text;
             *          shipment.IdDriverNavigation.Phone = tb_phone.Text;
             *          shipment.IdDriverNavigation.AutoNumber = tb_autonum.Text;
             *          shipment.IdDriverNavigation.Passport = tb_passport.Text;
             *          shipment.IdDriverNavigation.Info = tb_info.Text;
             *          shipment.IdDriverNavigation.ServiceInfo = DateTime.Now + " " + App.ActiveUser + " добавил карточку водителя";
             *
             *          shipment.IdTimeNavigation.DateTimeFactRegist = DateTime.Now;
             *
             *          shipment.ServiceInfo = DateTime.Now + " " + App.ActiveUser + " каскадное добавление с карточкой водителя";
             *
             *          ef.Add(shipment);
             *          ef.SaveChanges();
             *          ContentAdd.Hide();
             *          btn_refresh_Click(sender, e);
             *      }
             *  }
             *  catch (Exception ex)
             *  {
             *      ((MainWindow)System.Windows.Application.Current.MainWindow).ContentErrorText.ShowAsync();
             *      ((MainWindow)System.Windows.Application.Current.MainWindow).text_debuger.Text = ex.ToString();
             *  }
             * }
             * else
             * {
             *  MessageBox.Show("Введите хотябы фамилию водителя!", "Внимание!", MessageBoxButton.OK, MessageBoxImage.Error);
             * }*/
        }