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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#region
 
using System;
using System.Data;
using CSFrameworkV5.Business.BLL_Permission;
using CSFrameworkV5.Common;
using CSFrameworkV5.Core;
using CSFrameworkV5.Models;
using DevExpress.XtraGrid.Views.Grid;
 
#endregion
 
namespace CSFrameworkV5.Library.PermissionForms
{
    /// <summary>
    ///     功能点编辑窗体
    /// </summary>
    public partial class frmEditorAction : frmEditorBase
    {
        private DataTable _ActionData; //数据源
        private UpdateType _UpdateType = UpdateType.None;
        private GridView _View; //表格对象引用
 
        private bool Changed; //标记是否修改
 
        public frmEditorAction()
        {
            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 = _ActionData.NewRow();
                _ActionData.Rows.Add(current);
            }
 
            if (_UpdateType == UpdateType.Modify)
                current = _View.GetDataRow(_View.FocusedRowHandle);
 
            if (current != null)
            {
                current[tb_MyActions.ActionName] = txtName.Text;
                current[tb_MyActions.ActionValue] = txtValue.Text;
 
                Changed = true;
            }
 
            Close();
        }
 
        public static bool Execute(DataTable actionData, UpdateType updateType,
            GridView view)
        {
            var form = new frmEditorAction();
            form._ActionData = actionData;
            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 //修改
            {
                txtName.Text = ConvertEx.ToString(dr[tb_MyActions.ActionName]);
                txtValue.Text =
                    ConvertEx.ToString(dr[tb_MyActions.ActionValue]);
                txtName.Enabled = false; //名称禁止修改
            }
 
            btnOK.Enabled = updateType == UpdateType.Add ||
                            UpdateType.Modify == updateType;
            btnCancel.Enabled = btnOK.Enabled;
        }
 
        private bool ValidateInput()
        {
            if (txtName.Text == "")
            {
                Msg.Warning("名称不能为空!");
                txtName.Focus();
                return false;
            }
 
            if (txtValue.Text == "")
            {
                Msg.Warning("数值不能为空!");
                txtValue.Focus();
                return false;
            }
 
            var value = 0;
            if (false == int.TryParse(txtValue.Text, out value))
            {
                Msg.Warning("数值不正确,必须是数字!");
                txtValue.Focus();
                return false;
            }
 
            if (RoleActionsView.IsExistsInCache(_ActionData, txtName.Text,
                    tb_MyActions.ActionName, _UpdateType))
            {
                Msg.Warning("名称已经存在!");
                txtName.Focus();
                return false;
            }
 
            if (value > 0 &&
                RoleActionsView.IsExistsInCache(_ActionData, txtValue.Text,
                    tb_MyActions.ActionValue, _UpdateType))
            {
                Msg.Warning("数值已经存在!");
                txtValue.Focus();
                return false;
            }
 
            return true;
        }
    }
}