protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            var message = Request.QueryString["message"] ?? string.Empty;
            var phone = Request.QueryString["phone"] ?? string.Empty;
            var service = Request.QueryString["service"] ?? string.Empty;
            var port = Request.QueryString["port"] ?? string.Empty;
            var main = Request.QueryString["main"] ?? string.Empty;
            var sub = Request.QueryString["sub"] ?? string.Empty;

            var smsId = Guid.NewGuid().ToString();

            var systemSmsPort = ConfigurationManager.AppSettings["SMSPort"] ?? string.Empty;

            if (!string.IsNullOrEmpty(port) &&
                string.Compare(port, systemSmsPort, StringComparison.OrdinalIgnoreCase) == 0)
            {
                // validate the format of Message
                var smsMessage = UtilitiesHelpers.Instance.GetRightFormatOfMessage(message);
                if (smsMessage == null)
                {
                    PrintMessage(phone, Pharma.SMS_SMSReceiving_Invalid_sms_structure, smsId, service);
                }
                else
                {
                    // write to DB
                    var smsRepo = new SMSObjRepository();
                    smsRepo.InsertSMS(smsId, -1, phone, 1, smsMessage[1], -1, DateTime.Now, string.Empty, smsMessage[2],
                                      true, false, false, 1, -1);

                    // print result to screen
                    PrintMessage(phone, Pharma.SMS_SMSReceiving_Thank_For_Using, smsId, service);
                }
            }
            else
            {
                PrintMessage(phone, Pharma.SMS_SMSReceiving_Wrong_Root_Number, smsId, service);
            }
        }
    }
    public DataTable GetListPhonePromotion(string CustomerPhone,int from)
    {
        List<vwSMS> promitionIdList = new List<vwSMS>();
        SMSObjRepository SRepo=new SMSObjRepository();
        List<vwSchedulePromotion> viewSchedule = new List<vwSchedulePromotion>();
        if (from == Constant.inbox)
            promitionIdList = SRepo.GetInboxSMS(CustomerPhone);
        else
        {
            if(from==Constant.outbox)
                promitionIdList = SRepo.GetOutboxSMS(CustomerPhone);
        }

        string protionId = "0,";
        foreach(var item in promitionIdList)
        {
            protionId += item.PromotionId + ",";
        }
        protionId=protionId.Substring(0, protionId.Length - 1);

        return GetPromotionByIdList(protionId);
    }
    private void btnSendSMS_Click(object sender, EventArgs e)
    {
        string subject = (!string.IsNullOrEmpty(txtSubject.Text)) ? txtSubject.Text : "No subject";
        SmsHandler smsobj = new SmsHandler();
        SMSObjRepository smsobjRepo = new SMSObjRepository();
        AdministratorRepository ARepo = new AdministratorRepository();
        ObjLogin adm = (ObjLogin)Session["objLogin"];
        string SMSCode = Guid.NewGuid().ToString().ToLower();
       
        string listPhone = hdfPhoneNumbers.Value;
        if (string.IsNullOrEmpty(listPhone))
        {
            ShowErrorMessage("Please provide recipient to send");
            return;
        }

        char[] separator = new char[] { ',' };
        string[] phoneList = listPhone.Split(separator);
        bool flag = false;
        string PhoneNotExist = string.Empty;

        foreach (string phone in phoneList)
        {
            if (SRepo.CheckSalemenByPhoneNumber(phone))
            {
                smsobjRepo.InsertSMS(SMSCode, 0, adm.Phone, Constant.SalemenType, phone, Constant.SalemenType, DateTime.Now, subject, 
                    txtContent.Text, true, false, false, 1, int.Parse(ddlPromotion.SelectedValue));
                flag = true;
            }
            else
            {
                if (CRepo.IsExistedCustomerByPhone(phone))
                {
                    smsobjRepo.InsertSMS(SMSCode, 0, adm.Phone, Constant.SalemenType, phone, Constant.CustomerType, DateTime.Now, subject, 
                        txtContent.Text, true, false, false, 1, int.Parse(ddlPromotion.SelectedValue));
                    flag = true;
                }
                else
                {
                    if (ARepo.GetAdminByPhoneNumber(phone))
                    {
                        smsobjRepo.InsertSMS(SMSCode, 0, adm.Phone, Constant.SalemenType, phone, Constant.AdminType, DateTime.Now, subject, txtContent.Text, true, false, false, 1, int.Parse(ddlPromotion.SelectedValue));
                        flag = true;
                    }
                }
            }
            if (flag == false)
            {
                PhoneNotExist += phone + ", ";
            }
        }

        if (!string.IsNullOrEmpty(PhoneNotExist))
        {
            ShowErrorMessage(PhoneNotExist.Substring(0, PhoneNotExist.Length - 2) + " not found in database.");
        }
        else
        {
            ShowErrorMessage("Send success");
        }
    }