.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

SMS --Class file in ASP.NET

Posted By:Athira Sreejith       Posted Date: February 22, 2009    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  
 

SMS - This is the Class file  to send sms using your ASP.NET application.

using System;

using System.Data;

using System.Configuration;

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 System.Collections;

using System.Text.RegularExpressions;

using System.Collections.Generic;

#region

#endregion

///

/// Summary description for SMSParser

///

public class SMSParser

{

///

/// Used to store the user data

///

Hashtable HTInfo = new Hashtable();

///

/// Used to Parse the content of the SMS

///

///

///

/// Hashtable

public Hashtable ParseSMS(string SMSMsg, string PhoneNumber, Dictionary dicReplyMsg)

{

if (SMSMsg.Length > 4)

{

string SMSMsg1 = SMSMsg.Substring(3, SMSMsg.Length - 3);

//bool m_ReturnValue = false;

switch (SMSMsg1.Substring(0, 2).ToLower())

{

//case "rep": ReadReportSMS(SMSMsg);

//break;

case "ny": CreateUserSMS(SMSMsg1, PhoneNumber, dicReplyMsg);

break;

default: RegisterStepLogSMS(SMSMsg1, PhoneNumber, dicReplyMsg);

break;

}

}

else

{

string m_ReplyMessage = string.Empty;

if (dicReplyMsg.TryGetValue("SLRMC3", out m_ReplyMessage))

{

HTInfo.Add("Message", m_ReplyMessage);

}

HTInfo.Add("NV", "0");

}

CheckInfo();

return HTInfo;

}

///

/// Used to register steplog SMS

///

///

///

/// Hashtable

public Hashtable RegisterStepLogSMS(string SMSMsg, string PhoneNumber, Dictionary dicReplyMsg)

{

try

{

bool m_ReturnValue = true;

string m_SMSMessage = string.Empty;

string[] m_SMSSplit = SMSMsg.Split(' ');

string m_SLCode = string.Empty;

bool m_Anonymous = true;

string m_UserIds = string.Empty;

string m_Time = string.Empty;

string m_UserId = string.Empty;

string m_BlockString = "";

string m_BlogTextMsg = "";

string LocationID = "";

string m_RemString = string.Empty;

string m_Parameter = string.Empty;

string m_TimeString = string.Empty;

int startIndex; int leng; int tleng; int Pwd; int SMSRemainingCount;

decimal Rem;

string UID;

string NewUserId;

int Num;

bool m_UserCreatedMsg;

bool isSaved;

bool cond = true;

bool m_LocReturnValue = true;

bool m_CheckTimeFormat = true;

IDataReader m_RdrObj;

m_SLCode = m_SMSSplit[0].ToUpper().Replace('O', '0');

m_RdrObj = DBMethods.GetStepLogCodeDB(m_SLCode);

if (m_RdrObj.Read())

{

if (CheckDateTime(m_RdrObj["DisplayFrom"].ToString()) <= DateTime.Today && CheckDateTime(m_RdrObj["ValidTo"].ToString()) >= DateTime.Today)

{

if (SMSMsg.Length > 7)

{

startIndex = SMSMsg.IndexOf(' ');

//Comment below line for time...

//string m_Parameter = SMSMsg.Substring(startIndex);

//Uncomment below lines and comment above line for Time...

if (SMSMsg.IndexOf("t:") != -1)

{

leng = SMSMsg.IndexOf("t:") - startIndex;

m_Parameter = SMSMsg.Substring(startIndex, leng);

m_RemString = SMSMsg.Substring(SMSMsg.IndexOf("t:"));

if (m_RemString.IndexOf("b:") != -1)

{

tleng = m_RemString.IndexOf("b:") - m_RemString.IndexOf("t:");

m_TimeString = SMSMsg.Substring(SMSMsg.IndexOf("t:"), tleng);

m_BlockString = SMSMsg.Substring(SMSMsg.IndexOf("b:"));

}

else

{

m_TimeString = SMSMsg.Substring(SMSMsg.IndexOf("t:"));

}

if (m_TimeString.Split(':').Length == 4)

{

//TODO : Add the time by getting the format.

m_Time = m_TimeString.Substring(2, m_TimeString.Length - 2);

}

else

{

m_Time = "";

m_CheckTimeFormat = false;

}

if (m_BlockString != "")

{

m_BlogTextMsg = m_BlockString.Substring(2, m_BlockString.Length - 2);

//TODO : Add Blog text to user.

}

}

else

{

if (SMSMsg.IndexOf("b:") != -1)

{

tleng = SMSMsg.IndexOf("b:") - startIndex;

m_Parameter = SMSMsg.Substring(startIndex, tleng);

m_BlockString = SMSMsg.Substring(SMSMsg.IndexOf("b:"));

if (m_BlockString != "")

{

m_BlogTextMsg = m_BlockString.Substring(2, m_BlockString.Length - 2);

//TODO : Add Blog text to user.

}

}

else

{

m_Parameter = SMSMsg.Substring(startIndex);

}

}

foreach (string m_UID in m_Parameter.Split(','))

{

if (m_UID.Trim() != "")

{

m_UserIds += m_UID.Trim() + ",";

}

}

}

if (m_UserIds.Length > 0)

{

m_UserIds = m_UserIds.Substring(0, m_UserIds.Length - 1);

}

}

else

{

IDataReader m_RdrUser = DBMethods.ReadUserFromPhoneNoDB(PhoneNumber);

if (((System.Data.SqlClient.SqlDataReader)(m_RdrUser)).HasRows)

{

m_RdrUser.Read();

HTInfo.Add("UID", m_RdrUser["Id"].ToString());

HTInfo.Add("NU", "No");

if (m_RdrUser["SMSRemainingCount"].ToString() == "1")

{

HTInfo.Add("LM", "Yes");

}

HTInfo.Add("RM", CheckInteger(m_RdrUser["SMSRemainingCount"].ToString()) - 1);

}

else

{

HTInfo.Add("NV", "0");

}

m_ReturnValue = false;

string strReplyMessage = string.Empty;

if (dicReplyMsg.TryGetValue("SLRMC6", out strReplyMessage))

{

m_SMSMessage = strReplyMessage.Replace("~SLC Steplog code SLC~", m_SLCode);

}

HTInfo.Add("Message", m_SMSMessage);

return HTInfo;

}

}

//using loactionId

else

{

m_ReturnValue = false;

LocationID = m_SMSSplit[0].ToString();

m_RdrObj = DBMethods.GetLocationDB(LocationID);

if (((System.Data.SqlClient.SqlDataReader)(m_RdrObj)).HasRows)

{

if (m_RdrObj.Read())

{

//if (SMSMsg.Length > 7)

//{

startIndex = SMSMsg.IndexOf(' ');

if (startIndex != -1)

{

//Comment below line for time...

//string m_Parameter = SMSMsg.Substring(startIndex);

//Uncomment below lines and comment above line for Time...

if (SMSMsg.IndexOf("t:") != -1)

{

leng = SMSMsg.IndexOf("t:") - startIndex;

m_Parameter = SMSMsg.Substring(startIndex, leng);

m_RemString = SMSMsg.Substring(SMSMsg.IndexOf("t:"));

if (m_RemString.IndexOf("b:") != -1)

{

tleng = m_RemString.IndexOf("b:") - m_RemString.IndexOf("t:");

m_TimeString = SMSMsg.Substring(SMSMsg.IndexOf("t:"), tleng);

m_BlockString = SMSMsg.Substring(SMSMsg.IndexOf("b:"));

}

else

{

m_TimeString = SMSMsg.Substring(SMSMsg.IndexOf("t:"));

}

if (m_TimeString.Split(':').Length == 4)

{

//TODO : Add the time by getting the format.

m_Time = m_TimeString.Substring(2, m_TimeString.Length - 2);

}

else

{

m_Time = "";

m_CheckTimeFormat = false;

}

if (m_BlockString != "")

{

m_BlogTextMsg = m_BlockString.Substring(2, m_BlockString.Length - 2);

//TODO : Add Blog text to user.

}

foreach (string m_UID in m_Parameter.Split(','))

{

if (m_UID.Trim() != "")

{

m_UserIds += m_UID.Trim() + ",";

}

}

}

else

{

if (SMSMsg.IndexOf("b:") != -1)

{

tleng = SMSMsg.IndexOf("b:") - startIndex;

m_Parameter = SMSMsg.Substring(startIndex, tleng);

m_BlockString = SMSMsg.Substring(SMSMsg.IndexOf("b:"));

if (m_BlockString != "")

{

m_BlogTextMsg = m_BlockString.Substring(2, m_BlockString.Length - 2);

//TODO : Add Blog text to user.

}

foreach (string m_UID in m_Parameter.Split(','))

{

if (m_UID.Trim() != "")

{

m_UserIds += m_UID.Trim() + ",";

}

}

}

else

{

m_Parameter = SMSMsg.Substring(startIndex);

foreach (string m_UID in m_Parameter.Split(','))

{

if (m_UID.Trim() != "")

{

m_UserIds += m_UID.Trim() + ",";

}

}

}

}

 

}

if (m_UserIds.Length > 0)

{

m_UserIds = m_UserIds.Substring(0, m_UserIds.Length - 1);

}

}

}

else

{

IDataReader m_RdrUser = DBMethods.ReadUserFromPhoneNoDB(PhoneNumber);

if (((System.Data.SqlClient.SqlDataReader)(m_RdrUser)).HasRows)

{

m_RdrUser.Read();

HTInfo.Add("UID", m_RdrUser["Id"].ToString());

HTInfo.Add("NU", "No");

if (m_RdrUser["SMSRemainingCount"].ToString() == "1")

{

HTInfo.Add("LM", "Yes");

}

HTInfo.Add("RM", CheckInteger(m_RdrUser["SMSRemainingCount"].ToString()) - 1);

}

else

{

HTInfo.Add("NV", "0");

}

m_LocReturnValue = false;

string strReplyMessage = string.Empty;

if (dicReplyMsg.TryGetValue("SLRMC6", out strReplyMessage))

{

m_SMSMessage = strReplyMessage.Replace("~SLC Steplog code SLC~", LocationID);

}

 

HTInfo.Add("Message", m_SMSMessage);

 

return HTInfo;

}

}

if (m_ReturnValue)

{

IDataReader m_RdrUser = DBMethods.ReadUserFromPhoneNoDB(PhoneNumber);

if (((System.Data.SqlClient.SqlDataReader)(m_RdrUser)).HasRows)

{

m_RdrUser.Read();

}

if (!((System.Data.SqlClient.SqlDataReader)(m_RdrUser)).HasRows && m_UserIds.Length == 0)

{

Random RPassword = new Random();

Pwd = RPassword.Next(1000, 9999);

IDataReader Rdr = DBMethods.ReadSLAdminDB();

SMSRemainingCount = 0;

if (((System.Data.SqlClient.SqlDataReader)(Rdr)).HasRows)

{

Rdr.Read();

Rem = CheckDecimal(Rdr["SMSInitialAmount"].ToString());

SMSRemainingCount = decimal.ToInt32(Rem);

}

UID = "SL";

NewUserId = UID;

IDataReader m_Rdr;

do

{

m_Rdr = DBMethods.GetUserDB(NewUserId);

if (m_Rdr.Read())

{

Random m_RndmNum = new Random();

Num = m_RndmNum.Next(100, 999);

NewUserId = UID + Num.ToString();

}

else

{

break;

}

} while (true);

m_UserCreatedMsg = DBMethods.AddUserDB(NewUserId, Pwd.ToString(), SMSRemainingCount.ToString());

if (m_UserCreatedMsg)

{

IDataReader UserID = DBMethods.GetUserDB(NewUserId);

if (((System.Data.SqlClient.SqlDataReader)(UserID)).HasRows)

{

UserID.Read();

bool IsUserAccessRight = AddOfficialUserGroupRights(CheckDecimal(UserID["Id"].ToString()));

string addedUserGroupUsers = AssignUserGroupUsers(CheckDecimal("1"), CheckDecimal(UserID["Id"].ToString()), "0");

 

 

isSaved = DBMethods.AddPhoneUserDB(PhoneNumber, UserID["Id"].ToString());

RegisterSLCode(m_Anonymous, UserID["userId"].ToString(), m_BlogTextMsg, m_SLCode, m_Time);

IDataReader RdrCount = DBMethods.ReadLocationCount(CheckDecimal(m_RdrObj["locationid_id"].ToString()), CheckDecimal(UserID["Id"].ToString()));

if (((System.Data.SqlClient.SqlDataReader)(RdrCount)).HasRows)

{

RdrCount.Read();

string strReplyMessage = string.Empty;

if (dicReplyMsg.TryGetValue("SLRMC7", out strReplyMessage))

{

m_SMSMessage = strReplyMessage.Replace("~UID UserID UID~", NewUserId).Replace("~Pass Password Pass~", Pwd.ToString()).Replace("~LN Location Name LN~", RdrCount["name"].ToString());

}

HTInfo.Add("Message", m_SMSMessage);

HTInfo.Add("UID", UserID["Id"].ToString());

HTInfo.Add("NU", "Yes");

HTInfo.Add("RM", CheckInteger(UserID["SMSRemainingCount"].ToString()) - 1);

}

}

}

else

{

m_ReturnValue = false;

m_SMSMessage = "No";

}

}

else if (!((System.Data.SqlClient.SqlDataReader)(m_RdrUser)).HasRows && m_UserIds.Length >= 1)

{

foreach (string str in m_UserIds.Split(','))

{

string[] strId = RegisterSLCode(m_Anonymous, str, m_BlogTextMsg, m_SLCode, m_Time).Split('`');

 

 

IDataReader RdrCount = DBMethods.ReadLocationCount(CheckDecimal(m_RdrObj["locationid_id"].ToString()), CheckDecimal(strId[1]));

if (((System.Data.SqlClient.SqlDataReader)(RdrCount)).HasRows)

{

RdrCount.Read();

if (cond)

{

m_SMSMessage = RdrCount["name"].ToString() + " : ";

cond = false;

}

if (RdrCount["counter"].ToString() != "0")

{

string strReplyMessage = string.Empty;

if (dicReplyMsg.TryGetValue("SLRMC8", out strReplyMessage))

{

m_SMSMessage += strReplyMessage.Replace("~LN Location Name LN~ :", "").Replace("~UID UserID UID~", str).Replace("~NOV No Of Visits NOV~", RdrCount["counter"].ToString());

}

}

else

{

string strReplyMessage = string.Empty;

if (dicReplyMsg.TryGetValue("SLRMC9", out strReplyMessage))

{

m_SMSMessage += strReplyMessage.Replace("~LN Location Name LN~ :", "").Replace("~UID UserID UID~", str).Replace("~NOV No Of Visits NOV~", RdrCount["counter"].ToString());

}

}

}

 

 

}

if (!m_CheckTimeFormat)

{

string strReplyMessage = string.Empty;

if (dicReplyMsg.TryGetValue("SLRMC10", out strReplyMessage))

{

m_SMSMessage += strReplyMessage;

}

}

HTInfo.Add("Message", m_SMSMessage);

HTInfo.Add("UID", "0");

}

else if (((System.Data.SqlClient.SqlDataReader)(m_RdrUser)).HasRows && m_UserIds.Length == 0)

{

string[] strId = RegisterSLCode(m_Anonymous, m_RdrUser["UserId"].ToString(), m_BlogTextMsg, m_SLCode, m_Time).Split('`');

 

IDataReader RdrCount = DBMethods.ReadLocationCount(CheckDecimal(m_RdrObj["locationid_id"].ToString()), CheckDecimal(strId[1]));

if (((System.Data.SqlClient.SqlDataReader)(RdrCount)).HasRows)

{

RdrCount.Read();

m_SMSMessage = RdrCount["name"].ToString() + " : ";

if (RdrCount["counter"].ToString() != "0")

{

string strReplyMessage = string.Empty;

if (dicReplyMsg.TryGetValue("SLRMC8", out strReplyMessage))

{

m_SMSMessage += strReplyMessage.Replace("~LN Location Name LN~ :", "").Replace("~UID UserID UID~", m_RdrUser["UserId"].ToString()).Replace("~NOV No Of Visits NOV~", RdrCount["counter"].ToString());

}

}

else

{

string strReplyMessage = string.Empty;

if (dicReplyMsg.TryGetValue("SLRMC9", out strReplyMessage))

{

m_SMSMessage += strReplyMessage.Replace("~LN Location Name LN~ :", "").Replace("~UID UserID UID~", m_RdrUser["UserId"].ToString()).Replace("~NOV No Of Visits NOV~", RdrCount["counter"].ToString());

}

}

}

if (!m_CheckTimeFormat)

{

string strReplyMessage = string.Empty;

if (dicReplyMsg.TryGetValue("SLRMC10", out strReplyMessage))

{

m_SMSMessage += strReplyMessage;

}

}

HTInfo.Add("Message", m_SMSMessage);

HTInfo.Add("UID", strId[1]);

if (m_RdrUser["SMSRemainingCount"].ToString() == "1")

{

HTInfo.Add("LM", "Yes");

}

HTInfo.Add("RM", CheckInteger(m_RdrUser["SMSRemainingCount"].ToString()) - 1);

}

else if (((System.Data.SqlClient.SqlDataReader)(m_RdrUser)).HasRows && m_UserIds.Length >= 1)

{

m_SMSMessage = "";

foreach (string str in m_UserIds.Split(','))

{

string[] strId = RegisterSLCode(m_Anonymous, str, m_BlogTextMsg, m_SLCode, m_Time).Split('`');

 

 

IDataReader RdrCount = DBMethods.ReadLocationCount(CheckDecimal(m_RdrObj["locationid_id"].ToString()), CheckDecimal(strId[1]));

if (((System.Data.SqlClient.SqlDataReader)(RdrCount)).HasRows)

{

RdrCount.Read();

if (cond)

{

m_SMSMessage = RdrCount["name"].ToString() + " : ";

cond = false;

}

if (RdrCount["counter"].ToString() != "0")

{

string strReplyMessage = string.Empty;

if (dicReplyMsg.TryGetValue("SLRMC8", out strReplyMessage))

{

m_SMSMessage += strReplyMessage.Replace("~LN Location Name LN~ :", "").Replace("~UID UserID UID~", str).Replace("~NOV No Of Visits NOV~", RdrCount["counter"].ToString());

}

}

else

{

string strReplyMessage = string.Empty;

if (dicReplyMsg.TryGetValue("SLRMC9", out strReplyMessage))

{

m_SMSMessage += strReplyMessage.Replace("~LN Location Name LN~ :", "").Replace("~UID UserID UID~", str).Replace("~NOV No Of Visits NOV~", RdrCount["counter"].ToString());

}

}

}

}

if (!m_CheckTimeFormat)

{

string strReplyMessage = string.Empty;

if (dicReplyMsg.TryGetValue("SLRMC10", out strReplyMessage))

{

m_SMSMessage += strReplyMessage;

}

}

HTInfo.Add("Message", m_SMSMessage);

HTInfo.Add("UID", m_RdrUser["Id"].ToString());

if (m_RdrUser["SMSRemainingCount"].ToString() == "1")

{

HTInfo.Add("LM", "Yes");

}

HTInfo.Add("RM", CheckInteger(m_RdrUser["SMSRemainingCount"].ToString()) - 1);

 

}

}

else if (m_LocReturnValue)

{

IDataReader m_RdrUser = DBMethods.ReadUserFromPhoneNoDB(PhoneNumber);

if (((System.Data.SqlClient.SqlDataReader)(m_RdrUser)).HasRows)

{

m_RdrUser.Read();

}

if (!((System.Data.SqlClient.SqlDataReader)(m_RdrUser)).HasRows && m_UserIds.Length == 0)

{

Random RPassword = new Random();

Pwd = RPassword.Next(1000, 9999);

IDataReader Rdr = DBMethods.ReadSLAdminDB();

SMSRemainingCount = 0;

if (((System.Data.SqlClient.SqlDataReader)(Rdr)).HasRows)

{

Rdr.Read();

Rem = CheckDecimal(Rdr["SMSInitialAmount"].ToString());

SMSRemainingCount = decimal.ToInt32(Rem);

}

UID = "SL";

NewUserId = UID;

IDataReader m_Rdr;

do

{

m_Rdr = DBMethods.GetUserDB(NewUserId);

if (m_Rdr.Read())

{

Random m_RndmNum = new Random();

Num = m_RndmNum.Next(100, 999);

NewUserId = UID + Num.ToString();

}

else

{

break;

}

} while (true);

m_UserCreatedMsg = DBMethods.AddUserDB(NewUserId, Pwd.ToString(), SMSRemainingCount.ToString());

if (m_UserCreatedMsg)

{

IDataReader UserID = DBMethods.GetUserDB(NewUserId);



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend