Beispiel #1
0
        public void Prepare()
        {
            if (XMLNode != null && String.IsNullOrEmpty(FileName))
            {
                FileName = XMLNode.SelectSingleNode("@name").Value;
            }
            PreparePropertiesList();
            ReadPropertiesFromXMLNode();
            ComputePropertiesValues();

            GenerateTokens();
        }
Beispiel #2
0
 private void ReadPropertiesFromXMLNode()
 {
     if (XMLNode != null)
     {
         foreach (var projectProperty in ProjectProperties.Where(prop => !String.IsNullOrEmpty(prop.PathInFile)))
         {
             XPathNavigator node = XMLNode.SelectSingleNode(projectProperty.PathInFile);
             if (node != null)
             {
                 if (projectProperty.Type == Templates.Templates.Tags)
                 {
                     projectProperty.Words = Convert.ToDecimal(node.Value);
                 }
                 else
                 {
                     projectProperty.Words      = Convert.ToDecimal(node.SelectSingleNode("@words").Value);
                     projectProperty.Characters = Convert.ToDecimal(node.SelectSingleNode("@characters").Value);
                 }
             }
         }
         foreach (var projectProperty in ProjectProperties.Where(prop => String.IsNullOrEmpty(prop.PathInFile)))
         {
             ProjectProperty repsProp;
             ProjectProperty exactProp;
             ProjectProperty fuzzy95;
             ProjectProperty fuzzy85;
             ProjectProperty fuzzy75;
             ProjectProperty fuzzy50;
             if (projectProperty.Type == Templates.Templates.RepsAnd100Percent)
             {
                 repsProp                   = ProjectProperties.FirstOrDefault(prop => prop.Type == Templates.Templates.Repetitions);
                 exactProp                  = ProjectProperties.FirstOrDefault(prop => prop.Type == Templates.Templates.Percent100);
                 projectProperty.Words      = repsProp.Words + exactProp.Words;
                 projectProperty.Characters = repsProp.Characters + exactProp.Characters;
             }
             else if (projectProperty.Type == Templates.Templates.FuzzyMatches)
             {
                 fuzzy95 = ProjectProperties.FirstOrDefault(prop => prop.Type == Templates.Templates.Percent95);
                 fuzzy85 = ProjectProperties.FirstOrDefault(prop => prop.Type == Templates.Templates.Percent85);
                 fuzzy75 = ProjectProperties.FirstOrDefault(prop => prop.Type == Templates.Templates.Percent75);
                 fuzzy50 = ProjectProperties.FirstOrDefault(prop => prop.Type == Templates.Templates.Percent50);
                 projectProperty.Words      = fuzzy50.Words + fuzzy75.Words + fuzzy85.Words + fuzzy95.Words;
                 projectProperty.Characters = fuzzy50.Characters + fuzzy75.Characters + fuzzy85.Characters +
                                              fuzzy95.Characters;
             }
             else if (projectProperty.Type == Templates.Templates.NoMatch)
             {
                 exactProp = ProjectProperties.FirstOrDefault(prop => prop.Type == Templates.Templates.Percent100);
                 fuzzy95   = ProjectProperties.FirstOrDefault(prop => prop.Type == Templates.Templates.Percent95);
                 fuzzy85   = ProjectProperties.FirstOrDefault(prop => prop.Type == Templates.Templates.Percent85);
                 fuzzy75   = ProjectProperties.FirstOrDefault(prop => prop.Type == Templates.Templates.Percent75);
                 fuzzy50   = ProjectProperties.FirstOrDefault(prop => prop.Type == Templates.Templates.Percent50);
                 XPathNavigator node = XMLNode.SelectSingleNode("analyse/total");
                 if (node != null)
                 {
                     decimal totalWords      = Convert.ToDecimal(node.SelectSingleNode("@words").Value);
                     decimal totalCharacters = Convert.ToDecimal(node.SelectSingleNode("@characters").Value);
                     projectProperty.Words = totalWords -
                                             (exactProp.Words + fuzzy50.Words + fuzzy75.Words + fuzzy85.Words +
                                              fuzzy95.Words);
                     projectProperty.Characters = totalCharacters -
                                                  (exactProp.Characters + fuzzy50.Characters + fuzzy75.Characters +
                                                   fuzzy85.Characters + fuzzy95.Characters);
                 }
             }
         }
     }
 }
            //从XML文件读取并检测文件中的成员是否存在
            /// <summary>
            /// 从项目文件中读取数据,并打开相应的Excel程序与工作簿
            /// </summary>
            /// <remarks></remarks>
            public void LoadFromXmlFile()
            {
                //载入文档
                XmlDocument xmlDoc = new XmlDocument();

                xmlDoc.Load(this.P_FilePath);
                //
                clsData_FileContents FC = new clsData_FileContents();
                XMLNode eleRoot         = xmlDoc.SelectSingleNode(System.Convert.ToString(My.Settings.Default.ProjectName));
                //这里可以尝试用GetElementById
                XmlElement Node_DataBase = eleRoot.SelectSingleNode(DataBasePath.Nd1_DataBasePaths);

                if (Node_DataBase == null)
                {
                    return;
                }
                // ---------------------- 读取文档 ------------------------
                // ---------------------- 读取文档 ------------------------

                XmlNodeList eleWkbks = Node_DataBase.GetElementsByTagName(DataBasePath.Nd2_WorkbooksInProject);

                foreach (XmlElement eleWkbk in eleWkbks)
                {
                    string   strWkbkPath = eleWkbk.InnerText;
                    Workbook wkbk        = ExcelFunction.MatchOpenedWkbk(wkbkPath: ref strWkbkPath, Application: ref this.F_Application, OpenIfNotOpened: true);
                    if (wkbk != null)
                    {
                        FC.lstWkbks.Add(wkbk);
                    }
                    else                     //此工作簿不存在,或者是没有成功赋值
                    {
                        this.F_blnFileValid = false;
                        this.F_lstErrorMessage.Add("The Specified Workbook is not found : " + strWkbkPath);
                    }
                }

                // ---------------- 施工进度工作表
                bool        blnNodeForWorksheetValidated = false;
                XmlNodeList eleSheetsProgress            = Node_DataBase.GetElementsByTagName(DataBasePath.Nd2_Progress);

                foreach (XmlElement eleSheetProgress in eleSheetsProgress)
                {
                    Worksheet shtProgress = ValidateNodeForWorksheet(eleSheetProgress, FC, ref blnNodeForWorksheetValidated);
                    if (blnNodeForWorksheetValidated)
                    {
                        FC.lstSheets_Progress.Add(shtProgress);
                    }
                }

                // ---------------- 开挖平面图工作表

                XmlNodeList eleSheetPlanView = Node_DataBase.GetElementsByTagName(DataBasePath.Nd2_PlanView);
                var         shtPlanView      = ValidateNodeForWorksheet((System.Xml.XmlElement)(eleSheetPlanView.Item(0)), FC, ref blnNodeForWorksheetValidated);

                FC.Sheet_PlanView = shtPlanView;

                // ---------------- 开挖剖面图工作表

                XmlNodeList eleSheetSectionalView = Node_DataBase.GetElementsByTagName(DataBasePath.Nd2_SectionalView);
                Worksheet   shtSectionalView      = ValidateNodeForWorksheet((System.Xml.XmlElement)(eleSheetSectionalView.Item(0)), FC, ref blnNodeForWorksheetValidated);

                FC.Sheet_Elevation = shtSectionalView;

                // ---------------- 测点坐标工作表

                XmlNodeList eleSheetPointCoordinates = Node_DataBase.GetElementsByTagName(DataBasePath.Nd2_PointCoordinates);
                Worksheet   shtPoint = ValidateNodeForWorksheet((System.Xml.XmlElement)(eleSheetPointCoordinates.Item(0)), FC, ref blnNodeForWorksheetValidated);

                FC.Sheet_PointCoordinates = shtPoint;

                // ---------------- 开挖工况工作表

                XmlNodeList eleWorkingStage = Node_DataBase.GetElementsByTagName(DataBasePath.Nd2_WorkingStage);
                Worksheet   shtWorkingStage = ValidateNodeForWorksheet((System.Xml.XmlElement)(eleWorkingStage.Item(0)), FC, ref blnNodeForWorksheetValidated);

                FC.Sheet_WorkingStage = shtWorkingStage;
                //
                this.P_FileContents = FC;
                //刷新主程序界面显示
                APPLICATION_MAINFORM.MainForm.MainUI_ProjectOpened();
            }