Пример #1
0
 private void RemoveData(DataTransferObjectLibrary.Person person)
 {
     using (ServiceReference.ServiceClient client = new ServiceReference.ServiceClient())
     {
         int result = client.DeletePerson(person.Id);
     }
 }
Пример #2
0
 private void InsertData(DataTransferObjectLibrary.Person person)
 {
     using (ServiceReference.ServiceClient client = new ServiceReference.ServiceClient())
     {
         int result = client.InsertPerson(person);
     }
 }
Пример #3
0
        /// <summary>
        /// Event triggered once the "Delete Users" button is clicked.
        /// Users to delete will be obtained from UI, the list will be send to server
        /// and the applied changes in the server will be communicated with client to reflect in UI.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //Step1: Get list of Users to Delete from UI.
                List <string> usersToDelete = new List <string>();
                foreach (Users item in UsersDataGrid.ItemsSource)
                {
                    if (item.Delete == true)
                    {
                        usersToDelete.Add(item.UserName);
                    }
                }

                //Step 2: Send list of Users to Delete to Server (if any)
                //DataGrid will be updated at the end of deletion process
                if (usersToDelete.Count == 0)
                {
                    MessageBox.Show("No users selected for Delete!");
                }
                else
                {
                    ServiceReference.ServiceClient server = new ServiceReference.ServiceClient();
                    int numberOfDeletedUsers = server.DeleteUsers(usersToDelete.ToArray());
                    MessageBox.Show($"{numberOfDeletedUsers} users deleted");
                    UpdateDataGrid();
                }
            }
            catch (Exception err)
            {
                MessageBox.Show($"Error after Delete Users button clicked: {err}");
            }
        }
Пример #4
0
        /// <summary>
        /// Communicates with server and exchange login info.
        /// Upon successful login of normal user, it shows a popup
        /// Upon successful login of admin user, it shows a popup + load admin panel
        /// If login credentials are not correct, it shows a popup reporting this
        /// </summary>
        private void TryLogin()
        {
            try
            {
                ServiceReference.ServiceClient login = new ServiceReference.ServiceClient();

                bool isFound = login.MakeLogin(UserNameTextBox.Text, EncodedPassword);
                if (isFound == false)
                {
                    MessageBox.Show("User Not Found");
                }
                else
                {
                    if (isFound == true && UserNameTextBox.Text == "admin")
                    {
                        MessageBox.Show($"Successfull Login. Welcome {UserNameTextBox.Text}!");
                        AdminWindow adminWindow = new AdminWindow();
                        adminWindow.Show();
                    }
                    if (isFound == true && UserNameTextBox.Text != "admin")
                    {
                        MessageBox.Show($"Successfull Login. Welcome {UserNameTextBox.Text}!");
                    }
                }
            }
            catch (Exception err)
            {
                MessageBox.Show($"Error while trying to login in client side: {err}");
            }
        }
Пример #5
0
        private void Refresh()
        {
            DataTransferObjectLibrary.ListOfPerson persons;
            using (ServiceReference.ServiceClient client = new ServiceReference.ServiceClient())
            {
                persons = client.GetAllPerson();
            }

            this.Persons.Clear();

            foreach (var item in persons.PersonList)
            {
                this.Persons.Add(item);
            }

            this.data.ItemsSource       = this.Persons;
            this.data.DisplayMemberPath = "FirstName";
        }
Пример #6
0
 /// <summary>
 /// Updates the data grid according to the most recent version of the users obtained from server.
 /// </summary>
 private void UpdateDataGrid()
 {
     try
     {
         ServiceReference.ServiceClient server = new ServiceReference.ServiceClient();
         List <string> allUsers = server.GetAllUsers().ToList();
         List <Users>  users    = new List <Users>();
         foreach (var item in allUsers)
         {
             users.Add(new Users(item));
         }
         UsersDataGrid.ItemsSource = users;
     }
     catch (Exception err)
     {
         MessageBox.Show($"Error while trying to update the data grid: {err}");
     }
 }