コード例 #1
0
        /// <summary>
        /// Loads the project and writes the information about the project File
        /// </summary>
        /// <param name="fileName">Name of the xpf file from where the project is loaded</param>
        /// <param name="parent">Control which cursor should be changed to wait cursor</param>
        /// <param name="resManager">Resource Manager of the application</param>
        /// <param name="projectManager">Project Manager class</param>
        /// <param name="controlsManager">Controls manager that takes care of the controls</param>
        public static void LoadProject(string fileName, Control parent, 
            ResourceManager resManager, ref ProjectManager.ProjectManager projectManager,
            IControlsManager controlsManager)
        {
            string loadErrors = string.Empty;
            if (fileName != "")
            {
                FileStream fs = null;
                try
                {
                    fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open);
                }
                catch(FileNotFoundException)
                {
                    MessageBox.Show(resManager.GetString("ProjectLoadFileNotFound"),
                        resManager.GetString("ProjectLoadErrorCaption"),
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                try
                {
                    Cursor previosCursor = parent.Cursor;
                    parent.Cursor = Cursors.WaitCursor;
                    parent.Refresh();
                    loadErrors = projectManager.LoadProject(fs);
                    controlsManager.ProjectName = fileName;
                    controlsManager.GlobalAdapt();
                    parent.Cursor = previosCursor;
                }
                catch (InvalidOperationException)
                {
                    MessageBox.Show(resManager.GetString("ProjectLoadInvalidFormat"),
                        resManager.GetString("ProjectLoadErrorCaption"),
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                finally
                {
                    fs.Close();
                }
            }

            //displaying what has happened while loading the project
            if (loadErrors != string.Empty)
            {
                MessageBox.Show(loadErrors,
                    resManager.GetString("ProjectLoadErrorCaption"),
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }