void deleteButton_Click(object sender, EventArgs e) { int advertiserId = Int32.Parse(advertiserIdHidden.Value); if (idHidden.Value != String.Empty) { certificateId = Int32.Parse(idHidden.Value); try { CertificateNumberTableAdapter certNumberAdapter = new CertificateNumberTableAdapter(); certNumberAdapter.DeleteByCertificate(certificateId); CertificateTableAdapter certificateAdapter = new CertificateTableAdapter(); certificateAdapter.Delete(certificateId); Response.Redirect("~/admin/AdvertiserEdit.aspx?id=" + advertiserId); } catch (SqlException ex) { if (ex.Number == 547) { ErrorMessage = "Certificate cannot be deleted due to database constraints. De-activate it instead."; } else { throw ex; } } } }
private void ResetOrder() { OrderTableAdapter orderAdapter = new OrderTableAdapter(); CertificateNumberTableAdapter numberAdapter = new CertificateNumberTableAdapter(); Order.OrderStatusId = (int)OrderStatus.New; orderAdapter.Update(Order); foreach (DollarSaverDB.OrderLineItemRow releaseItem in Order.LineItems) { numberAdapter.Release(releaseItem.OrderLineItemId); } }
void createHistoryRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { DateTime createDate = (DateTime)e.Item.DataItem; Label createDateLabel = (Label)e.Item.FindControl("createDateLabel"); Label quantityLabel = (Label)e.Item.FindControl("quantityLabel"); CertificateNumberTableAdapter certificateNumberAdapter = new CertificateNumberTableAdapter(); int quantity = certificateNumberAdapter.GetByCertificateAndCreateDate(certificateId, createDate).Count; createDateLabel.Text = createDate.ToString("MM/dd/yyyy"); quantityLabel.Text = quantity.ToString(); } }
void removeNumbersButton_Click(object sender, EventArgs e) { int qty = 0; certificateId = Int32.Parse(idHidden.Value); try { qty = Int32.Parse(newQtyBox.Text); } catch { } if (qty > 0) { CertificateNumberTableAdapter certificateNumberAdapter = new CertificateNumberTableAdapter(); int qtyRemoved = certificateNumberAdapter.Remove(certificateId, qty); InfoMessage = qtyRemoved + " numbers removed"; Response.Redirect("~/admin/CertificateEdit.aspx?id=" + certificateId); } else { InfoMessage = "Quantity must be a postitive integer"; } }
protected void Page_Load(object sender, EventArgs e) { if (Order == null || Order.StationId != StationId || Order.OrderStatusId != (int)OrderStatus.New) { OrderId = 0; Response.Redirect("~/Cart.aspx"); } com.paypal.sdk.services.NVPCallerServices caller = PayPalAPI.PayPalAPIInitialize(IsDev); NVPCodec encoder = new NVPCodec(); encoder["METHOD"] = "GetExpressCheckoutDetails"; encoder["TOKEN"] = Session["TOKEN"].ToString(); string paypalRequest = encoder.Encode(); string paypalResponse = caller.Call(paypalRequest); NVPCodec decoder = new NVPCodec(); decoder.Decode(paypalResponse); String billingEmailAddress = String.Empty; String firstName = String.Empty; String lastName = String.Empty; String phoneNumber = String.Empty; /* * String address1 = String.Empty; * String address2 = String.Empty; * String city = String.Empty; * String stateCode = String.Empty; * String zipCode = String.Empty; */ string strAck = decoder["ACK"]; if (strAck != null && (strAck == "Success" || strAck == "SuccessWithWarning")) { Session["PAYERID"] = decoder["PAYERID"]; billingEmailAddress = decoder["EMAIL"]; firstName = decoder["FIRSTNAME"]; lastName = decoder["LASTNAME"]; phoneNumber = decoder["PHONENUM"]; } else { /* * string pStrError = * "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" + * "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" + * "Desc2=" + decoder["L_LONGMESSAGE0"]; * * Response.Redirect("APIError.aspx?" + pStrError); * */ ErrorMessage = decoder["L_LONGMESSAGE0"]; //Response.Redirect("~/Cart.aspx"); ResetAndRedirect(); } OrderLineItemTableAdapter orderLineItemAdapter = new OrderLineItemTableAdapter(); OrderTableAdapter orderAdapter = new OrderTableAdapter(); CertificateNumberTableAdapter numberAdapter = new CertificateNumberTableAdapter(); decimal subtotal = 0.0m; foreach (DollarSaverDB.OrderLineItemRow lineItem in Order.LineItems) { int numberAssigned = Convert.ToInt32(numberAdapter.Assign(lineItem.OrderLineItemId)); if (numberAssigned != lineItem.Quantity) { if (numberAssigned == 0) { ErrorMessage = "We're sorry, " + lineItem.Certificate.AdvertiserName + " is no longer available"; orderLineItemAdapter.Delete(lineItem.OrderLineItemId); } else { lineItem.Quantity = numberAssigned; orderLineItemAdapter.Update(lineItem); ErrorMessage = "We're sorry, " + lineItem.Certificate.AdvertiserName + " is no longer available in the quantity you requested. Please review your updated order and click on the chechout button if you would like to purchase the new quantity"; } ResetAndRedirect(); } subtotal += lineItem.Total; } // Check max purchase qty for Deal of the Week if (Station.StationSiteType == SiteType.DealOfTheWeek) { CertificateTableAdapter certificateAdapter = new CertificateTableAdapter(); DollarSaverDB.CertificateDataTable certificateTable = certificateAdapter.GetCurrentDeal(StationId); if (certificateTable.Count == 1) { DollarSaverDB.CertificateRow deal = certificateTable[0]; if (deal.MaxPurchaseQty > 0) { foreach (DollarSaverDB.OrderLineItemRow lineItem in Order.LineItems) { if (lineItem.CertificateId == deal.CertificateId) { int pastQty = Convert.ToInt32(orderLineItemAdapter.GetQtyByConsumer(firstName, lastName, billingEmailAddress, null, null, null, Order.ShippingEmail, deal.CertificateId)); if (pastQty + lineItem.Quantity > deal.MaxPurchaseQty) { ErrorMessage = "Sorry, the maximum purchase quantity per person for the Deal of the Week is " + deal.MaxPurchaseQty + "."; if (pastQty >= deal.MaxPurchaseQty) { ErrorMessage += "<BR>You have already purchased the maximum allowed."; } else { int allowedAmount = deal.MaxPurchaseQty - pastQty; ErrorMessage += "<BR>You may only purchase " + allowedAmount + " more."; } ResetAndRedirect(); } } } } } } //charge order here Order.SubTotal = subtotal; Order.GrandTotal = subtotal; Order.BillingFirstName = firstName; Order.BillingLastName = lastName; Order.BillingEmail = billingEmailAddress; /* * Order.BillingAddress1 = address1; * if (address2 != String.Empty) { * Order.BillingAddress2 = address2; * } else { * Order.SetBillingAddress2Null(); * } * Order.BillingCity = city; * Order.BillingStateCode = stateCode; * Order.BillingZipCode = zipCode; */ Order.BillingPhone = phoneNumber; Order.PaymentMethodId = (int)PaymentMethod.PayPal; orderAdapter.Update(Order); if (Order.CheckoutStartDate < Order.LineItemModifiedDate) { ErrorMessage = "Your cart has been updated while checking out, please verify your items and continue the checkout process."; ResetAndRedirect(); } Order.OrderStatusId = (int)OrderStatus.Processing; orderAdapter.Update(Order); encoder["METHOD"] = "DoExpressCheckoutPayment"; encoder["TOKEN"] = Session["TOKEN"].ToString(); encoder["PAYERID"] = Session["PAYERID"].ToString(); encoder["AMT"] = subtotal.ToString("0.00"); encoder["PAYMENTACTION"] = "Sale"; encoder["CURRENCYCODE"] = "USD"; encoder["INVNUM"] = Order.OrderId.ToString(); encoder["ITEMAMT"] = Order.LineItems.SubTotal.ToString("0.00"); foreach (DollarSaverDB.OrderLineItemRow lineItem in Order.LineItems.Rows) { int itemNumber = lineItem.SeqNo - 1; encoder["L_NAME" + itemNumber] = lineItem.ShortName; encoder["L_NUMBER" + itemNumber] = lineItem.CertificateId.ToString(); encoder["L_QTY" + itemNumber] = lineItem.Quantity.ToString(); encoder["L_AMT" + itemNumber] = lineItem.DiscountValue.ToString("0.00"); } paypalRequest = encoder.Encode(); paypalResponse = String.Empty; try { paypalResponse = caller.Call(paypalRequest); } catch { ErrorMessage = "An error occurred while processing your order, please try submitting it again."; ResetAndRedirect(); } decoder.Decode(paypalResponse); strAck = decoder["ACK"]; if (strAck != null && (strAck == "Success" || strAck == "SuccessWithWarning")) { /* * string pStrResQue = "TRANSACTIONID=" + decoder["TRANSACTIONID"] + "&" + * "CURRENCYCODE=" + decoder["CURRENCYCODE"] + "&" + * "AMT=" + decoder["AMT"]; * * Response.Redirect("DoExpressCheckoutPayment.aspx?" + pStrResQue); * */ string transactionId = decoder["TRANSACTIONID"]; Order.TransactionId = transactionId; Order.OrderDate = DateTime.Now; Order.OrderStatusId = (int)OrderStatus.Complete; orderAdapter.Update(Order); InfoMessage = "Successfully processed order"; if (SendReceipt()) { InfoMessage += "<BR />Receipt sent to " + Order.ShippingEmail; } if (Order.AddToMailingList) { CustomerContactTableAdapter customerContactAdapter = new CustomerContactTableAdapter(); customerContactAdapter.Insert(StationId, DateTime.Now, Order.ShippingEmail, Order.BillingFirstName, Order.BillingLastName); } Response.Redirect("~/Confirmation.aspx"); } else { /* * string pStrError = * "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" + * "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" + * "Desc2=" + decoder["L_LONGMESSAGE0"]; * * Response.Redirect("APIError.aspx?" + pStrError); * */ ErrorMessage = "An error has occurred while processing your order: " + decoder["L_LONGMESSAGE0"] + " (" + decoder["L_ERRORCODE0"] + ")"; ResetAndRedirect(); } }
void emailButton_Click(object sender, EventArgs e) { String emailAddress = emailBox.Text.Trim(); if (emailAddress == String.Empty) { return; } RegexStringValidator regex = new RegexStringValidator(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"); try { regex.Validate(emailAddress); } catch { ErrorMessage = "E-mail address is not valid"; return; } String createDateStr = String.Empty; createDateStr = createDateList.SelectedValue; DollarSaverDB.CertificateNumberDataTable certificateNumbers; if (createDateStr == String.Empty) { certificateNumbers = certificate.AllNumbers; createDateStr = "All Dates"; } else { DateTime createDate = DateTime.Now; try { createDate = Convert.ToDateTime(createDateStr); createDateStr = createDate.ToString("MM/dd/yyyy"); } catch { ErrorMessage = "Create Date must by in the format MM/DD/YYYY"; return; } CertificateNumberTableAdapter certificateNumberAdapter = new CertificateNumberTableAdapter(); certificateNumbers = certificateNumberAdapter.GetByCertificateAndCreateDate(certificateId, createDate); } //MailMessage message = new MailMessage("*****@*****.**", "*****@*****.**"); MailMessage message = new MailMessage("\"DollarSaver\" <*****@*****.**>", emailAddress); message.IsBodyHtml = true; message.Subject = "Certificate Numbers For " + certificate.AdvertiserName; String body = "<html><body><span style=\"font-family: Verdana; font-size: 12pt;\">"; /* * body += "<table cellpadding=\"3\" cellspacing=\"0\" border=\"0\" width=\"550px\">" + Environment.NewLine + * "<tr><td align=\"center\" style=\"font-size: 18pt;\">Advertiser: " + certificate.Advertiser.Name + "</td></tr>" + Environment.NewLine + * "<tr><td align=\"center\"><HR width=\"100%\" ></td></tr>" + Environment.NewLine + * "<tr><td align=\"left\">Station: " + Station.Name + "</td></tr>" + Environment.NewLine + * "<tr><td align=\"left\">Certificate: " + certificate.ShortName + "</td></tr>" + Environment.NewLine + * "<tr><td align=\"left\">Create Date: " + createDateStr + "</td></tr>" + Environment.NewLine + * "<tr><td align=\"left\">Quantity: " + certificateNumbers.Count + "</td></tr>" + Environment.NewLine + * "<tr><td align=\"center\"><HR width=\"100%\" ></td></tr>" + Environment.NewLine + * "<tr><td align=\"center\" style=\"font-size: 18pt;\"><U>CERTIFICATE NUMBERS</U></td></tr>" + Environment.NewLine + * "<tr><td align=\"center\"><B>Cross out number when certificate is redeemed</B></td></tr>" + Environment.NewLine + * "<tr><td align=\"center\"><B>--> Read numbers Left to Right --></B></td></tr>" + * "<tr><td align=\"center\"><HR width=\"100%\" ></td></tr>" + Environment.NewLine; */ body += "<table cellpadding=\"3\" cellspacing=\"0\" border=\"0\" width=\"550px\">" + Environment.NewLine + "<tr><td align=\"center\" style=\"font-size: 14pt;\">" + certificateNumbers.Count + " Certificate Numbers for " + certificate.Advertiser.Name + "</td></tr>" + Environment.NewLine + "<tr><td align=\"center\" style=\"font-size: 10pt;\">Certificate: " + certificate.ShortName + "</td></tr>" + Environment.NewLine + "<tr><td align=\"center\" style=\"font-size: 8pt;\"><B>Cross out number when certificate is redeemed</B> --> Read numbers Left to Right --></B></td></tr>" + "<tr><td align=\"center\"><HR width=\"100%\" ></td></tr>" + Environment.NewLine; body += "<tr><td><table cellpadding=\"3\" cellspacing=\"0\" border=\"0\" width=\"100%\">"; for (int i = 0; i < certificateNumbers.Count; i += 3) { body += "<tr><td style=\"font-size: 20pt\" align=\"center\">" + certificateNumbers[i].Number + "</td>" + Environment.NewLine; if (i + 1 < certificateNumbers.Count) { body += "<td style=\"font-size: 20pt\" align=\"center\">" + certificateNumbers[i + 1].Number + "</td>" + Environment.NewLine; } else { body += "<td style=\"font-size: 20pt\" align=\"center\"> </td>" + Environment.NewLine; } if (i + 2 < certificateNumbers.Count) { body += "<td style=\"font-size: 20pt\" align=\"center\">" + certificateNumbers[i + 2].Number + "</td></tr>" + Environment.NewLine; } else { body += "<td style=\"font-size: 20pt\" align=\"center\"> </td></tr>" + Environment.NewLine; } } body += "</table></tr></td>"; body += "<tr><td align=\"center\"><HR width=\"100%\" ></td></tr></table></body></html>"; // end message with a <CRLF>.<CRLF> ?? message.Body = body; bool success = false; try { //SmtpClient smtp = new SmtpClient("localhost", 25); //smtp.Send(message); Mailer mailer = new Mailer(); mailer.Send(message); InfoMessage = "Certificate Numbers sent to: " + emailAddress; success = true; } catch (Exception ex) { ErrorMessage = "Error Sending E-mail: " + ex.Message; } if (success) { Response.Redirect("~/admin/CertificateEdit.aspx?id=" + certificateId); } }
void saveButton_Click(object sender, EventArgs e) { if (Page.IsValid) { int advertiserId = Int32.Parse(advertiserIdHidden.Value); String shortName = nameBox.Text.Trim(); String description = descriptionBox.Text.Trim(); if (shortName == String.Empty) { ErrorMessage = "Name is required"; return; } if (shortName.Length > 100) { shortName = shortName.Substring(0, 100); } if (description == String.Empty) { ErrorMessage = "Description is required"; return; } if (description.Length > 500) { description = description.Substring(0, 500); } int minPurchaseQty = 0; try { minPurchaseQty = Int32.Parse(minPurchaseQtyBox.Text); } catch { ErrorMessage = "Min Purchase Qty must be an integer"; return; } if (minPurchaseQty <= 0) { ErrorMessage = "Min Purchase Qty must be a postive number"; return; } int maxPurchaseQty = 0; try { maxPurchaseQty = Int32.Parse(maxPurchaseQtyBox.Text); } catch { ErrorMessage = "Max Purchase Qty must be an integer"; return; } if (maxPurchaseQty < 0) { ErrorMessage = "Min Purchase Qty must be greater than or equal to 0"; return; } decimal faceValue = 0; try { faceValue = Decimal.Parse(faceValueBox.Text); } catch { ErrorMessage = "Face Value must be a decimal"; return; } if (faceValue <= 0) { ErrorMessage = "Face Value be a postive"; return; } decimal discount = 0; try { discount = Decimal.Parse(discountBox.Text); } catch { ErrorMessage = "Discount must be a decimal"; return; } if (discount <= 0) { ErrorMessage = "Discount be a postive"; return; } int discountTypeId = Int32.Parse(discountList.SelectedValue); String onSaleDateStr = String.Empty; if (Station.StationSiteType == SiteType.DealOfTheWeek) { onSaleDateStr = onSaleDateList.SelectedValue; } else { onSaleDateStr = onSaleDateBox.Text.Trim(); } if (onSaleDateStr == String.Empty) { ErrorMessage = "On Sale Date is required"; return; } if (Station.StationSiteType == SiteType.Standard) { onSaleDateStr += " " + onSaleHourList.SelectedValue + ":" + onSaleMinuteList.SelectedValue + ":00 "; } DateTime onSaleDate; try { onSaleDate = Convert.ToDateTime(onSaleDateStr); } catch { ErrorMessage = "On Sale Date must by in the format MM/DD/YYYY"; return; } onSaleDate = TimeZoneInfo.ConvertTime(onSaleDate, Station.StationTimeZoneInfo, TimeZoneInfo.Local); int lowStockAmount = 0; try { lowStockAmount = Int32.Parse(lowStockAmountBox.Text); } catch { ErrorMessage = "Low Stock Amount must be an integer"; return; } if (lowStockAmount < 0) { ErrorMessage = "Low Stock Amount must be greater than or equal to 0"; return; } int numberLength = Convert.ToInt32(numberLengthList.SelectedValue); int deliveryTypeId = Convert.ToInt32(deliveryList.SelectedValue); string deliveryNote = deliveryNoteBox.Text.Trim(); if (deliveryNote.Length > 500) { deliveryNote = deliveryNote.Substring(0, 500); } bool isActive = isActiveBox.Checked; CertificateTableAdapter certificateAdapter = new CertificateTableAdapter(); if (idHidden.Value != String.Empty) { certificateId = Int32.Parse(idHidden.Value); certificate = certificateAdapter.GetCertificate(certificateId)[0]; certificate.ShortName = shortName; certificate.Description = description; certificate.MinPurchaseQty = minPurchaseQty; certificate.MaxPurchaseQty = maxPurchaseQty; certificate.FaceValue = faceValue; certificate.Discount = discount; certificate.DiscountTypeId = discountTypeId; certificate.OnSaleDate = onSaleDate; certificate.LowStockAmount = lowStockAmount; certificate.NumberLength = numberLength; certificate.DeliveryTypeId = deliveryTypeId; certificate.DeliveryNote = deliveryNote; certificate.IsActive = isActive; certificateAdapter.Update(certificate); CertificateNumberTableAdapter certificateNumberAdapter = new CertificateNumberTableAdapter(); InfoMessage = "Certificate updated"; } else { int quantity = 0; try { quantity = Int32.Parse(qtyBox.Text.Trim()); } catch { ErrorMessage = "Quantity must be an integer"; return; } if (quantity <= 0) { ErrorMessage = "Quantity must be a postive"; return; } certificateId = Convert.ToInt32(certificateAdapter.InsertPK(advertiserId, shortName, description, minPurchaseQty, maxPurchaseQty, faceValue, discount, discountTypeId, deliveryTypeId, deliveryNote, isActive, onSaleDate, lowStockAmount, numberLength)); CertificateNumberTableAdapter certificateNumberAdapter = new CertificateNumberTableAdapter(); certificateNumberAdapter.Generate(certificateId, quantity); InfoMessage = "Certificate created"; } Response.Redirect("~/admin/AdvertiserEdit.aspx?id=" + advertiserId); } }
protected void Page_Load(object sender, EventArgs e) { saveButton.Click += new EventHandler(saveButton_Click); cancelButton.Click += new EventHandler(cancelButton_Click); deleteButton.Click += new EventHandler(deleteButton_Click); deleteButton.Attributes["onclick"] = "javascript: return confirm('Are you sure want to delete this item?');"; emailButton.Click += new EventHandler(emailButton_Click); addNumbersButton.Click += new EventHandler(addNumbersButton_Click); removeNumbersButton.Click += new EventHandler(removeNumbersButton_Click); createHistoryRepeater.ItemDataBound += new RepeaterItemEventHandler(createHistoryRepeater_ItemDataBound); availableNumberGrid.RowDataBound += new GridViewRowEventHandler(availableNumberGrid_RowDataBound); certificateId = GetIdFromQueryString(); int advertiserId = 0; CertificateTableAdapter certificateAdapter = new CertificateTableAdapter(); if (certificateId > 0) { DollarSaverDB.CertificateDataTable certificateTable = certificateAdapter.GetCertificate(certificateId); if (certificateTable.Count != 1) { Response.Redirect("~/admin/AdvertiserList.aspx"); } certificate = certificateTable[0]; advertiserId = certificate.AdvertiserId; } else { advertiserId = GetValueFromQueryString("advertiserId"); } if (!Page.IsPostBack) { if (Station.StationSiteType == SiteType.DealOfTheWeek) { standardDateHolder.Visible = false; onSaleDateBoxRFV.Enabled = false; onSaleDateList.Visible = true; ArrayList onSaleDates = new ArrayList(); onSaleDates = certificateAdapter.GetDealDates(StationId); onSaleDateList.DataSource = onSaleDates; onSaleDateList.DataTextFormatString = "{0:MM/dd/yyyy hh:mm:ss tt}"; onSaleDateList.DataBind(); DateTime onSaleNow = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Local, Station.StationTimeZoneInfo); onSaleNow = onSaleNow.AddDays(-14); onSaleDateList.Items.Add(new ListItem("-- On Sale Now --", onSaleNow.ToString("MM/dd/yyyy hh:mm:ss tt"))); } else { standardDateHolder.Visible = true; onSaleDateBoxRFV.Enabled = true; onSaleDateList.Visible = false; for (int i = 0; i <= 23; i++) { String hour; if (i % 12 == 0) { hour = "12"; } else { hour = (i % 12).ToString("00"); } onSaleHourList.Items.Add(new ListItem(hour + " " + (i < 12 ? "AM" : "PM"), i.ToString("00"))); } for (int i = 0; i <= 59; i++) { onSaleMinuteList.Items.Add(new ListItem(i.ToString("00"), i.ToString("00"))); } } AdvertiserTableAdapter advertiserAdapter = new AdvertiserTableAdapter(); DollarSaverDB.AdvertiserDataTable advertiserTable = advertiserAdapter.GetAdvertiser(advertiserId); if (advertiserTable.Count != 1) { Response.Redirect("~/admin/AdvertiserList.aspx"); } DollarSaverDB.AdvertiserRow advertiser = advertiserTable[0]; if (advertiser.StationId != StationId) { Response.Redirect("~/admin/AdvertiserList.aspx"); } if (advertiser.IsDeleted) { InfoMessage = "Sorry, this advertiser has been deleted"; Response.Redirect("~/admin/AdvertiserList.aspx"); } discountList.Items.Add(new ListItem("Percentage", "1")); discountList.Items.Add(new ListItem("Flat Amount", "2")); advertiserNameLabel.Text = advertiser.Name; advertiserIdHidden.Value = advertiserId.ToString(); if (certificateId > 0) { createEditLabel.Text = "Edit"; newCertHolder.Visible = false; idHidden.Value = certificateId.ToString(); nameBox.Text = certificate.ShortName; descriptionLengthLabel.Text = certificate.Description.Length.ToString(); descriptionBox.Text = certificate.Description; minPurchaseQtyBox.Text = certificate.MinPurchaseQty.ToString(); maxPurchaseQtyBox.Text = certificate.MaxPurchaseQty.ToString(); faceValueBox.Text = certificate.FaceValue.ToString("0.00"); discountBox.Text = certificate.Discount.ToString("0.00"); discountList.SelectedValue = certificate.DiscountTypeId.ToString(); if (CurrentUser.Role == AdminRole.Manager || CurrentUser.Role == AdminRole.SalesRep) { faceValueBox.Enabled = false; discountBox.Enabled = false; discountList.Enabled = false; } deliveryList.SelectedValue = certificate.DeliveryTypeId.ToString(); deliveryNoteBox.Text = certificate.DeliveryNote; isActiveBox.Checked = certificate.IsActive; lowStockAmountBox.Text = certificate.LowStockAmount.ToString(); if (numberLengthList.Items.FindByValue(certificate.NumberLength.ToString()) != null) { numberLengthList.SelectedValue = certificate.NumberLength.ToString(); } if (Station.StationSiteType == SiteType.DealOfTheWeek) { ListItem dateItem = onSaleDateList.Items.FindByText(certificate.AdjustedOnSaleDate.ToString("MM/dd/yyyy hh:mm:ss tt}")); if (dateItem != null) { onSaleDateList.SelectedIndex = onSaleDateList.Items.IndexOf(dateItem); } else { onSaleDateList.Items.Insert(0, new ListItem(certificate.AdjustedOnSaleDate.ToString("MM/dd/yyyy hh:mm:ss tt"), certificate.AdjustedOnSaleDate.ToString("M/d/yyyy h:mm:ss tt"))); } } else { onSaleDateBox.Text = certificate.AdjustedOnSaleDate.ToString("MM/dd/yyyy"); onSaleHourList.SelectedValue = certificate.AdjustedOnSaleDate.Hour.ToString("00"); onSaleMinuteList.SelectedValue = certificate.AdjustedOnSaleDate.Minute.ToString("00"); } CertificateNumberTableAdapter certificateNumberAdapter = new CertificateNumberTableAdapter(); ArrayList createDates = certificateNumberAdapter.GetDates(certificateId); createDateList.DataSource = createDates; createDateList.DataTextFormatString = "{0:MM/dd/yyyy}"; createDateList.DataBind(); createDateList.Items.Insert(0, new ListItem("-- All Dates --", "")); certificateNumberHolder.Visible = true; createHistoryRepeater.DataSource = createDates; createHistoryRepeater.DataBind(); if (certificate.DeliveryType == DeliveryType.Print) { printableHolder.Visible = true; notPrintableHolder.Visible = false; String queryString = "sample_id=" + certificate.CertificateId; String encryptedString = Server.UrlEncode(Cipher.Encrypt(queryString)); viewSampleLink.NavigateUrl = "~/ViewCertificate.aspx?x=" + encryptedString; BindNumbers(); } else { printableHolder.Visible = false; notPrintableHolder.Visible = true; availableCountLabel.Text = certificate.AvailableNumbers.Count.ToString(); usedCountLabel.Text = certificate.UsedNumbers.Count.ToString(); } } else { deleteButton.Visible = false; saveButton.Text = "Create"; createEditLabel.Text = "Create"; certificateNumberHolder.Visible = false; newCertHolder.Visible = true; onSaleDateBox.Text = DateTime.Now.ToString("MM/dd/yyyy"); } } }
private void LoadCertificateNumber() { CertificateNumberTableAdapter certificateNumberAdapter = new CertificateNumberTableAdapter(); int id = 0; int orderId = 0; int sampleId = 0; String cipherText = Request.QueryString["x"]; if (cipherText != null && cipherText != String.Empty) { try { String plainText = Server.UrlDecode(Cipher.Decrypt(cipherText)); String[] keysAndValues = plainText.Split('&'); foreach (String keyAndValueStr in keysAndValues) { String[] keyAndValue = keyAndValueStr.Split('='); if (keyAndValue.Length == 2) { if (keyAndValue[0] == "id") { try { id = Convert.ToInt32(keyAndValue[1]); } catch { } } else if (keyAndValue[0] == "order_id") { try { orderId = Convert.ToInt32(keyAndValue[1]); } catch { } } else if (keyAndValue[0] == "sample_id") { try { sampleId = Convert.ToInt32(keyAndValue[1]); } catch { } } } } } catch { } } if (sampleId == 0) { if (id == 0 || orderId == 0) { // check for old parameters for backward compatibility // viewcertificate?orderNum=13651&certNum=755426&backBtn=no orderId = GetValueFromQueryString("orderNum"); id = 0; // cut off backward compatibility after certain order id if (orderId < 17000) { String number = Convert.ToString(Request.QueryString["certNum"]); if (orderId == 0 || number == String.Empty) { return; } DollarSaverDB.CertificateNumberDataTable numberSearch = certificateNumberAdapter.GetBackward(orderId, number); if (numberSearch.Count == 1) { id = numberSearch[0].CertificateNumberId; } else { return; } } } DollarSaverDB.CertificateNumberDataTable certNumberTable = certificateNumberAdapter.GetCertificateNumber(id); if (certNumberTable.Count != 1) { return; } DollarSaverDB.CertificateNumberRow checkCertNumber = certNumberTable[0]; OrderTableAdapter orderAdapter = new OrderTableAdapter(); DollarSaverDB.OrderDataTable orderTable = orderAdapter.GetOrder(orderId); if (orderTable.Count != 1) { return; } DollarSaverDB.OrderRow order = orderTable[0]; if (order.OrderStatusId != (int)OrderStatus.Complete) { return; } if (checkCertNumber.IsOrderLineItemIdNull() || !order.LineItems.Contains(checkCertNumber.OrderLineItemId)) { return; } certNumber = checkCertNumber; certificate = certNumber.Certificate; } else { CertificateTableAdapter certAdapter = new CertificateTableAdapter(); DollarSaverDB.CertificateDataTable certificateTable = certAdapter.GetCertificate(sampleId); if (certificateTable.Count != 1) { return; } certificate = certificateTable[0]; } }
void placeOrderButton_Click(object sender, EventArgs e) { // Validate fields /* * string patternLenient = @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"; * * string patternStrict = @"^(([^<>()[\]\\.,;:\s@\""]+" + @"(\.[^<>()[\]\\.,;:\s@\""]+)*)|(\"".+\""))@" + @"((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" + @"\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+" + @"[a-zA-Z]{2,}))$"; + */ String creditCardType = creditCardList.SelectedValue; String creditCardNumber = creditCardNumberBox.Text.Trim(); creditCardNumber = Regex.Replace(creditCardNumber, @"\D", ""); String verificationNumber = verificationNumberBox.Text.Trim(); String firstName = firstNameBox.Text.Trim(); String lastName = lastNameBox.Text.Trim(); String address1 = address1Box.Text.Trim(); String address2 = address2Box.Text.Trim(); String city = cityBox.Text.Trim(); String stateCode = stateList.SelectedValue; String zipCode = zipCodeBox.Text.Trim(); String phoneNumber = phoneNumberBox.Text.Trim(); if (firstName == String.Empty) { ErrorMessage = "First Name is required"; return; } if (lastName == String.Empty) { ErrorMessage = "Last Name is required"; return; } if (address1 == String.Empty) { ErrorMessage = "Address is required"; return; } if (city == String.Empty) { ErrorMessage = "City is required"; return; } if (stateCode == String.Empty) { ErrorMessage = "State is required"; return; } if (zipCode == String.Empty) { ErrorMessage = "Zip Code is required"; return; } if (phoneNumber == String.Empty) { ErrorMessage = "Phone Number is required"; return; } if (phoneNumber.Length < 10) { ErrorMessage = "Phone Number must include area code plus 7 digit phone number"; return; } if (DsCookie["_c"] == "1") { DsCookie["_c_ba"] = Cipher.Encrypt2(firstName); DsCookie["_c_bb"] = Cipher.Encrypt2(lastName); DsCookie["_c_bc"] = Cipher.Encrypt2(address1); DsCookie["_c_bd"] = Cipher.Encrypt2(address2); DsCookie["_c_be"] = Cipher.Encrypt2(city); DsCookie["_c_bf"] = Cipher.Encrypt2(stateCode); DsCookie["_c_bg"] = Cipher.Encrypt2(zipCode); DsCookie["_c_bh"] = Cipher.Encrypt2(phoneNumber); } if (creditCardNumber == String.Empty) { ErrorMessage = "Credit Card Number is required"; return; } if (verificationNumber == String.Empty) { ErrorMessage = "Card Verification Number is required"; return; } OrderTableAdapter orderAdapter = new OrderTableAdapter(); CertificateNumberTableAdapter numberAdapter = new CertificateNumberTableAdapter(); OrderLineItemTableAdapter orderLineItemAdapter = new OrderLineItemTableAdapter(); decimal subtotal = 0.0m; foreach (DollarSaverDB.OrderLineItemRow lineItem in Order.LineItems) { int numberAssigned = Convert.ToInt32(numberAdapter.Assign(lineItem.OrderLineItemId)); if (numberAssigned != lineItem.Quantity) { if (numberAssigned == 0) { ErrorMessage = "We're sorry, " + lineItem.Certificate.AdvertiserName + " is no longer available"; orderLineItemAdapter.Delete(lineItem.OrderLineItemId); } else { lineItem.Quantity = numberAssigned; orderLineItemAdapter.Update(lineItem); ErrorMessage = "We're sorry, " + lineItem.Certificate.AdvertiserName + " is no longer available in the quantity you requested. Please review your updated order and click on the checkout button if you would like to purchase the new quantity"; } Order.LineItemModifiedDate = DateTime.Now; orderAdapter.Update(Order); ResetOrder(); Response.Redirect("~/Cart.aspx"); } subtotal += lineItem.Total; } switch (creditCardType) { case "Visa": Order.PaymentMethodId = (int)PaymentMethod.Visa; break; case "MasterCard": Order.PaymentMethodId = (int)PaymentMethod.MasterCard; break; case "Discover": Order.PaymentMethodId = (int)PaymentMethod.Discover; break; case "Amex": Order.PaymentMethodId = (int)PaymentMethod.Amex; break; default: break; } Order.SubTotal = subtotal; Order.GrandTotal = subtotal; Order.BillingFirstName = firstName; Order.BillingLastName = lastName; Order.BillingAddress1 = address1; if (address2 != String.Empty) { Order.BillingAddress2 = address2; } else { Order.SetBillingAddress2Null(); } Order.BillingCity = city; Order.BillingStateCode = stateCode; Order.BillingZipCode = zipCode; Order.BillingPhone = phoneNumber; orderAdapter.Update(Order); // Check max purchase qty for Deal of the Week if (Station.StationSiteType == SiteType.DealOfTheWeek) { CertificateTableAdapter certificateAdapter = new CertificateTableAdapter(); DollarSaverDB.CertificateDataTable certificateTable = certificateAdapter.GetCurrentDeal(StationId); if (certificateTable.Count == 1) { DollarSaverDB.CertificateRow deal = certificateTable[0]; if (deal.MaxPurchaseQty > 0) { foreach (DollarSaverDB.OrderLineItemRow lineItem in Order.LineItems) { if (lineItem.CertificateId == deal.CertificateId) { int pastQty = Convert.ToInt32(orderLineItemAdapter.GetQtyByConsumer(firstName, lastName, null, address1, city, stateCode, Order.ShippingEmail, deal.CertificateId)); if (pastQty + lineItem.Quantity > deal.MaxPurchaseQty) { ErrorMessage = "Sorry, the maximum purchase quantity per person for the Deal of the Week is " + deal.MaxPurchaseQty + "."; if (pastQty >= deal.MaxPurchaseQty) { ErrorMessage += "<BR>You have already purchased the maximum allowed."; } else { int allowedAmount = deal.MaxPurchaseQty - pastQty; ErrorMessage += "<BR>You may only purchase " + allowedAmount + " more."; } ResetOrder(); Response.Redirect("~/Cart.aspx"); } } } } } } if (Order.CheckoutStartDate < Order.LineItemModifiedDate) { ResetOrder(); ErrorMessage = "Your cart has been updated while checking out, please verify you items and continue the checkout process."; Response.Redirect("~/Cart.aspx"); } Order.OrderStatusId = (int)OrderStatus.Processing; orderAdapter.Update(Order); // charge order... NVPCallerServices caller = PayPalAPI.PayPalAPIInitialize(IsDev); NVPCodec encoder = new NVPCodec(); encoder["VERSION"] = "50.0"; encoder["METHOD"] = "DoDirectPayment"; encoder["PAYMENTACTION"] = "Sale"; encoder["AMT"] = subtotal.ToString("0.00"); encoder["CREDITCARDTYPE"] = creditCardType; encoder["ACCT"] = creditCardNumber; encoder["EXPDATE"] = expirationMonthList.SelectedValue + expirationYearList.SelectedValue; encoder["CVV2"] = verificationNumber; encoder["FIRSTNAME"] = firstName; encoder["LASTNAME"] = lastName; encoder["STREET"] = address1; encoder["CITY"] = city; encoder["STATE"] = stateCode; encoder["ZIP"] = zipCode; encoder["COUNTRYCODE"] = "US"; encoder["CURRENCYCODE"] = "USD"; /* * encoder["INVNUM"] = Order.OrderId.ToString(); * encoder["ITEMAMT"] = Order.LineItems.SubTotal.ToString("0.00"); * foreach (DollarSaverDB.OrderLineItemRow lineItem in Order.LineItems.Rows) { * int itemNumber = lineItem.SeqNo - 1; * * encoder["L_NAME" + itemNumber] = lineItem.ShortName; * encoder["L_NUMBER" + itemNumber] = lineItem.CertificateId.ToString(); * encoder["L_QTY" + itemNumber] = lineItem.Quantity.ToString(); * encoder["L_AMT" + itemNumber] = lineItem.DiscountValue.ToString("0.00"); * } */ string paypalRequest = encoder.Encode(); string paypalResponse = String.Empty; try { paypalResponse = caller.Call(paypalRequest); } catch { ResetOrder(); ErrorMessage = "An error occurred while processing your order, please try submitting it again."; return; } NVPCodec decoder = new NVPCodec(); decoder.Decode(paypalResponse); string strAck = decoder["ACK"]; if (strAck != null && (strAck == "Success" || strAck == "SuccessWithWarning")) { string transactionId = decoder["TRANSACTIONID"]; Order.TransactionId = transactionId; Order.OrderDate = DateTime.Now; Order.OrderStatusId = (int)OrderStatus.Complete; orderAdapter.Update(Order); InfoMessage = "Successfully processed order"; if (SendReceipt()) { InfoMessage += "<BR />Receipt sent to " + Order.ShippingEmail; } if (Order.AddToMailingList) { CustomerContactTableAdapter customerContactAdapter = new CustomerContactTableAdapter(); customerContactAdapter.Insert(StationId, DateTime.Now, Order.ShippingEmail, Order.BillingFirstName, Order.BillingLastName); } Response.Redirect("~/Confirmation.aspx", true); return; } else { ResetOrder(); ErrorMessage = "Error! " + decoder["L_LONGMESSAGE0"] + " (" + decoder["L_ERRORCODE0"] + ")"; return; } }
void saveButton_Click(object sender, EventArgs e) { OrderLineItemTableAdapter lineItemAdapter = new OrderLineItemTableAdapter(); CertificateNumberTableAdapter certificateNumberAdapter = new CertificateNumberTableAdapter(); decimal subtotal = 0.0m; foreach (RepeaterItem item in lineItemRepeater.Items) { if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem) { HiddenField lineItemIdHidden = (HiddenField)item.FindControl("lineItemIdHidden"); int lineItemId = Convert.ToInt32(lineItemIdHidden.Value); DollarSaverDB.OrderLineItemRow lineItem = lineItemAdapter.GetOrderLineItem(lineItemId)[0]; //DropDownList qtyList = (DropDownList)item.FindControl("qtyList"); //int qty = Convert.ToInt32(qtyList.SelectedValue); /* * if (lineItem.Quantity != qty) { * * * int returnedQty = lineItem.Quantity - qty; * certificateNumberAdapter.Return(lineItem.OrderLineItemId, returnedQty); * * if (qty == 0) { * lineItem.Returned = true; * lineItemAdapter.Update(lineItem); * } else { * lineItem.Quantity = qty; * lineItemAdapter.Update(lineItem); * * DollarSaverDB.OrderLineItemRow returnedItem = order.ReturnedLineItems.GetLineItem(lineItem.CertificateId); * * if (returnedItem != null) { * returnedItem.Quantity += returnedQty; * lineItemAdapter.Update(returnedItem); * } else { * lineItemAdapter.Insert(lineItem.OrderId, -1, returnedQty, lineItem.CertificateId, * lineItem.ShortName, lineItem.Description, lineItem.FaceValue, lineItem.Discount, lineItem.DiscountTypeId, lineItem.Printable, true); * } * } * * } */ GridView numberGrid = (GridView)item.FindControl("numberGrid"); int returnedQty = 0; foreach (GridViewRow certNumberRow in numberGrid.Rows) { CheckBox deleteBox = (CheckBox)certNumberRow.FindControl("deleteBox"); if (deleteBox.Checked) { returnedQty++; HiddenField certNumberIdHidden = (HiddenField)certNumberRow.FindControl("certNumberIdHidden"); int certNumberId = Convert.ToInt32(certNumberIdHidden.Value); DollarSaverDB.CertificateNumberRow certNumber = certificateNumberAdapter.GetCertificateNumber(certNumberId)[0]; certNumber.SetOrderLineItemIdNull(); certificateNumberAdapter.Update(certNumber); } } if (returnedQty > 0) { DollarSaverDB.OrderLineItemRow returnedItem = order.ReturnedLineItems.GetLineItem(lineItem.CertificateId); if (returnedItem != null) { returnedItem.Quantity += returnedQty; lineItemAdapter.Update(returnedItem); if (returnedQty == lineItem.Quantity) { lineItemAdapter.Delete(lineItem.OrderLineItemId); } else { lineItem.Quantity -= returnedQty; lineItemAdapter.Update(lineItem); subtotal += lineItem.Total; } } else { if (returnedQty == lineItem.Quantity) { lineItem.Returned = true; lineItemAdapter.Update(lineItem); } else { lineItemAdapter.Insert(lineItem.OrderId, -1, returnedQty, lineItem.CertificateId, lineItem.ShortName, lineItem.Description, lineItem.FaceValue, lineItem.Discount, lineItem.DiscountTypeId, lineItem.DeliveryTypeId, lineItem.DeliveryNote, true); lineItem.Quantity -= returnedQty; lineItemAdapter.Update(lineItem); subtotal += lineItem.Total; } } } else { subtotal += lineItem.Total; } } } order.SubTotal = subtotal; order.GrandTotal = subtotal; OrderTableAdapter orderAdapter = new OrderTableAdapter(); orderAdapter.Update(order); InfoMessage = "Order updated"; Response.Redirect("~/admin/OrderView.aspx?id=" + orderId); }