private async void deprovisionButton_Click(object sender, RoutedEventArgs e)
        {
            if (Globals.DeviceIdExists() == false)
            {
                outputField.Text = "No device ID currently in memory. Press " + submitDeviceId.Content + " then try again.";
                return;
            }
            int    depChoice = GetInput.GetDeprovisionReason();
            string depAction = null;

            switch (depChoice)
            {
            case 0:
                outputField.Text = "Either you cancelled or selected nothing.";
                return;

            case 1:
                // same model replacement
                depAction = "deprovision_same_model_replace";
                break;

            case 2:
                // different model replacement
                depAction = "deprovision_different_model_replace";
                break;

            case 3:
                // retiring device
                depAction = "deprovision_retiring_device";
                break;

            default:
                depAction = "thisbetterfailbecausesomethingiswrong";
                return;
            }

            string gamResult = null;

            if (Globals.DeviceId == "csv")
            {
                IsLoading = true;
                gamResult = await Task.Run(() => GAM.RunGAMFormatted(GAM.GetGAMCSVCommand(Globals.CsvLocation, "update cros", "action " + depAction + " acknowledge_device_touch_requirement")));

                IsLoading = false;
            }
            else
            {
                IsLoading = true;
                gamResult = await Task.Run(() => GAM.RunGAMFormatted("update cros " + Globals.DeviceId + " action " + depAction + " acknowledge_device_touch_requirement"));

                IsLoading = false;
            }
            outputField.Text = gamResult += "\nAs long as you don't see an error, this query completed successfully.";
        }
        private async void ApplyChangesButton_Click(object sender, RoutedEventArgs e)
        {
            // check to see which fields have been changed (ones that aren't the global or "<no value present>", should make this an independent function)
            ProgressBarDialog progressBar = GetInput.ShowProgressBarDialog("Updating Device", 50, "Updating device info...");
            await progressBar.UpdateBarAndText(50, "Updating device info...");

            string gamCommand = "update cros " + Globals.DeviceId + " ";
            string outputText = "";

            if (LocationField.Text != Globals.Location)
            {
                if (LocationField.Text.Length < 1)
                {
                    switch (GetInput.GetYesOrNo("Empty Location?", "Clear the field?", "Click yes if you want to empty the Location field. Click no to cancel."))
                    {
                    case "yes":
                        break;

                    case "no":
                        outputField.Text = "Cancelling because you didn't want to empty a field.";
                        progressBar.Close();
                        return;

                    default:
                        progressBar.Close();
                        return;
                    }
                }
                gamCommand      += "location \"" + LocationField.Text + "\" ";
                Globals.Location = LocationField.Text;
                outputText      += "Location, ";
            }
            if (AssetIdField.Text != Globals.AssetId)
            {
                if (AssetIdField.Text.Length < 1)
                {
                    switch (GetInput.GetYesOrNo("Empty Asset ID?", "Clear the field?", "Click yes if you want to empty the Asset ID field. Click no to cancel."))
                    {
                    case "yes":
                        break;

                    case "no":
                        outputField.Text = "Cancelling because you didn't want to empty a field.";
                        progressBar.Close();
                        return;

                    default:
                        progressBar.Close();
                        return;
                    }
                }
                gamCommand     += "asset_id \"" + AssetIdField.Text + "\" ";
                Globals.AssetId = LocationField.Text;
                outputText     += "Asset ID, ";
            }
            if (UserField.Text != Globals.User)
            {
                if (UserField.Text.Length < 1)
                {
                    switch (GetInput.GetYesOrNo("Empty User?", "Clear the field?", "Click yes if you want to empty the User field. Click no to cancel."))
                    {
                    case "yes":
                        break;

                    case "no":
                        outputField.Text = "Cancelling because you didn't want to empty a field.";
                        progressBar.Close();
                        return;

                    default:
                        progressBar.Close();
                        return;
                    }
                }
                gamCommand  += "user \"" + UserField.Text + "\" ";
                Globals.User = UserField.Text;
                outputText  += "User, ";
            }
            if (NoteField.Text != Globals.Note)
            {
                if (NoteField.Text.Length < 1)
                {
                    switch (GetInput.GetYesOrNo("Empty Note?", "Clear the field?", "Click yes if you want to empty the Note field. Click no to cancel."))
                    {
                    case "yes":
                        break;

                    case "no":
                        outputField.Text = "Cancelling because you didn't want to empty a field.";
                        progressBar.Close();
                        return;

                    default:
                        progressBar.Close();
                        return;
                    }
                }
                gamCommand  += "notes \"" + NoteField.Text.Replace("\"", "\\\"") + "\" "; // will output a note like this: "He told me \"Hello!\" yesterday."
                Globals.Note = NoteField.Text;
                outputText  += "Note, ";
            }
            if (StatusDisabledRadio.IsChecked == true && Globals.Status != "DISABLED")
            {
                gamCommand    += "action disable ";
                Globals.Status = "DISABLED";
                outputText    += "Status, ";
            }
            if (StatusActiveRadio.IsChecked == true && Globals.Status != "ACTIVE")
            {
                gamCommand    += "action reenable ";
                Globals.Status = "ACTIVE";
                outputText    += "Status, ";
            }
            if (StatusDeprovisionedRadio.IsChecked == true && Globals.Status != "DEPROVISIONED")
            {
                //deprovision_same_model_replace|deprovision_different_model_replace|deprovision_retiring_device [acknowledge_device_touch_requirement]
                int depReason = GetInput.GetDeprovisionReason();
                switch (depReason)
                {
                case 1:
                    gamCommand += "action deprovision_same_model_replace acknowledge_device_touch_requirement ";     // same
                    break;

                case 2:
                    gamCommand += "action deprovision_different_model_replace acknowledge_device_touch_requirement ";
                    break;  // different

                case 3:     // retire
                    gamCommand += "action deprovision_retiring_device acknowledge_device_touch_requirement ";
                    break;

                default:
                    outputField.Text = "No deprovision reason was selected so that choice was not saved.\n";
                    break;     // do nothing: they selected nothing.
                }
                if (depReason != 0)
                {
                    Globals.Status = "DEPROVISIONED";
                    outputText    += "Status, ";
                    StatusActiveRadio.IsEnabled        = false;
                    StatusDeprovisionedRadio.IsEnabled = false;
                    StatusDisabledRadio.IsEnabled      = false;
                }
            }
            if (OrganizationalUnitField.Text != Globals.OrgUnitPath && Globals.OrgUnitPath.Length > 0)
            {
                gamCommand         += "ou " + OrganizationalUnitField.Text + " ";
                Globals.OrgUnitPath = OrganizationalUnitField.Text;
                outputText         += "Orgizational Unit ";
            }

            if (gamCommand != "update cros " + Globals.DeviceId + " ") // if something was changed
            {
                string gamOutput = GAM.RunGAMFormatted(gamCommand);
                Console.WriteLine(gamOutput);
            }
            await progressBar.UpdateBarAndText(99, "Finishing up...");

            if (outputText.Length > 1)
            {
                outputField.Text = outputText += "was updated.";
            }
            progressBar.Close();
            // build a GAM command from that information
            // run it
            // update globals
            // show success in output field
        }
        private async void ApplyChangesButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                IsLoading = true;
                // check to see which fields have been changed (ones that aren't the global or "<no value present>", should make this an independent function)
                ProgressBarDialog progressBar = GetInput.ShowProgressBarDialog("Updating Device", 50, "Updating device info...");
                progressBar.UpdateBarAndText(50, "Updating device info...");
                var gamCommands = new List <string>();
                var wasChanged  = new List <string>();

                if (LocationField.Text != Globals.Location)
                {
                    if (ShouldEmptyField(LocationField.Text, Globals.Location))
                    {
                        switch (GetInput.GetYesOrNo("Empty Location?", "Clear the field?", "Click yes if you want to empty the Location field. Click no to cancel."))
                        {
                        case "yes":
                            break;

                        case "no":
                            outputField.Text = "Cancelling because you didn't want to empty a field.";
                            progressBar.Close();
                            IsLoading = false;
                            return;

                        default:
                            progressBar.Close();
                            return;
                        }
                    }
                    gamCommands.Add("location \"" + LocationField.Text + "\"");
                    Globals.Location = LocationField.Text;
                    wasChanged.Add("Location");
                }
                if (AssetIdField.Text != Globals.AssetId)
                {
                    if (ShouldEmptyField(AssetIdField.Text, Globals.AssetId))
                    {
                        switch (GetInput.GetYesOrNo("Empty Asset ID?", "Clear the field?", "Click yes if you want to empty the Asset ID field. Click no to cancel."))
                        {
                        case "yes":
                            break;

                        case "no":
                            outputField.Text = "Cancelling because you didn't want to empty a field.";
                            progressBar.Close();
                            IsLoading = false;
                            return;

                        default:
                            progressBar.Close();
                            return;
                        }
                    }
                    gamCommands.Add("asset_id \"" + AssetIdField.Text + "\"");
                    Globals.AssetId = LocationField.Text;
                    wasChanged.Add("Asset ID");
                }
                if (UserField.Text != Globals.User)
                {
                    if (ShouldEmptyField(UserField.Text, Globals.User))
                    {
                        switch (GetInput.GetYesOrNo("Empty User?", "Clear the field?", "Click yes if you want to empty the User field. Click no to cancel."))
                        {
                        case "yes":
                            break;

                        case "no":
                            outputField.Text = "Cancelling because you didn't want to empty a field.";
                            progressBar.Close();
                            return;

                        default:
                            progressBar.Close();
                            return;
                        }
                    }
                    gamCommands.Add("user \"" + UserField.Text + "\"");
                    Globals.User = UserField.Text;
                    wasChanged.Add("User");
                }
                if (NoteField.Text != Globals.Note)
                {
                    if (ShouldEmptyField(NoteField.Text, Globals.Note))
                    {
                        switch (GetInput.GetYesOrNo("Empty Note?", "Clear the field?", "Click yes if you want to empty the Note field. Click no to cancel."))
                        {
                        case "yes":
                            break;

                        case "no":
                            outputField.Text = "Cancelling because you didn't want to empty a field.";
                            progressBar.Close();
                            IsLoading = false;
                            return;

                        default:
                            progressBar.Close();
                            return;
                        }
                    }
                    gamCommands.Add("notes \"" + NoteField.Text.Replace("\"", "\\\"") + "\""); // will output a note like this: "He told me \"Hello!\" yesterday."
                    Globals.Note = NoteField.Text;
                    wasChanged.Add("Note");
                }
                if (StatusDisabledRadio.IsChecked == true && Globals.Status != "DISABLED")
                {
                    progressBar.UpdateBarAndText(55, "Disabling...");
                    await Task.Run(() => GAM.RunGAM("update cros " + Globals.DeviceId + " action disable"));

                    Globals.Status = "DISABLED";
                    wasChanged.Add("Status");
                }
                if (StatusActiveRadio.IsChecked == true && Globals.Status != "ACTIVE")
                {
                    progressBar.UpdateBarAndText(55, "Enabling...");
                    await Task.Run(() => GAM.RunGAM("update cros " + Globals.DeviceId + " action reenable"));

                    Globals.Status = "ACTIVE";
                    wasChanged.Add("Status");
                }
                if (StatusDeprovisionedRadio.IsChecked == true && Globals.Status != "DEPROVISIONED")
                {
                    //deprovision_same_model_replace|deprovision_different_model_replace|deprovision_retiring_device [acknowledge_device_touch_requirement]
                    int depReason = GetInput.GetDeprovisionReason();
                    switch (depReason)
                    {
                    case 1:
                        progressBar.UpdateBarAndText(55, "Deprovisioning...");
                        await Task.Run(() => GAM.RunGAM("update cros " + Globals.DeviceId + " action deprovision_same_model_replace acknowledge_device_touch_requirement"));

                        break;

                    case 2:
                        progressBar.UpdateBarAndText(55, "Deprovisioning...");
                        await Task.Run(() => GAM.RunGAM("update cros " + Globals.DeviceId + " action deprovision_different_model_replace acknowledge_device_touch_requirement"));

                        break;  // different

                    case 3:     // retire
                        progressBar.UpdateBarAndText(55, "Deprovisioning...");
                        await Task.Run(() => GAM.RunGAM("update cros " + Globals.DeviceId + " action deprovision_retiring_device acknowledge_device_touch_requirement"));

                        break;

                    default:
                        outputField.Text = "No deprovision reason was selected so that choice was not saved.\n";
                        break;     // do nothing: they selected nothing.
                    }
                    if (depReason != 0)
                    {
                        Globals.Status = "DEPROVISIONED";
                        wasChanged.Add("Status");
                        StatusActiveRadio.IsEnabled        = false;
                        StatusDeprovisionedRadio.IsEnabled = false;
                        StatusDisabledRadio.IsEnabled      = false;
                    }
                }

                if (OrganizationalUnitField.Text != Globals.OrgUnitPath)
                {
                    if (ShouldEmptyField(OrganizationalUnitField.Text, Globals.OrgUnitPath))
                    {
                        GetInput.ShowInfoDialog("Empty org unit path.", "Your org unit path can't be blank.", "You can't have a blank org unit path.");
                        return;
                    }
                    gamCommands.Add("ou \"" + OrganizationalUnitField.Text + "\"");
                    Globals.OrgUnitPath = OrganizationalUnitField.Text;
                    wasChanged.Add("Organizational Unit");
                }

                progressBar.UpdateBarAndText(75, "Updating info...");
                if (gamCommands.Count > 0) // if something was changed
                {
                    Console.WriteLine(string.Join(" ", gamCommands));
                    string gamOutput = await Task.Run(() => GAM.RunGAMFormatted("update cros " + Globals.DeviceId + " " + string.Join(" ", gamCommands)));

                    Console.WriteLine(gamOutput);
                }
                progressBar.UpdateBarAndText(99, "Finishing up...");
                IsLoading = false;
                if (wasChanged.Count > 0)
                {
                    outputField.Text = string.Join(", ", wasChanged) + " was changed.";
                }
                progressBar.Close();
                // build a GAM command from that information
                // run it
                // update globals
                // show success in output field
            }
            catch (Exception err)
            {
                Debug.CaptureRichException(err, CollectFieldsForRichException());
                Debug.ShowErrorMessage();
            }
        }