Search the manual:

Overview Quick start Download Manual How to buy FAQ Contact Us
OZEKI NG SMS Gateway - Product Guide

ASP user setup Contents | SearchE-mail to SMS Alerts

Home > Product Manual > Examples and Solutions > Pin game > ASP Source

SMS Gateway SMS Gateway Home

  Product Manual
  Introduction
  SMS technology
  Installation Guide
  User Guide
  Developers Guide
  Examples and Solutions
  Telephone networks
  Pin game
  Database
  ASP user setup
  ASP Source
  E-mail to SMS Alerts
  2 way SMS to Email gateway
  SMS Order System
  Least Cost Routing
  Load Balancing
  Asterisk PBX SMS
  SQL SMS Gateway
  SMS Service Provider
  Service Provider
  SMS PIN code query
  SMS Counter game
  SMS newsgroup
  Distributed SMS
  SMS Menu
  Google maps
  Forwarding
  Birthday greeting - SQL Express
  Birthday greeting - MySQL
  Birthday greeting - Oracle
  Instant brochure - MMS autoreply
  Alphabet letter game
  SMS sport betting service
  E-mail about outgoing SMS messages
  SMS Information Menu
  Email to SMS feature
  Reminder example
  Bulk SMS Client
  Bulk SMS to a given phone number range
  Filtering phone numbers
  Appendix
  FAQ
  Feature list
  Commercial Information
  Search
 



Contact Us!
If you wish to get further information, do not hesitate to contact us!

E-mail: info@ozekisms.com

If you have a technical question, please submit a support request on-line.


Callcenter developers
If you are working on telephone solutions, please check out the Ozeki VoIP SIP SDK.
It can be used to create:

Webphone solutions:
- Adobe Flash video phone
- Silverlight video phone
- Web to web calls
- Web to VoIP calls

Custom SIP clients:
- Silverlight SIP VoIP client
- Flash SIP VoIP client
- C# .net SIP VoIP client
- ASP .net SIP VoIP client
- Web based SIP VoIP client

Custom VoIP solutions:
- VoIP SIP softphones
- VoIP call center clients
- VoIP IVR systems
- VoIP predictive dialer systems
- VoIP auto dialer systems
- VoIP call assistant
- VoIP call recording systems
- VoIP intercom solutions

ASP Script for creating pin game


This page gives you the source code for an ASP script, that is used in the SMS PIN Game demo.


<%@ Page Language="C#"%>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Common" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<%
/************************************************************
 * copy the properties of the incoming SMS into local variables
 ************************************************************/

    string sender = Request.QueryString["sender"];
    string receiver = Request.QueryString["receiver"];
    string messagedata = Request.QueryString["messagedata"];
    string messageid = Request.QueryString["messageid"];
    string messagetype = Request.QueryString["messagetype"];
    string senttime = Request.QueryString["senttime"];
    string receivedtime = Request.QueryString["receivedtime"];
    string serviceprovider = Request.QueryString["operatornames"];

    string respmsg = "Hello, the following message was received: "+messagedata+
                     ". The message was sent at " + senttime;

/************************************************************
* Connect to the database
***********************************************************/
    bool connectedToDb;
    SqlConnection conn = new SqlConnection();;

    try
    {
        string sServer = ".\\SQLEXPRESS";
        string sUser = "ozekiuser";
        string sPwd = "ozekipass";
        string sDB = "ozeki";
        string connectionString = "Server=" + sServer + ";User ID=" + sUser + ";" +
        "password=" + sPwd + ";Database=" + sDB + ";Persist Security Info=True";

        conn.ConnectionString = connectionString;
        conn.Open();
        connectedToDb = true;
    }
    catch (Exception e)
    {
        respmsg = "Cannot connect to database." + e.Message;
        connectedToDb = false;
    }

/************************************************************
* Create database tables if they do not exist
***********************************************************/

    if (connectedToDb)
    {
        string sql1 =
        "if not exists(select * from INFORMATION_SCHEMA.tables where TABLE_NAME = 'pincode') "+
            "  CREATE TABLE pincode ( "+
                "id int IDENTITY (1,1),"+
                "pincode varchar(30),"+
                "response varchar(160),"+
                "used varchar(1)"+
                ")";

        try {
            SqlCommand cmd1 = conn.CreateCommand();
            cmd1.CommandText = sql1;
            cmd1.ExecuteNonQuery();
        } catch (Exception exp) {
            respmsg = "Cannot create database table: "+exp.Message;
        }
    }

/************************************************************
* Put some test data into the database
***********************************************************/
    if (connectedToDb)
    {
        string sql2 =
        "if not exists(select * from pincode) " +
            "begin " +
            "  INSERT INTO pincode (pincode,response,used ) VALUES ('3345','The treasure is behind the picture on the wall','0');" +
            "  INSERT INTO pincode (pincode,response,used ) VALUES ('4578','The treasure is under the pillow','0');" +
            "end";

        try {
            SqlCommand cmd2 = conn.CreateCommand();
            cmd2.CommandText = sql2;
            cmd2.ExecuteNonQuery();
        } catch (Exception exp) {
            respmsg = "Cannot create test data: "+exp.Message;
        }
    }

/************************************************************
* Process incoming message
***********************************************************/
    if (connectedToDb)
    {
        string pincode = messagedata.ToLower().Trim();

        string sql3 = "select used,response from pincode where pincode='" + pincode + "'";
        try
        {
            SqlCommand cmd3 = conn.CreateCommand();
            cmd3.CommandText = sql3;
            DbDataReader reader = cmd3.ExecuteReader();
            if (!reader.Read())
            {
                respmsg = "Invalid pin code '" + pincode + "'.";
                reader.Close();
            }
            else
            {
                string used = reader.GetValue(0).ToString();
                string treasurelocation = reader.GetValue(1).ToString();
                reader.Close();

                if (used != "0")
                {
                    respmsg = "The PIN code is correct, but this treasure has been taken.";
                }
                else
                {
                    respmsg = treasurelocation;
                    //update the database to mark the treasure as taken
                    SqlCommand cmd4 = conn.CreateCommand();
                    cmd4.CommandText = "update pincode set used='1' where pincode='" + pincode + "'";
                    cmd4.ExecuteNonQuery();
                }
            }
            //Close database connection
            conn.Close();

        }
        catch (Exception exp)
        {
            respmsg = "Invalid pin code. It could not be processed by the database. " + exp.Message;
        }
    }


//************************************************************
//create the response message(s). Format description:
//http://www.ozekisms.com/index.php?owpn=355
//************************************************************

string destnum = sender;
string resptype = "SMS:TEXT";
string resp = "{"+resptype+"}{}{}{"+destnum+"}{"+respmsg+"}";

Response.Write(resp);

%>



Dig deeper!
People who read this also read...





Next page: E-mail to SMS Alerts
Copyright © 2000 - 2013 Ozeki Informatics Ltd.
All rights reserved

Software PBX for Windows | VoIP SDK   |   Legal information   |   Privacy policy   |   Terms of use
Please, address your inquiries to info@ozekisms.com