Exemplo n.º 1
0
 private void saveButton_Click(object sender, EventArgs e)
 {
     Department department=new Department();
     department.Name = departmentsNameTextBox.Text;
     DepartmentManager departmentManager=new DepartmentManager();
     if (departmentManager.Save(department))
     {
         Close();
         MessageBox.Show("Department Successfully Added");
     }
 }
Exemplo n.º 2
0
 public bool Save(Department department)
 {
     if (department.Name == "")
     {
         MessageBox.Show("Name cannot be empty");
         return false;
     }
     else
     {
         return departmentGateway.Save(department);
     }
 }
Exemplo n.º 3
0
 public bool Save(Department department)
 {
     string connectionString = ConfigurationManager.ConnectionStrings["HospitalConnectionString"].ConnectionString;
     SqlConnection sqlConnection = new SqlConnection(connectionString);
     string query = "INSERT INTO DepartmentTable (Name) VALUES('" + department.Name + "')";
     SqlCommand sqlCommand = new SqlCommand(query, sqlConnection);
     sqlConnection.Open();
     int row = sqlCommand.ExecuteNonQuery();
     sqlConnection.Close();
     if (row == 1)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Exemplo n.º 4
0
 public List<Department> GetDepartments()
 {
     string connectionString = ConfigurationManager.ConnectionStrings["HospitalConnectionString"].ConnectionString;
     SqlConnection sqlConnection = new SqlConnection(connectionString);
     string query = "SELECT * FROM DepartmentTable";
     SqlCommand sqlCommand = new SqlCommand(query, sqlConnection);
     sqlConnection.Open();
     SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
     List<Department> departmentList = new List<Department>();
     while (sqlDataReader.Read())
     {
         Department department = new Department();
         department.Id = int.Parse(sqlDataReader["Id"].ToString());
         department.Name = sqlDataReader["Name"].ToString();
         departmentList.Add(department);
     }
     return departmentList;
 }