private void QueueTokenGenerationSMS()
        {
            SMSController smscontroller = new SMSController();
            SMSView smsview = new SMSView();
            DataTable QueueTokenGeneration = new DataTable();
            DataTable QueueTokenGenerationSentSMS = new DataTable();
            WebClient oWeb = new WebClient();
            Byte[] bytHeaders;


            try
            {
                QueueTokenGeneration = null;
                QueueTokenGenerationSentSMS = null;

                smsview = new SMSView();

                QueueTokenGeneration = smscontroller.GetGeneratedQueue();
                foreach (DataRow dr in QueueTokenGeneration.Rows)
                {
                    // ThreadRelease = 1;
                    // Thread.Sleep(2000);
                    DataTable dt = new DataTable();
                    smsview.QueueTransaction = (Convert.ToInt32(dr["queue_visit_tnxid"].ToString()));
                    string QueueTokenGenerationSMS = (dr["visit_queue_no_show"].ToString());
                    string QueueTokenGenerationPhoneNo = (Convert.ToString(dr["visit_customer_id"].ToString()));
                    long QueueCustomerId = (Convert.ToInt64(dr["visit_customer_id"].ToString()));
                    smsview.DepartmentID = (Convert.ToInt32(dr["queue_department_id"]));
                    string Cname = ((dr["visit_customer_name"]).ToString());
                    // dt = smscontroller.GetQueuePosition(smsview);
                    // string QueueTokenGenerationPhoneNo = 61 + QueueTokenGenerationPhoneNo1;
                    smsview.CustId = QueueCustomerId;
                    smsview.PhoneNo = QueueTokenGenerationPhoneNo;
                    int pos = 0;
                    dt = smscontroller.GetQueuePosition123(smsview);

                    foreach (DataRow dc in dt.Rows)
                    {
                        smsview.QueueTransaction = (Convert.ToInt32(dc["queue_visit_tnxid"].ToString()));
                        string dname = (dc["department_desc"].ToString());
                        // Thread.Sleep(100);
                        try
                        {
                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                string queno = (dc["visit_queue_no_show"].ToString());
                                smsview.MySms = queno;
                                // QueueToken = (dc["visit_queue_no_show"].ToString());
                                if (queno == QueueTokenGenerationSMS)
                                {
                                    if (dt != null && dt.Rows.Count > 0 && Convert.ToString(dt.Rows[i]["visit_queue_no_show"]).Equals(queno))
                                    // if (dt.Rows[i]["visit_queue_no_show"] == QueueToken)
                                    {
                                        DataTable CheckMessage = new DataTable();

                                        CheckMessage = smscontroller.GetNewMessageExistance(smsview);
                                        if (CheckMessage.Rows.Count <= 0)
                                        {
                                            pos = i;
                                            #region f pos>0
                                            if (pos > 0)
                                            {
                                                DataTable dtCustName = new DataTable();
                                                smsview.QueueNo = QueueTokenGenerationSMS;
                                                DataTable dtc = new DataTable();
                                                dtc = smscontroller.GetCustId(smsview);
                                                foreach (DataRow drc in dtc.Rows)
                                                {
                                                    

                                                    //retrieve name
                                                    //dtCustName = smscontroller.GetCustomerName(smsview);
                                                    //foreach (DataRow Custname in dtCustName.Rows)
                                                    //{
                                                        
                                                        //string mobileno = 61 + mobileno1;
                                                        //retrieve name
                                                        string SmsStatusMsg = string.Empty;
                                                        string SmsDeliveryStatus = string.Empty;
                                                        try
                                                        {
                                                            #region email
                                                            //if (toAddress != "")
                                                            //{
                                                            //    string subject = "Q Number Details from Welcome to Ampulatory Care Centre";
                                                            //    string body = "Dear  " + Cname + ",<br> Welcome to Ampulatory Care Centre <br/> Your Queue Number is :" + QueueTokenGenerationSMS + "<br/>" + "Selected Department is :" + dname + "<br/>" + "Date Time :" + DateTime.Now + "<br/>" + "Please do not reply to this email. If you have any questions or " + "<br />" + "require further information about the operation of this site," + "<br />" + " please contact: Helpdesk" + "<br />" + "Ph: +61 422889101" + "<br />" + "Email: [email protected]" + "<br />" + "";
                                                            //    MailMessage msgMail = new MailMessage("*****@*****.**", toAddress, subject, body);
                                                            //    msgMail.IsBodyHtml = true;
                                                            //    SmtpClient smtp = new SmtpClient();
                                                            //    smtp.Host = "mail.attsystemsgroup.com";
                                                            //    smtp.UseDefaultCredentials = true;
                                                            //    smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "User@123");
                                                            //    smtp.Send(msgMail);
                                                            //}
                                                            #endregion email
                                                            if (QueueTokenGenerationPhoneNo != "")
                                                            {

                                                                if (QueueTokenGenerationPhoneNo.Length == 11)
                                                                {
                                                                    int t = 5 * pos;

                                                                    TimeSpan span = TimeSpan.FromMinutes(t);
                                                                    string apxtime = span.ToString(@"hh\:mm");
                                                                    string strmsg = "Hi" + " " + Cname + ", Your ticket number is:" + QueueTokenGenerationSMS + " .Approximate time of service  at "+""+apxtime+", Thanks.";
                                                                    //Sample: "Hi Kara, your ticket number is 040, Approximate time of service  at 11.40 AM”
                                                                    //string strmsg1 = "Dear" + " " + Cname + ", Welcome to the Ambulatory Care Centre.\r\nYour ticket number is:" + QueueTokenGenerationSMS + " .\r\nTicket number will be called and displayed in the waiting room TV based on your appointment time. Please wait in the waiting room. Thanks";
                                                                    //\r\n\rTo track status of your queue no send SMS to 9214002002 e.g.: ATT<space><your Q number>";
                                                                    #region Proactive SMS Gateway
                                                                    //string URL = "http://sms.proactivesms.in/sendsms.jsp?user=attsystm&password=attsystm&mobiles=" + mobileno + "&sms=" + strmsg1 + "&senderid=ATTIPL";
                                                                    #endregion Proactive SMS Gateway

                                                                    #region AussieSMS Gateway

                                                                    // string URL = "https://api.aussiesms.com.au/?sendsms&mobileID=61422889101&password=att0424&to=" + mobileno + "&text=" + strmsg1 + "&from=QSoft&msg_type=SMS_TEXT";
                                                                    //string URL = "http://www.smsglobal.com/http-api.php?action=sendsms&user=yahtz6o2&password=46yAfp0i&api=1&to=" + mobileno + "&text=" + strmsg1 + "";
                                                                    //Hospital Gateway

                                                                    //bytHeaders = System.Text.ASCIIEncoding.UTF8.GetBytes("*****@*****.**" + ":" + "EqMs2015");
                                                                    //oWeb.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(bytHeaders));
                                                                    //oWeb.Headers.Add("Content-Type", "text/plain;charset=utf-8");
                                                                    //string URL = "https://tim.telstra.com/cgphttp/servlet/sendmsg?destination=" + mobileno + "&text=" + strmsg1 + "";

                                                                    //SMS for Samsung gateway
                                                                    // Set the username of the account holder.
                                                                    Messaging.MessageController.UserAccount.User = "******";
                                                                    // Set the password of the account holder.
                                                                    Messaging.MessageController.UserAccount.Password = "******";
                                                                    // Set the first name of the account holder (optional).
                                                                    Messaging.MessageController.UserAccount.ContactFirstName = "David";
                                                                    // Set the last name of the account holder (optional).
                                                                    Messaging.MessageController.UserAccount.ContactLastName = "Smith";
                                                                    // Set the mobile phone number of the account holder (optional).
                                                                    Messaging.MessageController.UserAccount.ContactPhone = "0423612367";
                                                                    // Set the landline phone number of the account holder (optional).
                                                                    Messaging.MessageController.UserAccount.ContactLandLine = "0338901234";
                                                                    // Set the contact email of the account holder (optional).
                                                                    Messaging.MessageController.UserAccount.ContactEmail = "*****@*****.**";
                                                                    // Set the country of origin of the account holder (optional).
                                                                    Messaging.MessageController.UserAccount.Country = Countries.Australia;
                                                                    bool testOK = false;
                                                                    try
                                                                    {
                                                                        // Test the user account settings.
                                                                        Account testAccount = Messaging.MessageController.UserAccount;
                                                                        testOK = Messaging.MessageController.TestAccount(testAccount);
                                                                    }
                                                                    catch (Exception ex)
                                                                    {
                                                                        // An exception was thrown. Display the details of the exception and return.
                                                                        string message = "There was an error testing the connection details:\n" +
                                                                        ex.Message;
                                                                        // MessageBox.Show(this, message, "Connection Failed", MessageBoxButtons.OK);
                                                                        return;
                                                                    }
                                                                    if (testOK)
                                                                    {
                                                                        // The user account settings were valid. Display a success message
                                                                        // box with the number of credits.
                                                                        int balance = Messaging.MessageController.UserAccount.Balance;
                                                                        string message = string.Format("You have {0} message credits available.",
                                                                        balance);
                                                                        // MessageBox.Show(this, message, "Connection Succeeded", MessageBoxButtons.OK);
                                                                    }
                                                                    else
                                                                    {
                                                                        // The username or password were incorrect. Display a failed message box.
                                                                        //  MessageBox.Show(this, "The username or password you entered were incorrect.",
                                                                        // "Connection Failed", MessageBoxButtons.OK);
                                                                    }

                                                                    Messaging.MessageController.Settings.TimeOut = 60;
                                                                    // Set the batch size (number of messages to be sent at once) to 200.
                                                                    Messaging.MessageController.Settings.BatchSize = 200;
                                                                    //string strmsg = "To confirm an appointment with the Samsung Experience Store,\r\nyou will need 4 characters password. The password is  " + strrandom + "";
                                                                    //string strmsg = "Hi " + " " + Cname + ", To finalize your appointment with the Samsung Experience Store  at Sydney Central Plaza,\r\nplease enter these 4 characters" + strrandom + "password on the Confirmation screen. Thank you";
                                                                    //string strmsg = "Hi " + " " + Cname + ", To finalize your appointment with the Samsung Experience Store  at Sydney Central Plaza,\r\nplease enter these 4 characters" + strrandom + "password on the Confirmation screen. Thank you";
                                                                    //string strmsg = "Hi" + " " + Cname + ",Your ticket number is:" + QueueTokenGenerationSMS + " . Thanks";

                                                                    //"Hi Kara, your ticket number is 040, Approximate waiting time is 00:40 minutes/hours”

                                                                    Messaging.MessageController.Settings.DeliveryReport = true;
                                                                    SMSMessage smsobj = new SMSMessage(QueueTokenGenerationPhoneNo, strmsg);
                                                                    Messaging.MessageController.AddToQueue(smsobj);
                                                                    Messaging.MessageController.SendMessages();
                                                                    //end of Samsung SMS
                                                                    #endregion AussieSMS Gateway

                                                                    //SmsStatusMsg = oWeb.DownloadString(URL);
                                                                    // if (SmsStatusMsg.Contains("<br>"))
                                                                    //  {
                                                                    //     SmsStatusMsg = SmsStatusMsg.Replace("<br>", ", ");
                                                                    //  }
                                                                    smsview.SMSStatusFlag = "A";
                                                                    QueueTokenGenerationSentSMS = smscontroller.GetQueueTokenGenerationSentSMS(smsview);
                                                                    Thread.Sleep(100);
                                                                    DataTable dt1 = new DataTable();
                                                                    dt1 = smscontroller.GetRetrieveSMSstatusFlag(smsview);

                                                                    foreach (DataRow dr123 in dt1.Rows)
                                                                    {
                                                                        string Sflag = (dr123["message_status_flag"].ToString());
                                                                        string uflag = Convert.ToString("N");
                                                                        if (Sflag == uflag)
                                                                        {
                                                                            smsview.SMSStatusFlag = "A";
                                                                            QueueTokenGenerationSentSMS = smscontroller.GetQueueTokenGenerationSentSMS(smsview);
                                                                        }
                                                                        else
                                                                        {
                                                                            #region xml for messageid
                                                                            //SmsStatusMsg = SmsStatusMsg.Replace("\r\n", "");
                                                                            //SmsStatusMsg = SmsStatusMsg.Replace("\t", "");
                                                                            //SmsStatusMsg = SmsStatusMsg.Replace("\n", "");
                                                                            //XmlDocument xml = new XmlDocument();
                                                                            //xml.LoadXml(SmsStatusMsg); //myXmlString is the xml file in string //copying xml to string: string myXmlString = xmldoc.OuterXml.ToString();
                                                                            //XmlNodeList xnList = xml.SelectNodes("smslist");
                                                                            //foreach (XmlNode xn in xnList)
                                                                            //{
                                                                            //    XmlNode example = xn.SelectSingleNode("sms");
                                                                            //    if (example != null)
                                                                            //    {
                                                                            //        string na = example["messageid"].InnerText;
                                                                            //        string no = example["smsclientid"].InnerText;
                                                                            //        string mobile_no = example["mobile-no"].InnerText;
                                                                            #endregion xml for messageid

                                                                            #region message id from Aussie Gateway

                                                                            //char[] delimiterChars = { ':' };

                                                                            //text = SmsStatusMsg;
                                                                            //System.Console.WriteLine("Original text: '{0}'", text);
                                                                            //string[] words = text.Split(delimiterChars);
                                                                            //System.Console.WriteLine("{0} words in text:", words.Length);

                                                                            //foreach (string s in words)
                                                                            //{
                                                                            //    for (i = 0; i < words.Length; i++)
                                                                            //    {
                                                                            //        if (pos == 1)
                                                                            //        {
                                                                            //            string[] digits = Regex.Split(s, @"\D+");
                                                                            //            //
                                                                            //            // Now we have each number string.
                                                                            //            //
                                                                            //            foreach (string value in digits)
                                                                            //            {
                                                                            //                //
                                                                            //                // Parse the value to get the number.
                                                                            //                //
                                                                            //                int number;
                                                                            //                if (int.TryParse(value, out number))
                                                                            //                {
                                                                            //                    messageid = value;
                                                                            //                }
                                                                            //            }
                                                                            //        }
                                                                            //    }

                                                                            //    // rsbel.QueueNo = s;
                                                                            //    pos++;
                                                                            //}

                                                                            #endregion message id from Aussie Gateway

                                                                            #region proactive delivery report

                                                                            //string URL1 = "http://sms.proactivesms.in/getDLR.jsp?userid=attsystm&password=attsystm&messageid=" + na + "redownload=yes&responce type=xml";

                                                                            #endregion proactive delivery report

                                                                            #region Aussie Delivery report

                                                                            //string URL1 = "https://api.aussiesms.com.au/?querymessage&mobileID=61422889101&password=att0424&msgid=20150617121452";
                                                                            //string URL1 = "https://api.aussiesms.com.au/?querymessage&mobileID=61422889101&password=att0424&msgid=" + messageid + "";


                                                                            #endregion Aussie Delivery report

                                                                            // SmsDeliveryStatus = client.DownloadString(URL1);
                                                                            #region xml for delivery report
                                                                            //SmsDeliveryStatus = SmsDeliveryStatus.Replace("\r\n", "");
                                                                            //SmsDeliveryStatus = SmsDeliveryStatus.Replace("\t", "");
                                                                            //SmsDeliveryStatus = SmsDeliveryStatus.Replace("\n", "");
                                                                            //XmlDocument xml1 = new XmlDocument();
                                                                            //xml.LoadXml(SmsDeliveryStatus); //myXmlString is the xml file in string //copying xml to string: string myXmlString = xmldoc.OuterXml.ToString();
                                                                            ////XmlNodeList xnList1 = xml.SelectNodes("response");

                                                                            ////foreach (XmlNode xn1 in xnList1)
                                                                            ////{
                                                                            //XmlNode example1 = xml.SelectSingleNode("response");
                                                                            //if (example1 != null)
                                                                            //{
                                                                            //    //string rscode = example1["responsecode"].InnerText;
                                                                            //    smsview.DeliveryReport = example1["resposedescription"].InnerText;
                                                                            //    //string dlrcount = example1["dlristcount"].InnerText;
                                                                            //    //string pendingcount = example1["pendingdrcount"].InnerText;

                                                                            //}

                                                                            // }
                                                                            #endregion xml for delivery report

                                                                            #region Aussie Delivery report

                                                                            //char[] delimiterChars1 = { ':' };
                                                                            //text = SmsDeliveryStatus;
                                                                            //System.Console.WriteLine("Original text: '{0}'", text);
                                                                            //words = text.Split(delimiterChars1);
                                                                            //System.Console.WriteLine("{0} words in text:", words.Length);

                                                                            //foreach (string s in words)
                                                                            //{

                                                                            //    smsview.DeliveryReport = s;
                                                                            //}


                                                                            #endregion Aussie Delivery report
                                                                            smsview.MySms = strmsg;
                                                                            smsview.QueueNo = QueueTokenGenerationSMS;
                                                                            smsview.IncomingsmsFlag = "N";
                                                                            smsview.SMSDateTime = System.DateTime.Now;
                                                                            string success;
                                                                            success = smscontroller.GetInsertNewSMS(smsview);

                                                                        }
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    if (QueueTokenGenerationPhoneNo.Length == 9)
                                                                    {
                                                                        QueueTokenGenerationPhoneNo = 61 + QueueTokenGenerationPhoneNo;

                                                                        int t = 5 * pos;

                                                                        TimeSpan span = TimeSpan.FromMinutes(t);
                                                                        string apxtime = span.ToString(@"hh\:mm");
                                                                        //string strmsg = "Dear" + " " + Cname + ", Welcome to the Samsung Experience Store .\r\nYour ticket number is:" + QueueTokenGenerationSMS + " . Thanks";
                                                                        string strmsg = "Hi" + " " + Cname + ", Your ticket number is:" + QueueTokenGenerationSMS + " .Approximate time of service  at " + "" + apxtime + ", Thanks.";
                                                                        //\r\n\rTo track status of your queue no send SMS to 9214002002 e.g.: ATT<space><your Q number>";
                                                                        #region Proactive SMS Gateway
                                                                        //string URL = "http://sms.proactivesms.in/sendsms.jsp?user=attsystm&password=attsystm&mobiles=" + mobileno + "&sms=" + strmsg1 + "&senderid=ATTIPL";
                                                                        #endregion Proactive SMS Gateway

                                                                        #region AussieSMS Gateway

                                                                        // string URL = "https://api.aussiesms.com.au/?sendsms&mobileID=61422889101&password=att0424&to=" + mobileno + "&text=" + strmsg1 + "&from=QSoft&msg_type=SMS_TEXT";
                                                                        //string URL = "http://www.smsglobal.com/http-api.php?action=sendsms&user=yahtz6o2&password=46yAfp0i&api=1&to=" + mobileno + "&text=" + strmsg1 + "";
                                                                        //Hospital Gateway

                                                                        //bytHeaders = System.Text.ASCIIEncoding.UTF8.GetBytes("*****@*****.**" + ":" + "EqMs2015");
                                                                        //oWeb.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(bytHeaders));
                                                                        //oWeb.Headers.Add("Content-Type", "text/plain;charset=utf-8");
                                                                        //string URL = "https://tim.telstra.com/cgphttp/servlet/sendmsg?destination=" + mobileno + "&text=" + strmsg1 + "";

                                                                        #endregion AussieSMS Gateway

                                                                        #region Samsung SMS gateway
                                                                        //SMS for Samsung gateway
                                                                        // Set the username of the account holder.
                                                                        Messaging.MessageController.UserAccount.User = "******";
                                                                        // Set the password of the account holder.
                                                                        Messaging.MessageController.UserAccount.Password = "******";
                                                                        // Set the first name of the account holder (optional).
                                                                        Messaging.MessageController.UserAccount.ContactFirstName = "David";
                                                                        // Set the last name of the account holder (optional).
                                                                        Messaging.MessageController.UserAccount.ContactLastName = "Smith";
                                                                        // Set the mobile phone number of the account holder (optional).
                                                                        Messaging.MessageController.UserAccount.ContactPhone = "0423612367";
                                                                        // Set the landline phone number of the account holder (optional).
                                                                        Messaging.MessageController.UserAccount.ContactLandLine = "0338901234";
                                                                        // Set the contact email of the account holder (optional).
                                                                        Messaging.MessageController.UserAccount.ContactEmail = "*****@*****.**";
                                                                        // Set the country of origin of the account holder (optional).
                                                                        Messaging.MessageController.UserAccount.Country = Countries.Australia;
                                                                        bool testOK = false;
                                                                        try
                                                                        {
                                                                            // Test the user account settings.
                                                                            Account testAccount = Messaging.MessageController.UserAccount;
                                                                            testOK = Messaging.MessageController.TestAccount(testAccount);
                                                                        }
                                                                        catch (Exception ex)
                                                                        {
                                                                            // An exception was thrown. Display the details of the exception and return.
                                                                            string message = "There was an error testing the connection details:\n" +
                                                                            ex.Message;
                                                                            // MessageBox.Show(this, message, "Connection Failed", MessageBoxButtons.OK);
                                                                            return;
                                                                        }
                                                                        if (testOK)
                                                                        {
                                                                            // The user account settings were valid. Display a success message
                                                                            // box with the number of credits.
                                                                            int balance = Messaging.MessageController.UserAccount.Balance;
                                                                            string message = string.Format("You have {0} message credits available.",
                                                                            balance);
                                                                            // MessageBox.Show(this, message, "Connection Succeeded", MessageBoxButtons.OK);
                                                                        }
                                                                        else
                                                                        {
                                                                            // The username or password were incorrect. Display a failed message box.
                                                                            //  MessageBox.Show(this, "The username or password you entered were incorrect.",
                                                                            // "Connection Failed", MessageBoxButtons.OK);
                                                                        }

                                                                        Messaging.MessageController.Settings.TimeOut = 60;
                                                                        // Set the batch size (number of messages to be sent at once) to 200.
                                                                        Messaging.MessageController.Settings.BatchSize = 200;
                                                                        //string strmsg = "To confirm an appointment with the Samsung Experience Store,\r\nyou will need 4 characters password. The password is  " + strrandom + "";
                                                                        //string strmsg = "Hi " + " " + Cname + ", To finalize your appointment with the Samsung Experience Store  at Sydney Central Plaza,\r\nplease enter these 4 characters" + strrandom + "password on the Confirmation screen. Thank you";
                                                                        //string strmsg = "Hi " + " " + Cname + ", To finalize your appointment with the Samsung Experience Store  at Sydney Central Plaza,\r\nplease enter these 4 characters" + strrandom + "password on the Confirmation screen. Thank you";
                                                                        //string strmsg = "Hi" + " " + Cname + ",Your ticket number is:" + QueueTokenGenerationSMS + " . Thanks";

                                                                        //"Hi Kara, your ticket number is 040, Approximate waiting time is 00:40 minutes/hours”

                                                                        Messaging.MessageController.Settings.DeliveryReport = true;
                                                                        SMSMessage smsobj = new SMSMessage(QueueTokenGenerationPhoneNo, strmsg);
                                                                        Messaging.MessageController.AddToQueue(smsobj);
                                                                        Messaging.MessageController.SendMessages();
                                                                        //end of Samsung SMS
                                                                        #endregion Samsung SMS gateway

                                                                        //SmsStatusMsg = oWeb.DownloadString(URL);
                                                                        if (SmsStatusMsg.Contains("<br>"))
                                                                        {
                                                                            SmsStatusMsg = SmsStatusMsg.Replace("<br>", ", ");
                                                                        }
                                                                        smsview.SMSStatusFlag = "A";
                                                                        QueueTokenGenerationSentSMS = smscontroller.GetQueueTokenGenerationSentSMS(smsview);
                                                                        // Thread.Sleep(100);
                                                                        DataTable dt1 = new DataTable();
                                                                        dt1 = smscontroller.GetRetrieveSMSstatusFlag(smsview);

                                                                        foreach (DataRow dr123 in dt1.Rows)
                                                                        {
                                                                            string Sflag = (dr123["sms_status_flag"].ToString());
                                                                            string uflag = Convert.ToString("N");
                                                                            if (Sflag == uflag)
                                                                            {
                                                                                smsview.SMSStatusFlag = "A";
                                                                                QueueTokenGenerationSentSMS = smscontroller.GetQueueTokenGenerationSentSMS(smsview);
                                                                            }
                                                                            else
                                                                            {
                                                                                #region xml for messageid
                                                                                //SmsStatusMsg = SmsStatusMsg.Replace("\r\n", "");
                                                                                //SmsStatusMsg = SmsStatusMsg.Replace("\t", "");
                                                                                //SmsStatusMsg = SmsStatusMsg.Replace("\n", "");
                                                                                //XmlDocument xml = new XmlDocument();
                                                                                //xml.LoadXml(SmsStatusMsg); //myXmlString is the xml file in string //copying xml to string: string myXmlString = xmldoc.OuterXml.ToString();
                                                                                //XmlNodeList xnList = xml.SelectNodes("smslist");
                                                                                //foreach (XmlNode xn in xnList)
                                                                                //{
                                                                                //    XmlNode example = xn.SelectSingleNode("sms");
                                                                                //    if (example != null)
                                                                                //    {
                                                                                //        string na = example["messageid"].InnerText;
                                                                                //        string no = example["smsclientid"].InnerText;
                                                                                //        string mobile_no = example["mobile-no"].InnerText;
                                                                                #endregion xml for messageid

                                                                                #region message id from Aussie Gateway

                                                                                //char[] delimiterChars = { ':' };

                                                                                //text = SmsStatusMsg;
                                                                                //System.Console.WriteLine("Original text: '{0}'", text);
                                                                                //string[] words = text.Split(delimiterChars);
                                                                                //System.Console.WriteLine("{0} words in text:", words.Length);

                                                                                //foreach (string s in words)
                                                                                //{
                                                                                //    for (i = 0; i < words.Length; i++)
                                                                                //    {
                                                                                //        if (pos == 1)
                                                                                //        {
                                                                                //            string[] digits = Regex.Split(s, @"\D+");
                                                                                //            //
                                                                                //            // Now we have each number string.
                                                                                //            //
                                                                                //            foreach (string value in digits)
                                                                                //            {
                                                                                //                //
                                                                                //                // Parse the value to get the number.
                                                                                //                //
                                                                                //                int number;
                                                                                //                if (int.TryParse(value, out number))
                                                                                //                {
                                                                                //                    messageid = value;
                                                                                //                }
                                                                                //            }
                                                                                //        }
                                                                                //    }

                                                                                //    // rsbel.QueueNo = s;
                                                                                //    pos++;
                                                                                //}

                                                                                #endregion message id from Aussie Gateway

                                                                                #region proactive delivery report

                                                                                //string URL1 = "http://sms.proactivesms.in/getDLR.jsp?userid=attsystm&password=attsystm&messageid=" + na + "redownload=yes&responce type=xml";

                                                                                #endregion proactive delivery report

                                                                                #region Aussie Delivery report

                                                                                //string URL1 = "https://api.aussiesms.com.au/?querymessage&mobileID=61422889101&password=att0424&msgid=20150617121452";
                                                                                //string URL1 = "https://api.aussiesms.com.au/?querymessage&mobileID=61422889101&password=att0424&msgid=" + messageid + "";


                                                                                #endregion Aussie Delivery report

                                                                                // SmsDeliveryStatus = client.DownloadString(URL1);
                                                                                #region xml for delivery report
                                                                                //SmsDeliveryStatus = SmsDeliveryStatus.Replace("\r\n", "");
                                                                                //SmsDeliveryStatus = SmsDeliveryStatus.Replace("\t", "");
                                                                                //SmsDeliveryStatus = SmsDeliveryStatus.Replace("\n", "");
                                                                                //XmlDocument xml1 = new XmlDocument();
                                                                                //xml.LoadXml(SmsDeliveryStatus); //myXmlString is the xml file in string //copying xml to string: string myXmlString = xmldoc.OuterXml.ToString();
                                                                                ////XmlNodeList xnList1 = xml.SelectNodes("response");

                                                                                ////foreach (XmlNode xn1 in xnList1)
                                                                                ////{
                                                                                //XmlNode example1 = xml.SelectSingleNode("response");
                                                                                //if (example1 != null)
                                                                                //{
                                                                                //    //string rscode = example1["responsecode"].InnerText;
                                                                                //    smsview.DeliveryReport = example1["resposedescription"].InnerText;
                                                                                //    //string dlrcount = example1["dlristcount"].InnerText;
                                                                                //    //string pendingcount = example1["pendingdrcount"].InnerText;

                                                                                //}

                                                                                // }
                                                                                #endregion xml for delivery report

                                                                                #region Aussie Delivery report

                                                                                //char[] delimiterChars1 = { ':' };
                                                                                //text = SmsDeliveryStatus;
                                                                                //System.Console.WriteLine("Original text: '{0}'", text);
                                                                                //words = text.Split(delimiterChars1);
                                                                                //System.Console.WriteLine("{0} words in text:", words.Length);

                                                                                //foreach (string s in words)
                                                                                //{

                                                                                //    smsview.DeliveryReport = s;
                                                                                //}


                                                                                #endregion Aussie Delivery report
                                                                                smsview.MySms = strmsg;
                                                                                smsview.QueueNo = QueueTokenGenerationSMS;
                                                                                smsview.IncomingsmsFlag = "N";
                                                                                smsview.SMSDateTime = System.DateTime.Now;
                                                                                string success;
                                                                                success = smscontroller.GetInsertNewSMS(smsview);

                                                                            }
                                                                        }
                                                                    }
                                                                }

                                                            }


                                                            //smsview.SMSStatusFlag = "A";
                                                            //QueueTokenGenerationSentSMS = smscontroller.GetQueueTokenGenerationSentSMS(smsview);
                                                        }
                                                        catch (WebException e1)
                                                        {
                                                            SmsStatusMsg = e1.Message;
                                                        }
                                                        catch (Exception e2)
                                                        {
                                                            SmsStatusMsg = e2.Message;
                                                        }
                                                    //}
                                                }
                                                // Thread.Sleep(2000);

                                            }
                                            #endregion if pos>0

                                            #region if pos<0
                                            else
                                            {
                                                DataTable dtCustName = new DataTable();
                                                smsview.QueueNo = QueueTokenGenerationSMS;
                                                DataTable dtc = new DataTable();
                                                dtc = smscontroller.GetCustId(smsview);
                                                foreach (DataRow drc in dtc.Rows)
                                                {
                                                    long custid = (Convert.ToInt64(drc["visit_customer_id"].ToString()));
                                                    smsview.MenberId = (Convert.ToInt32(drc["members_id"].ToString()));
                                                    smsview.CustId = custid;
                                                    //retrieve name
                                                    //dtCustName = smscontroller.GetCustomerName(smsview);
                                                    //foreach (DataRow Custname in dtCustName.Rows)
                                                    //{
                                                        //string custfname = (Custname["members_firstname"].ToString());
                                                        //string custlname = (Custname["members_lastname"].ToString());
                                                        //Cname = custfname + " " + custlname;
                                                        //string mobileno = (Custname["members_mobile"].ToString());
                                                        //toAddress = (Custname["members_email"].ToString());
                                                        //retrieve name
                                                        string SmsStatusMsg = string.Empty;
                                                        string SmsDeliveryStatus = string.Empty;

                                                        try
                                                        {
                                                            #region email
                                                            //if (toAddress != "")
                                                            //{
                                                            //    string subject = "Q Number Details from Welcome to Ampulatory Care Centre";
                                                            //    string body = " Dear  " + Cname + ",<br>Welcome to Ampulatory Care Centre <br/> Your Queue Number is :" + QueueTokenGenerationSMS + "<br/>" + "Selected Department is :" + dname + "<br/>" + "Date Time :" + DateTime.Now + "<br/>" + "<br/>Please do not reply to this email. If you have any questions or " + "<br />" + "require further information about the operation of this site," + "<br />" + " please contact: Helpdesk" + "<br />" + "Ph: +61 422889101" + "<br />" + "Email: [email protected]" + "<br />" + "";
                                                            //    MailMessage msgMail = new MailMessage("*****@*****.**", toAddress, subject, body);
                                                            //    msgMail.IsBodyHtml = true;
                                                            //    SmtpClient smtp = new SmtpClient();
                                                            //    smtp.Host = "mail.attsystemsgroup.com";
                                                            //    smtp.UseDefaultCredentials = true;
                                                            //    smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "User@123");
                                                            //    smtp.Send(msgMail);
                                                            //}
                                                            #endregion email
                                                            if (QueueTokenGenerationPhoneNo != "")
                                                            {
                                                                if (QueueTokenGenerationPhoneNo.Length == 11)
                                                                {
                                                                    int t = 0;
                                                                    TimeSpan span = TimeSpan.FromMinutes(t);
                                                                    string apxtime = span.ToString(@"hh\:mm");
                                                                    string strmsg = "Hi" + " " + Cname + ",Your ticket number is:" + QueueTokenGenerationSMS + " . Thanks";
                                                                    //\r\n\rTo track status of your queue no send SMS to 9214002002 e.g.: ATT<space><your Q number>";
                                                                    //string URL = "http://sms.proactivesms.in/sendsms.jsp?user=attsystm&password=attsystm&mobiles=" + QueueTokenGenerationPhoneNo + "&sms=" + strmsg1 + "&senderid=ATTIPL";
                                                                    //string URL = "https://api.aussiesms.com.au/?sendsms&mobileID=61422889101&password=att0424&to=" + QueueTokenGenerationPhoneNo + "&text=" + strmsg1 + "&from=QSoft&msg_type=SMS_TEXT";
                                                                    //string URL = "http://www.smsglobal.com/http-api.php?action=sendsms&user=yahtz6o2&password=46yAfp0i&api=1&to=" + QueueTokenGenerationPhoneNo + "&text=" + strmsg1 + "";


                                                                    //Hospital Gateway

                                                                    //bytHeaders = System.Text.ASCIIEncoding.UTF8.GetBytes("*****@*****.**" + ":" + "EqMs2015");
                                                                    //oWeb.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(bytHeaders));
                                                                    //oWeb.Headers.Add("Content-Type", "text/plain;charset=utf-8");
                                                                    //string URL = "https://tim.telstra.com/cgphttp/servlet/sendmsg?destination=" + QueueTokenGenerationPhoneNo + "&text=" + strmsg1 + "";

                                                                    #region Samsung SMS gateway
                                                                    //SMS for Samsung gateway
                                                                    // Set the username of the account holder.
                                                                    Messaging.MessageController.UserAccount.User = "******";
                                                                    // Set the password of the account holder.
                                                                    Messaging.MessageController.UserAccount.Password = "******";
                                                                    // Set the first name of the account holder (optional).
                                                                    Messaging.MessageController.UserAccount.ContactFirstName = "David";
                                                                    // Set the last name of the account holder (optional).
                                                                    Messaging.MessageController.UserAccount.ContactLastName = "Smith";
                                                                    // Set the mobile phone number of the account holder (optional).
                                                                    Messaging.MessageController.UserAccount.ContactPhone = "0423612367";
                                                                    // Set the landline phone number of the account holder (optional).
                                                                    Messaging.MessageController.UserAccount.ContactLandLine = "0338901234";
                                                                    // Set the contact email of the account holder (optional).
                                                                    Messaging.MessageController.UserAccount.ContactEmail = "*****@*****.**";
                                                                    // Set the country of origin of the account holder (optional).
                                                                    Messaging.MessageController.UserAccount.Country = Countries.Australia;
                                                                    bool testOK = false;
                                                                    try
                                                                    {
                                                                        // Test the user account settings.
                                                                        Account testAccount = Messaging.MessageController.UserAccount;
                                                                        testOK = Messaging.MessageController.TestAccount(testAccount);
                                                                    }
                                                                    catch (Exception ex)
                                                                    {
                                                                        // An exception was thrown. Display the details of the exception and return.
                                                                        string message = "There was an error testing the connection details:\n" +
                                                                        ex.Message;
                                                                        // MessageBox.Show(this, message, "Connection Failed", MessageBoxButtons.OK);
                                                                        return;
                                                                    }
                                                                    if (testOK)
                                                                    {
                                                                        // The user account settings were valid. Display a success message
                                                                        // box with the number of credits.
                                                                        int balance = Messaging.MessageController.UserAccount.Balance;
                                                                        string message = string.Format("You have {0} message credits available.",
                                                                        balance);
                                                                        // MessageBox.Show(this, message, "Connection Succeeded", MessageBoxButtons.OK);
                                                                    }
                                                                    else
                                                                    {
                                                                        // The username or password were incorrect. Display a failed message box.
                                                                        //  MessageBox.Show(this, "The username or password you entered were incorrect.",
                                                                        // "Connection Failed", MessageBoxButtons.OK);
                                                                    }

                                                                    Messaging.MessageController.Settings.TimeOut = 60;
                                                                    // Set the batch size (number of messages to be sent at once) to 200.
                                                                    Messaging.MessageController.Settings.BatchSize = 200;
                                                                    //string strmsg = "To confirm an appointment with the Samsung Experience Store,\r\nyou will need 4 characters password. The password is  " + strrandom + "";
                                                                    //string strmsg = "Hi " + " " + Cname + ", To finalize your appointment with the Samsung Experience Store  at Sydney Central Plaza,\r\nplease enter these 4 characters" + strrandom + "password on the Confirmation screen. Thank you";
                                                                    //string strmsg = "Hi " + " " + Cname + ", To finalize your appointment with the Samsung Experience Store  at Sydney Central Plaza,\r\nplease enter these 4 characters" + strrandom + "password on the Confirmation screen. Thank you";
                                                                    //string strmsg = "Hi" + " " + Cname + ",Your ticket number is:" + QueueTokenGenerationSMS + " . Thanks";

                                                                    //"Hi Kara, your ticket number is 040, Approximate waiting time is 00:40 minutes/hours”

                                                                    Messaging.MessageController.Settings.DeliveryReport = true;
                                                                    SMSMessage smsobj = new SMSMessage(QueueTokenGenerationPhoneNo, strmsg);
                                                                    Messaging.MessageController.AddToQueue(smsobj);
                                                                    Messaging.MessageController.SendMessages();
                                                                    //end of Samsung SMS
                                                                    #endregion Samsung SMS gateway

                                                                    //SmsStatusMsg = oWeb.DownloadString(URL);
                                                                    if (SmsStatusMsg.Contains("<br>"))
                                                                    {
                                                                        SmsStatusMsg = SmsStatusMsg.Replace("<br>", ", ");
                                                                    }
                                                                    smsview.SMSStatusFlag = "A";
                                                                    smscontroller.GetQueueTokenGenerationSentSMS(smsview);
                                                                    // Thread.Sleep(100);
                                                                    DataTable dt1 = new DataTable();
                                                                    dt1 = smscontroller.GetRetrieveSMSstatusFlag(smsview);

                                                                    foreach (DataRow dr123 in dt1.Rows)
                                                                    {
                                                                        string Sflag = (dr123["sms_status_flag"].ToString());
                                                                        string uflag = Convert.ToString("N");
                                                                        if (Sflag == uflag)
                                                                        {
                                                                            smsview.SMSStatusFlag = "A";
                                                                            QueueTokenGenerationSentSMS = smscontroller.GetQueueTokenGenerationSentSMS(smsview);
                                                                        }
                                                                        else
                                                                        {

                                                                            #region xml for message id
                                                                            //SmsStatusMsg = SmsStatusMsg.Replace("\r\n", "");
                                                                            //SmsStatusMsg = SmsStatusMsg.Replace("\t", "");
                                                                            //SmsStatusMsg = SmsStatusMsg.Replace("\n", "");
                                                                            //XmlDocument xml = new XmlDocument();
                                                                            //xml.LoadXml(SmsStatusMsg); //myXmlString is the xml file in string //copying xml to string: string myXmlString = xmldoc.OuterXml.ToString();
                                                                            //XmlNodeList xnList = xml.SelectNodes("smslist");
                                                                            //foreach (XmlNode xn in xnList)
                                                                            //{
                                                                            //    XmlNode example = xn.SelectSingleNode("sms");
                                                                            //    if (example != null)
                                                                            //    {
                                                                            //        string na = example["messageid"].InnerText;
                                                                            //        string no = example["smsclientid"].InnerText;
                                                                            //        string mobileno = example["mobile-no"].InnerText;
                                                                            #endregion xml for message id

                                                                            #region message id from Aussie Gateway

                                                                            //char[] delimiterChars = { ':' };

                                                                            //text = SmsStatusMsg;
                                                                            //System.Console.WriteLine("Original text: '{0}'", text);
                                                                            //string[] words = text.Split(delimiterChars);
                                                                            //System.Console.WriteLine("{0} words in text:", words.Length);

                                                                            //foreach (string s in words)
                                                                            //{
                                                                            //    for (i = 0; i < words.Length; i++)
                                                                            //    {
                                                                            //        if (pos == 1)
                                                                            //        {
                                                                            //            string[] digits = Regex.Split(s, @"\D+");
                                                                            //            //
                                                                            //            // Now we have each number string.
                                                                            //            //
                                                                            //            foreach (string value in digits)
                                                                            //            {
                                                                            //                //
                                                                            //                // Parse the value to get the number.
                                                                            //                //
                                                                            //                int number;
                                                                            //                if (int.TryParse(value, out number))
                                                                            //                {
                                                                            //                    messageid = value;
                                                                            //                }
                                                                            //            }
                                                                            //        }
                                                                            //    }

                                                                            //    // rsbel.QueueNo = s;
                                                                            //    pos++;
                                                                            //}

                                                                            #endregion message id from Aussie Gateway

                                                                            #region Proactive messageid
                                                                            //string URL1 = "http://sms.proactivesms.in/getDLR.jsp?userid=attsystm&password=attsystm&messageid=" + na + "redownload=yes&responce type=xml";
                                                                            #endregion Proactive messageid

                                                                            #region Aussie Delivery report

                                                                            //string URL1 = "https://api.aussiesms.com.au/?querymessage&mobileID=61422889101&password=att0424&msgid=" + messageid + "";

                                                                            #endregion Aussie Delivery Report
                                                                            //SmsDeliveryStatus = client.DownloadString(URL1);
                                                                            #region Proactive Delivery report
                                                                            //SmsDeliveryStatus = SmsDeliveryStatus.Replace("\r\n", "");
                                                                            //SmsDeliveryStatus = SmsDeliveryStatus.Replace("\t", "");
                                                                            //SmsDeliveryStatus = SmsDeliveryStatus.Replace("\n", "");
                                                                            //XmlDocument xml1 = new XmlDocument();
                                                                            //xml.LoadXml(SmsDeliveryStatus); //myXmlString is the xml file in string //copying xml to string: string myXmlString = xmldoc.OuterXml.ToString();
                                                                            ////XmlNodeList xnList1 = xml.SelectNodes("response");

                                                                            ////foreach (XmlNode xn1 in xnList1)
                                                                            ////{
                                                                            //XmlNode example1 = xml.SelectSingleNode("response");
                                                                            //if (example1 != null)
                                                                            //{
                                                                            //    //string rscode = example1["responsecode"].InnerText;
                                                                            //    smsview.DeliveryReport = example1["resposedescription"].InnerText;
                                                                            //    //string dlrcount = example1["dlristcount"].InnerText;
                                                                            //    //string pendingcount = example1["pendingdrcount"].InnerText;
                                                                            // }
                                                                            //}
                                                                            #endregion Proactive Delivery report

                                                                            #region Aussie Delivery report
                                                                            //char[] delimiterChars1 = { ':' };
                                                                            //text = SmsDeliveryStatus;
                                                                            //System.Console.WriteLine("Original text: '{0}'", text);
                                                                            //words = text.Split(delimiterChars1);
                                                                            //System.Console.WriteLine("{0} words in text:", words.Length);

                                                                            //foreach (string s in words)
                                                                            //{

                                                                            //    smsview.DeliveryReport = s;
                                                                            //}
                                                                            #endregion Aussie Delivery report

                                                                            smsview.MySms = strmsg;
                                                                            smsview.QueueNo = QueueTokenGenerationSMS;
                                                                            smsview.IncomingsmsFlag = "N";
                                                                            smsview.SMSDateTime = System.DateTime.Now;
                                                                            string success;
                                                                            success = smscontroller.GetInsertNewSMS(smsview);

                                                                        }

                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    if (QueueTokenGenerationPhoneNo.Length == 9)
                                                                    {
                                                                        QueueTokenGenerationPhoneNo = 61 + QueueTokenGenerationPhoneNo;

                                                                        int t = 20;
                                                                        TimeSpan span = TimeSpan.FromMinutes(t);
                                                                        string apxtime = span.ToString(@"hh\:mm");
                                                                        //string strmsg = "Dear" + " " + Cname + ",Your ticket number is:" + QueueTokenGenerationSMS + " . Thanks";
                                                                        string strmsg = "Hi" + " " + Cname + ", Your ticket number is:" + QueueTokenGenerationSMS + " .Approximate time of service  at " + "" + apxtime + ", Thanks.";
                                                                        //\r\n\rTo track status of your queue no send SMS to 9214002002 e.g.: ATT<space><your Q number>";
                                                                        // string URL = "http://sms.proactivesms.in/sendsms.jsp?user=attsystm&password=attsystm&mobiles=" + QueueTokenGenerationPhoneNo + "&sms=" + strmsg1 + "&senderid=ATTIPL";
                                                                        //string URL = "https://api.aussiesms.com.au/?sendsms&mobileID=61422889101&password=att0424&to=" + QueueTokenGenerationPhoneNo + "&text=" + strmsg1 + "&from=QSoft&msg_type=SMS_TEXT";
                                                                        //string URL = "http://www.smsglobal.com/http-api.php?action=sendsms&user=yahtz6o2&password=46yAfp0i&api=1&to=" + QueueTokenGenerationPhoneNo + "&text=" + strmsg1 + "";
                                                                        //Hospital Gateway

                                                                        //bytHeaders = System.Text.ASCIIEncoding.UTF8.GetBytes("*****@*****.**" + ":" + "EqMs2015");
                                                                        //oWeb.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(bytHeaders));
                                                                        //oWeb.Headers.Add("Content-Type", "text/plain;charset=utf-8");
                                                                        //string URL = "https://tim.telstra.com/cgphttp/servlet/sendmsg?destination=" + QueueTokenGenerationPhoneNo + "&text=" + strmsg1 + "";

                                                                        #region Samsung SMS gateway
                                                                        //SMS for Samsung gateway
                                                                        // Set the username of the account holder.
                                                                        Messaging.MessageController.UserAccount.User = "******";
                                                                        // Set the password of the account holder.
                                                                        Messaging.MessageController.UserAccount.Password = "******";
                                                                        // Set the first name of the account holder (optional).
                                                                        Messaging.MessageController.UserAccount.ContactFirstName = "David";
                                                                        // Set the last name of the account holder (optional).
                                                                        Messaging.MessageController.UserAccount.ContactLastName = "Smith";
                                                                        // Set the mobile phone number of the account holder (optional).
                                                                        Messaging.MessageController.UserAccount.ContactPhone = "0423612367";
                                                                        // Set the landline phone number of the account holder (optional).
                                                                        Messaging.MessageController.UserAccount.ContactLandLine = "0338901234";
                                                                        // Set the contact email of the account holder (optional).
                                                                        Messaging.MessageController.UserAccount.ContactEmail = "*****@*****.**";
                                                                        // Set the country of origin of the account holder (optional).
                                                                        Messaging.MessageController.UserAccount.Country = Countries.Australia;
                                                                        bool testOK = false;
                                                                        try
                                                                        {
                                                                            // Test the user account settings.
                                                                            Account testAccount = Messaging.MessageController.UserAccount;
                                                                            testOK = Messaging.MessageController.TestAccount(testAccount);
                                                                        }
                                                                        catch (Exception ex)
                                                                        {
                                                                            // An exception was thrown. Display the details of the exception and return.
                                                                            string message = "There was an error testing the connection details:\n" +
                                                                            ex.Message;
                                                                            // MessageBox.Show(this, message, "Connection Failed", MessageBoxButtons.OK);
                                                                            return;
                                                                        }
                                                                        if (testOK)
                                                                        {
                                                                            // The user account settings were valid. Display a success message
                                                                            // box with the number of credits.
                                                                            int balance = Messaging.MessageController.UserAccount.Balance;
                                                                            string message = string.Format("You have {0} message credits available.",
                                                                            balance);
                                                                            // MessageBox.Show(this, message, "Connection Succeeded", MessageBoxButtons.OK);
                                                                        }
                                                                        else
                                                                        {
                                                                            // The username or password were incorrect. Display a failed message box.
                                                                            //  MessageBox.Show(this, "The username or password you entered were incorrect.",
                                                                            // "Connection Failed", MessageBoxButtons.OK);
                                                                        }

                                                                        Messaging.MessageController.Settings.TimeOut = 60;
                                                                        // Set the batch size (number of messages to be sent at once) to 200.
                                                                        Messaging.MessageController.Settings.BatchSize = 200;
                                                                        //string strmsg = "To confirm an appointment with the Samsung Experience Store,\r\nyou will need 4 characters password. The password is  " + strrandom + "";
                                                                        //string strmsg = "Hi " + " " + Cname + ", To finalize your appointment with the Samsung Experience Store  at Sydney Central Plaza,\r\nplease enter these 4 characters" + strrandom + "password on the Confirmation screen. Thank you";
                                                                        //string strmsg = "Hi " + " " + Cname + ", To finalize your appointment with the Samsung Experience Store  at Sydney Central Plaza,\r\nplease enter these 4 characters" + strrandom + "password on the Confirmation screen. Thank you";
                                                                        //string strmsg = "Hi" + " " + Cname + ",Your ticket number is:" + QueueTokenGenerationSMS + " . Thanks";

                                                                        //"Hi Kara, your ticket number is 040, Approximate waiting time is 00:40 minutes/hours”

                                                                        Messaging.MessageController.Settings.DeliveryReport = true;
                                                                        SMSMessage smsobj = new SMSMessage(QueueTokenGenerationPhoneNo, strmsg);
                                                                        Messaging.MessageController.AddToQueue(smsobj);
                                                                        Messaging.MessageController.SendMessages();
                                                                        //end of Samsung SMS
                                                                        #endregion Samsung SMS gateway

                                                                        //SmsStatusMsg = oWeb.DownloadString(URL);
                                                                        if (SmsStatusMsg.Contains("<br>"))
                                                                        {
                                                                            SmsStatusMsg = SmsStatusMsg.Replace("<br>", ", ");
                                                                        }
                                                                        smsview.SMSStatusFlag = "A";
                                                                        smscontroller.GetQueueTokenGenerationSentSMS(smsview);
                                                                        // Thread.Sleep(100);
                                                                        DataTable dt1 = new DataTable();
                                                                        dt1 = smscontroller.GetRetrieveSMSstatusFlag(smsview);

                                                                        foreach (DataRow dr123 in dt1.Rows)
                                                                        {
                                                                            string Sflag = (dr123["message_status_flag"].ToString());
                                                                            string uflag = Convert.ToString("N");
                                                                            if (Sflag == uflag)
                                                                            {
                                                                                smsview.SMSStatusFlag = "A";
                                                                                QueueTokenGenerationSentSMS = smscontroller.GetQueueTokenGenerationSentSMS(smsview);
                                                                            }
                                                                            else
                                                                            {

                                                                                #region xml for message id
                                                                                //SmsStatusMsg = SmsStatusMsg.Replace("\r\n", "");
                                                                                //SmsStatusMsg = SmsStatusMsg.Replace("\t", "");
                                                                                //SmsStatusMsg = SmsStatusMsg.Replace("\n", "");
                                                                                //XmlDocument xml = new XmlDocument();
                                                                                //xml.LoadXml(SmsStatusMsg); //myXmlString is the xml file in string //copying xml to string: string myXmlString = xmldoc.OuterXml.ToString();
                                                                                //XmlNodeList xnList = xml.SelectNodes("smslist");
                                                                                //foreach (XmlNode xn in xnList)
                                                                                //{
                                                                                //    XmlNode example = xn.SelectSingleNode("sms");
                                                                                //    if (example != null)
                                                                                //    {
                                                                                //        string na = example["messageid"].InnerText;
                                                                                //        string no = example["smsclientid"].InnerText;
                                                                                //        string mobileno = example["mobile-no"].InnerText;
                                                                                #endregion xml for message id

                                                                                #region message id from Aussie Gateway

                                                                                //char[] delimiterChars = { ':' };

                                                                                //text = SmsStatusMsg;
                                                                                //System.Console.WriteLine("Original text: '{0}'", text);
                                                                                //string[] words = text.Split(delimiterChars);
                                                                                //System.Console.WriteLine("{0} words in text:", words.Length);

                                                                                //foreach (string s in words)
                                                                                //{
                                                                                //    for (i = 0; i < words.Length; i++)
                                                                                //    {
                                                                                //        if (pos == 1)
                                                                                //        {
                                                                                //            string[] digits = Regex.Split(s, @"\D+");
                                                                                //            //
                                                                                //            // Now we have each number string.
                                                                                //            //
                                                                                //            foreach (string value in digits)
                                                                                //            {
                                                                                //                //
                                                                                //                // Parse the value to get the number.
                                                                                //                //
                                                                                //                int number;
                                                                                //                if (int.TryParse(value, out number))
                                                                                //                {
                                                                                //                    messageid = value;
                                                                                //                }
                                                                                //            }
                                                                                //        }
                                                                                //    }

                                                                                //    // rsbel.QueueNo = s;
                                                                                //    pos++;
                                                                                //}

                                                                                #endregion message id from Aussie Gateway

                                                                                #region Proactive messageid
                                                                                //string URL1 = "http://sms.proactivesms.in/getDLR.jsp?userid=attsystm&password=attsystm&messageid=" + na + "redownload=yes&responce type=xml";
                                                                                #endregion Proactive messageid

                                                                                #region Aussie Delivery report

                                                                                //string URL1 = "https://api.aussiesms.com.au/?querymessage&mobileID=61422889101&password=att0424&msgid=" + messageid + "";

                                                                                #endregion Aussie Delivery Report
                                                                                //SmsDeliveryStatus = client.DownloadString(URL1);
                                                                                #region Proactive Delivery report
                                                                                //SmsDeliveryStatus = SmsDeliveryStatus.Replace("\r\n", "");
                                                                                //SmsDeliveryStatus = SmsDeliveryStatus.Replace("\t", "");
                                                                                //SmsDeliveryStatus = SmsDeliveryStatus.Replace("\n", "");
                                                                                //XmlDocument xml1 = new XmlDocument();
                                                                                //xml.LoadXml(SmsDeliveryStatus); //myXmlString is the xml file in string //copying xml to string: string myXmlString = xmldoc.OuterXml.ToString();
                                                                                ////XmlNodeList xnList1 = xml.SelectNodes("response");

                                                                                ////foreach (XmlNode xn1 in xnList1)
                                                                                ////{
                                                                                //XmlNode example1 = xml.SelectSingleNode("response");
                                                                                //if (example1 != null)
                                                                                //{
                                                                                //    //string rscode = example1["responsecode"].InnerText;
                                                                                //    smsview.DeliveryReport = example1["resposedescription"].InnerText;
                                                                                //    //string dlrcount = example1["dlristcount"].InnerText;
                                                                                //    //string pendingcount = example1["pendingdrcount"].InnerText;
                                                                                // }
                                                                                //}
                                                                                #endregion Proactive Delivery report

                                                                                #region Aussie Delivery report
                                                                                //char[] delimiterChars1 = { ':' };
                                                                                //text = SmsDeliveryStatus;
                                                                                //System.Console.WriteLine("Original text: '{0}'", text);
                                                                                //words = text.Split(delimiterChars1);
                                                                                //System.Console.WriteLine("{0} words in text:", words.Length);

                                                                                //foreach (string s in words)
                                                                                //{

                                                                                //    smsview.DeliveryReport = s;
                                                                                //}
                                                                                #endregion Aussie Delivery report

                                                                                smsview.MySms = strmsg;
                                                                                smsview.QueueNo = QueueTokenGenerationSMS;
                                                                                smsview.IncomingsmsFlag = "N";
                                                                                smsview.SMSDateTime = System.DateTime.Now;
                                                                                string success;
                                                                                success = smscontroller.GetInsertNewSMS(smsview);

                                                                            }

                                                                        }

                                                                    }
                                                                }



                                                            }
                                                        }
                                                        catch (WebException e1)
                                                        {
                                                            SmsStatusMsg = e1.Message;
                                                        }
                                                        catch (Exception e2)
                                                        {
                                                            SmsStatusMsg = e2.Message;
                                                        }

                                                    //}
                                                }
                                                // Thread.Sleep(100);
                                            }
                                            #endregion if pos<0
                                        }

                                    }
                                }
                            }

                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                    // Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            // Thread.Sleep(100);

        }