4.11更新

1.添加是否调用mes接口按钮,并只有admin用户可以点击,2.修改螺丝引导页面
3.端子只有一个,端子扫码借用扫码页面
This commit is contained in:
zhougf committed 2025-04-11 15:47:10 +08:00
1 parent 752e1f37b6
commit 69c851c09e
15 files changed
+1006 -387

No files matched your search

+295 -51
View File
@@ -5,6 +5,8 @@ using System.ComponentModel;
using System.IO;
using WindowsFormsApp1.mod;
using WindowsFormsApp1.db;
using System.Collections.Generic;
using System.Linq;
namespace WindowsFormsApp1
{
@@ -23,13 +25,33 @@ namespace WindowsFormsApp1
private string currentName = "";
private string currentPosition = "";
private bool isBlinking = false;
// 圆形标记相关参数
private float currentRadius = 20f;
private const float MIN_RADIUS = 20f;
private const float MAX_RADIUS = 50f;
private const float MIN_RADIUS = 30f;
private const float MAX_RADIUS = 55f;
private bool isExpanding = true;
private const float RADIUS_CHANGE_SPEED = 2f;
// 添加上一个位置的坐标
private int previousX = -1;
private int previousY = -1;
private bool hasPreviousPosition = false;
// 添加所有点位的列表
private List<t_imageposition> allPositions = new List<t_imageposition>();
private bool showAllPositions = true;
// 添加历史位置列表
private List<PositionHistory> previousPositions = new List<PositionHistory>();
// 定义历史位置类
private class PositionHistory
{
public int X { get; set; }
public int Y { get; set; }
public string Position { get; set; }
}
#endregion
#region 构造函数和初始化
@@ -43,6 +65,25 @@ namespace WindowsFormsApp1
autoUpdateTimer.Interval = 1000;
autoUpdateTimer.Tick += new EventHandler(AutoUpdateTimer_Tick);
autoUpdateTimer.Start();
// 添加窗体加载事件
this.Load += ImageDisplayForm_Load;
}
private void ImageDisplayForm_Load(object sender, EventArgs e)
{
// 设置窗体大小为屏幕工作区的80%
Screen screen = Screen.FromControl(this);
this.Size = new Size(
(int)(screen.WorkingArea.Width * 0.8),
(int)(screen.WorkingArea.Height * 0.8)
);
this.CenterToScreen();
// 或者使用以下代码设置为全屏但非最大化
// this.WindowState = FormWindowState.Normal;
// this.FormBorderStyle = FormBorderStyle.None;
// this.Bounds = Screen.FromControl(this).Bounds;
}
#endregion
@@ -98,6 +139,9 @@ namespace WindowsFormsApp1
originalImage = new Bitmap(imagePath);
markedImage = new Bitmap(originalImage);
pictureBox.Image = markedImage;
// 加载所有点位并标注
LoadAllPositions(name);
}
catch (Exception ex)
{
@@ -110,56 +154,101 @@ namespace WindowsFormsApp1
}
}
// 在图像上绘制标记
private void DrawMark(int x, int y)
// 加载所有点位并标注
private void LoadAllPositions(string name)
{
try
{
SQLiteHelper<t_imageposition> sQLiteHelper_position = new db.SQLiteHelper<t_imageposition>();
allPositions = sQLiteHelper_position.Query(x => x.name == name).Data;
if (allPositions != null && allPositions.Count > 0)
{
// 重新绘制图像,标注所有点位
RedrawImage();
}
}
catch (Exception ex)
{
Console.WriteLine($"加载所有点位失败:{ex.Message}");
}
}
// 重新绘制图像,包括所有标记
private void RedrawImage()
{
if (originalImage == null)
return;
// 创建新的标记图像
if (markedImage != null)
markedImage.Dispose();
markedImage = new Bitmap(originalImage);
using (Graphics g = Graphics.FromImage(markedImage))
{
if (isBlinking)
// 设置高质量绘图模式
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
// 绘制所有点位(白色实心圆和序号)
if (showAllPositions && allPositions != null)
{
// 设置高质量绘图模式
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
// 只绘制白色圆
using (Brush whiteBrush = new SolidBrush(Color.White))
for (int i = 0; i < allPositions.Count; i++)
{
g.FillEllipse(whiteBrush,
x - currentRadius,
y - currentRadius,
currentRadius * 2,
currentRadius * 2);
}
var pos = allPositions[i];
// 更新半径
if (isExpanding)
{
currentRadius += RADIUS_CHANGE_SPEED;
if (currentRadius >= MAX_RADIUS)
// 绘制白色实心圆
using (Brush whiteBrush = new SolidBrush(Color.White))
{
currentRadius = MAX_RADIUS;
isExpanding = false;
g.FillEllipse(whiteBrush,
pos.x - MIN_RADIUS,
pos.y - MIN_RADIUS,
MIN_RADIUS * 2,
MIN_RADIUS * 2);
}
}
else
{
currentRadius -= RADIUS_CHANGE_SPEED;
if (currentRadius <= MIN_RADIUS)
// 绘制白色序号
using (Font font = new Font("Arial", 16, FontStyle.Bold))
using (Brush textBrush = new SolidBrush(Color.Black))
{
currentRadius = MIN_RADIUS;
isExpanding = true;
string text = pos.position; // 使用position属性
SizeF textSize = g.MeasureString(text, font);
g.DrawString(text, font, textBrush,
pos.x - textSize.Width / 2,
pos.y - textSize.Height / 2);
}
}
}
// 绘制所有历史位置的绿色标记
foreach (var history in previousPositions)
{
using (Brush greenBrush = new SolidBrush(Color.Green))
{
g.FillEllipse(greenBrush,
history.X - MIN_RADIUS,
history.Y - MIN_RADIUS,
MIN_RADIUS * 2,
MIN_RADIUS * 2);
}
// 绘制绿色标记上的文字
using (Font font = new Font("Arial", 16, FontStyle.Bold))
using (Brush textBrush = new SolidBrush(Color.White))
{
string text = history.Position;
SizeF textSize = g.MeasureString(text, font);
g.DrawString(text, font, textBrush,
history.X - textSize.Width / 2,
history.Y - textSize.Height / 2);
}
}
}
pictureBox.Image = markedImage;
}
#endregion
#region 数据查询和更新
// 自动更新定时器事件
private void AutoUpdateTimer_Tick(object sender, EventArgs e)
{
@@ -169,6 +258,48 @@ namespace WindowsFormsApp1
if (newPosition != currentPosition || (string.IsNullOrEmpty(currentPosition) && !string.IsNullOrEmpty(newPosition)))
{
// 保存上一个位置
if (!string.IsNullOrEmpty(currentPosition))
{
SQLiteHelper<t_imageposition> sQLiteHelper_position = new db.SQLiteHelper<t_imageposition>();
var positions = sQLiteHelper_position.Query(x => x.name == currentName
&& x.position == currentPosition).Data;
if (positions != null && positions.Count > 0)
{
var pos = positions[0];
// 检查是否已经存在相同位置的历史记录
bool exists = false;
foreach (var history in previousPositions)
{
if (history.X == pos.x && history.Y == pos.y)
{
// 更新位置文本
history.Position = currentPosition;
exists = true;
break;
}
}
// 如果不存在,添加到历史记录
if (!exists)
{
previousPositions.Add(new PositionHistory
{
X = pos.x,
Y = pos.y,
Position = currentPosition
});
}
// 设置最近的历史位置
previousX = pos.x;
previousY = pos.y;
hasPreviousPosition = true;
}
}
currentPosition = newPosition;
// 如果名称和位置都有值,则查询坐标并标注
@@ -193,49 +324,162 @@ namespace WindowsFormsApp1
{
try
{
SQLiteHelper<t_imageposition> sQLiteHelper_position = new db.SQLiteHelper<t_imageposition>();
var positions = sQLiteHelper_position.Query(x => x.name == name
&& x.position == position).Data;
// 从已加载的点位列表中查找,避免重复查询数据库
var pos = allPositions?.FirstOrDefault(x => x.name == name && x.position == position);
if (positions != null && positions.Count > 0)
if (pos != null)
{
var pos = positions[0];
// 标记位置
if (originalImage != null)
{
isBlinking = true; // 设置为 true 后不再切换
currentRadius = MIN_RADIUS; // 重置半径
blinkTimer.Start();
// 确保闪烁定时器已启动
if (blinkTimer != null && !blinkTimer.Enabled)
blinkTimer.Start();
// 在图像上绘制标记
DrawMark(pos.x, pos.y);
}
}
else
{
// 如果在内存中没有找到,尝试从数据库查询
SQLiteHelper<t_imageposition> sQLiteHelper_position = new db.SQLiteHelper<t_imageposition>();
var positions = sQLiteHelper_position.Query(x => x.name == name && x.position == position).Data;
if (positions != null && positions.Count > 0)
{
pos = positions[0];
// 添加到内存中的列表
if (!allPositions.Any(x => x.name == name && x.position == position))
{
allPositions.Add(pos);
}
// 标记位置
if (originalImage != null)
{
isBlinking = true;
currentRadius = MIN_RADIUS;
if (blinkTimer != null && !blinkTimer.Enabled)
blinkTimer.Start();
DrawMark(pos.x, pos.y);
}
}
else
{
// 如果没有找到对应的位置,停止闪烁
isBlinking = false;
blinkTimer?.Stop();
// 仍然重绘图像以显示所有点位和之前的绿色标记
RedrawImage();
Console.WriteLine($"未找到名称为 {name} 位置为 {position} 的坐标");
}
}
}
catch (Exception ex)
{
Console.WriteLine($"查询坐标失败:{ex.Message}");
// 发生异常时也重绘图像
RedrawImage();
}
}
#endregion
#region 事件处理
// 在图像上绘制标记
private void DrawMark(int x, int y)
{
if (originalImage == null)
return;
// 先重新绘制基础图像(包含所有点位标记)
RedrawImage();
using (Graphics g = Graphics.FromImage(markedImage))
{
// 设置高质量绘图模式
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
if (isBlinking)
{
// 绘制当前位置的黄色实心圆
using (Brush brush = new SolidBrush(Color.Yellow))
{
g.FillEllipse(brush,
x - MIN_RADIUS,
y - MIN_RADIUS,
MIN_RADIUS * 2,
MIN_RADIUS * 2);
}
// 绘制白色数字标记
using (Font font = new Font("Arial", 16, FontStyle.Bold))
using (Brush textBrush = new SolidBrush(Color.Black))
{
string text = currentPosition;
SizeF textSize = g.MeasureString(text, font);
g.DrawString(text, font, textBrush,
x - textSize.Width / 2,
y - textSize.Height / 2);
}
// 绘制黄色虚线空心圆闪烁效果
using (Pen yellowPen = new Pen(Color.Yellow, 2))
{
yellowPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
g.DrawEllipse(yellowPen,
x - currentRadius,
y - currentRadius,
currentRadius * 2,
currentRadius * 2);
}
}
}
pictureBox.Image = markedImage;
}
// 闪烁定时器事件
private void BlinkTimer_Tick(object sender, EventArgs e)
{
SQLiteHelper<t_imageposition> sQLiteHelper_position = new db.SQLiteHelper<t_imageposition>();
var positions = sQLiteHelper_position.Query(x => x.name == currentName
&& x.position == currentPosition).Data;
// 从已加载的点位列表中查找当前位置
var pos = allPositions?.FirstOrDefault(x => x.name == currentName && x.position == currentPosition);
if (positions != null && positions.Count > 0)
if (pos != null)
{
var pos = positions[0];
// 直接调用DrawMark方法绘制标记
DrawMark(pos.x, pos.y);
// 更新半径
if (isExpanding)
{
currentRadius += RADIUS_CHANGE_SPEED;
if (currentRadius >= MAX_RADIUS)
{
currentRadius = MAX_RADIUS;
isExpanding = false;
}
}
else
{
currentRadius -= RADIUS_CHANGE_SPEED;
if (currentRadius <= MIN_RADIUS)
{
currentRadius = MIN_RADIUS;
isExpanding = true;
}
}
}
}
// 移除了 BtnLoadImage_Click 事件处理程序
#endregion
#region 资源释放
protected override void Dispose(bool disposing)
{
@@ -297,4 +541,4 @@ namespace WindowsFormsApp1
#endregion
}
}
}
+239
View File
@@ -0,0 +1,239 @@
namespace WindowsFormsApp1
{
partial class MaterialScanForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panelTop = new System.Windows.Forms.Panel();
this.lblScan = new System.Windows.Forms.Label();
this.lblPosition = new System.Windows.Forms.Label();
this.lblDescription = new System.Windows.Forms.Label();
this.txtScan = new System.Windows.Forms.TextBox();
this.rbPosition1 = new System.Windows.Forms.RadioButton();
this.rbPosition2 = new System.Windows.Forms.RadioButton();
this.txtDescription = new System.Windows.Forms.TextBox();
this.btnAdd = new System.Windows.Forms.Button();
this.dgvMaterials = new System.Windows.Forms.DataGridView();
this.colOffline = new System.Windows.Forms.DataGridViewButtonColumn();
this.colScanCode = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colPosition = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colDescription = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colTime = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.panelTop.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvMaterials)).BeginInit();
this.SuspendLayout();
//
// panelTop
//
this.panelTop.Controls.Add(this.lblScan);
this.panelTop.Controls.Add(this.lblPosition);
this.panelTop.Controls.Add(this.lblDescription);
this.panelTop.Controls.Add(this.txtScan);
this.panelTop.Controls.Add(this.rbPosition1);
this.panelTop.Controls.Add(this.rbPosition2);
this.panelTop.Controls.Add(this.txtDescription);
this.panelTop.Controls.Add(this.btnAdd);
this.panelTop.Dock = System.Windows.Forms.DockStyle.Top;
this.panelTop.Location = new System.Drawing.Point(0, 0);
this.panelTop.Margin = new System.Windows.Forms.Padding(6);
this.panelTop.Name = "panelTop";
this.panelTop.Size = new System.Drawing.Size(2148, 300);
this.panelTop.TabIndex = 6;
//
// lblScan
//
this.lblScan.Font = new System.Drawing.Font("微软雅黑", 14F);
this.lblScan.Location = new System.Drawing.Point(24, 50);
this.lblScan.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
this.lblScan.Name = "lblScan";
this.lblScan.Size = new System.Drawing.Size(200, 50);
this.lblScan.TabIndex = 0;
this.lblScan.Text = "扫描条码";
//
// lblPosition
//
this.lblPosition.Font = new System.Drawing.Font("微软雅黑", 14F);
this.lblPosition.Location = new System.Drawing.Point(700, 50);
this.lblPosition.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
this.lblPosition.Name = "lblPosition";
this.lblPosition.Size = new System.Drawing.Size(200, 50);
this.lblPosition.TabIndex = 1;
this.lblPosition.Text = "位置";
//
// lblDescription
//
this.lblDescription.Font = new System.Drawing.Font("微软雅黑", 14F);
this.lblDescription.Location = new System.Drawing.Point(1200, 50);
this.lblDescription.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
this.lblDescription.Name = "lblDescription";
this.lblDescription.Size = new System.Drawing.Size(200, 50);
this.lblDescription.TabIndex = 2;
this.lblDescription.Text = "说明";
//
// txtScan
//
this.txtScan.Font = new System.Drawing.Font("微软雅黑", 14F);
this.txtScan.Location = new System.Drawing.Point(24, 110);
this.txtScan.Margin = new System.Windows.Forms.Padding(6);
this.txtScan.Name = "txtScan";
this.txtScan.Size = new System.Drawing.Size(596, 57);
this.txtScan.TabIndex = 3;
//
// rbPosition1
//
this.rbPosition1.Checked = true;
this.rbPosition1.Font = new System.Drawing.Font("微软雅黑", 14F);
this.rbPosition1.Location = new System.Drawing.Point(700, 110);
this.rbPosition1.Margin = new System.Windows.Forms.Padding(6);
this.rbPosition1.Name = "rbPosition1";
this.rbPosition1.Size = new System.Drawing.Size(180, 64);
this.rbPosition1.TabIndex = 4;
this.rbPosition1.TabStop = true;
this.rbPosition1.Text = "位置1";
//
// rbPosition2
//
this.rbPosition2.Font = new System.Drawing.Font("微软雅黑", 14F);
this.rbPosition2.Location = new System.Drawing.Point(900, 110);
this.rbPosition2.Margin = new System.Windows.Forms.Padding(6);
this.rbPosition2.Name = "rbPosition2";
this.rbPosition2.Size = new System.Drawing.Size(180, 64);
this.rbPosition2.TabIndex = 5;
this.rbPosition2.Text = "位置2";
//
// txtDescription
//
this.txtDescription.Font = new System.Drawing.Font("微软雅黑", 14F);
this.txtDescription.Location = new System.Drawing.Point(1200, 110);
this.txtDescription.Margin = new System.Windows.Forms.Padding(6);
this.txtDescription.Name = "txtDescription";
this.txtDescription.Size = new System.Drawing.Size(596, 57);
this.txtDescription.TabIndex = 6;
//
// btnAdd
//
this.btnAdd.Font = new System.Drawing.Font("微软雅黑", 14F);
this.btnAdd.Location = new System.Drawing.Point(1840, 104);
this.btnAdd.Margin = new System.Windows.Forms.Padding(6);
this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(200, 76);
this.btnAdd.TabIndex = 7;
this.btnAdd.Text = "上线";
//
// dgvMaterials
//
this.dgvMaterials.AllowUserToAddRows = false;
this.dgvMaterials.AllowUserToDeleteRows = false;
this.dgvMaterials.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.dgvMaterials.ColumnHeadersHeight = 40;
this.dgvMaterials.Dock = System.Windows.Forms.DockStyle.Fill;
this.dgvMaterials.Font = new System.Drawing.Font("微软雅黑", 14F);
this.dgvMaterials.Location = new System.Drawing.Point(0, 300);
this.dgvMaterials.Margin = new System.Windows.Forms.Padding(6);
this.dgvMaterials.Name = "dgvMaterials";
this.dgvMaterials.ReadOnly = true;
this.dgvMaterials.RowHeadersWidth = 82;
this.dgvMaterials.RowTemplate.Height = 35;
this.dgvMaterials.Size = new System.Drawing.Size(2148, 1134);
this.dgvMaterials.TabIndex = 5;
//
// colOffline
//
this.colOffline.HeaderText = "";
this.colOffline.MinimumWidth = 10;
this.colOffline.Name = "colOffline";
this.colOffline.Text = "下线";
this.colOffline.UseColumnTextForButtonValue = true;
this.colOffline.Width = 80;
//
// colScanCode
//
this.colScanCode.HeaderText = "扫描码";
this.colScanCode.MinimumWidth = 10;
this.colScanCode.Name = "colScanCode";
this.colScanCode.Width = 200;
//
// colPosition
//
this.colPosition.HeaderText = "位置";
this.colPosition.MinimumWidth = 10;
this.colPosition.Name = "colPosition";
this.colPosition.Width = 200;
//
// colDescription
//
this.colDescription.HeaderText = "说明";
this.colDescription.MinimumWidth = 10;
this.colDescription.Name = "colDescription";
this.colDescription.Width = 200;
//
// colTime
//
this.colTime.HeaderText = "时间";
this.colTime.MinimumWidth = 10;
this.colTime.Name = "colTime";
this.colTime.ReadOnly = true;
this.colTime.Width = 200;
//
// MaterialScanForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(2148, 1434);
this.Controls.Add(this.dgvMaterials);
this.Controls.Add(this.panelTop);
this.Margin = new System.Windows.Forms.Padding(6);
this.Name = "MaterialScanForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "材料扫码管理";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.panelTop.ResumeLayout(false);
this.panelTop.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvMaterials)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel panelTop;
private System.Windows.Forms.TextBox txtScan;
private System.Windows.Forms.RadioButton rbPosition1;
private System.Windows.Forms.RadioButton rbPosition2;
private System.Windows.Forms.TextBox txtDescription;
private System.Windows.Forms.Button btnAdd;
private System.Windows.Forms.DataGridView dgvMaterials;
private System.Windows.Forms.Label lblScan;
private System.Windows.Forms.Label lblPosition;
private System.Windows.Forms.Label lblDescription;
private System.Windows.Forms.DataGridViewButtonColumn colOffline;
private System.Windows.Forms.DataGridViewTextBoxColumn colScanCode;
private System.Windows.Forms.DataGridViewTextBoxColumn colPosition;
private System.Windows.Forms.DataGridViewTextBoxColumn colDescription;
private System.Windows.Forms.DataGridViewTextBoxColumn colTime;
}
}
+268
View File
@@ -0,0 +1,268 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using WindowsFormsApp1.db;
using WindowsFormsApp1.mod;
using WindowsFormsApp1.mod.server;
using WindowsFormsApp1.server;
namespace WindowsFormsApp1
{
public partial class MaterialScanForm : Form
{
private SQLiteHelper<t_materialscan> _dbHelper;
private List<t_materialscan> materials = new List<t_materialscan>();
private ApiClient _apiClient;
public MaterialScanForm()
{
InitializeComponent();
// 检查串口是否可用
if (Init.ScanPort != null)
{
try
{
// 如果串口未打开,尝试打开
if (!Init.ScanPort.IsOpen)
{
Init.ScanPort.Open();
}
// 订阅事件
Init.ScanPort.DataReceived += SerialPort_DataReceived_CL;
}
catch (Exception ex)
{
MessageBox.Show($"扫码枪串口初始化失败: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("扫码枪串口未配置,请检查系统设置", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
_dbHelper = new SQLiteHelper<t_materialscan>();
_apiClient = new ApiClient();
LoadMaterials();
SetupControls();
}
private void LoadMaterials()
{
var result = _dbHelper.Query(m => m.isonline);
if (result.Success)
{
materials = result.Data;
}
RefreshDataGrid();
}
public void SerialPort_DataReceived_CL(object sender, SerialDataReceivedEventArgs e)
{
try
{
if (Init.ScanPort != null && !Init.ScanPort.IsOpen)
{
try
{
Init.ScanPort.Open();
}
catch (Exception ex)
{
MessageBox.Show($"无法打开扫码枪串口: {ex.Message}");
return;
}
}
// 读取串口接收到的数据
var dataBuilder = new StringBuilder();
while (Init.ScanPort.BytesToRead > 0)
{
System.Threading.Thread.Sleep(100);
dataBuilder.Append(Init.ScanPort.ReadExisting());
}
var barcode = dataBuilder.ToString();
txtScan.Text = barcode;
}
catch (Exception ex)
{
MessageBox.Show($"读取数据时出错: {ex.Message}");
}
}
private void BtnAdd_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(txtScan.Text) || txtScan.Text == "请扫描材料条码")
{
MessageBox.Show("请扫描材料条码!");
return;
}
string scanCode = txtScan.Text;
if (materials.Any(m => m.scancode == scanCode))
{
MessageBox.Show("该材料已经在列表中!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtScan.Text = "请扫描材料条码";
txtScan.ForeColor = Color.Gray;
txtScan.Focus();
return;
}
// 调用接口
var OtherData = new otherdata();
OtherData.JS_SN = scanCode;
OtherData.locationindex = rbPosition1.Checked ? 1 : 2;
OtherData.opindex = 1;
var mesResult = _apiClient.CallFunctionByName("Glue_CheckOut", new plcdata(), OtherData);
if (mesResult.Mesresult == mesresult.FAIL)
{
MessageBox.Show("上线失败!", mesResult.Msg, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
var material = new t_materialscan
{
scancode = scanCode,
position = rbPosition1.Checked ? "1" : "2",
description = txtDescription.Text == "请输入说明" ? "" : txtDescription.Text,
scantime = DateTime.Now,
isonline = true
};
var result = _dbHelper.Insert(material);
if (result.Success)
{
materials.Add(material);
RefreshDataGrid();
// 清空输入
txtScan.Text = "请扫描材料条码";
txtScan.ForeColor = Color.Gray;
txtDescription.Text = "请输入说明";
txtDescription.ForeColor = Color.Gray;
txtScan.Focus();
}
else
{
MessageBox.Show("保存失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void DgvMaterials_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0 && e.RowIndex >= 0)
{
if (MessageBox.Show("确认要下线该材料吗?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
var material = materials[e.RowIndex];
// 调用接口
var OtherData = new otherdata();
OtherData.JS_SN = material.scancode;
OtherData.locationindex = int.Parse(material.position);
OtherData.opindex = 2;
var mesResult = _apiClient.CallFunctionByName("Glue_CheckOut", new plcdata(), OtherData);
if (mesResult.Mesresult == mesresult.FAIL)
{
MessageBox.Show("下线失败!", mesResult.Msg, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
material.isonline = false;
var result = _dbHelper.Update(material);
if (result.Success)
{
materials.RemoveAt(e.RowIndex);
RefreshDataGrid();
}
else
{
MessageBox.Show("下线失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void SetupControls()
{
// 设置文本框默认提示
SetupTextBoxHint(txtScan, "请扫描材料条码");
SetupTextBoxHint(txtDescription, "请输入说明");
// 绑定事件
btnAdd.Click += BtnAdd_Click;
dgvMaterials.CellClick += DgvMaterials_CellClick;
// 调整表格行高和样式
dgvMaterials.RowTemplate.Height = 60; // 增加行高
dgvMaterials.ColumnHeadersHeight = 60; // 相应调整表头高度
dgvMaterials.DefaultCellStyle.Font = new Font("微软雅黑", 14F);
dgvMaterials.ColumnHeadersDefaultCellStyle.Font = new Font("微软雅黑", 14F);
dgvMaterials.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
dgvMaterials.AllowUserToAddRows = false;
dgvMaterials.AllowUserToDeleteRows = false;
dgvMaterials.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dgvMaterials.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
dgvMaterials.RowHeadersVisible = false;
}
private void SetupTextBoxHint(TextBox textBox, string hint)
{
textBox.Text = hint;
textBox.ForeColor = Color.Gray;
textBox.Enter += (s, e) => {
if (textBox.Text == hint)
{
textBox.Text = "";
textBox.ForeColor = Color.Black;
}
};
textBox.Leave += (s, e) => {
if (string.IsNullOrWhiteSpace(textBox.Text))
{
textBox.Text = hint;
textBox.ForeColor = Color.Gray;
}
};
}
private void RefreshDataGrid()
{
// 确保表格有列
if (dgvMaterials.Columns.Count == 0)
{
dgvMaterials.Columns.Add(colOffline);
dgvMaterials.Columns.Add(colScanCode);
dgvMaterials.Columns.Add(colPosition);
dgvMaterials.Columns.Add(colDescription);
dgvMaterials.Columns.Add(colTime);
// 调整列宽
colOffline.Width = 50;
colScanCode.Width = 400;
colPosition.Width = 50;
colDescription.Width = 80;
colTime.Width = 250;
}
dgvMaterials.Rows.Clear();
foreach (var material in materials)
{
dgvMaterials.Rows.Add("下线", material.scancode, material.position,
material.description, material.scantime.ToString("yyyy-MM-dd HH:mm:ss"));
}
// 确保所有行的高度都是60
foreach (DataGridViewRow row in dgvMaterials.Rows)
{
row.Height = 60;
}
}
}
}
+120
View File
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
+11 -2
View File
@@ -104,8 +104,17 @@ namespace WindowsFormsApp1
{
端子1校验.Text = "校验OK";
}));
// 写数据到 主页的barcode 数据库改,缓存改
var txt = Init.t_Keyvalues.FirstOrDefault(a => a.key == "Barcode1");
txt.value = 端子1.Text;
var code = key_sqlresult.Data.First(x => x.key == txt.key);
code.value = 端子1.Text;
sQLiteHelper_key.Update(code);
//继续调用接口
var result2 = ApiClient.CallFunctionByName("Link_Comp", PlcData, new otherdata() { JS_SN = barcode });
/*var result2 = ApiClient.CallFunctionByName("Link_Comp", PlcData, new otherdata() { JS_SN = barcode });
if (result2.Success && result2.Mesresult == mesresult.PASS)
{
this.Invoke(new Action(() =>
@@ -127,7 +136,7 @@ namespace WindowsFormsApp1
{
端子1结果.Text = "绑定NG";
}));
}
}*/
}
else
{
@@ -34,7 +34,7 @@ namespace WindowsFormsApp1
// 圆形标记相关参数
private float currentRadius = 20f;
private const float MIN_RADIUS = 20f;
private const float MIN_RADIUS = 25f;
private const float MAX_RADIUS = 50f;
private bool isExpanding = true;
private const float RADIUS_CHANGE_SPEED = 2f;
@@ -44,6 +44,24 @@ namespace WindowsFormsApp1
public SimpleImageDisplayForm()
{
InitializeComponent();
// 添加窗体加载事件
this.Load += ImageDisplayForm_Load;
}
private void ImageDisplayForm_Load(object sender, EventArgs e)
{
// 设置窗体大小为屏幕工作区的80%
Screen screen = Screen.FromControl(this);
this.Size = new Size(
(int)(screen.WorkingArea.Width * 0.8),
(int)(screen.WorkingArea.Height * 0.8)
);
this.CenterToScreen();
// 或者使用以下代码设置为全屏但非最大化
// this.WindowState = FormWindowState.Normal;
// this.FormBorderStyle = FormBorderStyle.None;
// this.Bounds = Screen.FromControl(this).Bounds;
}
#endregion
@@ -53,7 +71,7 @@ namespace WindowsFormsApp1
{
if (originalImage == null)
return;
markedImage.Dispose();
markedImage = new Bitmap(originalImage);
using (Graphics g = Graphics.FromImage(markedImage))
{
@@ -63,9 +81,9 @@ namespace WindowsFormsApp1
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
// 只绘制白色圆
using (Brush whiteBrush = new SolidBrush(Color.White))
using (var brush = new Pen(Color.Yellow))
{
g.FillEllipse(whiteBrush,
g.DrawEllipse(brush,
x - currentRadius,
y - currentRadius,
currentRadius * 2,