Exemple #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            classes.Payment payment   = new classes.Payment();
            DataTable       dtPayment = payment.GetPayment();

            DataRow[] dr     = dtPayment.Select("paymenttype='cash'");
            decimal   amount = 0;

            if (dr.Length > 0)
            {
                for (int i = 0; i < dr.Length; i++)
                {
                    amount += Convert.ToDecimal(dr[i]["amount"].ToString());
                }
            }
            td_cash_receivable.InnerText = amount.ToString("#0.00");
        }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ExpMonth.Items.Add(new ListItem("", ""));
                ExpYear.Items.Add(new ListItem("", ""));

                for (int i = 1; i <= 12; i++)
                {
                    ExpMonth.Items.Add(new ListItem(i.ToString(), i.ToString()));
                }

                for (int i = DateTime.Now.Year; i <= DateTime.Now.Year + 20; i++)
                {
                    ExpYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
                }

                if (!String.IsNullOrEmpty(Request.QueryString["Id"]))
                {
                    classes.Payment objPayment = new classes.Payment();
                    DataTable       dtPayment  = objPayment.GetPayment();
                    dtPayment.PrimaryKey = new DataColumn[] { dtPayment.Columns["Id"] };
                    DataRow dr = dtPayment.Rows.Find(Request.QueryString["Id"]);
                    if (dr != null)
                    {
                        tCardNo.Text           = dr["CardNo"].ToString();
                        ExpMonth.SelectedIndex = ExpMonth.Items.IndexOf(ExpMonth.Items.FindByValue(dr["CardExpMonth"].ToString()));
                        ExpYear.SelectedIndex  = ExpYear.Items.IndexOf(ExpYear.Items.FindByValue(dr["CardExpYear"].ToString()));
                        tCardName.Text         = dr["CardName"].ToString();

                        //dr.Delete();
                    }
                    HttpContext.Current.Session["Payment"] = dtPayment;
                }
            }
            else
            {
                ErrMsg.Text = "";
            }
        }
Exemple #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DBConnection DBConn = new DBConnection();
                Decimal      dTotal = 0;
                DataTable    DTE    = DBConn.ExecuteDataSet("SELECT ShoppingCart.*,ProductPrice*Quantity as Total,Name FROM ShoppingCart,ProductMaster WHERE ShoppingCart.ProductId = ProductMaster.ProductId and CurrentCartId = " + Session["CartId"], CommandType.Text).Tables[0];
                if (DTE.Rows.Count > 0)
                {
                    dC.DataSource = DTE;
                    dC.DataBind();

                    for (int i = 0; i < DTE.Rows.Count; i++)
                    {
                        dTotal += Functions.ToDecimal(DTE.Rows[i]["Total"]);
                    }
                }
                else
                {
                    dC.DataSource = null;
                    dC.DataBind();
                }
                DBConn = null;
                td_voucher_value.InnerText = "$" + Request.QueryString["amount"];    //dTotal.ToString();   single payment

                if (!String.IsNullOrEmpty(Request.QueryString["Id"]))
                {
                    classes.Payment objPayment = new classes.Payment();
                    DataTable       dtPayment  = objPayment.GetPayment();
                    dtPayment.PrimaryKey = new DataColumn[] { dtPayment.Columns["Id"] };
                    DataRow dr = dtPayment.Rows.Find(Request.QueryString["Id"]);
                    if (dr != null)
                    {
                        tVoucherNo.Text = dr["CardNo"].ToString();
                        dr.Delete();
                    }
                    HttpContext.Current.Session["Payment"] = dtPayment;
                }
            }
        }
