コード例 #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     Page.Form.DefaultFocus = symbols.ClientID;
     
     //Must get/decrypt FormsAuthentication ticket on this page only to get session created date for display.  
     //Would recommend not displaying session create date if really do not need to; depending on
     //configured Forms authentication protection level, decrypting ticket might be expensive!
     //We are needing to do here only to maintain same functionality as WebSphere Trade 6.1
     //for consistency and comparative benchmarking reasons.  If not for this, would simply need to grab userid 
     //(from which all logic/queries in this app are driven off of), from httpcontext.  You will note
     //in other authenticated pages where we do not need to display session created date on the aspx page for the user,
     //we just get userid from a property on the child ClosedOrders.Ascx control, which has gotten it
     //from HttpContext.Current.User.Identity.Name.  This control is embedded on every authenticated page per
     //Trade 6.1 design. This also avoids use of server-side Session state object entirely.  Its not that this is 
     //much faster than session state, the BIG advantage is that for deploying to web farms/clusters you never
     //have to worry about using ASP.NET state server or database configuration; it's "cluster-safe/webfarm-ready"
     //out of the box.
     HttpCookie authcookie = Request.Cookies[FormsAuthentication.FormsCookieName];
     if (authcookie == null)
         logout();
     FormsAuthenticationTicket ticket = (FormsAuthenticationTicket)FormsAuthentication.Decrypt(authcookie.Value);
     if (ticket == null)
         logout();
     userid = ticket.Name;
     SessionCreateDate.Text = ticket.IssueDate.ToString();
     // Create the delegate.
     caller1 = new GetHoldingsAsync(GetHoldings);
     // Initiate the asychronous call.
     result1 = caller1.BeginInvoke(null, null);
     // Repeat
     caller2 = new GetCustomerAsync(GetCustomer);
     // Initiate the asychronous call.
     result2 = caller2.BeginInvoke(null, null);
 }
