public void Print(bool backOnly = false) { Badge.PrintBadge(this, backOnly); }
private void BtnPurchase_Click(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; string reference; string source; if (TabPaymentMethods.SelectedTab == TabCredit) { source = "Stripe"; var dialog = new FrmProcessing { FirstTry = StripeFirstTry, Person = Purchaser, CardNumber = Card.CardNumber, CardMonth = Card.ExpireMonth, CardYear = Card.ExpireYear, CardCVC = txtCVC.Text, Amount = CalculateTotal() }; dialog.ShowDialog(); if (dialog.Charge != null) { reference = dialog.Charge.Id; } else { StripeFirstTry = false; Cursor = Cursors.Default; MessageBox.Show("The transaction was declined: " + dialog.Error.Message, "Charge Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } else { source = TabPaymentMethods.SelectedTab == TabCash ? "Cash" : "Check"; reference = GetRandomHexNumber(13); if (TabPaymentMethods.SelectedTab == TabCheck) { reference += "_#" + TxtCheckNumber.Text; } } var items = (from ListViewItem item in LstCart.Items select(SaleItem) item.Tag).ToList(); var payload = "action=RecordPurchase&"; if (Purchaser.PeopleID != null) { payload += "purchaser=" + Purchaser.PeopleID; } else { payload += "onetime=" + Purchaser.OneTimeID; } payload += "&reference=" + reference + "&source=" + source; if (TxtCode.TextLength > 0 && !TxtCode.Enabled) { payload += "&code=" + TxtCode.Text; } payload += "&items=" + JsonConvert.SerializeObject(items); var data = Encoding.ASCII.GetBytes(payload); var request = WebRequest.Create(Program.URL + "/functions/salesQuery.php"); request.ContentLength = data.Length; request.ContentType = "application/x-www-form-urlencoded"; request.Method = "POST"; using (var stream = request.GetRequestStream()) stream.Write(data, 0, data.Length); var webResponse = (HttpWebResponse)request.GetResponse(); var results = new StreamReader(webResponse.GetResponseStream()).ReadToEnd(); var response = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(results); if ((string)response["Result"] == "Success") { if (ChkPrintBadges.Checked && response.ContainsKey("BadgeNumbers")) { var badgeNumbers = JsonConvert.DeserializeObject <Dictionary <string, int> >((string)response["BadgeNumbers"]); foreach (var item in items) { if (item.CategoryID == 1) { var recipient = item.RecipientOneTimeID != null ? OneTimeRecipients[(int)item.RecipientOneTimeID] : Recipients[(int)item.RecipientPeopleID]; var badge = new Badge { BadgeName = item.Details, BadgeNumber = item.RecipientPeopleID != null ? badgeNumbers[item.RecipientPeopleID.ToString()] : badgeNumbers["_" + item.RecipientOneTimeID.ToString()], BadgeTypeID = item.TypeID, Description = item.Description, FirstName = recipient.FirstName, LastName = recipient.LastName, ParentName = recipient.ParentName, ParentContact = recipient.ParentContact }; Badge.PrintBadge(badge); } } } MessageBox.Show("Your purchases have been recorded! Your reference number is \"" + reference + "\".", "Purchase Complete", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; } else { MessageBox.Show( "An error occurred entering your purchases into the database: " + (string)response["Message"], "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } Cursor = Cursors.Default; }