/// <summary> /// 保存签收图片 /// </summary> private void btnSavePic_Click(object sender, EventArgs e) { FrmParent.ParentForm.ResetReturnDelay(); //if (txtOrderNumber.Text.Trim().Length != 12) string number = txtOrderNumber.Text.Trim(); if (number == string.Empty) { MessageBox.Show("请通过扫描或手工录入正确的运单编号!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); return; } if (btnCamera.Text == "拍摄") { MessageBox.Show("请完成当前照片的拍摄或按[-]删除掉再保存!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); return; } if (MessageBox.Show(string.Format("编号[{0}] 图片[{1}]张", number, lbPicList.Items.Count), "确定要保存吗?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.No) { return; } bool result = true; string exceptionStr = string.Empty; try { if (ucConsignors1._SelectConSignor.ConsignorId == -1) { try { ucConsignors1.AutoMatchConsignors(ref number); } catch (Exception ex) { result = false; exceptionStr = ex.Message; MessageBox.Show(exceptionStr, "请选择供应商", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); return; } //result = false; //exceptionStr = "请选择供应商"; //MessageBox.Show("请选择是自运单还是第三方单", "请选择供应商", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); //return; } //检查缓存文件 List <FileInfo> fileList = new List <FileInfo>(); foreach (PicNameAndPath item in lbPicList.Items) { try { fileList.Add(new FileInfo(item.PicPath + ".jpg")); } catch (Exception ex) { throw new Exception("获取缓存图片[" + item.PicName + "]出错:[" + ex.Message + "]"); } } //创建保存路径 string savePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase.ToString()) + "\\postback\\"; if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } List <string> filePathList = new List <string>(); //移动缓存文件 foreach (FileInfo fi in fileList) { try { string newFileName = savePath + fi.Name; fi.MoveTo(newFileName); filePathList.Add(newFileName); } catch (Exception ex) { throw new Exception("保存缓存图片[" + fi.Name + "]出错:[" + ex.Message + "]"); } } //保存文件路径 string content = string.Empty; DateTime dtNow = DateTime.Now; try { //SaveNode(); txtOrderNumber.Text = number; dtNow = WaybillServer.AddPostBack(number, filePathList, ucConsignors1._SelectConSignor.ConsignorId, ref content); Common.SaveOptRecord("保存签收图片成功", content, dtNow, number, ucConsignors1._SelectConSignor.ConsignorId); FrmParent.ParentForm.EndSleep(); } catch (Exception ex) { Common.SaveOptRecord("保存签收图片失败:" + ex.Message, content, dtNow, number, ucConsignors1._SelectConSignor.ConsignorId); throw new Exception("保存失败:[" + ex.Message + "]"); } InitPhoto(); } catch (Exception ex) { result = false; exceptionStr = ex.Message; //exceptionStr = "保存失败"; //if (ex.Message.Contains("重复扫描")) // exceptionStr = ex.Message; } finally { ShowResult(result, false, exceptionStr); ucConsignors1.SelectedConsignors(); } }
/// <summary> /// 保存签收图片 /// </summary> private void btnSavePic_Click(object sender, EventArgs e) { //if (txtOrderNumber.Text.Trim().Length != 12) if (txtOrderNumber.Text.Trim() == string.Empty) { MessageBox.Show("请通过扫描或手工录入正确的运单编号!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); return; } if (btnCamera.Text == "拍摄") { MessageBox.Show("请完成当前照片的拍摄或按[-]删除掉再保存!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); return; } if (MessageBox.Show(string.Format("编号[{0}] 图片[{1}]张", txtOrderNumber.Text.Trim(), lbPicList.Items.Count), "确定要保存吗?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.No) { return; } bool result = true; string exceptionStr = string.Empty; try { //检查缓存文件 List <FileInfo> fileList = new List <FileInfo>(); foreach (PicNameAndPath item in lbPicList.Items) { try { fileList.Add(new FileInfo(item.PicPath)); } catch (Exception ex) { throw new Exception("获取缓存图片[" + item.PicName + "]出错:[" + ex.Message + "]"); } } //创建保存路径 string savePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase.ToString()) + "\\postback\\"; if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } List <string> filePathList = new List <string>(); //移动缓存文件 foreach (FileInfo fi in fileList) { try { string newFileName = savePath + fi.Name; fi.MoveTo(newFileName); filePathList.Add(newFileName); } catch (Exception ex) { throw new Exception("保存缓存图片[" + fi.Name + "]出错:[" + ex.Message + "]"); } } //保存文件路径 try { WaybillServer.AddPostBack(txtOrderNumber.Text.Trim(), filePathList); } catch (Exception ex) { throw new Exception("保存数据出错:[" + ex.Message + "]"); } InitPhoto(); } catch (Exception ex) { result = false; exceptionStr = ex.Message; } finally { ShowResult(result, false, exceptionStr); } }