3. 打印
進行(xíng)相關參數(shù)設置後(指定打印機,設置模闆,設置打印數(shù)據),将指令通(tōng)過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 标簽打印開(kāi)發接口";
row["Field3"] = "901201251002404";
row["Field4"] = "325435";
prtdata.Rows.Add(row);
prtdata.AcceptChanges();
//指定打印機名稱
string selPrinter = "Deli DL-888C";
/*打印參數(shù)配置,打印數(shù)據設置*/
ConfigPrintSettings cfgData = new ConfigPrintSettings();
cfgData.XAction = "Print";
cfgData.XOpenId = openid;
cfgData.XTokens = token;
cfgData.ItemID = itemid;
/*指定打印機名稱,不使用默認打印機時(shí),為(wèi)空(kōng),則使用配置的打印機*/
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:\\臨時(shí)數(shù)據\\打印\\打印樣本\\智能制(zhì)造";
cfgData.TemplateName = "984.Lblx";
/*打印數(shù)據的類型,0-數(shù)組,1-Json數(shù)組,元素為(wèi)JSON對象,字段:值 , JSON.stringify(prtData) 2 Datatable*/
cfgData.PrintDataType = 2;
/*打印數(shù)據*/
cfgData.PrintData = prtdata;
return cfgData;
}