2

私はプログラミングが初めてです。

多くのプリンターに接続されている 1 台のコンピューターを使用しているため、プリンターをデフォルトとして設定せずに Zebra プリンターに直接印刷したいと考えています。クリックされる

どうすればこれを達成できますか? 前もって感謝します。

プリンターが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();
    }   
%>
4

1 に答える 1

1

システムのプリンターのリストにプリンターがリストされていますか? もしそうなら、あなたは使用することができます

PrintDocument pd = new PrintDocument();
pd.PrinterSettings.PrinterName = "Zebra Printer";

// Do stuff formatting your document, like drawing strings and images (possibly a zebra?)

if(pd.PrinterSettings.IsValid) pd.Print();
else MessageBox.Show("Printer is invalid.");

注: 別のフォーラムのこのスレッドからこれを取得しましたが、特定のプリンターがデフォルトのプリンターかどうかわからない場合は、同様の方法を使用して特定のプリンターに印刷しています。

あなたはおそらく Web サイトを使用していることに気づきました。上記の方法は、デフォルトのプリンターを選択するためにサーバー側で使用する場合にのみ使用できます。

これがクライアント側で実行できるかどうかはわかりませんが、疑わしいです。これにより、Web サイトがクライアントのコンピューターにアクセスできるようになり、これは重大なセキュリティ違反です。ユーザーが使用するプリンターを選択できる印刷ダイアログを表示する必要があると思います。

于 2013-06-13T11:04:26.273 に答える