protected void SaveDataAndClose()
        {
            // Show post status form to indicate we are doing something
            var post = new PostForm();

            post.Loading = true;
            post.Load   += async(object sender, EventArgs args) =>
            {
                // If there was an Inara Correction, save that to history first
                if (inaraCorrection != null)
                {
                    state.AddHistory(inaraCorrection);
                }

                // If there were updates to post to Inara, post them
                if (!deltas.IsZero)
                {
                    await api.PostMaterialsSheet(result);

                    // Save to History
                    state.AddHistory(deltas);
                }

                // Update Post Timestamp
                state.UpdateLastPostToCurrent();

                // Persist the state
                state.Persist();

                // Update post status form to indicate we are finished
                post.Loading = false;
            };

            post.ShowDialog();
        }
Exemple #2
0
        /// <summary>
        /// Handle user-requested close and save
        /// </summary>
        /// <param name="sender">Ignored</param>
        /// <param name="e">e.Cancel can be used to prevent window close</param>
        protected void OnCloseAndSave(object sender, CancelEventArgs e)
        {
            if (InitialMats.IsZero)
            {
                // If the data is all zero, that is a little unusual.
                // Warn the user that it is going to save all zeroes.
                if (!form.IsUserOKWithNoMats())
                {
                    // If they don't click OK, cancel the window close
                    e.Cancel = true;
                    return;
                }
            }

            // Either mats are not empty or the user is OK with it... save!
            state.AddHistory(InitialMats);

            // Update Post Timestamp
            state.UpdateLastPostToCurrent();

            // Persist the State
            state.Persist();
        }