private void LvData_SelectedIndexChanged(object sender, EventArgs e) { if (lvData.SelectedItems.Count == 0) { tbNote.Text = ""; SelectedAccount = null; } else { if (lvData.SelectedItems.Count > 1 || !Globals.CurrentProfile.Profiles.TryGetValue(lvData.SelectedItems[0].SubItems[0].Text, out SelectedAccount)) { return; } tbNote.Text = SelectedAccount.Note; } }
// Load the current profile into the table private void CbProfile_LoadToTable() { lvData.Items.Clear(); if (Globals.CurrentProfile.vProfileFormat < Globals.Info.vProfileFormat) { MessageBox.Show($"Invalid/Incompatible Profile JSON format version!\nLoaded JSON format version: {Globals.CurrentProfile.vProfileFormat}\nCurrent JSON format version: {Globals.Info.vProfileFormat}", "Load JSON", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Load all the accounts to our table if (Globals.CurrentProfile.Profiles != null) { foreach (KeyValuePair <string, Class.Account> _data in Globals.CurrentProfile.Profiles) { Class.Account _account = _data.Value; Utils.Account.AddToTable(ref lvData, _data.Key, ref _account); } } }
private void swapAccountPositionToolStripMenuItem_Click(object sender, EventArgs e) { if (Globals.CurrentProfile == null) { MessageBox.Show("No profile loaded.", "Swap Accounts Position", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ListView.SelectedListViewItemCollection selitems = lvData.SelectedItems; if (selitems.Count != 2) { MessageBox.Show("Please select 2 items to swap positions.", "Swap Accounts Position", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // for backwards compability, we store the class object id. in later versions the account class itself has this information. string swapA_ClassObjectID = lvData.SelectedItems[0].SubItems[0].Text; string swapB_ClassObjectID = lvData.SelectedItems[1].SubItems[0].Text; // Store the first account temporarily Class.Account swap_Account = Globals.CurrentProfile.Profiles[swapA_ClassObjectID]; // Swap the two accounts and Re-assign the class object id (Globals.CurrentProfile.Profiles[swapA_ClassObjectID] = Globals.CurrentProfile.Profiles[swapB_ClassObjectID]).ClassObjectID = swapA_ClassObjectID; (Globals.CurrentProfile.Profiles[swapB_ClassObjectID] = swap_Account).ClassObjectID = swapB_ClassObjectID; // Assign the new last login properly if applicable bool isSwapA = swapA_ClassObjectID == Globals.CurrentProfile.LastAccountLoggedIn; if (isSwapA || swapB_ClassObjectID == Globals.CurrentProfile.LastAccountLoggedIn) { Globals.CurrentProfile.LastAccountLoggedIn = isSwapA ? swapB_ClassObjectID : swapA_ClassObjectID; } // Reload the table CbProfile_LoadToTable(); }