public string GetLoginQRCode() { var token = Guid.NewGuid().ToString("N"); var code = QRCode.Generate(SystemPlatform.FiiiShop, QRCodeEnum.FiiiPayLogin, token); return(code); }
private void btnGenerate_Click(object sender, EventArgs e) { if (lstTicket == null || lstTicket.Count == 0) { MessageBox.Show("Please search ticket order first", "Disneyland", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string tempPath = Application.StartupPath + $@"\TicketTemplate\{order.OrderId}"; Word.Application wapp = new Word.Application(); wapp.Visible = false; if (Directory.Exists(tempPath)) { var files = Directory.GetFiles(tempPath); for (int i = 0; i < files.Length; i++) { File.Delete(files[i]); } Directory.Delete(tempPath); } Directory.CreateDirectory(tempPath); lstTicket.ForEach(x => { Word.Document ticketDoc = wapp.Documents.Open(Application.StartupPath + @"\ticketTemp.dotm"); ticketDoc.Bookmarks["date"].Range.Text = x.InvalidDate.ToString("yyyy-MMdd"); ticketDoc.Bookmarks["dateType"].Range.Text = x.TicketOffer.TicketName.Contains("年票") ? "有效" : "入園"; ticketDoc.Bookmarks["name"].Range.Text = x.GuestName; ticketDoc.Bookmarks["price"].Range.Text = x.TicketOffer.Price.ToString(); ticketDoc.Bookmarks["ticketId"].Range.Text = x.TicketId; ticketDoc.Bookmarks["ticketType"].Range.Font.Color = x.TicketOffer.TicketName.Contains("年票") ? Word.WdColor.wdColorRed : Word.WdColor.wdColorBlue; ticketDoc.Bookmarks["ticketType"].Range.Text = x.TicketOffer.TicketName.Contains("年票") ? "年票 Annual Pass" : "一日票 One Day Pass"; ticketDoc.Bookmarks["type"].Range.Text = x.TicketOffer.TicketName; Bitmap qrCode = QRCode.Generate(CreateCode(x), 100, 100); Clipboard.SetImage(qrCode); ticketDoc.Bookmarks["image"].Range.Paste(); Clipboard.Clear(); ticketDoc.SaveAs2(tempPath + $@"\{x.TicketId}.docx", Word.WdSaveFormat.wdFormatDocumentDefault); ticketDoc.Close(false); }); var lstFile = Directory.GetFiles(tempPath); Word.Document mainDoc = new Word.Document(); for (int i = 0; i < lstFile.Length; i++) { if (i % 5 == 0) { mainDoc = wapp.Documents.Add(); } Word.Paragraph paragraph = mainDoc.Paragraphs.Add(); paragraph.Range.InsertFile(lstFile[i]); paragraph.Range.Delete(); if (i == lstFile.Length - 1 || i % 5 == 4) { //mainDoc.SaveAs2(tempPath + $@"\{(int)(i / 5) + 1}.pdf", Word.WdSaveFormat.wdFormatPDF); mainDoc.PrintOut(false); mainDoc.Close(false); } } wapp.Quit(false); }