예제 #1
0
        /// <summary>
        /// The generate <c>qr</c> code method renders the <c>qr</c> code to picture box in form.
        /// </summary>
        private void GenerateQr()
        {
            if (this.textBox1.Text.Trim().Length == 0)
            {
                this.pictureBox1.Image.Dispose();
                this.pictureBox1.Image = null;

                return;
            }

            try
            {
                QrCodeCreator code = new QrCodeCreator(this.textBox1.Text.Trim());

                if (this.debugToolStripMenuItem.Checked)
                {
                    code.SetDebugMode((QrBreakPoint)this.comboBox6.SelectedIndex);
                }

                if (this.autoConfigToolStripMenuItem.Checked)
                {
                    code.SetAdvancedMode(
                        (QrType)this.comboBox1.SelectedIndex,
                        new QrVersion(this.comboBox2.SelectedIndex, (QrError)this.comboBox3.SelectedIndex),
                        new QrMask(this.comboBox4.SelectedIndex));

                    this.pictureBox1.Image = code.Render(this.comboBox5.SelectedIndex);
                }
                else
                {
                    this.pictureBox1.Image = code.Render(3);
                }

                if (this.debugToolStripMenuItem.Checked)
                {
                    this.textBox2.Text = code.GetDebugData().Replace("\n", "\r\n");
                }
            }
            catch (Exception ex)
            {
                if (this.debugToolStripMenuItem.Checked)
                {
                    this.textBox2.Text = "Exception during execution.\r\n" + ex.Message + "\r\n" + ex.StackTrace;
                }

                MessageBox.Show("Cannot generate QRCode: " + ex.Message, "Error");
            }
        }
예제 #2
0
        public async Task <ApiGatewayResponse> FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
        {
            List <InMemoryFile> fileList = new List <InMemoryFile>();

            var unprintedTags = await _tagService.GetUnprintedTags();

            Dictionary <Tags, InMemoryFile> filesDictionary = new Dictionary <Tags, InMemoryFile>();

            foreach (var val in unprintedTags)
            {
                var qrArray = QrCodeCreator.CreateQrArray($"https://petzfinder.net/tag/{val.TagId}");
                var file    = new InMemoryFile()
                {
                    Content  = qrArray,
                    FileName = $"{val.TagId}.png"
                };
                filesDictionary.Add(val, file);
            }
            var timeStamp = DateTime.Now.ToString("yyyy_MM_dd_mm");

            _AwsService.UploadZipFileToS3(ZipFile.GetZipArchive(filesDictionary.Values.ToList()), timeStamp);
            foreach (var tag in unprintedTags)
            {
                tag.Printed         = "true";
                tag.FileDestination = timeStamp.Replace("_mm_ss", "");
                await _tagService.UpdateTag(tag);
            }

            //_AwsService.UploadQRFileListToS3(filesDictionary);
            ApiGatewayResponse response = new ApiGatewayResponse()
            {
                StatusCode = 200
                             //Body = Base64UrlEncoder.Encode(ZipFile.GetZipArchive(filesDictionary.Values.ToList())),
                             //IsBase64Encoded = true
            };

            //var zip = ZipFile.GetZipArchive(filesDictionary.Values.ToList());
            return(response);
        }
예제 #3
0
        public async Task <IActionResult> Create([FromBody] Voucher voucher)
        {
            using var stringWriter     = new StringWriter();
            voucher.Logo               = Logo.GetLogo();
            voucher.BarCode            = "data:image/png;base64," + Convert.ToBase64String(QrCodeCreator.CreateQrCode(voucher.TicketNo));
            voucher.ValidPassengerIcon = IconToDisplay(voucher.TotalPersons, voucher.Passengers.Count);
            voucher.Facebook           = Facebook.GetLogo();
            voucher.YouTube            = YouTube.GetLogo();
            voucher.Instagram          = Instagram.GetLogo();
            var viewResult     = compositeViewEngine.FindView(ControllerContext, "Voucher", false);
            var viewDictionary = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
            {
                Model = voucher
            };
            var viewContext = new ViewContext(ControllerContext, viewResult.View, viewDictionary, TempData, stringWriter, new HtmlHelperOptions());
            var htmlToPdf   = new HtmlToPdf(1000, 1414);
            await viewResult.View.RenderAsync(viewContext);

            var pdf      = htmlToPdf.ConvertHtmlString(stringWriter.ToString());
            var pdfBytes = pdf.Save();

            if (!Directory.Exists("Vouchers"))
            {
                Directory.CreateDirectory("Vouchers");
            }
            using (var streamWriter = new StreamWriter("Vouchers\\Voucher" + voucher.TicketNo + ".pdf")) {
                await streamWriter.BaseStream.WriteAsync(pdfBytes.AsMemory(0, pdfBytes.Length));
            }
            return(StatusCode(200, new {
                response = ApiMessages.FileCreated()
            }));
        }