コード例 #1
0
        public override TEarthworkBlocking Import(Workbook workbook)
        {
            var sheet = ExcelHelper.GetWorksheet(workbook, EIssueType.GetSheetName());

            if (!WorksheetCheck(sheet))
            {
                return(null);
            }

            int  rowIndex         = 2;
            bool isEndTimeEarlier = false;
            bool isStartTimeError = false;
            bool isEndTimeError   = false;
            bool isTimeSpanError  = false;
            TEarthworkBlocking blocking;

            blocking = new TEarthworkBlocking();
            while (!string.IsNullOrEmpty(sheet.GetCellValueAsString(rowIndex, 1)))
            {
                var name         = sheet.GetCellValueAsString(rowIndex, 1);
                var startTimeStr = sheet.GetCellValueAsString(rowIndex, 2);
                var timeSpanStr  = sheet.GetCellValueAsString(rowIndex, 3);
                var endTimeStr   = sheet.GetCellValueAsString(rowIndex, 4);
                var description  = sheet.GetCellValueAsString(rowIndex, 5);
                rowIndex++;
                DateTime startTime, endTime;
                double   timeSpan;
                if (!DateTime.TryParse(startTimeStr, out startTime))
                {
                    isStartTimeError = true;
                    continue;
                }
                if (!DateTime.TryParse(endTimeStr, out endTime))
                {
                    isEndTimeError = true;
                    continue;
                }
                if (startTime > endTime)
                {
                    isEndTimeEarlier = true;
                    continue;
                }
                if (!double.TryParse(timeSpanStr, out timeSpan))
                {
                    isTimeSpanError = true;
                    continue;
                }
                var block = new TEarthworkBlock(DateTime.MinValue, blocking.GetEarthworkBlockMaxId())
                {
                    Name        = name,
                    Description = description,
                    EarthworkBlockImplementationInfo_Obj = new EarthworkBlockImplementationInfo()
                    {
                        StartTime    = startTime,
                        EndTime      = endTime,
                        ExposureTime = timeSpan,
                    }
                };
                blocking.Add(block);
            }
            if (isEndTimeEarlier || isStartTimeError || isEndTimeError || isTimeSpanError)
            {
                ShowMessage("部分导入的数据格式存在异常,或者不符合数据的规范");
            }
        }
コード例 #2
0
 public T Import(string path)
 {
     return(Import(ExcelHelper.GetWorkbook(path)));
 }