Beispiel #1
0
 private void CountryDepartureBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     using (PTLEntities db = new PTLEntities())
     {
         RegionDepartureBox.ItemsSource = db.Region.Select(x => x.Title);
     }
 }
 private void InitializeWindow()
 {
     if (PersonId != 0)
     {
         WindowTitle.Text     = "Редактирование персоны";
         DeleteBtn.Visibility = Visibility.Visible;
         AddBtn.Content       = "Сохранить";
         try
         {
             using (PTLEntities db = new PTLEntities())
             {
                 Person                      = db.Person.Find(PersonId);
                 SurnameBox.Text             = Person.Surname;
                 NameBox.Text                = Person.Name;
                 PatBox.Text                 = Person.Patronymic;
                 PhoneBox.Text               = Person.Phone;
                 PassportBox.Text            = Person.PassportNumber;
                 CountryComboBox.ItemsSource = db.Country.Select(x => x.Title).ToList();
                 CountryComboBox.Text        = Person.Country.Title;
             }
         }
         catch (System.Exception ex)
         {
             MessageBox.Show("Error: " + ex.Message, ex.Source, MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     else
     {
         using (PTLEntities db = new PTLEntities())
         {
             CountryComboBox.ItemsSource = db.Country.Select(x => x.Title).ToList();
             CountryComboBox.Text        = CountryComboBox.Items[0].ToString();
         }
     }
 }
Beispiel #3
0
        private void LoadComboBoxes()
        {
            var countries = new Dictionary <int, string>();

            using (PTLEntities db = new PTLEntities())
            {
                foreach (var item in places)
                {
                }
                countries = db.Country.Select(x => new
                {
                    countryId = x.Country_Id,
                    title     = x.Title
                }).AsEnumerable().Select(x => new Country
                {
                    Country_Id = x.countryId,
                    Title      = x.title
                }).ToDictionary(k => k.Country_Id, v => v.Title);
                CountryDepartureBox.ItemsSource = countries.Values;
                CountryArrivalBox.ItemsSource   = db.Country.Select(x => x.Title).ToList();
                CityArrivalBox.ItemsSource      = db.City.Select(x => x.Title).ToList();
                CityDepartureBox.ItemsSource    = db.City.Select(x => x.Title).ToList();
                RegionArrivalBox.ItemsSource    = db.Region.Select(x => x.Title).ToList();
                RegionDepartureBox.ItemsSource  = db.Region.Select(x => x.Title).ToList();
            }
        }
 private void AddBtn_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using (PTLEntities db = new PTLEntities())
         {
             var countryId = db.Country.Where(x => x.Title == CountryComboBox.Text).FirstOrDefault().Country_Id;
             if (Validation())
             {
                 if (PersonId == 0)
                 {
                     Person person = new Person
                     {
                         Surname        = SurnameBox.Text,
                         Name           = NameBox.Text,
                         Patronymic     = PatBox.Text,
                         Phone          = PhoneBox.Text,
                         PassportNumber = PassportBox.Text,
                         IsPrimary      = 0,
                         Country_Id     = countryId,
                         User_Id        = UserId
                     };
                     db.Person.Add(person);
                 }
                 else
                 {
                     var person = db.Person.Find(PersonId);
                     person.Surname        = SurnameBox.Text;
                     person.Name           = NameBox.Text;
                     person.Patronymic     = PatBox.Text;
                     person.Phone          = PhoneBox.Text;
                     person.PassportNumber = PassportBox.Text;
                     person.Country_Id     = countryId;
                 }
                 db.SaveChanges();
                 var ownerWindow = Owner as EditUser;
                 ownerWindow.LoadData();
                 Close();
             }
             else
             {
                 MessageBox.Show("Validation Error");
             }
         }
     }
     catch (System.Exception ex)
     {
         MessageBox.Show("Error: " + ex.Message, ex.Source, MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Beispiel #5
0
 private void LoadCountries()
 {
     try
     {
         using (PTLEntities db = new PTLEntities())
         {
             var coutries = db.Country.Select(x => x.Title).ToList();
             Country.ItemsSource = coutries;
             Country.Text        = Country.Items[0].ToString();
         }
     }
     catch (System.Exception ex)
     {
         MessageBox.Show("Error: " + ex.Message, ex.Source, MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Beispiel #6
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     if (!IsTextBoxEmpty() && IsLengthCorrect())
     {
         try
         {
             using (PTLEntities db = new PTLEntities())
             {
                 var login = db.User.Where(x => x.Login == Login.Text).FirstOrDefault();
                 if (Equals(login, null))
                 {
                     var    countryId    = db.Country.Where(x => x.Title == Country.Text).Select(x => x.Country_Id).FirstOrDefault();
                     string hashPassword = MainWindow.Sha256Encrypt(Password.Text);
                     User   user         = new User()
                     {
                         IsAdmin = 0, Login = Login.Text, PasswordHash = hashPassword
                     };
                     var person = new Person
                     {
                         Name           = PersonName.Text,
                         Surname        = Surname.Text,
                         Patronymic     = Patronymic.Text,
                         IsPrimary      = 1,
                         Phone          = Phone.Text,
                         PassportNumber = PassportNumber.Text,
                         Country_Id     = countryId,
                         User_Id        = user.User_Id
                     };
                     db.User.Add(user);
                     db.Person.Add(person);
                     db.SaveChanges();
                     Close();
                 }
                 else
                 {
                     MessageBox.Show("Такой пользователь уже существует!");
                 }
             }
         }
         catch (System.Exception ex)
         {
             MessageBox.Show("Error: " + ex.Message, ex.Source, MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
 }
 private void ChangePassBtn_Click(object sender, RoutedEventArgs e)
 {
     if (CurrentPassVer() && MatchVer() && LengthVer())
     {
         try
         {
             using (PTLEntities db = new PTLEntities())
             {
                 var user = db.User.Find(UserId);
                 user.PasswordHash = MainWindow.Sha256Encrypt(NewBox.Password);
                 db.SaveChanges();
                 Close();
             }
         }
         catch (System.Exception ex)
         {
             MessageBox.Show("Error: " + ex.Message, ex.Source, MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
 }
Beispiel #8
0
 public void LoadData()
 {
     try
     {
         using (PTLEntities db = new PTLEntities())
         {
             var Table = db.Person
                         .Where(x => x.User_Id == UserId)
                         .OrderByDescending(x => x.IsPrimary)
                         .Select(x => new
             {
                 surname    = x.Surname,
                 name       = x.Name,
                 patronymic = x.Patronymic,
                 country    = x.Country.Title,
                 phone      = x.Phone,
                 passport   = x.PassportNumber,
                 isprimary  = x.IsPrimary,
                 personid   = x.Person_Id
             }).AsEnumerable().Select(x => new Persons
             {
                 Surname        = x.surname,
                 Name           = x.name,
                 Patronymic     = x.patronymic,
                 Country        = x.country,
                 Phone          = x.phone,
                 PassportNumber = x.passport,
                 IsPrimary      = x.isprimary,
                 Person_Id      = x.personid
             }).ToList();
             User                 = db.User.Find(UserId);
             UsernameBox.Text     = User.Login;
             PasswordBox.Password = User.PasswordHash;
             DataGrid.ItemsSource = Table;
         }
     }
     catch (System.Exception ex)
     {
         MessageBox.Show("Error: " + ex.Message, ex.Source, MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Beispiel #9
0
 private void SelectMainBtn_Click(object sender, RoutedEventArgs e)
 {
     if (DataGrid.SelectedCells.Count != 0)
     {
         DataGridRow row = (DataGridRow)DataGrid.ItemContainerGenerator.ContainerFromIndex(DataGrid.SelectedIndex);
         if (row.GetIndex() != 0)
         {
             MessageBoxResult result = MessageBox.Show("Сменить основную персону?", "Confirm", MessageBoxButton.YesNoCancel, MessageBoxImage.Asterisk);
             if (result == MessageBoxResult.Yes)
             {
                 try
                 {
                     using (PTLEntities db = new PTLEntities())
                     {
                         var data              = DataGrid.ItemsSource as List <Persons>;
                         var personId          = data[DataGrid.SelectedIndex].Person_Id;
                         var selectedPerson    = db.Person.Where(x => x.Person_Id == personId).FirstOrDefault();
                         var currentMainPerson = db.Person.Where(x => User.User_Id == x.User_Id).Where(x => x.IsPrimary == 1)
                                                 .FirstOrDefault();
                         currentMainPerson.IsPrimary = 0;
                         selectedPerson.IsPrimary    = 1;
                         db.SaveChanges();
                         LoadData();
                     }
                 }
                 catch (System.Exception ex)
                 {
                     MessageBox.Show("Error: " + ex.Message, ex.Source, MessageBoxButton.OK, MessageBoxImage.Error);
                 }
             }
         }
         else
         {
             MessageBox.Show("Персона уже является основной");
         }
     }
     else
     {
         MessageBox.Show("Строка не выбрана");
     }
 }
Beispiel #10
0
        private bool Verification(string password, string login)
        {
            var hashedPassword = Sha256Encrypt(password);

            try
            {
                using (PTLEntities db = new PTLEntities())
                {
                    User = db.User.Where(x => x.Login == login && x.PasswordHash == hashedPassword).FirstOrDefault();
                    if (Equals(User, null))
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, ex.Source, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            return(true);
        }
Beispiel #11
0
        private void DeleteBtn_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("Удалить персону?", "Подтверждение", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                try
                {
                    using (PTLEntities db = new PTLEntities())
                    {
                        db.Person.Remove(db.Person.Find(PersonId));
                        db.SaveChanges();
                        var ownerWindow = Owner as EditUser;
                        ownerWindow.LoadData();
                        Close();
                    }
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message, ex.Source, MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Beispiel #12
0
 private void LoadData()
 {
     try
     {
         using (PTLEntities db = new PTLEntities())
         {
             var Table = db.User.Include("Person").SelectMany(x => x.Person)
                         .Where(x => x.IsPrimary == 1)
                         .Select(x => new
             {
                 userid  = x.User_Id,
                 login   = x.User.Login,
                 surname = x.Surname,
                 name    = x.Name,
                 country = x.Country.Title
             }).ToList();
             DataGrid.ItemsSource = Table;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error: " + ex.Message, ex.Source, MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }