1
yhj
2024-07-24 5e5d945e91568b973faa27d8ab0bcef99fc4a6c5
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
#region
 
using System;
using System.Data;
using CSFrameworkV5.Business.BLL_Permission;
using CSFrameworkV5.Common;
using CSFrameworkV5.Core;
using DevExpress.XtraGrid.Views.Grid;
 
#endregion
 
namespace CSFrameworkV5.Library.PermissionForms
{
    /// <summary>
    ///     角色定义的修改窗体。
    /// </summary>
    public partial class frmEditorRole : frmEditorBase
    {
        private DataTable _RoleData;
        private UpdateType _UpdateType = UpdateType.None;
        private GridView _View;
 
        private bool Changed;
 
        public frmEditorRole()
        {
            InitializeComponent();
        }
 
        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }
 
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (!ValidateInput()) return;
 
            DataRow current = null;
 
            if (_UpdateType == UpdateType.Add)
            {
                current = _RoleData.NewRow();
                _RoleData.Rows.Add(current);
            }
 
            if (_UpdateType == UpdateType.Modify)
                current = _View.GetDataRow(_View.FocusedRowHandle);
 
            if (current != null)
            {
                current["RoleID"] = txtRoleID.Text;
                current["RoleName"] = txtRoleName.Text;
 
                Changed = true;
            }
 
            Close();
        }
 
        public static bool Execute(DataTable roleData, UpdateType updateType,
            GridView view)
        {
            var form = new frmEditorRole();
            form._RoleData = roleData;
            form._View = view;
            form.InitEditor(updateType);
            form.ShowDialog();
            return form.Changed;
        }
 
        private void InitEditor(UpdateType updateType)
        {
            _UpdateType = updateType;
            var dr = _View.GetDataRow(_View.FocusedRowHandle);
 
            //新增菜单
            if (UpdateType.Add == updateType)
            {
            }
            else
            {
                txtRoleID.Text = ConvertEx.ToString(dr["RoleID"]);
                txtRoleName.Text = ConvertEx.ToString(dr["RoleName"]);
 
                txtRoleID.Enabled = false;
            }
 
            btnOK.Enabled = updateType == UpdateType.Add ||
                            UpdateType.Modify == updateType;
            btnCancel.Enabled = btnOK.Enabled;
        }
 
        private bool ValidateInput()
        {
            if (txtRoleID.Text == "")
            {
                Msg.Warning("角号编号不能为空!");
                txtRoleID.Focus();
                return false;
            }
 
            if (txtRoleName.Text == "")
            {
                Msg.Warning("角号名称不能为空!");
                txtRoleName.Focus();
                return false;
            }
 
            if (RoleActionsView.IsExistsInCache(_RoleData, txtRoleID.Text,
                    "RoleID", _UpdateType))
            {
                Msg.Warning("角号编号已经存在!");
                txtRoleID.Focus();
                return false;
            }
 
            return true;
        }
    }
}