Exemple #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ((Button)Pay.FindControl("bCancel")).Enabled = false;
            ((Button)Pay.FindControl("bFinish")).Enabled = false;

            if ("" + Session["CartId"] == "")
            {
                return;
            }

            if (!IsPostBack)
            {
                string          payment_type   = "";
                string          TransactionIds = "";
                classes.Payment payment        = new classes.Payment();
                bool            IsAuthorized   = payment.AuthorizePayment();
                DataTable       dt             = payment.GetPayment();
                DataList        dl             = (DataList)Pay.FindControl("dlPayment");
                dl.DataSource = dt;
                dl.DataBind();
                string PrintURL = "";
                if (IsAuthorized)
                {
                    string       sql           = "";
                    DBConnection dbCon         = new DBConnection();
                    int          SalesMasterId = 0;
                    int          SDOrderNo     = 0;
                    try
                    {
                        dbCon.BeginTransaction();
                        sql = "select sum(productprice*quantity) + sum(ChildProductPrice*ChildQuantity) as productprice, sum(servicefee*quantity) as servicefee from ShoppingCart where CurrentCartId = " + Session["CartId"];
                        DataTable dtSum = dbCon.ExecuteTransactionDataSet(sql, CommandType.Text).Tables[0];
                        if (dtSum.Rows.Count > 0)
                        {
                            decimal productprice = EventFunctions.Functions.ToDecimal(dtSum.Rows[0]["productprice"].ToString());
                            decimal servicefee   = EventFunctions.Functions.ToDecimal(dtSum.Rows[0]["servicefee"].ToString());

                            sql = @"insert into SalesMaster (CartId, SalesDate, PurchaseAmount, PurchaseTax, ServiceFee, GrandTotal, LocationId, ClerkId, CustomerName, CustomerAddress) values (" +
                                  Session["CartId"].ToString() + ", now()," + productprice.ToString() + ", 0, " + servicefee.ToString() + ", " + (productprice + servicefee).ToString() + ", " + Session["LocationId"] + ", '" + Session["userid"] + "', '" + dt.Rows[0]["cardname"].ToString().Replace("'", "''") + "', '')";
                            SalesMasterId = dbCon.ExecuteTransactionGetID(sql, CommandType.Text);

                            if (SalesMasterId > 0)
                            {
                                sql  = "select C.productid, C.SmartProductCode, C.productprice,C.quantity,C.ProductName,C.SmartProductCode,1 as IsAdult, (select group_concat(serialNumber SEPARATOR ',') from ShoppingCartSerialNo S where S.CurrentCartId = C.CurrentCartId and S.ProductId = C.ProductId) as SNo,IsSmartDestination from ShoppingCart C where C.CurrentCartId = " + Session["CartId"];
                                sql += " Union select C.productid, C.SmartProductCode, C.ChildProductPrice as productprice,C.ChildQuantity as quantity,Concat(C.ProductName,' - Child'),C.SmartProductCode,0 as IsAdult, '' as SNo,IsSmartDestination from ShoppingCart C where C.ChildQuantity >0 and  C.CurrentCartId = " + Session["CartId"];

                                DataTable dtCart = dbCon.ExecuteTransactionDataSet(sql, CommandType.Text).Tables[0];

                                DataTable dtSmart = new DataTable();
                                dtSmart.Columns.Add(new DataColumn("SmartProductCode"));
                                dtSmart.Columns.Add(new DataColumn("SmartProductId"));
                                dtSmart.Columns.Add(new DataColumn("SmartAdultQty"));
                                dtSmart.Columns.Add(new DataColumn("SmartChildQty"));
                                for (int i = 0; i < dtCart.Rows.Count; i++)
                                {
                                    //Inserting SalesDetails
                                    sql = "insert into SalesDetails (SalesMasterId, ProductId, SalesAmount, Count, SerialNo, LocationId,IsAdult,IsSmartDest,ProductName,ProductCode) values (" + SalesMasterId + ", " + dtCart.Rows[i]["productid"].ToString() + ", " + dtCart.Rows[i]["productprice"].ToString() + ", " + dtCart.Rows[i]["quantity"].ToString() + ", '" + dtCart.Rows[i]["SNo"].ToString() + "', " + Session["LocationId"] + "," + dtCart.Rows[i]["IsAdult"].ToString() + "," + dtCart.Rows[i]["IsSmartDestination"].ToString() + ",'" + dtCart.Rows[i]["ProductName"].ToString().Replace("'", "''") + "','" + dtCart.Rows[i]["SmartProductCode"].ToString().Replace("'", "''") + "')";
                                    int SalesDetailId = dbCon.ExecuteTransactionGetID(sql, CommandType.Text);

                                    if (dtCart.Rows[i]["IsSmartDestination"].ToString() == "0")
                                    {
                                        //Updating Status & SalesDetailId in ProductDetail table
                                        sql = @"update ProductDetail P Set P.SalesDetailId = " + SalesDetailId + @", P.Status = 1
                                                where ProductId = " + dtCart.Rows[i]["productid"].ToString() + " and LocationId = " + Session["LocationId"].ToString() + " and P.SerialNo in (" + dtCart.Rows[i]["SNo"].ToString() + ")";
                                        dbCon.ExecuteTransaction(sql, CommandType.Text);

                                        //Updating TicketCount in ProductMaster table
                                        sql = "update ProductMaster set TicketCount = TicketCount - " + dtCart.Rows[i]["quantity"].ToString() + " where ProductId = " + dtCart.Rows[i]["productid"].ToString();
                                        dbCon.ExecuteTransaction(sql, CommandType.Text);

                                        //updating TicketCount in ProductInventoryByLocation table
                                        sql = "update ProductInventoryByLocation set TicketCount = TicketCount - " + dtCart.Rows[i]["quantity"].ToString() + " where ProductId = " + dtCart.Rows[i]["productid"].ToString() + " and LocationId = " + Session["LocationId"].ToString();
                                        dbCon.ExecuteTransaction(sql, CommandType.Text);
                                    }
                                    else
                                    {
                                        DataRow drSmart = dtSmart.NewRow();
                                        drSmart["SmartProductCode"] = dtCart.Rows[i]["SmartProductCode"].ToString();
                                        drSmart["SmartProductId"]   = dtCart.Rows[i]["ProductId"].ToString();
                                        if (dtCart.Rows[i]["IsAdult"].ToString() == "1")
                                        {
                                            drSmart["SmartAdultQty"] = dtCart.Rows[i]["Quantity"].ToString();
                                            drSmart["SmartChildQty"] = "0";
                                        }
                                        else
                                        {
                                            drSmart["SmartAdultQty"] = "0";
                                            drSmart["SmartChildQty"] = dtCart.Rows[i]["Quantity"].ToString();
                                        }
                                        dtSmart.Rows.Add(drSmart);
                                    }
                                }


                                if (dtSmart.Rows.Count > 0)
                                {
                                    //Order Smart Destination Card Requet

                                    string skuOrderList  = "";
                                    string quantityAdult = "";
                                    string quantityChild = "";


                                    for (int i = 0; i < dtSmart.Rows.Count; i++)
                                    {
                                        if (skuOrderList.IndexOf(dtSmart.Rows[i]["SmartProductCode"].ToString()) < 0)
                                        {
                                            skuOrderList += (skuOrderList != "" ? "," : "") + dtSmart.Rows[i]["SmartProductCode"].ToString();
                                        }
                                        if (dtSmart.Rows[i]["SmartAdultQty"].ToString() != "0")
                                        {
                                            quantityAdult += (quantityAdult != "" ? "," : "") + dtSmart.Rows[i]["SmartAdultQty"].ToString();
                                        }
                                        if (dtSmart.Rows[i]["SmartChildQty"].ToString() != "0")
                                        {
                                            quantityChild += (quantityChild != "" ? "," : "") + dtSmart.Rows[i]["SmartChildQty"].ToString();
                                        }
                                    }
                                    if (quantityAdult == "")
                                    {
                                        quantityAdult = "0";
                                    }
                                    if (quantityChild == "")
                                    {
                                        quantityChild = "0";
                                    }
                                    string         SmartURL = string.Format("{0}/rest/secure/requestOrderMultipleAttr/skuOrderList/{1}/quantityAdult/{2}/quantityChild/{3}/email/{4}", System.Configuration.ConfigurationManager.AppSettings["smart_destination_url"], skuOrderList, quantityAdult, quantityChild, System.Configuration.ConfigurationManager.AppSettings["smart_destination_login"]);
                                    HttpWebRequest request  = (HttpWebRequest)WebRequest.Create(SmartURL);
                                    request.Credentials = new NetworkCredential(System.Configuration.ConfigurationManager.AppSettings["smart_destination_login"], System.Configuration.ConfigurationManager.AppSettings["smart_destination_password"]);
                                    request.Method      = "POST";
                                    HttpWebResponse response = null;
                                    try
                                    {
                                        request.Timeout = 240000; //extend to 4 minutes;
                                        response        = (HttpWebResponse)request.GetResponse();
                                    }
                                    catch (Exception ee)
                                    {
                                        Response.Write(ee.Message);
                                    }
                                    if (response.StatusCode == HttpStatusCode.Created)
                                    {
                                        WebHeaderCollection whc = response.Headers;
                                        string location         = whc["Location"];
                                        request.Credentials = new NetworkCredential(System.Configuration.ConfigurationManager.AppSettings["smart_destination_login"], System.Configuration.ConfigurationManager.AppSettings["smart_destination_password"]);
                                        request             = (HttpWebRequest)WebRequest.Create(location);
                                        System.IO.Stream responseStream = null;

                                        try
                                        {
                                            responseStream = request.GetResponse().GetResponseStream();
                                        }
                                        catch (Exception ex)
                                        {
                                            HttpWebRequest newrequest = (HttpWebRequest)WebRequest.Create(request.Address.AbsoluteUri);
                                            newrequest.Credentials = new NetworkCredential(System.Configuration.ConfigurationManager.AppSettings["smart_destination_login"], System.Configuration.ConfigurationManager.AppSettings["smart_destination_password"]);
                                            responseStream         = newrequest.GetResponse().GetResponseStream();
                                        }

                                        string jsonString = null;
                                        using (System.IO.StreamReader reader = new System.IO.StreamReader(responseStream))
                                        {
                                            jsonString = reader.ReadToEnd();
                                            reader.Close();
                                            XmlDocument xd = new XmlDocument();
                                            xd = (XmlDocument)JsonConvert.DeserializeXmlNode(jsonString, "skuCodeList");
                                            DataSet ds = new DataSet();
                                            ds.ReadXml(new XmlNodeReader(xd));
                                            PrintURL  = ds.Tables[0].Rows[0]["printPassesUrl"].ToString();
                                            SDOrderNo = Convert.ToInt32(ds.Tables[0].Rows[0]["orderNumber"].ToString());
                                            sql       = "Update SalesMaster set SDOrderNo = " + SDOrderNo + ", PrintURL = '" + PrintURL + "' where SalesMasterId = " + SalesMasterId;
                                            dbCon.ExecuteTransaction(sql, CommandType.Text);
                                        }
                                    }
                                }


                                //Inserting Payment details
                                for (int i = 0; i < dt.Rows.Count; i++)
                                {
                                    string transid = "0";
                                    if (dt.Rows[i]["PaymentType"].ToString() == "credit" && dt.Rows[i]["Response"] != null)
                                    {
                                        string[] ResponseArray = (string[])dt.Rows[i]["Response"];
                                        transid         = ResponseArray[6];
                                        TransactionIds += (TransactionIds.Length > 0 ? "," : "") + transid;
                                    }
                                    string CardNo = "";
                                    //string CardName = "";
                                    if (dt.Rows[i]["PaymentType"].ToString() == "credit")
                                    {
                                        CardNo = dt.Rows[i]["cardno"].ToString().Substring(dt.Rows[i]["cardno"].ToString().Length - 4);
                                        //CardName = dt.Rows[i]["cardname"].ToString();
                                    }
                                    else if (dt.Rows[i]["PaymentType"].ToString() == "voucher")
                                    {
                                        CardNo = dt.Rows[i]["cardno"].ToString();
                                    }

                                    if (dt.Rows[i]["PaymentType"].ToString() == "cash")
                                    {
                                        payment_type = "1";
                                    }
                                    else if (dt.Rows[i]["PaymentType"].ToString() == "credit")
                                    {
                                        payment_type = "2";
                                    }
                                    else if (dt.Rows[i]["PaymentType"].ToString() == "voucher")
                                    {
                                        payment_type = "3";
                                    }

                                    sql = @"insert into PaymentDetails (SalesMasterId, PaymentType, Amount, CardCheckNo, CardName, CardAdd1, CardAdd2, CardCity, CardState, CardZip, ExpiryMonth, ExpiryYear, CardType, CardAuthorizationId) values 
                                        (" + SalesMasterId + ", " + payment_type + ", " + dt.Rows[i]["amount"].ToString() + ", '" + CardNo + "',  '" + dt.Rows[i]["cardname"].ToString() + @"', 
                                        '', '', '', '', '', 0, 0, '" + dt.Rows[i]["CardType"].ToString() + "', " + transid + ")";

                                    int PaymentId = dbCon.ExecuteTransactionGetID(sql, CommandType.Text);

                                    if (dt.Rows[i]["PaymentType"].ToString() == "credit")
                                    {
                                        sql = "update PaymentResponse set PaymentId = " + PaymentId + " where CartId = " + Session["CartId"] + " and GuId = '" + dt.Rows[i]["Id"].ToString() + "'";
                                        dbCon.ExecuteTransaction(sql, CommandType.Text);
                                    }
                                }
                            }
                        }

                        lblMsg.Text = "<p style='padding-bottom:0; margin-bottom:0; font-size:16px; font-weight:bold;'>Payment succefully authorized.</p>";

                        /*
                         * string payment_description = "";
                         * if (payment_type == "1")
                         *  payment_description = "Cash payment received";
                         * else if (payment_type == "2")
                         *  payment_description = "CC payment authorization (#" + TransactionIds + ")";
                         * else if (payment_type == "3")
                         *  payment_description = "Voucher payment received, " + dt.Rows[0]["CardNo"].ToString();
                         * lblMsg.Text += "<p style='padding:0; margin:0; font-size:13px; font-weight:normal; padding-left:20px;'>" + payment_description + "</p>";
                         */

                        string payment_description = "";
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            if (dt.Rows[i]["paymenttype"].ToString() == "cash")
                            {
                                payment_description = "Cash payment received";
                            }
                            else if (dt.Rows[i]["paymenttype"].ToString() == "credit")
                            {
                                payment_description = "CC payment authorization (#" + TransactionIds + ")";
                            }
                            else if (dt.Rows[i]["paymenttype"].ToString() == "voucher")
                            {
                                payment_description = "Voucher payment received, " + dt.Rows[i]["CardNo"].ToString();
                            }
                            lblMsg.Text += "<p style='padding:0; margin:0; font-size:13px; font-weight:normal; padding-left:20px;'>" + payment_description + " for $" + Convert.ToDecimal(dt.Rows[i]["amount"].ToString()).ToString("#0.00") + "</p>";
                        }


                        lblMsg.Text += "<p style='padding:0; padding-top:5px; margin:0; font-size:13px; font-weight:bold; padding-left:20px;'>eVents transaction ID: " + SalesMasterId + "</p>";
                        lblMsg.Text += "<p style='padding-bottom:0; margin-bottom:0; font-size:16px; font-weight:bold;'>Ticket inventory adjusted.</p>";

                        sql = "select P.name, S.serialNumber from ProductMaster P, ShoppingCartSerialNo S where P.ProductId = S.ProductId and IsPhysicalInventory = 0 and S.CurrentCartId = " + Session["CartId"];
                        DataTable dtSNo = dbCon.ExecuteTransactionDataSet(sql, CommandType.Text).Tables[0];
                        for (int i = 0; i < dtSNo.Rows.Count; i++)
                        {
                            lblMsg.Text += "<p style='padding:0; margin:0; font-size:13px; font-weight:normal; padding-left:20px;'>" + dtSNo.Rows[i]["name"].ToString() + " s/n " + dtSNo.Rows[i]["serialNumber"].ToString() + "<span style='color:green; '><i> marked as sold</i></span></p>";
                        }
                        sql   = "select P.name, DATE_FORMAT(S.expirydate,'%m/%d/%Y') as expirydate, Count(*) as Qty from ProductMaster P, ShoppingCartSerialNo S where P.ProductId = S.ProductId and IsPhysicalInventory = 1 and S.CurrentCartId = " + Session["CartId"] + " group by P.name, S.expirydate";
                        dtSNo = dbCon.ExecuteTransactionDataSet(sql, CommandType.Text).Tables[0];
                        for (int i = 0; i < dtSNo.Rows.Count; i++)
                        {
                            lblMsg.Text += "<p style='padding:0; margin:0; font-size:13px; font-weight:normal; padding-left:20px;'>" + dtSNo.Rows[i]["name"].ToString() + " Expiry date: " + dtSNo.Rows[i]["expirydate"].ToString() + ", Qty: " + dtSNo.Rows[i]["Qty"].ToString() + "<span style='color:green; '><i> marked as sold</i></span></p>";
                        }


                        dtSNo = null;

                        lblMsg.Text += "<p style='font-size:18px; font-weight:bold; color:green;'>Please give tickets to the  customer.</p>";

                        PrintReceipt.Visible   = true;
                        btnProceed.Visible     = true;
                        btnBackPayment.Visible = false;
                        dbCon.CommitTransaction();

                        string sScript = "window.open('/Reports/Reports.aspx?ReportName=Receipt&DataSource=Receipt&SalesId=" + SalesMasterId + "', 'Receipt', 'statusbar=no'); window.open('/Reports/Reports.aspx?ReportName=Receipt&DataSource=Receipt&Dup=yes&SalesId=" + SalesMasterId + "', 'ReceiptCopy', 'statusbar=no'); return false; ";
                        PrintReceipt.Attributes.Add("onclick", sScript);

                        if (PrintURL != "")
                        {
                            sScript = "window.open('Viewpdf.aspx?filepath=" + Server.UrlEncode(PrintURL) + "', 'SDReceipt', 'status=no,resizable=yes,menubar=yes'); return false; ";
                            btnPrintPDF.Attributes.Add("onclick", sScript);
                            btnPrintPDF.Visible = true;
                        }
                        Session["CartId"]          = "";
                        Session["Payment"]         = null;
                        Session["AmountDue"]       = "";
                        Session["AmountRemaining"] = "";
                        Session["SalesMasterId"]   = "";

                        //string sScript = "<script>window.open('/Reports/Reports.aspx?ReportName=Receipt&DataSource=Receipt&SalesId=" + SalesMasterId + "', 'Receipt', 'statusbar=no');</script>";
                        //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "popupScript", sScript);
                        //Response.Write("<script>window.open('/Reports/Reports.aspx?ReportName=Receipt&DataSource=Receipt&SalesId=" + SalesMasterId + "', 'Receipt', 'statusbar=no');</script>");
                    }
                    catch (Exception)
                    {
                        dbCon.RollBackTransaction();
                    }
                    dbCon = null;
                }
                else
                {
                    lblMsg.Text            = "Payment could not be authorized.<br /><br />";
                    PrintReceipt.Visible   = false;
                    btnProceed.Visible     = false;
                    btnBackPayment.Visible = true;
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        if (dt.Rows[i]["Status"].ToString() == "1")
                        {
                            string ErrorResponse = "";
                            if (dt.Rows[i]["Response"] != null)
                            {
                                string[] ResponseArray = (string[])dt.Rows[i]["Response"];
                                ErrorResponse = ResponseArray[3];
                            }
                            lblMsg.Text += "<br />" + dt.Rows[i]["CardType"] + " " + dt.Rows[i]["Description"] + ": " + ErrorResponse;
                        }
                    }
                    //lblMsg.Text += "<br /><br /><span style='font-weight:bold; font-size:16px;'>Click on the payment to edit</span>";
                }
            }


            //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "popupScript", sScript);
        }
