using DevExpress.CodeParser; using DevExpress.XtraEditors.TextEditController.Win32; using DevExpress.XtraGrid; using HStation.Vmo; 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(); DateShow(); //ShowEmloyee(); } List _AllEmployee = new List(); private async void DateShow() { HStation.BLL.EmployeeMain _service = new(); _AllEmployee.Clear(); var _All = await _service.GetAll(); foreach (HStation.Vmo.EmployeeMain emp in _All) { //HStation.WinFrmUI.Organize.EmployeeViewModel All = new HStation.WinFrmUI.Organize.EmployeeViewModel(emp); _AllEmployee.Add(emp); } employeeModelBindingSource.DataSource = _AllEmployee; this.employeeModelBindingSource.ResetBindings(false); } //添加 private void BtnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var dlg = new AddEmployeeDlg(); if (dlg.ShowDialog() != DialogResult.OK) { return; } DateShow(); } //编辑 private void barBtnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var dlg = new UpdateEmployeeDlg(); var currentVm = this.gridView1.GetCurrentViewModel(_AllEmployee); //var a =currentVm.ErpCode; if (currentVm == null) { MessageBoxHelper.ShowWarning("请选择数据行"); return; } dlg.IncomingData(currentVm); if (dlg.ShowDialog() != DialogResult.OK) { return; } DateShow(); } private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e) { if (e.Column == colStaffStatus) { var employee = e.Row as HStation.Vmo.EmployeeMain; if (employee == null) { return; } e.Value = employee.StaffStatus == eJobType.exist ? "在职" : "离职"; } if (e.Column == colRequirePasswordReset) { var employee = e.Row as HStation.Vmo.EmployeeMain; if (employee == null) { return; } e.Value = employee.RequirePasswordReset == 1 ? "是" : "否"; } } //删除 private async void barButtonItemDelEmployee_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var currentVm = this.gridView1.GetCurrentViewModel(_AllEmployee); HStation.BLL.EmployeeMain _service = new(); if (currentVm == null) { MessageBox.Show("请选择数据行!"); return; } if (MessageBox.Show("确认删除这个员工吗?" , "删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) { return; } if (await _service.DeleteByID(currentVm.EmployeeID)) { _AllEmployee.Remove(currentVm); this.employeeModelBindingSource.ResetBindings(false); MessageBox.Show("删除成功!"); } } } }