コード例 #2
0
ファイル: Home.xaml.cs プロジェクト: vactorwu/catch23-project
        public override void onSectionReady()
        {
            if (App.BSL == null || Login.UserInfo == null)
            {
                this.Visibility = Visibility.Hidden;
                return;
            }

            Update.Text = "as of " + DateTime.Now;

            try
            {
                GetHoldingsAsync caller1 = new GetHoldingsAsync(GetHoldings);
                // Initiate the asychronous call.
                IAsyncResult result1 = caller1.BeginInvoke(null, null);
                // Repeat
                GetCustomerAsync caller2 = new GetCustomerAsync(GetCustomer);
                // Initiate the asychronous call.
                IAsyncResult result2 = caller2.BeginInvoke(null, null);
                MarketSummaryDataModelWS summary = App.BSL.getMarketSummary();
                List<HoldingDataModel> holdings = caller1.EndInvoke(result1);
                AccountDataModel customer = caller2.EndInvoke(result2);
                decimal marketValue = 0;
                decimal gain = 0;
                decimal basis = 0;
                decimal _gain = (decimal)0.00;
                decimal percentGain = (decimal)0.00;

                for (int i = 0; i < holdings.Count; i++)
                {
                    QuoteDataModel quote = App.BSL.getQuote(holdings[i].quoteID);
                    decimal _marketValue = (decimal)holdings[i].quantity * quote.price;
                    decimal _basis = (decimal)holdings[i].quantity * (decimal)holdings[i].purchasePrice;
                    gain += _marketValue - _basis;
                    marketValue += _marketValue;
                    basis += _basis;
                }

                AccountID.Text = customer.accountID.ToString();
                CreationDate.Text = customer.creationDate.ToString();
                LoginCount.Text = customer.loginCount.ToString();
                OpenBalance.Text = string.Format("{0:C}", customer.openBalance);
                Balance.Text = string.Format("{0:C}", customer.balance);
                NumHoldings.Text = holdings.Count.ToString();
                HoldingsTotal.Text = string.Format("{0:C}", marketValue);
                decimal totalcashandholdings = marketValue + customer.balance;
                SumOfCashHoldings.Text = string.Format("{0:C}", totalcashandholdings);
                _gain = totalcashandholdings - customer.openBalance;
                if (customer.openBalance != 0)
                    percentGain = gain / customer.openBalance * 100;
                else
                    percentGain = 0;

                Gain.Text = string.Format("{0:C}", _gain);
                PercentGain.Text = string.Format("{0:N}%", percentGain);
                if (_gain > 0)
                {
                    PercentGain.Foreground = new SolidColorBrush(Color.FromRgb(37, 120, 32));

                    GainIcon icon = new GainIcon();
                    icon.VerticalAlignment = VerticalAlignment.Bottom;
                    icon.HorizontalAlignment = HorizontalAlignment.Left;
                    icon.Margin = new Thickness(PercentGain.Margin.Left + PercentGain.ActualWidth + 40, PercentGain.Margin.Top, PercentGain.Margin.Right, PercentGain.Margin.Bottom);
                    LayoutRoot.Children.Add(icon);
                }
                else if (_gain < 0)
                {
                    PercentGain.Foreground = new SolidColorBrush(Color.FromRgb(191, 0, 0));
                    LossIcon icon = new LossIcon();
                    icon.VerticalAlignment = VerticalAlignment.Bottom;
                    icon.HorizontalAlignment = HorizontalAlignment.Left;
                    icon.Margin = new Thickness(PercentGain.Margin.Left + PercentGain.ActualWidth + 40, PercentGain.Margin.Top, PercentGain.Margin.Right, PercentGain.Margin.Bottom);
                    LayoutRoot.Children.Add(icon);

                }
                else
                    PercentGain.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0));

                
                TSIA.Text = String.Format("{0:N}", summary.TSIA);
                Volume.Text = String.Format("{0:N}", summary.volume);

                DataProvider data = new DataProvider();
                for (int i = 0; i < summary.topGainers.Count; i++)
                {
                    QuoteDataModel quote = summary.topGainers[i];



                    RowDataProvider row = new RowDataProvider();
                    row.id = i;

                    // symbol, current price, gain
                    row.Add(new GridColumnData());
                    row[0].value = quote.symbol;
                    row[0].numeric = i;

                    row.Add(new GridColumnGainData());
                    row[1].value = string.Format("{0:C}", quote.price);
                    row[1].numeric = (int)(quote.price * 100);
                    (row[1] as GridColumnGainData).increased = quote.change == 0 ? 0 : (quote.change > 0 ? 1 : -1);

                    row.Add(new GridColumnGainData());
                    row[2].value = string.Format("{0:C}", quote.change);
                    row[2].numeric = (int)(quote.change * 100);
                    (row[2] as GridColumnGainData).increased = quote.change == 0 ? 0 : (quote.change > 0 ? 1 : -1);

                    data.Add(row);
                }

                GainGrid.setData(data);

                data = new DataProvider();
                for (int i = 0; i < summary.topLosers.Count; i++)
                {
                    QuoteDataModel quote = summary.topLosers[i];




                    RowDataProvider row = new RowDataProvider();
                    row.id = i;

                    // symbol, current price, gain
                    row.Add(new GridColumnData());
                    row[0].value = quote.symbol;
                    row[0].numeric = i;

                    row.Add(new GridColumnGainData());
                    row[1].value = string.Format("{0:C}", quote.price);
                    row[1].numeric = (int)(quote.price * 100);
                    (row[1] as GridColumnGainData).increased = quote.change == 0 ? 0 : (quote.change > 0 ? 1 : -1);

                    row.Add(new GridColumnGainData());
                    row[2].value = string.Format("{0:C}", quote.change);
                    row[2].numeric = (int)(quote.change * 100);
                    (row[2] as GridColumnGainData).increased = quote.change == 0 ? 0 : (quote.change > 0 ? 1 : -1);

                    data.Add(row);
                }

                LoseGrid.setData(data);

                SessionCreateDate.Text = Login.LoginTime.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "StockTrader - Exception", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            this.Visibility = Visibility.Visible;
        }