コード例 #1
0
        public override int ParseDataToDatabase()
        {
            int recordsCount = 0;

            var PVCGroup         = _dbContext.PolymerGroups.Find(1);  // PVC
            var PVCColdGroup     = _dbContext.PolymerGroups.Find(10); // PVC Cold
            var PVCTermGroup     = _dbContext.PolymerGroups.Find(11); //PVC term
            var PVCLSGroup       = _dbContext.PolymerGroups.Find(6);  //PVC LS
            var PVCLSLTxGroup    = _dbContext.PolymerGroups.Find(7);  //PVC LSLTx
            var PESelfExtinguish = _dbContext.PolymerGroups.Find(12); //PE self extinguish

            var polymerGroups = new List <PolymerGroup> {
                PVCGroup, PVCColdGroup, PVCTermGroup, PVCLSGroup
            };
            var polymerGroupsLTx = new List <PolymerGroup> {
                PVCLSLTxGroup
            };
            var polymerGroupsPE = new List <PolymerGroup> {
                PESelfExtinguish
            };
            var polymerGroupsFull = new List <PolymerGroup> {
                PVCGroup, PVCColdGroup, PVCTermGroup, PVCLSGroup, PESelfExtinguish
            };

            var TU2  = _dbContext.TechnicalConditions.Find(1);
            var TU30 = _dbContext.TechnicalConditions.Find(35);
            var TU49 = _dbContext.TechnicalConditions.Find(20);

            var noFireProtectClass    = _dbContext.FireProtectionClasses.Find(1);  //О1.8.2.5.4
            var LSFireProtectClass    = _dbContext.FireProtectionClasses.Find(8);  //П1б.8.2.2.2
            var LSLTxFireProtectClass = _dbContext.FireProtectionClasses.Find(28); //П1б.8.2.1.2

            var PolymerGroupFireClassDict = new Dictionary <PolymerGroup, FireProtectionClass>()
            {
                { PVCGroup, noFireProtectClass },
                { PVCColdGroup, noFireProtectClass },
                { PVCTermGroup, noFireProtectClass },
                { PVCLSGroup, LSFireProtectClass },
                { PVCLSLTxGroup, LSLTxFireProtectClass },
                { PESelfExtinguish, noFireProtectClass }
            };

            var climaticModUHL = _dbContext.ClimaticMods.Find(3);

            var redColor   = _dbContext.Colors.Find(1);
            var blackColor = _dbContext.Colors.Find(2);

            var cableBrandName = _dbContext.CableBrandNames.Find(6);            // КПСВ(Э)

            var operatingVoltage        = _dbContext.OperatingVoltages.Find(6); // 300В 50Гц, постоянка - до 500В
            var operatingVoltageLoutoks = _dbContext.OperatingVoltages.Find(5); // 300В 50Гц

            var twistedElementType = _dbContext.TwistedElementTypes.Find(2);    //pair

            CablePropertySet?cablePropSimple   = null;
            CablePropertySet?cablePropShield   = CablePropertySet.HasFoilShield;
            CablePropertySet?cablePropKG       = CablePropertySet.HasArmourBraid;
            CablePropertySet?cablePropKGShield = CablePropertySet.HasFoilShield | CablePropertySet.HasArmourBraid;
            CablePropertySet?cablePropK        = CablePropertySet.HasArmourBraid | CablePropertySet.HasArmourTube;
            CablePropertySet?cablePropKShield  = CablePropertySet.HasFoilShield | CablePropertySet.HasArmourBraid | CablePropertySet.HasArmourTube;
            CablePropertySet?cablePropB        = CablePropertySet.HasArmourTape | CablePropertySet.HasArmourTube;
            CablePropertySet?cablePropBShield  = CablePropertySet.HasFoilShield | CablePropertySet.HasArmourTape | CablePropertySet.HasArmourTube;

            var configStart10 = new TableParserConfigurator(3, 2, 10, 5, 2, 1);
            var configStart8  = new TableParserConfigurator(3, 2, 8, 5, 2, 1);
            var configMid10   = new TableParserConfigurator(8, 2, 10, 5, 2, 1);
            var configMid8    = new TableParserConfigurator(8, 2, 8, 5, 2, 1);
            var configLTx1    = new TableParserConfigurator(3, 2, 9, 5, 2, 1);
            var configLTx2    = new TableParserConfigurator(9, 2, 9, 5, 8, 1);
            var configLTx3    = new TableParserConfigurator(15, 2, 9, 5, 14, 1);
            var configLTx4    = new TableParserConfigurator(21, 2, 9, 5, 20, 1);

            var configSet1  = (props : cablePropSimple, tu : TU2, configure : new List <(int tableIndex, TableParserConfigurator config)> {
                (0, configStart10), (1, configStart8)
            }, polymerGroups : polymerGroups);
            var configSet2  = (props : cablePropShield, tu : TU2, configure : new List <(int tableIndex, TableParserConfigurator config)> {
                (0, configMid10), (1, configMid8)
            }, polymerGroups : polymerGroups);
            var configSet3  = (props : cablePropSimple, tu : TU30, configure : new List <(int tableIndex, TableParserConfigurator config)> {
                (3, configStart10), (4, configStart8)
            }, polymerGroups : polymerGroupsPE);
            var configSet4  = (props : cablePropShield, tu : TU30, configure : new List <(int tableIndex, TableParserConfigurator config)> {
                (3, configMid10), (4, configMid8)
            }, polymerGroups : polymerGroupsPE);
            var configSet5  = (props : cablePropSimple, tu : TU49, configure : new List <(int tableIndex, TableParserConfigurator config)> {
                (2, configLTx1), (2, configLTx2)
            }, polymerGroups : polymerGroupsLTx);
            var configSet6  = (props : cablePropShield, tu : TU49, configure : new List <(int tableIndex, TableParserConfigurator config)> {
                (2, configLTx3), (2, configLTx4)
            }, polymerGroups : polymerGroupsLTx);
            var configSet7  = (props : cablePropKG, tu : TU30, configure : new List <(int tableIndex, TableParserConfigurator config)> {
                (5, configStart10), (6, configStart8)
            }, polymerGroups : polymerGroupsFull);
            var configSet8  = (props : cablePropKGShield, tu : TU30, configure : new List <(int tableIndex, TableParserConfigurator config)> {
                (5, configMid10), (6, configMid8)
            }, polymerGroups : polymerGroupsFull);
            var configSet9  = (props : cablePropK, tu : TU30, configure : new List <(int tableIndex, TableParserConfigurator config)> {
                (7, configStart10), (8, configStart8)
            }, polymerGroups : polymerGroupsFull);
            var configSet10 = (props : cablePropKShield, tu : TU30, configure : new List <(int tableIndex, TableParserConfigurator config)> {
                (7, configMid10), (8, configMid8)
            }, polymerGroups : polymerGroupsFull);
            var configSet11 = (props : cablePropB, tu : TU30, configure : new List <(int tableIndex, TableParserConfigurator config)> {
                (9, configStart10)
            }, polymerGroups : polymerGroupsFull);
            var configSet12 = (props : cablePropBShield, tu : TU30, configure : new List <(int tableIndex, TableParserConfigurator config)> {
                (9, configMid10)
            }, polymerGroups : polymerGroupsFull);

            var mainConfigArray = new[]
            { configSet1, configSet2, configSet3, configSet4, configSet5, configSet6, configSet7, configSet8, configSet9, configSet10, configSet11, configSet12 };

            var billets = _dbContext.InsulatedBillets.Where(b => b.CableBrandNameId == 6)
                          .Include(p => p.Conductor)
                          .Include(p => p.PolymerGroup)
                          .ToList();

            _wordTableParser = new XceedWordTableParser();
            _wordTableParser.OpenWordDocument(_mSWordFile);

            var cablePresenter = new CablePresenter {
                ClimaticModId = climaticModUHL.Id, TwistedElementTypeId = twistedElementType.Id
            };

            var optionsCount = 1.0;

            _provider.OpenConnection();
            try
            {
                foreach (var option in mainConfigArray)
                {
                    var tableDataCommon = new List <TableCellData>();
                    foreach (var(tableIndex, config) in option.configure)
                    {
                        tableDataCommon.AddRange(_wordTableParser.GetCableCellsCollection(tableIndex, config));
                    }

                    foreach (var polymerGroup in option.polymerGroups)
                    {
                        var insulationPolymerGroup     = polymerGroup == PVCColdGroup || polymerGroup == PESelfExtinguish ? PVCGroup : polymerGroup;
                        var currentPolymerGroupBillets = (from b in billets
                                                          where b.PolymerGroup == insulationPolymerGroup
                                                          select b);
                        foreach (var tableCellData in tableDataCommon)
                        {
                            cablePresenter.CoverPolimerGroupId = polymerGroup.Id;
                            cablePresenter.TechCondId          = option.tu.Id;
                            cablePresenter.CoverColorId        = polymerGroup == PVCColdGroup ? blackColor.Id : redColor.Id;
                            cablePresenter.OperatingVoltageId  = operatingVoltage.Id;
                            cablePresenter.FireProtectionId    = PolymerGroupFireClassDict[polymerGroup].Id;
                            ParseTableCellData(cablePresenter, tableCellData, currentPolymerGroupBillets, option.props, _splitter);
                            recordsCount++;
                        }
                    }
                    OnParseReport(optionsCount / mainConfigArray.Length);
                    optionsCount++;
                }
            }
            finally
            {
                _wordTableParser.CloseWordApp();
                _provider.CloseConnection();
            }
            return(recordsCount);
        }
