private void btnLoad_Click(object sender, Janus.Windows.Ribbon.CommandEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter      = "Xml Files (.xml)|*.xml";
            ofd.FilterIndex = 1;
            DialogResult userClickedOK = ofd.ShowDialog();

            // Process input if the user clicked OK.
            if (userClickedOK == DialogResult.OK)
            {
                btnNewPage.Enabled = true;
                EnableButtonAfterCreateOrNew();
                iObjNumber = 0;

                // Open the selected file to read.
                currentNews = CNewspaper.readXML(ofd.FileName);
                if (currentNews == null)
                {
                    MessageBox.Show("Please open another XML file", "Open file error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                try
                {
                    if (currentNews.LPages.Count > 0)
                    {
                        //reInitZoomUndoRedo();
                        curPageNum            = 1;
                        filename              = ofd.FileName;
                        currentNews.Directory = filename.Substring(0, filename.LastIndexOf("\\"));
                        loadPaper(curPageNum);
                        cbcPages.ComboBox.Items.Clear();
                        for (int i = 0; i < currentNews.NumPages; i++)
                        {
                            cbcPages.ComboBox.Items.Add("Page " + (i + 1));
                        }
                        cbcPages.ComboBox.SelectedIndex = 0;

                        propertyGrid1.Enabled = true;
                        //cbcPages.ComboBox.SelectedIndexChanged += new EventHandler(cbcPages_ComboBox_SelectedIndexChanged);
                        btnZoomIn.Enabled = true;
                        enableToolBar();
                    }
                }
                catch (Exception exp)
                {
                    MessageBox.Show("Please open another XML file", "Open file error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private void btnNew_Click(object sender, Janus.Windows.Ribbon.CommandEventArgs e)
        {
            btnNewPage.Enabled = true;
            EnableButtonAfterCreateOrNew();
            CNewspaper      news   = new CNewspaper();
            frmNewNewspaper frmNew = new frmNewNewspaper();

            frmNew.ShowDialog();
            if (frmNewNewspaper.news != null)
            {
                news = frmNewNewspaper.news;

                propertyGrid1.Enabled = true;
                currentNews           = news;
                curPageNum            = 1;
                filename = "";
                panelInnerScreen.Controls.Clear();
                cbcPages.ComboBox.Items.Clear();
                for (int i = 0; i < currentNews.NumPages; i++)
                {
                    cbcPages.ComboBox.Items.Add("Page " + (i + 1));
                    CPage p = new CPage();
                    p.HeightP = news.DefaultH;
                    p.WidthP  = news.DefaultW;
                    currentNews.LPages.Add(p);
                }
                currentNews.AttBgk.BackgrHeight       = currentNews.LPages[0].HeightP;
                currentNews.AttBgk.BackgrWidth        = currentNews.LPages[0].WidthP;
                this.panelInnerScreen.BackgroundImage = null;
                this.panelInnerScreen.BackColor       = Color.White;
                this.panelInnerScreen.Height          = currentNews.AttBgk.BackgrHeight;
                this.panelInnerScreen.Width           = currentNews.AttBgk.BackgrWidth;
                this.propertyGrid1.SelectedObject     = currentNews.AttBgk;

                enableToolBar();
                btnZoomIn.Enabled = true;
                cbcPages.ComboBox.SelectedIndex = 0;

                currentNews.Directory = Directory.GetCurrentDirectory() + @"\" + currentNews.KindOfNews + "-" + currentNews.Number.ToString();
                Directory.CreateDirectory(currentNews.Directory);
                reInitZoomUndoRedo();
                lstMarker = new List <INewsPaperControl>();
                MarkerList.lstMarkerList = new List <string>();
            }
        }
        private void btCreate_Click(object sender, EventArgs e)
        {
			news = new CNewspaper();
            news.KindOfNews = cbNewspaper.Text;
            news.Number = (int)nudNumber.Value;
            news.NumPages = (int)nudPages.Value;
            news.DefaultH = (int)nudH.Value;
            news.DefaultW = (int)nudW.Value;
            if (news.NumPages == 0)
            {
                MessageBox.Show("Please fill the number of pages!", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            news.Datetime = dtpDate.Value.Day.ToString() + "/" +
                dtpDate.Value.Month.ToString() + "/" +
                dtpDate.Value.Year.ToString();
            this.Close();
        }
Exemple #4
0
        public static bool writeXML(CNewspaper news, string filename)
        {
            List <INewsPaperControl> lstMarker = new List <INewsPaperControl>();

            foreach (CPage page in news.LPages)
            {
                List <INewsPaperControl> lstControl = new List <INewsPaperControl>();
                foreach (INewsPaperControl c in page.lstNewsPaperControl)
                {
                    if (c.getName() == "NewsPaperMarker")
                    {
                        lstMarker.Add(c);
                    }
                }
                foreach (INewsPaperControl c in page.lstNewsPaperControl)
                {
                    if (c.getName() != "NewsPaperMarker")
                    {
                        foreach (INewsPaperControl marker in lstMarker)
                        {
                            if (marker.getAttList().getInstanceName() == c.getAttList().getMarkerName())
                            {
                                Size  SizeOfMarker           = marker.getAttList().getSize();
                                Point LocationOfMarker       = marker.getAttList().getLocation();
                                Point MedianLocationOfMarker = new Point(LocationOfMarker.X + SizeOfMarker.Width / 2, LocationOfMarker.Y + SizeOfMarker.Height / 2);

                                Point NewLocationOfControl = new Point(c.getAttList().getLocation().X - MedianLocationOfMarker.X, MedianLocationOfMarker.Y - c.getAttList().getLocation().Y);
                                c.getAttList().setLocation(NewLocationOfControl);
                                break;
                            }
                        }
                    }
                }
            }

            try
            {
                XmlDocument xmlDoc      = new XmlDocument();
                XmlElement  xmlEleRoot  = xmlDoc.CreateElement("newspaper");
                XmlElement  xmlElePages = xmlDoc.CreateElement("pages");

                XmlElement xmlEleTitle = xmlDoc.CreateElement("title");
                xmlEleTitle.InnerText = news.KindOfNews;
                xmlEleRoot.AppendChild(xmlEleTitle);

                XmlElement xmlEleDate = xmlDoc.CreateElement("date");
                xmlEleDate.InnerText = news.Datetime;
                xmlEleRoot.AppendChild(xmlEleDate);

                XmlElement xmlElePageNum = xmlDoc.CreateElement("numpages");
                xmlElePageNum.InnerText = news.numPages.ToString();
                xmlEleRoot.AppendChild(xmlElePageNum);

                XmlElement xmlEleNumber = xmlDoc.CreateElement("number");
                xmlEleNumber.InnerText = news.number.ToString();
                xmlEleRoot.AppendChild(xmlEleNumber);

                for (int i = 0; i < news.LPages.Count; i++)
                {
                    XmlElement xmlElePage = xmlDoc.CreateElement("page");

                    XmlAttribute xmlAttWidth = xmlDoc.CreateAttribute("width");
                    xmlAttWidth.Value = news.LPages[i].WidthP.ToString();
                    xmlElePage.Attributes.Append(xmlAttWidth);

                    XmlAttribute xmlAttHeight = xmlDoc.CreateAttribute("height");
                    xmlAttHeight.Value = news.LPages[i].HeightP.ToString();
                    xmlElePage.Attributes.Append(xmlAttHeight);

                    XmlAttribute xmlAttBackground = xmlDoc.CreateAttribute("backgroundURL");
                    xmlAttBackground.Value = news.LPages[i].StrBackground;
                    xmlElePage.Attributes.Append(xmlAttBackground);

                    for (int j = 0; j < news.LPages[i].lstNewsPaperControl.Count; j++)
                    {
                        XmlDocument xmlDocPage = new XmlDocument();
                        xmlDocPage.LoadXml(news.LPages[i].lstNewsPaperControl[j].toXMLString());

                        XmlElement xmlEleObject = null;
                        if (news.LPages[i].lstNewsPaperControl[j].getName() == "NewsPaperMarker")
                        {
                            xmlEleObject = xmlDoc.CreateElement("marker");
                            foreach (XmlNode n in xmlDocPage.SelectNodes("marker//*"))
                            {
                                XmlElement xmlE = xmlDoc.CreateElement(n.Name);
                                xmlE.InnerText = n.InnerText;
                                xmlEleObject.AppendChild(xmlE);
                            }
                        }
                        else
                        {
                            xmlEleObject = xmlDoc.CreateElement("object");
                            foreach (XmlNode n in xmlDocPage.SelectNodes("object//*"))
                            {
                                XmlElement xmlE = xmlDoc.CreateElement(n.Name);
                                xmlE.InnerText = n.InnerText;
                                xmlEleObject.AppendChild(xmlE);
                            }
                        }

                        xmlElePage.AppendChild(xmlEleObject);
                    }

                    xmlElePages.AppendChild(xmlElePage);
                }

                xmlEleRoot.AppendChild(xmlElePages);
                xmlDoc.AppendChild(xmlEleRoot);

                xmlDoc.Save(filename);
            }
            catch { return(false); }

            foreach (CPage page in news.LPages)
            {
                ReCalculteRealLocation(page, lstMarker);
            }
            return(true);
        }
Exemple #5
0
        public static CNewspaper readXML(string filename)
        {
            CNewspaper news = new CNewspaper();

            news.Directory = filename.Substring(0, filename.LastIndexOf("\\"));

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(filename);

            news.KindOfNews = xmlDoc.SelectSingleNode("//title").InnerText;
            news.Datetime   = xmlDoc.SelectSingleNode("//date").InnerText;
            news.NumPages   = int.Parse(xmlDoc.SelectSingleNode("//numpages").InnerText);
            news.Number     = int.Parse(xmlDoc.SelectSingleNode("//number").InnerText);
            foreach (XmlNode n in xmlDoc.SelectNodes("//page"))
            {
                CPage p = new CPage();
                p.HeightP = int.Parse(n.Attributes["height"].Value);
                p.WidthP  = int.Parse(n.Attributes["width"].Value);
                string strBackURL = n.Attributes["backgroundURL"].Value;
                if (strBackURL == "")
                {
                    p.StrBackground = "";
                }
                else
                {
                    p.StrBackground = news.Directory + "\\" + strBackURL;
                }

                foreach (XmlNode xmlNodeObject in n.SelectNodes("object"))
                {
                    string strControlName = xmlNodeObject.SelectSingleNode("type").InnerText;
                    for (int i = 0; i < MainProgram.m_MyControlList.LstNewsPaperControl.Count; i++)
                    {
                        if (MainProgram.m_MyControlList.LstNewsPaperControl[i].getName() == strControlName)
                        {
                            Assembly Asm = Assembly.LoadFile(MainProgram.m_MyControlList.LstNewsPaperControl[i].getDllPath());
                            foreach (Type AsmType in Asm.GetTypes())
                            {
                                if (AsmType.GetInterface("INewsPaperControl") != null && AsmType.Name != "NewsPaperControlBase")
                                {
                                    NewsPaperControlBase Plugin = (NewsPaperControlBase)Activator.CreateInstance(AsmType);
                                    Plugin.loadfromXML(xmlNodeObject.OuterXml, news.Directory + "\\");
                                    p.lstNewsPaperControl.Add(Plugin);
                                    break;
                                }
                            }
                            break;
                        }
                    }
                }

                foreach (XmlNode xmlNodeObject in n.SelectNodes("marker"))
                {
                    string strControlName = "NewsPaperMarker";
                    for (int i = 0; i < MainProgram.m_MyControlList.LstNewsPaperControl.Count; i++)
                    {
                        if (MainProgram.m_MyControlList.LstNewsPaperControl[i].getName() == strControlName)
                        {
                            Assembly Asm = Assembly.LoadFile(MainProgram.m_MyControlList.LstNewsPaperControl[i].getDllPath());
                            foreach (Type AsmType in Asm.GetTypes())
                            {
                                if (AsmType.GetInterface("INewsPaperControl") != null && AsmType.Name != "NewsPaperControlBase")
                                {
                                    NewsPaperControlBase Plugin = (NewsPaperControlBase)Activator.CreateInstance(AsmType);
                                    Plugin.loadfromXML(xmlNodeObject.OuterXml, news.Directory + "\\");
                                    p.lstNewsPaperControl.Add(Plugin);
                                    break;
                                }
                            }
                            break;
                        }
                    }
                }

                news.LPages.Add(p);
            }

            foreach (CPage page in news.LPages)
            {
                List <INewsPaperControl> lstMarker  = new List <INewsPaperControl>();
                List <INewsPaperControl> lstControl = new List <INewsPaperControl>();
                foreach (INewsPaperControl c in page.lstNewsPaperControl)
                {
                    if (c.getName() == "NewsPaperMarker")
                    {
                        lstMarker.Add(c);
                    }
                }
                ReCalculteRealLocation(page, lstMarker);
            }

            return(news);
        }
        private bool saveToXMLFile()
        {
            if (filename != "")
            {
                //Delete all files and folder in the current directory
                try
                {
                    System.IO.DirectoryInfo directory = new DirectoryInfo(currentNews.Directory);
                    foreach (System.IO.FileInfo file in directory.GetFiles())
                    {
                        file.Delete();
                    }
                    foreach (System.IO.DirectoryInfo subDirectory in directory.GetDirectories())
                    {
                        directory.Delete(true);
                    }
                }
                catch { };

                CNewspaper.writeXML(currentNews, filename);

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(filename);

                foreach (XmlNode n in xmlDoc.SelectNodes("//object/marker"))
                {
                    if (n.InnerText == null || n.InnerText == "")
                    {
                        MessageBox.Show("Some objects lack Marker element");
                        return(false);
                    }
                }

                foreach (XmlNode n in xmlDoc.SelectNodes("//uri"))
                {
                    try
                    {
                        string strFileName    = n.InnerText.Substring(n.InnerText.LastIndexOf("\\") + 1);
                        string strOldFileName = n.InnerText;
                        n.InnerText = strFileName;
                        System.IO.File.Copy(strOldFileName, currentNews.Directory + "\\" + strFileName);
                        //n.InnerText = currentNews.Directory + "\\" + strFileName;
                    }
                    catch { };
                }

                foreach (XmlNode n in xmlDoc.SelectNodes("//page"))
                {
                    try
                    {
                        string str = n.Attributes["backgroundURL"].Value;
                        str = str.Substring(str.LastIndexOf("\\") + 1);
                        string strOldFileName = n.Attributes["backgroundURL"].Value;
                        n.Attributes["backgroundURL"].Value = str;
                        System.IO.File.Copy(strOldFileName, currentNews.Directory + "\\" + str);
                        //n.Attributes["backgroundURL"].Value = currentNews.Directory + "\\" + str;
                    }
                    catch { };
                }

                xmlDoc.Save(filename);

                System.Diagnostics.Process prc = new System.Diagnostics.Process();
                prc.StartInfo.FileName = currentNews.Directory;
                prc.Start();

                return(true);
            }
            return(false);
        }