You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
3.7 KiB
125 lines
3.7 KiB
3 years ago
|
@{
|
||
|
ViewData["Title"] = "测试";
|
||
|
Layout = "~/Views/Shared/_Index.cshtml";
|
||
|
}
|
||
|
|
||
|
<OBJECT ID="ObjPrint" style="display:none" CLASSID="CLSID:{A12BED81-5E58-464C-A074-A686891B5B15}" codebase="PRINTOCX.ocx">
|
||
|
</OBJECT>
|
||
|
|
||
|
<form id="form1" name="form1">
|
||
|
<input type="button" value="走纸" onclick="FeedPaper()">
|
||
|
<input type="button" value="打印" onclick="PrintString()">
|
||
|
<input type="button" value="切纸" onclick="CutPaper()">
|
||
|
<input type="button" value="版本 " onclick="TestAbout()">
|
||
|
</form>
|
||
|
|
||
|
<script language="javascript">
|
||
|
Object.assign = Object.assign || function (target) {
|
||
|
'use strict';
|
||
|
if (target == null) {
|
||
|
throw new TypeError('Cannot convert undefined or null to object');
|
||
|
}
|
||
|
|
||
|
target = Object(0,target);
|
||
|
for (var index = 1; index < arguments.length; index++) {
|
||
|
var source = arguments[index];
|
||
|
if (source != null) {
|
||
|
for (var key in source) {
|
||
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
||
|
target[key] = source[key];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return target;
|
||
|
};
|
||
|
|
||
|
var printManager = {
|
||
|
obj: null,//oxc对象
|
||
|
param: {
|
||
|
port: 13,
|
||
|
baudRate: 0
|
||
|
//port: 0x04837540,
|
||
|
//baudRate: 38400
|
||
|
},
|
||
|
init: function (obj, param) {
|
||
|
this.obj = obj;
|
||
|
console.log(obj);
|
||
|
Object.assign(this.param, param);//ie下需兼容(已兼容,/View/Shared/_Index.cshtml)
|
||
|
},
|
||
|
//切纸
|
||
|
cutPaper: function () {
|
||
|
var obj = this.obj;
|
||
|
return obj.CutPaper(this.param.port, this.param.baudRate);
|
||
|
},
|
||
|
//走纸(iMm,单位毫米,让打印机走纸)
|
||
|
feedPaper: function (iMn) {
|
||
|
var obj = this.obj;
|
||
|
return obj.FeedPaper(this.param.port, this.param.baudRate, iMn);
|
||
|
},
|
||
|
//打印字符串(str, 要打印的字符串,后面带回车符,马上打印出字符串,后面没带回车符,要满行时或使用走纸命令FeedPaper才会打印出字符串)
|
||
|
printString: function (str) {
|
||
|
var obj = this.obj;
|
||
|
return obj.PrintString(this.param.port, this.param.baudRate, str, str.length);
|
||
|
},
|
||
|
//打印 code39 条形码(str,要打印条码的条码内容字符串)
|
||
|
printCode39: function (str) {
|
||
|
var obj = this.obj;
|
||
|
return obj.PrintCode39(this.param.port, this.param.baudRate, str, str.length);
|
||
|
},
|
||
|
//打印运单
|
||
|
printBill: function (billEntity) {
|
||
|
var content = "";
|
||
|
//content += "运单号:\t" + billEntity.SerialNumber + "\n";
|
||
|
//content += "场地:\t" + billEntity.SiteName + "\n";
|
||
|
//content += "供应商:\t" + billEntity.SupplierName + "\n";
|
||
|
//content += "运输员:\t" + billEntity.DriverName + "\n";
|
||
|
//content += "运输车:\t" + billEntity.LicensePlate + "\n";
|
||
|
//content += "料号:\t" + billEntity.MaterialNo + "\n";
|
||
|
//content += "运单重量:\t" + billEntity.BillWeight + "\n";
|
||
|
//content += "入场重量:\t" + billEntity.InWeight + "\n";
|
||
|
//content += "出场重量:\t" + billEntity.OutWeight + "\n";
|
||
|
//content += "实际重量:\t" + billEntity.NetWeight + "\n";
|
||
|
//content += "入场时间:\t" + billEntity.InStartTime + "\n";
|
||
|
//content += "出场时间:\t" + billEntity.OutFinishTime + "\n";
|
||
|
this.printString(content);
|
||
|
},
|
||
|
//关于
|
||
|
aboutBox: function () {
|
||
|
var obj = this.obj;
|
||
|
obj.AboutBox();
|
||
|
obj.GetVersion();
|
||
|
},
|
||
|
canUse: function () {
|
||
|
var obj = this.obj;
|
||
|
return (!!obj && !!obj.PrintString && typeof (obj.PrintString) == "unknown");
|
||
|
},
|
||
|
showAlert: function (msg) {
|
||
|
alert(msg);
|
||
|
},
|
||
|
showConsole: function (msg) {
|
||
|
console.log(msg);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var objPrint = document.getElementById("ObjPrint");
|
||
|
printManager.init(objPrint);
|
||
|
|
||
|
function FeedPaper() {
|
||
|
console.log(printManager.feedPaper(1));
|
||
|
}
|
||
|
|
||
|
function PrintString() {
|
||
|
console.log(printManager.printString("123456789\n"));
|
||
|
}
|
||
|
|
||
|
function CutPaper() {
|
||
|
console.log(printManager.cutPaper());
|
||
|
}
|
||
|
|
||
|
function TestAbout() {
|
||
|
printManager.aboutBox();
|
||
|
}
|
||
|
|
||
|
</script>
|