ForgetPassword----------- using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using DAL; using BLL; using ENTITY; using System.Net; using System.Net.Mail; using System.Drawing; public partial class Forget_Password : System.Web.UI.Page { string UserName = string.Empty; string Password = string.Empty; string Name = string.Empty; BLL_AdminLogin bllforgetpassword = new BLL_AdminLogin(); ENT_AdminLogin entforgetpassword = new ENT_AdminLogin(); protected void Page_Load(object sender, EventArgs e) { } protected void btnforgetpassword_Click(object sender, EventArgs e) { try { DataTable dt = new DataTable(); //entforpass.IURegID = Convert.ToInt32(Session["URegID"].ToString()); entforgetpassword.SEmail = txtforgetpassword.Text.ToString(); dt = bllforgetpassword.selectforpass(entforgetpassword); if (dt.Rows.Count > 0) { Name = dt.Rows[0]["UserName"].ToString(); UserName = dt.Rows[0]["Email"].ToString(); Password = dt.Rows[0]["Password"].ToString(); SendMail(); Clear(); lblerror.ForeColor = Color.Green; lblerror.Text = "password has been sent on your email.."; } else { lblerror.Text = "Invalid Email"; lblerror.ForeColor = Color.Red; } } catch (Exception) { throw; } } protected void Clear() { txtforgetpassword.Text = ""; } public void SendMail() { string body = @" Untitled Page
Enquiry
  Dear  " + Name + @"    
     
Your Username & Password has been Recovered .  .
 

User Name :  " + UserName + @"

Password :  " + Password + @"

 
 
This is an auto-generated mail. Please do not reply
"; MailMessage message = new MailMessage(UserName, UserName, " Recovery Password ", body); message.IsBodyHtml = true; SmtpClient emailClient = new SmtpClient("smtp.gmail.com"); NetworkCredential smtpUserInfo = new System.Net.NetworkCredential("yourenquiryfromweb@gmail.com", "aoss@2311"); message.Bcc.Add("chatwithanuj@gmail.com"); emailClient.Port = 587; //for gamil emailClient.EnableSsl = true; message.Priority = MailPriority.High; emailClient.UseDefaultCredentials = false; emailClient.Credentials = smtpUserInfo; emailClient.EnableSsl = true; emailClient.Send(message); } } ----------------------------------------------------------------------------------------- Update Image---------------- public string CreateRandomCode(int codeCount) { string allChar = "0,1,2,3,4,5,6,7,8,9,a,A,b,B,c,C,d,D,e,E,f,F,G,g,H,h,I,i,j,J,K,k,L,l,M,m,N,n,O,o,P,p,Q,q,R,r,S,s,T,t,U,u,V,v,W,w,x,X,y,Y,Z,z"; string[] allCharArray = allChar.Split(','); string randomCode = ""; int temp = -1; Random rand = new Random(); for (int i = 0; i < codeCount; i++) { if (temp != -1) { rand = new Random(i * temp * ((int)DateTime.Now.Ticks)); } int t = rand.Next(62); if (temp != -1 && temp == t) { return CreateRandomCode(codeCount); } temp = t; randomCode += allCharArray[t]; } return randomCode; } -------------------------------------------------------------------- Image Upload---------------- if (btnsubmit.Text == "Submit") { if (fileupload.HasFile == true) { string filename = CreateRandomCode(20) + Path.GetFileName(fileupload.FileName); entbooks.SBookImage = filename; string fileExtantion = Path.GetExtension(fileupload.FileName); string fileurl = "~/UploadImage/" + filename; entbooks.SBookImage = fileurl; fileupload.SaveAs(Server.MapPath("~/UploadImage/") + filename); } else { entbooks.SBookImage = ""; } int iResult = bllbooks.insertbook(entbooks); if (iResult != 0) { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "addScript", "alert('Record Saved successfully.');", true); clear(); } else { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "addScript", "alert('Record Not Saved.');", true); } } --------------------------------------------------------------------------- Updte Image query--------------------- ALTER PROCEDURE [dbo].[Ad_U_AlbumPhoto] -- Add the parameters for the stored procedure here @PhotoId int, @PhotoNaame nvarchar(200), @PhotoUrl varchar(500), @Description nvarchar(max) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here if(@PhotoUrl='') Begin update Photo set Description=@Description where PhotoId=@PhotoId end else begin update Photo set PhotoNaame=@PhotoNaame,PhotoUrl =@PhotoUrl,Description=@Description where PhotoId=@PhotoId end END ---------------------------------------------------------------------------------- Login Code------------------ protected void btnlogin_Click(object sender, EventArgs e) { try { DataTable dt = new DataTable(); entadminlogin.SUserId = txtuser.Text.ToString(); entadminlogin.SPassword = txtpass.Text.ToString(); dt = blladminlogin.selectadminlogin(entadminlogin); if (dt.Rows.Count > 0) { Session["AdminLog"] = dt.Rows[0]["Uid"].ToString(); Session["UserName"] = dt.Rows[0]["UserName"].ToString(); Response.Redirect("~/Admin/Welcome-Admin.aspx", false); Clear(); } else { //error_message.Visible = true; lblerror.Text = "Username or password is invalid"; } } catch (Exception) { throw; } } ---------------------------------------------------------------------------------------------------- All Update and insert and select and delete--------------------- protected void btnsubmit_Click(object sender, EventArgs e) { try { enthelloparijat.sName = txtname.Text.ToString(); enthelloparijat.sFatherName = txtfathername.Text.ToString(); enthelloparijat.sEmail = txtemail.Text.ToString(); enthelloparijat.sPhoneNo = txtphone.Text.ToString(); enthelloparijat.sAddress = txtAddres.Text.ToString(); if (btnsubmit.Text == "Submit") { if (fileupload.HasFile == true) { string filename = CreateRandomCode(20) + Path.GetFileName(fileupload.FileName); enthelloparijat.sImage = filename; string fileExtantion = Path.GetExtension(fileupload.FileName); string fileurl = "~/UploadFile/" + filename; enthelloparijat.sImage = fileurl; fileupload.SaveAs(Server.MapPath("~/UploadFile/") + filename); } else { enthelloparijat.sImage = ""; } int iResult = bllhelloparijat.InsertHelloparijat(enthelloparijat); if (iResult != 0) { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "addScript", "alert('Record Saved successfully.');", true); Clear(); FillParijat(); } else { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "addScript", "alert('Record Not Saved.');", true); } } else if (btnsubmit.Text == "Update") { if (fileupload.HasFile == true) { string filename = CreateRandomCode(20) + Path.GetFileName(fileupload.FileName); enthelloparijat.sImage = filename; string fileExtantion = Path.GetExtension(fileupload.FileName); string fileurl = "~/UploadFile/" + filename; enthelloparijat.sImage = fileurl; fileupload.SaveAs(Server.MapPath("~/UploadFile/") + filename); } else { enthelloparijat.sImage = ViewState["image"].ToString(); } enthelloparijat.iUserId = Convert.ToInt32(hfId.Value); int iResult = bllhelloparijat.Updatehelloparijat(enthelloparijat); if (iResult != 0) { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "addScript", "alert('Recored has been Updated Successfully.');", true); btnsubmit.Text = "Submit"; txtname.Text = ""; txtfathername.Text = ""; txtemail.Text = ""; txtphone.Text = ""; txtAddres.Text = ""; FillParijat(); } else { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "addScript", "alert('Recored Not Updated.');", true); } } } catch (Exception) { throw; } } private void Clear() { txtname.Text = ""; txtfathername.Text = ""; txtemail.Text = ""; txtphone.Text = ""; txtAddres.Text = ""; } public string CreateRandomCode(int codeCount) { string allChar = "0,1,2,3,4,5,6,7,8,9,a,A,b,B,c,C,d,D,e,E,f,F,G,g,H,h,I,i,j,J,K,k,L,l,M,m,N,n,O,o,P,p,Q,q,R,r,S,s,T,t,U,u,V,v,W,w,x,X,y,Y,Z,z"; string[] allCharArray = allChar.Split(','); string randomCode = ""; int temp = -1; Random rand = new Random(); for (int i = 0; i < codeCount; i++) { if (temp != -1) { rand = new Random(i * temp * ((int)DateTime.Now.Ticks)); } int t = rand.Next(62); if (temp != -1 && temp == t) { return CreateRandomCode(codeCount); } temp = t; randomCode += allCharArray[t]; } return randomCode; } public void FillParijat() { try { DataTable dt = new DataTable(); dt = bllhelloparijat.Selecthelloparijat(); if (dt.Rows.Count > 0) { grdparijat.DataSource = dt; grdparijat.DataBind(); } else { DataRow datarow = dt.NewRow(); dt.Rows.Add(datarow); grdparijat.DataSource = dt; grdparijat.DataBind(); int totalcolumn = grdparijat.Rows[0].Cells.Count; grdparijat.Rows[0].Cells.Clear(); grdparijat.Rows[0].Cells.Add(new TableCell()); grdparijat.Rows[0].Cells[0].ColumnSpan = totalcolumn; grdparijat.Rows[0].Cells[0].Text = "There is no record."; } } catch (Exception ex) { lblmsg.ForeColor = Color.Red; lblmsg.Text = ex.Message; } } protected void grdparijat_PageIndexChanging(object sender, GridViewPageEventArgs e) { grdparijat.PageIndex = e.NewPageIndex; FillParijat(); } protected void imgbtnDeleteprijat_Click(object sender, EventArgs e) { try { Button btnButton = sender as Button; GridViewRow gvRow = (GridViewRow)btnButton.NamingContainer; enthelloparijat.iUserId = (int)grdparijat.DataKeys[gvRow.RowIndex].Value; int result = bllhelloparijat.Deletehelloparijat(enthelloparijat); if (result != 0) { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "addScript", "alert('Record has been Deleted successfully.');", true); FillParijat(); } } catch (Exception ex) { lblmsg.Text = ex.Message; } } protected void imgbtnEditparijat_Click(object sender, EventArgs e) { Button btnButton = sender as Button; GridViewRow gvRow = (GridViewRow)btnButton.NamingContainer; enthelloparijat.iUserId = (int)grdparijat.DataKeys[gvRow.RowIndex].Value; DataTable dt = new DataTable(); dt = bllhelloparijat.SelectUpdatehelloparijat(enthelloparijat); if (dt.Rows.Count > 0) { txtname.Text = dt.Rows[0]["Name"].ToString(); txtfathername.Text = dt.Rows[0]["FatherName"].ToString(); txtemail.Text = dt.Rows[0]["Email"].ToString(); txtphone.Text = dt.Rows[0]["PhoneNo"].ToString(); txtAddres.Text = dt.Rows[0]["Address"].ToString(); ViewState["image"] = dt.Rows[0]["Image"].ToString(); hfId.Value = ((int)grdparijat.DataKeys[gvRow.RowIndex].Value).ToString(); ViewState["UserId"] = hfId.Value; btnsubmit.Text = "Update"; } }