private void fillControls(SqlInt32 DesignationID) { DesignationBAL balDesignation = new DesignationBAL(); DesignationENT entDesignation = new DesignationENT(); entDesignation = balDesignation.SelectByPK(DesignationID); if (!entDesignation.DesignationName.IsNull) { txtDesignationName.Text = entDesignation.DesignationName.Value.ToString(); } }
protected void btnSave_Click(object sender, EventArgs e) { #region Collect Data UserENT entUser = new UserENT(); LeaveTypeENT entLeaveType = new LeaveTypeENT(); DesignationENT entDesignation = new DesignationENT(); if (ddlDepartment.SelectedIndex > 0) { entUser.DepartmentID = Convert.ToInt32(ddlDepartment.SelectedValue); } if (ddlInstitute.SelectedIndex > 0) { entUser.InstituteID = Convert.ToInt32(ddlInstitute.SelectedValue); } if (ddlDesignation.SelectedIndex > 0) { entUser.DesignationID = Convert.ToInt32(ddlDesignation.SelectedValue); entDesignation.DesignationID = Convert.ToInt32(ddlDesignation.SelectedValue); } if (rbFemale.Checked != false) { entUser.Gender = rbFemale.Text.Trim(); } if (rbMale.Checked != false) { entUser.Gender = rbMale.Text.Trim(); } if (txtUsername.Text.Trim() != "") { entUser.UserName = txtUsername.Text.Trim(); } if (txtPassword.Text.Trim() != "") { entUser.Password = txtPassword.Text.Trim(); } if (txtDisplayName.Text.Trim() != "") { entUser.DisplayName = txtDisplayName.Text.Trim(); } if (txtMobileNo.Text.Trim() != "") { entUser.MobileNo = txtMobileNo.Text.Trim(); } if (txtDOB.Text.Trim() != "") { entUser.DOB = txtDOB.Text.Trim(); } if (txtEmail.Text.Trim() != "") { entUser.Email = txtEmail.Text.Trim(); } if (txtExperience.Text.Trim() != "") { entUser.Experience = txtExperience.Text.Trim(); } if (txtQualification.Text.Trim() != "") { entUser.Qualification = txtQualification.Text.Trim(); } if (txtCity.Text.Trim() != "") { entUser.City = txtCity.Text.Trim(); } if (fuStaffPhoto.HasFile) { string strFileLocationSave = "~/Content/assets/images/"; string strPhysicalPath = ""; strPhysicalPath = Server.MapPath(strFileLocationSave); strPhysicalPath += fuStaffPhoto.FileName; strFileLocationSave += fuStaffPhoto.FileName; if (File.Exists(strPhysicalPath)) { File.Delete(strPhysicalPath); } fuStaffPhoto.SaveAs(strPhysicalPath); entUser.PhotoPath = strFileLocationSave; } #endregion Collect Data UserBAL balUser = new UserBAL(); LeaveTypeBAL balLeaveType = new LeaveTypeBAL(); DesignationBAL balDesignation = new DesignationBAL(); entDesignation = balDesignation.SelectByPK(entDesignation.DesignationID); if (Session["UserID"] == null) { if (entDesignation.DesignationName == "HOD") { balUser.Insert(entUser); entUser = balUser.SelectByPK(entUser.UserID); clearSelection(); lblSuccess.Text = "Data Inserted Successfully"; } else if (entDesignation.DesignationName != "HOD") { balUser.Insert(entUser); if (entUser.UserID > 0) { entLeaveType.UserID = entUser.UserID; entUser = balUser.SelectByPK(entUser.UserID); } else { lblErrorMessage.Text = "empty"; return; } entLeaveType.LeaveType = "Casual Leave"; entLeaveType.TotalDays = 25; balLeaveType.Insert(entLeaveType); entLeaveType.LeaveType = "Medical Leave"; entLeaveType.TotalDays = 15; balLeaveType.Insert(entLeaveType); entLeaveType.LeaveType = "LOP"; entLeaveType.TotalDays = 10; balLeaveType.Insert(entLeaveType); entLeaveType.LeaveType = "Other Leave"; entLeaveType.TotalDays = 5; balLeaveType.Insert(entLeaveType); clearSelection(); lblSuccess.Text = "Data Inserted Successfully"; } else { lblErrorMessage.Text = balUser.Message; } using (MailMessage mail = new MailMessage()) { mail.From = new MailAddress("*****@*****.**"); mail.To.Add(entUser.Email.ToString()); mail.Subject = "User Created Successfully !!"; mail.Body = "<h3>You can now login into Leave management system</h3><br>" + "Your Username Is :- " + Convert.ToString(entUser.UserName) + "<br>Your Password Is :- " + Convert.ToString(entUser.Password) + "<br><br><i>Please don't reply, this is auto generated email</i>"; mail.IsBodyHtml = true; using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587)) { smtp.Credentials = new NetworkCredential("*****@*****.**", "password"); smtp.EnableSsl = true; smtp.Send(mail); } } } else { entUser.UserID = Convert.ToInt32(Session["UserID"].ToString().Trim()); if (balUser.Update(entUser)) { if (Session["Select"].ToString() == "Employee") { Response.Redirect("~/Content/Home/Employee_Home.aspx"); } else if (Session["Select"].ToString() == "HOD") { Response.Redirect("~/Content/Home/HOD_Home.aspx"); } } else { lblErrorMessage.Text = balUser.Message; } } }