Example #1
0
        private void DeleteCommandExecucte(object obj)
        {
            if (SelectedDeleteElement != null)
            {
                var test = (from x in _ctx.PropMenuGastronomicThings_Dictionary_First
                            where x.ThingName == SelectedDeleteElement.ThingName &&
                            x.NettoMini == SelectedDeleteElement.NettoMini &&
                            x.SpecificType == SelectedDeleteElement.SpecificType &&
                            x.Vat == SelectedDeleteElement.Vat
                            select x).SingleOrDefault();
                _ctx.PropMenuGastronomicThings_Dictionary_First.Remove(test);
                _ctx.SaveChanges();
                Gastronomic =
                    new ObservableCollection <PropMenuGastronomicThings_Dictionary_First>(
                        (from q in _ctx.PropMenuGastronomicThings_Dictionary_First
                         select q).ToList());
                SelectedFilter = Filter[0];
                Xceed.Wpf.Toolkit.MessageBox.Show("Usunięto rekord", "Informacja", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                Gastronomic =
                    new ObservableCollection <PropMenuGastronomicThings_Dictionary_First>(
                        (from q in _ctx.PropMenuGastronomicThings_Dictionary_First
                         select q).ToList());

                SelectedFilter = Filter[0];
            }
        }
Example #2
0
        private void AddUserExecute()
        {
            try {
                var addUser = new Users
                {
                    Name        = _userName,
                    Surname     = _userSurname,
                    PhoneNum    = _userPhoneNumber,
                    Email       = _userEmail,
                    Position    = _userPosition,
                    AccountType = UserAccontType2(),
                    Login       = UserLogin,
                    Password    = "",
                    FirstLogin  = "******"
                };

                _ctx.Users.Add(addUser);
                _ctx.SaveChanges();
                Xceed.Wpf.Toolkit.MessageBox.Show("Konto użytkownika zostało utworzone!", "Informacja", MessageBoxButton.OK, MessageBoxImage.Information);
                Application.Current.MainWindow.Hide();
            }
            catch (Exception ex)
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("Wystąpił błąd! Konto użytkownika nie zostało utworzone.", "Błąd", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Example #3
0
 private void RemoveUserExecute()
 {
     //MessageBox.Show(_userProp.Id.ToString());
     try
     {
         var order = (from o in _ctx.Users
                      where o.Id == _userProp.Id
                      select o).First();
         var user = (from u in _ctx.Users
                     where u.AccountType == 1
                     select u).FirstOrDefault();
         var prop = (from u in _ctx.Proposition
                     where u.Id_user == _userProp.Id
                     select u).ToList();
         foreach (var tmp in prop)
         {
             tmp.Id_user = user.Id;
         }
         _ctx.Users.Remove(order);
         _ctx.SaveChanges();
         Xceed.Wpf.Toolkit.MessageBox.Show("Konto użytkownika zostało usunięte!", "Informacja", MessageBoxButton.OK, MessageBoxImage.Information);
         Application.Current.MainWindow.Hide();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
         Xceed.Wpf.Toolkit.MessageBox.Show("Wystąpił błąd! Konto użytkownika nie zostało usunięte.", "Błąd", MessageBoxButton.OK, MessageBoxImage.Warning);
     }
 }
Example #4
0
        private void UserList_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            try
            {
                // Approach: When user finish changes values of cells in row, trigger update
                // Get database Id of user from selected row in datagrid
                object item = UserList.SelectedItem;
                string ID   = (UserList.SelectedCells[0].Column.GetCellContent(item) as TextBlock).Text;
                //MessageBox.Show(ID);

                //convert ID to int
                int selected = Int32.Parse(ID);

                //object which stores all deta from selected row
                dynamic userRow = UserList.SelectedItem;
                int     tmp     = 0;
                if (userRow.UserAccountType == "Administrator")
                {
                    tmp = 1;
                }
                else
                {
                    tmp = 2;
                }

                //MessageBox.Show(userRow.UserName);
                //MessageBox.Show(userRow.UserEmail);
                DiamondDBEntities _ctx       = new DiamondDBEntities();
                Users             userUpdate = (from user in _ctx.Users
                                                where user.Id == selected // int selected!!! you know what i want up to date
                                                select user).First();

                // update values in database by select from 'dynamic userRow' properties
                // UserName UserEmail etc. are in xaml in line:
                // <TextBox Text="{Binding UserLogin, UpdateSourceTrigger=PropertyChanged}"/>
                // need to update 'dynamic userRow' with Trigger, when user write text into cell

                userUpdate.Name        = userRow.UserName;
                userUpdate.Surname     = userRow.UserSurname;
                userUpdate.PhoneNum    = userRow.UserPhoneNumber;
                userUpdate.Email       = userRow.UserEmail;
                userUpdate.Position    = userRow.UserPosition;
                userUpdate.AccountType = tmp;
                userUpdate.Login       = userRow.UserLogin;

                _ctx.SaveChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Example #5
0
        private void ResetPasswordExecute()
        {
            try
            {
                Users userUpdate = (from user in _ctx.Users
                                    where user.Id == _userProp.Id // int selected!!! you know what i want up to date
                                    select user).First();

                userUpdate.FirstLogin = "******";

                _ctx.SaveChanges();

                Xceed.Wpf.Toolkit.MessageBox.Show("Hasło użytkownika zostało zresetowane!", "Informacja", MessageBoxButton.OK, MessageBoxImage.Information);
                Application.Current.MainWindow.Hide();
            }
            catch (Exception ex)
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("Wystąpił błąd! Hasło użytkownika nie zostało zresetowane.", "Błąd", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Example #6
0
        public void RowEditGstronomic(object sender, DataGridRowEditEndingEventArgs e)
        {
            try
            {
                object item     = GstronomicGrid.SelectedItem;
                string ID       = (GstronomicGrid.SelectedCells[0].Column.GetCellContent(item) as TextBlock).Text;
                int    selected = Int32.Parse(ID);
                //int selected = ((PropMenuGastronomicThings_Dictionary_First)e.Row.Item).Id;

                dynamic userRow = GstronomicGrid.SelectedItem;

                if (Ctyp.SelectedItem.ToString() != " ")
                {
                    if (selected != 0 && userRow.ThingName != "" && userRow.ThingName != null &&
                        userRow.NettoMini != null && userRow.NettoMini != 0 && userRow.Vat.ToString() != "" &&
                        userRow.Vat.ToString() != null)
                    {
                        PropMenuGastronomicThings_Dictionary_First userUpdate =
                            (from q in _ctx.PropMenuGastronomicThings_Dictionary_First
                             where q.Id == selected
                             // int selected!!! you know what i want up to date
                             select q).First();
                        userUpdate.ThingName = userRow.ThingName;
                        userUpdate.NettoMini = userRow.NettoMini;
                        userUpdate.Vat       = userRow.Vat;
                        if (userRow.MergeType == null)
                        {
                            var mertyp = (from x in _ctx.PropMenuGastronomicThings_Dictionary_First
                                          where x.SpecificType == Ctyp.SelectedItem.ToString() &&
                                          x.Id == selected
                                          group x by x.MergeType
                                          into g
                                          select g.Key).ToList();

                            userUpdate.MergeType = mertyp.FirstOrDefault();
                        }
                        else
                        {
                            userUpdate.MergeType = userRow.MergeType;
                        }
                        userUpdate.SpecificType = Ctyp.SelectedItem.ToString();
                        _ctx.SaveChanges();
                    }
                    else if (userRow.ThingName != "" && userRow.ThingName != null &&
                             userRow.NettoMini != null && userRow.NettoMini != 0 && userRow.Vat.ToString() != "" &&
                             userRow.Vat.ToString() != null)
                    {
                        PropMenuGastronomicThings_Dictionary_First userUpdate =
                            new PropMenuGastronomicThings_Dictionary_First();
                        userUpdate.ThingName = userRow.ThingName;
                        userUpdate.NettoMini = userRow.NettoMini;
                        userUpdate.Vat       = userRow.Vat;
                        if (userRow.MergeType == null)
                        {
                            var mertyp = (from x in _ctx.PropMenuGastronomicThings_Dictionary_First
                                          where x.SpecificType == Ctyp.SelectedItem.ToString()
                                          group x by x.MergeType
                                          into g
                                          select g.Key).ToList();
                            userUpdate.MergeType = mertyp.FirstOrDefault();
                        }
                        else
                        {
                            userUpdate.MergeType = userRow.MergeType;
                        }


                        userUpdate.SpecificType = Ctyp.SelectedItem.ToString();
                        _ctx.PropMenuGastronomicThings_Dictionary_First.Add(userUpdate);
                        _ctx.SaveChanges();
                        Xceed.Wpf.Toolkit.MessageBox.Show("Dodano rekord", "Informacja", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        Xceed.Wpf.Toolkit.MessageBox.Show("Należy wypełnić  nazwe, netto i vat!", "Błąd", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
                else
                {
                    if (selected != 0)
                    {
                        if (userRow.ThingName != "" && userRow.ThingName != null &&
                            userRow.NettoMini != null && userRow.NettoMini != 0 &&
                            userRow.MergeType != null && userRow.Vat.ToString() != "" &&
                            userRow.Vat.ToString() != null && userRow.SpecificType != null)
                        {
                            PropMenuGastronomicThings_Dictionary_First userUpdate =
                                (from q in _ctx.PropMenuGastronomicThings_Dictionary_First
                                 where q.Id == selected
                                 // int selected!!! you know what i want up to date
                                 select q).First();
                            userUpdate.ThingName    = userRow.ThingName;
                            userUpdate.NettoMini    = userRow.NettoMini;
                            userUpdate.Vat          = userRow.Vat;
                            userUpdate.MergeType    = userRow.MergeType;
                            userUpdate.SpecificType = userRow.SpecificType;
                            _ctx.SaveChanges();
                        }
                    }
                    else if (userRow.ThingName != "" && userRow.ThingName != null &&
                             userRow.NettoMini != null && userRow.NettoMini != 0 &&
                             userRow.MergeType != null && userRow.Vat.ToString() != "" &&
                             userRow.Vat.ToString() != null && userRow.SpecificType != null)
                    {
                        PropMenuGastronomicThings_Dictionary_First userUpdate =
                            new PropMenuGastronomicThings_Dictionary_First();

                        userUpdate.ThingName    = userRow.ThingName;
                        userUpdate.NettoMini    = userRow.NettoMini;
                        userUpdate.Vat          = userRow.Vat;
                        userUpdate.SpecificType = userRow.SpecificType;
                        userUpdate.MergeType    = userRow.MergeType;
                        _ctx.PropMenuGastronomicThings_Dictionary_First.Add(userUpdate);
                        _ctx.SaveChanges();
                        Xceed.Wpf.Toolkit.MessageBox.Show("Dodano rekord", "Informacja", MessageBoxButton.OK, MessageBoxImage.Information);
                    }

                    else
                    {
                        Xceed.Wpf.Toolkit.MessageBox.Show("Należy wypełnić wszystkie komórki!", "Błąd", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
            }
            catch (Exception ex)
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("Błąd dodania pozycji!", "Błąd", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Example #7
0
        // login logic
        private void LoginExecute(PasswordBox passBox)
        {
            try
            {
                var userToLogin = (from u in _ctx.Users
                                   where u.Login == _userLogin
                                   select u);

                // jeżeli w bazie jest tylko jeden użytkownik o podanej nazwie użytkownika oraz jest to jego pierwsze logowanie
                if (userToLogin.Count() == 1 && userToLogin.SingleOrDefault().FirstLogin.ToUpper() == "T")
                {
                    if (PasswordValidator.ValidatePassword(passBox.Password))
                    {
                        //.Password = passBox.Password;
                        userToLogin.First().Password   = ShaConverter.sha256_hash(passBox.Password); // przypisz do konta użytkownika wpisane przez niego hasło
                        userToLogin.First().FirstLogin = "******";                                        // zmień tryb logowania
                        UserId    = userToLogin.First().Id;                                          // przypisz Id użytkownika w celu umożliwienia jego jednoznacznej identyfikacji
                        _userType = userToLogin.First().AccountPrivileges.AccountType;               // uzyskaj typ konta użytkownika znajdujący się w bazie danych
                        _ctx.SaveChanges();                                                          // zapisz zmiany
                        _allowToLog      = true;                                                     // umożliwienie zalogowania się
                        _isWrongPassword = false;
                    }
                    else
                    {
                        Xceed.Wpf.Toolkit.MessageBox.Show("Hasło musi zawierac przynajmniej 8 znaków w tym przynajmniej jedną dużą literę, małą literę oraz cyfrę. " +
                                                          Environment.NewLine + "Spróbuj ponownie!", "Błąd", MessageBoxButton.OK, MessageBoxImage.Warning);
                        _isWrongPassword = true;
                    }
                }
                //.Password == passBox.Password)
                // jeśli w bazie jest tylko jeden użytkownik o podanej nazwie użytkownika oraz podana nazwa konta oraz przypisane do niego hasło jest poprawne
                else if (userToLogin.Count() == 1 && userToLogin.First().Login == _userLogin && userToLogin.First().Password == ShaConverter.sha256_hash(passBox.Password))
                {
                    _userType   = userToLogin.First().AccountPrivileges.AccountType;
                    UserId      = userToLogin.First().Id;
                    _allowToLog = true;
                }
                // jeżli użytkownik otrzymał dostęp do logowania
                if (_allowToLog && _isWrongPassword == false)
                {
                    // w zależności od typu konta uruchom okno główne
                    if (_userType.ToUpper() == "A")
                    {
                        AdminMainView adminMainView = new AdminMainView(_userId);
                        adminMainView.Show();
                        Application.Current.MainWindow.Hide();
                    }
                    else if (_userType.ToUpper() == "S")
                    {
                        UserMainView userMainView = new UserMainView(_userId);
                        userMainView.Show();
                        Application.Current.MainWindow.Hide();
                    }
                    else
                    {
                        Xceed.Wpf.Toolkit.MessageBox.Show("Błędny typ konta usera", "Błąd", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
                else
                {
                    if (_isWrongPassword)
                    {
                        passBox.Clear();
                    }
                    else
                    {
                        Xceed.Wpf.Toolkit.MessageBox.Show("Podana nazwa użytkownika i/lub hasło jest niepoprawne!" + Environment.NewLine +
                                                          "Spróbuj ponownie!", "Błąd", MessageBoxButton.OK, MessageBoxImage.Warning);
                        UserLogin = string.Empty;
                        passBox.Clear();
                    }
                }
            }
            catch (Exception ex)
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("Błąd połączenia z bazą danych. Skontaktuj się z administratorem.", "Błąd", MessageBoxButton.OK, MessageBoxImage.Warning);

                //MessageBox.Show(ex.ToString());
                //MessageBox.Show("Błąd połączenia z bazą danych. Skontaktuj się z administratorem.");
            }
        }