示例#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(), "");
             }
         }
     }
 }
 /// <summary>
 /// 导入Excel数据到本地数据库
 /// </summary>
 public bool Import()
 {
     if (string.IsNullOrEmpty(txtFileFullPath.Text.Trim()))
     {
         XtraMessageBox.Show(@"请选择录单模板", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
         btnOpenExcel_Click(this, null);
         return(false);
     }
     if (!File.Exists(txtFileFullPath.Text))
     {
         XtraMessageBox.Show(@"选中文件不存在,请重新选择导入Excel文件", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
         btnOpenExcel_Click(this, null);
         return(false);
     }
     if (!splashScreenManagerImportExcel.IsSplashFormVisible)
     {
         splashScreenManagerImportExcel.ShowWaitForm();
     }
     Application.DoEvents();
     splashScreenManagerImportExcel.SetWaitFormCaption("请稍后");
     splashScreenManagerImportExcel.SetWaitFormDescription("开始导入Excel数据...");
     try
     {
         int crossRow = int.Parse(cmbPrintNumber.Text) - 1;
         if (crossRow < 0)
         {
             crossRow = 1;
         }
         DataTable chooseDt = ExcelHelper.ExcelToDataTable(txtFileFullPath.Text.Trim(), 38, 0, crossRow);
         if (chooseDt != null && chooseDt.Rows.Count > 0)
         {
             var list = new List <ZtoUserEntity>();
             int temp = 0;
             foreach (DataRow dr in chooseDt.Rows)
             {
                 ++temp;
                 splashScreenManagerImportExcel.SetWaitFormDescription(string.Format("正在导入Excel数据:{0}/{1}", temp, chooseDt.Rows.Count));
                 var userEntity = new ZtoUserEntity {
                     Realname = BaseBusinessLogic.ConvertToString(dr[8])
                 };
                 if (ValidateUtil.IsMobile(BaseBusinessLogic.ConvertToString(dr[9])))
                 {
                     userEntity.Mobile = BaseBusinessLogic.ConvertToString(dr[9]);
                 }
                 else
                 {
                     userEntity.TelePhone = BaseBusinessLogic.ConvertToString(dr[9]);
                 }
                 var tempProvince = BaseBusinessLogic.ConvertToString(dr[10]);
                 // 收件人地址(有可能用户不填写收件省市区)
                 userEntity.Address = BaseBusinessLogic.ConvertToString(dr[13]);
                 if (tempProvince != null)
                 {
                     userEntity.Province = tempProvince.Trim();
                 }
                 var tempCity = BaseBusinessLogic.ConvertToString(dr[11]);
                 if (tempCity != null)
                 {
                     userEntity.City = tempCity.Trim();
                 }
                 var tempCounty = BaseBusinessLogic.ConvertToString(dr[12]);
                 if (tempCounty != null)
                 {
                     userEntity.County = tempCounty.Trim();
                 }
                 if (string.IsNullOrEmpty(userEntity.Province) && string.IsNullOrEmpty(userEntity.City) && string.IsNullOrEmpty(userEntity.County))
                 {
                     if (!string.IsNullOrEmpty(userEntity.Address))
                     {
                         var result = BaiduMapHelper.GetProvCityDistFromBaiduMap(userEntity.Address);
                         if (result != null)
                         {
                             userEntity.Province = result.Result.AddressComponent.Province;
                             userEntity.City     = result.Result.AddressComponent.City;
                             userEntity.County   = result.Result.AddressComponent.District;
                         }
                     }
                 }
                 userEntity.Company         = BaseBusinessLogic.ConvertToString(dr[31]);
                 userEntity.Postcode        = BaseBusinessLogic.ConvertToString(dr[32]);
                 userEntity.Issendorreceive = "0";
                 if (string.IsNullOrEmpty(userEntity.Postcode))
                 {
                     if (!string.IsNullOrEmpty(userEntity.City) && !string.IsNullOrEmpty(userEntity.County))
                     {
                         userEntity.Postcode = NetworkHelper.GetPostCodeByAddress(userEntity.City, userEntity.County);
                     }
                 }
                 if (!string.IsNullOrEmpty(userEntity.Province))
                 {
                     var areaEntity = _areaManager.GetList <BaseAreaEntity>(new KeyValuePair <string, object>(BaseAreaEntity.FieldFullName, userEntity.Province)).FirstOrDefault();
                     if (areaEntity != null)
                     {
                         userEntity.ProvinceId = areaEntity.Id;
                     }
                 }
                 if (!string.IsNullOrEmpty(userEntity.City))
                 {
                     var areaEntity = _areaManager.GetList <BaseAreaEntity>(new KeyValuePair <string, object>(BaseAreaEntity.FieldFullName, userEntity.City)).FirstOrDefault();
                     if (areaEntity != null)
                     {
                         userEntity.CityId = areaEntity.Id;
                     }
                 }
                 if (!string.IsNullOrEmpty(userEntity.County))
                 {
                     var areaEntity = _areaManager.GetList <BaseAreaEntity>(new KeyValuePair <string, object>(BaseAreaEntity.FieldFullName, userEntity.County)).FirstOrDefault();
                     if (areaEntity != null)
                     {
                         userEntity.CountyId = areaEntity.Id;
                     }
                 }
                 userEntity.CreateOn = DateTime.Now;
                 list.Add(userEntity);
             }
             using (IDbHelper dbHelper = DbHelperFactory.GetHelper(CurrentDbType.SQLite, BillPrintHelper.BillPrintConnectionString))
             {
                 try
                 {
                     dbHelper.BeginTransaction();
                     var manager = new ZtoUserManager(dbHelper);
                     foreach (ZtoUserEntity ztoUserEntity in list)
                     {
                         manager.Add(ztoUserEntity, true);
                     }
                     dbHelper.CommitTransaction();
                     GridDataBind();
                 }
                 catch (Exception ex)
                 {
                     dbHelper.RollbackTransaction();
                     ProcessException(ex);
                 }
             }
             if (splashScreenManagerImportExcel != null && splashScreenManagerImportExcel.IsSplashFormVisible)
             {
                 splashScreenManagerImportExcel.CloseWaitForm();
             }
             Close();
         }
         else
         {
             XtraMessageBox.Show(@"模板没有填写任何数据,导入失败", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Error);
             return(false);
         }
     }
     catch (Exception ex)
     {
         ProcessException(ex);
         return(false);
     }
     finally
     {
         if (splashScreenManagerImportExcel != null && splashScreenManagerImportExcel.IsSplashFormVisible)
         {
             splashScreenManagerImportExcel.CloseWaitForm();
         }
     }
     return(true);
 }