| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Windows.Forms;
- using UAS_MES_NEW.DataOperate;
- using UAS_MES_NEW.Entity;
- using UAS_MES_NEW.PublicMethod;
- using DEV_HDL = System.UInt32;
- using LABEL_TEMP_HDL = System.UInt32;
- namespace UAS_MES_NEW.Special
- {
- public partial class Special_RePrintRFID : Form
- {
- [DllImport("lib/Win32/libDSThermal.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
- public static extern UInt32 DSTP2x_Lib_Init(string pSzInitInfo, Int32 nInitInfoLen, StringBuilder pSzResult, ref int pResultLen);
- [DllImport("lib/Win32/libDSThermal.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
- public static extern UInt32 DSTP2x_Lib_Clear();
- [DllImport("lib/Win32/libDSThermal.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
- public static extern UInt32 DSTP2x_EnumDev(Int32 nEnumType, byte[] szEnumList, ref int pDevSize, ref int pDevNum);
- [DllImport("lib/Win32/libDSThermal.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
- public static extern UInt32 DSTP2x_ConnEnumeratedDev(string szDevName, ref DEV_HDL pDevHdl);
- [DllImport("lib/Win32/libDSThermal.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
- public static extern UInt32 DSTP2x_DisconnDev(DEV_HDL ullDevHdl);
- [DllImport("lib/Win32/libDSThermal.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
- public static extern UInt32 DSTP2x_SetPrnEmulation(DEV_HDL ullDevHdl, Int32 nEmulation);
- [DllImport("lib/Win32/libDSThermal.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
- public static extern UInt32 DSTP2x_SetImgDpi(DEV_HDL ullDevHdl, Int32 nDpi);
- [DllImport("lib/Win32/libDSThermal.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
- public static extern UInt32 DSTP2x_LoadLabelTmpl(string szFileName, ref LABEL_TEMP_HDL pLTHdl);
- [DllImport("lib/Win32/libDSThermal.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
- public static extern UInt32 DSTP2x_PrintTmpl(DEV_HDL ullDevHdl, LABEL_TEMP_HDL ullLTHdl, byte[] szOutFile, ref int pOutFileSize, byte[] szOutRFID, ref int pOutRFIDSize);
- [DllImport("lib/Win32/libDSThermal.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
- public static extern UInt32 DSTP2x_DeleteTmpl(LABEL_TEMP_HDL ullLTHdl);
- [DllImport("lib/Win32/libDSThermal.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
- public static extern UInt32 DSTP2x_SetTmplPrnMode(LABEL_TEMP_HDL ullLTHdl, Int32 nPrnMode);
- [DllImport("lib/Win32/libDSThermal.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
- public static extern UInt32 DSTP2x_SetTmplPrnData(LABEL_TEMP_HDL ullLTHdl, string szElemID, string szActualData);
- [DllImport("lib/Win32/libDSThermal.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
- public static extern UInt32 DSTP2x_SetTmplRFIDData(LABEL_TEMP_HDL ullLTHdl, string szElemID, string pActualData, Int32 nActualDataSize);
- DataHelper dh = SystemInf.dh;
- LogStringBuilder sql = new LogStringBuilder();
- DEV_HDL uRet = 0;
- DEV_HDL dev_prt = 0;
- LABEL_TEMP_HDL tmp_prt = 0;
- byte[] pEnumList = new byte[1024];
- int enumListLen = 1024;
- byte[] szOutFile = new byte[1024];
- int pOutFileSize = 1024;
- byte[] szOutRFID = new byte[1024];
- int pOutRFIDSize = 1024;
- int deviceNum = 0;
- string device = "";
- StringBuilder pSzResult = new StringBuilder(256);
- int pResultLen = 256;
- public Special_RePrintRFID()
- {
- InitializeComponent();
- }
- private void Clean_Click(object sender, EventArgs e)
- {
- OperateResult.Clear();
- }
- private void Special_CancelCollection_Load(object sender, EventArgs e)
- {
- }
- private void ms_sncode_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- DataTable dt = (DataTable)dh.ExecuteSql("select ms_sncode,ms_makecode,pr_code,pr_detail from makeserial left join product on pr_code=ms_prodcode where ms_sncode='" + ms_sncode.Text + "' order by ms_id desc", "select");
- if (dt.Rows.Count == 0)
- {
- OperateResult.AppendText("" + ms_sncode.Text + "不存在\n");
- return;
- }
- else
- {
- BaseUtil.SetFormValue(this.Controls, dt);
- }
- string tmpPath = PrintLabel.Text;
- uRet = DSTP2x_Lib_Init("", 0, pSzResult, ref pResultLen);
- if (uRet != 0)
- {
- OperateResult.AppendText("DSTP2x_Lib_Init,error code:[" + uRet.ToString() + "]");
- return;
- }
- uRet = DSTP2x_EnumDev(1, pEnumList, ref enumListLen, ref deviceNum); //USB connection
- if (uRet != 0)
- {
- OperateResult.AppendText("Enumerate device error,error code:[" + uRet.ToString() + "]");
- goto SAMPLE_END;
- }
- if (deviceNum > 1)
- {
- string str = Encoding.UTF8.GetString(pEnumList, 0, enumListLen);
- string[] enumList = str.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
- device = enumList[0];
- }
- else if (deviceNum == 1)
- device = Encoding.UTF8.GetString(pEnumList, 0, enumListLen);
- else
- {
- OperateResult.AppendText("No device");
- goto SAMPLE_END;
- }
- //3.Connect the device.
- uRet = DSTP2x_ConnEnumeratedDev(device, ref dev_prt);
- if (uRet != 0)
- {
- OperateResult.AppendText("Failed to connect device,error code:[" + uRet.ToString() + "]");
- goto SAMPLE_END;
- }
- //Non essential interface. 1-ZPL, 2-TSPL, 3-ESCPOS
- uRet = DSTP2x_SetPrnEmulation(dev_prt, 1); //ZPL
- if (uRet != 0)
- {
- OperateResult.AppendText("Failed to set up print simulation,error code:[" + uRet.ToString() + "]");
- goto SAMPLE_END;
- }
- //4.Load the template.
- uRet = DSTP2x_LoadLabelTmpl(tmpPath, ref tmp_prt);
- if (uRet != 0)
- {
- OperateResult.AppendText("Failed to load label template,error code:[" + uRet.ToString() + "]");
- goto SAMPLE_END;
- }
- //5.Set the print mode. 0-print, 1-generate the prn file, 2-generate the preview image.
- uRet = DSTP2x_SetTmplPrnMode(tmp_prt, 0); //set print mode
- if (uRet != 0)
- {
- OperateResult.AppendText("Setting whether to print failed,error code:[" + uRet.ToString() + "]");
- goto SAMPLE_END;
- }
- //6.Set the print data.
- uRet = DSTP2x_SetTmplPrnData(tmp_prt, "Text-01", ms_sncode.Text); //The data must be utf-8
- uRet = DSTP2x_SetTmplPrnData(tmp_prt, "Text-02", ms_sncode.Text); //The data must be utf-8
- if (uRet != 0)
- {
- OperateResult.AppendText("Failed to set someone data in template,error code:[" + uRet.ToString() + "]");
- goto SAMPLE_END;
- }
- //7.Set the RFID data.
- uRet = DSTP2x_SetTmplRFIDData(tmp_prt, "EPC-01", Hex.Checked ? AsciiToHex(ms_sncode.Text) : ms_sncode.Text, Hex.Checked ? AsciiToHex(ms_sncode.Text).Length : ms_sncode.Text.Length);
- if (uRet != 0)
- {
- OperateResult.AppendText("Failed to set EPC data in template,error code:[" + uRet.ToString() + "]");
- goto SAMPLE_END;
- }
- //uRet = DSTP2x_SetTmplRFIDData(tmp_prt, "USER-01", "123ABC", "123ABC".Length);
- //if (uRet != 0)
- //{
- // OperateResult.AppendText("Failed to set USER data in template,error code:[" + uRet.ToString() + "]");
- // goto SAMPLE_END;
- //}
- //8.Print template and get the RFID data.
- uRet = DSTP2x_PrintTmpl(dev_prt, tmp_prt, szOutFile, ref pOutFileSize, szOutRFID, ref pOutRFIDSize);
- if (uRet != 0)
- {
- OperateResult.AppendText("Print template failed,error code:[" + uRet.ToString() + "]");
- goto SAMPLE_END;
- }
- OperateResult.AppendText("The RFID data is " + Encoding.UTF8.GetString(szOutRFID, 0, pOutRFIDSize));
- //9.Delete the handle of template.
- uRet = DSTP2x_DeleteTmpl(tmp_prt);
- if (uRet != 0)
- {
- OperateResult.AppendText("Delete handle of template failed,error code:[" + uRet.ToString() + "]");
- goto SAMPLE_END;
- }
- //10.Disconnect the device.
- uRet = DSTP2x_DisconnDev(dev_prt);
- if (uRet != 0)
- {
- OperateResult.AppendText("Delete handle of device failed,error code:[" + uRet.ToString() + "]");
- goto SAMPLE_END;
- }
- SAMPLE_END:
- {
- uRet = DSTP2x_Lib_Clear();
- }
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "RFID补打印", "RFID打印成功", ms_sncode.Text, "");
- ms_sncode.Clear();
- }
- }
- static string AsciiToHex(string asciiString)
- {
- byte[] bytes = Encoding.ASCII.GetBytes(asciiString);
- return BitConverter.ToString(bytes).Replace("-", "").ToLower();
- }
- private void pr_code_TextChanged(object sender, EventArgs e)
- {
- DataTable dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault from label where la_prodcode='" + pr_code.Text + "' and la_templatetype='RFID' and la_statuscode='AUDITED' order by la_isdefault", "select");
- if (dt.Rows.Count == 0)
- {
- dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault from label where la_prodcode is null and la_templatetype='RFID' and la_statuscode='AUDITED' order by la_isdefault", "select");
- }
- PrintLabel.DataSource = dt;
- PrintLabel.DisplayMember = "la_url";
- PrintLabel.ValueMember = "la_id";
- }
- }
- }
|