Esempio n. 1
0
        public override ParseResult ParseBookInto(Workbook workbook, TDetail detail)
        {
            //通用信息
            Worksheet sheet = workbook.Sheets[1] as Worksheet;

            //ReportName
            detail.ReportName = sheet.GetCellValueAsString(1, 1).Trim() + sheet.GetCellValueAsString(2, 1).Trim();
            //Contractor,Supervisor,Monitor
            Regex regex = new Regex(@"\s?承包单位:(.+)\s+监理单位:(.+)\s+监测单位:(.+)\s?");
            var   match = regex.Match(sheet.GetCellValueAsString(3, 1));

            if (match.Groups.Count != 4)
            {
                return(ParseResult.Participants_ParseFailure);
            }
            detail.Contractor = match.Groups[1].ToString().Trim();
            detail.Supervisor = match.Groups[2].ToString().Trim();
            detail.Monitor    = match.Groups[3].ToString().Trim();
            //IssueDateTime,IssueTimeRange
            regex = new Regex(@"\s?监测日期:(.+)\s+监测时间:(.+)-(.+)\s?");
            match = regex.Match(sheet.GetCellValueAsString(5, 1));
            if (match.Groups.Count != 4)
            {
                return(ParseResult.DateTime_ParseFailure);
            }
            var dateArgs      = match.Groups[1].ToString().Split('.').Select(c => int.Parse(c)).ToArray();
            var startTimeArgs = match.Groups[2].ToString().Split(':').Select(c => int.Parse(c)).ToArray();
            var endTimeArgs   = match.Groups[3].ToString().Split(':').Select(c => int.Parse(c)).ToArray();
            var startTime     = new DateTime(dateArgs[0], dateArgs[1], dateArgs[2], startTimeArgs[0], startTimeArgs[1], 0);
            var endTime       = new DateTime(dateArgs[0], dateArgs[1], dateArgs[2], endTimeArgs[0], endTimeArgs[1], 0);

            if (endTime < startTime)//如23:00-1:00认为跨天 但是跨天不支持10:00-11:00(第二天的11:00),这种情况跨天比较特殊,甚至跨多天,这个需要另提需求处理
            {
                endTime.AddDays(1);
            }
            //检测:监测时间的日期需与列表一致
            if (startTime.Date != detail.IssueDateTime.Date)
            {
                return(ParseResult.Date_Invalid);
            }
            if (!string.IsNullOrEmpty(detail.InstrumentCode) && startTime.Hour != detail.IssueDateTime.Hour)
            {
                return(ParseResult.Time_Invalid);
            }
            detail.IssueDateTime  = startTime;
            detail.IssueTimeRange = (short)(endTime - startTime).TotalMinutes;
            //InstrumentName,InstrumentCode
            regex = new Regex(@"\s?仪器名称:(.+)\s+仪器编号:(.+)\s?");
            match = regex.Match(sheet.GetCellValueAsString(6, 1));
            if (match.Groups.Count != 3)
            {
                return(ParseResult.Instrument_ParseFailure);
            }
            detail.InstrumentName = match.Groups[1].ToString().Trim();
            detail.InstrumentCode = match.Groups[2].ToString().Trim();
            //节点解析
            detail.DepthNodes = new List <TDepthNode>();
            foreach (Worksheet subSheet in workbook.Sheets)
            {
                int    currentRow = 9;
                string cellValue  = sheet.GetCellValueAsString(currentRow, 1);
                while (!string.IsNullOrEmpty(cellValue) && !cellValue.Contains("备注"))
                {
                    var data = new SkewBackDataV1(
                        subSheet.Name,
                        sheet.GetCellValueAsString(currentRow, 1),
                        sheet.GetCellValueAsString(currentRow, 2),
                        sheet.GetCellValueAsString(currentRow, 3),
                        sheet.GetCellValueAsString(currentRow, 4),
                        sheet.GetCellValueAsString(currentRow, 5)
                        );
                    var depthNode = new TDepthNode(detail.IssueType, detail.IssueDateTime, subSheet.Name, data.Depth);
                    depthNode.Data = data.SerializeToString();
                    detail.DepthNodes.Add(depthNode);
                    currentRow++;
                    cellValue = sheet.GetCellValueAsString(currentRow, 1);
                }
            }
            return(ParseResult.Success);
        }
Esempio n. 2
0
 public List <ElementId> GetElementIdsByTDepthNode(TDepthNode node, Document doc)
 {
     return(GetElementIds(node.NodeCode, node.Depth, doc));
 }