コード例 #2
0
        public override int ParseDataToDatabase()
        {
            int recordsCount = 0;
            var configurator = new TableParserConfigurator().SetDataRowsCount(1)
                               .SetDataColumnsCount(11)
                               .SetColumnHeadersRowIndex(2)
                               .SetDataStartColumnIndex(1);

            _wordTableParser = new XceedWordTableParser();

            IEnumerable <TableCellData> tableData;
            var cablePropertiesList = _dbContext.CableProperties.ToList();

            var climaticModV   = _dbContext.ClimaticMods.Where(c => c.Id == 7).Single();
            var climaticModUHL = _dbContext.ClimaticMods.Where(c => c.Id == 3).Single();

            var blackColor       = _dbContext.Colors.Where(c => c.Title.ToLower() == "black").Single();
            var greyColor        = _dbContext.Colors.Where(c => c.Title.ToLower() == "grey").Single();
            var operatingVoltage = _dbContext.OperatingVoltages.Where(o => o.ACVoltage == 300 && o.DCVoltage == null).Single();

            var noFireClass = _dbContext.FireProtectionClasses.Where(f => f.Id == 1).Single();
            var lsFireClass = _dbContext.FireProtectionClasses.Where(f => f.Id == 8).Single();
            var hfFireClass = _dbContext.FireProtectionClasses.Where(f => f.Id == 13).Single();

            var cond078            = _dbContext.Conductors.Where(c => c.WiresDiameter == 0.26m && c.WiresCount == 7 && c.MetalId == 2).Single();
            var cond060            = _dbContext.Conductors.Where(c => c.WiresDiameter == 0.20m && c.WiresCount == 7 && c.MetalId == 2).Single();
            var cableBrandName     = _dbContext.CableBrandNames.Where(n => n.BrandName == "КИП").Single();
            var twistedElementType = _dbContext.TwistedElementTypes.Where(t => t.Id == 2).Single();

            var billet060_150 = _dbContext.InsulatedBillets.Include(b => b.Conductor).Where(b => b.ConductorId == cond060.Id && b.Diameter == 1.50m && b.CableBrandName.BrandName == cableBrandName.BrandName).Single();
            var billet060_142 = _dbContext.InsulatedBillets.Include(b => b.Conductor).Where(b => b.ConductorId == cond060.Id && b.Diameter == 1.42m && b.CableBrandName.BrandName == cableBrandName.BrandName).Single();
            var billet078PE   = _dbContext.InsulatedBillets.Include(b => b.Conductor).Where(b => b.ConductorId == cond078.Id && b.Diameter == 1.78m && b.CableBrandName.BrandName == cableBrandName.BrandName).Single();
            var billet078PVC  = _dbContext.InsulatedBillets.Include(b => b.Conductor).Where(b => b.ConductorId == cond078.Id && b.Diameter == 1.60m && b.CableBrandName.BrandName == cableBrandName.BrandName).Single();

            var coverPolymerGroupList8TC = new List <(PolymerGroup polymerGroup, FireProtectionClass fireClass)>
            {
                (_dbContext.PolymerGroups.Where(p => p.Title == "PVC").Single(), noFireClass),
                (_dbContext.PolymerGroups.Where(p => p.Title == "PE").Single(), noFireClass),
                (_dbContext.PolymerGroups.Where(p => p.Title == "PVC Term").Single(), noFireClass),
                (_dbContext.PolymerGroups.Where(p => p.Title == "PVC Cold").Single(), noFireClass)
            };

            var hfPolymerGroup = _dbContext.PolymerGroups.Where(p => p.Title == "HFCompound").Single();

            var coverPolymerGroupList25TC = new List <(PolymerGroup polymerGroup, FireProtectionClass fireClass)>
            {
                (_dbContext.PolymerGroups.Where(p => p.Title == "PVC LS").Single(), lsFireClass),
                (hfPolymerGroup, hfFireClass)
            };
            var coverPolymerGroupList42TC = new List <(PolymerGroup polymerGroup, FireProtectionClass fireClass)>
            {
                (hfPolymerGroup, hfFireClass)
            };

            var techCondPolymerGroupsList = new List <(TechnicalConditions techCond, List <(PolymerGroup polymerGroup, FireProtectionClass fireClass)> paramGroups)>
            {
                (_dbContext.TechnicalConditions.Where(t => t.Title.ToUpper().Contains("008-2001")).Single(), coverPolymerGroupList8TC),
                (_dbContext.TechnicalConditions.Where(t => t.Title.ToUpper().Contains("025-2005")).Single(), coverPolymerGroupList25TC),
                (_dbContext.TechnicalConditions.Where(t => t.Title.ToUpper().Contains("042-2010")).Single(), coverPolymerGroupList42TC)
            };

            var cableProps = new List <CablePropertySet>
            {
                CablePropertySet.HasFoilShield | CablePropertySet.HasBraidShield,
                CablePropertySet.HasFoilShield | CablePropertySet.HasBraidShield | CablePropertySet.HasArmourBraid,
                CablePropertySet.HasFoilShield | CablePropertySet.HasBraidShield | CablePropertySet.HasArmourBraid | CablePropertySet.HasArmourTube,
                CablePropertySet.HasFoilShield | CablePropertySet.HasBraidShield | CablePropertySet.HasArmourTape | CablePropertySet.HasArmourTube
            };

            var dataStartRowIndexes = new int[2] {
                3, 7
            };
            InsulatedBillet billet;
            var             flagBG = false;


            _wordTableParser.OpenWordDocument(_mSWordFile);
            var currentPolymerGroupCount = 1;

            foreach (var techCondPolymerGroup in techCondPolymerGroupsList) //Не оптимально, но для разового метода сойдёт, если отделять БГ кабель от остальных со своей таблицей, придётся больше логики писать, пусть лучше чуть дольше работает метод)))
            {
                var tableIndex = techCondPolymerGroup.paramGroups == coverPolymerGroupList42TC ? 1 : 0;

                if (tableIndex == 1)
                {
                    flagBG = true;
                }

                foreach (var paramGroup in techCondPolymerGroup.paramGroups)
                {
                    foreach (var index in dataStartRowIndexes)
                    {
                        configurator.DataStartRowIndex = index;

                        foreach (var cableProp in cableProps)
                        {
                            tableData = _wordTableParser.GetCableCellsCollection(tableIndex, configurator);
                            foreach (var tableCellData in tableData)
                            {
                                if (decimal.TryParse(tableCellData.ColumnHeaderData, NumberStyles.Any, _cultureInfo, out decimal elementsCount) &&
                                    decimal.TryParse(tableCellData.CellData, NumberStyles.Any, _cultureInfo, out decimal maxCoverDiameter))
                                {
                                    if (index < 7)
                                    {
                                        if (elementsCount < 4)
                                        {
                                            billet = billet060_150;
                                        }
                                        else
                                        {
                                            billet = billet060_142;
                                        }
                                    }
                                    else
                                    {
                                        billet = billet078PE;
                                    }

                                    var kip = new Cable
                                    {
                                        ClimaticMod         = paramGroup.polymerGroup.Title == "PVC LS" ? climaticModUHL : climaticModV,
                                        CoverPolymerGroup   = paramGroup.polymerGroup,
                                        TechnicalConditions = techCondPolymerGroup.techCond,
                                        CoverColor          = paramGroup.polymerGroup.Title == "PVC" || paramGroup.polymerGroup.Title == "PVC Term" || paramGroup.polymerGroup.Title == "PVC LS" ? greyColor : blackColor,
                                        OperatingVoltage    = operatingVoltage,
                                        ElementsCount       = elementsCount,
                                        MaxCoverDiameter    = maxCoverDiameter,
                                        FireProtectionClass = paramGroup.fireClass,
                                        TwistedElementType  = twistedElementType,
                                    };

                                    kip.Title = _cableTitleBuilder.GetCableTitle(kip, billet, cableProp, flagBG);
                                    var cableRec = _dbContext.Cables.Add(kip).Entity;

                                    _dbContext.ListCableBillets.Add(new ListCableBillets {
                                        Billet = billet, Cable = cableRec
                                    });
                                    if (elementsCount == 1.5m)
                                    {
                                        _dbContext.ListCableBillets.Add(new ListCableBillets {
                                            Billet = billet078PVC, Cable = cableRec
                                        });
                                    }

                                    var propList = GetCableAssociatedPropertiesList(cableRec, cableProp);

                                    _dbContext.AddRange(propList);

                                    _dbContext.SaveChanges();

                                    recordsCount++;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            configurator.DataStartRowIndex++;
                        }
                    }
                    OnParseReport((double)currentPolymerGroupCount / POLYMER_GROUP_COUNT);
                    currentPolymerGroupCount++;
                }
            }
            _wordTableParser.CloseWordApp();
            return(recordsCount);
        }
    }
}
コード例 #3
0
        public override int ParseDataToDatabase()
        {
            int recordsCount = 0;
            var nameBuilder  = new KunrsNameBuider();
            var configurator = new TableParserConfigurator().SetDataColumnsCount(4)
                               .SetDataRowsCount(8)
                               .SetColumnHeadersRowIndex(2)
                               .SetRowHeadersColumnIndex(1)
                               .SetDataStartColumnIndex(2)
                               .SetDataStartRowIndex(3);

            _wordTableParser = new XceedWordTableParser();

            var cablePropsList = new List <CablePropertySet?>
            {
                null,
                CablePropertySet.HasFoilShield,
                CablePropertySet.HasArmourBraid | CablePropertySet.HasArmourTube,
                CablePropertySet.HasFoilShield | CablePropertySet.HasArmourBraid | CablePropertySet.HasArmourTube
            };

            var polymerGroupIdList = new List <int> {
                6, 4, 5
            };

            var powerColorsDict = new Dictionary <decimal, PowerWiresColorScheme[]>
            {
                { 2m, new [] { PowerWiresColorScheme.N } },
                { 3m, new [] { PowerWiresColorScheme.PEN, PowerWiresColorScheme.none } },
                { 4m, new [] { PowerWiresColorScheme.N, PowerWiresColorScheme.PE } },
                { 5m, new [] { PowerWiresColorScheme.PEN, PowerWiresColorScheme.none } }
            };

            var billets = _dbContext.InsulatedBillets.Where(b => b.CableBrandName.BrandName == "КУНРС")
                          .Include(b => b.Conductor)
                          .ToList();

            var kunrs = new CablePresenter
            {
                TwistedElementTypeId = 1,
                TechCondId           = 25,
                OperatingVoltageId   = 1,
                ClimaticModId        = 3
            };

            PowerWiresColorScheme[] powerColorSchemeArray;

            _wordTableParser.OpenWordDocument(_mSWordFile);
            _provider.OpenConnection();
            try
            {
                var parsePartNumber = 1d;
                foreach (var prop in cablePropsList)
                {
                    var tableData = _wordTableParser.GetCableCellsCollection(0, configurator);
                    foreach (var tableCellData in tableData)
                    {
                        if (decimal.TryParse(tableCellData.ColumnHeaderData, NumberStyles.Any, _cultureInfo, out decimal elementsCount) &&
                            decimal.TryParse(tableCellData.CellData, NumberStyles.Any, _cultureInfo, out decimal maxCoverDiameter) &&
                            decimal.TryParse(tableCellData.RowHeaderData, NumberStyles.Any, _cultureInfo, out decimal conductorAreaInSqrMm))
                        {
                            foreach (var polymerGroupId in polymerGroupIdList)
                            {
                                powerColorSchemeArray = powerColorsDict[elementsCount];
                                foreach (var powerColorScheme in powerColorSchemeArray)
                                {
                                    var cableProps = CablePropertySet.HasFilling;
                                    if (prop.HasValue)
                                    {
                                        cableProps |= prop.Value;
                                    }

                                    kunrs.ElementsCount       = elementsCount;
                                    kunrs.MaxCoverDiameter    = maxCoverDiameter;
                                    kunrs.FireProtectionId    = polymerGroupId == 6 ? 18 : 23;
                                    kunrs.CoverPolimerGroupId = polymerGroupId;
                                    kunrs.CoverColorId        = polymerGroupId == 5 ? 8 : 2;
                                    var billet = (from b in billets
                                                  where b.Conductor.AreaInSqrMm == conductorAreaInSqrMm
                                                  select b).Single();
                                    kunrs.Title = nameBuilder.GetCableName(kunrs, conductorAreaInSqrMm, cableProps, powerColorScheme);
                                    var cableId = _cableTableProvider.AddItem(kunrs);

                                    _listCableBilletsProvider.AddItem(new ListCableBilletsPresenter {
                                        CableId = cableId, BilletId = billet.Id
                                    });
                                    _listCablePowerColorProvider.AddItem(new ListCablePowerColorPresenter {
                                        CableId = cableId, PowerColorSchemeId = (int)powerColorScheme
                                    });

                                    var intProp = 0b_0000000001;

                                    for (int m = 0; m < cablePropertiesCount; m++)
                                    {
                                        var Prop = (CablePropertySet)intProp;

                                        if ((cableProps & Prop) == Prop)
                                        {
                                            var propertyObj = cablePropertiesList.Where(p => p.BitNumber == intProp).First();
                                            _listCablePropertiesProvider.AddItem(new ListCablePropertiesPresenter {
                                                PropertyId = propertyObj.Id, CableId = cableId
                                            });
                                        }
                                        intProp <<= 1;
                                    }
                                    recordsCount++;
                                }
                            }
                        }
                    }
                    OnParseReport(parsePartNumber / cablePropsList.Count);
                    configurator.DataStartRowIndex += configurator.DataRowsCount;
                    parsePartNumber++;
                }
            }
            finally
            {
                _wordTableParser.CloseWordApp();
                _provider.CloseConnection();
            }
            return(recordsCount);
        }
