feat(weldmat): 支持使用 DP30S 打印焊材标签
让领料确认和领用查询页面能够通过 DTPWeb 调用本机 DP30S,并与原打印方式共用标签取数,保持两种方式的字段口径一致。
This commit is contained in:
@@ -340,6 +340,7 @@
|
||||
<Compile Include="WeldMat\Stock\StockInService.cs" />
|
||||
<Compile Include="WeldMat\UsingPlan\UsingPlanService.cs" />
|
||||
<Compile Include="WeldMat\UsingPlan\UsingPlanTempService.cs" />
|
||||
<Compile Include="WeldMat\UsingSentMat\DtpWebMaterialLabel.cs" />
|
||||
<Compile Include="WeldMat\UsingSentMat\UsingMatService.cs" />
|
||||
<Compile Include="WeldMat\WeldMatDataBase\BakeRecordsService.cs" />
|
||||
<Compile Include="WeldMat\WeldMatDataBase\TemperatureAndHumidityService.cs" />
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using FineUIPro;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BLL
|
||||
{
|
||||
public static class DtpWebMaterialLabel
|
||||
{
|
||||
public static void RegisterPrint(string usingMatId)
|
||||
{
|
||||
var material = string.IsNullOrEmpty(usingMatId) ? null : UsingMatService.GetUsingMatById(usingMatId);
|
||||
if (material == null)
|
||||
{
|
||||
Alert.Show("未找到对应的焊材领用记录。", MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var fields = JsonConvert.SerializeObject(UsingMatService.GetMaterialLabelParameters(material), new JsonSerializerSettings
|
||||
{
|
||||
StringEscapeHandling = StringEscapeHandling.EscapeHtml
|
||||
});
|
||||
PageContext.RegisterStartupScript("DtpWebMaterialLabel.print(" + fields + ");");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,33 @@ namespace BLL
|
||||
return Funs.DB.Weld_UsingMat.FirstOrDefault(e => e.UsingMatId == usingMatId);
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> GetMaterialLabelParameters(Model.Weld_UsingMat material)
|
||||
{
|
||||
var weld = string.IsNullOrEmpty(material?.WeldId) ? null : WeldInfoService.GetWeldInfoById(material.WeldId);
|
||||
var weldType = string.IsNullOrEmpty(weld?.WeldTypeId) ? null : WeldTypeService.GetWeldTypeById(weld.WeldTypeId);
|
||||
var welder = string.IsNullOrEmpty(material?.UsingMan) ? null : HJGL_PersonManageService.GetWelderByWenId(material.UsingMan);
|
||||
var store = string.IsNullOrEmpty(material?.StoreMan) ? null : StoremanInfoService.GetStoremanById(material.StoreMan);
|
||||
|
||||
var number = string.Empty;
|
||||
if (material?.Amount != null || material?.TwoAmount != null)
|
||||
{
|
||||
var amount = material.Amount.GetValueOrDefault() + material.TwoAmount.GetValueOrDefault();
|
||||
var unit = weldType?.WeldTypeName == "焊丝" || weldType?.WeldTypeName == "焊条" ? "根" : "Kg";
|
||||
number = amount.ToString("0.#") + unit;
|
||||
}
|
||||
|
||||
var usingDate = material?.UsingDate;
|
||||
return new Dictionary<string, string>
|
||||
{
|
||||
{ "WeldSpec", weld?.WeldSpec ?? string.Empty },
|
||||
{ "WeldName", weld?.WeldName ?? string.Empty },
|
||||
{ "WelderName", welder == null ? string.Empty : welder.WED_Name + "(" + welder.WED_Code + ")" },
|
||||
{ "Number", number },
|
||||
{ "StoreName", store?.StoreName ?? string.Empty },
|
||||
{ "UsingDate", usingDate.HasValue ? usingDate.Value.ToShortDateString() + " " + usingDate.Value.ToShortTimeString() : string.Empty }
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加焊材领用
|
||||
/// </summary>
|
||||
|
||||
@@ -1577,6 +1577,7 @@
|
||||
<Content Include="SYBData\BlindFlangeInstallationAndRemoval.aspx" />
|
||||
<Content Include="SYBData\Cover.aspx" />
|
||||
<Content Include="res\js\cascade.js" />
|
||||
<Content Include="res\js\dtpweb-material-label.js" />
|
||||
<Content Include="res\js\ccv.js" />
|
||||
<Content Include="res\js\jquery-3.2.1.min.js" />
|
||||
<Content Include="res\js\jquery.facedetection.js" />
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<title>领料确认单</title>
|
||||
<link href="../../res/css/common.css" rel="stylesheet" type="text/css" />
|
||||
|
||||
<script src="../../res/js/dtpweb-material-label.js?v=2"></script>
|
||||
<style type="text/css">
|
||||
.customlabel
|
||||
{
|
||||
@@ -199,6 +200,12 @@
|
||||
Width="280px" Height="120px" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr align="center">
|
||||
<td align="center" valign="top" style="padding-top:20px">
|
||||
<asp:Button ID="btnDpPrinter" runat="server" Text="DP打印" CssClass="buttonfont"
|
||||
OnClick="btnDpPrinter_Click" Width="280px" Height="120px" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</td>
|
||||
|
||||
@@ -236,6 +236,17 @@ namespace FineUIPro.Web.WeldMat.UsingSentMat
|
||||
#endregion
|
||||
|
||||
#region 打印
|
||||
protected void btnDpPrinter_Click(object sender, EventArgs e)
|
||||
{
|
||||
string usingMatId = Request.Params["keyId"];
|
||||
if (Request.Params["grid"] == "2")
|
||||
{
|
||||
usingMatId = RecycleMatService.GetRecycleMatById(usingMatId)?.UsingMatId;
|
||||
}
|
||||
|
||||
DtpWebMaterialLabel.RegisterPrint(usingMatId);
|
||||
}
|
||||
|
||||
protected void btnPrinter_Click(object sender, EventArgs e)
|
||||
{
|
||||
BLL.Common.FastReportService.ResetData();
|
||||
@@ -244,68 +255,8 @@ namespace FineUIPro.Web.WeldMat.UsingSentMat
|
||||
string keyId = Request.Params["keyId"];
|
||||
if (!string.IsNullOrEmpty(keyId))
|
||||
{
|
||||
string weldSpec = string.Empty;//规格
|
||||
string weldName = string.Empty;//材质牌号
|
||||
string welderName = string.Empty;//焊工姓名
|
||||
string number = string.Empty;//领用数量
|
||||
string storeName = string.Empty;//保管员
|
||||
string usingDate = string.Empty;//时间
|
||||
string weldTypeName = string.Empty;//焊材类型
|
||||
var material = BLL.UsingMatService.GetUsingMatById(keyId);
|
||||
if (material != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(material.WeldId))
|
||||
{
|
||||
var weldInfo = WeldInfoService.GetWeldInfoById(material.WeldId);
|
||||
if (weldInfo != null)
|
||||
{
|
||||
weldSpec = weldInfo.WeldSpec;
|
||||
weldName = weldInfo.WeldName;
|
||||
if (!string.IsNullOrEmpty(weldInfo.WeldTypeId))
|
||||
{
|
||||
var weldType = BLL.WeldTypeService.GetWeldTypeById(weldInfo.WeldTypeId);
|
||||
if (weldType != null)
|
||||
{
|
||||
weldTypeName = weldType.WeldTypeName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(material.UsingMan))
|
||||
{
|
||||
var welder = HJGL_PersonManageService.GetWelderByWenId(material.UsingMan);
|
||||
if (welder != null)
|
||||
{
|
||||
welderName = welder.WED_Name + "(" + welder.WED_Code + ")";
|
||||
}
|
||||
}
|
||||
if (weldTypeName == "焊丝" || weldTypeName == "焊条")
|
||||
{
|
||||
//number = material.Amount.HasValue && material.Amount > 0 ? material.Amount.Value.ToString("0.#") + "根" : material.TwoAmount.HasValue ? material.TwoAmount.Value.ToString("0.#") + "根" : "";
|
||||
number = (material.Amount.Value + material.TwoAmount.Value).ToString("0.#") + "根";
|
||||
}
|
||||
else
|
||||
{
|
||||
//number = material.Amount.HasValue && material.Amount > 0 ? material.Amount.Value.ToString("0.#") + "Kg" : material.TwoAmount.HasValue ? material.TwoAmount.Value.ToString("0#") + "Kg" : "";
|
||||
number = (material.Amount.Value + material.TwoAmount.Value).ToString("0.#") + "Kg";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(material.StoreMan))
|
||||
{
|
||||
var store = BLL.StoremanInfoService.GetStoremanById(material.StoreMan);
|
||||
if (store != null)
|
||||
{
|
||||
storeName = store.StoreName;
|
||||
}
|
||||
}
|
||||
usingDate = material.UsingDate.Value.ToShortDateString() + " " + material.UsingDate.Value.ToShortTimeString();
|
||||
}
|
||||
Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
|
||||
keyValuePairs.Add("WeldSpec", weldSpec);
|
||||
keyValuePairs.Add("WeldName", weldName);
|
||||
keyValuePairs.Add("WelderName", welderName);
|
||||
keyValuePairs.Add("Number", number);
|
||||
keyValuePairs.Add("StoreName", storeName);
|
||||
keyValuePairs.Add("UsingDate", usingDate);
|
||||
var keyValuePairs = BLL.UsingMatService.GetMaterialLabelParameters(material);
|
||||
BLL.Common.FastReportService.AddFastreportParameter(keyValuePairs);
|
||||
|
||||
string initTemplatePath = "";
|
||||
|
||||
@@ -173,6 +173,15 @@ namespace FineUIPro.Web.WeldMat.UsingSentMat {
|
||||
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Button btnPrinter;
|
||||
|
||||
/// <summary>
|
||||
/// btnDpPrinter 控件。
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 自动生成的字段。
|
||||
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Button btnDpPrinter;
|
||||
|
||||
/// <summary>
|
||||
/// Window2 控件。
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<head runat="server">
|
||||
<title>焊材领用查询</title>
|
||||
<link href="../../res/css/common.css" rel="stylesheet" type="text/css" />
|
||||
<script src="../../res/js/dtpweb-material-label.js?v=2"></script>
|
||||
</head>
|
||||
<body>
|
||||
<form id="form1" runat="server">
|
||||
@@ -150,6 +151,8 @@
|
||||
HeaderTextAlign="Center" TextAlign="Center" ToolTip="显示签名" />
|
||||
<f:LinkButtonField ID="lbtnPrint" HeaderText="打印" Icon="Printer" Width="80px" CommandName="print"
|
||||
HeaderTextAlign="Center" TextAlign="Center" ToolTip="打印材料标签" />
|
||||
<f:LinkButtonField ID="lbtnDpPrint" HeaderText="DP打印" Icon="Printer" Width="80px" CommandName="dpPrint"
|
||||
HeaderTextAlign="Center" TextAlign="Center" ToolTip="使用DP打印材料标签" />
|
||||
</Columns>
|
||||
<PageItems>
|
||||
<f:ToolbarSeparator ID="ToolbarSeparator1" runat="server">
|
||||
|
||||
@@ -231,72 +231,17 @@ namespace FineUIPro.Web.WeldMat.UsingSentMat
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.CommandName == "dpPrint")
|
||||
{
|
||||
DtpWebMaterialLabel.RegisterPrint(e.RowID);
|
||||
}
|
||||
|
||||
if (e.CommandName == "print")//打印材料标签
|
||||
{
|
||||
if (!string.IsNullOrEmpty(this.Grid1.SelectedRowID))
|
||||
{
|
||||
string weldSpec = string.Empty;//规格
|
||||
string weldName = string.Empty;//材质牌号
|
||||
string welderName = string.Empty;//焊工姓名
|
||||
string number = string.Empty;//流水号
|
||||
string storeName = string.Empty;//保管员
|
||||
string usingDate = string.Empty;//时间
|
||||
string weldTypeName = string.Empty;//焊材类型
|
||||
var material = BLL.UsingMatService.GetUsingMatById(this.Grid1.SelectedRowID);
|
||||
if (material != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(material.WeldId))
|
||||
{
|
||||
var weldInfo = WeldInfoService.GetWeldInfoById(material.WeldId);
|
||||
if (weldInfo != null)
|
||||
{
|
||||
weldSpec = weldInfo.WeldSpec;
|
||||
weldName = weldInfo.WeldName;
|
||||
if (!string.IsNullOrEmpty(weldInfo.WeldTypeId))
|
||||
{
|
||||
var weldType = BLL.WeldTypeService.GetWeldTypeById(weldInfo.WeldTypeId);
|
||||
if (weldType != null)
|
||||
{
|
||||
weldTypeName = weldType.WeldTypeName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(material.UsingMan))
|
||||
{
|
||||
var welder = HJGL_PersonManageService.GetWelderByWenId(material.UsingMan);
|
||||
if (welder != null)
|
||||
{
|
||||
welderName = welder.WED_Name + "(" + welder.WED_Code + ")";
|
||||
}
|
||||
}
|
||||
if (weldTypeName == "焊丝" || weldTypeName == "焊条")
|
||||
{
|
||||
//number = material.Amount.HasValue && material.Amount > 0 ? material.Amount.Value.ToString("0.#") + "根" : material.TwoAmount.HasValue ? material.TwoAmount.Value.ToString("0.#") + "根" : "";
|
||||
number = (material.Amount.Value + material.TwoAmount.Value).ToString("0.#") + "根";
|
||||
}
|
||||
else
|
||||
{
|
||||
//number = material.Amount.HasValue && material.Amount > 0 ? material.Amount.Value.ToString("0.#") + "Kg" : material.TwoAmount.HasValue ? material.TwoAmount.Value.ToString("0#") + "Kg" : "";
|
||||
number = (material.Amount.Value + material.TwoAmount.Value).ToString("0.#") + "Kg";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(material.StoreMan))
|
||||
{
|
||||
var store = BLL.StoremanInfoService.GetStoremanById(material.StoreMan);
|
||||
if (store != null)
|
||||
{
|
||||
storeName = store.StoreName;
|
||||
}
|
||||
}
|
||||
usingDate = material.UsingDate.Value.ToShortDateString() + " " + material.UsingDate.Value.ToShortTimeString();
|
||||
}
|
||||
Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
|
||||
keyValuePairs.Add("WeldSpec", weldSpec);
|
||||
keyValuePairs.Add("WeldName", weldName);
|
||||
keyValuePairs.Add("WelderName", welderName);
|
||||
keyValuePairs.Add("Number", number);
|
||||
keyValuePairs.Add("StoreName", storeName);
|
||||
keyValuePairs.Add("UsingDate", usingDate);
|
||||
var keyValuePairs = BLL.UsingMatService.GetMaterialLabelParameters(material);
|
||||
|
||||
BLL.Common.FastReportService.ResetData();
|
||||
BLL.Common.FastReportService.AddFastreportParameter(keyValuePairs);
|
||||
|
||||
@@ -209,6 +209,15 @@ namespace FineUIPro.Web.WeldMat.UsingSentMat {
|
||||
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||
/// </remarks>
|
||||
protected global::FineUIPro.LinkButtonField lbtnPrint;
|
||||
|
||||
/// <summary>
|
||||
/// lbtnDpPrint 控件。
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 自动生成的字段。
|
||||
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||
/// </remarks>
|
||||
protected global::FineUIPro.LinkButtonField lbtnDpPrint;
|
||||
|
||||
/// <summary>
|
||||
/// ToolbarSeparator1 控件。
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
window.DtpWebMaterialLabel = (() => {
|
||||
let submitting = false;
|
||||
|
||||
async function findPrinter() {
|
||||
// 只在查找打印机时尝试两个本机端口。
|
||||
for (const port of [15216, 35216]) {
|
||||
const origin = 'http://127.0.0.1:' + port;
|
||||
let printers;
|
||||
try {
|
||||
const response = await fetch(origin + '/lpapi/GetPrinters?onlyOnline=true&onlyLocal=true&onlySupported=true', {
|
||||
signal: AbortSignal.timeout(2500)
|
||||
});
|
||||
if (!response.ok) continue;
|
||||
const result = await response.json();
|
||||
if (result.statusCode !== 0) continue;
|
||||
printers = result.resultInfo.printers.filter(printer => /^DP30S(?:\W|$)/i.test(printer.name));
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
if (!printers.length) throw new Error('未检测到在线的 DP30S,请检查打印机电源和连接。');
|
||||
if (printers.length > 1) throw new Error('检测到多台 DP30S,请只保留用于打印材料标签的一台。');
|
||||
return { origin, name: printers[0].name };
|
||||
}
|
||||
throw new Error('无法连接本机 DTPWeb 打印助手,请启动助手并允许网站访问本地网络。');
|
||||
}
|
||||
|
||||
function buildJob(printerName, fields) {
|
||||
const rows = [
|
||||
['焊材牌号', fields.WeldName],
|
||||
['规 格', fields.WeldSpec],
|
||||
['领用数量', fields.Number],
|
||||
['焊工姓名', fields.WelderName],
|
||||
['保 管 员', fields.StoreName],
|
||||
['时 间', fields.UsingDate]
|
||||
];
|
||||
|
||||
// 按《材料标签.frx》将表格坐标换算为毫米,左边框内移约一个打印点。
|
||||
const leftMargin = 2;
|
||||
const left = leftMargin + 0.2, split = leftMargin + 11.75, right = leftMargin + 35.5;
|
||||
const rowHeight = 3.64, lineWidth = 0.2;
|
||||
const bottom = (rows.length + 1) * rowHeight;
|
||||
const page = [
|
||||
{ type: 'rectangle', x: left, y: rowHeight, width: right - left, height: bottom - rowHeight, lineWidth },
|
||||
{ type: 'line', x1: split, y1: rowHeight, x2: split, y2: bottom, lineWidth }
|
||||
];
|
||||
|
||||
function drawText(text, x, y, width) {
|
||||
if (!text) return;
|
||||
page.push({ type: 'text', text, x: x + 0.35, y, width: width - 0.7, height: rowHeight,
|
||||
fontName: '黑体', fontHeight: 2.12, autoReturn: 0, horizontalAlignment: 1, verticalAlignment: 1 });
|
||||
}
|
||||
|
||||
drawText('材料标签', left, 0, right - left);
|
||||
rows.forEach(([label, value], index) => {
|
||||
const y = (index + 1) * rowHeight;
|
||||
if (index > 0) page.push({ type: 'line', x1: left, y1: y, x2: right, y2: y, lineWidth });
|
||||
drawText(label, left, y, split - left);
|
||||
drawText(value, split, y, right - split);
|
||||
});
|
||||
|
||||
return { printerInfo: { printerName }, jobInfo: { jobWidth: 40, jobHeight: 30, orientation: 0, gapType: 2 }, jobPages: [page] };
|
||||
}
|
||||
|
||||
async function print(fields) {
|
||||
if (submitting) return;
|
||||
submitting = true;
|
||||
try {
|
||||
const printer = await findPrinter();
|
||||
const job = buildJob(printer.name, fields);
|
||||
let result;
|
||||
try {
|
||||
const response = await fetch(printer.origin + '/lpapi/Print?action=4096', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json; charset=utf-8' },
|
||||
body: JSON.stringify(job),
|
||||
signal: AbortSignal.timeout(10000)
|
||||
});
|
||||
if (response.ok) result = await response.json();
|
||||
} catch {
|
||||
// 打印请求可能已经到达助手,重发前需核对出纸情况。
|
||||
}
|
||||
if (!result) throw new Error('未能确认打印结果,请检查出纸情况后再试。');
|
||||
if (result.statusCode !== 0) throw new Error('DTPWeb 返回打印失败,错误码:' + result.statusCode);
|
||||
F.notify({ message: '材料标签打印任务已提交。', target: '_top' });
|
||||
} catch (error) {
|
||||
window.alert(error.message);
|
||||
} finally {
|
||||
submitting = false;
|
||||
}
|
||||
}
|
||||
|
||||
return { print };
|
||||
})();
|
||||
Reference in New Issue
Block a user