Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add $5.00 amount to shopping cart total when checkbox is selected

Status
Not open for further replies.

yaknowss

Programmer
Apr 19, 2012
69
US
I want the cart total to apply an additional $5.00 charge when the txtBwayEDUGift checkbox is selected. I would also like to have the ability to have that charge removed if users deselect the txtBwayEDUGift checkbox. I've attached my aspx page, lines 11-233 is where you will find a javascript tag function that calculates the order total.

Thank you.

Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ConfirmBwaySeatDetails.aspx.cs"
    Inherits="SubRenewal.ConfirmBwaySeatDetails" %>
<%@ Register Assembly="TSC.Timeout" Namespace="TSC.Timeout" TagPrefix="tsc" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head id="Head1" runat="server">
    <title><%=SeasonDesc %> Subscription Renewal - Confirm your order information</title>
    <link href="css/main.css" rel="stylesheet" type="text/css" />
    <link href="css/BroadwayStyle.css" rel="stylesheet" type="text/css" />
    
    <script type="text/javascript">
    function calculate(increment, indexer)
    {
        var price = document.getElementById("divPrice" + indexer);
        var dPrice = price.innerHTML;
        dPrice = dPrice.replace("$","");
        dPrice = dPrice * 1;
        var subtotal = document.getElementById("txtSubTotal" + indexer);
        var dSubtotal = subtotal.value;
        dSubtotal = dSubtotal.replace("$","");
        dSubtotal = dSubtotal.replace(",","");
        dSubtotal = dSubtotal * 1;
        var tableRow = document.getElementById("tr" + indexer);
        if (increment == "A")
        {
            var newTotal = dSubtotal + dPrice;
            subtotal.value = "$" + newTotal.toString();
            calculateTotal(dPrice, "A");
            tableRow.style.backgroundImage = "url('images/otTableRowSelect.jpg')";
        }
        else if (increment == "S")
        {
            if (dSubtotal > 0)
            {
                var newTotal = dSubtotal - dPrice;
                if (newTotal == 0)
                {
                    subtotal.value = "";
                    calculateTotal(dPrice, "S");
                    tableRow.style.backgroundImage = "";
                    img = document.getElementById("imgSub" + indexer);
                    img.focus();
                }
                else
                {
                    subtotal.value = "$" + newTotal.toString();
                    calculateTotal(dPrice, "S");
                    img = document.getElementById("imgSub" + indexer);
                    img.focus();
                }
            }
        }
        var price2 = document.getElementById("divPrice" + indexer);
        var dPrice2 = price2.innerHTML;
        dPrice2 = dPrice2.replace("$","");
        dPrice2 = dPrice2 * 1;
        var subtotal2 = document.getElementById("txtSubTotal" + indexer);
        var dSubtotal2 = subtotal2.value;
        dSubtotal2 = dSubtotal2.replace("$","");
        dSubtotal2 = dSubtotal2 * 1;
        var txtQnty = document.getElementById("txtQnty" + indexer);
        var qnty = (dSubtotal2/dPrice2);
        if (qnty == 0)
        {
            txtQnty.value = "";
        }
        else
        {
            txtQnty.value = qnty;
        }
    }
    function calculateTotal(amountIn, type)
    {
        var total = document.getElementById("txtTotal");
        var dTotal = total.value.toString().replace("$","");
        dTotal = dTotal.replace(",","");
        dTotal = dTotal * 1;
        if (type == "A")
        {
            var newTotal = dTotal + amountIn;
            total.value = "$" + newTotal;
        }
        else if (type == "S")
        {
            var newTotal = dTotal - amountIn;
            if (newTotal == 0)
            {
                total.value = "";
            }
            else 
            {
                newTotal = addCommas(newTotal);
                total.value = "$" + newTotal;
            }
        }
    }
    function validateAmt(obj, type) //type, 0=OT League, 1=
    {
        var divPrevAmt;
        if (type == 0)
        {
            divPrevAmt = document.getElementById("divBwayGiftPrevAmt");
        }
        else if (type == 1)
        {
            divPrevAmt = document.getElementById("divBwayEDUGiftPrevPmt");
        }
        var txtAmt = document.getElementById(obj);
        var amt = txtAmt.value;
        amt = amt.toString().replace("$","");
        amt = amt.replace(",","");
        var prevAmt = divPrevAmt.innerHTML;
        try
        {
            amt = amt * 1;
        }
        catch(err)
        {
            txtAmt.value = "";
            return;
        }
        if (amt >= 0) //get the previous amount if any
        {
            if (type == 0)
            {
               if (prevAmt.toString().length > 0)
               {
                    prevAmt = prevAmt * 1;
               }
               else
               {
                    prevAmt = 0;
               }
            }
            else if (type == 1)
            {
               if (prevAmt.toString().length > 0)
               {
                    prevAmt = prevAmt * 1;
               }
               else
               {
                    prevAmt = 0;
               }
            }
        //now update the master total
        var total = document.getElementById("txtTotal");
        var dTotal = total.value.toString().replace("$","");
        dTotal = dTotal.replace(",","");
        dTotal = dTotal * 1;
        var newTotal = dTotal - prevAmt;
        newTotal = newTotal + amt;
        divPrevAmt.innerHTML = amt.toString();
        newTotal = addCommas(newTotal);
        amt = addCommas(amt);
        txtAmt.value = "$" + amt;
        total.value = "$" + newTotal;
       }
       else
       {
            txtAmt.value = "";
            return;
       }
    }
    function disable()
    {
        var txtTotal = document.getElementById("txtTotal");
        var txt = txtTotal.value;
        txtTotal.value = txt;
        var BwayGift = document.getElementById("txtBwayGift");
        BwayGift.focus();
    }
    function addCommas(nStr)
    {
	    nStr += '';
	    x = nStr.split('.');
	    x1 = x[0];
	    x2 = x.length > 1 ? '.' + x[1] : '';
	    var rgx = /(\d+)(\d{3})/;
	    while (rgx.test(x1)) {
		    x1 = x1.replace(rgx, '$1' + ',' + '$2');
	    }
	    var newTotal = x1 + x2;
	    if (newTotal.toString().indexOf(".") != -1)
	    {
	        newTotal = newTotal.substring(0,newTotal.indexOf(".") + 3);
	    }
	    return newTotal;
    }
    function checkChanged()
    {
        var cb = document.getElementById("cbOperaGala");
        if (cb.checked == true)
        {
            var tableRow = document.getElementById("trCheckbox");
            tableRow.style.backgroundImage = "url('images/otTableRowSelect.jpg')";
        }
        else if (cb.checked == false)
        {
            var tableRow = document.getElementById("trCheckbox");
            tableRow.style.backgroundImage = "";
        }
    }
    function alertIf()
    {
        var i = 0;
        for (i=5;i<=10;i++)
        {
            try{
            var subtotal2 = document.getElementById("txtSubTotal" + i);
            var dSubtotal2 = subtotal2.value;
            dSubtotal2 = dSubtotal2.replace("$","");
            dSubtotal2 = dSubtotal2 * 1;}
            catch (Error){dSubtotal2 = 0}
            if (dSubtotal2 > 0)
            {
                alert("You have selected the I want it all package, \n however you have also selected individual tickets to the same events. \n If you meant to do this, please disregard this message.");
                break;
            }
        }
    }
    
    function disableEnterKey(e)
    {
     var key;      
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox      

    return (key != 13);
    }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div id="divContainerMain">
        <div class="header">
        </div>
        <div id="mainHolder" style="width: 800px; margin: auto; margin-top: 20px;">
             <table cellspacing="0" cellpadding="2" width="800px" style="border: solid 1px #000000">
                <tr>
                    <td colspan="5">
                        <b>Please review and confirm your order information below:</b>
                    </td>
                </tr>
                  <tr>
                    <td colspan="5">
                         
                    </td>
                </tr>
                  <tr>
                    <td colspan="5" style="text-align:left;">
                        <b><%=PkgDesc %> - Number of seats: <%=NumSeats %></b>
                    </td>
                </tr>
                <tr style="background-color: #590b0b; color: White; font-weight: bold; padding: 2px">
                    <td width="75">
                        Section
                    </td>
                    <td width="50" class="row">  Row</td>
                    <td colspan="3" style="text-align:left;">
                        Seat(s)</td>
                </tr>
                <asp:Repeater ID="repSeats" runat="server">
                    <ItemTemplate>
                        <tr class="tableRow" style="border-top:dashed 1px black">
                            <td width="75" class="row">
                                <%#Eval("zoneDesc").ToString() %>
                            </td>
                            <td width="100" class="row">
                                <%#Eval("seatRow") %>
                            </td>
                            <td colspan="3" class="row" style="text-align:left;">
                                <%#Eval("seatNums") %>
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:Repeater>
                 <tr>
                    <td colspan="4" style=" background-color:#e8e8e8; border-top:dashed 1px black">
                       <div style="float:right; margin-right:40px;"><b>Subscription Price:</b> <%=AmtDue %></div>
                    </td>
                </tr>
                <tr>
                    <td style="font-weight: bold; border-top: solid 1px black; border-bottom: solid 1px black;
                        color: #590b0b" colspan="4">
                        The company is a 501(c)3 not-for-profit corporation
                        that depends on your generous contributions as well as ticket sales to keep the
                        arts alive in the Tampa Bay area.
                        <br />Would you consider making an additional tax-deductible
                        donation to support our mission?
                    </td>
                </tr>
                <tr style="background-color: #590b0b; color: White; font-weight: bold; padding: 2px">
                    <td width="100">
                    </td>
                    <td width="100">
                    </td>
                    <td width="450">
                        Gift Description
                    </td>
                    <td width="150">
                        Gift Amount
                    </td>
                </tr>
                <tr id="tr12" class="tableRow">
                    <td colspan="2" style="border-top: solid 1px black; width:200px;">
                     
                    </td>
                    <td width="450" style="border-top: solid 1px black;">
                        <strong>Add a gift to support</strong><br />
                        <a href="MemberBenefits.html" target="_blank">Member Benefits</a>
                    </td>
                    <td width="150" style="border-top: solid 1px black;">
                        <input id="txtBwayGift" type="text" style="width: 75px" onkeypress="return disableEnterKey(event);"
                        onchange="validateAmt(this.id, 0);" runat="server" />
                        <div id="divBwayGiftPrevAmt" style="color: #fff; font-size: 1px">
                        </div>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                    </td>
                </tr>
                <tr id="tr13" class="tableRow">
                    <td colspan="2" style="border-top: solid 1px black; width:200px;">
                     
                    </td>
                    <td width="450" style="border-top: solid 1px black;">
                        <strong>Add $5 to Support arts education</strong><br />
                    </td>
                    <td width="150" style="border-top: solid 1px black;">
                      <input id="txtBwayEDUGift" type="checkbox" checked="checked" runat="server" /> <strong>Yes</strong>
                        <div id="divBwayEDUGiftPrevPmt" style="color: #fff; font-size: 1px">
                        </div>
                    </td>
                </tr>
                <tr id="tr1" class="row3">
                    <td colspan="2" style="border-top: solid 1px black; width:200px;">
                     
                    </td>
                    <td width="450" style="border-top: solid 1px black;">
                        <strong>Cart total will reflect gift amount upon checkout.</strong><br />
                    </td>
                    <td width="150" style="border-top: solid 1px black;"> 
                     </td>
                </tr>
                <tr>
                     <td colspan="4" class="row3" style="padding-left:60px";> 
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <div style="width: 800px">
                            <div style="float: right; margin: 0 48px 0 10px; width:75px">
                                <asp:TextBox ID="txtTotal" runat="server" Width="75px" BorderColor="Black" BorderWidth="1px"
                                    onblur="disable();" onfocus="disable();" onchange="disable();"></asp:TextBox>
                            </div>
                            <div style="float: right;">
                                <b>Total:</b></div>
                        </div>
                    </td>
                </tr>
                <tr>
                      <td colspan="4" class="row">
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <div style="width: 800px">
                            <div style="float: right; margin: 0 45px 0 10px; width: 100px">
                                <div class="btnSmallActive" style="float: left; margin: 5px 0 0 20px">
                                    <a>
                                        <asp:ImageButton ID="btnCheckout" runat="server" ImageUrl="images/checkOut.png" 
                                        OnClick="btnCheckout_Click" /></a></div>
                            </div>
                        </div>
                    </td>
                </tr>
             </table>
            <br />
            <br />
        </div>
        <div id="footer" class="footer">
        </div>
    </div>
    <script type="text/javascript">
    var amtDue = '<%=AmtDue %>';
    var total = document.getElementById("txtTotal");
    total.value = amtDue;
    </script>
     </form>
