我是编程新手。
我想直接打印到 Zebra 打印机而不将打印机设置为默认值,因为我正在使用一台连接到多台打印机的计算机,并且请记住,当打印按钮时,我正在从 Web 浏览器获取记录/数据被点击
我怎样才能做到这一点?提前致谢。
如果打印机设置为 DEFAULTS,则以下代码可以正常工作
<%@ Page Language="C#" AutoEventWireup="true"%>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.IO" %>
<%
System.Web.Script.Serialization.JavaScriptSerializer jsoner = new System.Web.Script.Serialization.JavaScriptSerializer();
string UtiWayBillNumber =Request.QueryString["UtiWayBillNumber"];
string labelSerials = Request.QueryString["labelSerials"] ?? null;
string[] serialNumbers = labelSerials.Split('$');
using (SqlConnection dbConnection = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["HestoProductionControl"].ConnectionString))
{
dbConnection.Open();
SqlCommand cmd = dbConnection.CreateCommand();
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "GM_GetShipmentDetailInformation";
cmd.Parameters.AddWithValue("@utiWaybillNumber", UtiWayBillNumber);
SqlDataReader reader = cmd.ExecuteReader();
System.Collections.Generic.List<object> labelList = new List<object>();
string appPath = Request.PhysicalApplicationPath;
string IPAddress = HttpContext.Current.Request.UserHostAddress;
StringBuilder fileContents = new StringBuilder();
while (reader.Read())
{
if (labelSerials.StartsWith(" "))
{
DateTime date = DateTime.Now;
string quantity = reader["PackingQuantity"].ToString();
quantity = quantity.Remove(2,7);
fileContents.Append(reader["HestoBarcodeSerial"]);
fileContents.Append(",");
fileContents.Append(reader["CustomerStockCode"].ToString().Trim());
fileContents.Append(",");
fileContents.Append(quantity);
fileContents.Append(",");
fileContents.Append(reader["Description"].ToString().Trim());
fileContents.Append(",");
fileContents.Append(reader["StockCode"]);
fileContents.Append(",");
fileContents.Append(date.ToString("s"));
fileContents.Append(",");
fileContents.Append(reader["CustomerBarcodeSerial"]);
fileContents.Append("\r\n");
}
else{
DateTime date = DateTime.Now;
string quantity = reader["PackingQuantity"].ToString();
quantity = quantity.Remove(2,7);
if (serialNumbers.Contains<string>(reader["Serial"].ToString()) == false)
{
continue;
}
fileContents.Append(reader["HestoBarcodeSerial"]);
fileContents.Append(",");
fileContents.Append(reader["CustomerStockCode"].ToString().Trim());
fileContents.Append(",");
fileContents.Append(quantity);
fileContents.Append(",");
fileContents.Append(reader["Description"].ToString().Trim());
fileContents.Append(",");
fileContents.Append(reader["StockCode"]);
fileContents.Append(",");
fileContents.Append(date.ToString("s"));
fileContents.Append(",");
fileContents.Append(reader["CustomerBarcodeSerial"]);
fileContents.Append("\r\n");
}
};
Response.Write(fileContents.ToString());
Directory.CreateDirectory(appPath + "//PrintFile/" + IPAddress);
StreamWriter w;
w = File.CreateText(appPath + "//PrintFile/" + IPAddress + "/printLabels.txt");
w.WriteLine(fileContents.ToString());
w.Flush();
w.Close();
}
%>