public int InsertBarTenderPrintConfigXX(BarTenderPrintConfigModelXX model) { DynamicParameters dp = new DynamicParameters(); dp.Add("@UserId", model.UserId, DbType.Int32, ParameterDirection.Input); dp.Add("@HostName", model.HostName, DbType.String, ParameterDirection.Input); dp.Add("@TemplateTypeId", model.TemplateTypeId, DbType.Int32, ParameterDirection.Input); dp.Add("@TemplateTypeName", model.TemplateTypeName, DbType.String, ParameterDirection.Input); dp.Add("@PrinterName", model.PrinterName, DbType.String, ParameterDirection.Input); dp.Add("@TemplatePerPage", model.TemplateSelectedItem.TemplatePerPage, DbType.Int32, ParameterDirection.Input); dp.Add("@TemplateFullName", model.TemplateSelectedItem.TemplateFullName, DbType.String, ParameterDirection.Input); dp.Add("@TemplateFileName", model.TemplateSelectedItem.TemplateFileName, DbType.String, ParameterDirection.Input); dp.Add("@TemplateFolderPath", model.TemplateSelectedItem.TemplateFolderPath, DbType.String, ParameterDirection.Input); dp.Add("@TemplateTotalPage", model.TemplateSelectedItem.TemplateTotalPage, DbType.Int32, ParameterDirection.Input); dp.Add("@TemplateDisplayName", model.TemplateSelectedItem.TemplateDisplayName, DbType.String, ParameterDirection.Input); string sql = @" insert into SJBarTenderPrintConfig(UserId,HostName,TemplateTypeId,TemplateTypeName,TemplateFullName,TemplateFileName,TemplatePerPage,PrinterName,TemplateFolderPath,TemplateTotalPage,TemplateDisplayName) values(@UserId,@HostName,@TemplateTypeId,@TemplateTypeName,@TemplateFullName,@TemplateFileName,@TemplatePerPage,@PrinterName,@TemplateFolderPath,@TemplateTotalPage,@TemplateDisplayName); select SCOPE_IDENTITY() as Id;"; using (var connection = SqlDb.UpdateConnection) { return(Convert.ToInt32(connection.ExecuteScalar(sql, dp))); } }
public bool UpdateBarTenderPrintConfigXX(BarTenderPrintConfigModelXX model) { DynamicParameters dp = new DynamicParameters(); dp.Add("@PrinterName", model.PrinterName, DbType.String, ParameterDirection.Input); dp.Add("@TemplatePerPage", model.TemplateSelectedItem.TemplatePerPage, DbType.Int32, ParameterDirection.Input); dp.Add("@TemplateFullName", model.TemplateSelectedItem.TemplateFullName, DbType.String, ParameterDirection.Input); dp.Add("@TemplateFileName", model.TemplateSelectedItem.TemplateFileName, DbType.String, ParameterDirection.Input); dp.Add("@TemplateFolderPath", model.TemplateSelectedItem.TemplateFolderPath, DbType.String, ParameterDirection.Input); dp.Add("@TemplateTotalPage", model.TemplateSelectedItem.TemplateTotalPage, DbType.Int32, ParameterDirection.Input); dp.Add("@TemplateDisplayName", model.TemplateSelectedItem.TemplateDisplayName, DbType.String, ParameterDirection.Input); dp.Add("@HostName", model.HostName, DbType.String, ParameterDirection.Input); dp.Add("@TemplateTypeId", model.TemplateTypeId, DbType.Int32, ParameterDirection.Input); dp.Add("@UserId", model.UserId, DbType.Int32, ParameterDirection.Input); string sql = @" update SJBarTenderPrintConfig set PrinterName=@PrinterName ,TemplateFullName=@TemplateFullName,TemplateFileName=@TemplateFileName,TemplatePerPage=@TemplatePerPage ,TemplateFolderPath=@TemplateFolderPath,TemplateTotalPage=@TemplateTotalPage,TemplateDisplayName=@TemplateDisplayName,ModifyTime =getdate() where UserId=@UserId and HostName =@HostName and TemplateTypeId = @TemplateTypeId ; " ; using (var connection = SqlDb.UpdateConnection) { return(connection.Execute(sql, dp) > 0); } }
private void GetExpressPrintConfig() { ExpressPrintConfig = CommonService.GetBarTenderPrintConfigXX(User.ID, 3, HostName); if (ExpressPrintConfig != null) { //ExpressTemplateSelectedItem = ExpressPrintConfig.ExpressTemplateSelectedItem; //验证打印机和模板路径是否存在 if (!File.Exists(ExpressPrintConfig.TemplateSelectedItem.TemplateFullName)) { MessageBox.Show(" 模板路径不存在,请手动选择模板目录 \r\n"); ExpressPrintConfig.TemplateSelectedItem = null; return; } if (!ComputerPrinters.Contains(ExpressPrintConfig.PrinterName)) { MessageBox.Show("打印机错误或不存在,请手动选择 打印机 \r\n"); ExpressPrintConfig.PrinterName = null; return; } ExpressTemplates = CommonService.GetTenderPrintTemplates(ExpressPrintConfig.TemplateSelectedItem.TemplateFolderPath); } else { ExpressPrintConfig = new BarTenderPrintConfigModelXX(); } }
private void InitData() { Task.Factory.StartNew(() => { PrintLSLists = new ObservableCollection <LabelPrintLSModel>(); ProductionDate = DateTime.Now.Date; HostConfig = CommonService.GetHostConfig(DataGridId, HostName, User.ID) ?? new HostConfigModel() { TypeId = DataGridId, Host = HostName, UserId = User.ID, TypeDesciption = "蓝思标签打印" }; ComputerPrinters = PrintHelper.GetComputerPrinters(); var config = CommonService.GetBarTenderPrintConfigXX(User.ID, DataGridId, HostName); if (config == null) { PrintConfiguration = new BarTenderPrintConfigModelXX { TemplateTypeId = DataGridId, HostName = HostName, UserId = User.ID, TemplateTypeName = "蓝思标签打印" } } ; else { PrintConfiguration = config; PirntTemplates = PrintHelper.GetTenderPrintTemplates(config.TemplateSelectedItem.TemplateFolderPath); } BarcodeTypeLists = CommonService.GetEnumLists(10); BarcodeTypeSelectedItem = BarcodeTypeLists.FirstOrDefault(); UIExecute.RunAsync(() => { QueryBaseCommand.Execute(null); }); }); }
// 验证打印参数是否选择 public static string VerifyPrintConfiguration(BarTenderPrintConfigModelXX config) { if (string.IsNullOrEmpty(config.PrinterName) || config.TemplateSelectedItem == null) { return("请选择模板和打印机"); } return(null); }
public static void VerifyPrintConfiguration(BarTenderPrintConfigModelXX config) { if (string.IsNullOrEmpty(config.PrinterName) || config.TemplateSelectedItem == null) { MessageBox.Show("请选择模板和打印机"); return; } }
public int SaveBarTenderPrintConfigXX(BarTenderPrintConfigModelXX model) { if (model.Id == 0) { return(InsertBarTenderPrintConfigXX(model)); } UpdateBarTenderPrintConfigXX(model); return(model.Id); }
public BaseViewModel() { CommonService = new CommonService(); Menu = MemoryCache.Default["PageCache"] as MainMenuModel; User = (MemoryCache.Default["UserCache"] as UserCacheModel).User; HostName = Dns.GetHostName(); DataGridId = Menu == null ? 0: Menu.ID * 10000 + 1; ComboBoxSearchService = new ComboBoxSearchService(); ExportHelper = new DataTableImportExportHelper(); DataGridManagementService = new DataGridManagementService(); UserDataId = CommonService.GetUserDataId(User, Menu == null ? 0 :Menu.ID); PrintConfiguration = new BarTenderPrintConfigModelXX(); }
public string BarTenderPrintLS <T>(IEnumerable <T> lists, BarTenderPrintConfigModelXX config) { string printerName = config.PrinterName; // 打印机名称 string templateName = config.TemplateSelectedItem.TemplateFullName; //通用模板名称 BarTender.Application btApp = new BarTender.Application(); try { // StringBuilder stringBuilder = new StringBuilder(); BarTender.Format btFormat = btApp.Formats.Open(templateName, false, ""); btFormat.PrintSetup.Printer = printerName; btFormat.PrintSetup.NumberSerializedLabels = 1; btFormat.PrintSetup.IdenticalCopiesOfLabel = 1; string nameValues = "," + btFormat.NamedSubStrings.GetAll("|", ","); Regex rg = new Regex(@",([^|]*)", RegexOptions.IgnoreCase); var fieldLists = GetTendarFieldName(nameValues.Replace(Environment.NewLine, ""), rg); foreach (var entry in lists) { SetTemplateNamedSubStringValueToPart(btFormat, fieldLists, entry); var s1 = btFormat.PrintOut(false, false); if (s1 != 0) { btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges); return("打印结果不正常,打开模板手动打印取消警告窗口"); } else { WriteRowHashValueLog(entry); } } return("打印成功"); } catch (Exception ex) { btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges); throw new Exception(ex.Message); } finally { if (btApp != null) { btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges); } } }
private void InitData() { Task.Factory.StartNew(() => { QueryParameter = new ProductionDeptLabelPrintA4QueryParameterModel { ProductionDate = DateTime.Now.Date }; PrintHistoryLists = new ObservableCollection <LabelPrintHistoryModel>(); HostConfig = CommonService.GetHostConfig(DataGridId, HostName, User.ID) ?? new HostConfigModel() { TypeId = DataGridId, Host = HostName, UserId = User.ID, TypeDesciption = "标签A4打印" }; ComputerPrinters = PrintHelper.GetComputerPrinters(); var config = CommonService.GetBarTenderPrintConfigXX(User.ID, DataGridId, HostName); if (config == null) { PrintConfiguration = new BarTenderPrintConfigModelXX { TemplateTypeId = DataGridId, HostName = HostName, UserId = User.ID, TemplateTypeName = "标签A4打印" } } ; else { PrintConfiguration = config; PirntTemplates = PrintHelper.GetTenderPrintA4Templates(config.TemplateSelectedItem.TemplateFolderPath); } var ss = _service.GetHistoryLists(CommonService.GetSqlWhereString(QueryParameter)); UIExecute.RunAsync(() => { ss.ForEach(x => PrintHistoryLists.Add(x)); }); }); }
public string BarTenderPrintA4WeightRem <T>(IEnumerable <T> lists, BarTenderPrintConfigModelXX config) { return(null); }
public string BarTenderPrintA4 <T>(IEnumerable <T> lists, BarTenderPrintConfigModelXX config, int totalPages) { string printerName = config.PrinterName; // 打印机名称 int templateTotalPage = config.TemplateSelectedItem.TemplateTotalPage; //一张A4纸里面的小张数 int pages = (int)Math.Ceiling(totalPages / (double)templateTotalPage); // 应该打印A4纸张数 int initPages = pages; //原始打印张数 int remainCount = totalPages % templateTotalPage; // 最后一个模板张数 string templateName = config.TemplateSelectedItem.TemplateFullName; //通用模板名称 string newtemplateName = remainCount == 0 ? Path.Combine(config.TemplateSelectedItem.TemplateFolderPath, $"1{config.TemplateSelectedItem.TemplateFileName.Substring(1)}") : Path.Combine(config.TemplateSelectedItem.TemplateFolderPath, $"{remainCount}{config.TemplateSelectedItem.TemplateFileName.Substring(1)}"); // 最后一个模板名称 BarTender.Application btApp = new BarTender.Application(); try { #region 整数张数数据打印 // 最多纸张模板 BarTender.Format btFormat = btApp.Formats.Open(templateName, false, ""); btFormat.PrintSetup.Printer = printerName; btFormat.PrintSetup.NumberSerializedLabels = 1; btFormat.PrintSetup.IdenticalCopiesOfLabel = 1; string nameValues = "," + btFormat.NamedSubStrings.GetAll("|", ","); Regex rg = new Regex(@",([^|]*)", RegexOptions.IgnoreCase); var fieldLists = GetTendarFieldName(nameValues.Replace(Environment.NewLine, ""), rg); // 剩余部分模板 BarTender.Format btFormat1 = null; List <string> fieldLists1 = new List <string>(); if (remainCount > 0) { btFormat1 = btApp.Formats.Open(newtemplateName, false, ""); btFormat1.PrintSetup.Printer = printerName; btFormat1.PrintSetup.NumberSerializedLabels = 1; btFormat1.PrintSetup.IdenticalCopiesOfLabel = 1; string nameValues1 = "," + btFormat1.NamedSubStrings.GetAll("|", ","); Regex rg1 = new Regex(@",([^|]*)", RegexOptions.IgnoreCase); fieldLists1 = GetTendarFieldName(nameValues1.Replace(Environment.NewLine, ""), rg1); } //对各个部分赋值 int beginPartId = 0; //StringBuilder logStrings = new StringBuilder(); foreach (var entry in lists) { //某行记录的打印张数,直接写日志 int printCount = GetPrintCountAndWriteLog(entry); // 如果本次打印张数超过一张A4纸上 while (printCount + beginPartId >= templateTotalPage) { for (int z = beginPartId; z < templateTotalPage; z++) { SetTemplateNamedSubStringValueToPartN(btFormat, fieldLists, entry, z); } printCount = printCount + beginPartId - templateTotalPage; beginPartId = 0; pages--; var s1 = btFormat.PrintOut(false, false); if (s1 != 0) { btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges); return("打印结果不正常,打开模板手动打印取消警告窗口"); } } //单条记录完全打印最后新开一张A4打印的数据(先部分赋值,和剩下行记录数据一起打印) if (printCount > 0) { for (int z = beginPartId; z < printCount + beginPartId; z++) { if (pages == 1 && remainCount > 0) //最后一页把值赋到第二个模板上 { SetTemplateNamedSubStringValueToPartN(btFormat1, fieldLists1, entry, z); } else { SetTemplateNamedSubStringValueToPartN(btFormat, fieldLists, entry, z); } } beginPartId += printCount; } } // 如果是最后一张A4的打印情况下, 新开模板赋值打印 if (pages == 1) { if (remainCount == 0) { var s111 = btFormat.PrintOut(false, false); btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges); if (s111 != 0) { btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges); return("打印结果不正常,打开模板手动打印取消警告窗口"); } } else { var s222 = btFormat1.PrintOut(false, false); btFormat1.Close(BarTender.BtSaveOptions.btDoNotSaveChanges); btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges); if (s222 != 0) { btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges); return("打印结果不正常,打开模板手动打印取消警告窗口"); } } } #endregion // 写日志 //new CommonService().ExecuteSqlAsyncReturns(logStrings.ToString()); return("打印成功"); } catch (Exception ex) { btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges); throw new Exception(ex.Message); } finally { if (btApp != null) { btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges); } } }
public bool BarTenderExpressPrint(BarTenderPrintConfigModelXX config, decimal formmainId) { string printerName = config.PrinterName; string templateName = config.TemplateSelectedItem.TemplateFullName; BarTender.Application btApp = new BarTender.Application(); try { var data = new OilSampleService().GetExpressPrintData(formmainId); BarTender.Format btFormat = btApp.Formats.Open(templateName, false, ""); btFormat.PrintSetup.Printer = printerName; string nameValues = "," + btFormat.NamedSubStrings.GetAll("|", ","); Regex rg = new Regex(@",([^|]*)", RegexOptions.IgnoreCase); var list = GetTendarFieldName(nameValues.Replace(Environment.NewLine, ""), rg); btFormat.PrintSetup.IdenticalCopiesOfLabel = 1; btFormat.PrintSetup.NumberSerializedLabels = 1; //btFormat.SetNamedSubStringValue("AA", data.SendName); if (list.Contains("SendName")) { btFormat.SetNamedSubStringValue("SendName", data.SendName); } if (list.Contains("SendPhone")) { btFormat.SetNamedSubStringValue("SendPhone", data.SendPhone); } if (list.Contains("SendCompanyName")) { btFormat.SetNamedSubStringValue("SendCompanyName", data.SendCompanyName); } if (list.Contains("SendAddress")) { btFormat.SetNamedSubStringValue("SendAddress", data.SendAddress); } if (list.Contains("ContractMan")) { btFormat.SetNamedSubStringValue("ContractMan", data.ContractMan); } if (list.Contains("ContractPhone")) { btFormat.SetNamedSubStringValue("ContractPhone", data.ContractPhone); } if (list.Contains("ContractCompanyName")) { btFormat.SetNamedSubStringValue("ContractCompanyName", data.ContractCompanyName); } if (list.Contains("ContractAddress")) { btFormat.SetNamedSubStringValue("ContractAddress", data.ContractAddress); } /* var s= 结果是0 可能是成功的意思 */ var s = btFormat.PrintOut(false, false); btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges); btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges); return(true); } catch (Exception ex) { btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges); throw new Exception(ex.Message); } finally { if (btApp != null) { btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges); } } }