protected void SaveLinkButton_Click(object sender, EventArgs e) { FileUpload file = (FileUpload)ProductFormView.FindControl("FileUploadImage") as FileUpload; if (file.HasFile) { file.SaveAs(Server.MapPath("~/ProductImages/" + file.FileName)); Label saveProduct = (Label)ProductFormView.FindControl("ImageUrlLabel") as Label; saveProduct.Text = "~/ProductImages/" + file.FileName; } }
protected void Page_Load(object sender, EventArgs e) { string imagePath = Request.Url.ToString(); string imageName = Path.GetFileName(imagePath); TextBox txt = ProductFormView.FindControl("AddImage") as TextBox; if (txt.Text == "") { txt.Text = "unknown.jpg"; } }
private void LoadProduct(string productId) { try { DataView view = (Cache["Products"] as DataTable).DefaultView; view.RowFilter = "productId = '" + productId + "'"; ProductFormView.DataSource = view; ProductFormView.DataBind(); } catch (Exception ex) { ShowMessage(ex.Message, MessageInfo.Error); } }
protected void GenerateDdlItems() { var fcStock = ProductFormView.FindControl("StockLabel") as Label; string itemStock = fcStock.Text; int cStock = int.Parse(itemStock); // Code Adapted From East, 2012 for (int i = 1; i <= cStock; i++) { ListItem li = new ListItem { Text = i.ToString(), Value = i.ToString() }; ddlProductQuantity.Items.Add(li); } // End of Adapted Code }
protected void Page_Load(object sender, EventArgs e) { //Code to obtain images for image viewer string productId = Request.QueryString["ID"]; string filename = productId + ".jpg"; CurrentImage.ImageUrl = "~/ProductImages/" + filename; GenerateDdlItems(); //Code to convert user's line breaks from database to actual html line breaks //Code Adapted From JK., 2011 var fcDescription = ProductFormView.FindControl("DescriptionLabel") as Label; string itemDesc = fcDescription.Text; string updateItem = itemDesc.Replace("\r\n", "<br />"); test1.Text = updateItem; //End of Adapted Code }
protected void UploadButton_Click(object sender, EventArgs e) { if (IsValid) { Stream stream = FileUpload.FileContent; //Stream stream = FileUpload.FileContent; String name = FileUpload.FileName; try { var image = images.SaveImage(stream, name); isUploaded = true; TextBox txt = ProductFormView.FindControl("AddImage") as TextBox; if (name == "") { txt.Text = "unknown.jpg"; } else { txt.Text = name; } //UploadMessage.Visible = true; //Response.Redirect("Default.aspx/" + image); } catch { var CustomValidator1 = new CustomValidator(); CustomValidator1.IsValid = false; CustomValidator1.ErrorMessage = "Ett fel inträffade då bilden skulle överföras."; this.Page.Validators.Add(CustomValidator1); } } }
/// <summary> /// Behavior for selected index changed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ProductGridView_SelectedIndexChanged(object sender, EventArgs e) { ViewState["ProductId"] = ProductGridView.SelectedDataKey.Value; ProductFormView.ChangeMode(FormViewMode.Edit); }
protected void BtnPurchaseProduct_Click(object sender, EventArgs e) { // Code Adapted from Piras, 2011 var fcPrice = ProductFormView.FindControl("PriceLabel") as Label; var itemPrice = fcPrice.Text; var fcName = ProductFormView.FindControl("NameLabel") as Label; string itemName = fcName.Text; var fcSKU = ProductFormView.FindControl("ModelCodeLabel") as Label; string itemSKU = fcSKU.Text; var fcSize = ProductFormView.FindControl("SizeLabel") as Label; string itemSize = fcSize.Text; // End of adapted code //Obtain product ID to transfer to other page string productId = Request.QueryString["ID"]; decimal postagePackingCost = 4.99m; decimal productPrice = decimal.Parse(itemPrice); decimal quantityOfProduct = int.Parse(ddlProductQuantity.SelectedValue); decimal subtotal = (quantityOfProduct * productPrice); decimal total = subtotal + postagePackingCost; // Authenticate with PayPal var config = ConfigManager.Instance.GetProperties(); var accessToken = new OAuthTokenCredential(config).GetAccessToken(); // Get APIContext Object var apiContext = new APIContext(accessToken); var productItem = new Item { name = itemName + " " + itemSize, currency = "USD", price = productPrice.ToString(), sku = itemSKU, quantity = quantityOfProduct.ToString() }; var transactionDetails = new Details { tax = "0", shipping = postagePackingCost.ToString(), subtotal = subtotal.ToString("0.00") }; var transactionAmount = new Amount { currency = "USD", total = total.ToString("0.00"), details = transactionDetails }; var transaction = new Transaction { description = "Order Summary:", invoice_number = Guid.NewGuid().ToString(), amount = transactionAmount, item_list = new ItemList { items = new List <Item> { productItem } } }; var payer = new Payer { payment_method = "paypal" }; var redirectUrls = new RedirectUrls { cancel_url = "http://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath + "/Cancel.aspx", return_url = "http://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath + "/CompletePurchase.aspx?Quant=" + quantityOfProduct + "&ID=" + productId }; try { var payment = Payment.Create(apiContext, new Payment { intent = "sale", payer = payer, transactions = new List <Transaction> { transaction }, redirect_urls = redirectUrls }); Session["paymentId"] = payment.id; foreach (var link in payment.links) { if (link.rel.ToLower().Trim().Equals("approval_url")) { //Found the appropriate link, send the user there Response.Redirect(link.href); } } } catch (PaymentsException ex) { Response.Write(ex.Response); } }
protected void btnPurchase_Click(object sender, EventArgs e) { var prodPrice = ProductFormView.FindControl("ProductPriceLabel") as Label; var priceItem = prodPrice.Text; var prodName = ProductFormView.FindControl("ProductNameLabel") as Label; string nameItem = prodName.Text; var sizeFc = ProductFormView.FindControl("ProductTypeLabel") as Label; string labelItem = sizeFc.Text; decimal postagePackagingCost = 3.99m; decimal productPrice = decimal.Parse(priceItem); int quantityOfProduct = int.Parse(DDLQuantity.SelectedValue); decimal subTotal = (quantityOfProduct * productPrice); decimal total = subTotal + postagePackagingCost; var config = ConfigManager.Instance.GetProperties(); var accessToken = new OAuthTokenCredential(config).GetAccessToken(); var apiContext = new APIContext(accessToken); var productItem = new Item(); productItem.name = nameItem; productItem.currency = "GBP"; productItem.price = productPrice.ToString(); productItem.sku = "FipPro"; productItem.quantity = quantityOfProduct.ToString(); var transactionDetails = new Details(); transactionDetails.tax = "0"; transactionDetails.shipping = postagePackagingCost.ToString(); transactionDetails.subtotal = subTotal.ToString("0.00"); var transactionAmount = new Amount(); transactionAmount.currency = "GBP"; transactionAmount.total = total.ToString("0.00"); transactionAmount.details = transactionDetails; var transaction = new Transaction(); transaction.description = "Products you have ordered!"; transaction.invoice_number = Guid.NewGuid().ToString(); transaction.amount = transactionAmount; transaction.item_list = new ItemList { items = new List <Item> { productItem } }; var payer = new Payer(); payer.payment_method = "paypal"; var redirectUrls = new RedirectUrls(); redirectUrls.cancel_url = "http://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath + "/Default.aspx"; redirectUrls.return_url = "http://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath + "/user/CompletePurchase.aspx"; var payment = Payment.Create(apiContext, new Payment { intent = "sale", payer = payer, transactions = new List <Transaction> { transaction }, redirect_urls = redirectUrls }); Session["paymentId"] = payment.id; foreach (var link in payment.links) { if (link.rel.ToLower().Trim().Equals("approval_url")) { Response.Redirect(link.href); } } }
protected void btnBuyNow_Click(object sender, EventArgs e) { DropDownList DDLProductQty = (DropDownList)ProductFormView.FindControl("ProductQtyDropDownList"); Label productPrice = (Label)ProductFormView.FindControl("lblProductPrice"); decimal shippingPackagingCost = 5.00m; int productPrice1; int.TryParse((string)productPrice.Text, out productPrice1); int quantityOfProducts = int.Parse(DDLProductQty.SelectedValue); decimal subTotal = (quantityOfProducts * productPrice1); decimal totalAmount = subTotal + shippingPackagingCost; //Authenticate with PayPal var config = ConfigManager.Instance.GetProperties(); var accessToken = new OAuthTokenCredential(config).GetAccessToken(); //Get APIContext Object var apiContext = new APIContext(accessToken); var productStock = new Item(); productStock.name = "Products"; productStock.currency = "SGD"; productStock.price = productPrice1.ToString(); productStock.sku = "ProductCO5027"; //sku is stock keeping unit e.g. manufacturer code productStock.quantity = quantityOfProducts.ToString(); var transactionDetails = new Details(); transactionDetails.tax = "0"; transactionDetails.shipping = shippingPackagingCost.ToString(); transactionDetails.subtotal = subTotal.ToString("0.00"); var transactionAmount = new Amount(); transactionAmount.currency = "SGD"; transactionAmount.total = totalAmount.ToString("0.00"); transactionAmount.details = transactionDetails; var transaction = new Transaction(); transaction.description = "Your order from Fleur.com.bn."; transaction.invoice_number = Guid.NewGuid().ToString(); // this should ideally be the id of a record storing the order transaction.amount = transactionAmount; transaction.item_list = new ItemList { items = new List <Item> { productStock } }; var payer = new Payer(); payer.payment_method = "paypal"; var redirectUrls = new RedirectUrls(); string strPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery; string strUrl = HttpContext.Current.Request.Url.AbsoluteUri.Replace(strPathAndQuery, "/"); redirectUrls.cancel_url = strUrl + "cancel.aspx"; redirectUrls.return_url = strUrl + "completePurchase.aspx"; var payment = Payment.Create(apiContext, new Payment { intent = "sale", payer = payer, transactions = new List <Transaction> { transaction }, redirect_urls = redirectUrls }); Session["paymentId"] = payment.id; foreach (var link in payment.links) { if (link.rel.ToLower().Trim().Equals("approval_url")) { //found the appropriate link, send the user there Response.Redirect(link.href); } } }