How to pass string value from Public Class to public partial class in C#

Last Reply on Aug 02, 2012 05:13 AM By Mudassar

Posted on Aug 02, 2012 03:44 AM
Hi,
I am having one Method like below in public class,I just need to retrieve one string value(res[0])in another public partial class(page class).
Any help could be greatly Thankful.

public SMSResultStatusEnum SendSMS(StringBuilder mobilenumber, string message, string Language) { string Unicode; string SMSUsername = AppSettingsManager.Instance.SMSUsername; string SMSPassword = AppSettingsManager.Instance.SMSPassword; string SMSSenderID = AppSettingsManager.Instance.SMSSenderID; string correctedmobilenumber = CorrectMobileNumber(mobilenumber); ///@todo: REMOVE THIS IN PRODUCTION! //return // SMSResultStatus.SUCCESSFUL; if (Language.ToLower() == "english") { Unicode = "E"; } else { Unicode = "U"; message = ToHexString(message); } //Uri uri = new Uri("http://59.162.167.52/api/MessageCompose?admin=imran@instareach.com&user=" + SMSUsername + ":" + SMSPassword + "&senderID=" + SMSSenderID + "&receipientno=" + correctedmobilenumber + "&msgtxt=" + message + "&state=4"); Uri uri = new Uri("http://183.81.161.84:13016/cgi-bin/sendsms?username=" + SMSUsername + "&password=" + SMSPassword + "&to=" + correctedmobilenumber + "&from=" + SMSSenderID + "&text=" + message); try { HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(uri); HttpWebResponse httpResponse = (HttpWebResponse)(httpReq.GetResponse()); StreamReader reader = new StreamReader(httpResponse.GetResponseStream()); string tmp = reader.ReadToEnd(); string[] res = tmp.Split('&'); //string Result = tmp.Substring(0, 8) + "".ToString(); httpResponse.Close(); //SMSResultStatusEnum statusCode = (SMSResultStatusEnum)SMSResultStatusEnum.Successfull; if (res[0] == "status=0") { SMSResultStatusEnum statusCode = (SMSResultStatusEnum)SMSResultStatusEnum.Successfull; return statusCode; } else if (res[0] == "status=1") { SMSResultStatusEnum statusCode = (SMSResultStatusEnum)SMSResultStatusEnum.AuthorisationFailed; return statusCode; } else if (res[0] == "status=28") { SMSResultStatusEnum statusCode = (SMSResultStatusEnum)SMSResultStatusEnum.InvalidDestinationNumber; return statusCode; } else { SMSResultStatusEnum statusCode = (SMSResultStatusEnum)SMSResultStatusEnum.OtherProblems; return statusCode; } //return statusCode; } catch { return SMSResultStatusEnum.OtherProblems; } }

 

Results 1 - 5 of 8 12
Posted on Aug 02, 2012 03:44 AM

In your class create a Public method and then call it in your Partial class


Posted on Aug 02, 2012 04:33 AM

I have created public Method in first class,but when I put breakpoint at this method debugger is not at all coming at this method so the the vlaue is not coming in the string which I have declared in Public Method so and I cant able to use it in another class.Please have a kind look at my code.

public class SMSHelper
    {
 public static string smsstatusnew;
        string smsstatus; 
        string[] res;

public SMSResultStatusEnum SendSMS(StringBuilder mobilenumber, string message, string Language)
        {
            string Unicode;
            string SMSUsername = AppSettingsManager.Instance.SMSUsername;
            string SMSPassword = AppSettingsManager.Instance.SMSPassword;
            string SMSSenderID = AppSettingsManager.Instance.SMSSenderID;
            string correctedmobilenumber = CorrectMobileNumber(mobilenumber);

            ///@todo: REMOVE THIS IN PRODUCTION!
            //return
            //    SMSResultStatus.SUCCESSFUL;

            if (Language.ToLower() == "english")
            {
                Unicode = "E";
            }
            else
            {
                Unicode = "U";
                message = ToHexString(message);
            }

            //Uri uri = new Uri("http://59.162.167.52/api/MessageCompose?admin=imran@instareach.com&user=" + SMSUsername + ":" + SMSPassword + "&senderID=" + SMSSenderID + "&receipientno=" + correctedmobilenumber + "&msgtxt=" + message + "&state=4");
            Uri uri = new Uri("http://183.81.161.84:13016/cgi-bin/sendsms?username=" + SMSUsername + "&password=" + SMSPassword + "&to=" + correctedmobilenumber + "&from=" + SMSSenderID + "&text=" + message);
            
            try
            {
                HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(uri);

                HttpWebResponse httpResponse = (HttpWebResponse)(httpReq.GetResponse());
                StreamReader reader = new StreamReader(httpResponse.GetResponseStream());
                string tmp = reader.ReadToEnd();
                res = tmp.Split('&');
                //string Result = tmp.Substring(0, 8) + "".ToString();
                httpResponse.Close();
                
                //SMSResultStatusEnum statusCode = (SMSResultStatusEnum)SMSResultStatusEnum.Successfull;
                if (res[0] == "status=0")
                {
                    SMSResultStatusEnum statusCode = (SMSResultStatusEnum)SMSResultStatusEnum.Successfull;
                    return statusCode;
                }
                else if (res[0] == "status=1")
                {
                    SMSResultStatusEnum statusCode = (SMSResultStatusEnum)SMSResultStatusEnum.AuthorisationFailed;
                    return statusCode;

                }

                else if (res[0] == "status=28")
                {
                    SMSResultStatusEnum statusCode = (SMSResultStatusEnum)SMSResultStatusEnum.InvalidDestinationNumber;
                    return statusCode;

                }
                else
                {

                    SMSResultStatusEnum statusCode = (SMSResultStatusEnum)SMSResultStatusEnum.OtherProblems;
                    return statusCode;
                }
                //return statusCode;
            }
            catch
            {
                return SMSResultStatusEnum.OtherProblems;
            }
        }

 public void SMSStatus()
        {

             smsstatus = res[0];
            smsstatusnew = smsstatus;
        }
}

 


Posted on Aug 02, 2012 04:35 AM

How are you calling this public method?


Posted on Aug 02, 2012 04:37 AM

In Public Partial class as

string smsstatus =SMSHelper.smsstatusnew;


Posted on Aug 02, 2012 04:38 AM

In Public Partial class(page class) as

string smsstatus =SMSHelper.smsstatusnew;

I agree, here is the link: http://e-iceblue.com/free-api