Example #1
0
        private void RoomDeleteBtn_Click(object sender, RoutedEventArgs e)
        {
            //Create varible of type Room1
            Room1 CurrentRoom = new Room1();

            CurrentRoom = (Room1)RoomDataGrid.SelectedItem;

            //asks the user if they really want to delete the record
            MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Delete " + CurrentRoom.RoomName + "?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                //executes the query to delete the record
                dbContext.Database.ExecuteSqlCommand("Delete from Room where RoomNumber = @RoomNumber",
                                                     new SqlParameter("RoomNumber", CurrentRoom.RoomNumber));
                //Sets RName to the value of the current room name that is selected so that it is displayed when the room is deleted
                String RName = CurrentRoom.RoomName.ToString();
                //Repopulates the Datagrid with the updated rooms
                var Room = dbContext.Rooms1.SqlQuery("Select * from Rooms").ToList();
                RoomDataGrid.ItemsSource   = Room;
                RoomDataGrid.SelectedIndex = 0;

                RoomNameTxt1.Text  = null;
                RoomNumberTxt.Text = null;
                RNum = null;

                RoomAddBtn.IsEnabled  = true;
                RoomEditBtn.IsEnabled = true;
                //confirmation that the room was deleted
                MessageBox.Show(RName + " deleted from Current Rooms");

                RoomNumberTxt.Visibility = System.Windows.Visibility.Collapsed;
                RoomNumLbl.Visibility    = System.Windows.Visibility.Collapsed;
            }
        }
Example #2
0
        private void RoomEditBtn_Click(object sender, RoutedEventArgs e)
        {
            //Create varible of type Room1
            Room1 CurrentRoom = new Room1();

            CurrentRoom = (Room1)RoomDataGrid.SelectedItem;
            //populates the texts fields by using the object CurrentRoom to grab the values
            RoomNameTxt1.Text  = CurrentRoom.RoomName;
            RoomNumberTxt.Text = CurrentRoom.RoomNumber.ToString();

            //sets the index and RNum that we use in the update
            Index = RoomDataGrid.SelectedIndex;
            RNum  = RoomNumberTxt.Text;

            //makes the number field visisble so that user knows which record is being updated
            RoomNumberTxt.Visibility = System.Windows.Visibility.Visible;
            RoomNumLbl.Visibility    = System.Windows.Visibility.Visible;

            RoomAddBtn.IsEnabled  = false;
            RoomEditBtn.IsEnabled = false;
        }
Example #3
0
        private void RoomAddBtn_Click(object sender, RoutedEventArgs e)
        {
            //The if statement makes sure that you cannot add a room without a name
            if (RoomNameTxt1.Text == "")
            {
                MessageBox.Show("Please Enter Room Name");
            }
            else
            {
                //iMatch holds the value to know if the room name matches any name in current room
                int iMatch = 0;
                //the for loop goes through all the records to check if there are any matches
                for (int iCount = 0; iCount < RoomDataGrid.Items.Count - 1; iCount++)
                {
                    Room1 CurrentRoom = new Room1();
                    RoomDataGrid.SelectedIndex = iCount;// set the index to that of the iCount
                    CurrentRoom = (Room1)RoomDataGrid.SelectedItem;

                    //if the new name matches a record, one is added to iMatch
                    if (RoomNameTxt1.Text.ToLowerInvariant() == CurrentRoom.RoomName.ToLowerInvariant())
                    {
                        iMatch++;
                    }
                }
                //if iMatch is greater than zero it means that a room already has the new name
                if (iMatch > 0)
                {
                    //asks the user if they want to add the name even tho it already exists
                    MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Room already exists with this name, add anyway?", "Add Confirmation", System.Windows.MessageBoxButton.YesNo);
                    if (messageBoxResult == MessageBoxResult.Yes)
                    {
                        Console.WriteLine(iMatch);
                        String RoomName = RoomNameTxt1.Text + iMatch;
                        Console.WriteLine(RoomName);
                        dbContext.Database.ExecuteSqlCommand("Insert into Room (RoomName, RoomNumber) values (@RoomName, @RoomNumber)",
                                                             new SqlParameter("RoomName", RoomName),
                                                             new SqlParameter("RoomNumber", RoomDataGrid.Items.Count + 1));

                        var Room = dbContext.Rooms1.SqlQuery("select * from Rooms").ToList();
                        RoomDataGrid.ItemsSource   = Room;
                        RoomDataGrid.SelectedIndex = 0;

                        //confirmation that the room is added
                        MessageBox.Show(RoomNameTxt1.Text + " added to Current Rooms");
                        //resets the textbox
                        RoomNameTxt1.Text = null;
                    }
                    else
                    {     //resets the textbox
                        RoomNameTxt1.Text = null;
                    }
                }
                else
                {
                    dbContext.Database.ExecuteSqlCommand("Insert into Room (RoomName, RoomNumber) values (@RoomName, @RoomNumber)",
                                                         new SqlParameter("RoomName", RoomNameTxt1.Text),
                                                         new SqlParameter("RoomNumber", RoomDataGrid.Items.Count + 1));

                    var Room = dbContext.Rooms1.SqlQuery("select * from Rooms").ToList();
                    RoomDataGrid.ItemsSource   = Room;
                    RoomDataGrid.SelectedIndex = 0;

                    MessageBox.Show(RoomNameTxt1.Text + " added to Current Rooms");
                    //resets the textbox
                    RoomNameTxt1.Text = null;
                }
            }
        }