예제 #1
0
        private void RemoveRack_Click(object sender, RoutedEventArgs e)
        {
            //string value = "";
            //try
            //{
            //    value = RacksListBox.SelectedItem.ToString();
            //}
            //catch
            //{
            //    return;
            //}

            //if (value != null)
            //{

            //    Guid tempGuid = Guid.Parse(((ListBoxItem)RacksListBox.SelectedItem).Tag.ToString());
            //    for (int i = 0; i < Globals.AllRacks.Count; i++)
            //    {
            //        Rack rack = Globals.AllRacks[i];
            //        if (rack.guid == tempGuid)
            //        {
            //            SQLDatabase.DeleteRack(rack);
            //            Globals.InitializeGlobals();
            //            DisplayRacks();
            //            return;
            //        }
            //    }

            //}
            //else
            //{
            //    return;
            //}
            try
            {
                Rack varRack = (Rack)RackListGrid.SelectedItem;
            }
            catch
            {
                string           messageBoxText = "Please select a rack.";
                string           caption        = "Rack Select Warning";
                MessageBoxButton button         = MessageBoxButton.OK;
                MessageBoxImage  icon           = MessageBoxImage.Warning; //MessageBoxImage.YesNoCancel; -allows yes, no and cancel button to be displayed on dialog box
                MessageBox.Show(messageBoxText, caption, button, icon);
                return;
            }
            Rack rack = (Rack)RackListGrid.SelectedItem;

            if (rack != null)
            {
                string           messageBoxText = "Are you sure you want to delete this rack?";
                string           caption        = "Rack Deletion Warning";
                MessageBoxButton button         = MessageBoxButton.YesNo;
                MessageBoxImage  icon           = MessageBoxImage.Warning; //MessageBoxImage.YesNoCancel; -allows yes, no and cancel button to be displayed on dialog box
                MessageBoxResult result         = MessageBox.Show(messageBoxText, caption, button, icon);
                switch (result)
                {
                case MessageBoxResult.Yes:
                    // User pressed Yes button
                    // ...
                    SQLDatabase.DeleteRack(rack);
                    Globals.InitializeGlobals();
                    DisplayRacks(Globals.AllRacks);
                    break;

                case MessageBoxResult.No:
                    // User pressed No button
                    // ...
                    break;
                }
            }
            else
            {
                return;
            }
        }