</body>
</html>
 
nowhere in your code do you refer (in javascript) to txtBwayEDUGift. do you do not appear to be testing for its value, and therefore making no conditional tests against it.

that's the place to start.
 
This is true. I am unsure how or where to refer txtBwayEDUGift in my javascript. I am looking for suggestions.
 
attach an on change event to trigger checkboxAdd.

Code:
onChange="checkboxAdd(this);"

get rid of the runat directive.

Code:
function checkboxAdd( ctl ){
 if(ctl.checked == true ){
   calculateAmount(5, "A");
  } else {
   calculateAmount( 5, "S");
  }
}

if your server code does not automatically do this too, make sure you also fire off this scriptlet on page load.
 
Okay I'll give it a shot and let you know my results. Most likely won't be until tomrrow. Thank u!!!
 
I've added the following code to my page:
Code:
<input type="checkbox" name="txtBwayEDUGift" onchange="checkboxadd(this);" checked="checked" />

function checkboxAdd( ctl ){
 if(ctl.checked == true ){
   calculateAmount(5, "A");
  } else {
   calculateAmount( 5, "S");
  }
}

However, I received an error when testing - Microsoft JScript runtime error: Object expected.
 
i see nothing wrong with that code, save that the capitalisation is not consistent with the call to checkboxadd and the function name.

