Exemplo n.º 1
0
        private void OpenFile(string fileName)
        {
            try
            {
                XmlDocument xmlDoc = new XmlDocument();

                xmlDoc.Load(fileName);

                string projectVer = xmlDoc.DocumentElement.Attributes.GetNamedItem("ProjectVersion").Value;

                if (projectVer != GetProjectVersion())
                {
                    if (DialogResult.Cancel ==
                        MessageBox.Show(
                            m_strOpenVersionMismatch
                            .Replace("#N#", "\n")
                            .Replace("#OPEN-PROJECT-VER#", projectVer)
                            .Replace("#OPEN-PROJECT-CREATED-VER#", xmlDoc.DocumentElement.Attributes.GetNamedItem("Version").Value)
                            .Replace("#CURRENT-PROJECT-VER#", GetProjectVersion()),
                            m_strOpenProject, MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                    {
                        return;
                    }
                }

                m_editControl.ClearImages();
                m_editControl.ClearGroup();

                string projectDir = ProjectExport.GetFolder(fileName);

                List <string> loadFaild = new List <string>();

                m_editControl.CanvasSize = new Size(
                    int.Parse(xmlDoc.DocumentElement.Attributes.GetNamedItem("Width").Value),
                    int.Parse(xmlDoc.DocumentElement.Attributes.GetNamedItem("Height").Value)
                    );

                string[] colorParams =
                    xmlDoc.DocumentElement.Attributes.GetNamedItem("Background").Value.Split(',');

                if (colorParams.Count() == 3)
                {
                    m_editControl.ColorWorkSpace = Color.FromArgb(
                        int.Parse(colorParams[0]),
                        int.Parse(colorParams[1]),
                        int.Parse(colorParams[2]));
                }
                else
                {
                    m_editControl.ColorWorkSpace = Color.White;
                }

                m_editControl.RimView =
                    xmlDoc.DocumentElement.Attributes.GetNamedItem("RimView").Value == "True";

                m_lastExportFile =
                    xmlDoc.DocumentElement.Attributes.GetNamedItem("LastExportFile").Value;

                m_lastExportFilterIndex =
                    int.Parse(xmlDoc.DocumentElement.Attributes.GetNamedItem("LastExportFilterIndex").Value);


                bool defaultSeted = false;

                int groupIndex = 0;

                foreach (XmlNode n in xmlDoc.DocumentElement)
                {
                    switch (n.Name)
                    {
                    case "Group":
                    {
                        if (defaultSeted == false)
                        {
                            m_editControl.SetDefaultGroup(n.Attributes.GetNamedItem("Expression").Value);

                            defaultSeted = true;
                        }
                        else
                        {
                            groupIndex = m_editControl.AddGroup(n.Attributes.GetNamedItem("Expression").Value);
                        }
                    }
                    break;

                    case "Image":
                        if (m_editControl.AddImage(
                                n.Attributes.GetNamedItem("Source").Value.Replace("$(ProjectDir)", projectDir),
                                n.Attributes.GetNamedItem("Name").Value,
                                new Point(
                                    int.Parse(n.Attributes.GetNamedItem("XPos").Value),
                                    int.Parse(n.Attributes.GetNamedItem("YPos").Value)
                                    ),
                                new Size(
                                    int.Parse(n.Attributes.GetNamedItem("Width").Value),
                                    int.Parse(n.Attributes.GetNamedItem("Height").Value)
                                    ),
                                groupIndex
                                ) == false)
                        {
                            loadFaild.Add(n.Attributes.GetNamedItem("Source").Value.Replace("$(ProjectDir)", projectDir));
                        }
                        break;
                    }
                }

                if (loadFaild.Count != 0)
                {
                    string text = m_strOpenImageFailed;

                    foreach (string s in loadFaild)
                    {
                        text = text + "\n\n" + s;
                    }

                    MessageBox.Show(text, m_strOpenProject, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                m_editControl.Redraw();

                m_docPath = fileName;

                toolStripStatusLabel.Text = m_strStatusReady;

                AddRecentFiles(fileName);

                m_editControl.Modify = false;
            }
            catch (SystemException exc)
            {
                MessageBox.Show(m_strOpenProjectFailed.Replace("#FILENAME#", fileName) + "\n\n" + exc.Message,
                                m_strOpenProject, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }