// 查詢該員工資料並將資料填進UI中 private void SetAllEmplDataToUI() { _employeeController = new EmployeeController(_employeePresentationModel); _employeePresentationModel = _employeeController.SearchDataByEmplID(); try { _newEmplIDTB.Text = _employeePresentationModel.GetEmplID(); _newEmplBirthDP.Value = _employeePresentationModel.GetBirth(); _newEmplMarriedStatCB.SelectedItem = _employeePresentationModel.GetMarriedStatus(); // 1 為未婚 // 0 為已婚 if (_newEmplMarriedStatCB.SelectedIndex == 1) { _newEmplSpouseTB.Text = _employeePresentationModel.GetSpouse(); } else if (_newEmplMarriedStatCB.SelectedIndex == 0) { _newEmplSpouseTB.ReadOnly = true; _newEmplSpouseTB.Text = null; } _newEmplJobStatCB.SelectedItem = _employeePresentationModel.GetJobStatus(); _newEmplMilitaryStatCB.SelectedItem = _employeePresentationModel.GetMilitaryStatus(); _newEmplBloodCB.SelectedItem = _employeePresentationModel.GetBlood(); _newEmplSexCB.SelectedItem = _employeePresentationModel.GetSex(); _newEmplNameTB.Text = _employeePresentationModel.GetName(); _newEmpllSsnTB.Text = _employeePresentationModel.GetSsn(); ; _newEmplAddrTB.Text = _employeePresentationModel.GetAddress(); _newEmplEmerPersonTB.Text = _employeePresentationModel.GetEmerPerson(); _newEmplEmerPhoneTB.Text = _employeePresentationModel.GetEmerPhone(); _newEmplBasicSalaryTB.Text = _employeePresentationModel.GetBasicSalary().ToString(); _newEmplPhoneTB.Text = _employeePresentationModel.GetPhone(); _newEmplDeptCB.SelectedValue = _employeePresentationModel.GetDeptID(); _newEmplPositionCB.SelectedValue = _employeePresentationModel.GetPositionID(); _addEmplLoginPWTB.Text = _employeePresentationModel.GetEmplLoginPassword(); } catch(Exception ex) { Console.WriteLine(ex.Message); MessageBox.Show("系統發生錯誤, 請稍後再嘗試!"); } }
// 建構子 public EmployeeController(EmployeePresentationModel employeePresentationModel) { this._employeeModel.SetEmplID(employeePresentationModel.GetEmplID()); this._employeeModel.SetName(employeePresentationModel.GetName()); this._employeeModel.SetSsn(employeePresentationModel.GetSsn()); this._employeeModel.SetSex(employeePresentationModel.GetSex()); this._employeeModel.SetPhone(employeePresentationModel.GetPhone()); this._employeeModel.SetAddress(employeePresentationModel.GetAddress()); this._employeeModel.SetBlood(employeePresentationModel.GetBlood()); this._employeeModel.SetBirth(employeePresentationModel.GetBirth()); this._employeeModel.SetEmerPerson(employeePresentationModel.GetEmerPerson()); this._employeeModel.SetEmerPhone(employeePresentationModel.GetEmerPhone()); this._employeeModel.SetMilitaryStatus(employeePresentationModel.GetMilitaryStatus()); this._employeeModel.SetJobStatus(employeePresentationModel.GetJobStatus()); this._employeeModel.SetMarriedStatus(employeePresentationModel.GetMarriedStatus()); this._employeeModel.SetSpouse(employeePresentationModel.GetSpouse()); this._employeeModel.SetDeptID(employeePresentationModel.GetDeptID()); this._employeeModel.SetPositoinID(employeePresentationModel.GetPositionID()); this._employeeModel.SetBasicSalary(employeePresentationModel.GetBasicSalary()); this._employeeModel.SetEmplLoginPassword(employeePresentationModel.GetEmplLoginPassword()); }
// 呼叫service 利用員工ID查詢員工資料 public EmployeePresentationModel SearchDataByEmplID() { EmployeePresentationModel emplPresentationModel = new EmployeePresentationModel(); if (this._employeeModel.GetEmplID() == null || this._employeeModel.GetEmplID() == "") MessageBox.Show("請輸入員工ID"); else { _employeeService = new EmployeeService(this._employeeModel); _employeeModel = _employeeService.searchByEmplID(); emplPresentationModel.SetEmplID(_employeeModel.GetEmplID()); emplPresentationModel.SetName(_employeeModel.GetName()); emplPresentationModel.SetSsn(_employeeModel.GetSsn()); emplPresentationModel.SetSex(_employeeModel.GetSex()); emplPresentationModel.SetPhone(_employeeModel.GetPhone()); emplPresentationModel.SetAddress(_employeeModel.GetAddress()); emplPresentationModel.SetBlood(_employeeModel.GetBlood()); emplPresentationModel.SetBirth(_employeeModel.GetBirth()); emplPresentationModel.SetEmerPerson(_employeeModel.GetEmerPerson()); emplPresentationModel.SetEmerPhone(_employeeModel.GetEmerPhone()); emplPresentationModel.SetMilitaryStatus(_employeeModel.GetMilitaryStatus()); emplPresentationModel.SetJobStatus(_employeeModel.GetJobStatus()); emplPresentationModel.SetMarriedStatus(_employeeModel.GetMarriedStatus()); emplPresentationModel.SetSpouse(_employeeModel.GetSpouse()); emplPresentationModel.SetDeptID(_employeeModel.GetDeptID()); emplPresentationModel.SetPositoinID(_employeeModel.GetPositionID()); emplPresentationModel.SetBasicSalary(_employeeModel.GetBasicSalary()); if (_employeeModel.GetName() == null || _employeeModel.GetName() == "") { MessageBox.Show("此員工ID不存在!"); emplPresentationModel.SetEmplID(null); } } return emplPresentationModel; }
// 按下查詢員工按鈕 private void ClickSearchEmplButtom(object sender, EventArgs e) { String emplID = _editEmplIDTB.Text; _employeePresentationModel.SetEmplID(emplID); _employeeController = new EmployeeController(_employeePresentationModel); _employeePresentationModel = _employeeController.SearchDataByEmplID(); if (_employeePresentationModel.GetEmplID() == null || _employeePresentationModel.GetEmplID() == "") return; this.SetAllEmplEditToEnable(); this.ResetSearchEditEmplUI(); }