コード例 #4
0
        public override int ParseDataToDatabase()
        {
            _recordsCount = 0;

            var twistedElementType = _dbContext.TwistedElementTypes.Where(t => t.ElementType.ToLower() == "single").First();
            var techCond           = _dbContext.TechnicalConditions.Where(c => c.Title == "ТУ 16.К99-046-2011").First();
            var climaticMod        = _dbContext.ClimaticMods.Where(m => m.Title == "УХЛ").First();
            var operatingVoltage   = _dbContext.OperatingVoltages.Find(4);

            var fireClassPVCLS = _dbContext.FireProtectionClasses.Find(8);
            var fireClassHF    = _dbContext.FireProtectionClasses.Find(23);
            var fireClassPURHF = _dbContext.FireProtectionClasses.Find(26);

            var polymerPVCLS = _dbContext.PolymerGroups.Find(6);
            var polymerHF    = _dbContext.PolymerGroups.Find(4);
            var polymerPUR   = _dbContext.PolymerGroups.Find(5);

            var colorGrey   = _dbContext.Colors.Find(9);
            var colorBlack  = _dbContext.Colors.Find(2);
            var colorOrange = _dbContext.Colors.Find(8);

            var pvcBillets = _dbContext.InsulatedBillets.Where(b => b.CableBrandName.BrandName.ToLower().StartsWith("кэв"))
                             .Include(b => b.Conductor)
                             .Include(b => b.PolymerGroup)
                             .ToList();

            var rubberBillets = _dbContext.InsulatedBillets.Where(b => b.CableBrandName.BrandName.ToLower().StartsWith("кэрс"))
                                .Include(b => b.Conductor)
                                .Include(b => b.PolymerGroup)
                                .ToList();

            var configurator = new TableParserConfigurator().SetDataRowsCount(7)
                               .SetColumnHeadersRowIndex(2)
                               .SetRowHeadersColumnIndex(2)
                               .SetDataStartColumnIndex(3);

            _wordTableParser = new XceedWordTableParser(configurator);

            var kersParams = new List <(FireProtectionClass fireClass, PolymerGroup polymer, Color color)>
            {
                (fireClassHF, polymerHF, colorBlack), (fireClassPURHF, polymerPUR, colorOrange)
            };

            var cableProps = new List <CablePropertySet?>
            {
                null, CablePropertySet.HasBraidShield
            };

            _wordTableParser.OpenWordDocument(_mSWordFile);

            var patternCable = new Cable
            {
                TwistedElementType  = twistedElementType,
                TechnicalConditions = techCond,
                ClimaticMod         = climaticMod,
                OperatingVoltage    = operatingVoltage
            };

            for (int i = 0; i < tablesCount; i++)
            {
                configurator.DataColumnsCount = (i + 1) % 2 == 0 ? 7 : 9; //выбираем число столбцов в зависимости от чётности номера таблицы

                foreach (var prop in cableProps)
                {
                    configurator.DataStartRowIndex = prop.HasValue ? 10 : 3;

                    var tableData = _wordTableParser.GetCableCellsCollection(i);

                    foreach (var tableCellData in tableData)
                    {
                        if (i < 2) //первые 2 таблицы для КЭВВ, остальные - КЭРс
                        {
                            var cable = patternCable.Clone();
                            cable.FireProtectionClass = fireClassPVCLS;
                            cable.CoverPolymerGroup   = polymerPVCLS;
                            cable.CoverColor          = colorGrey;

                            ParseTableCellData(cable, tableCellData, pvcBillets, prop);
                            _recordsCount++;
                        }
                        else
                        {
                            foreach (var param in kersParams)
                            {
                                var cable = patternCable.Clone();
                                cable.FireProtectionClass = param.fireClass;
                                cable.CoverPolymerGroup   = param.polymer;
                                cable.CoverColor          = param.color;

                                ParseTableCellData(cable, tableCellData, rubberBillets, prop);
                                _recordsCount++;
                            }
                        }
                    }
                    OnParseReport((double)_recordsCount / CABLE_BRANDS_COUNT);
                }
            }
            _wordTableParser.CloseWordApp();
            return(_recordsCount);
        }
