#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 { /// /// 功能点编辑窗体 /// 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; } } }