// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. // The ASF licenses this file to You under the Apache License, Version 2.0 // (the "License"); you may not use this file except in compliance with // the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // using System; using System.Web; using System.Web.Security; using Trade.BusinessServiceClient; using Trade.StockTraderWebApplicationModelClasses; using Trade.StockTraderWebApplicationSettings; using Trade.Utility; namespace Trade.Web { /// /// Allows users to enter number of shares for a buy/sell operation. /// public partial class StockTrade : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string userid = null; BSLClient businessServicesClient = new BSLClient(); string action = Input.InputText(Request["action"], 5) ?? string.Empty; if (action.Equals(StockTraderUtility.ORDER_TYPE_BUY, StringComparison.InvariantCultureIgnoreCase)) { this.InvalidActionPanel.Visible = false; this.BuyPanel.Visible = true; string quoteSymbol = Input.InputText(Request["symbol"], StockTraderUtility.QUOTESYMBOL_MAX_LENGTH); QuoteDataUI quote = businessServicesClient.getQuote(quoteSymbol); this.Symbol.Value = quoteSymbol; this.BuySymbol.Text = quote.quoteLink; this.BuyCurrentPrice.Text = quote.price.ToString("C"); this.CancelBuy.PostBackUrl = Settings.PAGE_QUOTES + "?symbols=" + quoteSymbol; } else if (action.Equals(StockTraderUtility.ORDER_TYPE_SELL, StringComparison.InvariantCultureIgnoreCase)) { this.InvalidActionPanel.Visible = false; this.SellPanel.Visible = true; this.CancelSell.PostBackUrl = GetReturnUrl(); string holdingIdString = Request["holdingid"]; this.HoldingId.Text = holdingIdString; int holdingId; if (Int32.TryParse(holdingIdString, out holdingId)) { HoldingDataUI holding = businessServicesClient.getHolding(userid, holdingId); this.HoldingQuantity.Text = holding.quantity; this.HoldingSymbol.Text = holding.quoteID; SellQuantityRangeValidator.MaximumValue = holding.quantityDouble.ToString(); if(!this.Page.IsPostBack) SellQuantity.Text = holding.quantityDouble.ToString(); } } else { this.InvalidActionButton.PostBackUrl = GetReturnUrl(); } } protected void Buy_Click(object sender, EventArgs e) { Response.Redirect(Settings.PAGE_ORDER + "?action=" + StockTraderUtility.ORDER_TYPE_BUY + "&symbol=" + this.Symbol.Value + "&quantity=" + this.BuyQuantity.Text); } protected void Sell_Click(object sender, EventArgs e) { Response.Redirect(Settings.PAGE_ORDER + "?action=" + StockTraderUtility.ORDER_TYPE_SELL + "&holdingid=" + this.HoldingId.Text + "&quantity=" + this.SellQuantity.Text); } private string GetReturnUrl() { string returnUrl = Input.InputText(Request["return"], 25) ?? string.Empty; if (!string.IsNullOrEmpty(returnUrl)) { return returnUrl; } if (Request.UrlReferrer != null) { return Request.UrlReferrer.ToString(); } return Settings.PAGE_QUOTES; } } }