how to make Y update in table and sms and email not send after update Y in table
SqlConnection con = new SqlConnection(@"Data Source=(localdb)\Projects;Initial Catalog=Employee;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False");
protected void Page_Load(object sender, EventArgs e)
{
if (Session["FirstName"] == null)
Response.Redirect("login.aspx");
else
{
String EmplooyeId = Convert.ToString((int)Session["empid"]);
String FirstName = Session["FirstName"].ToString();
String LastName = Session["LastName"].ToString();
String Department = Session["Department"].ToString();
lbluserInfo.Text = "Department:- " + Department + ".";
Label1.Text = "Welcome, " + FirstName + " " + LastName + ".";
}
if (!Page.IsPostBack)
{
BindEmpGrid();
}
}
protected void BindEmpGrid()
{
SqlCommand cmd = new SqlCommand("select * from email", con);
DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(dt);
grEmp.DataSource = dt;
grEmp.DataBind();
}
protected void btnSendMail_Click(object sender, EventArgs e)
{
string Id = string.Empty;
DataTable dt = new DataTable();
try
{
foreach (GridViewRow row in grEmp.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("chkSelect");
if (cb.Checked == true)
{
if (cb != null && cb.Checked)
{
//get Current EMAIL_ID from the DataKey
Id = Convert.ToString(grEmp.DataKeys[row.RowIndex].Value);
SqlCommand cmd = new SqlCommand("select email, txn_desc, amt, phone from email where Id=" + Id + "", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
//Fill datatable with EMAIL_ID corresponding to Current EMP_ID
adp.Fill(dt);
//Get EMAIL_ID into variable
string emailId = dt.Rows[0]["email"].ToString();
string txn_desc = dt.Rows[0]["txn_desc"].ToString();
string amt = dt.Rows[0]["amt"].ToString();
string phoneNo = dt.Rows[0]["phone"].ToString();
//write code to send mail
SendEmailUsingGmail(emailId, txn_desc, amt);
sendSMS(phoneNo.Trim(), "Amount of Rs " + amt + " for " + txn_desc + "is sent to your Bank account");
dt.Clear();
dt.Dispose();
}
}
}
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('Payment Details Sent Successfully');", true);
}
catch (Exception ex)
{
Response.Write("Error occured: " + ex.Message.ToString());
}
finally
{
Id = string.Empty;
}
}
private void SendEmailUsingGmail(string toEmailAddress, string txndesc, string amount)
{
try
{
SmtpClient smtp = new SmtpClient();
smtp.Credentials = new NetworkCredential("indradeo7306@gmail.com", "7503431478");
smtp.Port = 587;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
MailMessage message = new MailMessage();
message.From = new MailAddress("indradeo7306@gmail.com");
message.To.Add(toEmailAddress);
message.Subject = " PAYMENT INFORMATION";
message.Body = "Amount of Rs " + amount + " for " + txndesc + "is sent to your Bank account";
smtp.Send(message);
}
catch (Exception ex)
{
Response.Write("Error occured: " + ex.Message.ToString());
}
}
protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
CheckBox chkAll =
(CheckBox)grEmp.HeaderRow.FindControl("chkSelectAll");
if (chkAll.Checked == true)
{
foreach (GridViewRow gvRow in grEmp.Rows)
{
CheckBox chkSel =
(CheckBox)gvRow.FindControl("chkSelect");
chkSel.Checked = true;
}
}
else
{
foreach (GridViewRow gvRow in grEmp.Rows)
{
CheckBox chkSel = (CheckBox)gvRow.FindControl("chkSelect");
chkSel.Checked = false;
}
}
if (chkAll.Checked == true)
{
string flag = chkAll.Checked ? "Y" : "N";
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
SqlCommand cmd = new SqlCommand("UPDATE email SET flag = @flag where Id=@Id");
cmd.Connection = con;
cmd.Parameters.AddWithValue("@flag", flag);
con.Open();
String isUpdated = Convert.ToString(cmd.ExecuteNonQuery());
cmd.ExecuteNonQuery();
con.Close();
}
}
}
static string sendSMS(string mobileNo, string messageTxt)
{
string SMSurl = "gateway";
WebRequest request = HttpWebRequest.Create(SMSurl);
WebResponse response = request.GetResponse();
string retString = response.ToString();
response.Close();
return retString;
}
protected void LinkButton16_Click(object sender, EventArgs e)
{
Response.Redirect("login1.aspx");
}