This commit is contained in:
XingCheng3
2026-05-26 09:41:24 +08:00
commit dff0156cdd
1329 changed files with 88153 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MesDataFunction
{
public class PP
{
public static string ConnectionString_MES { get; set; }
public static string PrintURL { get; set; }
public static int IsDemoMesServer { get; set; }
public static Dictionary<string, string[]> SpecialOpList { get; set; }
}
}

View File

@@ -0,0 +1,86 @@
using MesServerFunctions;
using MesWork;
using NPOI.XWPF.UserModel;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Runtime.CompilerServices.RuntimeHelpers;
namespace MesDataFunction
{
public class PrintTo
{
/// <summary>
///
/// </summary>
/// <param name="str"></param>
public static bool Print(bool isSinglePrint,string url,string[] strArray)
{
if (PP.IsDemoMesServer == 1)
{
var list = new List<string>();
foreach (string str in strArray)
{
var printStr = str;
if (isSinglePrint)
{
printStr = str.Replace("^XB", "");
}
list.Add(printStr);
}
File.WriteAllText($"PrintContent_{DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")}.print", string.Join(" ", list));
return true;
}
var sucess = false;
try
{
var client = new System.Net.Sockets.TcpClient();
client.Connect(url.Split(':')[0], Convert.ToInt32(url.Split(':')[1]));
foreach (string str in strArray)
{
var printStr = str;
if (isSinglePrint)
{
printStr = str.Replace("^XB", "");
}
client.Client.Send(System.Text.Encoding.ASCII.GetBytes(printStr));
}
client.Close();
sucess = true;
}
catch (Exception err) { }
return sucess;
}
public static bool PrintByMqtt(string OpName,string LeftTop,string RightTop,string LeftBottom,string BarCode)
{
var sucess = false;
try
{
string topic = ConfigurationManager.AppSettings["MqttUrl"].Split(',')[1];
string templeName = ConfigurationManager.AppSettings["PrintTempleName"];
string opName = "OPPrint";
string sendMsg = $"{opName}~1~ZT411{OpName}~{templeName}{OpName}|BarCode^Code0^{BarCode}|TEXT^TEXT1^{RightTop}|TEXT^TEXT0^{LeftTop}|TEXT^TEXT2^{LeftBottom}|TEXT^TEXT3^{BarCode}";
Task.Run(() => Mqtt.Publish(topic, sendMsg));
}
catch(Exception err)
{
sucess = false;
}
return sucess;
}
}
}

View File

@@ -0,0 +1,80 @@
using MesDataFunction;
using MesWork;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MesDataFunction
{
public class Print_Sql
{
public static bool Select_Print_Template(out DataTable dt_Print_Template)
{
/*
SELECT [IDG],[TemplateName],[TemplateContent],[DefSelect],[UpdateTime] FROM [OL_Repair_Print_Template]
*/
bool success = false;
var sql =
@"
SELECT [IDG],[TemplateName],[DefSelect],[UpdateTime] FROM [OL_Repair_Print_Template]
ORDER BY [UpdateTime]
";
success = DataLinkMesWork.SQLCommon.ExecuteDataTable(sql, PP.ConnectionString_MES, out DataTable dt, out string err2);
dt_Print_Template = dt;
return success;
}
public static bool Select_Print_TemplateStr(string IDG, out string templateStr)
{
/*
SELECT [IDG],[TemplateName],[TemplateContent],[DefSelect],[UpdateTime] FROM [OL_Repair_Print_Template]
*/
templateStr = "";
bool success = false;
var sql =
$" DECLARE @IDG nvarchar(50) = '{IDG}'" +
@"
SELECT [TemplateContent] FROM [OL_Repair_Print_Template]
WHERE [IDG] = @IDG
";
success = DataLinkMesWork.SQLCommon.ExecuteDataTable(sql, PP.ConnectionString_MES, out DataTable dt, out string err2);
if (dt.Rows.Count > 0)
{
templateStr = dt.Rows[0]["TemplateContent"].ToString();
}
return success;
}
public static bool Select_Print_Template_Def(out string templateStr)
{
/*
SELECT [IDG],[TemplateName],[TemplateContent],[DefSelect],[UpdateTime] FROM [OL_Repair_Print_Template]
*/
templateStr = "";
bool success = false;
var sql =
@"
SELECT top 1 [TemplateContent] FROM [OL_Repair_Print_Template]
WHERE [DefSelect]= 'True'
";
success = DataLinkMesWork.SQLCommon.ExecuteDataTable(sql, PP.ConnectionString_MES, out DataTable dt, out string err2);
if (dt.Rows.Count > 0)
{
templateStr = dt.Rows[0]["TemplateContent"].ToString();
}
return success;
}
}
}

View File

@@ -0,0 +1,63 @@
using MesWork;
using MisDataFunDll;
using MisDataSaveDate;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MesDataFunction
{
public class PrinterCommandCenter
{
public static bool PrintToPrinter(string opName, string code)
{
bool success = false;
Print_Sql.Select_Print_Template_Def(out string templateStr);
CallWebService.Call_getAllLabelContents(opName, code, out string res_code, out string res_message, out LabelContent labelContent);
List<LabelField> LabelFields = labelContent.LabelFields;
var printContent = Template_Make_Zpl(templateStr, code);
string LeftTop = "", RightTop = "", LeftBottom = "";
for (int i = 0; i < LabelFields.Count; i++)
{
if (LabelFields[i].Field == "TEXT1")
{
printContent = printContent.Replace("@LeftTop", LabelFields[i].Value);
LeftTop = LabelFields[i].Value;
}
if (LabelFields[i].Field == "TEXT2")
{
printContent = printContent.Replace("@RightTop", LabelFields[i].Value);
RightTop = LabelFields[i].Value;
}
if (LabelFields[i].Field == "TEXT3")
{
printContent = printContent.Replace("@LeftBottom", LabelFields[i].Value);
LeftBottom = LabelFields[i].Value;
}
}
if (LeftTop == "" || RightTop == "" || LeftBottom == "") return false;
MisDataFun.OpPrintBarCodeRecord_Add(opName, code, LeftTop, RightTop, LeftBottom);
//PrintTo.Print(true, PP.PrintURL, new string[] { printContent });
PrintTo.PrintByMqtt(opName, LeftTop, RightTop, LeftBottom, code);
return success;
}
public static string Template_Make_Zpl(string templateStr,string TowCode)
{
return templateStr.Replace("@TowCode", TowCode);
}
}
}