天津投入产出系统后端
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.
 
 
 
 
 
 

281 lines
9.1 KiB

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using EQUIPINTERFACETEST;
namespace QM.Assist
{
public class PrintUtil
{
/// <summary>
/// 条码打印队列1
/// </summary>
public static List<LabelInfo> LabelList1 = new List<LabelInfo>();
/// <summary>
/// 条码打印队列2(PDF虚拟打印机)
/// </summary>
public static List<LabelInfo> LabelList2 = new List<LabelInfo>();
int count1 = 0;
/// <summary>
/// 截取字符串函数每行放20个字符
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
private string[] strSplit(string str)
{
//计数如果大于20则放弃
string[] tempStr = new string[3];
int strNo = 0;
//分解的次数
int number = 0;
string strTemp = string.Empty;
for (int i = 0; i < str.Length; i++)
{
strTemp = str.Substring(i, 1);
byte[] strByte = Encoding.Default.GetBytes(strTemp);
if (strNo + strByte.Length <= 20)
{
strNo += strByte.Length;
tempStr[number] = tempStr[number] + strTemp;
}
else
{
strNo = strByte.Length;
number += 1;
tempStr[number] = tempStr[number] + strTemp;
}
}
return tempStr;
}
/// <summary>
/// 打印条码2(PDF)
/// </summary>
public void PrintLabel2(string proPath, string temPath, string dataPath)
{
/*************************************测试用***********************************************************************************************************/
#region
while (true)
{
WriteLog.Write("1");
count1 = LabelList2.Count;
System.Diagnostics.Process[] thisproc = System.Diagnostics.Process.GetProcessesByName("Lmwprint");
if (thisproc.Length == 0)
{
#region
if (count1 > 0)
{
WriteLog.Write("2");
ModifyDataBase2(dataPath);
try
{
WriteLog.Write("3");
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "\"" + proPath + "\"";
proc.StartInfo.Arguments = " \"" + temPath + "\"";
proc.Start();
for (int i = 0; i < count1; i++)
{
LabelList2.RemoveAt(0);
}
WriteLog.Write("4");
break;
}
catch (Exception ex)
{
WriteLog.Write(ex.Message);
throw ex;
}
}
#endregion
}
else
{
thisproc[0].Kill();
}
WriteLog.Write("5");
System.Threading.Thread.Sleep(1000);
}
#endregion
}
/// <summary>
/// 修改2号条码数据文件(PDF)
/// </summary>
private void ModifyDataBase2(string dataPath)
{
#region
WriteLog.Write("ModifyDataBase2-1");
while (true)
{
try
{
WriteLog.Write("ModifyDataBase2-2");
string head = System.IO.File.ReadAllLines(dataPath, Encoding.ASCII)[0];
string[] lines = new string[count1 + 1];
lines[0] = head;
for (int i = 1; i <= count1; i++)
{
lines[i] = LabelList2[i - 1].BarCode;
//QM.Assist.ExceptionUtil.WriteTrace(lines[i]);
}
WriteLog.Write("ModifyDataBase2-3");
System.IO.File.WriteAllLines(dataPath, lines, Encoding.Default);
lines = null;
break;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
/// <summary>
/// 打印条码
/// </summary>
public void PrintLabel()
{
#region
while (true)
{
count1 = LabelList2.Count;
System.Diagnostics.Process[] thisproc = System.Diagnostics.Process.GetProcessesByName("Lmwprint");
if (thisproc.Length == 0)
{
if (count1 > 0)
{
ModifyDataBase();
try
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "\"" + "程序文件" + "\"";
proc.StartInfo.Arguments = " \"" + "模板文件" + "\"";
proc.Start();
for (int i = 0; i < count1; i++)
{
LabelList2.RemoveAt(0);
}
break;
}
catch (Exception ex)
{
throw ex;
}
}
}
else
{
thisproc[0].Kill();
}
System.Threading.Thread.Sleep(1000);
}
#endregion
}
/// <summary>
/// 修改2号条码数据文件(PDF)
/// </summary>
private void ModifyDataBase()
{
#region
while (true)
{
try
{
string head = System.IO.File.ReadAllLines("数据文件", Encoding.ASCII)[0];
string[] lines = new string[count1 + 1];
lines[0] = head;
for (int i = 1; i <= count1; i++)
{
lines[i] = LabelList2[i - 1].LabelData.Rows[0]["LABELID"].ToString()
+ "," + "零件号 " + LabelList2[i - 1].LabelData.Rows[0]["MATNO"].ToString()
+ "," + LabelList2[i - 1].LabelData.Rows[0]["ITEMNAME"].ToString()
+ "," + LabelList2[i - 1].LabelData.Rows[0]["MATNAME"].ToString()
+ "," + LabelList2[i - 1].LabelData.Rows[0]["PACKAAGEQUAN"].ToString()
+ "," + LabelList2[i - 1].LabelData.Rows[0]["COLOR"].ToString()
+ "," + LabelList2[i - 1].LabelData.Rows[0]["SIZE"].ToString()
+ "," + LabelList2[i - 1].LabelData.Rows[0]["WEIGHT"].ToString()
+ "," + LabelList2[i - 1].LabelData.Rows[0]["BATCH"].ToString()
+ "," + "供应商编号 " + LabelList2[i - 1].LabelData.Rows[0]["VENDORID"].ToString()
+ "," + LabelList2[i - 1].LabelData.Rows[0]["VENDORNAME"].ToString();
//QM.Assist.ExceptionUtil.WriteTrace(lines[i]);
}
System.IO.File.WriteAllLines("数据文件", lines, Encoding.Default);
lines = null;
break;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
public static class BarCode
{
public static string Get128CodeString(string inputData)
{
string result;
int checksum = 104;
for (int ii = 0; ii < inputData.Length; ii++)
{
if (inputData[ii] >= 32)
{
checksum += (inputData[ii] - 32) * (ii + 1);
}
else
{
checksum += (inputData[ii] + 64) * (ii + 1);
}
}
checksum = checksum % 103;
if (checksum < 95)
{
checksum += 32;
}
else
{
checksum += 100;
}
result = Convert.ToChar(204) + inputData + Convert.ToChar(checksum) + Convert.ToChar(206);
return result;
}
}
}
}