SVN r1000

SVN-Revision: r1000
This commit is contained in:
cyf
2025-09-28 06:50:51 +00:00
parent d6739afcd1
commit 533029e001
10 changed files with 354 additions and 112 deletions
+237 -15
View File
@@ -480,23 +480,19 @@ namespace Lskj.Control
}
#region LabPicUrl控件实现事件
//this.gridView.CustomUnboundColumnData += OnGridViewCustomUnboundColumnData;
//this.gridView.DoubleClick += OnShowImageDoubleClick;
//this.gridView.DoubleClick += OnShowImageDoubleClick;
LabPicUrlPreview.Attach(this.gridView); // 必须
LabPicUrlPreview.AttachPreview(this.gridView); // 新增(双击预览)
#endregion
if (SystemInfo.Instance.GroupSpecialMode) this.gridView.EndGrouping += GridView_EndGrouping;
//this.gridView.ShowingEditor += GridView_ShowingEditor;
this.gridView.ShowingEditor += GridView_ShowingEditor;
this.gridView.MouseDown += GridView_MouseDown;
}
@@ -1306,7 +1302,8 @@ namespace Lskj.Control
rightMentTab = BaseModuleImpl.GetBaseGridRightMenus(this.Model.ModuleCode);
}
}
if (this.Model != null && BaseModuleImpl.IsGridViewRightMenuBtnEdit(rightMentTab))
//左侧如果配置表格,也和出现和主表一样的操作列。先限制为左侧固定不加载(要加载的话要获取左侧的fieldKey)
if (this.Model != null && BaseModuleImpl.IsGridViewRightMenuBtnEdit(rightMentTab)&&!customColumKey.Contains("BaseLeftGridView_"))
{
this.InitRightMenuBtnEdit();
}
@@ -1707,7 +1704,8 @@ namespace Lskj.Control
rightMentTab = BaseModuleImpl.GetBaseGridRightMenus(this.Model.ModuleCode);
}
}
if (this.Model != null && BaseModuleImpl.IsGridViewRightMenuBtnEdit(rightMentTab))
//左侧如果配置表格,也和出现和主表一样的操作列。先限制为左侧固定不加载(要加载的话要获取左侧的fieldKey)
if (this.Model != null && BaseModuleImpl.IsGridViewRightMenuBtnEdit(rightMentTab) && !customColumKey.Contains("BaseLeftGridView_"))
{
this.InitRightMenuBtnEdit();
}
@@ -4759,8 +4757,15 @@ namespace Lskj.Control
editorButton.Kind = ButtonPredefines.Glyph;
editorButton.Width = this.CalculateTextWidth(editorButton.Caption, editorButton.Appearance.Font);
editorButton.Tag = menuModel;
ItemButtonEdit.Buttons.Add(editorButton);
editorButton.Appearance.BackColor = Color.FromArgb(240, 240, 240); // 浅灰背景
editorButton.Appearance.BorderColor = Color.FromArgb(180, 180, 180); // 边框色
editorButton.Appearance.ForeColor = Color.FromArgb(50, 50, 50); // 文本色
editorButton.Appearance.Options.UseBackColor = true;
editorButton.Appearance.Options.UseBorderColor = true;
editorButton.Appearance.Options.UseForeColor = true;
ItemButtonEdit.Buttons.Add(editorButton);
ColumnWidth += editorButton.Width;
}
}
@@ -4774,6 +4779,8 @@ namespace Lskj.Control
gridColumn.MinWidth = ColumnWidth;
gridColumn.Width = ColumnWidth;
}
private void OnHighBeater(object sender, ButtonPressedEventArgs e)
{
FrmHighBeater highBeater = new FrmHighBeater();
@@ -9537,17 +9544,232 @@ namespace Lskj.Control
private void GridView_ShowingEditor(object sender, CancelEventArgs e)
{
GridColumn gridColumn = gridView.FocusedColumn;
if (gridColumn != null && gridColumn.Tag != null)
if (gridColumn != null && gridColumn.Tag != null&& gridColumn.Tag is GridColumnModel)
{
GridColumnModel model = (GridColumnModel)gridColumn.Tag;
if ((model.FieldType == ControlType.LabTextInt || model.FieldType == ControlType.LabCalcText || model.FieldType == ControlType.LabAccount)&& gridColumn.RealColumnEdit!=null)
if (model.FormatEditBox && (model.FieldType == ControlType.LabTextInt || model.FieldType == ControlType.LabCalcText || model.FieldType == ControlType.LabAccount)&& gridColumn.RealColumnEdit!=null&& !gridColumn.RealColumnEdit.EditFormat.FormatString.Equals(model.DataFormat))
{
gridColumn.RealColumnEdit.EditFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
gridColumn.RealColumnEdit.EditFormat.FormatString = model.DataFormat;
//编辑框输入的小数位数根据和格式一致
//if (gridColumn.RealColumnEdit is RepositoryItemTextEdit textEditItem)
//{
// // 从格式字符串中提取小数位数
// int decimalPlaces = 0;
// if (model.DataFormat.Contains("."))
// {
// string decimalPart = model.DataFormat.Split('.')[1];
// decimalPlaces = decimalPart.Length;
// }
// // 设置输入掩码(例如n4表示4位小数)
// if (decimalPlaces > 0)
// {
// textEditItem.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.Numeric;
// textEditItem.Mask.EditMask = $"n{decimalPlaces}";
// textEditItem.Mask.UseMaskAsDisplayFormat = true;
// }
//}
}
}
}
/// 计
/// 计算EditorButton文本所需的精确宽度
/// </summary>
/// <param name="caption">按钮文本</param>
/// <param name="font">按钮字体</param>
/// <param name="padding">额外边距(像素)</param>
/// <returns>推荐的按钮宽度</returns>
public int CalculateTextWidth(string caption, Font font, int padding = 15)
{
if (string.IsNullOrEmpty(caption))
return 40; // 空文本默认宽度
using (Bitmap tempBitmap = new Bitmap(1, 1))
using (Graphics g = Graphics.FromImage(tempBitmap))
{
// 测量文本尺寸
SizeF textSize = g.MeasureString(caption, font);
// 计算总宽度 = 文本宽度 + 左右边距
int width = (int)textSize.Width + padding;
// 确保宽度不小于最小值
return Math.Max(width, 40); // 最小宽度40像素
}
}
#region
/// <summary>
/// 表格点击事件(处理表格禁编状态时的右键列点击逻辑)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void GridView_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left) return;
GridView view = sender as GridView;
if (view.OptionsBehavior.Editable) return;
GridHitInfo hitInfo = view.CalcHitInfo(e.Location);
if (hitInfo.InRowCell && hitInfo.Column.ColumnEdit is RepositoryItemButtonEdit)
{
RepositoryItemButtonEdit repo = hitInfo.Column.ColumnEdit as RepositoryItemButtonEdit;
if (!hitInfo.Column.FieldName.Equals("RightMenuBtnEdit")) return;
int rowHandle = hitInfo.RowHandle;
this.gridView.SelectRowHandler(rowHandle);
int buttonIndex = this.GetClickedButtonIndex(repo, view, rowHandle, hitInfo.Column, e.Location, hitInfo.Column.Width);
if (buttonIndex != -1)
{
// 成功获取按钮索引,触发原有逻辑
EditorButton clickedButton = repo.Buttons[buttonIndex];
if (clickedButton == null) return;
this.RightButtonClick(clickedButton);
}
}
}
/// <summary>
/// 执行点击的右键按钮
/// </summary>
/// <param name="editorButton"></param>
private void RightButtonClick(EditorButton editorButton)
{
GridRightMenuModel menuModel = editorButton.Tag as GridRightMenuModel;
ToolStripMenuItem toolStripMenuItem = this.gridViewRightMenu.RightMenuBtnEdits.ContainsKey(menuModel.Id) ? this.gridViewRightMenu.RightMenuBtnEdits[menuModel.Id] : null;
if (toolStripMenuItem != null)
{
bool allowClick = true;
int[] mSelectRows = this.gridView.GetSelectedRows();
DataRow mSelectRow = this.gridView.GetDataRow(mSelectRows[0]);
if (menuModel != null)
{
if (menuModel.PrivilegeOper.Length > 1 && !menuModel.PrivilegeOper.Contains(ERPInfo.Instance.UserName + ","))
{
allowClick = false;
}
else
{
if (!string.IsNullOrWhiteSpace(menuModel.MenuCond))
{
try
{
string cond = string.Empty;
if (this.gridViewRightMenu.ControlObj != null)
cond = this.gridViewRightMenu.ControlObj.ReplaceParentControlValue(menuModel.MenuCond);
cond = ReplaceHelper.ReplaceRowParam(mSelectRow, menuModel.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.gridView.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 (this.gridViewRightMenu.ControlObj != null)
cond = this.gridViewRightMenu.ControlObj.ReplaceParentControlValue(cond);
allowClick = ReplaceHelper.EvalCond(cond);
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(ResourceKeys.SetRightMenuCondFault + "\r\n" + Message);
}
}
}
}
if (allowClick) toolStripMenuItem.PerformClick();
}
}
/// <summary>
/// 计算点击是单元格中的第几个按钮
/// </summary>
/// <param name="repo"></param>
/// <param name="view"></param>
/// <param name="rowHandle">点击行</param>
/// <param name="column">点击列</param>
/// <param name="clickPoint">点击位置</param>
/// <param name="ColumnWidth">单元格宽度</param>
/// <param name="buttonSpacing"></param>
/// <returns></returns>
public int GetClickedButtonIndex(RepositoryItemButtonEdit repo, GridView view, int rowHandle, GridColumn column, Point clickPoint, int ColumnWidth, int buttonSpacing = 2)
{
// 1. 获取单元格在网格控件中的绝对区域(关键修正)
Rectangle cellRect = GetCellAbsoluteRect(view, rowHandle, column);
if (cellRect.IsEmpty)
return -1;
// 2. 验证点击是否在单元格范围内(首要检查)
if (!cellRect.Contains(clickPoint))
return -1;
// 3. 计算单元格内的相对坐标(修正坐标转换)
Point relativePoint = new Point(
clickPoint.X - cellRect.Left,
clickPoint.Y - cellRect.Top
);
// 4. 计算按钮布局(针对固定宽度)
//int buttonWidth = repo.Buttons[0].Width; // 固定宽度
int buttonWidth = ColumnWidth / repo.Buttons.Count;
int totalButtonsWidth = repo.Buttons.Count * buttonWidth +
(repo.Buttons.Count - 1) * buttonSpacing;
// 5. 确定按钮排列方式(默认靠右对齐,可根据IsLeft调整)
int startX = GetButtonStartX(cellRect.Width, totalButtonsWidth, repo.Buttons[0].IsLeft);
// 6. 精确匹配按钮区域(核心修正)
for (int i = 0; i < repo.Buttons.Count; i++)
{
// 计算当前按钮的区域(相对单元格)
Rectangle buttonRect = new Rectangle(
startX + i * (buttonWidth + buttonSpacing),
0,
buttonWidth,
cellRect.Height
);
// 扩大1-2像素检测范围,解决边界点击问题
Rectangle expandedRect = Rectangle.Inflate(buttonRect, 1, 1);
if (expandedRect.Contains(relativePoint))
{
return i; // 返回正确索引
}
}
return -1;
}
// 获取单元格在网格控件中的绝对坐标区域
private Rectangle GetCellAbsoluteRect(GridView view, int rowHandle, GridColumn column)
{
try
{
GridViewInfo viewInfo = view.GetViewInfo() as GridViewInfo;
if (viewInfo == null)
return Rectangle.Empty;
GridDataRowInfo rowInfo = (GridDataRowInfo)viewInfo.RowsInfo.FindRow(rowHandle);
if (rowInfo == null)
return Rectangle.Empty;
GridCellInfo cellInfo = rowInfo.Cells[column];
if (cellInfo == null)
return Rectangle.Empty;
// 转换为网格控件内的坐标(关键修正)