|
@@ -4,7 +4,7 @@ using System.Collections.Generic;
|
|
|
using System.Data;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
-using System.Text;
|
|
|
+//using System.Text;
|
|
|
using Microsoft.Win32;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
@@ -50,6 +50,9 @@ using FaFrameUI;
|
|
|
using System.Security.Policy;
|
|
|
using static MainForm.ClassFile.XiaomiClass.MesHelper;
|
|
|
using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
|
|
|
+using System.Drawing.Imaging;
|
|
|
+using System.Drawing;
|
|
|
+using ICSharpCode.SharpZipLib.Zip;
|
|
|
|
|
|
/*
|
|
|
* 注:本源码对外提供,所以有些地方使用中文命名方法及变量
|
|
@@ -2507,7 +2510,19 @@ namespace MainForm
|
|
|
isCollectingFlagRight = false;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ public static (int,string) CompressFolder(string folderPath, string zipFilePath)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ // 创建zip文件,将指定文件夹内的所有内容压缩到这个zip文件中
|
|
|
+ System.IO.Compression.ZipFile.CreateFromDirectory(folderPath, zipFilePath);
|
|
|
+ return (1, "文件夹已成功压缩!");
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ return (0, "文件压缩出错!"+ ex.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
/// <summary>
|
|
|
/// 上传文件
|
|
|
/// </summary>
|
|
@@ -2522,7 +2537,7 @@ namespace MainForm
|
|
|
int result = 0;
|
|
|
var formData = new MultipartFormDataContent();
|
|
|
string msg = "";
|
|
|
- string file_category = "IMAGE"; //IMAGE 、TEXT 、UNKNOWN 这里上传图片
|
|
|
+ string file_category = "IMAGE"; //IMAGE 、TEXT 、UNKNOWN
|
|
|
string file_type = "IMAGE";
|
|
|
string project = GlobalContext.ProgramName;
|
|
|
string run_mode = GlobalContext.run_mode;
|
|
@@ -2533,93 +2548,98 @@ namespace MainForm
|
|
|
string staion_id = xiaomiParm.stationCode;
|
|
|
string bucket =
|
|
|
$"{file_category}/{file_type}/{project}/{product_mode}/{run_mode}/{pass_result}/{device_code}/{sn}/{staion_id}";
|
|
|
-
|
|
|
// 获取所有图片文件
|
|
|
- List<string> imageFiles = GetAllImageFiles(path);
|
|
|
+
|
|
|
+ if (guid == "")
|
|
|
+ {
|
|
|
+ guid = Guid.NewGuid().ToString();
|
|
|
+ }
|
|
|
try
|
|
|
{
|
|
|
- if (imageFiles.Count > 0)
|
|
|
- {
|
|
|
- foreach (string imageFile in imageFiles)
|
|
|
- {
|
|
|
- if (guid == "")
|
|
|
- {
|
|
|
- guid = Guid.NewGuid().ToString();
|
|
|
- }
|
|
|
-
|
|
|
- filename = Path.GetFileName(imageFile);
|
|
|
-
|
|
|
- sql = string.Format(
|
|
|
- "INSERT INTO [dbo].[DataFiles](stationCode,stationName,CarrierBarcode,ProductBarcode,bucket,fileName,fileContext,uuid,fileUrl,status,submitTime,createTime) " +
|
|
|
- "VALUES('{0}','{1}','{2}' ,'{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')"
|
|
|
- , stationCode
|
|
|
- , stationName
|
|
|
- , BarcodeSet.strCarrierBarcode
|
|
|
- , BarcodeSet.strProductBarcode
|
|
|
- , bucket
|
|
|
- , filename
|
|
|
- , ""
|
|
|
- , guid
|
|
|
- , ""
|
|
|
- , 0
|
|
|
- , ""
|
|
|
- , DateTime.Now
|
|
|
- );
|
|
|
- string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
|
|
|
-
|
|
|
- FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
|
|
|
- fileUpload_X5.bucket = bucket;
|
|
|
- fileUpload_X5.name = filename;
|
|
|
- fileUpload_X5.uuid = guid.ToString();
|
|
|
- ///需要上传文件
|
|
|
- FileInfo file = new FileInfo(imageFile);
|
|
|
- string fileMd5Hex = GetMD5Hex(file);
|
|
|
- fileUpload_X5.md5 = fileMd5Hex;
|
|
|
- fileUpload_X5.uploadCloud = true;
|
|
|
- fileUpload_X5.informMqtt = true;
|
|
|
-
|
|
|
- FileMqttPayload fileMqttPayload = new FileMqttPayload();
|
|
|
- fileMqttPayload.factory = GlobalContext.Factory_Code;
|
|
|
- fileMqttPayload.project_name = GlobalContext.Project_Code;
|
|
|
- fileMqttPayload.product_mode = GlobalContext.product_mode;
|
|
|
- fileMqttPayload.line_no = GlobalContext.LineCode;
|
|
|
- fileMqttPayload.work_station_no = xiaomiParm.workstation;
|
|
|
- fileMqttPayload.equipment_no = xiaomiParm.deviceCode;
|
|
|
- fileMqttPayload.station_no = xiaomiParm.stationCode;
|
|
|
- fileMqttPayload.file_id = guid;
|
|
|
- fileMqttPayload.file_name = filename;
|
|
|
- fileMqttPayload.sn = BarcodeSet.strProductBarcode;
|
|
|
- //fileMqttPayload.opt_time = "";
|
|
|
- //fileMqttPayload.file_type = "";
|
|
|
- //fileMqttPayload.file_category = "";
|
|
|
- //fileMqttPayload.tag = "";
|
|
|
- fileMqttPayload.reference_info.pass_station_id = uuid;
|
|
|
-
|
|
|
- var fileresult =
|
|
|
- XiaomiMESHttp_UpLoadFile.FileUoladToMes(imageFile, fileUpload_X5, fileMqttPayload);
|
|
|
-
|
|
|
- if (fileresult.Result.Item1 == 0)
|
|
|
- {
|
|
|
- sql = string.Format("UPDATE [dbo].[DataFiles] SET status='{0}' WHERE uuid='{1}'", 1, guid);
|
|
|
- string retnew = SQLHelper_New.ExecuteNonQuery(sql, null);
|
|
|
- }
|
|
|
-
|
|
|
- msg = msg + $"{fileresult.Result.Item2}\r\n";
|
|
|
- }
|
|
|
-
|
|
|
- return (1, msg);
|
|
|
- }
|
|
|
- else
|
|
|
+ if (GlobalContext.MESIsSendUpFile)
|
|
|
{
|
|
|
- return (1, "文件不存在!");
|
|
|
+ List<string> imageFiles = GetAllImageFiles(path);
|
|
|
+
|
|
|
+ string toPath = GlobalContext.MqttFileBackupLogDir;
|
|
|
+ filename = $"{xiaomiParm.workstation}_{file_type}_{sn}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
|
|
|
+ //string directoryPath = Path.GetDirectoryName(path);
|
|
|
+ string strFilePath = toPath+ "\\"+ filename;
|
|
|
+
|
|
|
+ if (imageFiles.Count > 0)
|
|
|
+ {
|
|
|
+ var r = CompressFolder(path, strFilePath);
|
|
|
+ if (r.Item1 == 0)
|
|
|
+ {
|
|
|
+ return (0, r.Item2);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ msg = r.Item2 + "\r\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return (0, "文件不存在!");
|
|
|
+ }
|
|
|
+
|
|
|
+ FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
|
|
|
+ fileUpload_X5.bucket = bucket;
|
|
|
+ fileUpload_X5.name = filename;
|
|
|
+ fileUpload_X5.uuid = guid.ToString();
|
|
|
+ ///需要上传文件
|
|
|
+ FileInfo file = new FileInfo(strFilePath);
|
|
|
+ string fileMd5Hex = GetMD5Hex(file);
|
|
|
+ fileUpload_X5.md5 = fileMd5Hex;
|
|
|
+ fileUpload_X5.uploadCloud = true;
|
|
|
+ fileUpload_X5.informMqtt = true;
|
|
|
+
|
|
|
+ FileMqttPayload fileMqttPayload = new FileMqttPayload();
|
|
|
+ fileMqttPayload.factory = GlobalContext.Factory_Code;
|
|
|
+ fileMqttPayload.project_name = GlobalContext.Project_Code;
|
|
|
+ fileMqttPayload.product_mode = GlobalContext.product_mode;
|
|
|
+ fileMqttPayload.line_no = GlobalContext.LineCode;
|
|
|
+ fileMqttPayload.work_station_no = xiaomiParm.workstation;
|
|
|
+ fileMqttPayload.equipment_no = xiaomiParm.deviceCode;
|
|
|
+ fileMqttPayload.station_no = xiaomiParm.stationCode;
|
|
|
+ fileMqttPayload.file_id = guid;
|
|
|
+ fileMqttPayload.file_name = filename;
|
|
|
+ fileMqttPayload.sn = BarcodeSet.strProductBarcode;
|
|
|
+ //fileMqttPayload.opt_time = "";
|
|
|
+ //fileMqttPayload.file_type = "";
|
|
|
+ //fileMqttPayload.file_category = "";
|
|
|
+ //fileMqttPayload.tag = "";
|
|
|
+ fileMqttPayload.reference_info.pass_station_id = uuid;
|
|
|
+
|
|
|
+ var fileresult =await
|
|
|
+ XiaomiMESHttp_UpLoadFile.FileUoladToMes(strFilePath, fileUpload_X5, fileMqttPayload);
|
|
|
+ if (fileresult.Item1 != 1)
|
|
|
+ {
|
|
|
+ return (0, msg + fileresult.Item2 + "\r\n");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ msg = msg + fileresult.Item2 + "\r\n";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ foreach (var imageFile in imageFiles) {
|
|
|
+ if (File.Exists(imageFile))
|
|
|
+ {
|
|
|
+ //删除文件
|
|
|
+ (bool, string) newResult = DeleteFile(imageFile);
|
|
|
+ if (!newResult.Item1)
|
|
|
+ {
|
|
|
+ return (0, Path.GetFileName(imageFile) + newResult.Item2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ return (1, msg);
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
- return (1,
|
|
|
- filename + $"图片保存失败!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode},错误原因:" +
|
|
|
+ return (0,
|
|
|
+ filename + $"文件上传错误!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode},错误原因:" +
|
|
|
e.Message);
|
|
|
- //AddMessage_Station(stationName, LogType.Error, filename + $"图片保存失败!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode}");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -5305,11 +5325,10 @@ namespace MainForm
|
|
|
stopwatch2.Start();
|
|
|
|
|
|
//测试数据
|
|
|
- // stPLC_MesData.mesCommFrmPLC.cmd = 1;
|
|
|
- // stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
|
|
|
- // stPLC_MesData.BarcodeSet.strPCBBarcode = "123456";
|
|
|
- // stPLC_MesData.iotData.BeatAction = 1;
|
|
|
- // stPLC_MesData.iotData.BeatAction = 2;
|
|
|
+ stPLC_MesData.mesCommFrmPLC.cmd = 2;
|
|
|
+ stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
|
|
|
+ stPLC_MesData.BarcodeSet.strPCBBarcode = "A1507V000239";
|
|
|
+ stPLC_MesData.iotData.BeatAction = 1;
|
|
|
|
|
|
#region 一次性读取所有数据
|
|
|
|