to what line number did the error pertain? might it be elsewhere in your code?

test this by stubbing out the calculateAmount function calls

Code:
<input type="checkbox" name="txtBwayEDUGift" onchange="checkboxAdd(this);" checked="checked" />
<script type="text/javascript">
function checkboxAdd( ctl ){
 if(ctl.checked == true ){
   alert("adding $5");
   //calculateAmount(5, "A");
  } else {
   alert("deducting $5");
   //calculateAmount( 5, "S");
  }
} 
</script>
 
Does the calculateAmmount() function exist? I see no mention of it in your code above, only calculate() and calculateTotal() functions seem to be defined there.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
ah yes .... good spot ;)

should have been calculateTotal()
 
I've added your code and did not receive the runtime error like before. When I went to debug, I noticed the txtTotal was not including the additional $5.00 charge that I hoped for when the checkbox was checked. However, a pop-up message appeared when I checked and unchecked the box.

Picture1
Picture2
 
So you know that the code is not generating the error any more.
So comment out the alerts and delete the comments on the calculateTotal lines (remember to change to Total rather than Amount)
 
Thank you for your help. I commented out the alerts, replaced the calculateAmount to calculateTotal.

It appears the functionality is there and is working to an extent. But instead of adding the $5.00 charge to the order, it is instead keeping the orginal amount and only reducing the amount when unchecked. It is not adding the $5.00 to the order amount when checked. Please see my screenshots below. With the $5.00 added the order amount should be $1,126.00 in my example. I hope this makes sense. Please help in anyway possible. thank you.


