ningshuxia
57 分钟以前 71c12ff40d58c3dbdde6867396dd99224e57fc32
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
using Yw.WinFrmUI;
 
namespace HStation.WinFrmUI.Auth
{
    public partial class RoleMainMgrPanel : DocumentPage
    {
        public RoleMainMgrPanel()
        {
            InitializeComponent();
            GetData();
        }
        string error;
        List<Yw.Vmo.Role> RoleData = new List<Yw.Vmo.Role>();
        Yw.BLL.Role _service = new Yw.BLL.Role();
        public async void GetData()
        {
            this.gridControl.DataSource = null;
            var DataList = await _service.GetAll();
            RoleData.Clear();
            foreach (var Data in DataList)
            {
                RoleData.Add(Data);
            }
            this.gridControl.DataSource = RoleData;
 
            //showRoleList.SetCorprationName(RoleData);
            //Yw.BLL.Role.ReferenceEquals
            //var Datalist = await Yw.BLLFactory<string>.Instance.GetAll();
        }
 
        //添加角色
        private void RoleAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var dlg = new AddRoleDlg();
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            GetData();
        }
        //修改角色
        private void RoleEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var dlg = new UpdateRoleDlg();
            var SelectData = this.gridView1.GetCurrentViewModel(RoleData);
            if (SelectData == null)
            {
                MessageBox.Show("请选择数据行!");
                return;
            }
            dlg.IncomingData(SelectData);
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            GetData();
        }
        //删除角色
        private async void RoleDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var SelectData = this.gridView1.GetCurrentViewModel(RoleData);
            if (SelectData == null)
            {
                MessageBox.Show("请选择数据行!");
                return;
            }
            var result = MessageBox.Show("确定删除这个角色吗?", "确认操作", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (result == DialogResult.OK)
            {
 
                if (!await _service.DeleteByID(SelectData.ID))
                {
                    MessageBox.Show("删除失败!");
                    return;
                }
                RoleData.Remove(SelectData);
                this.gridControl.DataSource = null;
                this.gridControl.DataSource = RoleData;
                MessageBox.Show("删除成功!");
            }
 
 
        }
 
        private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
        {
            if (e.Column == colUseStatus)
            {
                var role = e.Row as Yw.Vmo.Role;
                if (role == null)
                {
                    return;
                }
                e.Value = role.UseStatus == Yw.Vmo.eUseStatus.Disable ? "禁用" : "启用";
            }
        }
 
        private void showRoleList_Click(object sender, EventArgs e)
        {
            error = "";
            showRoleList.GetCorprationName(out error);
        }
    }
}