/// <summary> /// Executes when the upoun form load /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void JasonAndFriends_Load(object sender, EventArgs e) { this.friendSheet = GenFriendSheetController(); List <Friend> friends; string data = DataMan.LoadFromFile(SAVE_FILE); if (data == null) { friends = new List <Friend>(); } else { friends = JsonConvert.DeserializeObject <List <Friend> >(data) ?? new List <Friend>(); } foreach (Friend fr in friends) { this.ComboBoxFriends.Items.Add(fr); } this.listBring = GenWillBringListController(); this.listWant = GenWillWantListController(); }
/// <summary> /// Executes when the process detects the form is in the middle of closing /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void JasonAndFriends_Closing(object sender, FormClosingEventArgs e) { bool saved = CheckUnsavedData(this.friendSheet, this.listBring, this.listWant); if (!saved) { switch (DataNotSavedDialog()) { case DialogResult.Yes: DialogResult saveStatus = PerformSaveOpWithDialog(); if (saveStatus == DialogResult.Abort) { e.Cancel = true; return; } break; case DialogResult.No: break; // Does nothing and lets the process continue closing case DialogResult.Cancel: e.Cancel = true; return; // Cancels the process and exits before the data is saved into the Json file default: throw new NotSupportedException(); } } List <Friend> friends = GenFriendListFromComboBox(this.ComboBoxFriends); string data = JsonConvert.SerializeObject(friends, Formatting.Indented); DataMan.SaveToFile(SAVE_FILE, data); }