private async void generateQrCodeButton_Click(object sender, EventArgs e) { var selectedCells = this.titlesDataGrid.SelectedCells; var selectedRows = (from DataGridViewCell item in selectedCells select this.titlesDataGrid.Rows[item.RowIndex]).Distinct().ToArray(); const byte maxTitles = 15; if (selectedRows.Length > maxTitles) { MessageBox.Show( $"If you make a QR code which has more than {maxTitles} titles, your 3DS will not read it. The camera on the thing isn't that good. Please select less titles.", $"{maxTitles} title limit", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.statusProgressbar.Style = ProgressBarStyle.Marquee; // var mboxResult = // MessageBox.Show( // $"Generate one QR code for all {selectedRows.Length} titles? If you select no, individual QR codes will be generated.", // "Multiple titles selected", // MessageBoxButtons.YesNo); // if (mboxResult == DialogResult.Yes) // { var qrContents = new List <string[]>(); for (var index = 0; index < selectedRows.Length; index++) { var row = selectedRows[index]; var cells = row.Cells; var titleId = cells[0].Value.ToString(); var name = cells[2].Value.ToString(); var size = cells[7].Value.ToString(); var url = "https://3ds.titlekeys.com/ticket/" + titleId.ToLower(); this.UpdateAction($"Shortening url ({index + 1}/{selectedRows.Length})"); var shortUrl = await Task.Run(() => QrUtils.Shorten(url)); qrContents.Add(new[] { titleId, name, size, shortUrl }); } var urls = qrContents.Select(a => a[3]).ToArray(); var result = QrUtils.MakeUrlIntoQrCode(string.Join("\n", urls)); var resultForm = new QrCodeResultForm(qrContents.ToArray(), result.QrCode); resultForm.Show(this); // } this.UpdateAction(string.Empty); this.statusProgressbar.Style = ProgressBarStyle.Blocks; }
public ActionResult QrCode() { var uri = Request.Url; var url = string.Format("{0}://{1}{3}/{4}", uri.Scheme, uri.Host, uri.Port, Request.ApplicationPath, "Account/Login?username=UN&password=PW"); var qrCode = QrUtils.GenerateQr(url, ImageFormat.Png); return(File(qrCode, MimeType.Pdf, "login.png")); }