using DevExpress.CodeParser; using DevExpress.XtraEditors.TextEditController.Win32; using DevExpress.XtraGrid; using HStation.Dto; using HStation.Model; using HStation.WinFrmUI.Organize.Core._00_UserControl; using HStation.WinFrmUI.Organize.Core._02_Employee; using Mapster; using Yw.WinFrmUI; using static DevExpress.Xpo.DB.DataStoreLongrunnersWatch; namespace HStation.WinFrmUI.Organize { public partial class EmployeeMgrMainPanel : DocumentPage { public EmployeeMgrMainPanel() { InitializeComponent(); DateChanged(); //ShowEmloyee(); } List _AllEmployee = new List(); private void DateChanged() { HStation.Service.EmployeeMain _service = new(); _AllEmployee.Clear(); var _All = _service.GetAll(); List _AllDateSource = _All.Adapt, List>(); foreach (EmployeeViewModel emp in _AllDateSource) { emp.StaffStatusLabel = emp.StaffStatus == 0 ? "离职" : "在职"; emp.RequirePasswordResetLabel = emp.RequirePasswordReset == 0 ? "否" : "是"; if (String.IsNullOrEmpty(emp.LastName)) { emp.LastName = "暂无"; } _AllEmployee.Add(emp); } employeeViewModelBindingSource.DataSource = _AllEmployee; this.employeeViewModelBindingSource.ResetBindings(false); } //public void ShowEmloyee() //{ // List all = _service.GetAll(); // employeeViewModelBindingSource.DataSource = all; //} //添加 private async void BtnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var dlg = new AddEmployeeDlg(); dlg.ShowDialog(); if (dlg.GetAddSuccessfully() != true) { return; } var bll = new BLL.EmployeeMain(); var NewAddemployeeDate = await bll.GetByID(dlg.GetNewAddEmloyeeId()); EmployeeViewModel _NewAddemployeeDate = NewAddemployeeDate.Adapt(); _NewAddemployeeDate.StaffStatusLabel = _NewAddemployeeDate.StaffStatus == 0 ? "离职" : "在职"; _NewAddemployeeDate.RequirePasswordResetLabel = _NewAddemployeeDate.RequirePasswordReset == 0 ? "否" : "是"; _AllEmployee.Add(_NewAddemployeeDate); this.employeeViewModelBindingSource.ResetBindings(false); } //编辑 private void barBtnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var dlg = new UpdateEmployeeDlg(); var currentVm = this.gridView1.GetCurrentViewModel(_AllEmployee); if (currentVm == null) { MessageBoxHelper.ShowWarning("请选择数据行"); return; } dlg.SetDate(currentVm.ID); dlg.ShowDialog(); DateChanged(); this.employeeViewModelBindingSource.ResetBindings(false); } //删除 private async void BtnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var bll = new BLL.EmployeeMain(); var currentVm = this.gridView1.GetCurrentViewModel(_AllEmployee); if (currentVm == null) { MessageBox.Show("请选择数据行!"); } else { if (MessageBox.Show("确认删除员工" + currentVm.ID + "吗?", "删除", MessageBoxButtons.OKCancel) == DialogResult.Cancel) { return; } if (await bll.DeleteByID(currentVm.ID)) { _AllEmployee.Remove(currentVm); this.employeeViewModelBindingSource.ResetBindings(false); MessageBox.Show("删除成功!"); } } } } }