protected void RPbtnSMSSendDept_Click(object sender, EventArgs e) { try { #region "Start" if (Page.IsValid) { LRlblSmSResultDept.Visible = true; string SMSLongCode = string.Empty, Mobile = string.Empty, Message = string.Empty, CampusID = string.Empty, StudentNo = string.Empty, LeadNo = string.Empty, DeptId = string.Empty, isdcode = string.Empty; lblSmSResultDept.Text = string.Empty; CampusID = Convert.ToString(Session["CampusID"]); DeptId = Convert.ToString(Session["DeptID"]); StudentNo = "0"; LeadNo = "0"; SMSLongCode = Convert.ToString(RddlSMSLongCodeDept.SelectedText); isdcode = Convert.ToString(RtxtIscode.Text); Mobile = isdcode + Convert.ToString(RtxtMobileDept.Text); Message = Convert.ToString(REMessageSMSEditorDept.Text); string SMSLongCodeId = string.Empty; SMSLongCodeId = Convert.ToString(RddlSMSLongCodeDept.SelectedValue); DataTable dtSMSSetup = DataAccessManager.GetSMSLongCodeFullList(Convert.ToString(Session["CampusID"]), SMSLongCodeId); if (dtSMSSetup.Rows.Count > 0) { try { var twilio = new Twilio.TwilioRestClient(dtSMSSetup.Rows[0]["AccountSID"].ToString(), dtSMSSetup.Rows[0]["AuthToken"].ToString()); var message = twilio.SendMessage(SMSLongCode, Mobile, Message); if (message != null) { if (message.Sid != null) { try { var twilioGet = new Twilio.TwilioRestClient(dtSMSSetup.Rows[0]["AccountSID"].ToString(), dtSMSSetup.Rows[0]["AuthToken"].ToString()); var msg = twilioGet.GetMessage(message.Sid); Boolean result = DataAccessManager.ReadSMSAndSaveDatabase(msg.AccountSid, msg.DateSent.ToString("yyyy-MM-dd HH:mm:ss"), Convert.ToString(msg.Sid), Convert.ToString(msg.To), Convert.ToString(msg.From), Convert.ToString(msg.Body), Convert.ToString(msg.Status), Convert.ToString(msg.Direction), Convert.ToString(msg.ErrorCode), Convert.ToString(msg.ErrorMessage), msg.DateCreated.ToString("yyyy-MM-dd HH:mm:ss"), msg.DateUpdated.ToString("yyyy-MM-dd HH:mm:ss"), Convert.ToString(StudentNo), Convert.ToString(LeadNo), Convert.ToString(DeptId)); if (result == true) { RPbtnSMSSendDept.Enabled = true; //lblSmSResultDept.Text = "Message has been sent!"; if (Convert.ToInt32(ViewState["count"]) == 2) { RddlSMSLongCodeDept.SelectedIndex = 1; } RtxtMobileDept.Text = string.Empty; REMessageSMSEditorDept.Text = string.Empty; RtxtIscode.Text = "+1"; /*27 july change After SMS Message send, return to SMS page*/ /*Start*/ string LeadId = string.Empty; LeadId = Convert.ToString(Session["LeadId"]); StudentNo = Convert.ToString(Session["StudentNo"]); string type = string.Empty; if (StudentNo != string.Empty && StudentNo != null && StudentNo != "0") { type = "Student"; } if (LeadId != string.Empty && LeadId != null && LeadId != "0") { type = "Lead"; } Session["PageClick"] = "0"; Response.Redirect("~/frmdepartment.aspx?type=Department&Operation=Receive SMS"); /*End*/ } // DeptGridBind("SMSSent"); // DeptGridBind("SMSReceived"); ; } catch (Exception ex) { RPbtnSMSSendDept.Enabled = true; lblSmSResultDept.Text = "Message Failed!"; } } else { lblSmSResultDept.Text = "Message failed,Please check the number."; } } else { lblSmSResultDept.Text = "Message Failed!"; } } catch (Exception ex) { RPbtnSMSSendDept.Enabled = true; lblSmSResultDept.Text = "Message Failed!"; } } else { lblSmSResultDept.Text = "Please make sure update SMS Configration!."; } } #endregion } catch (Exception ex) { } }