Ejemplo n.º 1
0
        private AddressModel GetNewAddress(string district, string address, int rowNumber, WorkObject workObj)
        {
            var adr = new AddressModel {
                District = district, Address = address
            };

            foreach (var item in workObj.Profile.Items.Where(i => i.Column > 0).ToList())
            {
                adr.SetData(item.Name, workObj.ActiveRange[rowNumber, item.Column] + "");
            }

            foreach (var rgx in _repository.RegexList.Items)
            {
                adr.Regex = string.IsNullOrWhiteSpace(adr.Regex)
                    ? Regex.Replace(adr.Address, rgx.Expression, rgx.ReplceExpression)
                    : Regex.Replace(adr.Regex, rgx.Expression, rgx.ReplceExpression);
            }

            adr.Regex = adr.District + adr.Regex;

            if (!string.IsNullOrWhiteSpace(adr.Regex)) //регулярки могут убить полностью значение
            {
                var findAdr = _repository.AddressList.Items.FirstOrDefault(i => i.Regex == adr.Regex);
                if (findAdr != null)
                {
                    adr.Number      = findAdr.Number;
                    adr.KgiopStatus = findAdr.KgiopStatus;
                    adr.Uid         = findAdr.Uid;
                }
            }

            return(adr);
        }
Ejemplo n.º 2
0
        private void CollectDataFromProfile(WorkObject workObj)
        {
            workObj.Addresses.Clear();


            var distColumn          = workObj.Profile.FirstDistrictCell.Column;
            var adrColumn           = workObj.Profile.FirstAddressCell.Column;
            var districtKeyWord     = workObj.Profile.DistrictKeyWord;
            var districtWordReplace = workObj.Profile.DistrictWordReplace;
            var addressNotKeyWord   = workObj.Profile.AddressNotKeyWord;

            Dictionary <string, int> regValuesCount = new Dictionary <string, int>(); //проверка на уникальность

            for (int row = workObj.Profile.FirstDistrictCell.Row; row < workObj.Profile.GetLastRow() + 1; row++)
            {
                AddressModel adr = null;

                var district = workObj.ActiveRange[row, distColumn] + "";
                var address  = workObj.ActiveRange[row, adrColumn] + "";

                var distrcitStrings  = districtKeyWord.Split('|'); //эти слова используются для поиска района
                var distrReplStrings = districtWordReplace.Split('&');
                var adrNotKeyStrings = addressNotKeyWord.Split('|');

                foreach (var str in distrcitStrings)
                {
                    if (str.Length > 0 && district.Contains(str))
                    {
                        lastDistrict = district;
                        foreach (var str_repl in distrReplStrings)
                        {
                            lastDistrict = lastDistrict.Replace(str_repl, "");
                        }
                        break;
                    }
                    else if (districtKeyWord.Length == 0)
                    {
                        lastDistrict = district;
                    }
                }



                if (!string.IsNullOrWhiteSpace(address))
                {
                    bool flag = true;
                    if (addressNotKeyWord.Length > 0)
                    {
                        foreach (var str in adrNotKeyStrings)
                        {
                            if (address.ToLower().Contains(str.ToLower()))
                            {
                                flag = false;
                                break;
                            }
                        }
                    }


                    if (flag)
                    {
                        adr = GetNewAddress(lastDistrict, address, row, workObj);
                        workObj.Addresses.Add(adr);
                    }
                }

                //проверить на уникальность
                if (adr != null && regValuesCount.ContainsKey(adr.Regex))
                {
                    regValuesCount[adr.Regex]++;
                }
                else if (adr != null && !regValuesCount.ContainsKey(adr.Regex))
                {
                    regValuesCount.Add(adr.Regex, 1);
                }
            }

            //проверка на уникальность
            var negativeList = regValuesCount.Where(i => i.Value > 1);

            foreach (var hashValue in negativeList)
            {
                var list = workObj.Addresses.Where(i => i.Regex == hashValue.Key).ToList();
                foreach (var negativeAdr in list)
                {
                    negativeAdr.Number = 0;
                }
            }
        }