#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 { /// /// 角色定义的修改窗体。 /// 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; } } }