/// <summary> /// 刷新界面消息,最后执行导入 /// </summary> /// <param name="id"></param> private void Refresh(object id) { if (!splashScreenManagerImportExcel.IsSplashFormVisible) { splashScreenManagerImportExcel.ShowWaitForm(); } splashScreenManagerImportExcel.SetWaitFormCaption("请稍后......"); splashScreenManagerImportExcel.SetWaitFormDescription(string.Format("导入{0}条,成功:{1},失败:{2}", BillCodeCount, PrintBillEntities.Count, 0)); if (BillCodeCount == BillCodeIndex) { marqueeProgressBarControl1.Properties.Stopped = true; marqueeProgressBarControl1.BeginInvoke(new Action(() => { marqueeProgressBarControl1.Text = "获取结束,开始导入,请稍后..."; })); if (!splashScreenManagerImportExcel.IsSplashFormVisible) { splashScreenManagerImportExcel.ShowWaitForm(); } Application.DoEvents(); splashScreenManagerImportExcel.SetWaitFormCaption("请稍后"); splashScreenManagerImportExcel.SetWaitFormDescription(string.Format("保存{0}条记录到本地.....", PrintBillEntities.Count)); if (PrintBillEntities.Any()) { ZtoPrintBillManager printBillManager = new ZtoPrintBillManager(BillPrintHelper.DbHelper); if (PrintSourceBillList.Count == PrintBillEntities.Count) { PrintBillEntities.Clear(); PrintBillEntities.AddRange(PrintSourceBillList); } foreach (ZtoPrintBillEntity ztoPrintBillEntity in PrintBillEntities) { if (ztoPrintBillEntity != null) { printBillManager.Add(ztoPrintBillEntity, true); } } GridDataBind(); } Thread.Sleep(1500); splashScreenManagerImportExcel.CloseWaitForm(); var ts = DateTime.Now - StartDt; lblTime.Text += string.Format(" 耗时:{0}时{1}分{2}秒{3}毫秒", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds); Close(); } }
/// <summary> /// 保存本地 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { var entity = BuildPrintBillEntity(); if (entity != null) { string result; if (!string.IsNullOrEmpty(SelectedId)) { entity.Id = Convert.ToDecimal(SelectedId); // 更新 result = _printBillManager.Update(entity).ToString(); } else { result = _printBillManager.Add(entity, true); } if (!string.IsNullOrEmpty(result)) { XtraMessageBox.Show(@"保存成功", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); if (string.IsNullOrEmpty(SelectedId)) { if (ckKeep.Checked) { ClearText(); } } if (ckGetDefaultSendMan.Checked) { txtReceiveMan.Focus(); txtReceiveMan.Select(); } else { txtSendMan.Focus(); } } else { XtraMessageBox.Show("保存失败", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// 保存本地 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { if (_list.Any()) { var printBillEntities = new List <ZtoPrintBillEntity>(); foreach (ZtoPrintBillEntity ztoPrintBillEntity in _list) { ztoPrintBillEntity.OrderNumber = ""; ztoPrintBillEntity.BillCode = ""; printBillEntities.Add(ztoPrintBillEntity); } var printAddEntities = new List <ZtoPrintBillEntity>(); for (int i = 0; i < int.Parse(cmbPrintNumber.Text); i++) { printAddEntities.AddRange(printBillEntities); } if (printAddEntities.Any()) { var ztoPrintBillManager = new ZtoPrintBillManager(BillPrintHelper.DbHelper); if (!IsAddToPrintData) { ztoPrintBillManager.DbHelper = BillPrintHelper.BackupDbHelper; } int result = 0; foreach (ZtoPrintBillEntity ztoPrintBillEntity in printAddEntities) { ztoPrintBillEntity.OrderNumber = Guid.NewGuid().ToString("N").ToLower(); ztoPrintBillManager.Add(ztoPrintBillEntity, true); ++result; } _isAdd = result > 0; MessageBox.Show(string.Format("新增成功{0}条记录", result), DotNet.Utilities.AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
/// <summary> /// 保存本地 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSaveBill_Click(object sender, EventArgs e) { //构建实体 ZtoPrintBillEntity printBillEntity = BuildPrintEntity(); //if (!string.IsNullOrEmpty(PrintBillId)) //{ // printBillEntity = new ZtoPrintBillManager(BillPrintHelper.DbHelper).GetObject(PrintBillId); //} //printBillEntity.SendMan = txtSendMan.Text; //printBillEntity.SendPhone = txtSendPhone.Text; //printBillEntity.SendCompany = txtSendCompany.Text; //printBillEntity.SendAddress = txtSendAddress.Text; //printBillEntity.SendDate = string.IsNullOrEmpty(txtSendDate.Text) ? DateTime.Now.ToString(BaseSystemInfo.DateFormat) : txtSendDate.Text; //if (!string.IsNullOrEmpty(dgvSendArea.Text)) //{ // var sendAreaArray = dgvSendArea.Text.Split('-'); // printBillEntity.SendProvince = sendAreaArray[0]; // printBillEntity.SendCity = sendAreaArray[1]; // printBillEntity.SendCounty = sendAreaArray[2]; //} //printBillEntity.ReceiveMan = txtReceiveMan.Text; //printBillEntity.ReceivePhone = txtReceivePhone.Text; //printBillEntity.ReceiveCompany = txtReceiveCompany.Text; //printBillEntity.ReceiveAddress = txtReceiveAddress.Text; //if (!string.IsNullOrEmpty(dgvReceiveArea.Text)) //{ // var receiveAreaArray = dgvReceiveArea.Text.Split('-'); // printBillEntity.ReceiveProvince = receiveAreaArray[0]; // printBillEntity.ReceiveCity = receiveAreaArray[1]; // printBillEntity.ReceiveCounty = receiveAreaArray[2]; //} //printBillEntity.GoodsName = cmbGoodsName.Text; //printBillEntity.Weight = txtGoodsWeight.Text; //printBillEntity.GOODS_PAYMENT = string.IsNullOrEmpty(txtGoodsPayment.Text) ? 0 : decimal.Parse(txtGoodsPayment.Text); //printBillEntity.TOPAYMENT = string.IsNullOrEmpty(txtToPayMent.Text) ? 0 : decimal.Parse(txtToPayMent.Text); //printBillEntity.Remark = txtRemark.Text; //printBillEntity.BigPen = txtBigPen.Text; var ztoPrintBillManager = new ZtoPrintBillManager(BillPrintHelper.DbHelper); // 表示更新 if (!string.IsNullOrEmpty(PrintBillId)) { printBillEntity.Id = BaseBusinessLogic.ConvertToDecimal(PrintBillId); ztoPrintBillManager.Update(printBillEntity); XtraMessageBox.Show("更新成功", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { _list.Clear(); var saveCount = int.Parse(cmbPrintNumber.Text); if (saveCount == 0) { cmbPrintNumber.Text = "1"; saveCount = 1; } // 这里要有订单号可以输入,不能系统生成,这样不科学,2016年6月15日22:33:11,杨恒连 // 如果他大于1条的话,后面的订单号要系统生成了 // 最好检查这个订单号有么有重复使用,重复使用就不好了,这样获取到用过的单号是要罚款的 if (!string.IsNullOrEmpty(txtOrderNumber.Text)) { saveCount = saveCount - 1; printBillEntity.OrderNumber = txtOrderNumber.Text; ztoPrintBillManager.Add(printBillEntity, true); _list.Add(printBillEntity); } for (int i = 0; i < saveCount; i++) { printBillEntity.OrderNumber = Guid.NewGuid().ToString("N").ToLower(); ztoPrintBillManager.Add(printBillEntity, true); _list.Add(printBillEntity); } XtraMessageBox.Show(string.Format("新增成功{0}条记录", cmbPrintNumber.Text), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void CheckZtoElecInfo() { ZtoElecUserInfoEntity elecUserInfoEntity = BillPrintHelper.GetElecUserInfoEntity(); if (elecUserInfoEntity != null) { if (_list == null || _list.Count == 0) { MessageUtil.ShowWarning("请认真填写好发件人和收件人的姓名、电话、省市区、地址"); return; } var list = ZtoElecBillHelper.BindElecBillByCustomerId(_list, elecUserInfoEntity); if (list != null && list.Any()) { txtBillCode.Text = list.First().BillCode; txtBigPen.Text = list.First().BigPen; _list.First().BillCode = txtBillCode.Text; _list.First().BigPen = txtBigPen.Text; var printBillManager = new ZtoPrintBillManager(BillPrintHelper.DbHelper); // 表示更新 if (!string.IsNullOrEmpty(PrintBillId)) { list.First().Id = BaseBusinessLogic.ConvertToDecimal(PrintBillId); printBillManager.Update(list.First()); MessageUtil.ShowTips("获取成功,已更新本地"); } else { // 新增 printBillManager.Add(list.First(), true); MessageUtil.ShowTips("获取成功,已保存本地"); } } else { MessageUtil.ShowError("全部获取电子面单单号失败"); } } else { // 在默认发件人那边修改个人的商家ID信息 // 获取系统是否有默认发件人,如果有救修改,如果没有就新增 ZtoUserManager userManager = new ZtoUserManager(BillPrintHelper.DbHelper); var userList = userManager.GetList <ZtoUserEntity>(new KeyValuePair <string, object>(ZtoUserEntity.FieldIsDefault, 1), new KeyValuePair <string, object>(ZtoUserEntity.FieldIssendorreceive, 1)); if (!userList.Any()) { XtraMessageBox.Show("系统未绑定默认发件人和商家ID,请进行绑定", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); FrmAddSendMan addSendMan = new FrmAddSendMan(); addSendMan.ShowDialog(); addSendMan.Dispose(); } else { XtraMessageBox.Show("默认发件人未绑定商家ID,请进行绑定", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); FrmAddSendMan frmSendMan = new FrmAddSendMan { Id = userList.First().Id.ToString() }; frmSendMan.ShowDialog(); frmSendMan.Dispose(); } } }
/// <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); } var startDateTime = DateTime.Now; StartDt = startDateTime; if (!splashScreenManagerImportExcel.IsSplashFormVisible) { splashScreenManagerImportExcel.ShowWaitForm(); } Application.DoEvents(); splashScreenManagerImportExcel.SetWaitFormCaption("请稍后"); splashScreenManagerImportExcel.SetWaitFormDescription("开始导入Excel数据..."); try { DataTable chooseDt = ExcelHelper.ExcelToDataTable(txtFileFullPath.Text.Trim(), 38, 0, 3); if (chooseDt != null && chooseDt.Rows.Count > 0) { var list = new List <ZtoPrintBillEntity>(); int temp = 0; var defaultUserList = new ZtoUserManager(BillPrintHelper.DbHelper).GetList <ZtoUserEntity>(new KeyValuePair <string, object>(ZtoUserEntity.FieldIsDefault, 1), new KeyValuePair <string, object>(ZtoUserEntity.FieldIssendorreceive, 1)); ZtoUserEntity defaultUserEntity = null; if (defaultUserList.Any()) { defaultUserEntity = defaultUserList.First(); } foreach (DataRow dr in chooseDt.Rows) { ++temp; splashScreenManagerImportExcel.SetWaitFormDescription(string.Format("正在导入Excel数据:{0}/{1}", temp, chooseDt.Rows.Count)); ZtoPrintBillEntity entity = new ZtoPrintBillEntity(); if (ckTodaySend.Checked) { entity.SendDate = DateTime.Now.ToString(BaseSystemInfo.DateFormat); } if (ckUserDefaultSendMan.Checked) { if (defaultUserEntity != null) { entity.SendMan = defaultUserEntity.Realname; entity.SendPhone = defaultUserEntity.Mobile + " " + defaultUserEntity.TelePhone; entity.SendProvince = defaultUserEntity.Province; entity.SendCity = defaultUserEntity.City; entity.SendCounty = defaultUserEntity.County; entity.SendAddress = defaultUserEntity.Address; entity.SendSite = ""; entity.SendDeparture = entity.SendProvince; entity.SendCompany = defaultUserEntity.Company; entity.SendDepartment = defaultUserEntity.Department; entity.SendPostcode = defaultUserEntity.Postcode; } } else { if (this.Tag != null) { var sendUserEntity = this.Tag as ZtoUserEntity; // 表示选择了一个发件人的信息,这样也不用读取Excel里面的发件人了 if (sendUserEntity != null) { entity.SendMan = sendUserEntity.Realname; entity.SendPhone = sendUserEntity.Mobile + " " + sendUserEntity.TelePhone; entity.SendProvince = sendUserEntity.Province; entity.SendCity = sendUserEntity.City; entity.SendCounty = sendUserEntity.County; entity.SendAddress = sendUserEntity.Address; entity.SendSite = ""; entity.SendDeparture = sendUserEntity.Province; entity.SendCompany = sendUserEntity.Company; entity.SendDepartment = sendUserEntity.Department; entity.SendPostcode = sendUserEntity.Postcode; } } else { entity.SendMan = BaseBusinessLogic.ConvertToString(dr[2]); entity.SendPhone = BaseBusinessLogic.ConvertToString(dr[3]); entity.SendProvince = BaseBusinessLogic.ConvertToString(dr[4]); entity.SendCity = BaseBusinessLogic.ConvertToString(dr[5]); entity.SendCounty = BaseBusinessLogic.ConvertToString(dr[6]); entity.SendAddress = BaseBusinessLogic.ConvertToString(dr[7]); entity.SendSite = ""; entity.SendDeparture = BaseBusinessLogic.ConvertToString(dr[26]); if (string.IsNullOrEmpty(entity.SendDeparture)) { entity.SendDeparture = entity.SendProvince; } entity.SendCompany = BaseBusinessLogic.ConvertToString(dr[27]); entity.SendDepartment = BaseBusinessLogic.ConvertToString(dr[28]); entity.SendPostcode = BaseBusinessLogic.ConvertToString(dr[29]); } } entity.ReceiveMan = BaseBusinessLogic.ConvertToString(dr[8]); entity.ReceivePhone = BaseBusinessLogic.ConvertToString(dr[9]); entity.ReceiveProvince = BaseBusinessLogic.ConvertToString(dr[10]); entity.ReceiveCity = BaseBusinessLogic.ConvertToString(dr[11]); entity.ReceiveCounty = BaseBusinessLogic.ConvertToString(dr[12]); entity.ReceiveAddress = BaseBusinessLogic.ConvertToString(dr[13]); entity.ReceiveDestination = BaseBusinessLogic.ConvertToString(dr[30]); if (string.IsNullOrEmpty(entity.ReceiveDestination)) { entity.ReceiveDestination = entity.ReceiveProvince; } entity.ReceiveCompany = BaseBusinessLogic.ConvertToString(dr[31]); entity.ReceivePostcode = BaseBusinessLogic.ConvertToString(dr[32]); entity.GoodsName = BaseBusinessLogic.ConvertToString(dr[14]); entity.Weight = BaseBusinessLogic.ConvertToString(dr[15]); entity.TranFee = BaseBusinessLogic.ConvertToString(dr[16]); entity.GOODS_PAYMENT = BaseBusinessLogic.ConvertToDecimal(dr[17]); entity.TOPAYMENT = BaseBusinessLogic.ConvertToDecimal(dr[18]); entity.Length = BaseBusinessLogic.ConvertToString(dr[33]); entity.Width = BaseBusinessLogic.ConvertToString(dr[34]); entity.Height = BaseBusinessLogic.ConvertToString(dr[35]); entity.TotalNumber = BaseBusinessLogic.ConvertToString(dr[36]); entity.OrderNumber = BaseBusinessLogic.ConvertToString(dr[37]); entity.Remark = BaseBusinessLogic.ConvertToString(dr[22]); entity.CreateUserName = ""; entity.CreateSite = ""; entity.CreateOn = DateTime.Now; entity.PaymentType = "现金"; // 如果Excel里面没有填写订单号系统自动生成一个订单号,这样提取电子面单单号就不用怕了,2016-1-23 14:07:12 if (string.IsNullOrEmpty(entity.OrderNumber)) { // 导入自动生成订单号(电子面单)79170-南昌昌南 18779176845 这个qq提供的思路,2016-1-20 20:08:50 entity.OrderNumber = Guid.NewGuid().ToString("N").ToLower(); } if (!ckGetServerPrintMark.Checked) { entity.BigPen = string.Format("{0} {1} {2}", entity.ReceiveProvince, entity.ReceiveCity, entity.ReceiveCounty); } else { entity.BigPen = ""; } list.Add(entity); } if (!ckGetServerPrintMark.Checked) { var manager = new ZtoPrintBillManager(BillPrintHelper.DbHelper); foreach (ZtoPrintBillEntity ztoPrintBillEntity in list) { manager.Add(ztoPrintBillEntity, true); } if (splashScreenManagerImportExcel != null && splashScreenManagerImportExcel.IsSplashFormVisible) { splashScreenManagerImportExcel.CloseWaitForm(); } GridDataBind(); var ts = DateTime.Now - startDateTime; lblTime.Text = string.Format("耗时:{0}时{1}分{2}秒{3}毫秒", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds); Close(); } else { splashScreenManagerImportExcel.SetWaitFormDescription("正在联网获取大头笔信息,请稍后......"); // 开线程去读取大头笔的 CheckBillCode(list); } } 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); }
/// <summary> /// 导入Excel数据到本地数据库 /// </summary> public bool Import() { if (string.IsNullOrEmpty(txtFileFullPath.Text.Trim())) { XtraMessageBox.Show(@"请选择淘宝订单Excel", 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); } #region 检查是否选择了发件人 ZtoUserEntity defaultUserEntity = null; if (ckUserDefaultSendMan.Checked) { // 获取到默认的发件人 var defaultUserList = new ZtoUserManager(BillPrintHelper.DbHelper).GetList <ZtoUserEntity>(new KeyValuePair <string, object>(ZtoUserEntity.FieldIsDefault, 1), new KeyValuePair <string, object>(ZtoUserEntity.FieldIssendorreceive, 1)); if (defaultUserList.Any()) { defaultUserEntity = defaultUserList.FirstOrDefault(); if (defaultUserEntity == null) { XtraMessageBox.Show(@"请添加一个默认的发件人,然后再导入订单数据", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } } else { XtraMessageBox.Show(@"请添加一个默认的发件人,然后再导入订单数据", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } } else { if (this.Tag != null) { defaultUserEntity = this.Tag as ZtoUserEntity; // 表示选择了一个发件人的信息,这样也不用读取Excel里面的发件人了 if (defaultUserEntity == null) { XtraMessageBox.Show(@"请重新选择一个发件人,然后再导入订单数据", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); ckChooseSendMan.Checked = true; Import(); } } else { XtraMessageBox.Show(@"请选择一个发件人,然后再导入订单数据", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); ckChooseSendMan.Checked = true; Import(); } } #endregion var startDateTime = DateTime.Now; StartDt = startDateTime; if (!splashScreenManagerImportExcel.IsSplashFormVisible) { splashScreenManagerImportExcel.ShowWaitForm(); } Application.DoEvents(); splashScreenManagerImportExcel.SetWaitFormCaption("请稍后"); splashScreenManagerImportExcel.SetWaitFormDescription("开始导入淘宝订单Excel数据..."); try { DataTable chooseDt; if (Path.GetExtension(txtFileFullPath.Text) == ".csv") { var readCsv = new ReadCsvHelper(txtFileFullPath.Text); readCsv.CreateTable(); chooseDt = readCsv.GetResoultTable(); } else { chooseDt = ExcelHelper.ExcelToDataTable(txtFileFullPath.Text, 0, null); } if (chooseDt != null && chooseDt.Rows.Count > 0) { var list = new List <ZtoPrintBillEntity>(); int temp = 0; foreach (DataRow dr in chooseDt.Rows) { ++temp; splashScreenManagerImportExcel.SetWaitFormDescription(string.Format("正在导入Excel数据:{0}/{1}", temp, chooseDt.Rows.Count)); var entity = new ZtoPrintBillEntity(); if (ckTodaySend.Checked) { entity.SendDate = DateTime.Now.ToString(BaseSystemInfo.DateFormat); } if (defaultUserEntity != null) { entity.SendMan = defaultUserEntity.Realname; entity.SendPhone = defaultUserEntity.Mobile + " " + defaultUserEntity.TelePhone; entity.SendProvince = defaultUserEntity.Province; entity.SendCity = defaultUserEntity.City; entity.SendCounty = defaultUserEntity.County; entity.SendAddress = defaultUserEntity.Address; entity.SendCompany = defaultUserEntity.Company; entity.SendDepartment = defaultUserEntity.Department; entity.SendPostcode = defaultUserEntity.Postcode; } entity.SendSite = ""; entity.SendDeparture = entity.SendProvince; entity.ReceiveMan = BaseBusinessLogic.ConvertToString(dr[12]); entity.ReceivePhone = BaseBusinessLogic.ConvertToString(dr[16]); entity.ReceiveProvince = ""; entity.ReceiveCity = ""; entity.ReceiveCounty = ""; entity.ReceiveAddress = BaseBusinessLogic.ConvertToString(dr[13]).Replace(" ", ""); // 目的地 entity.ReceiveDestination = ""; if (string.IsNullOrEmpty(entity.ReceiveDestination)) { entity.ReceiveDestination = entity.ReceiveProvince; } entity.ReceiveCompany = ""; entity.ReceivePostcode = ""; entity.GoodsName = BaseBusinessLogic.ConvertToString(dr[19]); entity.Weight = ""; entity.TranFee = ""; entity.GOODS_PAYMENT = 0; entity.TOPAYMENT = 0; entity.Length = ""; entity.Width = ""; entity.Height = ""; entity.TotalNumber = ""; entity.OrderNumber = BaseBusinessLogic.ConvertToString(dr[0]); entity.Remark = BaseBusinessLogic.ConvertToString(dr[23]); entity.CreateUserName = ""; entity.CreateSite = ""; entity.CreateOn = DateTime.Now; entity.PaymentType = ""; // 如果Excel里面没有填写订单号系统自动生成一个订单号,这样提取电子面单单号就不用怕了,2016-1-23 14:07:12 if (string.IsNullOrEmpty(entity.OrderNumber)) { // 导入自动生成订单号(电子面单)79170-南昌昌南 18779176845 这个qq提供的思路,2016-1-20 20:08:50 entity.OrderNumber = Guid.NewGuid().ToString("N").ToLower(); } if (!ckGetServerPrintMark.Checked) { entity.BigPen = string.Format("{0} {1} {2}", entity.ReceiveProvince, entity.ReceiveCity, entity.ReceiveCounty); } else { entity.BigPen = ""; } list.Add(entity); } if (!ckGetServerPrintMark.Checked) { var manager = new ZtoPrintBillManager(BillPrintHelper.DbHelper); foreach (ZtoPrintBillEntity ztoPrintBillEntity in list) { manager.Add(ztoPrintBillEntity, true); } if (splashScreenManagerImportExcel != null && splashScreenManagerImportExcel.IsSplashFormVisible) { splashScreenManagerImportExcel.CloseWaitForm(); } GridDataBind(); Close(); } else { splashScreenManagerImportExcel.SetWaitFormDescription("正在联网获取大头笔信息,请稍后......"); // 开线程去读取大头笔的 CheckBillCode(list); } } 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); }
/// <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); } var startDateTime = DateTime.Now; StartDt = startDateTime; if (!splashScreenManagerImportExcel.IsSplashFormVisible) { splashScreenManagerImportExcel.ShowWaitForm(); } Application.DoEvents(); splashScreenManagerImportExcel.SetWaitFormCaption("请稍后"); splashScreenManagerImportExcel.SetWaitFormDescription("开始导入Excel数据..."); try { DataTable chooseDt = ExcelHelper.ExcelToDataTable(txtFileFullPath.Text.Trim(), 11, 0, 1); if (chooseDt != null && chooseDt.Rows.Count > 0) { var list = new List <ZtoPrintBillEntity>(); int temp = 0; var defaultUserList = new ZtoUserManager(BillPrintHelper.DbHelper).GetList <ZtoUserEntity>(new KeyValuePair <string, object>(ZtoUserEntity.FieldIsDefault, 1), new KeyValuePair <string, object>(ZtoUserEntity.FieldIssendorreceive, 1)); ZtoUserEntity defaultUserEntity = null; if (defaultUserList.Any()) { defaultUserEntity = defaultUserList.First(); } foreach (DataRow dr in chooseDt.Rows) { ++temp; splashScreenManagerImportExcel.SetWaitFormDescription(string.Format("正在导入Excel数据:{0}/{1}", temp, chooseDt.Rows.Count)); ZtoPrintBillEntity entity = new ZtoPrintBillEntity(); if (ckTodaySend.Checked) { entity.SendDate = DateTime.Now.ToString(BaseSystemInfo.DateFormat); } if (ckUserDefaultSendMan.Checked) { if (defaultUserEntity != null) { entity.SendMan = defaultUserEntity.Realname; entity.SendPhone = defaultUserEntity.Mobile + " " + defaultUserEntity.TelePhone; entity.SendProvince = defaultUserEntity.Province; entity.SendCity = defaultUserEntity.City; entity.SendCounty = defaultUserEntity.County; entity.SendAddress = defaultUserEntity.Address; entity.SendDeparture = entity.SendProvince; entity.SendCompany = defaultUserEntity.Company; entity.SendDepartment = defaultUserEntity.Department; entity.SendPostcode = defaultUserEntity.Postcode; } } else { // 使用Excel里面的发件人 entity.SendMan = BaseBusinessLogic.ConvertToString(dr[6]); entity.SendPhone = BaseBusinessLogic.ConvertToString(dr[7]); entity.SendAddress = BaseBusinessLogic.ConvertToString(dr[8]); if (string.IsNullOrEmpty(entity.SendProvince) && string.IsNullOrEmpty(entity.SendCity) && string.IsNullOrEmpty(entity.SendCounty)) { if (!string.IsNullOrEmpty(entity.SendAddress)) { var baiAddressEntity = BaiduMapHelper.GetProvCityDistFromBaiduMap(entity.SendAddress); if (baiAddressEntity != null) { entity.SendProvince = baiAddressEntity.Result.AddressComponent.Province; entity.SendCity = baiAddressEntity.Result.AddressComponent.City; entity.SendCounty = baiAddressEntity.Result.AddressComponent.District; } } } entity.SendDeparture = entity.SendProvince; if (string.IsNullOrEmpty(entity.SendDeparture)) { entity.SendDeparture = entity.SendProvince; } entity.SendCompany = BaseBusinessLogic.ConvertToString(dr[10]); entity.SendDepartment = BaseBusinessLogic.ConvertToString(dr[11]); entity.SendPostcode = BaseBusinessLogic.ConvertToString(dr[9]); } entity.ReceiveMan = BaseBusinessLogic.ConvertToString(dr[0]); entity.ReceivePhone = BaseBusinessLogic.ConvertToString(dr[1]); entity.ReceiveAddress = BaseBusinessLogic.ConvertToString(dr[2]); //if (string.IsNullOrEmpty(entity.ReceiveProvince) && string.IsNullOrEmpty(entity.ReceiveCity) && string.IsNullOrEmpty(entity.ReceiveCounty)) //{ // if (!string.IsNullOrEmpty(entity.ReceiveAddress)) // { // var baiAddressEntity = BaiduHelper.GetProvCityDistFromBaiduMap(entity.ReceiveAddress); // if (baiAddressEntity != null) // { // entity.ReceiveProvince = baiAddressEntity.Result.AddressComponent.Province; // entity.ReceiveCity = baiAddressEntity.Result.AddressComponent.City; // entity.ReceiveCounty = baiAddressEntity.Result.AddressComponent.District; // } // } //} entity.ReceiveDestination = entity.ReceiveProvince; if (string.IsNullOrEmpty(entity.ReceiveDestination)) { entity.ReceiveDestination = entity.ReceiveProvince; } //entity.ReceiveCompany = BaseBusinessLogic.ConvertToString(dr[31]); //entity.ReceivePostcode = BaseBusinessLogic.ConvertToString(dr[32]); //entity.GoodsName = BaseBusinessLogic.ConvertToString(dr[14]); //entity.Weight = BaseBusinessLogic.ConvertToString(dr[15]); //entity.TranFee = BaseBusinessLogic.ConvertToString(dr[16]); //entity.Length = BaseBusinessLogic.ConvertToString(dr[33]); //entity.Width = BaseBusinessLogic.ConvertToString(dr[34]); //entity.Height = BaseBusinessLogic.ConvertToString(dr[35]); //entity.TotalNumber = BaseBusinessLogic.ConvertToString(dr[36]); entity.Remark = BaseBusinessLogic.ConvertToString(dr[4]); entity.OrderNumber = BaseBusinessLogic.ConvertToString(dr[3]); entity.TranFee = BaseBusinessLogic.ConvertToString(dr[5]); entity.CreateOn = DateTime.Now; if (!ckGetServerPrintMark.Checked) { entity.BigPen = string.Format("{0} {1} {2}", entity.ReceiveProvince, entity.ReceiveCity, entity.ReceiveCounty); } else { entity.BigPen = ""; } list.Add(entity); } if (!ckGetServerPrintMark.Checked) { var manager = new ZtoPrintBillManager(BillPrintHelper.DbHelper); foreach (ZtoPrintBillEntity ztoPrintBillEntity in list) { manager.Add(ztoPrintBillEntity, true); } if (splashScreenManagerImportExcel != null && splashScreenManagerImportExcel.IsSplashFormVisible) { splashScreenManagerImportExcel.CloseWaitForm(); } GridDataBind(); var ts = DateTime.Now - startDateTime; lblTime.Text = string.Format("耗时:{0}时{1}分{2}秒{3}毫秒", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds); Close(); } else { splashScreenManagerImportExcel.SetWaitFormDescription("正在联网获取大头笔信息"); if (splashScreenManagerImportExcel != null && splashScreenManagerImportExcel.IsSplashFormVisible) { splashScreenManagerImportExcel.CloseWaitForm(); } // 开线程去读取大头笔的 CheckBillCode(list); } } 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); }