1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
public class AccountInfo : ObservableObject { private int _no; private bool _isChecked; private string? _username; private string? _createDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); private string? _role; private bool _enable; private string? _phone; private string? _archivesPath; private List<Permission> _permission = new List<Permission>() { new Permission(false, "测试项1","测试项1"), new Permission(false, "测试项2","测试项2"), new Permission(false, "测试项3","测试项3"), new Permission(false, "测试项4","测试项4"), new Permission(false, "测试项5","测试项5") }; private List<string> _roles = new List<string>() { "系统管理员", "角色1" }; [ZFormTextColumn("序 号", Index = 1, IsReadOnlyColumn = true, IsHideFormItem = true, Width = 30, WidthUnit = DataGridLengthUnitType.Pixel)] public int NO { get => _no; set => SetProperty(ref _no, value); } [ZFormCheckColumn("选 择", Index = 0, IsHideFormItem = true, Width = 30, WidthUnit = DataGridLengthUnitType.Pixel)] public bool IsChecked { get => _isChecked; set => SetProperty(ref _isChecked, value); } [ZFormTextColumn("用户名", Index = 1, IsHideFormColumn = false, IsReadOnlyColumn = false, IsHideFormItem = false, IsReadOnlyItem = false, IsSearchProperty = true, MemberPath = null, Width = 100, WidthUnit = DataGridLengthUnitType.Pixel)] public virtual string? Username { get => _username; set => SetProperty(ref _username, value); } [ZFormDateColumn("创建日期", Index = 2, Width = 200, WidthUnit = DataGridLengthUnitType.Pixel)] public string? CreateDate { get => _createDate; set => SetProperty(ref _createDate, value); } [ZFormComboColumn("角 色", Index = 3, IsSearchProperty = true, ItemsSourceProperty = nameof(Roles), Width = 100, WidthUnit = DataGridLengthUnitType.Pixel)] public string? Role { get => _role; set => SetProperty(ref _role, value); } public List<string> Roles { get => _roles; set => _roles = value; } [ZFormCheckColumn("状 态", Index = 3, Width = 30, WidthUnit = DataGridLengthUnitType.Pixel)] public bool Enable { get => _enable; set => SetProperty(ref _enable, value); } [ZFormTextColumn("联系电话", Index = 4, IsSearchProperty = true, Width = 100, WidthUnit = DataGridLengthUnitType.Pixel)] public string? Phone { get => _phone; set => SetProperty(ref _phone, value); } [ZFormTextButtonColumn("档案路径", Index = 5, ButtonContent = "更 改", RelayCommandName = nameof(CommandModifyArchivesPath), Width = 200, WidthUnit = DataGridLengthUnitType.Pixel)] public string? ArchivesPath { get => _archivesPath; set => SetProperty(ref _archivesPath, value); } public RelayCommand<AccountInfo> CommandModifyArchivesPath => new RelayCommand<AccountInfo>(ModifyArchivesPath); private void ModifyArchivesPath(AccountInfo? accountInfo) { if (accountInfo == null) { return; } OpenFileDialog fileDialog = new OpenFileDialog(); bool? dr = fileDialog.ShowDialog(); if (dr == false) { return; } accountInfo.ArchivesPath = fileDialog.FileName; } [ZFormMultiCheckColumn("权 限", "IsChecked", "Name", IsSearchProperty = true, WidthUnit = DataGridLengthUnitType.Auto)] public List<Permission> Permission { get => _permission; set => SetProperty(ref _permission, value); } [ZFormOperColumnButton("查看", Index = 0, ButtonStyle = ZFormButtonStyle.InfoButton)] public RelayCommand<Tuple<object?, IList?>> CommandViewItem => new RelayCommand<Tuple<object?, IList?>>(ViewItem); private void ViewItem(Tuple<object?, IList?>? param) { if (param == null) { return; } AccountInfo? accountInfo = param.Item1 as AccountInfo; if (accountInfo == null) { return; } string msg = FormItemUtils.Print(accountInfo); MessageBox.Show(msg, "属性信息", MessageBoxButton.OK, MessageBoxImage.Information); } [ZFormOperColumnButton("更新", Index = 0, ButtonStyle = ZFormButtonStyle.WarnButton)] public RelayCommand<Tuple<object?, IList?>> CommandUpdateItem => new RelayCommand<Tuple<object?, IList?>>(UpdateItem); private void UpdateItem(Tuple<object?, IList?>? param) { MessageBox.Show("更新"); } [ZFormOperColumnButton("导出", Index = 0, ButtonStyle = ZFormButtonStyle.SuccessButton)] public RelayCommand<Tuple<object?, IList?>> CommandExportItem => new RelayCommand<Tuple<object?, IList?>>(ExportItem); private void ExportItem(Tuple<object?, IList?>? param) { MessageBox.Show("导出"); } [ZFormOperColumnButton("删 除", Index = 1, ButtonStyle = ZFormButtonStyle.ErrorButton)] public RelayCommand<Tuple<object?, IList?>> CommandDeleteItem => new RelayCommand<Tuple<object?, IList?>>(DeleteItem); private void DeleteItem(Tuple<object?, IList?>? param) { if (param == null) { return; } AccountInfo? accountInfo = param.Item1 as AccountInfo; IList? accountInfos = param.Item2 as IList; MessageBoxResult messageBoxResult = MessageBox.Show("确认删除?!", "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (messageBoxResult != MessageBoxResult.Yes) { return; } accountInfos?.Remove(accountInfo); } [ZFormToolButton("全 选", Index = 0, Dock = Dock.Right, ButtonStyle = ZFormButtonStyle.DefaultButton, Location = ButtonLocation.Bottom)] public RelayCommand<IList?> CommandCheckTotalItem => new RelayCommand<IList?>(CheckTotalItem); private void CheckTotalItem(IList? items) { if (items == null) return; foreach (AccountInfo? item in items) { if (item == null) continue; item.IsChecked = true; } } [ZFormToolButton("全不选", Index = 1, Location = ButtonLocation.Bottom)] public RelayCommand<IList?> CommandUncheckTotalItem => new RelayCommand<IList?>(UncheckTotalItem); private void UncheckTotalItem(IList? items) { if (items == null) return; foreach (AccountInfo? item in items) { if (item == null) continue; item.IsChecked = false; } } [ZFormToolButton("添 加", Index = 0, ButtonStyle = ZFormButtonStyle.InfoButton)] public RelayCommand<IList?> CommandAddItem => new RelayCommand<IList?>(AddItem); private async void AddItem(IList? items) { if (items == null) return; AccountInfo accountInfo = new AccountInfo(); await Task.Run(() => { Application.Current.Dispatcher.Invoke(() => { ZFormDialog zFormDialog = new ZFormDialog(accountInfo); zFormDialog.Title = "Add"; bool? dr = zFormDialog.ShowDialog(); if (dr == false) { return; } }); }); items.Add(accountInfo); accountInfo.NO = items.IndexOf(accountInfo) + 1; } [ZFormToolButton("批量删除", Index = 1, ButtonStyle = ZFormButtonStyle.ErrorButton)] public RelayCommand<IList?> CommandBatchDeleteItem => new RelayCommand<IList?>(BatchDeleteItem); private void BatchDeleteItem(IList? items) { if (items == null) return; List<AccountInfo> rm = new List<AccountInfo>(); foreach (AccountInfo accountInfo in items) if (accountInfo?.IsChecked == true) rm.Add(accountInfo); if (rm.Count < 1) return; MessageBoxResult messageBoxResult = MessageBox.Show("确认删除?!", "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (messageBoxResult != MessageBoxResult.Yes) return; foreach (var item in rm) items.Remove(item); } }
|