179 lines
5.5 KiB
C#
179 lines
5.5 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.IO.Ports;
|
||
using System.Linq;
|
||
using System.Reflection;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using WindowsFormsApp1.db;
|
||
using WindowsFormsApp1.mod;
|
||
using WindowsFormsApp1.mod.database;
|
||
using WindowsFormsApp1.mod.server;
|
||
using WindowsFormsApp1.server;
|
||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||
|
||
namespace WindowsFormsApp1
|
||
{
|
||
public partial class ScanForm_SSQ : Form
|
||
{
|
||
// 自定义属性,用于存储返回值
|
||
/// <summary>
|
||
/// 0代表无位置
|
||
/// </summary>
|
||
int index = 0;
|
||
public string ReturnValue { get; set; }
|
||
public ApiClient ApiClient = new ApiClient();
|
||
public ScanForm_SSQ()
|
||
{
|
||
InitializeComponent();
|
||
Init.ScanPort.DataReceived += SerialPort_DataReceived_SSQ;
|
||
LOt号.Visible = false;
|
||
}
|
||
private void button1_Click(object sender, EventArgs e)
|
||
{
|
||
if (string.IsNullOrWhiteSpace(ReturnValue))
|
||
{
|
||
MessageBox.Show("扫码为空,请确认!");
|
||
return;
|
||
}
|
||
LogExecute.logNet.WriteDebug($"{ReturnValue}上线点击");
|
||
//this.Close();
|
||
//请求后端接口,index代表位置
|
||
var PlcData = new plcdata();
|
||
var OtherData = new otherdata();
|
||
OtherData.locationindex = index;
|
||
OtherData.opindex = 1;
|
||
OtherData.JS_SN = ReturnValue;
|
||
|
||
var result = ApiClient.CallFunctionByName("Glue_CheckOut", PlcData, OtherData);
|
||
if (result.Success && result.Mesresult == mesresult.PASS)
|
||
{
|
||
this.Close();
|
||
}
|
||
else
|
||
{
|
||
//失败逻辑
|
||
}
|
||
//更新下数据库和init里面的keyvalue值,缓存
|
||
}
|
||
|
||
private void button2_Click(object sender, EventArgs e)
|
||
{
|
||
if (string.IsNullOrWhiteSpace(ReturnValue))
|
||
{
|
||
MessageBox.Show("扫码为空,请确认!");
|
||
return;
|
||
}
|
||
LogExecute.logNet.WriteDebug($"{ReturnValue}下线点击");
|
||
this.Close();
|
||
//请求后端接口,index代表位置
|
||
var PlcData = new plcdata();
|
||
var OtherData = new otherdata();
|
||
OtherData.locationindex = index;
|
||
OtherData.opindex = 1;
|
||
OtherData.JS_SN = ReturnValue;
|
||
|
||
var result = ApiClient.CallFunctionByName("Glue_CheckOut", PlcData, OtherData);
|
||
if (result.Success)
|
||
{
|
||
this.Close();
|
||
}
|
||
else
|
||
{
|
||
//失败逻辑
|
||
}
|
||
//更新下数据库和init里面的keyvalue值,删除缓存
|
||
}
|
||
|
||
private void timer1_Tick(object sender, EventArgs e)
|
||
{
|
||
if (请扫描条码.ForeColor == Color.Red)
|
||
{
|
||
请扫描条码.ForeColor = Color.RosyBrown;
|
||
}
|
||
else
|
||
{
|
||
请扫描条码.ForeColor = Color.Red;
|
||
}
|
||
}
|
||
|
||
public void SerialPort_DataReceived_SSQ(object sender, SerialDataReceivedEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (!Init.ScanPort.IsOpen)
|
||
{
|
||
Init.ScanPort?.Open();
|
||
}
|
||
// 读取串口接收到的数据
|
||
var dataBuilder = new StringBuilder();
|
||
while(Init.ScanPort.BytesToRead > 0)
|
||
{
|
||
System.Threading.Thread.Sleep(100);
|
||
dataBuilder.Append(Init.ScanPort.ReadExisting());
|
||
}
|
||
ReturnValue = dataBuilder.ToString();
|
||
|
||
if (this.InvokeRequired)
|
||
{
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
LOt号.Text = ReturnValue;
|
||
LOt号.Visible = true;
|
||
}));
|
||
}
|
||
else
|
||
{
|
||
LOt号.Text = ReturnValue;
|
||
LOt号.Visible = true;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show($"读取数据时出错: {ex.Message}");
|
||
}
|
||
}
|
||
|
||
private void button1_Click_1(object sender, EventArgs e)
|
||
{
|
||
if (button1.BackColor == Color.Red)
|
||
{
|
||
index = 0;
|
||
button1.BackColor = SystemColors.Control;
|
||
button2.BackColor = SystemColors.Control;
|
||
}
|
||
else
|
||
{
|
||
index = 1;
|
||
button1.BackColor = Color.Red;
|
||
button2.BackColor = SystemColors.Control;
|
||
}
|
||
}
|
||
|
||
private void button2_Click_1(object sender, EventArgs e)
|
||
{
|
||
if (button2.BackColor == Color.Red)
|
||
{
|
||
index = 0;
|
||
button2.BackColor = SystemColors.Control;
|
||
button1.BackColor = SystemColors.Control;
|
||
}
|
||
else
|
||
{
|
||
index = 2;
|
||
button2.BackColor = Color.Red;
|
||
button1.BackColor = SystemColors.Control;
|
||
}
|
||
}
|
||
|
||
private void ScanForm_SSQ_FormClosed(object sender, FormClosedEventArgs e)
|
||
{
|
||
FormHelp.RemoveAllEventHandlers(Init.ScanPort, "DataReceived");
|
||
}
|
||
}
|
||
}
|