コード例 #5
0
        public override int ParseDataToDatabase()
        {
            int recordsCount = 0;

            var techCond = _dbContext.TechnicalConditions.Where(c => c.Title == "ТУ 16.К99-061-2013").First();

            var voltage250 = _dbContext.OperatingVoltages.Find(2);
            var voltage660 = _dbContext.OperatingVoltages.Find(3);

            var climaticModUHL = _dbContext.ClimaticMods.Find(3);
            var climaticModV   = _dbContext.ClimaticMods.Find(7);

            var colorBlack = _dbContext.Colors.Find(2);
            var colorBlue  = _dbContext.Colors.Find(3);

            var skabPropertiesList = new List <CablePropertySet?>
            {
                CablePropertySet.HasFilling | CablePropertySet.HasBraidShield,
                CablePropertySet.HasWaterBlockStripe | CablePropertySet.HasFilling | CablePropertySet.HasBraidShield,
                CablePropertySet.HasBraidShield,
                CablePropertySet.HasWaterBlockStripe | CablePropertySet.HasBraidShield,
                CablePropertySet.HasFilling,
                CablePropertySet.HasWaterBlockStripe | CablePropertySet.HasFilling,
                null,
                CablePropertySet.HasWaterBlockStripe
            };

            var operatingVoltages = new List <OperatingVoltage> {
                voltage250, voltage660
            };                                                                             // 1 - СКАБ 250, 2 - СКАБ 660

            var skabArmorPropertiesList = new List <CablePropertySet?>
            {
                null,
                CablePropertySet.HasArmourBraid,
                CablePropertySet.HasArmourBraid | CablePropertySet.HasArmourTube
            };

            var insulationTypes = new List <int> {
                0, 1
            };                                            //1 = rubber, 0 = others

            var single = _dbContext.TwistedElementTypes.Find(1);
            var pair   = _dbContext.TwistedElementTypes.Find(2);
            var triple = _dbContext.TwistedElementTypes.Find(3);

            var fireLS    = _dbContext.FireProtectionClasses.Find(8);
            var fireHF    = _dbContext.FireProtectionClasses.Find(13);
            var fireFRLS  = _dbContext.FireProtectionClasses.Find(18);
            var fireFRHF  = _dbContext.FireProtectionClasses.Find(23);
            var fireCFRHF = _dbContext.FireProtectionClasses.Find(25);

            var polymerLS     = _dbContext.PolymerGroups.Find(6);
            var polymerHF     = _dbContext.PolymerGroups.Find(4);
            var polymerRubber = _dbContext.PolymerGroups.Find(3);
            var polymerPUR    = _dbContext.PolymerGroups.Find(5);

            var configurator = new TableParserConfigurator().SetDataRowsCount(5)
                               .SetDataStartColumnIndex(3)
                               .SetRowHeadersColumnIndex(2);

            var twistParamsList = new List <(TwistedElementType twistMode, CablePropertySet?hasIndividualFoilSHields, TableParserConfigurator configurator)>
            {
                (single, null, new TableParserConfigurator(3, 2, 13, 5, 2, 1)),
                (pair, null, new TableParserConfigurator(10, 2, 14, 5, 9, 1)),
                (triple, null, new TableParserConfigurator(15, 2, 14, 5, 9, 1)),
                (pair, CablePropertySet.HasIndividualFoilShields, new TableParserConfigurator(21, 2, 13, 5, 20, 1)),
                (triple, CablePropertySet.HasIndividualFoilShields, new TableParserConfigurator(26, 2, 13, 5, 20, 1))
            };

            var plasticInsParams = new List <(FireProtectionClass fireClass, PolymerGroup insPolymerGroup, PolymerGroup coverPolymerGroup)>
            {
                (fireLS, polymerLS, polymerLS), (fireHF, polymerHF, polymerHF)
            };

            var rubberInsParams = new List <(FireProtectionClass fireClass, PolymerGroup insPolymerGroup, PolymerGroup coverPolymerGroup)>
            {
                (fireFRLS, polymerRubber, polymerLS), (fireFRHF, polymerRubber, polymerHF), (fireCFRHF, polymerRubber, polymerPUR)
            };

            var exiProperties = new List <CablePropertySet?> {
                null, CablePropertySet.SparkSafety
            };

            var billets = _dbContext.InsulatedBillets.Where(b => b.CableBrandName.BrandName == "СКАБ")
                          .Include(b => b.Conductor)
                          .Include(b => b.PolymerGroup)
                          .Include(b => b.OperatingVoltage)
                          .ToList();

            _wordTableParser = new XceedWordTableParser();
            _wordTableParser.OpenWordDocument(_mSWordFile);

            var maxDiamTableCount = _wordTableParser.DocumentTablesCount / 2;

            var cablePresenter = new CablePresenter {
                TechCondId = techCond.Id
            };
            var nameBuilder = new SkabNameBuilder();

            _provider.OpenConnection();
            var tableNumber = 0;

            try
            {
                while (tableNumber < maxDiamTableCount)
                {
                    foreach (var mod in skabPropertiesList)
                    {
                        foreach (var voltage in operatingVoltages)
                        {
                            foreach (var insType in insulationTypes)
                            {
                                foreach (var armourType in skabArmorPropertiesList)
                                {
                                    foreach (var twistTypeParams in twistParamsList)
                                    {
                                        var tableData = _wordTableParser.GetCableCellsCollection(tableNumber, twistTypeParams.configurator);

                                        foreach (var tableCellData in tableData)
                                        {
                                            if (decimal.TryParse(tableCellData.ColumnHeaderData, NumberStyles.Any, _cultureInfo, out decimal elementsCount) &&
                                                decimal.TryParse(tableCellData.CellData, NumberStyles.Any, _cultureInfo, out decimal maxCoverDiameter) &&
                                                decimal.TryParse(tableCellData.RowHeaderData, NumberStyles.Any, _cultureInfo, out decimal conductorAreaInSqrMm))
                                            {
                                                var materialParams = insType == 0 ? plasticInsParams : rubberInsParams;
                                                foreach (var matParam in materialParams)
                                                {
                                                    foreach (var exiParam in exiProperties)
                                                    {
                                                        var cableProps = CablePropertySet.HasFoilShield;
                                                        if (twistTypeParams.hasIndividualFoilSHields.HasValue)
                                                        {
                                                            cableProps |= twistTypeParams.hasIndividualFoilSHields.Value;
                                                        }
                                                        if (mod.HasValue)
                                                        {
                                                            cableProps |= mod.Value;
                                                        }
                                                        if (armourType.HasValue)
                                                        {
                                                            cableProps |= armourType.Value;
                                                        }
                                                        if (exiParam.HasValue)
                                                        {
                                                            cableProps |= exiParam.Value;
                                                        }

                                                        var billet = billets.Where(b => b.OperatingVoltage == voltage &&
                                                                                   b.PolymerGroup == matParam.insPolymerGroup &&
                                                                                   b.Conductor.AreaInSqrMm == conductorAreaInSqrMm)
                                                                     .First();

                                                        cablePresenter.ElementsCount        = elementsCount;
                                                        cablePresenter.OperatingVoltageId   = voltage.Id;
                                                        cablePresenter.TwistedElementTypeId = twistTypeParams.twistMode.Id;
                                                        cablePresenter.MaxCoverDiameter     = maxCoverDiameter;
                                                        cablePresenter.FireProtectionId     = matParam.fireClass.Id;
                                                        cablePresenter.CoverPolimerGroupId  = matParam.coverPolymerGroup.Id;
                                                        cablePresenter.CoverColorId         = (exiParam.HasValue && (!armourType.HasValue || (armourType.Value & CablePropertySet.HasArmourTube) != CablePropertySet.HasArmourTube)) ? colorBlue.Id : colorBlack.Id;
                                                        cablePresenter.ClimaticModId        = matParam.coverPolymerGroup.Id == 6 ? climaticModUHL.Id : climaticModV.Id;

                                                        cablePresenter.Title = nameBuilder.GetCableName(cablePresenter, conductorAreaInSqrMm, cableProps);
                                                        var cablePresenterId = _cableTableProvider.AddItem(cablePresenter);

                                                        _listCableBilletsProvider.AddItem(new ListCableBilletsPresenter {
                                                            CableId = cablePresenterId, BilletId = billet.Id
                                                        });

                                                        var intProp = 0b_0000000001;

                                                        for (int j = 0; j < cablePropertiesCount; j++)
                                                        {
                                                            var Prop = (CablePropertySet)intProp;

                                                            if ((cableProps & Prop) == Prop)
                                                            {
                                                                var propertyObj = cablePropertiesList.Where(p => p.BitNumber == intProp).First();
                                                                _listCablePropertiesProvider.AddItem(new ListCablePropertiesPresenter {
                                                                    PropertyId = propertyObj.Id, CableId = cablePresenterId
                                                                });
                                                            }
                                                            intProp <<= 1;
                                                        }
                                                        recordsCount++;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                throw new Exception($"Не удалось распарсить ячейку таблицы №{tableNumber}!");
                                            }
                                        }
                                    }
                                    OnParseReport((double)(tableNumber + 1) / maxDiamTableCount);
                                    tableNumber++;
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                _wordTableParser.CloseWordApp();
                _provider.CloseConnection();
            }
            return(recordsCount);
        }
    }
}
コード例 #6
0
        public override int ParseDataToDatabase()
        {
            _recordsCount = 0;

            var configuratorTSimpleAndKG  = new TableParserConfigurator(3, 2, 9, 6, 2, 1);
            var configuratorTSimpleAndKGS = new TableParserConfigurator(9, 2, 9, 6, 2, 1);
            var configuratorK             = new TableParserConfigurator(3, 2, 7, 6, 2, 1);
            var configuratorKS            = new TableParserConfigurator(9, 2, 7, 6, 2, 1);

            var techCond = _dbContext.TechnicalConditions.Where(c => c.Title == "ТУ 16.К99-037-2009").First();

            var voltage = _dbContext.OperatingVoltages.Find(5);

            var climaticModUHL = _dbContext.ClimaticMods.Where(c => c.Title == "УХЛ").First();
            var climaticModV   = _dbContext.ClimaticMods.Where(c => c.Title == "В").First();

            var colorOrange = _dbContext.Colors.Where(c => c.Title == "orange").First();
            var colorBlack  = _dbContext.Colors.Where(c => c.Title == "black").First();

            _fireFRLS = _dbContext.FireProtectionClasses.Find(18);
            _fireFRHF = _dbContext.FireProtectionClasses.Find(23);

            var polymerLS = _dbContext.PolymerGroups.Find(6);
            var polymerHF = _dbContext.PolymerGroups.Find(4);

            var pair = _dbContext.TwistedElementTypes.Find(2);

            var cablePropertiesSetList = new List <CablePropertySet?>
            {
                CablePropertySet.HasFoilShield,
                CablePropertySet.HasFoilShield | CablePropertySet.HasMicaWinding,
                CablePropertySet.HasFoilShield | CablePropertySet.HasArmourBraid,
                CablePropertySet.HasFoilShield | CablePropertySet.HasArmourBraid | CablePropertySet.HasMicaWinding,
                CablePropertySet.HasFoilShield | CablePropertySet.HasArmourBraid | CablePropertySet.HasArmourTube,
                CablePropertySet.HasFoilShield | CablePropertySet.HasArmourBraid | CablePropertySet.HasArmourTube | CablePropertySet.HasMicaWinding,
            };

            _coverPolymerGroups = new[] { polymerLS, polymerHF };

            _billets = _dbContext.InsulatedBillets.Where(b => b.CableBrandName.BrandName == "КСБ")
                       .Include(b => b.Conductor)
                       .ToList();

            _nameBuilder = new KsbgNameBuilder();

            _wordTableParser = new XceedWordTableParser();
            _wordTableParser.OpenWordDocument(_mSWordFile);

            var tableDataCommon = new List <TableCellData>();
            var cablePresenter  = new CablePresenter
            {
                TechCondId         = techCond.Id,
                OperatingVoltageId = voltage.Id,
                ClimaticModId      = climaticModUHL.Id,
            };

            _provider.OpenConnection();

            try
            {
            }
            finally
            {
                _wordTableParser.CloseWordApp();
                _provider.CloseConnection();
            }

            return(_recordsCount);
        }
コード例 #7
0
        public override int ParseDataToDatabase()
        {
            _recordsCount = 0;

            var configuratorTop           = new TableParserConfigurator(3, 2, 9, 7, 2, 1);
            var configuratorBottom        = new TableParserConfigurator(11, 2, 9, 7, 10, 1);
            var configuratorSingleBillets = new TableParserConfigurator(4, 1, 2, 7, 3, 0);

            var techCond = _dbContext.TechnicalConditions.Where(c => c.Title == "ТУ 16.К99-036-2007").First();

            var voltage = _dbContext.OperatingVoltages.Find(5);

            var climaticModUHL = _dbContext.ClimaticMods.Find(3);

            var colorOrange = _dbContext.Colors.Find(8);

            _fireFRLS = _dbContext.FireProtectionClasses.Find(18);
            _fireFRHF = _dbContext.FireProtectionClasses.Find(23);

            var polymerLS = _dbContext.PolymerGroups.Find(6);
            var polymerHF = _dbContext.PolymerGroups.Find(4);


            var single = _dbContext.TwistedElementTypes.Find(1);
            var pair   = _dbContext.TwistedElementTypes.Find(2);

            var cablePropertiesSetList = new List <CablePropertySet?>
            {
                CablePropertySet.HasFoilShield,
                null,
                CablePropertySet.HasFoilShield | CablePropertySet.HasMicaWinding,
                CablePropertySet.HasMicaWinding
            };

            _coverPolymerGroups = new[] { polymerLS, polymerHF };

            _billets = _dbContext.InsulatedBillets.Where(b => b.CableBrandName.BrandName == "КПС(Э)")
                       .Include(b => b.Conductor)
                       .ToList();

            _nameBuilder = new KpseNameBuilder();

            _wordTableParser = new XceedWordTableParser();
            _wordTableParser.OpenWordDocument(_mSWordFile);

            var tableDataCommon = new List <TableCellData>();
            var cablePresenter  = new CablePresenter
            {
                TechCondId         = techCond.Id,
                OperatingVoltageId = voltage.Id,
                ClimaticModId      = climaticModUHL.Id,
                CoverColorId       = colorOrange.Id
            };

            _provider.OpenConnection();

            try
            {
                var tableIndex = 0;
                foreach (var cableProps in cablePropertiesSetList)
                {
                    tableDataCommon.AddRange(_wordTableParser.GetCableCellsCollection(tableIndex, configuratorTop));
                    tableDataCommon.AddRange(_wordTableParser.GetCableCellsCollection(tableIndex, configuratorBottom));

                    cablePresenter.TwistedElementTypeId = pair.Id;
                    InsertCablesFromTableCellData(tableDataCommon, cablePresenter, cableProps);
                    tableDataCommon.Clear();

                    tableDataCommon.AddRange(_wordTableParser.GetCableCellsCollection(4, configuratorSingleBillets));
                    cablePresenter.TwistedElementTypeId = single.Id;
                    InsertCablesFromTableCellData(tableDataCommon, cablePresenter, cableProps);
                    tableDataCommon.Clear();
                    configuratorSingleBillets.DataStartColumnIndex += (tableIndex + 1) % 2 == 0 ? -2 : 4;

                    OnParseReport((double)(tableIndex + 1) / cablePropertiesSetList.Count);
                    tableIndex++;
                }
            }
            finally
            {
                _wordTableParser.CloseWordApp();
                _provider.CloseConnection();
            }

            return(_recordsCount);
        }