// asp code Generated by Basic Processor
// Original Page Name: C:\gmTestBed\FMStocks\src\FMSWeb\ASP\checkout.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 _checkout : System.Web.UI.Page
{
   public FMSWeb._t_head _t_head1 = null;
   public FMSWeb._t_begin_cart _t_begin_cart1 = null;
   public FMSWeb._t_end _t_end1 = null;
   public FMSWeb._t_begin _t_begin1 = null;

   protected void Page_Load(object sender, EventArgs e)
   {
      _t_head1 = new FMSWeb._t_head();
      _t_begin_cart1 = new FMSWeb._t_begin_cart();
      _t_end1 = new FMSWeb._t_end();
      _t_begin1 = new FMSWeb._t_begin();
      _t_begin_cart1.Include_Load(_t_head1, _t_begin1);
      _t_end1.Include_Load(_t_head1);
      _t_begin1.Include_Load(_t_head1);
   }
   private FMStocks_Bus.Version bus = new FMStocks_Bus.Version();
   public void PerformCheckout()
   {
      gmRTL.DataLib.SqlClient.Recordset rs = null;
      double total = 0.0;
      double quantity = 0.0;
      double price = 0.0;
      double subtotal = 0.0;
      rs = _t_begin_cart1.cart.ListByAccount(_t_head1.g_AccountID.ToInt());
      if (rs.EOF)
      {
         // nothing in the cart
         HttpContext.Current.Response.Write("		You have no items in your shopping cart." + "\n");
      }
      else if (HttpContext.Current.Request["Action"] == "Buy")
      {
         _t_begin_cart1.cart.Buy(_t_head1.g_AccountID.ToInt());
         // a buy was executed
         HttpContext.Current.Response.Write("<p><br><br>" + "\n");
         HttpContext.Current.Response.Write("<font size='6'>Thank you for your purchase.</font></p> <br><br><p> An email will be sent" + "\n");
         HttpContext.Current.Response.Write("that contains an itemized list of your items and shipping costs." + "\n");
         HttpContext.Current.Response.Write("<br><br> If you do not recieve this email in the next 12 hours please call" + "\n");
         HttpContext.Current.Response.Write("our customer support number." + "\n");
         HttpContext.Current.Response.Write("</p>" + "\n");
      }
      else
      {
         // things are in the cart
         HttpContext.Current.Response.Write("		<form action='checkout.aspx' method='POST'>" + "\n");
         HttpContext.Current.Response.Write("		<table border='0'>" + "\n");
         HttpContext.Current.Response.Write("		<thead>" + "\n");
         HttpContext.Current.Response.Write("			<tr><th>Quantity<th>Price<th>Sub-total<th>Description" + "\n");
         HttpContext.Current.Response.Write("		<tbody>" + "\n");
         total = 0;
         while (!(rs.EOF))
         {
            quantity = gmRTL.Core.ConversionHelper.DBNullToValue<double>(rs.Fields["Quantity"].Value);
            price = gmRTL.Core.ConversionHelper.DBNullToValue<double>(rs.Fields["Price"].Value);
            subtotal = quantity * price;
            HttpContext.Current.Response.Write("			<tr><td>" + quantity);
            HttpContext.Current.Response.Write("				<td>" + gmRTL.Core.FormatHelper.FormatCurrency(price,-1,gmRTL.Core.Enums.TriState.UseDefault,gmRTL.Core.Enums.TriState.UseDefault,gmRTL.Core.Enums.TriState.UseDefault));
            HttpContext.Current.Response.Write("				<td>" + gmRTL.Core.FormatHelper.FormatCurrency(subtotal,-1,gmRTL.Core.Enums.TriState.UseDefault,gmRTL.Core.Enums.TriState.UseDefault,gmRTL.Core.Enums.TriState.UseDefault));
            HttpContext.Current.Response.Write("				<td><a title='View this product' href='" + "ViewProduct.aspx?SKU=" + rs.Fields["SKU"].Value + "'>" + HttpContext.Current.Server.HtmlEncode(rs.Fields["Description"].Value.ToStr()) + "</a></td>" + "\n");
            rs.MoveNext();
            total = total + subtotal;
         }
         HttpContext.Current.Response.Write("			<tr><td>&nbsp" + "\n");
         HttpContext.Current.Response.Write("			<tr><td align='RIGHT' colspan='2'><b>Total:<td><b>" + gmRTL.Core.FormatHelper.FormatCurrency(total,-1,gmRTL.Core.Enums.TriState.UseDefault,gmRTL.Core.Enums.TriState.UseDefault,gmRTL.Core.Enums.TriState.UseDefault) + "</b>" + "\n");
         HttpContext.Current.Response.Write("			<tr><td colspan='2'><td colspan='2'><input type='SUBMIT' name='Action' value='Buy'>" + "\n");
         HttpContext.Current.Response.Write("		</table>" + "\n");
         HttpContext.Current.Response.Write("		</form>" + "\n");
      }
   }
}
}
