using AllBase; using AllBase.Model.Result; using NaiBa.Util.Extension; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using TemuKJD.BaseForms; using Work; namespace TemuKJD.KJDForms.JITForms { public partial class JitOrderUploadFileForm : LRBaseForm { public bool isClientJit; TemuDBOrderInfo temuDBOrderInfo = null; public JitOrderUploadFileForm(TemuDBOrderInfo _temuDBOrderInfo) { InitializeComponent(); temuDBOrderInfo = _temuDBOrderInfo; } private void JitOrderUploadFileForm_Load(object sender, EventArgs e) { btnUpload1.Visible = btnUpload2.Visible = false; btnOk.Visible = false; lblShippingMark.Text = lblBarCode.Text = ""; if (isClientJit) { btnUpload1.Visible = btnUpload2.Visible = true; btnOk.Visible = true; } this.txtJiaTongCode.Text = temuDBOrderInfo?.jiaTongCode; Task.Run(() => { if (!string.IsNullOrEmpty(temuDBOrderInfo.barCodeMd5)) { var url = BaseClass.BuildObjString("order/get_order_code_file"); var data = UserLogin.GetSignaturex(); data += "&file_md5=" + temuDBOrderInfo.barCodeMd5; data += "&shop_id=" + temuDBOrderInfo.supplierId; data += "&purchaseTime=" + temuDBOrderInfo.purchaseTime; var html = GetHtml.PostUtf8(url, data); if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) html = GetHtml.PostUtf8(url, data); if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) { var errMsg = BaseRegex.GetStringJson(ref html, "msg"); BaseMsgForm.ShowError(errMsg); return; } else { Invoke(new Action(() => { this.pbBarCode.Image = Properties.Resources.pdf; var file_md5 = BaseRegex.GetStringJson(ref html, "file_md5"); var file_base64 = BaseRegex.GetStringJson(ref html, "file_base64"); this.pbBarCode.Tag = file_base64; this.lblBarCode.Text = file_md5 + ".pdf"; lblBarCodeShow.Visible = true; })); } } if (!string.IsNullOrEmpty(temuDBOrderInfo.shippingMarkMd5)) { var url = BaseClass.BuildObjString("order/get_order_code_file"); var data = UserLogin.GetSignaturex(); data += "&file_md5=" + temuDBOrderInfo.shippingMarkMd5; data += "&shop_id=" + temuDBOrderInfo.supplierId; data += "&purchaseTime=" + temuDBOrderInfo.purchaseTime; var html = GetHtml.PostUtf8(url, data); if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) html = GetHtml.PostUtf8(url, data); if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) { var errMsg = BaseRegex.GetStringJson(ref html, "msg"); BaseMsgForm.ShowError(errMsg); return; } else { Invoke(new Action(() => { this.pbShippingMark.Image = Properties.Resources.pdf; var file_md5 = BaseRegex.GetStringJson(ref html, "file_md5"); var file_base64 = BaseRegex.GetStringJson(ref html, "file_base64"); this.pbShippingMark.Tag = file_base64; this.lblShippingMark.Text = file_md5 + ".pdf"; lblShippingMarkShow.Visible = true; })); } } }); } private void btnSet1_Click(object sender, EventArgs e) { } private void btnUpload1_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Multiselect = false; // 设置过滤条件,只显示文本文件 openFileDialog.Filter = "dpf文件 (*.pdf)|*.pdf|All files (*.*)|*.*"; // 显示对话框并获取结果 if (openFileDialog.ShowDialog() == DialogResult.OK) { string filePath = openFileDialog.FileName; UpdatePdfFile(filePath, "barCode"); } } private void btnUpload2_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Multiselect = false; // 设置过滤条件,只显示文本文件 openFileDialog.Filter = "dpf文件 (*.pdf)|*.pdf|All files (*.*)|*.*"; // 显示对话框并获取结果 if (openFileDialog.ShowDialog() == DialogResult.OK) { string filePath = openFileDialog.FileName; UpdatePdfFile(filePath, "shippingMark"); } } bool UpdatePdfFile(string filePath, string type) { try { byte[] fileBytes = File.ReadAllBytes(filePath); // 将字节数组转换为Base64字符串 string file_base64 = Convert.ToBase64String(fileBytes); string file_md5 = BaseClass.GetFileMd5(filePath); var url = BaseClass.BuildObjString("order/add_order_code_file"); var data = UserLogin.GetSignaturex(); data += "&file_base64=" + file_base64; data += "&file_md5=" + file_md5; data += "&shop_id=" + temuDBOrderInfo.supplierId; data += "&purchaseTime=" + temuDBOrderInfo.purchaseTime; var html = GetHtml.PostUtf8(url, data); if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) html = GetHtml.PostUtf8(url, data); if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) { var errMsg = BaseRegex.GetStringJson(ref html, "msg"); BaseMsgForm.ShowError("文件上传服务端失败,请重试!" + errMsg); return false; } else { if (type == "shippingMark") { this.pbShippingMark.Image = Properties.Resources.pdf; this.pbShippingMark.Tag = file_base64; this.lblShippingMark.Text = file_md5 + ".pdf"; lblShippingMarkShow.Visible = true; } if (type == "barCode") { this.pbBarCode.Image = Properties.Resources.pdf; this.pbBarCode.Tag = file_base64; this.lblBarCode.Text = file_md5 + ".pdf"; lblBarCodeShow.Visible = true; } } return true; } catch (Exception ex) { BaseMsgForm.ShowError("文件上传服务端失败!" + ex.Message); return false; } } private void btnOk_Click(object sender, EventArgs e) { string jiaTongCode = txtJiaTongCode.Text.Trim(); string shippingMarkMd5 = lblShippingMark.Text.Replace(".pdf", ""); string barCodeMd5 = lblBarCode.Text.Replace(".pdf", ""); var url = BaseClass.BuildObjString("order/save_order_code_file_link"); var data = UserLogin.GetSignaturex(); data += "&jia_tong_code=" + jiaTongCode; data += "&bar_code_md5=" + barCodeMd5; data += "&shipping_mark_md5=" + shippingMarkMd5; data += "&sub_order_sn=" + temuDBOrderInfo.subPurchaseOrderSn; data += "&shop_id=" + temuDBOrderInfo.supplierId; data += "&purchaseTime=" + temuDBOrderInfo.purchaseTime; var html = GetHtml.PostUtf8(url, data); if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) html = GetHtml.PostUtf8(url, data); if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) { var errMsg = BaseRegex.GetStringJson(ref html, "msg"); BaseMsgForm.ShowError(errMsg); } else { temuDBOrderInfo.jiaTongCode = jiaTongCode; temuDBOrderInfo.shippingMarkMd5 = shippingMarkMd5; temuDBOrderInfo.barCodeMd5 = barCodeMd5; BaseMsgForm.ShowInfo("保存成功!"); this.Close(); } } private void pbBarCode_Click(object sender, EventArgs e) { var base64String = pbBarCode.Tag.ParseToString(); if (!string.IsNullOrEmpty(base64String)) { SaveFileDialog dialog = new SaveFileDialog(); dialog.Title = "保存pdf文件..."; dialog.Filter = "pdf files (*.pdf)|*.pdf|All files (*.*)|*.*"; dialog.RestoreDirectory = true; dialog.FileName = temuDBOrderInfo.subPurchaseOrderSn + " - 商品条码.pdf"; if (dialog.ShowDialog() != DialogResult.OK) return; byte[] pdfBytes = Convert.FromBase64String(base64String); // 将字节数组写入到文件 File.WriteAllBytes(dialog.FileName, pdfBytes); } } private void pbShippingMark_Click(object sender, EventArgs e) { var base64String = pbShippingMark.Tag.ParseToString(); if (!string.IsNullOrEmpty(base64String)) { SaveFileDialog dialog = new SaveFileDialog(); dialog.Title = "保存pdf文件..."; dialog.Filter = "pdf files (*.pdf)|*.pdf|All files (*.*)|*.*"; dialog.RestoreDirectory = true; dialog.FileName = temuDBOrderInfo.subPurchaseOrderSn + " - 箱唛.pdf"; if (dialog.ShowDialog() != DialogResult.OK) return; byte[] pdfBytes = Convert.FromBase64String(base64String); // 将字节数组写入到文件 File.WriteAllBytes(dialog.FileName, pdfBytes); } } private void btnClose_Click(object sender, EventArgs e) { this.Close(); } } }