protected override void OnLoad(EventArgs e)
 {
     //Thread.Sleep(10000);
     string userid = HttpContext.Current.User.Identity.Name;
     if (userid != null)
     {
         string action = Request["action"];
         if (!(Request["action"] == null) && !Input.InputText(Request["action"], StockTraderUtility.EXPRESSION_NAME_13))
         {
             FormsAuthentication.SignOut();
             Response.Redirect(Settings.PAGE_LOGIN, true);
         }
         else
         {
             BSLClient businessServicesClient = new BSLClient();
             if (action == "showtoporders" && (Settings.ACCESS_MODE != StockTraderUtility.BSL_SOAP))
             {
                 ordersRequested = Settings.MAX_DISPLAY_TOP_ORDERS;
                 orderData = businessServicesClient.getTopOrders(userid);
             }
             else
             {
                 ordersRequested = Settings.MAX_DISPLAY_ORDERS;
                 orderData = businessServicesClient.getOrders(userid);
             }
             if (orderData.orders.Count != 0)
             {
                 AccountOrdersRepeater.DataSource = orderData.orders;
                 AccountOrdersRepeater.DataBind();
             }
             totalOrders = orderData.orders.Count;
         }
     }
 }
 protected override void OnLoad(EventArgs e)
 {
     BSLClient businessServicesClient = new BSLClient();
     marketSummaryData = businessServicesClient.getMarketSummary();
     List<QuoteDataUI> topGainers = marketSummaryData.topGainers;
     List<QuoteDataUI> topLosers = marketSummaryData.topLosers;
     summaryDate.Text = DateTime.Now.ToString("f");
     TSIA.Text = String.Format("{0:N}",marketSummaryData.TSIA);
     decimal gainpercent =  marketSummaryData.gainPercent;
     if (gainpercent > 0)
     {
         GainPercent.ForeColor = System.Drawing.ColorTranslator.FromHtml("palegreen");  
         GainPercent.Text = String.Format("{0:N}" + Settings.UPARROWLINK, gainpercent);
     }
         else if (gainpercent < 0)
         {
             GainPercent.ForeColor = System.Drawing.ColorTranslator.FromHtml("#A40707");
             GainPercent.Text = String.Format("{0:N}" + Settings.DOWNARROWLINK, gainpercent);
         }
             else
             {
                 GainPercent.Text = String.Format("{0:N}", gainpercent);
             }
     Volume.Text = String.Format("{0:N}", marketSummaryData.volume);
     TopGainers.DataSource = marketSummaryData.topGainers;
     TopLosers.DataSource = marketSummaryData.topLosers;
     TopGainers.DataBind();
     TopLosers.DataBind();
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     string userid = HttpContext.Current.User.Identity.Name;
     if (userid == null)
         logout();
     BSLClient businessServicesClient = new BSLClient();
     totalHoldings = businessServicesClient.getHoldingsBySymbolSubTotaled(userid);
     numOfUniqueStocks.Text = totalHoldings.uniqueStockCount.ToString();
     PortfolioBySymbolRepeater.DataSource = totalHoldings.holdings;
     PortfolioBySymbolRepeater.DataBind();
 }
 private void submitData()
 {
     Page.Validate();
     if (Page.IsValid)
     {
         RegisterMessage.ForeColor = System.Drawing.ColorTranslator.FromHtml("#A40707");
         theFullName = FullName.Text;
         theAddress = Address.Text;
         emailAddress = Email.Text;
         thecreditCard = CreditCard.Text;
         theuserID = UserID.Text;
         thePassword = Password.Text;
         theOpenBalance = Decimal.Parse(OpenBalance.Text);
         AccountDataUI customer = null;
         RegisterMessage.Text = "";
         try
         {
             BSLClient businessServicesClient = new BSLClient();
             customer = businessServicesClient.register(theuserID, thePassword, theFullName, theAddress, emailAddress, thecreditCard, theOpenBalance);
         }
         catch (System.ServiceModel.FaultException)
         {
             //TODO:  Need to use BSL Fault handler to provide fault detail so we can determine if this is real cause of exception.
             RegisterMessage.Text = StockTraderUtility.EXCEPTION_MESSAGE_DUPLICATE_PRIMARY_KEY;
         }
         catch (Exception e)
         {
             //Depending on web.config user setting just catch the duplicate key exception and display a 
             //user-friendly message, or throw a 500 back to browser to make it easy to catch
             //this error from benchmark scripts. You can mark DisplayDuplicateKeyExceptions true/false
             //in Web.Config for this setting.  However, only applies when running in AccessMode = InProcess Activation.
             //else we will get a ServiceModel fault exception (remote) per above catch block.  TODO above is improve handling
             //of remote dupe/key exception from BSL to distinguish vs. a more catastrophic exception--like BSL is offline completely. 
             if (e.Message.Contains(StockTraderUtility.EXCEPTION_DOTNET_DUPLICATE_PRIMARY_KEY) || e.Message.ToLower().Contains(StockTraderUtility.EXCEPTION_WEBSPHERE_DUPLICATE_PRIMARY_KEY.ToLower()))
             {
                 if (Settings.DISPLAY_DUPLICATE_KEY_EXCEPTIONS)
                     throw;
                 RegisterMessage.Text = StockTraderUtility.EXCEPTION_MESSAGE_DUPLICATE_PRIMARY_KEY;
             }
             else
                 if (e.Message.Equals(ConfigSettings.EXCEPTION_SERVICEHOST_NOTREACHABLE))
                     RegisterMessage.Text = Utility.StockTraderUtility.EXCEPTION_MESSAGE_REMOTE_BSL_OFFLINE_EXCEPTION;
                 else
                     RegisterMessage.Text = "We are sorry, the StockTrader application may be down for maintenance, or is experiencing a technical issue. Please try again later.";
         }
         if (RegisterMessage.Text == "")
         {
             FormsAuthentication.SetAuthCookie(customer.profileID, false);
             Response.Redirect(Settings.PAGE_HOME, true);
         }
     }
 }
 protected override void OnLoad(EventArgs e)
 {
     Page.Form.DefaultFocus = Symbols.ClientID;
     BSLClient businessServicesClient = new BSLClient();
     string symbols;
     if (IsPostBack)
     {
         symbols = Symbols.Text;
     }
     else
         symbols = Request.QueryString["symbols"].Trim().ToLower();
     if (symbols != null && symbols.Length > 0 && Input.InputText(symbols, StockTraderUtility.EXPRESSION_QUOTES))
     {
         quoteList = businessServicesClient.getQuotes(symbols);
         Symbols.Text = symbols;
     }
 }
 protected override void OnLoad(EventArgs e)
 {
      HttpCookie authcookie = Request.Cookies[FormsAuthentication.FormsCookieName];
      if (authcookie != null)
      {
          FormsAuthenticationTicket ticket = (FormsAuthenticationTicket)FormsAuthentication.Decrypt(authcookie.Value);
          if (ticket != null)
          {
              if (User.Identity.IsAuthenticated)
              {
                  string userid = User.Identity.Name;
                  BSLClient businessServicesClient = new BSLClient();
                  businessServicesClient.logout(userid);
              }
          }
      }
     
      FormsAuthentication.SignOut();
     
      Response.Redirect(Settings.PAGE_LOGIN, true);         
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     Page.Form.DefaultFocus = quantity.ClientID;
    // if (TextBoxID.Text == "Refresh")
    //     Response.Redirect(Settings.PAGE_HOME, true);
     string userid = HttpContext.Current.User.Identity.Name;
     if (userid == null)
         logout();
     if (!IsPostBack)
     {
         PanelTrade.Visible = false;
         PanelConfirm.Visible = true;
         BSLClient businessServicesClient = new BSLClient();
         string action = Request["action"];
         if (!Input.InputText(action, StockTraderUtility.EXPRESSION_NAME_10))
             Response.Redirect(Settings.PAGE_HOME, true);
         if (action == StockTraderUtility.ORDER_TYPE_BUY)
         {
             string quoteSymbol = Request["symbol"];
             if (!Input.InputText(quoteSymbol, StockTraderUtility.EXPRESSION_QUOTE_ID))
                 Response.Redirect(Settings.PAGE_HOME, true);
             QuoteDataUI quote = businessServicesClient.getQuote(quoteSymbol);
             if (quote == null)
                 Response.Redirect(Settings.PAGE_HOME, true);
             TradeOperation.Text = "<span style=\"text-align:center\">You have requested to <b>buy</b> shares of " + quote.quoteLink + " which is currently trading at " + quote.priceWithArrow + "</span>";
             TextBoxID.Text = quote.symbol;
         }
         else
         {
             int holdingid = 0;
             string holdingID = Request["holdingid"];
             if (!Input.InputText(holdingID, StockTraderUtility.EXPRESSION_HOLDINGID))
                 Response.Redirect(Settings.PAGE_HOME, true);
             try
             {
                 holdingid = Convert.ToInt32(holdingID);
             }
             catch
             {
                 Response.Redirect(Settings.PAGE_HOME,true);
             }
             if (action == StockTraderUtility.ORDER_TYPE_SELL)
             {
                 if (Settings.ACCESS_MODE == StockTraderUtility.BSL_SOAP)
                 {
                     TradeOperation.Text = "You have requested to sell your holding " + holdingID + ". Please confirm this request.";
                     //indicate for postback we are running against WebSphere Java Trade 6.1 which does not implement the functionality/business logic
                     //to sell a portion of a holding--only the entire holding can be sold at once.
                     quantity.Text = "-1";
                     quantity.Visible = false;
                     ButtonTrade.Text = "  Sell  ";
                     TextBoxID.Text = holdingID;
                 }
                 else
                 {
                     HoldingDataUI holding = businessServicesClient.getHolding(userid, holdingid);
                     if (holding == null)
                         Response.Redirect(Settings.PAGE_HOME, true);
                     StringBuilder strBldr = new StringBuilder("You have requested to sell all or part of your holding ");
                     strBldr.Append(holdingID);
                     strBldr.Append(". This holding has a total of ");
                     strBldr.Append(holding.quantity);
                     strBldr.Append(" shares of stock <b>");
                     strBldr.Append(holding.quoteID);
                     strBldr.Append("</b>. Please indicate how many shares to sell.");
                     TradeOperation.Text = strBldr.ToString();
                     decimal amount = Convert.ToDecimal(holding.quantity);
                     quantity.Text = amount.ToString();
                     ButtonTrade.Text = "  Sell  ";
                     TextBoxID.Text = holdingID;
                 }
             }
         }
     }
     else
     {
         PanelTrade.Visible = true;
         PanelConfirm.Visible = false;
     }
 }
        protected void ButtonTrade_Click(object sender, EventArgs e)
        {
            double quantityTrade = 0;
            string symbol = null;
            int holdingID = -1;
            string userid = HttpContext.Current.User.Identity.Name;
            if (userid == null)
                logout();
            if (!double.TryParse(quantity.Text, out quantityTrade))
            {
                RequiredFieldValidator1.IsValid=false;
                RequiredFieldValidator1.ErrorMessage = "Please enter a valid value...";
                return;
            }
            BSLClient businessServicesClient = new BSLClient();
            OrderDataUI order = null;
            string action = Request["action"];
            if (!Input.InputText(action, StockTraderUtility.EXPRESSION_NAME_10))
                Response.Redirect(Settings.PAGE_HOME, true);
            
            if (tradenow == "sell")
            {
                ButtonTrade.Text = "Sell";
                holdingID = Convert.ToInt32((string)Request["holdingid"]);
            }
            else if (tradenow == "buy")
            {
                ButtonTrade.Text = "Buy";
                symbol = (string)Request["symbol"];
            }
            ConfirmMessage.Text = "";
            try
            {
                if (ButtonTrade.Text.Contains("Buy"))
                {
                    if (symbol == null)
                        symbol = TextBoxID.Text;
                    order = businessServicesClient.buy(userid, symbol, quantityTrade);
                }
                else if (ButtonTrade.Text.Contains("Sell"))
                {
                    if (holdingID == -1)
                        holdingID = Convert.ToInt32(TextBoxID.Text);


                    if (quantityTrade == -1)
                        quantityTrade = 0;  //Value of 0 indicates to sell entire holding.
                    order = businessServicesClient.sell(userid, holdingID, quantityTrade);
                }
                else
                    //Goodbye! Only valid ops are buy and sell. This is a harsh 
                    //penalty for trying to be tricky.
                    Response.Redirect(Settings.PAGE_LOGOUT, true);
            }
            catch (System.ServiceModel.FaultException)
            {
                ConfirmMessage.Text = "<span style=\"color:Maroon;\">" + StockTraderUtility.EXCEPTION_MESSAGE_REMOTE_OPS_EXCEPTION + "</span>";
            }
            catch (Exception)
            {
                //Two catch blocks perhaps in future could customize the message a bit more depending on exception type.  
                ConfirmMessage.Text = "<span style=\"color:Maroon;\">" + StockTraderUtility.EXCEPTION_MESSAGE_REMOTE_OPS_EXCEPTION + "</span>";
            }
            if (order != null)
            {
                string orderIdStr = order.orderID.ToString();
                OrderID.Text = orderIdStr;
                OrderStatus.Text = order.orderStatus;
                OpenDate.Text = order.openDate.ToString();
                CompletionDate.Text = order.completionDate.ToString();
                OrderFee.Text = string.Format("{0:C}", order.orderFee);
                OrderType.Text = order.orderType;
                string orderLink = order.quoteLink;
                Symbol.Text = orderLink;
                string orderQty = string.Format("{0:0,0}", order.quantity);
                QtyTraded.Text = orderQty;
                StringBuilder strBuilder = new StringBuilder("Order <b>");
                strBuilder.Append(orderIdStr);
                strBuilder.Append("</b> to ");
                strBuilder.Append(order.orderType);
                strBuilder.Append(" ");
                strBuilder.Append(orderQty);
                strBuilder.Append(" shares of ");
                strBuilder.Append(orderLink);
                strBuilder.Append(" has been submitted for processing.<br/><br/>");
                strBuilder.Append("Order Details:");
                ConfirmMessage.Text = (strBuilder.ToString());
            }
            else
                if (ConfirmMessage.Text=="")
                    ConfirmMessage.Text = StockTraderUtility.EXCEPTION_MESSAGE_BAD_ORDER_RETURN;
            TextBoxID.Text = "";
        }
 AccountDataUI GetCustomer()
 {
     BSLClient businessServicesClient = new BSLClient();
     return businessServicesClient.getAccountData(userid);
 }
 TotalHoldingsUI GetHoldings()
 {
     BSLClient businessServicesClient = new BSLClient();
     return businessServicesClient.getHoldings(userid);
 }
        protected override void OnLoad(EventArgs e)
        {
            
            
            //Here we are going to use an absolute expiration and the .NET object cache to enable
            //the application to optionally not execute the order alert query on every page; rather just check every
            //n seconds (this setting is adjustable in Web.config).  Executing the alert control 
            //logic on every page is not the best design: users can stand to get their completion alerts after 60
            //seconds vs. right away, plus we are going to invalidate the cache entry
            //anyway on an order being placed, so they will only have to wait if they place the order from
            //another browser. The reduction on database queries is substantial (and impact on perf) 
            //simply by making this choice. They will STILL get an order alert within 60 seconds of
            //browsing even if another program (such as the async Order Processor Service or any program) completes 
            //the order outside of the scope of the Web application.

            //Order alerts and stock market summary/mkt index are the only two places in this app that really
            //make sense to cache.  All other data elements such as account info/balances, stock prices,
            //holdings, orders etc. are not good candidates for caching in our opinion.  These data elements 
            //should always reflect what is actually in the database.  This is becuase other systems besides 
            //StockTrader would quite likely be changing this data in the real world, so invalidating the cache within StockTrader app 
            //(ala WebSphere Trade 6.1) does more harm than good--since the middle tier is completely unaware of
            //what other applications may have done to change the database information being cached.
            //On the other hand, order alerts and market summaries are excellent choices for caching:
            //data here can be safely be refreshed every 30, 60 seconds (or more) without impacting data 
            //integrity or alarming a user with an inconsistent value. 

            //The .NET cache for this control will only be used if the Web.config setting
            //"CheckOrderAlertsOnEveryRequest" = false. For benchmark comparisons, its important this be true
            //if measuring .NET perf against WebSphere or other product if those products are not also caching data.
            //In our published data, we used the "true" setting so the control is executed on every
            //requested page, and alerts come up immediately as opposed to slightly delayed.   

            
            string userid = HttpContext.Current.User.Identity.Name;
            if (userid == "")
            {
                HttpCookie authcookie = Request.Cookies[FormsAuthentication.FormsCookieName];
                if (authcookie != null)
                {
                    FormsAuthenticationTicket ticket = (FormsAuthenticationTicket)FormsAuthentication.Decrypt(authcookie.Value);
                    if (ticket != null)
                        userid = ticket.Name;
                }
            }
            string item = (string)Cache[Settings.CACHE_KEY_CLOSED_ORDERSALERT];
            if ((userid != "" && userid != null && Settings.CHECK_ORDER_ALERT_EVERY_REQUEST) || item == null)
            {
                //Either the setting in web.config is set for checking on every page, or
                //the timeout on our cache has expired. So we must invoke our BSL layer
                //now to check for closed orders.
                BSLClient businessServicesClient = new BSLClient();
                closedOrderData = businessServicesClient.getClosedOrders(userid);
                //We are not interested in actually caching any data here: after all, users only get notified
                //via an alert 1 time per order.  Rather, we are using the cache as a convenient way to
                //ensure alert checks only happen based on our desired frequency.  This frequency is set as a config setting.
                if (!Settings.CHECK_ORDER_ALERT_EVERY_REQUEST)
                    Cache.Insert(Settings.CACHE_KEY_CLOSED_ORDERSALERT, "O", null, System.DateTime.UtcNow.AddSeconds(Settings.ORDER_ALERT_CHECK_FREQUENCY), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);
            }
        }
        private void submitData(AccountProfileDataUI customerprofile)
        {
            if (userid.ToLower().Equals("demouser"))
            {
                UpdateMessage.Text = "Demouser cannot be changed.";
                return;
            }
            Page.Validate();
            if (Page.IsValid)
            {

                customerprofile.address = Address.Text;
                customerprofile.creditCard = CreditCard.Text;
                customerprofile.email = Email.Text;
                customerprofile.fullName = FullName.Text;
                customerprofile.password = Password.Text;
                BSLClient businessServicesClient = new BSLClient();
                customerprofile = businessServicesClient.updateAccountProfile(customerprofile);
                ViewState["custprofile"] = customerprofile;
                UpdateMessage.Text = "Account Updated";
            }
        }