public Boolean Insert(HospitalWiseDoctorENT entHospitalWiseDoctor) { HospitalWiseDoctorDAL dalHospitalWiseDoctor = new HospitalWiseDoctorDAL(); if (dalHospitalWiseDoctor.Insert(entHospitalWiseDoctor)) { return(true); } else { Message = dalHospitalWiseDoctor.Message; return(false); } }
public Boolean Insert(HospitalWiseDoctorENT entHospitalWiseDoctor) { using (SqlConnection objConn = new SqlConnection(ConnectionString)) { objConn.Open(); using (SqlCommand objCmd = objConn.CreateCommand()) { try { #region Prepare Command objCmd.CommandType = CommandType.StoredProcedure; objCmd.CommandText = "PR_HospitalWiseDoctor_Insert"; objCmd.Parameters.Add("@HospitalWiseDoctorID", SqlDbType.Int, 4).Direction = ParameterDirection.Output; objCmd.Parameters.Add("@HospitalID", SqlDbType.Int).Value = entHospitalWiseDoctor.HospitalID; objCmd.Parameters.Add("@DoctorID", SqlDbType.Int).Value = entHospitalWiseDoctor.DoctorID; #endregion Prepare Command objCmd.ExecuteNonQuery(); if (objCmd.Parameters["@HospitalWiseDoctorID"] != null) { entHospitalWiseDoctor.HospitalWiseDoctorID = Convert.ToInt32(objCmd.Parameters["@HospitalWiseDoctorID"].Value); } return(true); } catch (SqlException sqlEx) { Message = sqlEx.InnerException.Message; return(false); } catch (Exception ex) { Message = ex.InnerException.Message; return(false); } finally { if (objConn.State == ConnectionState.Open) { objConn.Close(); } } } } }
protected void btnSave_Click(object sender, EventArgs e) { #region server side validation String strErrorMessage = ""; if (txtDoctorName.Text.Trim() == "") { strErrorMessage += "- Enter Doctor Name <br/>"; } if (ddlDepartment.SelectedIndex <= 0) { strErrorMessage += "- Select Department <br/>"; } if (txtExperince.Text.Trim() == "") { strErrorMessage += "- Enter Experence (In year) <br/>"; } if (Request.QueryString["DoctorID"] == null) { if (txtUserName.Text.Trim() == "") { strErrorMessage += "- Enter UserName <br/>"; } if (txtPassword.Text.Trim() == "") { strErrorMessage += "- Enter Password <br/>"; } if (txtReTypePassword.Text.Trim() == "") { strErrorMessage += "- Re-type Password <br/>"; } if (txtPassword.Text.Trim() != txtReTypePassword.Text.Trim()) { strErrorMessage += "- Password & Re-type Password must be Same.<br/>"; } } if (strErrorMessage.Trim() != "") { lblErrorMessage.Text = strErrorMessage; return; } else { lblErrorMessage.Text = ""; } #endregion server side validation #region Collect Form Data DoctorENT entDoctor = new DoctorENT(); String strLogicalPath = "~/UploadedData/Images/Doctors/"; String strPhysicalPath = ""; if (txtDoctorName.Text.Trim() != "") { entDoctor.DoctorName = txtDoctorName.Text.Trim(); } if (txtExperince.Text.Trim() != "") { entDoctor.Experince = Convert.ToInt32(txtExperince.Text.ToString().Trim()); } if (ddlDepartment.SelectedIndex > 0) { entDoctor.DepartmentID = Convert.ToInt32(ddlDepartment.SelectedValue.ToString().Trim()); } if (fuDoctorImage.HasFile) { strPhysicalPath = Server.MapPath(strLogicalPath) + fuDoctorImage.FileName; if (File.Exists(strPhysicalPath)) { File.Delete(strPhysicalPath); } fuDoctorImage.SaveAs(strPhysicalPath); entDoctor.DoctorImage = strLogicalPath + fuDoctorImage.FileName; } else { entDoctor.DoctorImage = "~/UploadedData/Images/Doctors/avatar5.png"; } if (txtUserName.Text.Trim() != "") { entDoctor.UserName = txtUserName.Text.Trim(); } if (txtPassword.Text.Trim() != "") { entDoctor.Password = txtPassword.Text.Trim(); } HospitalWiseDoctorENT entHospitalWiseDoctor = new HospitalWiseDoctorENT(); entHospitalWiseDoctor.HospitalID = Convert.ToInt32(Request.QueryString["HospitalID"].ToString().Trim()); #endregion Collect Form Data DoctorBAL balDoctor = new DoctorBAL(); HospitalWiseDoctorBAL balHospitalWiseDoctor = new HospitalWiseDoctorBAL(); if (Request.QueryString["DoctorID"] == null) { if (balDoctor.Insert(entDoctor)) { entHospitalWiseDoctor.DoctorID = entDoctor.DoctorID; if (balHospitalWiseDoctor.Insert(entHospitalWiseDoctor)) { ClientScript.RegisterStartupScript(GetType(), "SweetAlert", "swal({ type: 'success', title: 'Doctor Inserted Successfully', showConfirmButton: false, timer: 2000});", true); ClearControls(); } else { lblErrorMessage.Text = balHospitalWiseDoctor.Message; } } else { lblErrorMessage.Text = balDoctor.Message; } } }