protected void btnSend_Click(object sender, EventArgs e)
        {
            BusinessLayer.SMS.ApiConfiguration ObjApi = new BusinessLayer.SMS.ApiConfiguration();
            DataTable dt = ObjApi.GetAll();
            DataView  DV = new DataView(dt);

            DV.RowFilter = "IsActive = 1";
            string mobiles     = "";
            string message     = FitMessage(txtMssg.Text.Trim());
            int    smsPerTrans = 20;
            int    memberType  = 1; //1=All, 2=Only Paid,3=Only UnPaid

            BusinessLayer.SMS.SMSTrigger objTrigger = new BusinessLayer.SMS.SMSTrigger();
            //string ROUTE_1 = System.Configuration.ConfigurationSettings.AppSettings["ROUTE_1"];
            //string ROUTE_2 = System.Configuration.ConfigurationSettings.AppSettings["ROUTE_2"];
            //API_INDEX = ROUTE_1;

            string API = string.Empty;

            API_INDEX = Convert.ToString(DV[0]["SMSAPIId"]);

            string strUrl;
            string dataString;
            int    MobNoCount = 0;

            try
            {
                if (txtMobiles.Text.Trim().Length > 0)
                {
                    string[] Arrmob = txtMobiles.Text.Trim().Split(',');
                    for (int i = 0; i < Arrmob.Length; i++)
                    {
                        if (Arrmob[i].Length == 10)
                        {
                            if (API_INDEX == "1")
                            {
                                mobiles += "91" + Arrmob[i].Trim() + ",";
                            }
                            else if (API_INDEX == "2" || API_INDEX == "3" || API_INDEX == "4")
                            {
                                mobiles += Arrmob[i].Trim() + ",";
                            }
                            else if (API_INDEX == "5")
                            {
                                mobiles += "91" + Arrmob[i].Trim() + ";";
                            }
                        }
                        else if (Arrmob[i].Length == 12)
                        {
                            if (API_INDEX == "1")
                            {
                                mobiles += Arrmob[i].Trim() + ",";
                            }
                            else if (API_INDEX == "2" || API_INDEX == "3" || API_INDEX == "4")
                            {
                                mobiles += Arrmob[i].Trim().Substring(2) + ",";
                            }
                            else if (API_INDEX == "5")
                            {
                                mobiles += Arrmob[i].Trim() + ";";
                            }
                        }
                    }

                    if (mobiles.Trim().Length > 0)
                    {
                        mobiles = mobiles.Trim().Substring(0, mobiles.Length - 1).Trim();
                        strUrl  = GetHTTPAPI(mobiles, message);

                        WebRequest      request1    = HttpWebRequest.Create(strUrl);
                        HttpWebResponse response1   = (HttpWebResponse)request1.GetResponse();
                        Stream          s1          = (Stream)response1.GetResponseStream();
                        StreamReader    readStream1 = new StreamReader(s1);
                        dataString = readStream1.ReadToEnd();
                        response1.Close();
                        s1.Close();
                        readStream1.Close();
                    }
                }
                else
                {
                    DataSet   Ds       = new DataSet();
                    DataTable DTMobNos = getMobileNumbers(memberType);//Fetch mobile numbers from Member tables based on MemberType(pritam)
                    DataView  Dv;
                    Dv           = new DataView(DTMobNos);
                    Dv.RowFilter = "Priority = 0"; //Route 1
                    Ds.Tables.Add(Dv.ToTable("TBL_PRIORITY_0"));

                    Dv           = new DataView(DTMobNos);
                    Dv.RowFilter = "Priority = 1"; //Route 2
                    Ds.Tables.Add(Dv.ToTable("TBL_PRIORITY_1"));

                    foreach (DataTable DT in Ds.Tables)
                    {
                        if (DT.Rows.Count > 0)
                        {
                            //if (DT.Rows[0]["Priority"].ToString().Equals("0"))
                            //    API_INDEX = ROUTE_1;
                            //else if (DT.Rows[0]["Priority"].ToString().Equals("1"))


                            //API_INDEX = ROUTE_2;

                            int counter = 0;
                            mobiles = "";

                            foreach (DataRow DR in DT.Rows)
                            {
                                if (API_INDEX == "1")
                                {
                                    mobiles += "91" + DR["MobileNo"].ToString() + ",";
                                }
                                else if (API_INDEX == "2" || API_INDEX == "3" || API_INDEX == "4")
                                {
                                    mobiles += DR["MobileNo"].ToString() + ",";
                                }
                                else if (API_INDEX == "5")
                                {
                                    mobiles += "91" + DR["MobileNo"].ToString() + ";";
                                }

                                MobNoCount++;
                                counter++;

                                if (counter == smsPerTrans)
                                {
                                    mobiles = mobiles.Trim().Substring(0, mobiles.Length - 1).Trim();
                                    strUrl  = GetHTTPAPI(mobiles, message);

                                    WebRequest      request    = HttpWebRequest.Create(strUrl);
                                    HttpWebResponse response   = (HttpWebResponse)request.GetResponse();
                                    Stream          s          = (Stream)response.GetResponseStream();
                                    StreamReader    readStream = new StreamReader(s);
                                    dataString = readStream.ReadToEnd();
                                    response.Close();
                                    s.Close();
                                    readStream.Close();

                                    counter = 0;
                                    mobiles = "";
                                }
                            }

                            if (mobiles.Trim().Length > 0)
                            {
                                mobiles = mobiles.Trim().Substring(0, mobiles.Length - 1).Trim();
                                strUrl  = GetHTTPAPI(mobiles, message);

                                WebRequest      request1    = HttpWebRequest.Create(strUrl);
                                HttpWebResponse response1   = (HttpWebResponse)request1.GetResponse();
                                Stream          s1          = (Stream)response1.GetResponseStream();
                                StreamReader    readStream1 = new StreamReader(s1);
                                dataString = readStream1.ReadToEnd();
                                response1.Close();
                                s1.Close();
                                readStream1.Close();
                            }
                        }
                    }
                }
                ShowMsg("Message Send Successfully");
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
            finally
            {
                if (txtMobiles.Text.Trim().Length == 0)
                {
                    if (MobNoCount > 0)
                    {
                        objTrigger.Save(MobNoCount);
                        Hidden1.Value = "1";
                        btnSend.Style.Add("display", "none");
                    }
                }
            }
        }
        private void SendSMS()
        {
            BusinessLayer.SMS.ApiConfiguration ObjApi = new BusinessLayer.SMS.ApiConfiguration();
            DataTable dt = ObjApi.GetAll();
            DataView  DV = new DataView(dt);

            DV.RowFilter = "IsActive = 1";
            string API = string.Empty;

            API_INDEX = Convert.ToString(DV[0]["SMSAPIId"]);

            try
            {
                string mobiles = "";
                string message = "";
                string strUrl;
                string dataString;

                message = txtMsg.Text.Trim();
                mobiles = txtMobNo.Text.Trim();

                int MobNoCount = 0;
                if (mobiles.Length > 0)
                {
                    string[] Arrmob = mobiles.Trim().Split(',');
                    MobNoCount = Arrmob.Length;//How many nos are sending for SMS
                    mobiles    = "";
                    for (int index = 0; index < Arrmob.Length; index++)
                    {
                        if (Arrmob[index].Length == 10)
                        {
                            mobiles += "91" + Arrmob[index].Trim() + ";";
                        }
                        else if (Arrmob[index].Length == 12)
                        {
                            mobiles += Arrmob[index].Trim() + ";";
                        }
                    }
                    mobiles = mobiles.Trim().Substring(0, mobiles.Length - 1).Trim();
                }
                //------------------------------------

                if (message.Length > 0)
                {
                    if (mobiles.Length == 0)//Then fetch mobile numbers from Database
                    {
                        DataTable dtDB = getMobileNumbers(Convert.ToInt32(ddlGroup.SelectedValue));
                        MobNoCount = dtDB.Rows.Count;//How many nos are sending for SMS
                        int counter = 0;
                        foreach (DataRow dr in dtDB.Rows)
                        {
                            mobiles += "91" + dr["MobileNo"].ToString() + ";";
                            counter++;
                            if (counter == MobNoCount)
                            {
                                mobiles = mobiles.Trim().Substring(0, mobiles.Length - 1);
                                counter = 0;
                            }
                        }
                    }
                    int Credit      = Convert.ToInt32(txtCredit.Text);
                    int TotalCredit = Credit * MobNoCount;
                    strUrl = GetHTTPAPI(mobiles, message);

                    WebRequest      request1    = HttpWebRequest.Create(strUrl);
                    HttpWebResponse response1   = (HttpWebResponse)request1.GetResponse();
                    Stream          s1          = (Stream)response1.GetResponseStream();
                    StreamReader    readStream1 = new StreamReader(s1);
                    dataString = readStream1.ReadToEnd();
                    response1.Close();
                    s1.Close();
                    readStream1.Close();

                    BusinessLayer.SMS.DoctorsSMSTrigger ObjDocSMSTrigger = new BusinessLayer.SMS.DoctorsSMSTrigger();
                    Entity.SMS.DoctorsSMSTrigger        docEntity        = new Entity.SMS.DoctorsSMSTrigger();
                    if (MobNoCount > 0)
                    {
                        docEntity.DoctorsSMSTriggerId = 0;
                        docEntity.Username            = Session["UserId"].ToString();
                        docEntity.GroupId             = Convert.ToInt32(ddlGroup.SelectedValue);
                        docEntity.NoofTrigger         = TotalCredit;
                        docEntity.MessageBody         = txtMsg.Text.ToString();
                        ObjDocSMSTrigger.Save(docEntity);
                        lblMsg.Text   = "<h2>Message send successfully</h2>";
                        Hidden1.Value = "1";
                        btnSendSMS.Style.Add("display", "none");
                    }
                }
            }

            catch (Exception ex)
            {
                lblMsg.Text = "<h2>Error: " + ex.Message + "</h2>";
            }
        }