Picture-1
Picture-2
 
I suspect that you did not add the 5.00 in the server side code.

you can work around this with javascript but you _must_ revalidated in the server side code.

Code:
<input type="checkbox" name="txtBwayEDUGift" id="txtBwayEDUGift" onchange="checkboxAdd(this);" checked="checked" />
<script type="text/javascript">
function checkboxAdd( ctl ){
 if(ctl.checked == true ){
  // alert("adding $5");
   calculateTotal(5, "A");
  } else {
   //alert("deducting $5");
   calculateTotal( 5, "S");
  }
}
//note this only works in newer browsers. if older browsers are of concern then you should adapt accordingly
document.addEventListener('DOMContentLoaded',
                           checkboxAdd(document.getElementById('txtBwayEDUGift')));
</script>

however now that i see your screen shots i'd suggest that the better way of dealing with this structurally would be to add/delete a product to the list. that way you could more easily do server side validation.

also, I don't entirely trust the calculateTotal function. I would prefer to see some code which picked up each line item of the 'cart' and recalculated the total based on that each time.

have you considered perhaps using an open source shopping cart?

 
No I have not considered an open source shopping cart. This page was built by a previous developer and I am trying to modify the existing infrastructure to meet the requirements.

I'm unsure where I would validate in the server side code. Below is the C# file if you want to take a look. This page is using javascript and C#, which I have minimal experience in. There is a section "addDonation" could I validate here? Thanks for your help thus far. I do appreciate it greatly.