Exemple #5
0
        protected void OK_Click(object sender, EventArgs e)
        {
            DBConnection DBConn = new DBConnection();

            string CardType     = CheckCardType(this.tCardNo.Text.Trim());
            string CardNo       = tCardNo.Text.Trim();
            int    CardExpMonth = 0;

            if (ExpMonth.SelectedIndex > 0)
            {
                CardExpMonth = Convert.ToInt16(ExpMonth.SelectedValue);
            }
            int CardExpYear = 0;

            if (ExpYear.SelectedIndex > 0)
            {
                CardExpYear = Convert.ToInt16(ExpYear.SelectedValue);
            }
            string  CardName = tCardName.Text.Trim().Replace("'", "''");
            decimal amount   = Convert.ToDecimal(Request.QueryString["amount"]); // Convert.ToDecimal(Session["AmountDue"].ToString()); // single payment

            if (CardType == "Unknown" || CardNo == "")
            {
                ErrMsg.Text = "Invalid card number";
                return;
            }
            if (CardExpMonth == 0)
            {
                ErrMsg.Text = "Please select card expiry month";
                return;
            }
            if (CardExpYear == 0)
            {
                ErrMsg.Text = "Please select card expiry year";
                return;
            }
            if (CardExpYear == DateTime.Now.Year && CardExpMonth < DateTime.Now.Month)
            {
                ErrMsg.Text = "Card expired.  Please check expiry month and year";
                return;
            }
            if (CardName == "")
            {
                ErrMsg.Text = "Please enter card name";
                return;
            }


            /*
             * string sql = @"insert into ShoppingCartPayment (CartId, PaymentType, Amount, SellDate, CardType, CardNo, CardExpMonth, CardExpYear, CardName)
             *          values (" + Session["CartId"] + ", 'card', " + amount.ToString() + ", now(), '" + CardType + "', '" + CardNo + "', " + CardExpMonth.ToString() + ", " + CardExpYear.ToString() + ", '" + CardName + "')";
             * DBConn.Execute(sql, CommandType.Text);
             * DBConn = null;
             */

            classes.Payment payment = new classes.Payment();

            if (!String.IsNullOrEmpty(Request.QueryString["Id"]))
            {
                DataTable dtPayment = payment.GetPayment();
                dtPayment.PrimaryKey = new DataColumn[] { dtPayment.Columns["Id"] };
                DataRow dr = dtPayment.Rows.Find(Request.QueryString["Id"]);
                dr.Delete();
            }

            payment.CartId       = Functions.ToInt(Session["CartId"].ToString());
            payment.PaymentType  = "credit";
            payment.Amount       = amount;
            payment.CardType     = CardType;
            payment.CardNo       = CardNo;
            payment.CardExpMonth = CardExpMonth;
            payment.CardExpYear  = CardExpYear;
            payment.CardName     = CardName;
            payment.SetPayment();

            if (!String.IsNullOrEmpty(Request.QueryString["from"]))
            {
                if (Request.QueryString["from"] == "a")
                {
                    Response.Write("<script>window.opener.location.href='Authorize.aspx'; window.close();</script>");
                }
                else if (Request.QueryString["from"] == "t")
                {
                    Response.Write("<script>window.opener.location.href='Tickets.aspx'; window.close();</script>");
                }
            }
            else
            {
                Response.Write("<script>window.opener.location.href='paymentoptionsNew.aspx'; window.close();</script>");
            }
            return;
        }