// asp code Generated by Basic Processor
// Original Page Name: C:\gmTestBed\FMStocks\src\FMSWeb\ASP\Portfolio.asp

namespace FMSWeb
{
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using VBNET=Microsoft.VisualBasic;
using gmRTL.Core;

public partial class _Portfolio : System.Web.UI.Page
{
   public FMSWeb._t_head _t_head1 = null;
   public FMSWeb._t_begin _t_begin1 = null;
   public FMSWeb._t_end _t_end1 = null;

   protected void Page_Load(object sender, EventArgs e)
   {
      _t_head1 = new FMSWeb._t_head();
      _t_begin1 = new FMSWeb._t_begin();
      _t_end1 = new FMSWeb._t_end();
      _t_begin1.Include_Load(_t_head1);
      _t_end1.Include_Load(_t_head1);
   }
   private FMStocks_Bus.Account objAccount = new FMStocks_Bus.Account();
   public void ListPositions()
   {
      gmRTL.DataLib.SqlClient.Recordset rs = null;
      int rownum = 0;
      double total = 0.0;
      double mv = 0.0;
      double tempMarketValue = 0.0;
      double tempYouPaid = 0.0;
      gmRTL.Core.ErrorHandling.ResumeNext(() =>
      {
         rs = objAccount.ListPositions(_t_head1.g_AccountID.ToInt());
         if (gmRTL.Core.GlobalException.Instance.Number != 0)
         {
            _t_head1.BuildErrorMessage();
            return;
         }
      });
      rownum = 0;
      total = 0;
      mv = 0;
      if (!(rs.EOF && rs.BOF))
      {
         EmitHeader();
         while (!(rs.EOF))
         {
            rownum = rownum + 1;
            if (rownum % 2 == 0)
            {
               HttpContext.Current.Response.Write("<tr bgcolor=\"#D8D8D8\">");
            }
            else
            {
               HttpContext.Current.Response.Write("<tr bgcolor=\"#FFFFCC\">");
            }
            tempMarketValue = rs.Fields["SharesOwned"].Value.ToDbl() * rs.Fields["LastPrice"].Value.ToDbl();
            tempYouPaid = rs.Fields["SharesOwned"].Value.ToDbl() * rs.Fields["AvgPricePaid"].Value.ToDbl();
            Item(rs.Fields["ticker"].Value,"left");
            Item(rs.Fields["company"].Value,"left");
            Item(rs.Fields["SharesOwned"].Value,"right");
            Item(rs.Fields["LastPrice"].Value,"right");
            Item(gmRTL.Core.FormatHelper.FormatCurrency(tempMarketValue,-1,gmRTL.Core.Enums.TriState.UseDefault,gmRTL.Core.Enums.TriState.UseDefault,gmRTL.Core.Enums.TriState.UseDefault),"right");
            Item(rs.Fields["AvgPricePaid"].Value,"right");
            Item(gmRTL.Core.FormatHelper.FormatCurrency(tempYouPaid,-1,gmRTL.Core.Enums.TriState.UseDefault,gmRTL.Core.Enums.TriState.UseDefault,gmRTL.Core.Enums.TriState.UseDefault),"right");
            HttpContext.Current.Response.Write("</tr>");
            total = total + tempYouPaid;
            mv = mv + tempMarketValue;
            rs.MoveNext();
         }
         EmitFooter(total,mv);
      }
      else
      {
         HttpContext.Current.Response.Write("<p>Your portfolio is empty. Click <a href='buystock.aspx'>here</a> to purchase stocks.</p>");
      }
      rs = null;
   }
   public void Item(object text,string align)
   {
      HttpContext.Current.Response.Write("	<td nowrap class='StockItem' align='" + align + "'>" + text + "</td>" + "\n");
   }
   public void EmitHeader()
   {
      HttpContext.Current.Response.Write("<tr>" + "\n");
      HttpContext.Current.Response.Write("	<td><p class='section'>Your portfolio</p>" + "\n");
      HttpContext.Current.Response.Write("<tr>" + "\n");
      HttpContext.Current.Response.Write("	<td>" + "\n");
      HttpContext.Current.Response.Write("	<table cellpadding='0' cellspacing='0' border='0'>" + "\n");
      HttpContext.Current.Response.Write("	<tr>" + "\n");
      HttpContext.Current.Response.Write("		<td class='StockHeading'>Symbol&nbsp;&nbsp;" + "\n");
      HttpContext.Current.Response.Write("		<td class='StockHeading'>Name" + "\n");
      HttpContext.Current.Response.Write("		<td class='StockHeading' align='right' width='50'>Qty" + "\n");
      HttpContext.Current.Response.Write("		<td class='StockHeading' width='50' align='right'>Last Price" + "\n");
      HttpContext.Current.Response.Write("		<td class='StockHeading' align='right'>Current Value" + "\n");
      HttpContext.Current.Response.Write("		<td class='StockHeading' align='right'>Avg. Price" + "\n");
      HttpContext.Current.Response.Write("		<td class='StockHeading' align='right'>Total Investment" + "\n");
      HttpContext.Current.Response.Write("	<tr>" + "\n");
      HttpContext.Current.Response.Write("		<td colspan='14' bgcolor='purple'>" + "\n");
      HttpContext.Current.Response.Write("		<img src='images/dot_clear.gif' width='1' height='1'></td></tr>" + "\n");
   }
   public void EmitFooter(double total,double mv)
   {
      decimal net = 0.00M;
      net = (mv - total).ToDec();
      string msg = "";
      if (net > 0)
      {
         msg = "Gain";
      }
      else
      {
         msg = "Loss";
      }
      HttpContext.Current.Response.Write("	<tr><td height='8'></td></tr>" + "\n");
      HttpContext.Current.Response.Write("	<tr bgcolor='#FFCC00'>" + "\n");
      HttpContext.Current.Response.Write("		<td colspan='2' class='StockItemNoBorder'>Subtotals:</td>" + "\n");
      HttpContext.Current.Response.Write("		<td colspan='3' class='StockItemNoBorder' align='right'>" + gmRTL.Core.FormatHelper.FormatCurrency(mv,-1,gmRTL.Core.Enums.TriState.UseDefault,gmRTL.Core.Enums.TriState.UseDefault,gmRTL.Core.Enums.TriState.UseDefault) + "</td>" + "\n");
      HttpContext.Current.Response.Write("		<td class='StockItemNoBorder' align='right'>&nbsp</td>" + "\n");
      HttpContext.Current.Response.Write("		<td class='StockItemNoBorder' align='right'>" + gmRTL.Core.FormatHelper.FormatCurrency(total,-1,gmRTL.Core.Enums.TriState.UseDefault,gmRTL.Core.Enums.TriState.UseDefault,gmRTL.Core.Enums.TriState.UseDefault) + "</td>" + "\n");
      HttpContext.Current.Response.Write("		<td colspan='4'>" + "\n");
      HttpContext.Current.Response.Write("		<img src='images/dot_clear.gif' width='1' height='1'></td>" + "\n");
      HttpContext.Current.Response.Write("	</tr>" + "\n");
      HttpContext.Current.Response.Write("	<tr bgcolor='#FFCC00'>" + "\n");
      HttpContext.Current.Response.Write("		<td colspan='99' class='StockItemNoBorder'><b>Net " + msg + "&nbsp " + gmRTL.Core.FormatHelper.FormatCurrency(net,-1,gmRTL.Core.Enums.TriState.UseDefault,gmRTL.Core.Enums.TriState.UseDefault,gmRTL.Core.Enums.TriState.UseDefault) + "</b></td>" + "\n");
      HttpContext.Current.Response.Write("	</tr>" + "\n");
      HttpContext.Current.Response.Write("		<td>&nbsp</td>" + "\n");
      HttpContext.Current.Response.Write("	<tr>" + "\n");
      HttpContext.Current.Response.Write("	</tr>" + "\n");
      HttpContext.Current.Response.Write("	<tr><td colspan='9'><table><tr>" + "\n");
      HttpContext.Current.Response.Write("		<td><p class='section'></p></td>" + "\n");
      HttpContext.Current.Response.Write("		<td align='right'><img src='images/djianasd.png'></td>" + "\n");
      HttpContext.Current.Response.Write("	</tr></table></td></tr>" + "\n");
      HttpContext.Current.Response.Write("	</table>" + "\n");
   }
}
}
