• <video id="g6cmf"></video>
    C# 調用打印機API - APISample c# 標簽打印范例代碼,,C# 打印, C#實現打印,C#調用打印機, C# 打印API,C# 打印報表,CSharp標簽打印,CSharp單據打印 ,CCPrintingAPI , C# 打印范例代碼,C#標簽打印,條碼,二維碼標簽,C# 單據打印,很容易集成。
    CCPrintingAPI XI
    輕量、簡潔、穩定、可靠,通用的打印機API接口,支持近百個品牌,數千個型號打印機。
    打印機接口API C# 范例代碼
    C#
    CCPrintingAPI C# API打印范例代碼,C#調用打印機,調用CCPrintingAPI打印機接口API。

    1. 引入 CCPrintingApiNet.dll
    引入CCPrintingApiNet.dll后,即可使用API的相關方法,進行設置和打印操作。
    CCPrintingApiNet CCPrintingAPI = null;
    CCPrintingAPI = new CCPrintingApiNet();
    //獲取HID
    GetHID(m_OpenId, m_Tokens);
    //獲取所有打印機
    GetPrinters(m_OpenId, m_Tokens,6789);    
    //打印
    Print(m_OpenId, m_Tokens,6789);  
    2. 獲取打印機
    獲取計算機上所有打印機, 打印時,指定該列表的打印機名稱。如果能確保打印機名稱不變,該操作也可省去。
    public void GetPrinters(String openid,String token,int itemid){
         ConfigPrintSettings cfgData = new ConfigPrintSettings() ;
         cfgData.XAction = "Printers";
         cfgData.XOpenId = openid;
         cfgData.XTokens = token;
         cfgData.ItemID = itemid;
         CCPrintingAPI.Excute(cfgData, (status, arg0, sessionid) =>
                {
                    Console.WriteLine(string.Format("Excute Status:{0}, SessionId:{1}", status, sessionid));
                    if (arg0 == null || arg0.Length == 0) return;
                    Console.WriteLine(string.Format("Excute Result:{0}", string.Join(" ", arg0)));
                });
    }
    3. 打印
    進行相關參數設置后(指定打印機,設置模板,設置打印數據),將指令通過API傳給打印機。
    public void Print(String openid,String token,int itemid){
    ConfigPrintSettings cfgData = GetPrintSettings(openid, token, itemid);
    CCPrintingAPI.Excute(cfgData, (status, arg0, sessionid) =>
    {
         Console.WriteLine(string.Format("Excute Status:{0}, SessionId:{1}", status, sessionid));
          if (arg0 == null || arg0.Length == 0) return;
          Console.WriteLine(string.Format("Excute Result:{0}", string.Join(" ", arg0)));
      });
    }
    
      
    private ConfigPrintSettings GetPrintSettings(string openid, string token, int itemid)
    {
            DataTable prtdata = new DataTable("PrintData");
            prtdata.Columns.Add("Field1", typeof(string));
            prtdata.Columns.Add("Field2", typeof(string));
            prtdata.Columns.Add("Field3", typeof(string));
            prtdata.Columns.Add("Field4", typeof(string));
    
            DataRow row = prtdata.NewRow();
            row["Field1"] = "CCPrintingAPI";
            row["Field2"] = ".Net 標簽打印開發接口";
            row["Field3"] = "901201251002404";
            row["Field4"] = "325435";
            prtdata.Rows.Add(row);
            prtdata.AcceptChanges();
    
            //指定打印機名稱
            string selPrinter = "Deli DL-888C";
            /*打印參數配置,打印數據設置*/
            ConfigPrintSettings cfgData = new ConfigPrintSettings();
            cfgData.XAction = "Print";
            cfgData.XOpenId = openid;
            cfgData.XTokens = token;
            cfgData.ItemID = itemid;
            /*指定打印機名稱,不使用默認打印機時,為空,則使用配置的打印機*/
            cfgData.PrinterName = selPrinter;
            /*0-打印,3-獲取打印預覽*/
            cfgData.Preview = 0;
            /*模板方式,0-客戶端模板,1-遠程模板,2-如果本地模板存在,使用本地,不存在使用遠程模板,3-不使用模板*/
            cfgData.TemplateMode = 1;
            /*遠程模板URL*/
            cfgData.TemplateURL = "http://img.51321.cn/web/chicore/VPrinting/API";
            //cfgPrintSettings.TemplateURL = "E:\\臨時數據\\打印\\打印樣本\\智能制造";
            cfgData.TemplateName = "984.Lblx";
            /*打印數據的類型,0-數組,1-Json數組,元素為JSON對象,字段:值 , JSON.stringify(prtData) 2 Datatable*/
            cfgData.PrintDataType = 2;
            /*打印數據*/
            cfgData.PrintData = prtdata;
            return cfgData;
    }
    4. 讀取客戶端HID
    讀取安裝CCPrintingAPI的客戶端計算機HID,該HID可以用來標識計算機。該方法,根據需要使用。
    public void GetHID(String openid,String token){
    ConfigPrintSettings cfgData = new ConfigPrintSettings() ;
    cfgData.XAction = "HID";
    cfgData.XOpenId = openid;
    cfgData.XTokens = token;
    CCPrintingAPI.Excute(cfgData, (status, arg0, sessionid) =>
     {
            Console.WriteLine(string.Format("Excute Status:{0}, SessionId:{1}", status, sessionid));
             if (arg0 == null || arg0.Length == 0) return;
             Console.WriteLine(string.Format("Excute Result:{0}", string.Join(" ", arg0)));
       });
    }
    亚洲日本乱码一区二区在线二产线_亚洲欧美色中文字幕在线_国产精品美女久久久免费_加勒比无码专区中文字幕

  • <video id="g6cmf"></video>
    亚洲4444在线观看 | 亚洲国产精品大秀在线播放 | 三a视频在线观看日本 | 天天在线精品一区 | 亚洲2020香蕉在线观看 | 日韩一区二区三区精品视频 |