/// <summary>
        /// 导入电缆汇总清单
        /// </summary>
        /// <param name="numberNo">流水号</param>
        /// <param name="path">文件路径</param>
        public void InsertCableSummarizedBill(string numberNo, string path)
        {
            var        cableConstantall  = _cableConstantRepository.GetAll().ToList();
            var        bridgeConstantall = _bridgeConstantRepository.GetAll().ToList();
            string     file = _hostingEnvironment.WebRootPath + "/upload/" + numberNo + ".xlsx";
            NPOIHelper nPOI = new NPOIHelper(file);

            try
            {
                Workbook wb       = new Workbook(path);
                var      sheet    = wb.Worksheets[0];
                int      errorcol = 1;
                List <BridgeInstances> instances = new List <BridgeInstances>();
                for (int i = 1; i < sheet.Cells.MaxRow + 1; i++)
                {
                    string message = "默认";
                    CableSummarizedBillDto entityDto = new CableSummarizedBillDto();
                    PropertyInfo[]         propertys = entityDto.GetType().GetProperties();
                    for (int j = 0; j < propertys.Length; j++)
                    {
                        propertys[j].SetValue(entityDto, (sheet.Cells[i, j].Value ?? "").ToString().Trim());
                    }
                    var entity = new CableSummarizedBill();
                    entity.Id          = Guid.NewGuid().ToString("N");
                    entity.Description = numberNo;
                    ObjectMapper.Map(entityDto, entity);
                    try
                    {
                        message = "电缆型号或规格不匹配";
                        var cable = cableConstantall.FirstOrDefault(u => u.Version == entityDto.U && u.Specification.Replace("×", "x") == entityDto.V.Replace("×", "x"));
                        entity.WeightLimit = 999;
                        entity.Diameter    = 999;
                        if (double.TryParse(cable.WeightLimit, out double weightLimit))
                        {
                            entity.WeightLimit = weightLimit;
                        }
                        if (double.TryParse(cable.Diameter, out double diameter))
                        {
                            entity.Diameter = diameter;
                        }
                        _cableSummarizedBillRepository.Insert(entity);
                        message = "桥架编码不存在";
                        InsertBridgeInstances(numberNo, entity.Q, entity.Z, bridgeConstantall, instances);
                        //同时把电缆路径拆分,插入桥架实例表中
                    }
                    catch (Exception e)
                    {
                        nPOI.InsertCableSummarizedBill(file, entity, message, errorcol);
                        errorcol++;
                    }
                }
                nPOI.Save();
                _bridgeInstancesRepository.InsertBatch(instances);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Пример #2
0
        public void InsertCableSummarizedBill(string path, CableSummarizedBill entity, string message, int rownum = 1)
        {
            var sheet = workbook.GetSheetAt(1);
            var row   = sheet.CreateRow(rownum);

            row.CreateCell(0).SetCellValue(entity.A);
            row.CreateCell(1).SetCellValue(entity.C);
            row.CreateCell(2).SetCellValue(entity.U);
            row.CreateCell(3).SetCellValue(entity.V);
            row.CreateCell(4).SetCellValue(entity.Q);
            row.CreateCell(5).SetCellValue(entity.Z);
            row.CreateCell(6).SetCellValue(message);
        }