120 lines
4.7 KiB
C#
120 lines
4.7 KiB
C#
using Lskj.Business.Impl;
|
|
using Lskj.Control;
|
|
using Lskj.Control.Model;
|
|
using Lskj.Util;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Lskj.PubArgoxPrint
|
|
{
|
|
public partial class FrmMain : BaseForm
|
|
{
|
|
public DynamicArgoxPrintModel Model;
|
|
public FrmMain()
|
|
{
|
|
InitializeComponent();
|
|
this.Opacity = 0;
|
|
this.Load += OnFrmMainLoad;
|
|
}
|
|
/// <summary>
|
|
/// 初始化
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnFrmMainLoad(object sender, EventArgs e)
|
|
{
|
|
WaitForm.ShowForm("正在打印中...");
|
|
try
|
|
{
|
|
string printSql = Model.MainPrintSql;
|
|
printSql = ReplaceHelper.ReplaceRowParam(Model.MaintabFocusedRow, Model.MainPrintSql);
|
|
DataTable printTable = BaseImpl.GetDataTableResult(printSql);
|
|
if (printTable == null || printTable.Rows.Count == 0)
|
|
{
|
|
MessageUtil.Show("没有打印数据");
|
|
return;
|
|
}
|
|
int nLen = PrintUtil.A_GetUSBBufferLen() + 1;
|
|
if (nLen <= 1)
|
|
{
|
|
MessageUtil.Show("打印机未连接");
|
|
return;
|
|
}
|
|
byte[] pbuf = new byte[128];
|
|
int len1 = 128;
|
|
int len2 = 128;
|
|
byte[] buf1 = new byte[len1];
|
|
byte[] buf2 = new byte[len2];
|
|
PrintUtil.A_EnumUSB(pbuf);
|
|
PrintUtil.A_GetUSBDeviceInfo(1, buf1, out len1, buf2, out len2);
|
|
int ret = PrintUtil.A_CreatePrn(12, Encoding.ASCII.GetString(buf2, 0, len2));//open usb.
|
|
if (ret != 0)
|
|
{
|
|
MessageBox.Show("打印启动失败");
|
|
return;
|
|
}
|
|
PrintUtil.A_Set_DebugDialog(0);
|
|
PrintUtil.A_Set_Unit('m');
|
|
PrintUtil.A_Set_Syssetting(1, 0, 0, 0, 0);
|
|
PrintUtil.A_Set_Darkness(13);
|
|
PrintUtil.A_Del_Graphic(1, "*");//delete all picture.
|
|
string[] locationxArray = Model.LocationX.Split(',');
|
|
string[] printArgsArray = Model.PrintArgs.Split(',');
|
|
int columnCount = locationxArray.Length;
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
for (int i = 0; i < printTable.Rows.Count; i++)
|
|
{
|
|
if (i % columnCount == 0)
|
|
{
|
|
PrintUtil.A_Clear_Memory();//clear memory.
|
|
}
|
|
DataRow printRow = printTable.Rows[i];
|
|
if (!string.IsNullOrEmpty(this.Model.AfterSql))
|
|
{
|
|
string str = ReplaceHelper.ReplaceRowParam(printRow, this.Model.AfterSql);
|
|
stringBuilder.AppendLine(str + ";");
|
|
}
|
|
for (int j = 0; j < printTable.Columns.Count; j++)
|
|
{
|
|
int locationX = int.TryParse(locationxArray[i % columnCount], out locationX) ? locationX : 0;
|
|
PrintModel printModel = new PrintModel(printArgsArray[j % columnCount].Split('_'));
|
|
string printValue = printRow[j] + "";
|
|
if (printModel.PrintType == 0)
|
|
{
|
|
PrintUtil.A_Prn_Text_TrueType(locationX + printModel.X, printModel.Y, printModel.FontSize, "Arial", 1, 400, 0, 0, 0, "AA", printValue, 1);
|
|
}
|
|
else if (printModel.PrintType == 1)
|
|
{
|
|
PrintUtil.A_Prn_Barcode(locationX + printModel.X, printModel.Y, 1, 'E', 1, 2, printModel.FontSize, 'N', 1, printValue);
|
|
}
|
|
}
|
|
if ((i % columnCount == columnCount - 1) || (i == printTable.Rows.Count - 1))
|
|
{
|
|
PrintUtil.A_Print_Out(1, 1, 1, 1);
|
|
}
|
|
}
|
|
if (!string.IsNullOrEmpty(stringBuilder.ToString()))
|
|
{
|
|
BaseImpl.ExecSqlValue(stringBuilder.ToString());
|
|
}
|
|
PrintUtil.A_ClosePrn();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageUtil.Show(ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
WaitForm.HideForm();
|
|
Close();
|
|
}
|
|
}
|
|
}
|
|
}
|