From 4f4b091c78009266173790cbb87c9dde53e686f5 Mon Sep 17 00:00:00 2001 From: wyf Date: Fri, 18 Apr 2025 04:02:51 +0000 Subject: [PATCH] SVN r497 SVN-Revision: r497 --- .../Model/MenuStrip/BandedGridMenuStrip.cs | 98 ++++-------- .../Model/MenuStrip/GridViewMenuStrip.cs | 149 +++++++----------- .../Model/MenuStrip/TreeGridViewMenuStrip.cs | 63 ++------ 3 files changed, 102 insertions(+), 208 deletions(-) diff --git a/插件库/Lskj.Control/Model/MenuStrip/BandedGridMenuStrip.cs b/插件库/Lskj.Control/Model/MenuStrip/BandedGridMenuStrip.cs index 944f27d..bb54e5e 100644 --- a/插件库/Lskj.Control/Model/MenuStrip/BandedGridMenuStrip.cs +++ b/插件库/Lskj.Control/Model/MenuStrip/BandedGridMenuStrip.cs @@ -91,50 +91,39 @@ namespace Lskj.Control.Model.MenuStrip GridRightMenuModel model = cms.Tag as GridRightMenuModel; if (model != null) { - if (model.PrivilegeOper.Length > 1 && !model.PrivilegeOper.Contains(ERPInfo.Instance.UserName + ",")) + if (!string.IsNullOrWhiteSpace(model.MenuCond)) { - if (model.ForbiddenDisplay) + try { - cms.Visible = false; + string cond = string.Empty; + if (this._control != null) + cond = _control.ReplaceParentControlValue(model.MenuCond); + cond = ReplaceHelper.ReplaceRowParam(mSelectRow, model.MenuCond); + if (this._gridView != null) + { + GridCell[] cells = this._gridView.GetSelectedCells(); + if (cells != null && cells.Length > 0 && cond.Contains("{COLUMN_")) + { + GridCell cell = cells[0]; + DataRow focusedRow = this.BaseGridView.GetFocusedDataRow(); + string colValue = focusedRow == null || !focusedRow.Table.Columns.Contains(cell.Column.Name) ? "" : focusedRow[cell.Column.Name] + ""; + cond = cond.ReplaceColumnParam(cell.Column.Name, cell.Column.Caption, colValue); + } + } + if (ControlObj != null) + cond = ControlObj.ReplaceParentControlValue(cond); + //cms.Enabled = ReplaceHelper.EvalCond(cond); + if (model.ForbiddenDisplay) + { + cms.Visible = ValidateCond(cond, null); ; + } + cms.Enabled = ValidateCond(cond, null); ; } - cms.Enabled = false; - } - else - { - if (!string.IsNullOrWhiteSpace(model.MenuCond)) + catch (Exception ex) { - try - { - string cond = string.Empty; - if (this._control != null) - cond = _control.ReplaceParentControlValue(model.MenuCond); - cond = ReplaceHelper.ReplaceRowParam(mSelectRow, model.MenuCond); - if (this._gridView != null) - { - GridCell[] cells = this._gridView.GetSelectedCells(); - if (cells != null && cells.Length > 0 && cond.Contains("{COLUMN_")) - { - GridCell cell = cells[0]; - DataRow focusedRow = this.BaseGridView.GetFocusedDataRow(); - string colValue = focusedRow == null || !focusedRow.Table.Columns.Contains(cell.Column.Name) ? "" : focusedRow[cell.Column.Name] + ""; - cond = cond.ReplaceColumnParam(cell.Column.Name, cell.Column.Caption, colValue); - } - } - if (ControlObj != null) - cond = ControlObj.ReplaceParentControlValue(cond); - //cms.Enabled = ReplaceHelper.EvalCond(cond); - if (model.ForbiddenDisplay) - { - cms.Visible = ValidateCond(cond, null); ; - } - cms.Enabled = ValidateCond(cond, null); ; - } - catch (Exception ex) - { - string Message = ErrorMessage.PromptErrorMessage(ex); - MessageUtil.Show(ResourceKeys.SetRightMenuCondFault + "\r\n" + Message); - break; - } + string Message = ErrorMessage.PromptErrorMessage(ex); + MessageUtil.Show(ResourceKeys.SetRightMenuCondFault + "\r\n" + Message); + break; } } } @@ -157,31 +146,4 @@ namespace Lskj.Control.Model.MenuStrip this._gridView.ClearSelection(); this._gridView.SelectRowHandler(this._oldRowHandler); } - protected override List HandleRightMenuParams(List paramList, DataRow rowData, DataRow[] rowDatas = null, int actionType = 0) - { - List handleParamList = base.HandleRightMenuParams(paramList, rowData, rowDatas, actionType); - - foreach (string item in handleParamList) - { - if (item.StartsWith("{")) - { - string field = item.Replace("{", "").Replace("}", ""); - if ("COLUMN_NAME".Equals(field)) - { - handleParamList.Add(this._gridView.FocusedColumn.FieldName); - } - else if ("COLUMN_TITLE".Equals(field)) - { - - handleParamList.Add(this._gridView.FocusedColumn.GetTextCaption()); - } - else - { - handleParamList.Add(rowData[field] + ""); - } - } - } - return handleParamList; - } - } -} + protected override List HandleRightMenuParams(List para \ No newline at end of file diff --git a/插件库/Lskj.Control/Model/MenuStrip/GridViewMenuStrip.cs b/插件库/Lskj.Control/Model/MenuStrip/GridViewMenuStrip.cs index 6012802..741e3ae 100644 --- a/插件库/Lskj.Control/Model/MenuStrip/GridViewMenuStrip.cs +++ b/插件库/Lskj.Control/Model/MenuStrip/GridViewMenuStrip.cs @@ -90,88 +90,84 @@ namespace Lskj.Control.Model cmsMenu.Items.AddRange(mQQArray.ToArray()); cmsMenu.Items.AddRange(mBrowerArray.ToArray()); - // 判断右键菜单是否可用 + Dictionary cmsModelDic = new Dictionary(); + List roleNamesList = new List(); foreach (ToolStripItem cms in cmsMenu.Items) { GridRightMenuModel model = cms.Tag as GridRightMenuModel; + cmsModelDic[cms] = model; + roleNamesList.Add(model.PrivilegeOper); + } + // 判断右键菜单是否可用 + foreach (ToolStripItem cms in cmsMenu.Items) + { + GridRightMenuModel model = cmsModelDic.ContainsKey(cms) ? cmsModelDic[cms] : cms.Tag as GridRightMenuModel; if (model != null) { - // !model.PrivilegeOper.Contains(ERPInfo.Instance.UserName + "," 2024-2-23换成下面的判断 - if (model.PrivilegeOper.Length > 1 && !model.PrivilegeOper.Split(',').Contains(ERPInfo.Instance.UserName)) + if (!string.IsNullOrWhiteSpace(model.MenuCond)) { - if (model.ForbiddenDisplay) + try { - cms.Visible = false; - } - cms.Enabled = false; - } - else - { - if (!string.IsNullOrWhiteSpace(model.MenuCond)) - { - try + bool condResult = false; + StringBuilder condBuilder = new StringBuilder(); + StringBuilder sqlCondBuilder = new StringBuilder(); + GridCell[] cells = this._gridView.GetSelectedCells(); + DataRow focusedRow = this.BaseGridView.GetFocusedDataRow(); + foreach (int itemIndex in mSelectRows) { - bool condResult = false; - StringBuilder condBuilder = new StringBuilder(); - StringBuilder sqlCondBuilder = new StringBuilder(); - GridCell[] cells = this._gridView.GetSelectedCells(); - DataRow focusedRow = this.BaseGridView.GetFocusedDataRow(); - foreach (int itemIndex in mSelectRows) + DataRow selectRow = this._gridView.GetDataRow(itemIndex); + string cond = string.Empty; + if (this._control != null) { - DataRow selectRow = this._gridView.GetDataRow(itemIndex); - string cond = string.Empty; - if (this._control != null) + cond = _control.ReplaceParentControlValue(model.MenuCond); + } + cond = ReplaceHelper.ReplaceRowParam(selectRow, model.MenuCond); + if (this._gridView != null) + { + if (cells != null && cells.Length > 0 && cond.Contains("{COLUMN_")) { - cond = _control.ReplaceParentControlValue(model.MenuCond); - } - cond = ReplaceHelper.ReplaceRowParam(selectRow, model.MenuCond); - if (this._gridView != null) - { - if (cells != null && cells.Length > 0 && cond.Contains("{COLUMN_")) - { - GridCell cell = cells[0]; - string colValue = focusedRow == null || !focusedRow.Table.Columns.Contains(cell.Column.Name) ? "" : focusedRow[cell.Column.Name] + ""; - cond = cond.ReplaceColumnParam(cell.Column.Name, cell.Column.Caption, colValue); - } - } - if (ControlObj != null) - { - cond = ControlObj.ReplaceParentControlValue(cond); - } - if (cond.StartsWith("@")) - { - sqlCondBuilder.Append($"({cond.TrimStart('@')}) = '1' and "); - } - else - { - condBuilder.Append($"({cond}) and "); + GridCell cell = cells[0]; + string colValue = focusedRow == null || !focusedRow.Table.Columns.Contains(cell.Column.Name) ? "" : focusedRow[cell.Column.Name] + ""; + cond = cond.ReplaceColumnParam(cell.Column.Name, cell.Column.Caption, colValue); } } - string condStr = ""; - if (model.MenuCond.StartsWith("@")) + if (ControlObj != null) { - condStr = $"@if({sqlCondBuilder.ToString().TrimEnd().TrimEnd('d', 'n', 'a')}) begin select '1' end else begin select '0' end"; + cond = ControlObj.ReplaceParentControlValue(cond); + } + if (cond.StartsWith("@")) + { + sqlCondBuilder.Append($"({cond.TrimStart('@')}) = '1' and "); } else { - condStr = condBuilder.ToString().TrimEnd().TrimEnd('d', 'n', 'a'); + condBuilder.Append($"({cond}) and "); } - condResult = ValidateCond(condStr, null); - //if (!condResult) break; - //cms.Enabled = ReplaceHelper.EvalCond(cond); - if (model.ForbiddenDisplay) - { - cms.Visible = condResult; - } - cms.Enabled = condResult; } - catch (Exception ex) + string condStr = ""; + if (model.MenuCond.StartsWith("@")) { - string Message = ErrorMessage.PromptErrorMessage(ex); - MessageUtil.Show(ResourceKeys.SetRightMenuCondFault + "\r\n" + Message); - e.Cancel = true; - break; + condStr = $"@if({sqlCondBuilder.ToString().TrimEnd().TrimEnd('d', 'n', 'a')}) begin select '1' end else begin select '0' end"; } + else + { + condStr = condBuilder.ToString().TrimEnd().TrimEnd('d', 'n', 'a'); + } + condResult = ValidateCond(condStr, null); + //if (!condResult) break; + //cms.Enabled = ReplaceHelper.EvalCond(cond); + if (model.ForbiddenDisplay) + { + cms.Visible = condResult; + } + cms.Enabled = condResult; + } + catch (Exception ex) + { + string Message = ErrorMessage.PromptErrorMessage(ex); + MessageUtil.Show(ResourceKeys.SetRightMenuCondFault + "\r\n" + Message); + e.Cancel = true; + break; } } } @@ -227,31 +223,4 @@ namespace Lskj.Control.Model this._gridView.SelectRowHandler(this._oldRowHandler); } } - protected override List HandleRightMenuParams(List paramList, DataRow rowData, DataRow[] rowDatas = null, int actionType = 0) - { - List handleParamList = base.HandleRightMenuParams(paramList, rowData, rowDatas, actionType); - - foreach (string item in handleParamList) - { - if (item.StartsWith("{")) - { - string field = item.Replace("{", "").Replace("}", ""); - if ("COLUMN_NAME".Equals(field)) - { - handleParamList.Add(this._gridView.FocusedColumn.FieldName); - } - else if ("COLUMN_TITLE".Equals(field)) - { - - handleParamList.Add(this._gridView.FocusedColumn.GetTextCaption()); - } - else - { - handleParamList.Add(rowData[field] + ""); - } - } - } - return handleParamList; - } - } -} + protected override List HandleRightMenuParams(List para \ No newline at end of file diff --git a/插件库/Lskj.Control/Model/MenuStrip/TreeGridViewMenuStrip.cs b/插件库/Lskj.Control/Model/MenuStrip/TreeGridViewMenuStrip.cs index 9e217fb..a379b93 100644 --- a/插件库/Lskj.Control/Model/MenuStrip/TreeGridViewMenuStrip.cs +++ b/插件库/Lskj.Control/Model/MenuStrip/TreeGridViewMenuStrip.cs @@ -123,57 +123,20 @@ namespace Lskj.Control.Model.MenuStrip GridRightMenuModel model = cms.Tag as GridRightMenuModel; if (model != null) { - if (model.PrivilegeOper.Length > 1 && !model.PrivilegeOper.Contains(ERPInfo.Instance.UserName + ",")) + if (!string.IsNullOrWhiteSpace(model.MenuCond)) { - if (model.ForbiddenDisplay) + try { - cms.Visible = false; - } - cms.Enabled = false; - } - else - { - if (!string.IsNullOrWhiteSpace(model.MenuCond)) - { - try + string cond = string.Empty; + if (this._control != null) + cond = _control.ReplaceParentControlValue(model.MenuCond); + cond = ReplaceHelper.ReplaceRowParam(mSelectRow, model.MenuCond); + if (this._treeView != null) { - string cond = string.Empty; - if (this._control != null) - cond = _control.ReplaceParentControlValue(model.MenuCond); - cond = ReplaceHelper.ReplaceRowParam(mSelectRow, model.MenuCond); - if (this._treeView != null) + List cells = this._treeView.GetSelectedCells(); + if (cells != null && cells.Count > 0 && cond.Contains("{COLUMN_")) { - List cells = this._treeView.GetSelectedCells(); - if (cells != null && cells.Count > 0 && cond.Contains("{COLUMN_")) - { - TreeListCell cell = cells[0]; - DataRow focusedRow = this.BaseGridView.GetFocusedDataRow(); - string colValue = focusedRow == null || !focusedRow.Table.Columns.Contains(cell.Column.Name) ? "" : focusedRow[cell.Column.Name] + ""; - cond = cond.ReplaceColumnParam(cell.Column.Name, cell.Column.Caption, colValue); - } - } - if (ControlObj != null) - cond = ControlObj.ReplaceParentControlValue(cond); - //cms.Enabled = ReplaceHelper.EvalCond(cond); - - if (model.ForbiddenDisplay) - { - cms.Visible = ValidateCond(cond, null); - } - - cms.Enabled = ValidateCond(cond, null); ; - - } - catch (Exception ex) - { - string Message = ErrorMessage.PromptErrorMessage(ex); - MessageUtil.Show(ResourceKeys.SetRightMenuCondFault + "\r\n" + Message); - break; - } - } - } - } - } - } - } -} + TreeListCell cell = cells[0]; + DataRow focusedRow = this.BaseGridView.GetFocusedDataRow(); + string colValue = focusedRow == null || !focusedRow.Table.Columns.Contains(cell.Column.Name) ? "" : focusedRow[cell.Column.Name] + ""; + cond = cond.ReplaceColumnParam( \ No newline at end of file