Example #1
0
        private string searchAmphorInDB(string amphor, string provinceCode)
        {
            string _district = string.Empty;

            if (provinceCode.isNotEmpty())
            {
                models.Provinces _provinceList = _liProvince.Where(p => p.ProvinceCode == provinceCode).FirstOrDefault();
                if (_provinceList != null)
                {
                    _district = _provinceList.liDistrict
                                .Where(d => d.District == amphor)
                                .Select(d => d.District)
                                .FirstOrDefault();

                    int _len = amphor.Length;
                    if (_district.isEmpty() && _len > 1)
                    {
                        _district = string.Empty;
                        string        _tmp = string.Empty;
                        List <string> _li;

                        // #forward search
                        for (int i = 2; i <= _len; i++)
                        {
                            _tmp = amphor.Substring(0, i);
                            _li  = _provinceList.liDistrict
                                   .Where(p => p.District.StartsWith(_tmp))
                                   .Select(d => d.District)
                                   .ToList();

                            if (_li.Count == 1)
                            {
                                _district = _li[0];
                            }
                        }

                        if (_district.isEmpty())
                        {
                            // #backward search
                            for (int i = _len - 2; i > 0; i--)
                            {
                                _tmp = amphor.Substring(i);
                                _li  = _provinceList.liDistrict
                                       .Where(p => p.District.EndsWith(_tmp))
                                       .Select(d => d.District)
                                       .ToList();

                                if (_li.Count == 1)
                                {
                                    _district = _li[0];
                                }
                            }
                        }
                    }
                }
            }
            return(_district);
        }
Example #2
0
        private string getProvinceCode(string province)
        {
            string _province = string.Empty;

            models.Provinces _provinceList = _liProvince.Where(p => p.ProvinceName == province).FirstOrDefault();
            if (_provinceList != null)
            {
                _province = _provinceList.ProvinceCode;
            }
            return(_province);
        }
Example #3
0
        private string searchProvinceInDB(string province)
        {
            string _province = string.Empty;

            models.Provinces _provinceList = _liProvince.Where(p => p.ProvinceName == province).FirstOrDefault();
            if (_provinceList != null)
            {
                _province = _provinceList.ProvinceName;
            }
            else
            {
                string _tmp = string.Empty;
                List <models.Provinces> _li;
                int _len = province.Length;
                if (_len > 1)
                {
                    // #forward search
                    for (int i = 2; i <= _len; i++)
                    {
                        _tmp = province.Substring(0, i);
                        _li  = _liProvince.Where(p => p.ProvinceName.StartsWith(_tmp)).ToList();
                        if (_li.Count == 1)
                        {
                            _province = _li[0].ProvinceName;
                            break;
                        }
                    }

                    if (_province.isEmpty())
                    {
                        // #backward search
                        for (int i = _len - 2; i > 0; i--)
                        {
                            _tmp = province.Substring(i);
                            _li  = _liProvince.Where(p => p.ProvinceName.EndsWith(_tmp)).ToList();
                            if (_li.Count == 1)
                            {
                                _province = _li[0].ProvinceName;
                                break;
                            }
                        }
                    }
                }
            }

            return(_province);
        }