diff --git a/linesider_screen_bankend/Models/linesider_sreen_bankend.Models/SQLHepler/SqlSugarHelper.cs b/linesider_screen_bankend/Models/linesider_sreen_bankend.Models/SQLHepler/SqlSugarHelper.cs
index eb6fde1..70e625a 100644
--- a/linesider_screen_bankend/Models/linesider_sreen_bankend.Models/SQLHepler/SqlSugarHelper.cs
+++ b/linesider_screen_bankend/Models/linesider_sreen_bankend.Models/SQLHepler/SqlSugarHelper.cs
@@ -9,7 +9,7 @@ namespace linesider_screen_bankend.Services.SQLHepler
{
var config = new ConnectionConfig()
{
- ConnectionString = "Server=139.224.232.211;Database=gxassembly;Uid=root;Pwd=123456;Port=3308", // 替换为你的MySQL连接字符串
+ ConnectionString = "Data Source=139.224.232.211;User ID=root;Password=doantech123;Initial Catalog=GXAssembly;Port=3308", // 替换为你的MySQL连接字符串
DbType = DbType.MySql, // 数据库类型设置为MySQL
IsAutoCloseConnection = true, // 自动释放
InitKeyType = InitKeyType.Attribute // 从实体特性读取主键信息
diff --git a/linesider_screen_bankend/linesider_screen_bankend/Controller/OnlyPrintProductLabelController.cs b/linesider_screen_bankend/linesider_screen_bankend/Controller/OnlyPrintProductLabelController.cs
new file mode 100644
index 0000000..0d45567
--- /dev/null
+++ b/linesider_screen_bankend/linesider_screen_bankend/Controller/OnlyPrintProductLabelController.cs
@@ -0,0 +1,249 @@
+using EmbedIO.Routing;
+using EmbedIO.WebApi;
+using EmbedIO;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using DOAN.Model.MES.product;
+using linesider_screen_bankend.Core.Tools;
+using linesider_screen_bankend.Services.SQLHepler;
+using Google.Protobuf.WellKnownTypes;
+using System.Configuration;
+using linesider_screen_bankend.Core.Tools.HttpHepler;
+using System.Net.Http;
+using static Mysqlx.Crud.Order.Types;
+
+namespace linesider_screen_bankend.Controller
+{
+ ///
+ /// 只打印产品标签
+ ///
+
+ public class OnlyPrintProductLabelController : WebApiController
+ {
+ private readonly Action _logAction;
+
+ public OnlyPrintProductLabelController(Action logAction)
+ {
+ _logAction = logAction;
+ }
+
+ [Route(HttpVerbs.Get, "/hello")]
+ public string GetHello()
+ {
+ _logAction?.Invoke($"GET /api/hello from {HttpContext.RemoteEndPoint}");
+ return "Hello from WPF!";
+ }
+
+ //TODO 1.出首件校验标签
+ [Route(HttpVerbs.Get, "/first_inspection_label")]
+ public async Task FirstInspectionLabel()
+ {
+ _logAction?.Invoke($"GET /api/first_inspection_label from {HttpContext.RemoteEndPoint}");
+ // 获取所有查询参数
+ var queryParams = HttpContext.Request.QueryString;
+ // 获取特定参数
+ string workorder = queryParams["workorder"];
+ string model = queryParams["model"];
+ string direction = queryParams["direction"];
+
+
+
+
+ try
+ {
+ ProWorkorder workorderInfo = SqlSugarHelper.Db.Queryable()
+ .Where(x => x.Workorder == workorder)
+ .First();
+ if (workorderInfo != null)
+ {
+ // 使用 using 语句确保资源正确释放
+ using (var bartender = new BartenderPrintHelper())
+ {
+ // 准备打印数据
+ string templatePath = ConfigurationManager.AppSettings["label_path"];
+ var variables = new Dictionary
+ {
+ { "partnumber", workorderInfo.Specification },
+ { "model", model },
+ { "direction", direction },
+ { "productdate", DateTime.Now.ToString("yyyy/MM/dd") },
+ {"workorder",workorderInfo.Workorder+"|"+workorderInfo.Specification+"|"+model+"|"+direction }
+ };
+
+ // 打印标签
+ bool success = bartender.PrintLabel(
+ templatePath: templatePath,
+ subStringValues: variables,
+ copies: 1, // 打印2份
+ serializedLabels: 1 // 序列化标签数为1
+ );
+
+ if (success)
+ {
+ _logAction?.Invoke("标签打印成功");
+
+ }
+
+ }
+
+
+ // 模拟从数据库获取用户
+ var user = new { Id = 123, Name = "张三", Age = 25 };
+ // 返回成功响应
+ await this.HttpContext.SendApiSuccessAsync(null);
+ }
+
+ }
+ catch (Exception ex)
+ {
+ // 返回错误响应
+ await this.HttpContext.SendApiFailAsync(500, ex.Message);
+ }
+
+ }
+
+ //TODO 2.校验是否首件标签是否合格
+ [Route(HttpVerbs.Get, "/first_inspection_label_isQualified")]
+ public async Task FirstInspectionLabelIsQualified()
+ {
+ _logAction?.Invoke($"GET /api/first_inspection_label_isQualified from {HttpContext.RemoteEndPoint}");
+ // 获取所有查询参数
+ var queryParams = HttpContext.Request.QueryString;
+ // 获取特定参数
+ string workorder = queryParams["workorder"];
+ try
+ {
+
+ await this.HttpContext.SendApiSuccessAsync(null);
+ }
+ catch (Exception ex)
+ {
+ // 返回错误响应
+ await this.HttpContext.SendApiFailAsync(500, ex.Message);
+ }
+
+ }
+ //TODO 3.出自由标签
+
+ [Route(HttpVerbs.Get, "/freenum_label")]
+ public async Task FreeNumLabel()
+ {
+ _logAction?.Invoke($"GET /api/freenum_label from {HttpContext.RemoteEndPoint}");
+ // 获取所有查询参数
+ var queryParams = HttpContext.Request.QueryString;
+ // 获取特定参数
+ string workorder = queryParams["workorder"];
+ int LabelNum = int.Parse(queryParams["label_num"]);
+
+ try
+ {
+ ProWorkorder workorderInfo = SqlSugarHelper.Db.Queryable()
+ .Where(x => x.Workorder == workorder)
+ .First();
+ // 使用 using 语句确保资源正确释放
+ using (var bartender = new BartenderPrintHelper())
+ {
+ // 准备打印数据
+ string templatePath = ConfigurationManager.AppSettings["label_path"];
+ var variables = new Dictionary
+ {
+ { "ProductName", "高级笔记本电脑" },
+ { "SerialNumber", "SN-20230401-001" },
+ { "ManufactureDate", DateTime.Now.ToString("yyyy-MM-dd") }
+ };
+
+ // 打印标签
+ bool success = bartender.PrintLabel(
+ templatePath: templatePath,
+ subStringValues: variables,
+ copies: 2, // 打印2份
+ serializedLabels: 1 // 序列化标签数为1
+ );
+
+ if (success)
+ {
+ _logAction?.Invoke("标签打印成功");
+
+ }
+
+ }
+
+
+ // 模拟从数据库获取用户
+ var user = new { Id = 123, Name = "张三", Age = 25 };
+ // 返回成功响应
+ await this.HttpContext.SendApiSuccessAsync(null);
+ }
+ catch (Exception ex)
+ {
+ // 返回错误响应
+ await this.HttpContext.SendApiFailAsync(500, ex.Message);
+ }
+
+ }
+
+ //TODO 4.补打标签
+ [Route(HttpVerbs.Get, "/supplement_label")]
+ public async Task SupplementLabel()
+ {
+ _logAction?.Invoke($"GET /api/supplement_label from {HttpContext.RemoteEndPoint}");
+ // 获取所有查询参数
+ var queryParams = HttpContext.Request.QueryString;
+ // 获取特定参数
+ string workorder = queryParams["workorder"];
+ int LabelNum = int.Parse(queryParams["label_num"]);
+
+ try
+ {
+ ProWorkorder workorderInfo = SqlSugarHelper.Db.Queryable()
+ .Where(x => x.Workorder == workorder)
+ .First();
+ // 使用 using 语句确保资源正确释放
+ using (var bartender = new BartenderPrintHelper())
+ {
+ // 准备打印数据
+ string templatePath = ConfigurationManager.AppSettings["label_path"];
+ var variables = new Dictionary
+ {
+ { "ProductName", "高级笔记本电脑" },
+ { "SerialNumber", "SN-20230401-001" },
+ { "ManufactureDate", DateTime.Now.ToString("yyyy-MM-dd") }
+ };
+
+ // 打印标签
+ bool success = bartender.PrintLabel(
+ templatePath: templatePath,
+ subStringValues: variables,
+ copies: 2, // 打印2份
+ serializedLabels: 1 // 序列化标签数为1
+ );
+
+ if (success)
+ {
+ _logAction?.Invoke("标签打印成功");
+
+ }
+
+ }
+
+
+ // 模拟从数据库获取用户
+ var user = new { Id = 123, Name = "张三", Age = 25 };
+ // 返回成功响应
+ await this.HttpContext.SendApiSuccessAsync(null);
+ }
+ catch (Exception ex)
+ {
+ // 返回错误响应
+ await this.HttpContext.SendApiFailAsync(500, ex.Message);
+ }
+ }
+
+
+
+
+ }
+}
diff --git a/linesider_screen_bankend/linesider_screen_bankend/Views/MainWindow.xaml.cs b/linesider_screen_bankend/linesider_screen_bankend/Views/MainWindow.xaml.cs
index ba10de4..9e492bf 100644
--- a/linesider_screen_bankend/linesider_screen_bankend/Views/MainWindow.xaml.cs
+++ b/linesider_screen_bankend/linesider_screen_bankend/Views/MainWindow.xaml.cs
@@ -91,9 +91,10 @@ namespace linesider_screen_bankend.Views
var server = new WebServer(o => o
.WithUrlPrefix(url)
.WithMode(HttpListenerMode.EmbedIO))
- .WithWebApi("/print_api", m => m
- .WithController(() => new PrintCommunicationController(AddLog)))
- .WithStaticFolder("/", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot"), true);
+ .WithWebApi("/print_api", m => m
+ .WithController(() => new PrintCommunicationController(AddLog))
+ .WithController(() => new OnlyPrintProductLabelController(AddLog)))
+ .WithStaticFolder("/", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot"), true);
// 添加请求日志中间件
server.OnHttpException += async (context, exception) =>
diff --git a/linesider_screen_bankend/linesider_screen_bankend/appsettings.json b/linesider_screen_bankend/linesider_screen_bankend/appsettings.json
new file mode 100644
index 0000000..6f911ce
--- /dev/null
+++ b/linesider_screen_bankend/linesider_screen_bankend/appsettings.json
@@ -0,0 +1,4 @@
+{
+
+ "label_path": "C:\\Labels\\MyLabel.btw" //标签路径
+}
\ No newline at end of file