While i have login then sms has been automatic send to destination number.
please help me stop this. i am stack on there.
namespace Mob_del_dtls
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
int PROJECT_ID;
SqlConnection con = new SqlConnection(@"Data Source=(localdb)\Projects;Initial Catalog=mob_usg_dtls;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False");
con.Open();
SqlCommand cmd = new SqlCommand("Select * from emp_mast1 where emp_id=@emp_id and Password=@Password", con);
cmd.Parameters.AddWithValue("@emp_id", TextBox1.Text.ToString());
cmd.Parameters.AddWithValue("@Password", TextBox2.Text.ToString());
SqlDataReader reader = cmd.ExecuteReader();
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
if (reader.Read())
{
Session["emp_id"] = reader["emp_id"].ToString();
Session["firstname"] = reader["firstname"].ToString();
Session["lastname"] = reader["lastname"].ToString();
Session["department"] = reader["department"].ToString();
reader.Close();
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
PROJECT_ID = int.Parse(dt.Rows[0]["PROJECT_ID"].ToString());
switch (PROJECT_ID)
{
case 1003:
string EmpId = TextBox1.Text;
Response.Redirect(string.Format("~/index.aspx?EmpId={0}", EmpId));
break;
case 1002:
Response.Redirect("admn.aspx");
break;
case 1008:
Response.Redirect("admn.aspx");
break;
}
}
}
else
{
reader.Close();
cmd.Dispose();
con.Close();
lblMessage.Font.Size = FontUnit.Large;
lblMessage.Text = "Invalid credentials";
lblMessage.ForeColor = System.Drawing.Color.Red;
}
}
}
}
namespace Mob_del_dtls
{
public partial class admn : System.Web.UI.Page
{
public void CreateConnection()
{
SqlConnection _sqlConnection = new SqlConnection(strConnectionString);
_sqlCommand = new SqlCommand();
_sqlCommand.Connection = _sqlConnection;
}
public void OpenConnection()
{
_sqlCommand.Connection.Open();
}
public void CloseConnection()
{
_sqlCommand.Connection.Close();
}
public void DisposeConnection()
{
_sqlCommand.Connection.Dispose();
}
private string strConnectionString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
private SqlCommand _sqlCommand;
public string query, constr;
public SqlConnection con;
public void connection()
{
constr = ConfigurationManager.ConnectionStrings["constr"].ToString();
con = new SqlConnection(constr);
con.Open();
}
protected void Page_Load(object sender, EventArgs e)
{
if (Session["FirstName"] == null)
Response.Redirect("login1.aspx");
else
{
// String emp_id = Convert.ToString((int)Session["empid"]);
String firstname = Session["firstname"].ToString();
String lastname = Session["firstname"].ToString();
String department = Session["department"].ToString();
lbluserInfo.Text = "Department:- " + department + ".";
Label1.Text = "Welcome Mr." + firstname + " " + lastname + " ";
}
if (!IsPostBack)
{
BindGrid();
}
}
protected void btnSensms(object sender, EventArgs e)
{
string Id = string.Empty;
DataTable dt = new DataTable();
try
{
foreach (GridViewRow row in GridView1.Rows)
{
//get Current EMAIL_ID from the DataKey
Id = Convert.ToString(GridView1.DataKeys[row.RowIndex].Value);
CheckBox cb = (CheckBox)row.FindControl("chkSelect");
string msg_flag = cb.Checked ? "Y" : "N";
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
SqlCommand cmd = new SqlCommand("UPDATE mbl_usg_dtl SET msg_flag = @msg_flag where Id=@Id");
cmd.Connection = con;
cmd.Parameters.AddWithValue("@msg_flag", msg_flag);
cmd.Parameters.AddWithValue("@Id", Id);
con.Open();
string isUpdated = Convert.ToString(cmd.ExecuteNonQuery());
con.Close();
}
if (cb.Checked)
{
using (SqlConnection con = new SqlConnection(constr))
{
SqlCommand cmd = new SqlCommand("select emp_id,emp_nm, mob_nm, Bill_mob_nm,frm_dt, to_dt, invc_no,invc_dt,lctn,vrfd_by,vrfd,rmk from mbl_usg_dtl where Id=@Id", con);
cmd.Parameters.AddWithValue("@Id", Id);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
//Fill datatable with EMAIL_ID corresponding to Current EMP_ID
adp.Fill(dt);
//Get EMAIL_ID into variable
string emp_id = dt.Rows[0]["emp_id"].ToString();
string emp_nm = dt.Rows[0]["emp_nm"].ToString();
string mob_nm = dt.Rows[0]["mob_nm"].ToString();
string Bill_mob_nm = dt.Rows[0]["Bill_mob_nm"].ToString();
string frm_dt = dt.Rows[0]["frm_dt"].ToString();
string to_dt = dt.Rows[0]["to_dt"].ToString();
string invc_no = dt.Rows[0]["invc_no"].ToString();
string invc_dt = dt.Rows[0]["invc_dt"].ToString();
string lctn = dt.Rows[0]["lctn"].ToString();
string vrfd_by = dt.Rows[0]["vrfd_by"].ToString();
string vrfd = dt.Rows[0]["vrfd"].ToString();
string rmk = dt.Rows[0]["rmk"].ToString();
//sendSMS(mob_nm.Trim(), "Amount of Rs " + frm_dt + " for " + to_dt + " is sent to your Bank account against " + invc_no + " ");
// sendSMS(mob_nm.Trim(), "Monthly bill for the mobile number " + mob_nm + " currently used by " + lctn + " has been generated for date " + frm_dt + " to " + to_dt + " date . kindly verify the bill in MUNPL intranet " );
dt.Clear();
dt.Dispose();
}
}
}
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('Mobile Details has been Sent Successfully.....');", true);
}
catch (Exception ex)
{
Response.Write("Error occured: " + ex.Message.ToString());
}
finally
{
Id = string.Empty;
}
System.Threading.Thread.Sleep(5000);
}
private void BindGrid()
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT Id, emp_id, emp_nm, mob_nm,Bill_mob_nm, frm_dt, to_dt,invc_no, invc_dt,lctn,vrfd_by,vrfd,rmk FROM mbl_usg_dtl "))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
foreach (GridViewRow gvRow in GridView1.Rows)
{
string mob_nm = gvRow.Cells[3].Text;
string lctn = gvRow.Cells[4].Text;
string Bill_mob_nm = gvRow.Cells[9].Text;
string frm_dt = gvRow.Cells[5].Text;
string to_dt = gvRow.Cells[6].Text;
string SMSurl = "http://185.255.8.59/sms/1/text/query?username=NTpc&password=NTpc@321&to=" + mob_nm + "&text=+Monthly bill for the mobile number " + lctn + " currently used by " + Bill_mob_nm + " has been generated for date " + frm_dt + " to " + to_dt + ". kindly verify the bill in MUNPL intranet. &from=MUNPLA & indiaDltContentTemplateId=1207163677944481674&indiaDltPrincipalEntityId=1201159222154902387";
//string SMSurl = "http://185.255.8.59/sms/1/text/query?username=NTpc&password=NTpc@321&to=" + phoneNo + "&text=+ Wish you a Many Many Happy Returns of the Day. May God bless you with Health, Wealth and Prosperity in your life. HAPPY BIRTHDAY. TEAM IT MEJA +&from=MUNPLA & indiaDltContentTemplateId=1207161278139947033&indiaDltPrincipalEntityId=1201159222154902387";
// string SMSurl = "http://185.255.8.59/sms/1/text/query?username=NTpc&password=NTpc@321&to=" + phoneNo + "&text=" + message + " &from=MUNPLA";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(SMSurl);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
}
}
}
}
}
}