// 輸入部門ID搜尋部門資料 public DepartmentModel searchByDeptID() { if (this.connectToDB()) { try { DataTable dataset = new DataTable(); String searchString = String.Format("SELECT * FROM department WHERE departmentID = '" + this._deptModel.GetDepartmentID() + "'"); MySqlCommand searchCommand = new MySqlCommand(searchString, myConnection); searchCommand.ExecuteNonQuery(); MySqlDataAdapter adapter = new MySqlDataAdapter(searchCommand); adapter.Fill(dataset); foreach (DataRow searchDr in dataset.Rows) { _deptModel.SetDepartmentName(searchDr["departmentName"].ToString()); _deptModel.SetDepartmentStartTime(System.Convert.ToDateTime(searchDr["departmentStartTime"])); _deptModel.SetDepartmentEndTime(System.Convert.ToDateTime(searchDr["departmentEndTime"])); _deptModel.SetDepartmentManager(searchDr["departmentManager"].ToString()); } } catch (MySqlException ex) { Console.WriteLine("Error " + ex.Number + " : " + ex.Message); } } this.closeConnection(); return(this._deptModel); }
//建構子 public DepartmentController(DepartmentPresentationModel deptPresentationModel) { _deptModel.SetDepartmentID(deptPresentationModel.getDepartmentID()); _deptModel.SetDepartmentName(deptPresentationModel.getDepartmentName()); _deptModel.SetDepartmentStartTime(deptPresentationModel.getDepartmentStartTime()); _deptModel.SetDepartmentEndTime(deptPresentationModel.getDepartmentEndTime()); _deptModel.SetDepartmentManager(deptPresentationModel.getDepartmentManager()); }
public void TestDepartmentName() { _department.SetDepartmentName("testdepName"); Assert.AreEqual("testdepName", _department.GetDepartmentName()); }