示例#1
0
 /// <summary>
 /// Кнопка добавление, реального добавления
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btn_add_add_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using (DB.RegistrantCoreContext ef = new DB.RegistrantCoreContext())
         {
             DB.Contragent contragent = new DB.Contragent();
             contragent.Name        = tb_namecontragent.Text;
             contragent.ServiceInfo = DateTime.Now + " " + App.ActiveUser + " добавил контрагента";
             contragent.Active      = "1";
             ef.Add(contragent);
             ef.SaveChanges();
             //btn_refresh_Click(sender, e);
             ContentAdd.Hide();
         }
     }
     catch (Exception ex)
     {
         ((MainWindow)System.Windows.Application.Current.MainWindow).ContentErrorText.ShowAsync();
         ((MainWindow)System.Windows.Application.Current.MainWindow).text_debuger.Text = ex.ToString();
     }
 }
示例#2
0
        /// Кнопка редактировать
        private void btn_edit_Click(object sender, RoutedEventArgs e)
        {
            if (App.LevelAccess == "shipment")
            {
                if (cb_drivers.Text != "")
                {
                    if (cb_contragent.Text != "")
                    {
                        try
                        {
                            using (DB.RegistrantCoreContext ef = new DB.RegistrantCoreContext())
                            {
                                var shipment = ef.Shipments.FirstOrDefault(x => x.IdShipment == Convert.ToInt64(idcont.Text));

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

                                    shipment.IdDriverNavigation.Phone      = tb_phone.Text;
                                    shipment.IdDriverNavigation.Attorney   = tb_attorney.Text;
                                    shipment.IdDriverNavigation.Auto       = tb_auto.Text;
                                    shipment.IdDriverNavigation.AutoNumber = tb_autonum.Text;
                                }
                                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.Auto        = tb_auto.Text;
                                    driver.AutoNumber  = tb_autonum.Text;
                                    driver.Attorney    = tb_attorney.Text;
                                    driver.Phone       = tb_phone.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;
                                }



                                if (dt_plan.Value != null)
                                {
                                    shipment.IdTimeNavigation.DateTimePlanRegist = dt_plan.Value;
                                }
                                if (dt_fact.Value != null)
                                {
                                    shipment.IdTimeNavigation.DateTimeFactRegist = dt_fact.Value;
                                }
                                if (dt_arrive.Value != null)
                                {
                                    shipment.IdTimeNavigation.DateTimeArrive = dt_arrive.Value;
                                }

                                if (dt_left.Value != null)
                                {
                                    shipment.IdTimeNavigation.DateTimeLeft = dt_left.Value;
                                }
                                if (tb_numrealese.Text != "")
                                {
                                    shipment.NumRealese = tb_numrealese.Text;
                                }
                                if (tb_packetdoc.Text != "")
                                {
                                    shipment.PacketDocuments = tb_packetdoc.Text;
                                }
                                if (tb_typeload.Text != "")
                                {
                                    shipment.TypeLoad = tb_typeload.Text;
                                }
                                if (tb_tochkaload.Text != "")
                                {
                                    shipment.TochkaLoad = tb_tochkaload.Text;
                                }
                                if (tb_descript.Text != "")
                                {
                                    shipment.Description = tb_descript.Text;
                                }



                                shipment.ServiceInfo = shipment.ServiceInfo + "\n" + DateTime.Now + " " + App.ActiveUser + " внес изменения в отгрузку";
                                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 if (App.LevelAccess == "warehouse")
            {
                try
                {
                    using (DB.RegistrantCoreContext ef = new DB.RegistrantCoreContext())
                    {
                        var shipment = ef.Shipments.FirstOrDefault(x => x.IdShipment == Convert.ToInt64(idcont.Text));

                        if (dt_load.Value != null)
                        {
                            shipment.IdTimeNavigation.DateTimeLoad = dt_load.Value;
                        }
                        if (dt_endload.Value != null)
                        {
                            shipment.IdTimeNavigation.DateTimeEndLoad = dt_endload.Value;
                        }
                        if (tb_CountPodons.Text != "")
                        {
                            shipment.CountPodons = tb_CountPodons.Text;
                        }
                        if (tb_nomencluture.Text != "")
                        {
                            shipment.Nomenclature = tb_nomencluture.Text;
                        }
                        if (tb_size.Text != "")
                        {
                            shipment.Size = tb_size.Text;
                        }
                        if (tb_Destination.Text != "")
                        {
                            shipment.Destination = tb_Destination.Text;
                        }
                        if (tb_typeload.Text != "")
                        {
                            shipment.TypeLoad = tb_typeload.Text;
                        }
                        if (tb_descript.Text != null)
                        {
                            shipment.Description = tb_descript.Text;
                        }
                        if (tb_storekeeper.Text != "")
                        {
                            shipment.StoreKeeper = tb_storekeeper.Text;
                        }
                        else
                        {
                            shipment.StoreKeeper = App.ActiveUser;
                        }

                        //shipment.StoreKeeper = App.ActiveUser;
                        shipment.ServiceInfo = shipment.ServiceInfo + "\n" + DateTime.Now + " " + App.ActiveUser + " внес изменения в отгрузку";
                        ef.SaveChanges();
                        Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Программное исключене", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else if (App.LevelAccess == "admin")
            {
                if (cb_drivers.Text != "")
                {
                    if (cb_contragent.Text != "")
                    {
                        try
                        {
                            using (DB.RegistrantCoreContext ef = new DB.RegistrantCoreContext())
                            {
                                var shipment = ef.Shipments.FirstOrDefault(x => x.IdShipment == Convert.ToInt64(idcont.Text));

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

                                    shipment.IdDriverNavigation.Phone      = tb_phone.Text;
                                    shipment.IdDriverNavigation.Attorney   = tb_attorney.Text;
                                    shipment.IdDriverNavigation.Auto       = tb_auto.Text;
                                    shipment.IdDriverNavigation.AutoNumber = tb_autonum.Text;
                                }
                                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.Auto        = tb_auto.Text;
                                    driver.AutoNumber  = tb_autonum.Text;
                                    driver.Attorney    = tb_attorney.Text;
                                    driver.Phone       = tb_phone.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;
                                }

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

                                if (tb_numrealese.Text != "")
                                {
                                    shipment.NumRealese = tb_numrealese.Text;
                                }
                                if (tb_packetdoc.Text != "")
                                {
                                    shipment.PacketDocuments = tb_packetdoc.Text;
                                }
                                if (tb_tochkaload.Text != "")
                                {
                                    shipment.TochkaLoad = tb_tochkaload.Text;
                                }
                                if (tb_CountPodons.Text != "")
                                {
                                    shipment.CountPodons = tb_CountPodons.Text;
                                }
                                if (tb_nomencluture.Text != "")
                                {
                                    shipment.Nomenclature = tb_nomencluture.Text;
                                }
                                if (tb_size.Text != "")
                                {
                                    shipment.Size = tb_size.Text;
                                }
                                if (tb_Destination.Text != "")
                                {
                                    shipment.Destination = tb_Destination.Text;
                                }
                                if (tb_typeload.Text != "")
                                {
                                    shipment.TypeLoad = tb_typeload.Text;
                                }
                                if (tb_descript.Text != "")
                                {
                                    shipment.Description = tb_descript.Text;
                                }
                                if (tb_storekeeper.Text != "")
                                {
                                    shipment.StoreKeeper = tb_storekeeper.Text;
                                }

                                shipment.Active      = "1";
                                shipment.ServiceInfo = shipment.ServiceInfo + "\n" + DateTime.Now + " " + App.ActiveUser + " внес изменения в отгрузку";
                                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);
                }
            }
        }