lixiaojun
2025-01-13 1c30ee4068eb5dba3c6b9a4987b98034f2a622d0
WinFrmUI/HStation.WinFrmUI.Auth.Core/01-Role/RoleMainMgrPanel.cs
@@ -1,39 +1,104 @@
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Yw.WinFrmUI;
using Yw.WinFrmUI;
namespace HStation.WinFrmUI.Auth.Core._01_Role
namespace HStation.WinFrmUI.Auth
{
    public partial class RoleMainMgrPanel : DocumentPage
    {
    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();
            dlg.ShowDialog();
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            GetData();
        }
        //修改角色
        private void RoleEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var dlg = new UpdateRoleDlg();
            dlg.ShowDialog();
            var SelectData = this.gridView1.GetCurrentViewModel(RoleData);
            if (SelectData == null)
            {
                MessageBox.Show("请选择数据行!");
                return;
            }
            dlg.IncomingData(SelectData);
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            GetData();
        }
        //删除角色
        private void RoleDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        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);
        }
    }
}