public object Format(PrintTemplate template, PrintTemplateItem item, long shopId) { var shop = ServiceContainer.GetService <ShopService>().GetById(shopId); if (shop == null || string.IsNullOrWhiteSpace(shop.Mark)) { return(""); } string file = System.IO.Path.Combine(EnvironmentDirHelper.DIR_DATA, shop.Mark + ".png"); if (File.Exists(file) == false) { file = System.IO.Path.Combine(EnvironmentDirHelper.DIR_DATA, shop.Mark + ".jpg"); } if (File.Exists(file) == false) { return(null); } var bi = new BitmapImage(); bi.BeginInit(); bi.UriSource = new Uri(file); bi.EndInit(); return(bi); }
private string GetPrintTemplateByName(int type, string templateName, string loginDomain, string loginSite) { PrintTemplate printTemplate = _dbContext.Set <PrintTemplate>().Where(p => p.Type == type).FirstOrDefault(); if (printTemplate != null) { // site at first printTemplate = _dbContext.Set <PrintTemplate>().Where(p => p.Type == type && p.Site == loginSite && p.TemplateName == templateName).FirstOrDefault(); if (printTemplate != null) { return(generatePrintTemplate(printTemplate)); } // domain then printTemplate = _dbContext.Set <PrintTemplate>().Where(p => p.Type == type && p.Domain == loginDomain && p.TemplateName == templateName).FirstOrDefault(); if (printTemplate != null) { return(generatePrintTemplate(printTemplate)); } // global printTemplate = _dbContext.Set <PrintTemplate>().Where(p => p.Type == type && p.TemplateName == templateName).FirstOrDefault(); if (printTemplate != null) { return(generatePrintTemplate(printTemplate)); } } return(string.Empty); }
private async void InitializeTemplate(PrintTemplate template) { PrintTemplate = new PrintTemplateWrapper(template); if (ModelWrappers != null) { _interpreter.Context = new Context(template.Template); _interpreter.Expression = Expression.IndexExpression; _interpreter.Wrappers = ModelWrappers; var intepretedTemplate = _interpreter.GetInterpretedContext(); PrintTemplate.Template = intepretedTemplate.Output; IsNavigationBarVisible = true; PrintTemplates.Clear(); var templates = await _templeteRepository.GetAllAsync(); foreach (var temp in templates) { PrintTemplates.Add(temp); } } PrintTemplate.PropertyChanged += (s, a) => { if (!HasChanges) { HasChanges = _templeteRepository.HasChanges(); SaveCommand.RaiseCanExecuteChanged(); } }; SaveCommand.RaiseCanExecuteChanged(); }
public PrintTemplateItemViewModelForImage(PrintTemplate template) : base(template) { this.PropertyUI = new PrintTemplateItemImageUserControl(); this.PropertyUI.DataContext = this; this.PreviewValue = new Image(); }
public PrintTemplateItemViewModelForDate(PrintTemplate template) : base(template) { this.PropertyUI = new PrintTemplateItemDateUserControl(); this.PropertyUI.DataContext = this; this.Format = "yyyy MM dd"; }
private void tbNewDeliveryPrintTemplate_Click(object sender, RoutedEventArgs e) { try { string name = this.tbNewDeliverPrintTemplateName.Text.Trim(); if (string.IsNullOrWhiteSpace(name)) { MessageBox.Show("模板名称不能为空"); return; } if (this.deliveryTemplates.Any(obj => obj.Name == name)) { MessageBox.Show("已存在相同的模板名称"); return; } PrintTemplate deliveryTemplate = new PrintTemplate { Name = name }; PrintTemplateService.InsertLocal(deliveryTemplate); this.deliveryTemplates.Add(deliveryTemplate); this.lstDeliveryPrintTemplates.SelectedItem = deliveryTemplate; } catch (Exception ex) { MessageBox.Show(ex.Message, "添加失败"); } }
public PrintTemplateItemViewModelForText(PrintTemplate template) : base(template) { this.PropertyUI = new PrintTemplateItemTextUserControl(); this.PropertyUI.DataContext = this; this.Format = "自定义文本"; }
public void StartPrint(T[] values, string printer, bool showPrinterDialog, PrintTemplate template) { if (template == null) { throw new Exception("打印失败参数:template 为空"); } if (values == null) { throw new Exception("打印失败参数:vlaues 为空"); } if (values.Length == 0) { throw new Exception("打印失败参数:vlaues 没有数据"); } if (values.Any(obj => obj == null)) { throw new Exception("打印失败参数:vlaues 中含有空对象"); } System.Drawing.Printing.PrintDocument document = new System.Drawing.Printing.PrintDocument(); if (showPrinterDialog == false) { if (string.IsNullOrWhiteSpace(printer)) { throw new Exception("打印机名称为空,请设置打印机"); } if (System.Drawing.Printing.PrinterSettings.InstalledPrinters.OfType <string>().Contains(printer) == false) { throw new Exception("打印机不存在此电脑上:" + printer); } document.PrinterSettings.PrinterName = printer; } else { var pd = new System.Windows.Forms.PrintDialog() { UseEXDialog = true }; var ret = pd.ShowDialog(); if (ret != System.Windows.Forms.DialogResult.OK && ret != System.Windows.Forms.DialogResult.Yes) { return; } document.PrinterSettings.PrinterName = pd.PrinterSettings.PrinterName; } document.PrintController = new System.Drawing.Printing.StandardPrintController(); document.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("shoperp_print_size", (int)MapToPrinterPix(template.Width), (int)MapToPrinterPix(template.Height)); document.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0); document.DocumentName = template.Name + DateTime.Now; document.PrintPage += Document_PrintPage; document.BeginPrint += Document_BeginPrint; document.EndPrint += Document_EndPrint; this.index = 0; this.Values = values; this.Template = template; document.Print(); }
private Templator(string templateFilePath) { var xs = new XmlSerializer(typeof(PrintTemplate)); using (var stream = File.OpenRead(templateFilePath)) { this.PrintTemplate = (PrintTemplate)xs.Deserialize(stream); } }
public ShowHtmlDataDto GetReportViewer2(string reportID, string loginDomain, string loginSite, string printTemplateID) { List <ProcedureDto> procedureDtos = GetProcedureByReportID(reportID).ToList(); ProcedureDto procedure = procedureDtos[0]; DataTable dt; string templateInfo = ""; //use store procedure Order order = _dbContext.Set <Order>().Where(p => p.UniqueID == procedure.OrderID).FirstOrDefault(); string accNo = order.AccNo; string modalityType = procedure.ModalityType; ReportDBService reportDBService = new ReportDBService(); string templateID = ""; reportDBService.GetReportPrintTemplate(accNo, modalityType, reportID, loginSite, out templateID, out dt); //print templateID if (!string.IsNullOrEmpty(printTemplateID)) { Report report = _dbContext.Set <Report>().Where(r => r.UniqueID == reportID).FirstOrDefault(); if (report != null && report.Status < (int)RPStatus.FirstApprove) { templateID = printTemplateID; } } if (templateID != "") { PrintTemplate printTemplate = _dbContext.Set <PrintTemplate>().Where(p => p.UniqueID == templateID).FirstOrDefault(); if (printTemplate != null) { templateInfo = generatePrintTemplate(printTemplate); } } else { return(null); } string templateGuid = ReportUtils.GetFirstRowValueFromDataSet(dt.DataSet, ReportCommon.FIELDNAME_tbReport__PrintTemplateGuid); DataTable newdt = generateDataTable4PrintingForReport(dt.DataSet, ref templateInfo, reportID, loginDomain); using (MemoryStream ms = new MemoryStream()) { BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(ms, newdt); return(new ShowHtmlDataDto { Template = templateInfo, data = Convert.ToBase64String(ms.ToArray()) }); } }
private PrintTemplate GetNewDetail() { var template = new PrintTemplate(); _templeteRepository.Add(template); IsToolbarVisible = true; return(template); }
public object Format(PrintTemplate template, PrintTemplateItem item, long shopId) { var shop = ServiceContainer.GetService <ShopService>().GetById(shopId); if (shop == null) { return(""); } return(shop.Mark); }
public object Format(PrintTemplate template, PrintTemplateItem item, OrderReturn or) { var ss = or.GoodsInfo.Split(new char[] { ',', ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); if (ss.Length > 0) { return(ss[0]); } throw new Exception("无法解析信息:" + or.GoodsInfo); }
public PrintTemplateItemViewModelForBarcode(PrintTemplate template) : base(template) { this.Format = BarcodeFormat.CODE_128.ToString(); this.Types = MultiFormatWriter.SupportedWriters.Select(obj => obj.ToString()).ToArray(); this.PropertyUI = new PrintTemplateItemBarcodeUserControl(); this.PropertyUI.DataContext = this; this.PreviewValue = new Image(); this.Value = "是"; this.Value1 = "699999999988"; }
public PdfRenderContext(PrintTemplate template) { this.PageSettings = template.PageSettings; this.Template = template; this.IsDebug = template.IsDebug; this.renderers.Add(new PdfText()); this.renderers.Add(new PdfLine()); this.renderers.Add(new PdfImage()); this.renderers.Add(new PdfRect()); }
public async Task <IActionResult> OnGetAsync(Guid?id, string contentType) { if (id == null) { return(NotFound()); } PrintTemplate = await _context.PrintTemplates.FirstOrDefaultAsync(m => m.Id == id); Order order = await _context.Orders .Include(o => o.AgencyCompany).ThenInclude(ac => ac.Person) .Include(o => o.Customer).ThenInclude(c => c.Person).ThenInclude(p => p.ApplicationUser) .Include(o => o.Customer).ThenInclude(c => c.Person.IdDocument).ThenInclude(d => d.DocumentType) .Include(o => o.Customer).ThenInclude(c => c.CustomerCompany) .Include(o => o.Manager).ThenInclude(m => m.Person) .Include(o => o.Manager).ThenInclude(m => m.PowerAttorneys) .Include(o => o.Manager).ThenInclude(m => m.AgencyOffice) .Include(o => o.OrderStatus) .Include(o => o.TouroperatorBrand) .Include(o => o.Touroperators).ThenInclude(t => t.TouroperatorCompany) .Include(o => o.Services).ThenInclude(s => ((AccomodationService)s).Hotel) .Include(o => o.Services).ThenInclude(s => ((AccomodationService)s).Resort) .Include(o => o.Services).ThenInclude(s => ((AccomodationService)s).Country) .Include(o => o.Services).ThenInclude(s => ((AccomodationService)s).FoodType) .Include(o => o.Services).ThenInclude(s => ((AccomodationService)s).RoomType) .Include(o => o.Services).ThenInclude(s => ((TransportService)s).TransportType) .Include(o => o.Services).ThenInclude(s => ((TransferService)s).TransferType) .Include(o => o.Services).ThenInclude(s => ((InsuranceService)s).InsuranceCompany) .Include(o => o.Services).ThenInclude(s => ((InsuranceService)s).InsuranceType) .Include(o => o.Services).ThenInclude(s => ((VisaService)s).VisaType) .Include(o => o.Services).ThenInclude(s => s.CurrencyType) .IgnoreQueryFilters() .AsNoTracking().FirstOrDefaultAsync(m => m.Number == 0); DocumentContent = PrintTemplate.GetContent(order); if (PrintTemplate == null) { return(NotFound()); } if (contentType == "pdf") { return(new ViewAsPdf("DetailsPdf", DocumentContent)); } if (contentType == "html") { return(Content(WrapHtml(DocumentContent), "text/html; charset = utf-8")); } return(Page()); }
public static void UpdateLocal(PrintTemplate deliveryTemplate, string newName) { if (deliveryTemplate.Name.Equals(newName) == false) { var files = Directory.GetFiles(DATA_DIR, newName + FILE_EXTENSION); if (files.Count() > 0) { throw new Exception("已有相同模板名称存在"); } } DeleteLocal(deliveryTemplate.Name); deliveryTemplate.Name = newName; InsertLocal(deliveryTemplate); }
public async Task <IActionResult> OnGetAsync(Guid?id) { if (id == null) { return(NotFound()); } PrintTemplate = await _context.PrintTemplates.FirstOrDefaultAsync(m => m.Id == id); if (PrintTemplate == null) { return(NotFound()); } return(Page()); }
public object Format(PrintTemplate template, PrintTemplateItem item) { var af = template.AttachFiles.FirstOrDefault(obj => obj.Name == item.Format); if (af == null) { throw new Exception("图片不存在"); } System.Drawing.Image i = null; using (var ms = new MemoryStream(af.Value, false)) { i = System.Drawing.Image.FromStream(ms); } return(i); }
public object Format(PrintTemplate template, PrintTemplateItem item) { if (string.IsNullOrWhiteSpace(item.Format)) { item.Format = Brushes.Black.ToString(); } int argb = int.Parse(item.Format.Replace("#", ""), System.Globalization.NumberStyles.HexNumber); System.Drawing.Color c = System.Drawing.Color.FromArgb((int)(item.Opacity * 255), System.Drawing.Color.FromArgb(argb)); System.Drawing.Pen pen = new System.Drawing.Pen(c, (float)(item.Height > item.Width ? item.Width : item.Height)); pen.DashStyle = item.Value == "是" ? System.Drawing.Drawing2D.DashStyle.Dot : System.Drawing.Drawing2D.DashStyle.Solid; pen.DashCap = System.Drawing.Drawing2D.DashCap.Flat; pen.EndCap = System.Drawing.Drawing2D.LineCap.Flat; pen.StartCap = System.Drawing.Drawing2D.LineCap.Flat; return(pen); }
public async Task <IActionResult> OnGet(Guid?orderId, Guid?printId, string contentType) { PrintTemplate print = await _context.PrintTemplates.FindAsync(printId); Order order = await _context.Orders .Include(o => o.AgencyCompany).ThenInclude(ac => ac.Person) .Include(o => o.Customer).ThenInclude(c => c.Person).ThenInclude(p => p.ApplicationUser) .Include(o => o.Customer).ThenInclude(c => c.Person.IdDocument).ThenInclude(d => d.DocumentType) .Include(o => o.Customer).ThenInclude(c => c.CustomerCompany) .Include(o => o.Manager).ThenInclude(m => m.Person) .Include(o => o.Manager).ThenInclude(m => m.PowerAttorneys) .Include(o => o.Manager).ThenInclude(m => m.AgencyOffice) .Include(o => o.OrderStatus) .Include(o => o.TouroperatorBrand) .Include(o => o.Touroperators).ThenInclude(t => t.TouroperatorCompany) .Include(o => o.Services).ThenInclude(s => ((AccomodationService)s).Hotel) .Include(o => o.Services).ThenInclude(s => ((AccomodationService)s).Resort) .Include(o => o.Services).ThenInclude(s => ((AccomodationService)s).Country) .Include(o => o.Services).ThenInclude(s => ((AccomodationService)s).FoodType) .Include(o => o.Services).ThenInclude(s => ((AccomodationService)s).RoomType) .Include(o => o.Services).ThenInclude(s => ((TransportService)s).TransportType) .Include(o => o.Services).ThenInclude(s => ((TransferService)s).TransferType) .Include(o => o.Services).ThenInclude(s => ((InsuranceService)s).InsuranceCompany) .Include(o => o.Services).ThenInclude(s => ((InsuranceService)s).InsuranceType) .Include(o => o.Services).ThenInclude(s => ((VisaService)s).VisaType) .Include(o => o.Services).ThenInclude(s => s.CurrencyType) .FirstOrDefaultAsync(o => o.Id == orderId); DocumentContent = print.GetContent(order); if (contentType == "pdf") { string customSwitches = string.Format( $@"--footer-left ""Подпись: Заказчик____________________"" --footer-right ""Стр: [page] из [toPage]"" --footer-font-size ""8"" --footer-spacing ""2"" "); return(new ViewAsPdf("ViewAsPdf", DocumentContent) { CustomSwitches = customSwitches }); } if (contentType == "html") { return(Content(WrapHtml(DocumentContent), "text/html; charset = utf-8")); } return(Page()); }
public object Format(PrintTemplate template, PrintTemplateItem item, OrderGoods orderGoods) { string ma = "材质:"; if (orderGoods.GoodsId < 1) { return(ma); } var gu = ServiceContainer.GetService <GoodsService>().GetById(orderGoods.GoodsId); if (gu != null) { return(ma + gu.Material); } return(""); }
public async Task <IActionResult> OnPostAsync(Guid?id) { if (id == null) { return(NotFound()); } PrintTemplate = await _context.PrintTemplates.FindAsync(id); if (PrintTemplate != null) { PrintTemplate.IsDeleted = true; await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public static PrintTemplateItemViewModelCommon Create(PrintTemplate template, string type, string previewValue) { //退货类型 if (type == PrintTemplateItemType.RETURN_ORDERCHANDE_ID_BARCODE) { return(new PrintTemplateItemViewModelForBarcode(template)); } //其它 if (type == PrintTemplateItemType.OTHER_RANDOM) { return(new PrintTemplateItemViewModelForRandom(template) { PreviewValue = "DFF2-3" }); } if (type == PrintTemplateItemType.OTHER_BARCODE) { return(new PrintTemplateItemViewModelForBarcode(template)); } if (type == PrintTemplateItemType.OTHER_STATICTEXT) { return(new PrintTemplateItemViewModelForText(template)); } if (type == PrintTemplateItemType.OTHER_IMAGE) { return(new PrintTemplateItemViewModelForImage(template) { PreviewValue = "请选择图片" }); } if (type == PrintTemplateItemType.OTHER_LINE) { return(new PrintTemplateItemViewModelForLine(template)); } return(new PrintTemplateItemViewModelCommon(template) { PreviewValue = previewValue }); }
public ActionResult PrintDesignerSave(int?id, PrintTemplate item) { var account = User.Identity.GetAccount(); DataContext db = new DataContext(account.ApplicationId); string json = JsonConvert.SerializeObject(item); using (NpgsqlConnection connection = new NpgsqlConnection(db.ConnectionString)) { connection.Open(); NpgsqlCommand command = new NpgsqlCommand(); command.Connection = connection; if (id.HasValue) { command.CommandText = "select count(0) as cnt from printtemplate where content->>'name'='" + item.Name + "' and content->>'category'='" + item.Category + "' and id<>" + id.Value; int cnt = Convert.ToInt32(command.ExecuteScalar()); if (cnt > 0) { return(Json(new { message = "模板名称重复!" }, "text/plain")); } command.CommandText = "update printtemplate set content=@content where id=" + id.Value; } else { command.CommandText = "select count(0) as cnt from printtemplate where content->>'name'='" + item.Name + "' and content->>'category'='" + item.Category + "' "; int cnt = Convert.ToInt32(command.ExecuteScalar()); if (cnt > 0) { return(Json(new { message = "模板名称重复!" }, "text/plain")); } command.CommandText = "insert into printtemplate (content) values (@content)"; } command.Parameters.Add("content", NpgsqlTypes.NpgsqlDbType.Jsonb).Value = json.ToLower(); command.ExecuteNonQuery(); connection.Close(); } return(Json(new { message = "ok" }, "text/plain")); }
private void chkPrintPrv_CheckedChanged(object sender, EventArgs e) { try { if (chkPrintPrv.Checked) { chkPrintPrv.Text = "Generated Preview"; PrintPreviewControl ppc; PrintDocument docToPrint = new PrintDocument(); PaperSize psize = new PaperSize("Custom", 280, 300); ppc = new PrintPreviewControl(); ppc.Name = "PrintPreviewControl1"; ppc.Dock = DockStyle.Fill; ppc.Location = new Point(0, 0); ppc.Document = docToPrint; ppc.Zoom = 1; ppc.Document.DocumentName = "c:\\"; ppc.UseAntiAlias = true; ppc.Margin = new Padding(0); ppc.BackColor = Color.White; ppc.Document.DefaultPageSettings.PaperSize = psize; ppc.Document.PrintController = new StandardPrintController(); tpanelRptPrev.Controls.Clear(); tpanelRptPrev.Controls.Add(ppc, 0, 0); objPrintTemp = new PrintTemplate(); new PrintTemplate(CartData.GetData()); docToPrint.PrintPage += new PrintPageEventHandler(objPrintTemp.Default_Receipt); docToPrint.Dispose(); } else { chkPrintPrv.Text = "Print Preview"; tpanelRptPrev.Controls.Clear(); } } catch (Exception) { throw; } }
public object Format(PrintTemplate template, PrintTemplateItem item) { if (string.IsNullOrWhiteSpace(item.Format) || string.IsNullOrWhiteSpace(item.Value)) { throw new Exception("配置项参数不完整"); } char[] cc = new char[int.Parse(item.Value)]; for (int i = 0; i < cc.Length; i++) { int j = r.Next(item.Format.Length); cc[i] = item.Format[j]; } if (cc[0] == '-' && cc.Length > 1) { cc[0] = item.Format.FirstOrDefault(c => c != '-'); } return(item.Value1 + new string(cc)); }
public static void InsertLocal(PrintTemplate deliveryTemplate) { var keys = deliveryTemplate.AttachFiles.Select(obj => obj.Name).ToArray(); foreach (string key in keys) { if (deliveryTemplate.Items.Any(obj => obj.Id.ToString() == key) == false) { var af = deliveryTemplate.AttachFiles.FirstOrDefault(obj => obj.Name == key); deliveryTemplate.AttachFiles.Remove(af); } } string file = System.IO.Path.Combine(DATA_DIR, deliveryTemplate.Name + FILE_EXTENSION); using (Stream stream = new FileStream(file, FileMode.Create, FileAccess.Write)) { string content = Newtonsoft.Json.JsonConvert.SerializeObject(deliveryTemplate); var bytes = UTF8Encoding.UTF8.GetBytes(content); stream.Write(bytes, 0, bytes.Length); } }
public string GetReportViewer(string reportID, string loginDomain, string loginSite) { List <ProcedureDto> procedureDtos = GetProcedureByReportID(reportID).ToList(); ProcedureDto procedure = procedureDtos[0]; DataTable dt; string templateInfo = ""; //use store procedure Order order = _dbContext.Set <Order>().Where(p => p.UniqueID == procedure.OrderID).FirstOrDefault(); string accNo = order.AccNo; string modalityType = procedure.ModalityType; ReportDBService reportDBService = new ReportDBService(); string templateID = ""; reportDBService.GetReportPrintTemplate(accNo, modalityType, reportID, loginSite, out templateID, out dt); if (templateID != "") { PrintTemplate printTemplate = _dbContext.Set <PrintTemplate>().Where(p => p.UniqueID == templateID).FirstOrDefault(); if (printTemplate != null) { templateInfo = generatePrintTemplate(printTemplate); } } else { return(null); } string templateGuid = ReportUtils.GetFirstRowValueFromDataSet(dt.DataSet, ReportCommon.FIELDNAME_tbReport__PrintTemplateGuid); DataTable newdt = generateDataTable4PrintingForReport(dt.DataSet, ref templateInfo, reportID, loginDomain); DataSet newds = new DataSet(); newds.Tables.Add(newdt); //get html return(GetRenderedReportHtml(newds, templateInfo)); }
public object Format(PrintTemplate template, PrintTemplateItem item, OrderReturn or) { string vendorName = ""; var ss = or.GoodsInfo.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); if (ss.Length > 0) { vendorName = ss[0]; } if (string.IsNullOrWhiteSpace(vendorName)) { return(""); } var vens = ServiceContainer.GetService <VendorService>().GetVendorAddress_InCach(vendorName); if (string.IsNullOrWhiteSpace(vens)) { return(""); } var door = VendorService.FormatVendorDoor(vens); return(door); }