#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 frmEditorModule : frmEditorBase { private DataTable _ModuleData; private UpdateType _UpdateType = UpdateType.None; private GridView _View; private bool Changed; public frmEditorModule() { 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 = _ModuleData.NewRow(); _ModuleData.Rows.Add(current); } if (_UpdateType == UpdateType.Modify) current = _View.GetDataRow(_View.FocusedRowHandle); if (current != null) { current[sys_ModuleFileList.ModuleID] = txtCode.Text; current[sys_ModuleFileList.ModuleName] = txtName.Text; Changed = true; } Close(); } public static bool Execute(DataTable moduleData, UpdateType updateType, GridView view) { var form = new frmEditorModule(); form._ModuleData = moduleData; 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 { txtCode.Text = ConvertEx.ToString(dr[sys_ModuleFileList.ModuleID]); txtName.Text = ConvertEx.ToString(dr[sys_ModuleFileList.ModuleName]); txtCode.Enabled = false; } btnOK.Enabled = updateType == UpdateType.Add || UpdateType.Modify == updateType; btnCancel.Enabled = btnOK.Enabled; } private bool ValidateInput() { if (txtCode.Text == "") { Msg.Warning("编号不能为空!"); txtCode.Focus(); return false; } if (txtName.Text == "") { Msg.Warning("名称不能为空!"); txtName.Focus(); return false; } if (RoleActionsView.IsExistsInCache(_ModuleData, txtCode.Text, sys_ModuleFileList.ModuleID, _UpdateType)) { Msg.Warning("编号已经存在!"); txtCode.Focus(); return false; } return true; } } }