Code:
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using System.Configuration;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Web;
using SubRenewal.com.Tessy;
using SubRenewal.Classes;
using TSC.Timeout;
using System.Web.UI.HtmlControls;
using System.Web.Services.Protocols;

namespace SubRenewal
{
    public partial class ConfirmBwaySeatDetails : System.Web.UI.Page
    {
        protected class SeatInfo
        {
            public string seatRow { get; set; }
            public string seatNum { get; set; }
            public string seatNo { get; set; }
            public int packageNo { get; set; }
            public string zoneDesc { get; set; }
            public int zoneNo { get; set; }
            public int priceType { get; set; }
            public string facilDesc { get; set; }
        }
        protected class SeatToDisplay
        {
            public string zoneDesc { get; set; }
            public string seatRow { get; set; }
            public string seatNums { get; set; }
        }
        private string _priceToUse = ""; //depending on whether or not user is a member
        public string PriceToUse
        {
            get { return _priceToUse; }
        }
        private string _amtDue = ""; //depending on whether or not user is a member
        public string AmtDue
        {
            get { return _amtDue; }
        }
        private string _seasonDesc = "";
        public string SeasonDesc
        {
            get { return _seasonDesc; }
        }
        private string _numSeats = "";
        public string NumSeats
        {
            get { return _numSeats; }
        }
        private string _pkgDesc = "";
        public string PkgDesc
        {
            get { return _pkgDesc; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Tessitura tess = new Tessitura();
                Activity a = new Activity();
                _seasonDesc = a.getSeasonDesc(1); //1=BWay
                if (Session["renewType"] == null)
                    Response.Redirect("~/Default.aspx");
                string sessionKey = a.getSession();
                DataSet dsConstitInfo = tess.GetConstituentInfo(sessionKey);
                int customerNo = Convert.ToInt32(dsConstitInfo.Tables["ConstituentHeader"].Rows[0]["customer_no"]);
                Session["customerNo"] = customerNo;
                Session["fullName"] = dsConstitInfo.Tables["ConstituentHeader"].Rows[0]["full_name1"].ToString();
                foreach (DataRow drCInfo in dsConstitInfo.Tables["Addresses"].Rows)
                {
                    if (drCInfo["primary_ind"].ToString() == "Y")
                        Session["addressNo"] = Convert.ToInt32(drCInfo["address_no"]);
                }
                DataView dvAtts = dsConstitInfo.Tables[1].DefaultView;
                //dvAtts.RowFilter = "attribute = 'League 1011 Member'";
                ////determine whether or not user is a member
                //bool isLeagueMember = false;
                //if (dvAtts.ToTable().Rows.Count > 0)
                //{
                //    string sLeagueMember = dvAtts[0][1].ToString();
                //    if (sLeagueMember == "Y")
                //        isLeagueMember = true;
                //}
                //set price to use based on membership status
                //_priceToUse = a.getOTSubPrice(isLeagueMember).ToString();
                dvAtts.Dispose();
                //change mos to 8
                int mos = a.getMOS();
                tess.ChangeModeOfSaleEx(sessionKey, mos);
                DataSet dsSubOrders = tess.GetOrdersEx(sessionKey, 0, "", 'N', "", "", 0, customerNo, 8, 'Y', 0);
                //NOW Look for the open order
                DataTable dtOpenOrders = dsSubOrders.Tables[0];
                DataView dvOpenOrders = new DataView(dtOpenOrders);
                dvOpenOrders.Sort = "tot_paid_amt ASC";
                dtOpenOrders = dvOpenOrders.ToTable();
                dvOpenOrders.Dispose();
                int currentOrderNo = 0;
                if (dtOpenOrders.Rows.Count >= 1)
                {
                    bool hasBwayOrders = false;
                    foreach (DataRow dr in dtOpenOrders.Rows)
                    {
                        if (hasBwayOrders == true)
                            break;
                        bool orderLocked = false;
                        int status = Convert.ToInt32(dr["status"]);
                        decimal paidAmt = Convert.ToDecimal(dr["tot_paid_amt"]);
                        if (status != 1 && paidAmt == 0)
                            orderLocked = true;
                        int tempOrderNumber = Convert.ToInt32(dr["order_no"]);
                        DataSet dsOrderDetailsEval = tess.GetOrderDetails(sessionKey, tempOrderNumber);
                        DataTable dtLI = dsOrderDetailsEval.Tables["LineItem"];
                        foreach (DataRow drLI in dtLI.Rows)
                        {
                            int pkgNumber = Convert.ToInt32(drLI["pkg_no"]);
                            if (pkgNumber != 1013 && pkgNumber != 1017 && pkgNumber != 0 && pkgNumber != 1022 && pkgNumber != 1026 && pkgNumber != 1030 && pkgNumber != 1034 && pkgNumber != 1038 && pkgNumber != 1042)
                            {
                                if (orderLocked == true)
                                {
                                    string sLockedOrderNum = tempOrderNumber.ToString();
                                    string lockedOrder = @"<p><em>Our system shows you have a locked [open] season ticket order in process for this account.</em><br><strong><br>Don't Worry: The order lock will be released in 20 minutes, when you can try again.</strong><br><p class='thinRedLine'>Order No: <strong>" + sLockedOrderNum + "</strong> was locked by a previous session.</p></p>";
                                    Session["systemError"] = lockedOrder;
                                    Response.Redirect("~/RenewSystemMessage.aspx");
                                }
                                else
                                {
                                    if (status != 1 && paidAmt > 0)
                                    {
                                        string paidOrder = tempOrderNumber.ToString();
                                        string alreadyPaidOrder = @"<p><em>Our system shows you have already renewed your season ticket(s) for this season. If this is incorrect, please contact the Ticket Sales Office</p>";
                                        Session["systemError"] = alreadyPaidOrder;
                                        Response.Redirect("~/RenewSystemMessage.aspx");
                                    }
                                    else
                                    {
                                        hasBwayOrders = true;
                                        currentOrderNo = tempOrderNumber;
                                        _amtDue = Convert.ToDecimal(dr["tot_due_amt"]).ToString("c");
                                        _amtDue = a.formatString(_amtDue);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (hasBwayOrders == false)
                    {
                        string noOrdersError = "<p>Our system shows no active season ticket orders for this account.<br> Please contact the Ticket Sales Office.</p>";
                        Session["systemError"] = noOrdersError;
                        Response.Redirect("~/RenewSystemMessage.aspx");
                    }
                }
                else if (dtOpenOrders.Rows.Count == 0)
                {
                    string noOrdersError = "<p>Our system shows no active season ticket orders for this account.<br> Please contact the Ticket Sales Office.</p>";
                    Session["systemError"] = noOrdersError;
                    Response.Redirect("~/RenewSystemMessage.aspx");
                }
                if (currentOrderNo == 0)
                    currentOrderNo = Convert.ToInt32(dtOpenOrders.Rows[0]["order_no"].ToString());
                Session["orderNo"] = currentOrderNo;
                try
                {
                    tess.LoadExistingOrder(sessionKey, currentOrderNo);
                }
                catch
                {
                    string loadOrderError = "<p>An error occurred loading the order. If you have refreshed this page, the order has been locked for 20 minutes. Please wait and try again later or contact the Ticket Sales Office.</p>";
                    Session["systemError"] = loadOrderError;
                    Response.Redirect("~/RenewSystemMessage.aspx");
                }
                DataSet dsThisOrderDetails = tess.GetOrderDetails(sessionKey, currentOrderNo);
                DataTable dtLineItem = dsThisOrderDetails.Tables[1];
                DataTable dtSubLineItem = dsThisOrderDetails.Tables[2];
                var seats = (from li in dtLineItem.AsEnumerable()
                             join sli in dtSubLineItem.AsEnumerable()
                             on li.Field<int>("li_seq_no") equals sli.Field<int>("li_seq_no")
                             orderby sli.Field<int>("seat_no")
                             select new
                             {
                                 seatNo = sli.Field<int>("seat_no").ToString(),
                                 packageNo = li.Field<int>("pkg_no"),
                                 facilDesc = li.Field<string>("facility_desc"),
                                 zoneDesc = sli.Field<string>("section_desc"),
                                 zoneNo = sli.Field<int>("zone_no"),
                                 priceType = sli.Field<Int16>("price_type"),
                             }).Distinct();
                List<SeatInfo> seatList = new List<SeatInfo>();
                int seatCounter = 0;
                foreach (var seat in seats)
                {
                    if (seat.packageNo != 1013 && seat.packageNo != 1017 && seat.packageNo != 1022 && seat.packageNo != 1026 && seat.packageNo != 1030 && seat.packageNo != 1034 && seat.packageNo != 1038 && seat.packageNo != 1042 && seat.facilDesc.ToString().IndexOf("Mor") != -1)
                    {
                        SeatInfo s =
                            new SeatInfo()
                            {
                                seatNo = seat.seatNo,
                                packageNo = seat.packageNo,
                                zoneDesc = a.zoneDesc(seat.zoneDesc),
                                zoneNo = seat.zoneNo,
                                priceType = seat.priceType,
                            };
                        seatList.Add(s);
                        seatCounter = seatCounter + 1;
                    }
                }
                string prevRow = "";
                string prevZoneDesc = "";
                StringBuilder sbSeats = new StringBuilder();
                int xxxi = 0;
                //Get Seat Details
                List<SeatToDisplay> seatsToDisplayList = new List<SeatToDisplay>();
                foreach (SeatInfo si in seatList)
                {
                    switch (si.packageNo)
                    {
                        case 1008:
                        case 1011:
                        case 1010:
                            _pkgDesc = "Tuesday Evening";
                            break;
                        case 1016:
                        case 1009:
                        case 1014:
                            _pkgDesc = "Wednesday Evening";
                            break;
                        case 1021:
                        case 1019:
                        case 1020:
                            _pkgDesc = "Thursday Evening";
                            break;
                        case 1023:
                        case 1025:
                        case 1024:
                            _pkgDesc = "Friday Evening";
                            break;
                        case 1027:
                        case 1029:
                        case 1028:
                            _pkgDesc = "Saturday Matinee";
                            break;
                        case 1031:
                        case 1033:
                        case 1032:
                            _pkgDesc = "Saturday Evening";
                            break;
                        case 1035:
                        case 1037:
                        case 1036:
                            _pkgDesc = "Sunday Matinee";
                            break;
                        case 1039:
                        case 1041:
                        case 1040:
                            _pkgDesc = "Sunday Evening";
                            break;
                     }
                    int seatNo = Convert.ToInt32(si.seatNo);
                    DataSet dsSeatDetails = tess.GetSeats(sessionKey, si.packageNo, -1, si.zoneNo.ToString(), "", "", 'N', 'N', si.priceType.ToString(), 'Y');
                    var seatDets = (from sD in dsSeatDetails.Tables[0].AsEnumerable()
                                    where sD.Field<int>("seat_no") == seatNo
                                    orderby sD.Field<string>("seat_num"), sD.Field<string>("seat_num")
                                    select new
                                    {
                                        seatRow = sD.Field<string>("seat_row").ToString(),
                                        seatNum = sD.Field<string>("seat_num").ToString(),
                                    }).Distinct();
                    foreach (var seatDetailz in seatDets)
                    {
                        si.seatRow = seatDetailz.seatRow;
                        si.seatNum = seatDetailz.seatNum;
                    }
                    string tempRow = (si.seatRow.ToString().IndexOf("BX") != -1 ? si.seatRow.Replace("BX", "Box ") : si.seatRow);
                    if (tempRow != prevRow && xxxi != 0)
                    {
                        SeatToDisplay std = new SeatToDisplay();
                        std.zoneDesc = prevZoneDesc;
                        std.seatRow = prevRow;
                        string tempString = sbSeats.ToString();
                        tempString = orderSeats(tempString);
                        std.seatNums = tempString;
                        seatsToDisplayList.Add(std);
                        prevRow = "";
                        prevZoneDesc = "";
                        sbSeats = new StringBuilder();
                        sbSeats.Append(si.seatNum + ",");
                    }
                    else
                    {
                        sbSeats.Append(si.seatNum + ",");
                    }
                    prevZoneDesc = si.zoneDesc;
                    prevRow = (si.seatRow.ToString().IndexOf("BX") != -1 ? si.seatRow.Replace("BX", "Box ") : si.seatRow);
                    xxxi = xxxi + 1;
                }
                _numSeats = seatCounter.ToString();
                if (seatsToDisplayList.Count == 0)
                {
                    SeatToDisplay std = new SeatToDisplay();
                    std.zoneDesc = prevZoneDesc;
                    std.seatRow = prevRow;
                    string tempString = sbSeats.ToString();
                    tempString = orderSeats(tempString);
                    std.seatNums = tempString;
                    seatsToDisplayList.Add(std);
                }
                else if (seatsToDisplayList.Count > 0 && !string.IsNullOrEmpty(sbSeats.ToString()))
                {
                    SeatToDisplay std = new SeatToDisplay();
                    std.zoneDesc = prevZoneDesc;
                    std.seatRow = prevRow;
                    string tempString = sbSeats.ToString();
                    tempString = orderSeats(tempString);
                    std.seatNums = tempString;
                    seatsToDisplayList.Add(std);
                }
                repSeats.DataSource = seatsToDisplayList;
                repSeats.DataBind();
                a.addCartItem(_pkgDesc + " - Number of seats: " + _numSeats);
                foreach (SeatToDisplay std2 in seatsToDisplayList)
                {
                    a.addCartItem("Section: " + std2.zoneDesc + " | Row: " + std2.seatRow + " | Seat(s): " + std2.seatNums);
                }
            }
        }
        private static string orderSeats(string seatString)
        {
            string sString = "";
            string[] s = seatString.Split(',');
            if (s.Length > 2)
            {
                int s1 = Convert.ToInt32(s[0]);
                int s2 = Convert.ToInt32(s[1]);
                if (s1 > s2)
                {
                    for (int i = s.Length; i > 0; i--)
                    {
                        sString = sString + s[i - 1].ToString() + ",";
                    }
                    sString = sString.Remove(0, 1);
                    sString = sString.Substring(0, sString.Length - 1);
                }
                else
                    sString = seatString.Substring(0, seatString.Length - 1);
            }
            else
                sString = seatString.Substring(0, seatString.Length - 1);
            return sString;
        }
        protected void btnCheckout_Click(object sender, ImageClickEventArgs e)
        {
            string balanceDue = txtTotal.Text;
            Session["balanceDue"] = balanceDue;
            addOnAcctMethods();
            Response.Redirect("SecureCheckout.aspx");
        }
        protected void btnResetSession_Click(object sender, ImageClickEventArgs e)
        {
            Activity a = new Activity();
            //Set the expiration value for the Cart -- we'll set it to 18 minutes to be safe float fSeatExpiration = 1;
            float fSeatExpiration = 15;
            Timeout timeoutControl = (Timeout)Page.FindControl("timeoutControl");
            timeoutControl.TimeoutMinutes = fSeatExpiration;
            timeoutControl.AboutToTimeoutMinutes = fSeatExpiration - 1;
            timeoutControl.Enabled = true;
            Tessitura tess = new Tessitura();
            string sessionKey = a.getSession();
            int iBU = a.getBU();
            string newSessionKey = tess.GetNewSessionKeyEx(sessionKey, iBU);
            tess.TransferSession(sessionKey, newSessionKey);
        }
        private void addOnAcctMethods()
        {
            Activity a = new Activity();
            decimal number = 0;
            decimal addOnTotal = 0;
            if (decimal.TryParse(txtBwayGift.Value.ToString().Replace("$", ""), out number))//93
            {
                addItemToCart("Educational Gift of ", number);
                addDonations(number, 93);
                addOnTotal = addOnTotal + number;
            }
            if (addOnTotal > 0)
                Session["addOnTotal"] = addOnTotal;
        }
        private void addDonations(decimal amtIn, int onAcctMethod)
        {
            if (amtIn > 0)
            {
                Tessitura tess = new Tessitura();
                Activity a = new Activity();
                string sessionKey = a.getSession();
                tess.AddContribution(sessionKey, amtIn, 0, onAcctMethod, false, false);
            }
        }
        private void addItemToCart(string desc, decimal amt)
        {
            if (amt > 0)
            {
                Activity a = new Activity();
                string sessionKey = a.getSession();
                a.addCartItem(desc + amt.ToString("c"));
            }
        }
        
    }
}
 
Got it. I needed to add jquery:
function load()
{
alert("Page is loaded");
}
</script>
</head>

<body onload="load()">

and reference the function in my c# page:

if (txtBwayEDUGift.Checked)
{
addDonations(5.00, 93);
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top