protected void saveDoctorButton_Click(object sender, EventArgs e) { Doctor aDoctor = new Doctor(); aDoctor.Name = doctorNameTextBox.Text; aDoctor.Degree = doctorDegreeTextBox.Text; aDoctor.Specialization = doctorSpecializationTextBox.Text; Center aCenter = centerManager.GetCenterIdbyCenterCode(centercode); aDoctor.CenterId = aCenter.Id; messageLabel.Text = doctorManager.SaveDoctor(aDoctor); }
public bool IsThisDoctorNameExists(Doctor aDoctor) { string searchMedicine = "SELECT * FROM tbl_doctor WHERE Name='" + aDoctor.Name + "' AND degree='" + aDoctor.Degree + "' AND specialization='" + aDoctor.Specialization + "'"; sqlConnection.Open(); sqlCommand.CommandText = searchMedicine; SqlDataReader reader = sqlCommand.ExecuteReader(); bool isThisDOctorNameExists = false; while (reader.Read()) { isThisDOctorNameExists = true; } reader.Close(); sqlConnection.Close(); return isThisDOctorNameExists; }
public bool SaveDoctor(Doctor aDoctor) { string saveDoctor = "INSERT INTO tbl_doctor (name,degree,specialization,CenterId) VALUES(@name,@degree,@specialization,@centerId)"; sqlConnection.Open(); sqlCommand.CommandText = saveDoctor; sqlCommand.Parameters.AddWithValue("@name", aDoctor.Name); sqlCommand.Parameters.AddWithValue("@degree", aDoctor.Degree); sqlCommand.Parameters.AddWithValue("@specialization", aDoctor.Specialization); sqlCommand.Parameters.AddWithValue("@centerId", aDoctor.CenterId); int rowAffected = sqlCommand.ExecuteNonQuery(); sqlConnection.Close(); if (rowAffected > 0) { return true; } return false; }
public string SaveDoctor(Doctor aDoctor) { if (doctorGatetway.IsThisDoctorNameExists(aDoctor)) { return "Doctor Name already Saved"; } else { if (doctorGatetway.SaveDoctor(aDoctor)) { return "Successfully Saved"; } else { return "Save failed"; } } }
public List<Doctor> GetAllDoctorByCenterId(int centerId) { string query = "SELECT * FROM tbl_doctor WHERE CenterId ='" + centerId + "' ORDER BY name ASC"; sqlConnection.Open(); sqlCommand.CommandText = query; SqlDataReader reader = sqlCommand.ExecuteReader(); List<Doctor> doctorList = new List<Doctor>(); string name = ""; string specia = ""; while (reader.Read()) { Doctor aDoctor = new Doctor(); aDoctor.Id = (int)reader["id"]; name = reader["name"].ToString(); specia = reader["specialization"].ToString(); aDoctor.Name = name + " (" + specia + ")"; doctorList.Add(aDoctor); } reader.Close(); sqlConnection.Close(); return doctorList; }