Пример #1
0
        private void txtReceiveAddress_Leave(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtReceiveAddress.Text))
            {
                BindPrintMark();
            }
            // 如果收件的省市区存在的话就对的,不用提取收件省市区了。
            if (!string.IsNullOrEmpty(dgvReceiveArea.Text))
            {
                return;
            }
            // 根据收件的地址,获取到百度地图提供的省市区信息
            var result = BaiduMapHelper.GetProvCityDistFromBaiduMap(txtReceiveAddress.Text);

            if (result != null)
            {
                var area = string.Format("{0}-{1}-{2}", result.Result.AddressComponent.Province.Trim(), result.Result.AddressComponent.City.Trim(), result.Result.AddressComponent.District.Trim());
                dgvReceiveArea.Text = area;
                if (string.IsNullOrEmpty(dgvReceiveArea.Text))
                {
                    BaseAreaManager areaManager = new BaseAreaManager(BillPrintHelper.DbHelper);
                    // 去数据库找
                    var countyEntity = areaManager.GetList <BaseAreaEntity>(new KeyValuePair <string, object>(BaseAreaEntity.FieldFullName, result.Result.AddressComponent.District.Trim())).FirstOrDefault();
                    if (countyEntity != null)
                    {
                        var cityEntity     = areaManager.GetObject(countyEntity.ParentId);
                        var provinceEntity = areaManager.GetObject(cityEntity.ParentId);
                        dgvReceiveArea.Text = string.Format("{0}-{1}-{2}", provinceEntity.FullName, cityEntity.FullName, countyEntity.FullName);
                    }
                }
            }
        }
Пример #2
0
 /// <summary>
 /// 自动获取到地址所在省市区
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void txtSendAddress_Leave(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(txtSendAddress.Text))
     {
         var result = BaiduMapHelper.GetProvCityDistFromBaiduMap(dgvSearchSendArea.Text + txtSendAddress.Text);
         if (result != null)
         {
             var area = string.Format("{0}-{1}-{2}", result.Result.AddressComponent.Province.Trim(),
                                      result.Result.AddressComponent.City.Trim(),
                                      result.Result.AddressComponent.District.Trim());
             dgvSearchSendArea.Text = area;
             if (string.IsNullOrEmpty(dgvSearchSendArea.Text))
             {
                 BaseAreaManager areaManager = new BaseAreaManager(BillPrintHelper.DbHelper);
                 // 去数据库找
                 var countyEntity =
                     areaManager.GetList <BaseAreaEntity>(
                         new KeyValuePair <string, object>(BaseAreaEntity.FieldFullName,
                                                           result.Result.AddressComponent.District.Trim())).
                     FirstOrDefault();
                 if (countyEntity != null)
                 {
                     var cityEntity     = areaManager.GetObject(countyEntity.ParentId);
                     var provinceEntity = areaManager.GetObject(cityEntity.ParentId);
                     dgvSearchSendArea.Text = string.Format("{0}-{1}-{2}", provinceEntity.FullName,
                                                            cityEntity.FullName, countyEntity.FullName);
                     // 详细地址把省市区过滤掉
                     txtSendAddress.Text =
                         txtSendAddress.Text.Replace(provinceEntity.FullName, "").Replace(
                             cityEntity.FullName, "").Replace(
                             countyEntity.FullName, "");
                 }
             }
             else
             {
                 // 详细地址把省市区过滤掉
                 txtSendAddress.Text =
                     txtSendAddress.Text.Replace(result.Result.AddressComponent.Province.Trim(), "").Replace(
                         result.Result.AddressComponent.City.Trim(), "").Replace(
                         result.Result.AddressComponent.District.Trim(), "");
             }
         }
     }
 }