Thursday, February 4, 2010

CHANGE PASSWORD AND SEND MAIL FUNCTION

protected void btnsave_Click(object sender, EventArgs e)
{
try
{
DataTable dt = new DataTable();
int userid = Convert.ToInt16(Session["UserID"].ToString());
BLL_Users objuser = new BLL_Users();
objuser.UserID = userid;
objuser.Password = txtoldpwd.Text.Trim();
objuser.NewPwd = txtnewpwd.Text.Trim();

dt = objuser.ValidateUserByUserID();
if (dt.Rows.Count > 0)
{

if ((Convert.ToInt16(dt.Rows[0]["IsChange"])) > 0)
{
lblsuccess.Font.Bold = true;
lblsuccess.ForeColor = Color.Red;
lblsuccess.Text = "Please enter correct old password.";
txtoldpwd.Text = "";
}
else
{
lblsuccess.Font.Bold = true;
lblsuccess.ForeColor = Color.Green;
lblsuccess.Text = "Password has been changed successfully.";

DataTable dt1 = new DataTable();
BLL_Users objView = new BLL_Users();
objView.UserID = Convert.ToInt32(Session["UserID"].ToString());
dt1 = objView.GetUserInformation();
if (dt1.Rows.Count > 0)
{
String bodyText = "";
bodyText = "";
bodyText = bodyText + "Dear" + " " + dt1.Rows[0]["FirstName"].ToString() + " " +

dt1.Rows[0]["LastName"].ToString() + ",";
bodyText = bodyText + "
";
bodyText = bodyText + "
";
bodyText = bodyText + "Your password has been changed to :";
bodyText = bodyText + " " + txtnewpwd.Text + "";
bodyText = bodyText + "
";
bodyText = bodyText + "
";
bodyText = bodyText + "If you have any queries or want to send nominations, please mail the same to

aatish09@gmail.com " + "
";
bodyText = bodyText + "
";
bodyText = bodyText + "All the best!";
bodyText = bodyText + "
";
bodyText = bodyText + "
";
bodyText = bodyText + "Regards,";
bodyText = bodyText + "
";
bodyText = bodyText + "Learning Organization ";
bodyText = bodyText + "
";
bodyText = bodyText + "Three Sixty Degree Data Research Pvt.Ltd. Pune";
bodyText = bodyText + "
";
//bodyText = String.Empty;
bool check;

BLL_SendMail objmail = new BLL_SendMail();
check = objmail.sendMail(ConfigurationSettings.AppSettings["adminEmail"],

dt1.Rows[0]["EmailID"].ToString(), "Change Password", bodyText, MailFormat.Html, "", "");
if (check == true)
{
lblsendmail.Visible = true;
lblsendmail.Text = "Password has been Mailed to you, Please check mail.";

}
else
{
lblsendmail.Visible = true;
lblsendmail.Font.Bold = true;
lblsendmail.ForeColor = Color.Red;
lblsendmail.Text = "Problem in sending Email.";
}
}
}
}
}
catch(Exception ex)
{
String errorMessage;
errorMessage = "Error: ";
errorMessage = String.Concat(errorMessage, ex.Message);
errorMessage = String.Concat(errorMessage, " Line: ");
errorMessage = String.Concat(errorMessage, ex.Source);
LCE.Configuration.ErrorLog("Preferences/ChangePassword.cs", errorMessage);
}
}

No comments:

Post a Comment