689 lines
32 KiB
C#
689 lines
32 KiB
C#
using MesWork;
|
||
using Newtonsoft.Json;
|
||
using Opc.Ua;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Data.SqlClient;
|
||
using System.Drawing;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Net;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
|
||
namespace CCYQ_JieFang
|
||
{
|
||
public partial class AgvTest : Form
|
||
{
|
||
string currentOpName;
|
||
public AgvTest(string opName)
|
||
{
|
||
currentOpName = opName;
|
||
InitializeComponent();
|
||
InitPartInfo();
|
||
}
|
||
|
||
private void InitPartInfo()
|
||
{
|
||
if(publicCore.partCount == 1)
|
||
{
|
||
checkBox1_position1.Visible = true;
|
||
checkBox2_position2.Visible = false;
|
||
checkBox3_position3.Visible = false;
|
||
checkBox4_position4.Visible = false;
|
||
}
|
||
else if(publicCore.partCount == 2)
|
||
{
|
||
checkBox1_position1.Visible = true;
|
||
checkBox2_position2.Visible = true;
|
||
checkBox3_position3.Visible = false;
|
||
checkBox4_position4.Visible = false;
|
||
}
|
||
else if(publicCore.partCount == 3)
|
||
{
|
||
checkBox1_position1.Visible = true;
|
||
checkBox2_position2.Visible = true;
|
||
checkBox3_position3.Visible = true;
|
||
checkBox4_position4.Visible = false;
|
||
}
|
||
else if(publicCore.partCount == 4)
|
||
{
|
||
checkBox1_position1.Visible = true;
|
||
checkBox2_position2.Visible = true;
|
||
checkBox3_position3.Visible = true;
|
||
checkBox4_position4.Visible = true;
|
||
}
|
||
|
||
|
||
}
|
||
|
||
private void button1_Click(object sender, EventArgs e)
|
||
{
|
||
label1.Text = "正在发送请求,请稍后...";
|
||
publicCore.LogInsert("IPC_product", "Info", "正在发送请求,请稍后...");
|
||
try
|
||
{
|
||
IPC_product iPC_product = new IPC_product();
|
||
iPC_product.MsgId = AnalysisMsg.UuidUtil();
|
||
iPC_product.Location = currentOpName;
|
||
iPC_product.MsgSource = 2;
|
||
iPC_product.SendTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||
iPC_product.AssemblyInformation = SolveProductCount();
|
||
|
||
//准备上传的数据 反序列化
|
||
string bodydata = JsonConvert.SerializeObject(iPC_product);
|
||
|
||
publicCore.LogInsert(currentOpName, "Info", bodydata);
|
||
|
||
string urlstr = MesWorkForm.IPC_product;
|
||
string retString;
|
||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlstr);
|
||
request.Method = "post";
|
||
byte[] bytes = Encoding.UTF8.GetBytes(bodydata);
|
||
request.Accept = "*/*";
|
||
request.ContentType = "application/json;charset=utf-8";
|
||
|
||
// 反序列化后先把JSON做接口记录
|
||
//存储日志
|
||
int AID = -1;
|
||
var CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||
//Event_MOM_Log_Insert,@创建时间,@内容
|
||
var reqParam = new SqlParameter[] {
|
||
new SqlParameter("@接口地址",urlstr),
|
||
new SqlParameter("@接口类型",1), // 1. 主动调用接口 2. 被调用接口
|
||
new SqlParameter("@请求内容",bodydata),
|
||
new SqlParameter("@请求时间",CreateTime)
|
||
};
|
||
DataLinkMesWork.SQLCommon.ExecuteStoredProcedure("接口_IOT接口交互日志_请求记录", MesWorkForm.ConnectionString, ref reqParam, out DataTable reqDt, out string errorMessage);
|
||
if (reqDt.Rows.Count > 0)
|
||
{
|
||
AID = Convert.ToInt32(reqDt.Rows[0]["AID"]);
|
||
}
|
||
|
||
request.ContentLength = bytes.Length;
|
||
|
||
// 准备请求体
|
||
Stream myResponseStream = request.GetRequestStream();
|
||
myResponseStream.Write(bytes, 0, bytes.Length);
|
||
//发送webapi请求 等待相应
|
||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||
StreamReader myStreamReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
|
||
retString = myStreamReader.ReadToEnd();
|
||
|
||
//响应结果
|
||
CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||
var resParam = new SqlParameter[] {
|
||
new SqlParameter("@AID",AID),
|
||
new SqlParameter("@响应时间",CreateTime),
|
||
new SqlParameter("@响应内容",retString)
|
||
};
|
||
DataLinkMesWork.SQLCommon.ExecuteStoredProcedure("接口_IOT接口交互日志_响应记录", MesWorkForm.ConnectionString, ref resParam, out errorMessage);
|
||
|
||
// 序列化响应内容
|
||
msgResHeader mrh = JsonConvert.DeserializeObject<msgResHeader>(retString);
|
||
int statusCode = (int)response.StatusCode;
|
||
// 对响应内容进行处理 更新数据库标志
|
||
if (statusCode == 200)
|
||
{
|
||
myStreamReader.Close();
|
||
myResponseStream.Close();
|
||
label1.Text = "请求发送成功!详细信息查看日志";
|
||
publicCore.LogInsert("IPC_product", "Info", "请求发送成功!详细信息查看日志");
|
||
|
||
if (response != null)
|
||
{
|
||
// 失败
|
||
if (mrh.Code != "200")
|
||
{
|
||
publicCore.LogInsert(currentOpName, "Error", "接口【IPC-接收装配信息】失败!" + mrh.Message);
|
||
}
|
||
response.Close();
|
||
}
|
||
if (request != null)
|
||
{
|
||
request.Abort();
|
||
}
|
||
publicCore.LogInsert(currentOpName, "Info", retString);
|
||
}
|
||
else
|
||
{
|
||
label1.Text = "正在发送请求,请稍后...";
|
||
publicCore.LogInsert("IPC_product", "Error", "接口【IPC-接收装配信息】失败!" + statusCode);
|
||
}
|
||
}
|
||
catch (Exception err)
|
||
{
|
||
publicCore.LogInsert("IPC_product", "Error", "接口【IPC-接收装配信息】失败!" + err.Message);
|
||
}
|
||
|
||
}
|
||
|
||
private void button2_Click(object sender, EventArgs e)
|
||
{
|
||
label2.Text = "正在发送请求,请稍后...";
|
||
publicCore.LogInsert("IPC_RequestEnterOrLeave_Enter", "Info", "正在发送请求,请稍后...");
|
||
try
|
||
{
|
||
IPC_RequestEnterOrLeave iPC_RequestEnterOrLeave = new IPC_RequestEnterOrLeave();
|
||
iPC_RequestEnterOrLeave.MsgId = AnalysisMsg.UuidUtil();
|
||
iPC_RequestEnterOrLeave.Location = currentOpName;
|
||
iPC_RequestEnterOrLeave.MsgSource = 2;
|
||
iPC_RequestEnterOrLeave.RequestType = 1;
|
||
iPC_RequestEnterOrLeave.SendTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||
|
||
//准备上传的数据 反序列化
|
||
string bodydata = JsonConvert.SerializeObject(iPC_RequestEnterOrLeave);
|
||
|
||
publicCore.LogInsert("IPC_RequestEnterOrLeave_Enter", "Info", bodydata);
|
||
|
||
string urlstr = MesWorkForm.IPC_RequestEnterOrLeave;
|
||
string retString;
|
||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlstr);
|
||
request.Method = "post";
|
||
byte[] bytes = Encoding.UTF8.GetBytes(bodydata);
|
||
request.Accept = "*/*";
|
||
request.ContentType = "application/json;charset=utf-8";
|
||
|
||
// 反序列化后先把JSON做接口记录
|
||
//存储日志
|
||
int AID = -1;
|
||
var CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||
//Event_MOM_Log_Insert,@创建时间,@内容
|
||
var reqParam = new SqlParameter[] {
|
||
new SqlParameter("@接口地址",urlstr),
|
||
new SqlParameter("@接口类型",1), // 1. 主动调用接口 2. 被调用接口
|
||
new SqlParameter("@请求内容",bodydata),
|
||
new SqlParameter("@请求时间",CreateTime)
|
||
};
|
||
DataLinkMesWork.SQLCommon.ExecuteStoredProcedure("接口_IOT接口交互日志_请求记录", MesWorkForm.ConnectionString, ref reqParam, out DataTable reqDt, out string errorMessage);
|
||
if (reqDt.Rows.Count > 0)
|
||
{
|
||
AID = Convert.ToInt32(reqDt.Rows[0]["AID"]);
|
||
}
|
||
|
||
request.ContentLength = bytes.Length;
|
||
|
||
// 准备请求体
|
||
Stream myResponseStream = request.GetRequestStream();
|
||
myResponseStream.Write(bytes, 0, bytes.Length);
|
||
//发送webapi请求 等待相应
|
||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||
StreamReader myStreamReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
|
||
retString = myStreamReader.ReadToEnd();
|
||
|
||
//响应结果
|
||
CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||
var resParam = new SqlParameter[] {
|
||
new SqlParameter("@AID",AID),
|
||
new SqlParameter("@响应时间",CreateTime),
|
||
new SqlParameter("@响应内容",retString)
|
||
};
|
||
DataLinkMesWork.SQLCommon.ExecuteStoredProcedure("接口_IOT接口交互日志_响应记录", MesWorkForm.ConnectionString, ref resParam, out errorMessage);
|
||
|
||
// 序列化响应内容
|
||
msgResHeader mrh = JsonConvert.DeserializeObject<msgResHeader>(retString);
|
||
int statusCode = (int)response.StatusCode;
|
||
// 对响应内容进行处理 更新数据库标志
|
||
if (statusCode == 200)
|
||
{
|
||
myStreamReader.Close();
|
||
myResponseStream.Close();
|
||
label2.Text = "请求发送成功!详细信息查看日志";
|
||
publicCore.LogInsert("IPC_RequestEnterOrLeave_Enter", "Info", "请求发送成功!详细信息查看日志");
|
||
|
||
if (response != null)
|
||
{
|
||
// 失败
|
||
if (mrh.Code != "200")
|
||
{
|
||
publicCore.LogInsert("IPC_RequestEnterOrLeave_Enter", "Error", "接口【IPC-AGV请求进入/离开】失败!" + mrh.Message);
|
||
}
|
||
response.Close();
|
||
}
|
||
if (request != null)
|
||
{
|
||
request.Abort();
|
||
}
|
||
publicCore.LogInsert("IPC_RequestEnterOrLeave_Enter", "Info", retString);
|
||
}
|
||
else
|
||
{
|
||
label2.Text = "正在发送请求,请稍后...";
|
||
publicCore.LogInsert("IPC_RequestEnterOrLeave_Enter", "Error", "接口【IPC-AGV请求进入/离开】失败!" + statusCode);
|
||
}
|
||
}
|
||
catch (Exception err)
|
||
{
|
||
publicCore.LogInsert(currentOpName, "Error", "接口【IPC-接收装配信息】失败!" + err.Message);
|
||
}
|
||
}
|
||
|
||
private void button3_Click(object sender, EventArgs e)
|
||
{
|
||
label3.Text = "正在发送请求,请稍后...";
|
||
publicCore.LogInsert("IPC_RequestEnterOrLeave_Leave", "Info", "正在发送请求,请稍后...");
|
||
try
|
||
{
|
||
IPC_RequestEnterOrLeave iPC_RequestEnterOrLeave = new IPC_RequestEnterOrLeave();
|
||
iPC_RequestEnterOrLeave.MsgId = AnalysisMsg.UuidUtil();
|
||
iPC_RequestEnterOrLeave.Location = currentOpName;
|
||
iPC_RequestEnterOrLeave.MsgSource = 2;
|
||
iPC_RequestEnterOrLeave.RequestType = 2;
|
||
iPC_RequestEnterOrLeave.SendTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||
|
||
//准备上传的数据 反序列化
|
||
string bodydata = JsonConvert.SerializeObject(iPC_RequestEnterOrLeave);
|
||
|
||
publicCore.LogInsert("IPC_RequestEnterOrLeave_Leave", "Info", bodydata);
|
||
|
||
string urlstr = MesWorkForm.IPC_RequestEnterOrLeave;
|
||
string retString;
|
||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlstr);
|
||
request.Method = "post";
|
||
byte[] bytes = Encoding.UTF8.GetBytes(bodydata);
|
||
request.Accept = "*/*";
|
||
request.ContentType = "application/json;charset=utf-8";
|
||
|
||
// 反序列化后先把JSON做接口记录
|
||
//存储日志
|
||
int AID = -1;
|
||
var CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||
//Event_MOM_Log_Insert,@创建时间,@内容
|
||
var reqParam = new SqlParameter[] {
|
||
new SqlParameter("@接口地址",urlstr),
|
||
new SqlParameter("@接口类型",1), // 1. 主动调用接口 2. 被调用接口
|
||
new SqlParameter("@请求内容",bodydata),
|
||
new SqlParameter("@请求时间",CreateTime)
|
||
};
|
||
DataLinkMesWork.SQLCommon.ExecuteStoredProcedure("接口_IOT接口交互日志_请求记录", MesWorkForm.ConnectionString, ref reqParam, out DataTable reqDt, out string errorMessage);
|
||
if (reqDt.Rows.Count > 0)
|
||
{
|
||
AID = Convert.ToInt32(reqDt.Rows[0]["AID"]);
|
||
}
|
||
|
||
request.ContentLength = bytes.Length;
|
||
|
||
// 准备请求体
|
||
Stream myResponseStream = request.GetRequestStream();
|
||
myResponseStream.Write(bytes, 0, bytes.Length);
|
||
//发送webapi请求 等待相应
|
||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||
StreamReader myStreamReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
|
||
retString = myStreamReader.ReadToEnd();
|
||
|
||
//响应结果
|
||
CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||
var resParam = new SqlParameter[] {
|
||
new SqlParameter("@AID",AID),
|
||
new SqlParameter("@响应时间",CreateTime),
|
||
new SqlParameter("@响应内容",retString)
|
||
};
|
||
DataLinkMesWork.SQLCommon.ExecuteStoredProcedure("接口_IOT接口交互日志_响应记录", MesWorkForm.ConnectionString, ref resParam, out errorMessage);
|
||
|
||
// 序列化响应内容
|
||
msgResHeader mrh = JsonConvert.DeserializeObject<msgResHeader>(retString);
|
||
int statusCode = (int)response.StatusCode;
|
||
// 对响应内容进行处理 更新数据库标志
|
||
if (statusCode == 200)
|
||
{
|
||
myStreamReader.Close();
|
||
myResponseStream.Close();
|
||
label3.Text = "请求发送成功!详细信息查看日志";
|
||
publicCore.LogInsert("IPC_RequestEnterOrLeave_Leave", "Info", "请求发送成功!详细信息查看日志");
|
||
|
||
if (response != null)
|
||
{
|
||
// 失败
|
||
if (mrh.Code != "200")
|
||
{
|
||
publicCore.LogInsert("IPC_RequestEnterOrLeave_Leave", "Error", "接口【IPC-AGV请求进入/离开】失败!" + mrh.Message);
|
||
}
|
||
response.Close();
|
||
}
|
||
if (request != null)
|
||
{
|
||
request.Abort();
|
||
}
|
||
publicCore.LogInsert("IPC_RequestEnterOrLeave_Leave", "Info", retString);
|
||
}
|
||
else
|
||
{
|
||
label3.Text = "正在发送请求,请稍后...";
|
||
publicCore.LogInsert("IPC_RequestEnterOrLeave_Leave", "Error", "接口【IPC-AGV请求进入/离开】失败!" + statusCode);
|
||
}
|
||
}
|
||
catch (Exception err)
|
||
{
|
||
publicCore.LogInsert("IPC_RequestEnterOrLeave_Leave", "Error", "接口【IPC-AGV请求进入/离开】失败!" + err.Message);
|
||
}
|
||
}
|
||
|
||
private void button4_Click(object sender, EventArgs e)
|
||
{
|
||
label4.Text = "正在发送请求,请稍后...";
|
||
publicCore.LogInsert("IPC_WorkFinsih_Up", "Info", "正在发送请求,请稍后...");
|
||
try
|
||
{
|
||
IPC_WorkFinsih iPC_WorkFinsih = new IPC_WorkFinsih();
|
||
iPC_WorkFinsih.MsgId = AnalysisMsg.UuidUtil();
|
||
iPC_WorkFinsih.Location = currentOpName;
|
||
iPC_WorkFinsih.MsgSource = 2;
|
||
iPC_WorkFinsih.FinishType = 1;
|
||
iPC_WorkFinsih.SendTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||
|
||
//准备上传的数据 反序列化
|
||
string bodydata = JsonConvert.SerializeObject(iPC_WorkFinsih);
|
||
|
||
publicCore.LogInsert("IPC_WorkFinsih_Up", "Info", bodydata);
|
||
|
||
string urlstr = MesWorkForm.IPC_WorkFinsih;
|
||
string retString;
|
||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlstr);
|
||
request.Method = "post";
|
||
byte[] bytes = Encoding.UTF8.GetBytes(bodydata);
|
||
request.Accept = "*/*";
|
||
request.ContentType = "application/json;charset=utf-8";
|
||
|
||
// 反序列化后先把JSON做接口记录
|
||
//存储日志
|
||
int AID = -1;
|
||
var CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||
//Event_MOM_Log_Insert,@创建时间,@内容
|
||
var reqParam = new SqlParameter[] {
|
||
new SqlParameter("@接口地址",urlstr),
|
||
new SqlParameter("@接口类型",1), // 1. 主动调用接口 2. 被调用接口
|
||
new SqlParameter("@请求内容",bodydata),
|
||
new SqlParameter("@请求时间",CreateTime)
|
||
};
|
||
DataLinkMesWork.SQLCommon.ExecuteStoredProcedure("接口_IOT接口交互日志_请求记录", MesWorkForm.ConnectionString, ref reqParam, out DataTable reqDt, out string errorMessage);
|
||
if (reqDt.Rows.Count > 0)
|
||
{
|
||
AID = Convert.ToInt32(reqDt.Rows[0]["AID"]);
|
||
}
|
||
|
||
request.ContentLength = bytes.Length;
|
||
|
||
// 准备请求体
|
||
Stream myResponseStream = request.GetRequestStream();
|
||
myResponseStream.Write(bytes, 0, bytes.Length);
|
||
//发送webapi请求 等待相应
|
||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||
StreamReader myStreamReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
|
||
retString = myStreamReader.ReadToEnd();
|
||
|
||
//响应结果
|
||
CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||
var resParam = new SqlParameter[] {
|
||
new SqlParameter("@AID",AID),
|
||
new SqlParameter("@响应时间",CreateTime),
|
||
new SqlParameter("@响应内容",retString)
|
||
};
|
||
DataLinkMesWork.SQLCommon.ExecuteStoredProcedure("接口_IOT接口交互日志_响应记录", MesWorkForm.ConnectionString, ref resParam, out errorMessage);
|
||
|
||
// 序列化响应内容
|
||
msgResHeader mrh = JsonConvert.DeserializeObject<msgResHeader>(retString);
|
||
int statusCode = (int)response.StatusCode;
|
||
// 对响应内容进行处理 更新数据库标志
|
||
if (statusCode == 200)
|
||
{
|
||
myStreamReader.Close();
|
||
myResponseStream.Close();
|
||
label4.Text = "请求发送成功!详细信息查看日志";
|
||
publicCore.LogInsert("IPC_WorkFinsih_Up", "Info", "请求发送成功!详细信息查看日志");
|
||
|
||
if (response != null)
|
||
{
|
||
// 失败
|
||
if (mrh.Code != "200")
|
||
{
|
||
publicCore.LogInsert("IPC_WorkFinsih_Up", "Error", "接口【IPC-AGV上料完成离开】失败!" + mrh.Message);
|
||
}
|
||
response.Close();
|
||
}
|
||
if (request != null)
|
||
{
|
||
request.Abort();
|
||
}
|
||
publicCore.LogInsert("IPC_WorkFinsih_Up", "Info", retString);
|
||
}
|
||
else
|
||
{
|
||
label4.Text = "正在发送请求,请稍后...";
|
||
publicCore.LogInsert("IPC_WorkFinsih_Up", "Error", "接口【IPC-AGV上料完成离开】失败!" + statusCode);
|
||
}
|
||
}
|
||
catch (Exception err)
|
||
{
|
||
publicCore.LogInsert("IPC_WorkFinsih_Up", "Error", "接口【IPC-AGV上料完成离开】失败!" + err.Message);
|
||
}
|
||
}
|
||
|
||
private void button5_Click(object sender, EventArgs e)
|
||
{
|
||
label5.Text = "正在发送请求,请稍后...";
|
||
publicCore.LogInsert("IPC_WorkFinsih_Down", "Info", "正在发送请求,请稍后...");
|
||
try
|
||
{
|
||
IPC_WorkFinsih iPC_WorkFinsih = new IPC_WorkFinsih();
|
||
iPC_WorkFinsih.MsgId = AnalysisMsg.UuidUtil();
|
||
iPC_WorkFinsih.Location = currentOpName;
|
||
iPC_WorkFinsih.MsgSource = 2;
|
||
iPC_WorkFinsih.FinishType = 2;
|
||
iPC_WorkFinsih.SendTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||
|
||
//准备上传的数据 反序列化
|
||
string bodydata = JsonConvert.SerializeObject(iPC_WorkFinsih);
|
||
|
||
publicCore.LogInsert("IPC_WorkFinsih_Down", "Info", bodydata);
|
||
|
||
string urlstr = MesWorkForm.IPC_WorkFinsih;
|
||
string retString;
|
||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlstr);
|
||
request.Method = "post";
|
||
byte[] bytes = Encoding.UTF8.GetBytes(bodydata);
|
||
request.Accept = "*/*";
|
||
request.ContentType = "application/json;charset=utf-8";
|
||
|
||
// 反序列化后先把JSON做接口记录
|
||
//存储日志
|
||
int AID = -1;
|
||
var CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||
//Event_MOM_Log_Insert,@创建时间,@内容
|
||
var reqParam = new SqlParameter[] {
|
||
new SqlParameter("@接口地址",urlstr),
|
||
new SqlParameter("@接口类型",1), // 1. 主动调用接口 2. 被调用接口
|
||
new SqlParameter("@请求内容",bodydata),
|
||
new SqlParameter("@请求时间",CreateTime)
|
||
};
|
||
DataLinkMesWork.SQLCommon.ExecuteStoredProcedure("接口_IOT接口交互日志_请求记录", MesWorkForm.ConnectionString, ref reqParam, out DataTable reqDt, out string errorMessage);
|
||
if (reqDt.Rows.Count > 0)
|
||
{
|
||
AID = Convert.ToInt32(reqDt.Rows[0]["AID"]);
|
||
}
|
||
|
||
request.ContentLength = bytes.Length;
|
||
|
||
// 准备请求体
|
||
Stream myResponseStream = request.GetRequestStream();
|
||
myResponseStream.Write(bytes, 0, bytes.Length);
|
||
//发送webapi请求 等待相应
|
||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||
StreamReader myStreamReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
|
||
retString = myStreamReader.ReadToEnd();
|
||
|
||
//响应结果
|
||
CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||
var resParam = new SqlParameter[] {
|
||
new SqlParameter("@AID",AID),
|
||
new SqlParameter("@响应时间",CreateTime),
|
||
new SqlParameter("@响应内容",retString)
|
||
};
|
||
DataLinkMesWork.SQLCommon.ExecuteStoredProcedure("接口_IOT接口交互日志_响应记录", MesWorkForm.ConnectionString, ref resParam, out errorMessage);
|
||
|
||
// 序列化响应内容
|
||
msgResHeader mrh = JsonConvert.DeserializeObject<msgResHeader>(retString);
|
||
int statusCode = (int)response.StatusCode;
|
||
// 对响应内容进行处理 更新数据库标志
|
||
if (statusCode == 200)
|
||
{
|
||
myStreamReader.Close();
|
||
myResponseStream.Close();
|
||
label5.Text = "请求发送成功!详细信息查看日志";
|
||
publicCore.LogInsert("IPC_WorkFinsih_Down", "Info", "请求发送成功!详细信息查看日志");
|
||
|
||
if (response != null)
|
||
{
|
||
// 失败
|
||
if (mrh.Code != "200")
|
||
{
|
||
publicCore.LogInsert("IPC_WorkFinsih_Down", "Error", "接口【IPC-AGV上料完成离开】失败!" + mrh.Message);
|
||
}
|
||
response.Close();
|
||
}
|
||
if (request != null)
|
||
{
|
||
request.Abort();
|
||
}
|
||
publicCore.LogInsert("IPC_WorkFinsih_Down", "Info", retString);
|
||
}
|
||
else
|
||
{
|
||
label4.Text = "正在发送请求,请稍后...";
|
||
publicCore.LogInsert("IPC_WorkFinsih_Down", "Error", "接口【IPC-AGV上料完成离开】失败!" + statusCode);
|
||
}
|
||
}
|
||
catch (Exception err)
|
||
{
|
||
publicCore.LogInsert("IPC_WorkFinsih_Down", "Error", "接口【IPC-AGV上料完成离开】失败!" + err.Message);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
private List<IPC_product_AssemblyInformation> SolveProductCount()
|
||
{
|
||
List<IPC_product_AssemblyInformation> AssemblyInformation = new List<IPC_product_AssemblyInformation>();
|
||
string currentTime = DateTime.Now.ToString("yyyyMMddHHmmss");
|
||
if (publicCore.partCount == 1)
|
||
{
|
||
if(checkBox1_position1.Checked)
|
||
{
|
||
IPC_product_AssemblyInformation product_AssemblyInformation1 = new IPC_product_AssemblyInformation();
|
||
product_AssemblyInformation1.productPosition = 1;
|
||
product_AssemblyInformation1.productNo = currentTime + "_part1";
|
||
product_AssemblyInformation1.productName = "装配件01";
|
||
AssemblyInformation.Add(product_AssemblyInformation1);
|
||
}
|
||
|
||
|
||
}
|
||
else if (publicCore.partCount == 2)
|
||
{
|
||
if (checkBox1_position1.Checked)
|
||
{
|
||
IPC_product_AssemblyInformation product_AssemblyInformation1 = new IPC_product_AssemblyInformation();
|
||
product_AssemblyInformation1.productPosition = 1;
|
||
product_AssemblyInformation1.productNo = currentTime + "_part1";
|
||
product_AssemblyInformation1.productName = "装配件01";
|
||
AssemblyInformation.Add(product_AssemblyInformation1);
|
||
}
|
||
if (checkBox2_position2.Checked)
|
||
{
|
||
IPC_product_AssemblyInformation product_AssemblyInformation2 = new IPC_product_AssemblyInformation();
|
||
product_AssemblyInformation2.productPosition = 2;
|
||
product_AssemblyInformation2.productNo = currentTime + "_part2";
|
||
product_AssemblyInformation2.productName = "装配件02";
|
||
AssemblyInformation.Add(product_AssemblyInformation2);
|
||
}
|
||
|
||
}
|
||
else if (publicCore.partCount == 3)
|
||
{
|
||
if (checkBox1_position1.Checked)
|
||
{
|
||
IPC_product_AssemblyInformation product_AssemblyInformation1 = new IPC_product_AssemblyInformation();
|
||
product_AssemblyInformation1.productPosition = 1;
|
||
product_AssemblyInformation1.productNo = currentTime + "_part1";
|
||
product_AssemblyInformation1.productName = "装配件01";
|
||
AssemblyInformation.Add(product_AssemblyInformation1);
|
||
}
|
||
if (checkBox2_position2.Checked)
|
||
{
|
||
IPC_product_AssemblyInformation product_AssemblyInformation2 = new IPC_product_AssemblyInformation();
|
||
product_AssemblyInformation2.productPosition = 2;
|
||
product_AssemblyInformation2.productNo = currentTime + "_part2";
|
||
product_AssemblyInformation2.productName = "装配件02";
|
||
AssemblyInformation.Add(product_AssemblyInformation2);
|
||
}
|
||
if (checkBox3_position3.Checked)
|
||
{
|
||
IPC_product_AssemblyInformation product_AssemblyInformation3 = new IPC_product_AssemblyInformation();
|
||
product_AssemblyInformation3.productPosition = 3;
|
||
product_AssemblyInformation3.productNo = currentTime + "_part3";
|
||
product_AssemblyInformation3.productName = "装配件03";
|
||
AssemblyInformation.Add(product_AssemblyInformation3);
|
||
}
|
||
}
|
||
else if (publicCore.partCount == 4)
|
||
{
|
||
if (checkBox1_position1.Checked)
|
||
{
|
||
IPC_product_AssemblyInformation product_AssemblyInformation1 = new IPC_product_AssemblyInformation();
|
||
product_AssemblyInformation1.productPosition = 1;
|
||
product_AssemblyInformation1.productNo = currentTime + "_part1";
|
||
product_AssemblyInformation1.productName = "装配件01";
|
||
AssemblyInformation.Add(product_AssemblyInformation1);
|
||
}
|
||
if (checkBox2_position2.Checked)
|
||
{
|
||
IPC_product_AssemblyInformation product_AssemblyInformation2 = new IPC_product_AssemblyInformation();
|
||
product_AssemblyInformation2.productPosition = 2;
|
||
product_AssemblyInformation2.productNo = currentTime + "_part2";
|
||
product_AssemblyInformation2.productName = "装配件02";
|
||
AssemblyInformation.Add(product_AssemblyInformation2);
|
||
}
|
||
if (checkBox3_position3.Checked)
|
||
{
|
||
IPC_product_AssemblyInformation product_AssemblyInformation3 = new IPC_product_AssemblyInformation();
|
||
product_AssemblyInformation3.productPosition = 3;
|
||
product_AssemblyInformation3.productNo = currentTime + "_part3";
|
||
product_AssemblyInformation3.productName = "装配件03";
|
||
AssemblyInformation.Add(product_AssemblyInformation3);
|
||
}
|
||
if (checkBox4_position4.Checked)
|
||
{
|
||
IPC_product_AssemblyInformation product_AssemblyInformation4 = new IPC_product_AssemblyInformation();
|
||
product_AssemblyInformation4.productPosition = 4;
|
||
product_AssemblyInformation4.productNo = currentTime + "_part4";
|
||
product_AssemblyInformation4.productName = "装配件04";
|
||
AssemblyInformation.Add(product_AssemblyInformation4);
|
||
}
|
||
}
|
||
return AssemblyInformation;
|
||
}
|
||
|
||
private void checkBox1_position1_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
SolveProductCount();
|
||
}
|
||
|
||
private void checkBox2_position2_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
SolveProductCount();
|
||
}
|
||
|
||
private void checkBox3_position3_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
SolveProductCount();
|
||
}
|
||
|
||
private void checkBox4_position4_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
SolveProductCount();
|
||
}
|
||
}
|
||
}
|