|
@@ -37,6 +37,9 @@ using System.Web.Services.Description;
|
|
|
using System.Numerics;
|
|
|
using MathNet.Numerics.RootFinding;
|
|
|
using System.Net.Http;
|
|
|
+using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_UpLoadFile;
|
|
|
+using MathNet.Numerics.Statistics;
|
|
|
+using System.Runtime.Remoting.Contexts;
|
|
|
|
|
|
/*
|
|
|
* 注:本源码对外提供,所以有些地方使用中文命名方法及变量
|
|
@@ -1332,6 +1335,8 @@ namespace MainForm
|
|
|
string leftPath = path + "\\Left";
|
|
|
string rightPath = path + "\\Right";
|
|
|
string sql = "";
|
|
|
+ Guid guid;
|
|
|
+ int result = 0;
|
|
|
var formData = new MultipartFormDataContent();
|
|
|
|
|
|
// 获取所有图片文件
|
|
@@ -1341,6 +1346,7 @@ namespace MainForm
|
|
|
{
|
|
|
foreach (string imageFile in imageFiles_L)
|
|
|
{
|
|
|
+ guid = Guid.NewGuid();
|
|
|
//formData = MultipartbyFile(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}')"
|
|
@@ -1351,13 +1357,14 @@ namespace MainForm
|
|
|
, "/mesCommToPC/pic/left"
|
|
|
, Path.GetFileName(imageFile)
|
|
|
, ""
|
|
|
- , ""
|
|
|
+ , guid.ToString()
|
|
|
, ""
|
|
|
, 0
|
|
|
, ""
|
|
|
, DateTime.Now
|
|
|
);
|
|
|
string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
|
|
|
+ sendPostFile(path, Path.GetFileName(imageFile), guid.ToString(), "");
|
|
|
}
|
|
|
foreach (string imageFile in imageFiles_R)
|
|
|
{
|
|
@@ -1378,13 +1385,14 @@ namespace MainForm
|
|
|
, DateTime.Now
|
|
|
);
|
|
|
string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
|
|
|
+ result = ret == "成功" ? 1 : 6;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
AddMessage_Station(stationName, LogType.Error, $"图片保存失败!载具码:{stPLC_MesData.BarcodeSet.strCarrierBarcode}产品码{stPLC_MesData.BarcodeSet.strProductBarcode}");
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -1432,6 +1440,69 @@ namespace MainForm
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public int sendPostFile(string bucket, string filename,string guid, string context)
|
|
|
+ {
|
|
|
+ int result = 0;
|
|
|
+
|
|
|
+ XmMES_UpFile_Request_Body inRequest_Body = new XmMES_UpFile_Request_Body();
|
|
|
+ inRequest_Body.bucket = bucket;
|
|
|
+ inRequest_Body.name = filename;
|
|
|
+ inRequest_Body.uuid = guid;
|
|
|
+ inRequest_Body.file = context;
|
|
|
+
|
|
|
+ string json_Body = JsonConvert.SerializeObject(inRequest_Body);
|
|
|
+ //await Task.Delay(200);
|
|
|
+ // 上传MES
|
|
|
+ if (GlobalContext.IsSendStationIn)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ XmMES_UpFile_Response response = new XmMES_UpFile_Response();
|
|
|
+ string mesRet = string.Empty;
|
|
|
+ int i = 0;
|
|
|
+ while (i < 2) // 1009会多次尝试上传
|
|
|
+ {
|
|
|
+ response = XiaomiMESHttp_UpLoadFile.UpFilePost(inRequest_Body);
|
|
|
+ if (response != null && response.header.code == "200")
|
|
|
+ break;
|
|
|
+ else if (!mesRet.Contains("1009")) // 1009是未知错误
|
|
|
+ i++;
|
|
|
+
|
|
|
+ i++;
|
|
|
+
|
|
|
+ mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
|
|
|
+ // 记录失败原因
|
|
|
+ OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + json_Body);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (response?.header?.code == "200")
|
|
|
+ {
|
|
|
+ //string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
|
|
|
+ //string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
|
|
|
+ //result = ret_Upd == "成功" ? 1 : 6;
|
|
|
+ //AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ result = 5;
|
|
|
+ //AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
|
|
|
+ }
|
|
|
+ //string sql_response = stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
|
|
|
+ //SQLHelper_New.ExecuteNonQuery(sql_response, null);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ result = 6;
|
|
|
+ string str = ex.StackTrace;
|
|
|
+ //AddMessage_Station(stationNameStr, LogType.Error, $"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
//private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
|
|
|
//{
|
|
|
// Stopwatch stopwatch = new Stopwatch();
|