예제 #1
0
        /// <summary>
        /// Closes the current file, if any, and creates a new one under the specified name.
        /// The new file will have no GnuCash session loaded.
        /// </summary>
        public static void NewFile(string filename)
        {
            if (CurFile != null)
            {
                CloseFile();
            }

            CurFile = new GncFileWrapper();
            CurFile.LoadedFromFile = filename;
            CurFile.SaveToFile();
            CurFile.ReloadSession();

            AddRecent(filename);
        }
예제 #2
0
        /// <summary>
        /// Opens a GncFileWrapper of the specified file name. Loads a <see cref="GncSession"/> for
        /// the underlying file.
        /// </summary>
        /// <remarks>
        /// <para>If successful, attempts to start the server.</para>
        /// <para>If there is an exception loading the GnuCash session, displays the message
        /// in a dialog box and does not open a file, but returns successfully.</para>
        /// <para>If the session opens successfully but has warnings, displays a dialog box
        /// with a button to view the warnings in the browser.</para>
        /// </remarks>
        public static void OpenFile(string filename)
        {
            Program.CloseFile();

#if !DEBUG
            try
#endif
            {
                CurFile = GncFileWrapper.LoadFromFile(filename);
                CurFile.ReloadSession();
            }
#if !DEBUG
            catch (Exception e)
            {
                CurFile = null;
                DlgMessage.ShowWarning(Tr.Warning_CouldNotOpenAccountsWeb.Fmt(filename, CurFile == null ? Tr.Warning_AccWeb_NA.Translation : (CurFile.GnuCashFile ?? "-"), e.Message));
                return;
            }
#endif

            Interface.StartServer(Program.CurFile.ServerOptions, Program.CurFile.FileSystemOptions);

            AddRecent(filename);
        }