/// <summary>
        /// 转换所有Project
        /// </summary>
        /// <param name="bll"></param>
        public static void GenerateXinHuaProjects(BllManager bll, string outPath)
        {
            session = bll.manager.session;
            IList<Prj_Project> projects = bll.manager.ProjectCRUD.GetPrj_Projects();    // 加载全部工程列表

            GenerateXinHuaControls(bll, projects[0], outPath);
        }
        private static int maxPage = 0;                 // 输出的页面数量(生成画面时),0:不限制

        /// <summary>
        /// 生成页面目录文件
        /// </summary>
        /// <param name="bll"></param>
        /// <param name="outPath">项目输出路径,页面文件的输出路径为:outPath + "\\data\\xinhua"</param>
        public static void GenerateXinHuaPageList(BllManager bll, string outPath)
        {
            string filePath = outPath + "\\data\\xinhua\\";
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }

            XmlTextWriter listWriter = new XmlTextWriter(filePath + "PageList.xml", Encoding.UTF8);
            listWriter.Indentation = 4;
            listWriter.Formatting = Formatting.Indented;

            IList<Prj_Project> projects = bll.manager.ProjectCRUD.GetPrj_Projects();
            listWriter.WriteStartElement("XDPS");
            listWriter.WriteAttributeString("Describe", projects[0].ProjectName);

            IList<Prj_Network> networks = bll.manager.NetworkCRUD.GetPrj_Networks_By_Prj_Project_ID(projects[0].ID);
            IList<Prj_Unit> units = bll.manager.UnitCRUD.GetPrj_Units_By_Prj_Network_ID(networks[0].ID);
            IList<Prj_Controller> controllers = bll.manager.ControllerCRUD.GetPrj_Controllers_By_Prj_Unit_ID(units[0].ID);

            foreach (Prj_Controller controller in controllers)
            {
                listWriter.WriteStartElement("DPU");
                listWriter.WriteAttributeString("Drop", controller.ControllerAddress);
                listWriter.WriteAttributeString("Name", controller.ControllerName);
                listWriter.WriteAttributeString("Describe", controller.Description);
                listWriter.WriteAttributeString("Version", controller.Version);

                IList<Prj_Document> documents = bll.manager.DocumentCRUD.GetPrj_Documents_By_Prj_Controller_ID(controller.ID);
                foreach (Prj_Document document in documents)
                {
                    listWriter.WriteStartElement("Page");
                    listWriter.WriteAttributeString("PageNum", document.DocumentName.Substring(document.DocumentName.LastIndexOf('-') + 1));
                    listWriter.WriteAttributeString("Describe", document.DocumentCaption);
                    listWriter.WriteEndElement();
                }

                listWriter.WriteEndElement();
            }

            listWriter.WriteEndElement();
            listWriter.Close();
        }
        /// <summary>
        /// 转换所有Control
        /// </summary>
        /// <param name="bll"></param>
        /// <param name="project"></param>
        public static void GenerateXinHuaControls(BllManager bll, Prj_Project project, string outPath)
        {
            // 新华系统中,每个Project仅包含一个Network,每个Network仅包含一个Unit
            IList<Prj_Network> networks = bll.manager.NetworkCRUD.GetPrj_Networks_By_Prj_Project_ID(project.ID);
            IList<Prj_Unit> units = networks.Count > 0 ? bll.manager.UnitCRUD.GetPrj_Units_By_Prj_Network_ID(networks[0].ID) : new List<Prj_Unit>();
            IList<Prj_Controller> controllers = units.Count > 0 ? bll.manager.ControllerCRUD.GetPrj_Controllers_By_Prj_Unit_ID(units[0].ID) : new List<Prj_Controller>();

            for (int i = 0; i < controllers.Count; i++)
            {
                GeneralXinHuaDocuments(bll, controllers[i], outPath);
            }
        }
        /// <summary>
        /// Prj_Sheet to Xml
        /// </summary>
        /// <param name="sheet"></param>
        public static void GenerateXinHuaSheets(BllManager bll, Prj_Document documet, string outPath)
        {
            string pagesPath = outPath + "\\data\\xinhua\\Pages\\";
            if (!Directory.Exists(pagesPath))
            {
                Directory.CreateDirectory(pagesPath);
            }

            if (session == null)
            {
                session = bll.manager.session;
            }

            try
            {
                // 每个Document只包含一个Sheet
                int sheetID = bll.manager.SheetCRUD.GetPrj_Sheets_By_Prj_Document_ID(documet.ID)[0].ID;
                Prj_Sheet sheet = bll.manager.SheetCRUD.Load_Sheet(sheetID);

                ArrayList symbols = new ArrayList();

                // 算法块

                foreach (Cld_FCBlock block in sheet.Cld_FCBlock_List)
                {

                    #region if(特殊块)
                    if (block.FunctionName == "XAI")
                    {
                        GenerateXAIBlock(block, symbols);
                    }
                    else if (block.FunctionName == "XAO")
                    {
                        GenerateXAOBlock(block, symbols);
                    }
                    else if (block.FunctionName == "XDI")
                    {
                        GenerateXDIBlock(block, symbols);
                    }
                    else if (block.FunctionName == "XDO")
                    {
                        GenerateXDOBlock(block, symbols);
                    }
                    else if (block.FunctionName == "XPI")
                    {
                        GenerateXPIBlock(block, symbols);
                    }
                    else if (block.FunctionName == "XPgAI")
                    {
                        GenerateXPgAIBlock(block, symbols);
                    }
                    else if (block.FunctionName == "XPgAO")
                    {
                        GenerateXPgAOBlock(block, symbols);
                    }
                    else if (block.FunctionName == "XPgDI")
                    {
                        GenerateXPgDIBlock(block, symbols);
                    }
                    else if (block.FunctionName == "XPgDO")
                    {
                        GenerateXPgDOBlock(block, symbols);
                    }
                    else if (block.FunctionName == "XNetAI")
                    {
                        GenerateXNetAIBlock(block, symbols);
                    }
                    else if (block.FunctionName == "XNetAO")
                    {
                        GenerateXNetAOBlock(block, symbols);
                    }
                    else if (block.FunctionName == "XNetDI")
                    {
                        GenerateXNetDIBlock(block, symbols);
                    }
                    else if (block.FunctionName == "XNetDO")
                    {
                        GenerateXNetDOBlock(block, symbols);
                    }
                    #endregion
                    else
                    {
                        bll.generate_Rec_symbol(block, BllManager.rela_pos.UPLEFT);
                        GenerateCommonBlock(block, symbols);
                    }
                }

                // 文本块

                foreach (Cld_Graphic graphic in sheet.Cld_Graphic_List)
                {
                    if (graphic.Type == "Text")
                    {
                        GenerateText(graphic, symbols);
                    }
                }

                //IList constants = sheet.Cld_Constant_List;

                // 信号线

                IDictionary<string, Cld_Signal> signalTable = bll.GenerateSignalLines(sheet);
                foreach (Cld_Signal signal in signalTable.Values)
                {
                    string[] signalDataList = signal.Data.TrimEnd(' ', ';').Split(';');
                    foreach (string signalData in signalDataList)
                    {
                        LogicSignalLine signalline = new LogicSignalLine(signalData, signal.Name, signal.SignalType);
                        symbols.Add(signalline);
                    }
                }

                // 创建XmlTextWriter类的实例对象
                XmlTextWriter textWriter = new XmlTextWriter(pagesPath + documet.DocumentName.Replace('-', '_') + ".xfig", Encoding.UTF8);
                textWriter.Indentation = 4;
                textWriter.Formatting = Formatting.Indented;

                textWriter.WriteStartElement("document");
                textWriter.WriteAttributeString("Type", "BeginNode");
                textWriter.WriteAttributeString("GraphicName", documet.DocumentCaption);
                textWriter.WriteAttributeString("BackColor", "FF FF FF FF");
                textWriter.WriteAttributeString("width", Convert.ToString(sheet.Width * 10));
                textWriter.WriteAttributeString("heigth", Convert.ToString(sheet.Height * 10));

                LogicRectangle pageBounds0 = new LogicRectangle();
                pageBounds0.Location = new PointF(0, 0);
                pageBounds0.Size = new SizeF(sheet.Width, sheet.Height);
                pageBounds0.LineWidth = 1;
                pageBounds0.GetXinhuaGraphicXml(textWriter);

                LogicRectangle pageBounds1 = new LogicRectangle();
                pageBounds1.Location = new PointF(30, 30);
                pageBounds1.Size = new SizeF(sheet.Width - 60f, sheet.Height - 60f);
                pageBounds1.LineWidth = 2;
                pageBounds1.GetXinhuaGraphicXml(textWriter);

                foreach (object obj in symbols)
                {
                    ((ILogicGraphicFormat)obj).GetXinhuaGraphicXml(textWriter);
                }
                textWriter.WriteEndElement();
                textWriter.Close();
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
        /// <summary>
        /// 转换所有Document
        /// </summary>
        /// <param name="bll"></param>
        /// <param name="path"></param>
        /// <param name="listWriter"></param>
        /// <param name="controller"></param>
        public static void GeneralXinHuaDocuments(BllManager bll, Prj_Controller controller, string outPath)
        {
            IList<Prj_Document> documents = bll.manager.DocumentCRUD.GetPrj_Documents_By_Prj_Controller_ID(controller.ID);

            for (int i = 0; i < documents.Count; i++)
            {
                Prj_Document document = documents[i];
                string pageNum = document.DocumentName.Substring(document.DocumentName.LastIndexOf('-') + 1);

                // 生成页面文件
                GenerateXinHuaSheets(bll, document, outPath);
            }
        }
Example #6
0
        /// <summary>
        /// Prj_Sheet To Xml
        /// </summary>
        /// <param name="sheet"></param>
        public static void Generate_Sheet_Xml(Prj_Sheet sheet, BllManager bll)
        {
            //因为此方法采用反射来获取类中的所有共有属性进行输出,因此这里屏蔽对象中的某些不需要输出的属性
            List<string> myclass = new List<string>();
            myclass.Add("Prj_Project");
            myclass.Add("Prj_Network");
            myclass.Add("Prj_Unit");
            myclass.Add("Prj_Controller");
            myclass.Add("Prj_Document");
            myclass.Add("Prj_Sheet");
            myclass.Add("Cld_FCBlock");
            myclass.Add("Cld_Signal");
            myclass.Add("Cld_Constant");
            myclass.Add("Cld_Graphic");
            myclass.Add("X");
            myclass.Add("Y");
            myclass.Add("PinIndex");

            try
            {
                // 创建XmlTextWriter类的实例对象
                XmlTextWriter textWriter = new XmlTextWriter(sheet.ID.ToString() + ".xml", null);
                textWriter.Formatting = Formatting.Indented;

                // 开始写过程,调用WriteStartDocument方法
                textWriter.WriteStartDocument();
                // 写入说明
                textWriter.WriteComment("First Comment XmlTextWriter Sample Example");
                textWriter.WriteComment("w3sky.xml in root dir");

                Type sheet_type = typeof(Prj_Sheet);
                Type fcblock_type = typeof(Cld_FCBlock);
                Type fcconst_type = typeof(Cld_Constant);
                Type fcgraphic_type = typeof(Cld_Graphic);
                Type fcsignal_type = typeof(Cld_Signal);
                Type fcinput_type = typeof(Cld_FCInput);
                Type fcoutput_type = typeof(Cld_FCOutput);
                Type fcpara_type = typeof(Cld_FCParameter);



                //创建sheet结点
                textWriter.WriteStartElement("sheet");
                foreach (PropertyInfo pi in sheet_type.GetProperties())
                {
                    object value_object = pi.GetValue(sheet, null);
                    string value_string = "";

                    if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name))
                    {
                        continue;
                    }
                    if (value_object != null)
                    {
                        value_string = value_object.ToString();
                    }
                    textWriter.WriteAttributeString(pi.Name, value_string);
                }


                //fcblock
                foreach (Cld_FCBlock fcblock in sheet.Cld_FCBlock_List)
                {
                    textWriter.WriteStartElement("element");
                    textWriter.WriteAttributeString("type", "Cld_FCBlock");

                    bll.generate_Rec_symbol(fcblock, TDK.Core.Logic.BLL.BllManager.rela_pos.UPLEFT);

                    foreach (PropertyInfo pi in fcblock_type.GetProperties())
                    {
                        object value_object = pi.GetValue(fcblock, null);
                        string value_string = "";

                        if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name))
                        {
                            continue;
                        }
                        if (value_object != null)
                        {
                            value_string = value_object.ToString();
                        }
                        textWriter.WriteAttributeString(pi.Name, value_string);
                    }

                    foreach (Cld_FCInput input in fcblock.Cld_FCInput_List)
                    {
                        textWriter.WriteStartElement("element");
                        textWriter.WriteAttributeString("type", "Cld_FCInput");
                        foreach (PropertyInfo pi in fcinput_type.GetProperties())
                        {
                            object value_object = pi.GetValue(input, null);
                            string value_string = "";

                            if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name))
                            {
                                continue;
                            }
                            if (value_object != null)
                            {
                                value_string = value_object.ToString();
                            }
                            textWriter.WriteAttributeString(pi.Name, value_string);
                        }
                        textWriter.WriteEndElement();
                    }

                    //foreach (Cld_FCOutput output in fcblock.Cld_FCOutput_List)
                    //{
                    //    textWriter.WriteStartElement("element");
                    //    textWriter.WriteAttributeString("type", "FCOutput");
                    //    foreach (PropertyInfo pi in fcoutput_type.GetProperties())
                    //    {
                    //        object value_object = pi.GetValue(output, null);
                    //        string value_string = "";

                    //        if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name))
                    //        {
                    //            continue;
                    //        }
                    //        if (value_object != null)
                    //        {
                    //            value_string = value_object.ToString();
                    //        }
                    //        textWriter.WriteAttributeString(pi.Name, value_string);
                    //    }
                    //    textWriter.WriteEndElement();
                    //}
                    //foreach (Cld_FCParameter para in fcblock.Cld_FCParameter_List)
                    //{
                    //    textWriter.WriteStartElement("element");
                    //    textWriter.WriteAttributeString("type", "Cld_FCParameter");
                    //    foreach (PropertyInfo pi in fcpara_type.GetProperties())
                    //    {
                    //        object value_object = pi.GetValue(para, null);
                    //        string value_string = "";

                    //        if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name))
                    //        {
                    //            continue;
                    //        }
                    //        if (value_object != null)
                    //        {
                    //            value_string = value_object.ToString();
                    //        }
                    //        textWriter.WriteAttributeString(pi.Name, value_string);
                    //    }
                    //    textWriter.WriteEndElement();
                    //}
                    textWriter.WriteEndElement();
                }

                ////const
                //foreach (Cld_Constant cldconst in sheet.Cld_Constant_List)
                //{
                //    textWriter.WriteStartElement("element");
                //    textWriter.WriteAttributeString("type", "Cld_Constant");
                //    foreach (PropertyInfo pi in fcconst_type.GetProperties())
                //    {
                //        object value_object = pi.GetValue(cldconst, null);
                //        string value_string = "";

                //        if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name))
                //        {
                //            continue;
                //        }
                //        if (value_object == null)
                //        {
                //            value_string = value_object.ToString();
                //        }
                //        textWriter.WriteAttributeString(pi.Name, value_string);
                //    }
                //    textWriter.WriteEndElement();
                //}

                ////graphic
                //foreach (Cld_Graphic graphic in sheet.Cld_Graphic_List)
                //{
                //    textWriter.WriteStartElement("element");
                //    textWriter.WriteAttributeString("type", "Cld_Graphic");
                //    foreach (PropertyInfo pi in fcgraphic_type.GetProperties())
                //    {
                //        object value_object = pi.GetValue(graphic, null);
                //        string value_string = "";

                //        if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name))
                //        {
                //            continue;
                //        }
                //        if (value_object == null)
                //        {
                //            value_string = value_object.ToString();
                //        }
                //        textWriter.WriteAttributeString(pi.Name, value_string);
                //    }
                //    textWriter.WriteEndElement();
                //}

                ////signal
                //foreach (Cld_Signal signal in sheet.Cld_Signal_List)
                //{
                //    textWriter.WriteStartElement("element");
                //    textWriter.WriteAttributeString("type", "Cld_Signal");
                //    foreach (PropertyInfo pi in fcsignal_type.GetProperties())
                //    {
                //        object value_object = pi.GetValue(signal, null);
                //        string value_string = "";

                //        if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name))
                //        {
                //            continue;
                //        }
                //        if (value_object == null)
                //        {
                //            value_string = value_object.ToString();
                //        }
                //        textWriter.WriteAttributeString(pi.Name, value_string);
                //    }
                //    textWriter.WriteEndElement();
                //}

                textWriter.WriteEndElement();

                // 关闭textWriter
                textWriter.Close();
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.ToString());
            }

        }