10582 lines
498 KiB
C#
10582 lines
498 KiB
C#
/******************************
|
||
* 说明:自定义表格控件
|
||
* 创建人:龚宇超
|
||
* 创建日期:2017-08-21
|
||
* 修改人:
|
||
* 修改日期:
|
||
* 修改备注:
|
||
* 版本:1.0.0.0
|
||
******************************/
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Drawing;
|
||
using System.Data;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Windows.Forms;
|
||
using DevExpress.Utils;
|
||
using DevExpress.XtraGrid.Views.Grid;
|
||
using DevExpress.XtraGrid;
|
||
using DevExpress.XtraGrid.Columns;
|
||
using DevExpress.XtraEditors.Repository;
|
||
using Lskj.Control.Model;
|
||
using DevExpress.Data;
|
||
using DevExpress.XtraEditors.Controls;
|
||
using Lskj.Business;
|
||
using Lskj.Business.Impl;
|
||
using Lskj.Util;
|
||
using Lskj.Control.Properties;
|
||
using Lskj.Model;
|
||
using Lskj.Data;
|
||
using DevExpress.XtraEditors;
|
||
using System.Data.SqlClient;
|
||
using System.IO;
|
||
using DevExpress.XtraPrinting;
|
||
using DevExpress.XtraGrid.Views.Base;
|
||
using DevExpress.XtraGrid.Menu;
|
||
using DevExpress.Utils.Menu;
|
||
using Lskj.Control.MultiGridLookUp;
|
||
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
|
||
using System.Reflection;
|
||
using DevExpress.Data.Filtering;
|
||
using Lskj.Core;
|
||
using System.Text.RegularExpressions;
|
||
using DevExpress.XtraGrid.Views.BandedGrid;
|
||
using Lskj.Control.MultiModelLookUp;
|
||
using Lskj.Control.HighBeaterInvoice;
|
||
using DevExpress.XtraGrid.Drawing;
|
||
using DevExpress.XtraPrinting.BarCode.Native;
|
||
using Spire.Barcode;
|
||
using System.Threading.Tasks;
|
||
using System.Collections;
|
||
using Newtonsoft.Json;
|
||
using System.Net;
|
||
using System.Data.Common;
|
||
using Lskj.Control.SpecialDate;
|
||
|
||
namespace Lskj.Control
|
||
{
|
||
/// <summary>
|
||
/// 自定义表格控件
|
||
/// </summary>
|
||
public partial class GridControlEx : UserControl
|
||
{
|
||
/// <summary>
|
||
/// <para>说明:缓存计划行</para>
|
||
/// <para>时间:2024-5-22</para>
|
||
/// </summary>
|
||
public DataRow jhrowitem = null;
|
||
/// <summary>
|
||
/// <para>说明:第一列获取合计</para>
|
||
/// <para>时间:2022-5-7</para>
|
||
/// </summary>
|
||
private bool isFirstVisableCol = true;
|
||
/// <summary>
|
||
/// 表格自定义字体
|
||
/// </summary>
|
||
private System.Drawing.Text.PrivateFontCollection customFont = new System.Drawing.Text.PrivateFontCollection();
|
||
/// <summary>
|
||
/// The _grid enum object
|
||
/// </summary>
|
||
private HeaderSiftEnum _columnEnumObj;
|
||
protected bool GridSumming = false;
|
||
/// <summary>
|
||
/// 表格列头筛选
|
||
/// </summary>
|
||
protected GridColumn HeaderColumnSift;
|
||
/// <summary>
|
||
/// 列筛选值
|
||
/// </summary>
|
||
protected int ColumnSiftValue;
|
||
/// <summary>
|
||
/// 筛选类型
|
||
/// </summary>
|
||
public enum HeaderSiftEnum
|
||
{
|
||
/// <summary>
|
||
/// 求和类型
|
||
/// </summary>
|
||
Sum,
|
||
/// <summary>
|
||
/// 平均类型
|
||
/// </summary>
|
||
Avg,
|
||
/// <summary>
|
||
/// 最大
|
||
/// </summary>
|
||
Max,
|
||
/// 最小
|
||
/// </summary>
|
||
Min,
|
||
/// <summary>
|
||
/// 计数
|
||
/// </summary>
|
||
Count
|
||
}
|
||
/// <summary>
|
||
/// 表格类型
|
||
/// </summary>
|
||
/// <value>The grid enum object.</value>
|
||
public virtual HeaderSiftEnum SiftEnumObj
|
||
{
|
||
get
|
||
{
|
||
return this._columnEnumObj == null ? HeaderSiftEnum.Count : this._columnEnumObj;
|
||
}
|
||
set
|
||
{
|
||
this._columnEnumObj = value;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 表格类型
|
||
/// </summary>
|
||
/// <value>The grid enum object.</value>
|
||
public virtual DevExpress.XtraEditors.PanelControl plbuttomObj
|
||
{
|
||
get
|
||
{
|
||
return this.pl_buttom;
|
||
}
|
||
}
|
||
|
||
public List<GridColumnModel> ObjmControlList
|
||
{
|
||
get
|
||
{
|
||
return ColumnList;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 表格列头颜色
|
||
/// </summary>
|
||
protected string HeaderColor = string.IsNullOrWhiteSpace(SystemInfo.Instance.HeaderColor) ? "#A0A0A0" : SystemInfo.Instance.HeaderColor;
|
||
/// <summary>
|
||
/// 必填颜色
|
||
/// </summary>
|
||
protected Color RequiredForceColor = string.IsNullOrEmpty(SystemInfo.Instance.ControlRequiredColor) ? Color.Blue : ColorTranslator.FromHtml(SystemInfo.Instance.ControlRequiredColor);
|
||
/// <summary>
|
||
/// The reset colum primary key
|
||
/// </summary>
|
||
protected string CustomColumKey;
|
||
/// <summary>
|
||
/// 缓存列对象
|
||
/// </summary>
|
||
protected List<GridColumnModel> ColumnList = new List<GridColumnModel>();
|
||
/// <summary>
|
||
/// 缓存自动填充值列对象
|
||
/// </summary>
|
||
protected List<GridColumnModel> AutoPadDataReleColList = new List<GridColumnModel>();
|
||
/// <summary>
|
||
/// 表格行颜色数据源
|
||
/// </summary>
|
||
protected DataTable GridRowColorsTable;
|
||
/// <summary>
|
||
/// 表格行颜色数据源
|
||
/// </summary>
|
||
protected DataTable ChartTable = new DataTable();
|
||
protected string CurrentOperColumnKey = string.Empty;
|
||
protected GridColumnModel CurrentOperModel = null;
|
||
protected GridView CurrentOperGridView = null;
|
||
public List<string> ImageList = new List<string>();
|
||
|
||
protected bool mLoading = false;
|
||
protected Timer mTimer = new Timer();
|
||
/// <summary>
|
||
/// 配置有数据源的控件对象
|
||
/// </summary>
|
||
protected List<GridColumnModel> mControlList = new List<GridColumnModel>();
|
||
/// <summary>
|
||
/// 数据源任务对象
|
||
/// </summary>
|
||
public Dictionary<GridColumnModel, Task<DataTable>> mControlSourceDic = new Dictionary<GridColumnModel, Task<DataTable>>();
|
||
/// <summary>
|
||
/// 计算值
|
||
/// </summary>
|
||
public decimal customSum;
|
||
/// <summary>
|
||
/// 计算配置求和值
|
||
/// </summary>
|
||
public string SumText;
|
||
/// <summary>
|
||
/// 求和列的虚拟表
|
||
/// </summary>
|
||
public DataRow sumdr;
|
||
/// <summary>
|
||
/// 是否为PubSpec模块
|
||
/// </summary>
|
||
public bool IsSpecModel = false;
|
||
/// <summary>
|
||
/// 禁用控件是否改变颜色
|
||
/// </summary>
|
||
public bool EnabledChangeColor = true;
|
||
/// <summary>
|
||
/// 上一次查询SQL
|
||
/// </summary>
|
||
public string LastSearchSql = string.Empty;
|
||
/// <summary>
|
||
/// 上一次点击搜索按钮查询SQL
|
||
/// </summary>
|
||
public string LastSearchButtonhSql = string.Empty;
|
||
/// <summary>
|
||
/// 调用动态链接库默认传递参数
|
||
/// </summary>
|
||
public DynamicModel Model;
|
||
/// <summary>
|
||
/// 系统模块实体对象
|
||
/// </summary>
|
||
/// <value>The system model.</value>
|
||
public ModuleModel SysModel { get; set; }
|
||
/// <summary>
|
||
/// 合计弹出浮窗
|
||
/// </summary>
|
||
public SumPanelControl sumPanel;
|
||
/// <summary>
|
||
/// 单据主表控件、基础档案查询条件控件等等
|
||
/// </summary>
|
||
public MyControl ParentControl;
|
||
/// <summary>
|
||
/// Gets or sets the adapter object.
|
||
/// </summary>
|
||
/// <value>The adapter object.</value>
|
||
public DbDataAdapter AdapterObj { get; set; }
|
||
/// <summary>
|
||
/// Gets the grid view.
|
||
/// </summary>
|
||
/// <value>The grid view.</value>
|
||
public virtual GridView GridView { get { return gridView; } }
|
||
/// <summary>
|
||
/// Gets the grid control.
|
||
/// </summary>
|
||
/// <value>The grid control.</value>
|
||
public virtual GridControl GridControl { get { return gridControl; } }
|
||
/// <summary>
|
||
/// 下拉框数据源绑定完成后执行
|
||
/// </summary>
|
||
public event EventHandler OnDataSourceBindCallBack;
|
||
/// <summary>
|
||
/// Delegate ParseGridDataEventHandler
|
||
/// </summary>
|
||
/// <param name="rowItem">The row item.</param>
|
||
public delegate void ParseGridDataEventHandler(DataRow rowItem);
|
||
/// <summary>
|
||
/// 粘贴表格数据时调用
|
||
/// </summary>
|
||
public event ParseGridDataEventHandler OnParseGridDataCallBack;
|
||
/// <summary>
|
||
/// 所有数据粘贴完成后调用
|
||
/// </summary>
|
||
public event EventHandler OnAllAfterParseCallBack;
|
||
/// <summary>
|
||
/// Delegate GridColumnCallDLL
|
||
/// </summary>
|
||
/// <param name="rowItem">The row item.</param>
|
||
public delegate void GridColumnCallDLL(string type);
|
||
/// <summary>
|
||
/// 表格列右键调用dll用
|
||
/// </summary>
|
||
public event GridColumnCallDLL OnGridColumnCallDLL;
|
||
/// <summary>
|
||
/// 表格列为会计模块
|
||
/// </summary>
|
||
private AmountCellRender cellHelper;
|
||
/// <summary>
|
||
/// 合并求和时,前一行的内容
|
||
/// </summary>
|
||
public decimal BeforeClass;
|
||
/// <summary>
|
||
/// 合并求和时,前一行合并组名
|
||
/// </summary>
|
||
public string BeforeGroupName;
|
||
/// <summary>
|
||
/// 界面关闭时
|
||
/// </summary>
|
||
public event EventHandler OnPopupClosed;
|
||
/// <summary>
|
||
/// 默认自定义控件
|
||
/// </summary>
|
||
public PopupContainerEdit PopupEdit;
|
||
/// <summary>
|
||
/// 缓存筛选数据
|
||
/// </summary>
|
||
private Dictionary<string, List<CheckedListBoxItem>> _CheckedList = new Dictionary<string, List<CheckedListBoxItem>>();
|
||
//修改过的单元格
|
||
public Dictionary<int, string> modifyThePosition = new Dictionary<int, string>();
|
||
/// <summary>
|
||
/// 右键菜单类
|
||
/// </summary>
|
||
public BaseRightMenu gridViewRightMenu;
|
||
/// <summary>
|
||
/// 构建表格列的数据源
|
||
/// </summary>
|
||
public DataTable InitGridColumsTab;
|
||
/// <summary>
|
||
/// 上次选中行
|
||
/// </summary>
|
||
public int LastFocusedRowHandle;
|
||
/// <summary>
|
||
/// 是否加载导出
|
||
/// </summary>
|
||
public bool ExportPermission = true;
|
||
/// <summary>
|
||
/// 当前选中行数组
|
||
/// </summary>
|
||
private int[] SelectedRows = new int[0];
|
||
/// <summary>
|
||
/// 修改条件
|
||
/// </summary>
|
||
public string ModifyCond = string.Empty;
|
||
/// <summary>
|
||
///超链接点击回调
|
||
/// </summary>
|
||
public event EventHandler OnAfterLinkCilk;
|
||
/// <summary>
|
||
/// 表格粘贴行后回调
|
||
/// </summary>
|
||
public event EventHandler OnAfterPasting;
|
||
//模块返回id框(text)的数据源
|
||
public Dictionary<string, DataTable> ModuleEnclosure = new Dictionary<string, DataTable>();
|
||
/// <summary>
|
||
/// 保存时需要验证是否重复的列
|
||
/// </summary>
|
||
public List<string> RepeatedVerificationNames = new List<string>();
|
||
/// <summary>
|
||
/// 触发计算关联后,计算合计
|
||
/// </summary>
|
||
public bool RefreshTotal = true;
|
||
|
||
/// <summary>
|
||
/// 排序关联值
|
||
/// </summary>
|
||
private string DetailOrderField = string.Empty;
|
||
/// <summary>
|
||
/// 冻结列
|
||
/// </summary>
|
||
private List<GridColumn> FrozenColumns = new List<GridColumn>();
|
||
|
||
private Point m_mouseDownLocation;
|
||
private int m_dragHandle;
|
||
private int[] dragRowsIndex;
|
||
private DragForm m_dragRowShadow;
|
||
/// <summary>
|
||
/// 判断明细是否是拖拽中
|
||
/// </summary>
|
||
private bool isSortDrag;
|
||
/// <summary>
|
||
/// 设置数据源时是否允许清空列
|
||
/// </summary>
|
||
public bool AllowClearColumns = true;
|
||
/// <summary>
|
||
/// 第一次保存全部的列
|
||
/// </summary>
|
||
private List<GridColumn> ColumnsList = new List<GridColumn>();
|
||
/// <summary>
|
||
///复选模式,表格主键
|
||
/// </summary>
|
||
public string MultiplePrimary = string.Empty;
|
||
/// <summary>
|
||
///选中的行在数据源中的主键值
|
||
/// </summary>
|
||
private List<string> SelectedDataSource = new List<string>();
|
||
/// <summary>
|
||
/// 禁显列不加载数据源
|
||
/// </summary>
|
||
public bool DisableFieldSources;
|
||
/// <summary>
|
||
/// 表格重新赋值数据源时,更新的列
|
||
/// </summary>
|
||
public string UpdateColumns;
|
||
/// <summary>
|
||
/// 聚合多表头控件
|
||
/// </summary>
|
||
public BandedGridControlEx CustomGroupBandEx;
|
||
/// <summary>
|
||
/// 聚合多表头控件
|
||
/// </summary>
|
||
public TreeBandedGridControlEx CustomGroupTreeBandEx;
|
||
/// <summary>
|
||
/// 聚合界面是否冻结基本信息列
|
||
/// </summary>
|
||
public bool AggregationFreeze;
|
||
|
||
/// <summary>
|
||
/// 聚合多表头控件选中行
|
||
/// </summary>
|
||
public DataRow CustomGroupSelectedRow
|
||
{
|
||
get
|
||
{
|
||
DataRow dataRow = null;
|
||
if (CustomGroupBandEx != null)
|
||
{
|
||
dataRow = CustomGroupBandEx.GetViewFocusedDataRow();
|
||
}
|
||
else if (CustomGroupTreeBandEx != null)
|
||
{
|
||
dataRow = CustomGroupTreeBandEx.GetViewFocusedDataRow();
|
||
}
|
||
return dataRow;
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 导出名不包含日期
|
||
/// </summary>
|
||
public bool ExportNameWithoutDate = false;
|
||
/// <summary>
|
||
/// 导出名不包含日期
|
||
/// </summary>
|
||
public bool IgnoreTab = false;
|
||
/// <summary>
|
||
/// 创建动态分组列控件回调
|
||
/// </summary>
|
||
public event EventHandler OnBuildGroupedColumnCallBack;
|
||
/// <summary>
|
||
/// 记录上一次分组状态,避免重复排序
|
||
/// </summary>
|
||
private int _lastGroupCount = 0;
|
||
/// <summary>
|
||
/// 分组后根据汇总排序是否完成
|
||
/// </summary>
|
||
private bool Completed = true;
|
||
/// <summary>
|
||
/// 进度条类型的列名称
|
||
/// </summary>
|
||
private List<string> ProgressBarColumn = new List<string>();
|
||
/// <summary>
|
||
/// 提示文本 字段(列名,提示信息)
|
||
/// </summary>
|
||
public Dictionary<string, string> PromptMessage = new Dictionary<string, string>();
|
||
/// <summary>
|
||
/// 合计行格式(设置成全局变量,更好的处理语言翻译的情况)
|
||
/// </summary>
|
||
public string TotalFormat = Business.Impl.LanguageTranslation.Translatable ? Business.Impl.LanguageTranslation.GetTranslatedText("合计") + ": {0:#,###}" + Business.Impl.LanguageTranslation.GetTranslatedText("行") : "合计: {0:#,###}行";
|
||
/// <summary>
|
||
/// 搜索框 手动添加行
|
||
/// </summary>
|
||
public Dictionary<string, List<DataRow>> ManuallyAddData = new Dictionary<string, List<DataRow>>();
|
||
/// <summary>
|
||
/// 修改字段
|
||
/// </summary>
|
||
public string ModifyFields = string.Empty;
|
||
/// <summary>
|
||
/// 必填字段
|
||
/// </summary>
|
||
public string RequiredFields = string.Empty;
|
||
/// <summary>
|
||
/// 合计显示选中行数
|
||
/// </summary>
|
||
public bool TotalQuantity;
|
||
|
||
|
||
/// <summary>
|
||
///新增行
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
public event ModuleAddLine OnNewLine;
|
||
public delegate void ModuleAddLine(string name, List<string> list);
|
||
|
||
public GridControlEx()
|
||
{
|
||
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.Selectable | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true);
|
||
InitializeComponent();
|
||
|
||
// 自定义选中区域方式
|
||
this.gridView.CustomDrawRowIndicator += new RowIndicatorCustomDrawEventHandler(OnGridViewCustomDrawRowIndicator);
|
||
this.gridView.SelectionChanged += new SelectionChangedEventHandler(OnGridViewSelectionChanged);
|
||
this.gridView.FocusedRowObjectChanged += new FocusedRowObjectChangedEventHandler(OnGridViewFocusedRowObjectChanged);
|
||
this.gridView.BeforeLeaveRow += new RowAllowEventHandler(OnGridView_BeforeLeaveRow);
|
||
this.gridView.CustomDrawCell += new RowCellCustomDrawEventHandler(OnGridViewCustomDrawCell);
|
||
this.gridView.CellValueChanged += new CellValueChangedEventHandler(OnGridViewCellValueChanged);
|
||
this.gridView.DragObjectDrop += new DragObjectDropEventHandler(OnGridViewDragObjectDrop);
|
||
this.gridView.CustomDrawGroupRow += new RowObjectCustomDrawEventHandler(OnGridCustomDrawGroupRow);
|
||
this.gridView.KeyDown += new KeyEventHandler(OnGridViewKeyDown);
|
||
this.gridView.DoubleClick += new EventHandler(OnGridViewDoubleClick);
|
||
this.gridView.Click += new EventHandler(OnGridViewClick);
|
||
this.gridView.CellMerge += new CellMergeEventHandler(OnGridViewCellMerge);
|
||
this.gridView.CustomSummaryCalculate += new CustomSummaryEventHandler(OnGridViewSummaryCalculate);
|
||
this.gridView.OptionsNavigation.EnterMoveNextColumn = true;
|
||
this.gridView.OptionsBehavior.EditorShowMode = EditorShowMode.MouseDownFocused;
|
||
this.SetGridRowHeightAndFont();
|
||
this.gridView.ShowFilterPopupCheckedListBox += new FilterPopupCheckedListBoxEventHandler(OnShowFilterPopupCheckedListBox);//(修复筛选条件)
|
||
//this.gridView.ValidateRow += OnGridView_ValidateRow;
|
||
this.gridView.DataSourceChanged += new EventHandler(OnGridDataSourceChanged);
|
||
cellHelper = new AmountCellRender(this.gridView);
|
||
//鼠标悬浮提示框
|
||
ToolTipController MainGvTool = new ToolTipController();
|
||
MainGvTool.AutoPopDelay = 1000000;//提示框显示时间 10分钟
|
||
MainGvTool.BeforeShow += new ToolTipControllerBeforeShowEventHandler(MainGvTool_BeforeShow);
|
||
this.gridControl.ToolTipController = MainGvTool;
|
||
//this.gridView.PopupMenuShowing += new PopupMenuShowingEventHandler(OnGridView_PopupMenuShowing);//添加Footer菜单选项
|
||
this.gridView.Click += new EventHandler(OnGridView_Click);//点击复制Footer数据信息
|
||
if (SystemInfo.Instance.SelectColorHighlight)
|
||
{
|
||
this.gridView.RowCellStyle += GridView_RowCellStyle;
|
||
}
|
||
if (SystemInfo.Instance.GroupRowFontSizeDelta > 0)
|
||
{
|
||
this.gridView.Appearance.GroupRow.FontSizeDelta = SystemInfo.Instance.GroupRowFontSizeDelta;
|
||
}
|
||
if (SystemInfo.Instance.DisplayCheckboxSelection)
|
||
{
|
||
this.gridView.CustomRowFilter += GridView_CustomRowFilter;
|
||
}
|
||
#region LabPicUrl控件实现事件
|
||
//this.gridView.CustomUnboundColumnData += OnGridViewCustomUnboundColumnData;
|
||
//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.MouseDown += GridView_MouseDown;
|
||
//绑定滚轮横向滚动
|
||
this.gridView.MouseWheel += GridView_MouseWheel;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 保存前反写多表头数据源
|
||
/// </summary>
|
||
public void callbackUpdData()
|
||
{
|
||
try
|
||
{
|
||
if (CustomGroupBandEx != null)
|
||
{
|
||
// 获取动态多表头的Grid控件数据源 (假设为DataTable)
|
||
DataTable updatedTable = CustomGroupBandEx.gridControl.DataSource as DataTable;
|
||
if (updatedTable == null) return;
|
||
|
||
// 获取原始的GridControl的数据源
|
||
DataTable originalDataTable = this.gridControl.DataSource as DataTable;
|
||
if (originalDataTable == null) return;
|
||
|
||
// 获取分组相关的列定义
|
||
GridColumnModel GroupPrimary = ColumnList.FirstOrDefault(o => o.IsCustomGroupPrimary);
|
||
GridColumnModel GroupFieldprimary = ColumnList.FirstOrDefault(o => o.IsCustomGroupField == 1);
|
||
List<GridColumnModel> GroupField = ColumnList.Where(o => o.IsCustomGroupField == 2).ToList();
|
||
|
||
if (GroupPrimary == null || GroupFieldprimary == null || !GroupField.Any()) return;
|
||
|
||
// 遍历每一行更新回原始数据表
|
||
foreach (DataRow updatedRow in updatedTable.Rows)
|
||
{
|
||
string primaryKeyValue = updatedRow[GroupPrimary.FieldName]?.ToString();
|
||
|
||
// 根据主键定位原始表中的行集合
|
||
var originalRows = originalDataTable.AsEnumerable()
|
||
.Where(row => row.Field<string>(GroupPrimary.FieldName) == primaryKeyValue).ToList();
|
||
|
||
if (!originalRows.Any()) continue; // 若没有匹配的行,跳过
|
||
|
||
// 遍历动态表头的Band及子列
|
||
foreach (GridBand band in CustomGroupBandEx.BandedView.Bands)
|
||
{
|
||
if (band.Caption == "基本信息") continue; // 跳过普通列Band
|
||
|
||
string groupFieldPrimaryValue = band.Caption;
|
||
|
||
foreach (BandedGridColumn column in band.Columns)
|
||
{
|
||
var subField = column.Tag as GridColumnModel;
|
||
if (subField == null) continue;
|
||
|
||
string dynamicFieldName = column.FieldName;
|
||
object updatedValue = updatedRow[dynamicFieldName];
|
||
|
||
// 精确匹配原数据源对应的单行
|
||
DataRow targetRow = originalRows.FirstOrDefault(r =>
|
||
r.Field<string>(GroupFieldprimary.FieldName) == groupFieldPrimaryValue);
|
||
|
||
// 若找到行,则更新该行对应的字段
|
||
if (targetRow != null && originalDataTable.Columns.Contains(subField.FieldName))
|
||
{
|
||
targetRow[subField.FieldName] = updatedValue;
|
||
}
|
||
else if (targetRow == null)
|
||
{
|
||
// 若没找到,说明可能为新增数据行,插入新行(若业务需要)
|
||
DataRow newOriginalRow = originalDataTable.NewRow();
|
||
newOriginalRow[GroupPrimary.FieldName] = primaryKeyValue;
|
||
newOriginalRow[GroupFieldprimary.FieldName] = groupFieldPrimaryValue;
|
||
|
||
foreach (var col in ColumnList.Where(x => !x.IsCustomGroupField.Equals(1) && !x.IsCustomGroupPrimary))
|
||
{
|
||
if (updatedTable.Columns.Contains(col.FieldName) && originalDataTable.Columns.Contains(col.FieldName))
|
||
{
|
||
newOriginalRow[col.FieldName] = updatedRow[col.FieldName];
|
||
}
|
||
}
|
||
|
||
if (originalDataTable.Columns.Contains(subField.FieldName))
|
||
{
|
||
newOriginalRow[subField.FieldName] = updatedValue;
|
||
}
|
||
|
||
originalDataTable.Rows.Add(newOriginalRow);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else if (CustomGroupTreeBandEx != null)
|
||
{
|
||
|
||
// 获取动态多表头的Grid控件数据源 (假设为DataTable)
|
||
DataTable updatedTable = CustomGroupTreeBandEx.TreeListObj.DataSource as DataTable;
|
||
if (updatedTable == null) return;
|
||
|
||
// 获取原始的GridControl的数据源
|
||
DataTable originalDataTable = this.gridControl.DataSource as DataTable;
|
||
if (originalDataTable == null) return;
|
||
|
||
// 获取分组相关的列定义
|
||
GridColumnModel GroupPrimary = ColumnList.FirstOrDefault(o => o.IsCustomGroupPrimary);
|
||
GridColumnModel GroupFieldprimary = ColumnList.FirstOrDefault(o => o.IsCustomGroupField == 1);
|
||
List<GridColumnModel> GroupField = ColumnList.Where(o => o.IsCustomGroupField == 2).ToList();
|
||
|
||
if (GroupPrimary == null || GroupFieldprimary == null || !GroupField.Any()) return;
|
||
|
||
// 遍历每一行更新回原始数据表
|
||
foreach (DataRow updatedRow in updatedTable.Rows)
|
||
{
|
||
string primaryKeyValue = updatedRow[GroupPrimary.FieldName]?.ToString();
|
||
|
||
// 根据主键定位原始表中的行集合
|
||
var originalRows = originalDataTable.AsEnumerable()
|
||
.Where(row => row.Field<string>(GroupPrimary.FieldName) == primaryKeyValue).ToList();
|
||
|
||
if (!originalRows.Any()) continue; // 若没有匹配的行,跳过
|
||
|
||
// 遍历动态表头的Band及子列
|
||
foreach (DevExpress.XtraTreeList.Columns.TreeListBand band in CustomGroupTreeBandEx.TreeListObj.Bands)
|
||
{
|
||
if (band.Caption == "基本信息") continue; // 跳过普通列Band
|
||
|
||
string groupFieldPrimaryValue = band.Caption;
|
||
|
||
foreach (DevExpress.XtraTreeList.Columns.TreeListColumn column in band.Columns)
|
||
{
|
||
var subField = column.Tag as GridColumnModel;
|
||
if (subField == null) continue;
|
||
|
||
string dynamicFieldName = column.FieldName;
|
||
object updatedValue = updatedRow[dynamicFieldName];
|
||
|
||
// 精确匹配原数据源对应的单行
|
||
DataRow targetRow = originalRows.FirstOrDefault(r =>
|
||
r.Field<string>(GroupFieldprimary.FieldName) == groupFieldPrimaryValue);
|
||
|
||
// 若找到行,则更新该行对应的字段
|
||
if (targetRow != null && originalDataTable.Columns.Contains(subField.FieldName))
|
||
{
|
||
targetRow[subField.FieldName] = updatedValue;
|
||
}
|
||
else if (targetRow == null)
|
||
{
|
||
// 若没找到,说明可能为新增数据行,插入新行(若业务需要)
|
||
DataRow newOriginalRow = originalDataTable.NewRow();
|
||
newOriginalRow[GroupPrimary.FieldName] = primaryKeyValue;
|
||
newOriginalRow[GroupFieldprimary.FieldName] = groupFieldPrimaryValue;
|
||
|
||
foreach (var col in ColumnList.Where(x => !x.IsCustomGroupField.Equals(1) && !x.IsCustomGroupPrimary))
|
||
{
|
||
if (updatedTable.Columns.Contains(col.FieldName) && originalDataTable.Columns.Contains(col.FieldName))
|
||
{
|
||
newOriginalRow[col.FieldName] = updatedRow[col.FieldName];
|
||
}
|
||
}
|
||
|
||
if (originalDataTable.Columns.Contains(subField.FieldName))
|
||
{
|
||
newOriginalRow[subField.FieldName] = updatedValue;
|
||
}
|
||
|
||
originalDataTable.Rows.Add(newOriginalRow);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("保存失败:" + ex.Message);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:单元格合并</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期: </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="CellMergeEventArgs"/> instance containing the event data.</param>
|
||
protected void OnGridViewCellMerge(object sender, CellMergeEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
GridColumn column = e.Column;
|
||
GridColumnModel model = column.Tag as GridColumnModel;
|
||
if (string.IsNullOrEmpty(model.MergeGroup)) return;
|
||
string[] fields = model.MergeGroup.Trim(',').Split(',');
|
||
bool handled = false;//默认合并
|
||
DataTable table = gridView.GridControl.DataSourceTable();
|
||
for (int i = 0; i < fields.Length; i++)
|
||
{
|
||
int row1 = e.RowHandle1;
|
||
int row2 = e.RowHandle2;
|
||
string McColumn = fields[i] + "";//关联条件列
|
||
if (!table.Columns.Contains(McColumn)) break;
|
||
string value1 = gridView.GetDataRow(row1)[McColumn].ToString();
|
||
string value2 = gridView.GetDataRow(row2)[McColumn].ToString();
|
||
if (value1 != value2)
|
||
{
|
||
//e.Handled = true;
|
||
handled = true;//如果配置多个,有一个分组上下值不同,则不会合并
|
||
}
|
||
//else
|
||
//{
|
||
// //e.Handled = false;
|
||
//}
|
||
}
|
||
e.Handled = handled;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
|
||
LogHelper.Instance.WriteError(ex);
|
||
}
|
||
}
|
||
|
||
private string GetMergeGroupValue(GridColumnModel model, DataRow row)
|
||
{
|
||
if (model == null || row == null || string.IsNullOrEmpty(model.MergeGroup)) return string.Empty;
|
||
|
||
string[] fields = model.MergeGroup.Trim(',').Split(',');
|
||
StringBuilder groupValue = new StringBuilder();
|
||
foreach (string item in fields)
|
||
{
|
||
string fieldName = (item + "").Trim();
|
||
if (string.IsNullOrEmpty(fieldName) || !row.Table.Columns.Contains(fieldName)) continue;
|
||
|
||
groupValue.Append(fieldName);
|
||
groupValue.Append("=");
|
||
groupValue.Append(row[fieldName] + "");
|
||
groupValue.Append("|");
|
||
}
|
||
return groupValue.ToString();
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:表格列求和触发事件</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2020-09-22 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="CustomSummaryEventArgs"/> instance containing the event data.</param>
|
||
protected virtual void OnGridViewSummaryCalculate(object sender, CustomSummaryEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
bool isSum = false;
|
||
//DataRow NRow = e.Row != null ? (e.Row as DataRowView).Row : null;
|
||
var gridView = sender as DevExpress.XtraGrid.Views.Grid.GridView;
|
||
GridSummaryItem gridSummaryItem = e.Item as GridSummaryItem;
|
||
GridColumn gridColumn = gridView.Columns[gridSummaryItem.FieldName] as GridColumn;
|
||
GridColumnModel model = gridColumn.Tag as GridColumnModel;
|
||
GridViewInfo info = gridView.GetViewInfo() as GridViewInfo;
|
||
switch (e.SummaryProcess)
|
||
{
|
||
//calculation entry point 计算开始时
|
||
case DevExpress.Data.CustomSummaryProcess.Start:
|
||
customSum = 0;
|
||
SumText = model.sumCalc;
|
||
sumdr = null;
|
||
if (!string.IsNullOrEmpty(model.sumCalc))
|
||
{
|
||
DataTable SumTab = new DataTable();
|
||
List<string> condition = ReplaceHelper.GetParamFields(model.sumCalc);
|
||
foreach (string item in condition)
|
||
{
|
||
string field = item.Replace("{", "").Replace("}", "");
|
||
SumTab.Columns.Add(field);
|
||
}
|
||
sumdr = SumTab.NewRow();
|
||
}
|
||
break;
|
||
//consequent calculations 计算中自定义计算方法
|
||
case CustomSummaryProcess.Calculate:
|
||
bool isAddCheck = gridView.OptionsSelection.MultiSelect == true && gridView.OptionsSelection.MultiSelectMode == GridMultiSelectMode.CheckBoxRowSelect && gridView.OptionsSelection.EnableAppearanceFocusedCell == false ? true : false;
|
||
DataRow gridRow = null;
|
||
if (isAddCheck && this.SelectedRows != null && this.SelectedRows.Count() > 0)
|
||
{
|
||
if (this.SelectedRows != null && this.SelectedRows.Contains(e.RowHandle))
|
||
{
|
||
gridRow = gridView.GetDataRow(e.RowHandle);
|
||
}
|
||
else
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
gridRow = gridView.GetDataRow(e.RowHandle);
|
||
}
|
||
isSum = !string.IsNullOrWhiteSpace(model.SumCond) ? "true".Equals(EvalHelper.Eval(ReplaceHelper.ReplaceEvalCond(ReplaceHelper.ReplaceRowParam(gridRow, model.SumCond))) + "", StringComparison.OrdinalIgnoreCase) : true;
|
||
if (!string.IsNullOrEmpty(model.sumCalc))
|
||
{
|
||
foreach (DataColumn col in sumdr.Table.Columns)
|
||
{
|
||
sumdr[col.ColumnName] = Convert.ToDecimal(string.IsNullOrEmpty(sumdr[col.ColumnName] + "") ? "0" :
|
||
sumdr[col.ColumnName] + "") + Convert.ToDecimal(string.IsNullOrEmpty(gridRow[col.ColumnName] + "") ? "0" : gridRow[col.ColumnName] + "");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (model.isSumMerge && !string.IsNullOrEmpty(e.FieldValue + ""))
|
||
{
|
||
if (!string.IsNullOrEmpty(model.MergeGroup))
|
||
{
|
||
string currentGroupName = GetMergeGroupValue(model, gridRow);
|
||
bool isMergrGroup = !string.IsNullOrEmpty(currentGroupName) && e.RowHandle != 0 ? currentGroupName.Equals(BeforeGroupName) : false;
|
||
|
||
if (model.CanMerge && BeforeClass == Convert.ToDecimal(e.FieldValue) && isMergrGroup)
|
||
{
|
||
BeforeClass = Convert.ToDecimal(e.FieldValue);
|
||
BeforeGroupName = currentGroupName;
|
||
}
|
||
else
|
||
{
|
||
BeforeClass = Convert.ToDecimal(e.FieldValue);
|
||
BeforeGroupName = currentGroupName;
|
||
if (isSum || String.IsNullOrEmpty(model.SumCond)) customSum += Convert.ToDecimal(e.FieldValue);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (model.CanMerge && BeforeClass == Convert.ToDecimal(e.FieldValue))
|
||
{
|
||
BeforeClass = Convert.ToDecimal(e.FieldValue);
|
||
}
|
||
else
|
||
{
|
||
BeforeClass = Convert.ToDecimal(e.FieldValue); BeforeGroupName = !string.IsNullOrEmpty(model.MergeGroup) && gridRow.Table.Columns.Contains(model.MergeGroup) ? gridRow[model.MergeGroup] + "" : "";
|
||
if (isSum || String.IsNullOrEmpty(model.SumCond)) customSum += Convert.ToDecimal(e.FieldValue);
|
||
}
|
||
}
|
||
}
|
||
if (model.CanSum && isSum)
|
||
{
|
||
if (BeforeClass != Convert.ToDecimal(e.FieldValue))
|
||
{
|
||
customSum += Convert.ToDecimal(e.FieldValue);
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
//final summary value 计算结束
|
||
case CustomSummaryProcess.Finalize:
|
||
if (gridView.GridControl.DataSourceTable().Rows.Count == 0) break;
|
||
if (sumdr != null)
|
||
{
|
||
foreach (DataColumn col in sumdr.Table.Columns)
|
||
{
|
||
string newresult = sumdr[col.ColumnName] + "";
|
||
GridColumn newColumn = gridView.Columns[col.ColumnName] as GridColumn;
|
||
GridColumnModel newModel = newColumn.Tag as GridColumnModel;
|
||
if (!string.IsNullOrEmpty(newModel.DataFormat))
|
||
{
|
||
//计算后先执行保存小数位数
|
||
if (!model.sumCalc.StartsWith("@"))
|
||
{
|
||
newresult = string.Format("{0:" + newModel.DataFormat + "}", Convert.ToDecimal(string.IsNullOrEmpty(newresult) ? "0" : newresult));
|
||
}
|
||
}
|
||
sumdr[col.ColumnName] = newresult + "";
|
||
}
|
||
if (this.ParentControl != null)
|
||
SumText = ParentControl.ReplaceParentControlValue(model.sumCalc);
|
||
SumText = ReplaceHelper.ReplaceRowParam(sumdr, SumText);
|
||
string result = string.Empty;
|
||
if (SumText.StartsWith("@"))
|
||
{
|
||
try
|
||
{
|
||
result = MainImpl.GetResult(SumText.Replace("@", "")) + "";
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
else
|
||
{
|
||
result = EvalHelper.Eval2(ReplaceHelper.ReplaceEvalCond(SumText)) + "";
|
||
}
|
||
if (result.Equals("NaN") || string.IsNullOrWhiteSpace(result)) result = "0";
|
||
|
||
if (string.IsNullOrEmpty(model.DataFormat))
|
||
{
|
||
result = Math.Round(Convert.ToDouble(result), model.Decimals, MidpointRounding.AwayFromZero) + "";
|
||
}
|
||
else
|
||
{
|
||
//计算后先执行保存小数位数
|
||
result = string.Format("{0:" + model.DataFormat + "}", Convert.ToDecimal(result));
|
||
}
|
||
//如果是数值类型,就去掉百分号
|
||
//if (model.FieldType == 7 && result.Contains('%'))
|
||
//{
|
||
// result = (double.Parse(result.Replace("%", "")) * 0.01).ToString();
|
||
//}
|
||
e.TotalValue = result;
|
||
}
|
||
else
|
||
{
|
||
e.TotalValue = customSum;
|
||
BeforeClass = 0;
|
||
BeforeGroupName = "";
|
||
}
|
||
//汇总数据为当前列展示值相加
|
||
if (model.CanSum && model.Summation)
|
||
{
|
||
if (gridColumn != null)
|
||
{
|
||
double value = 0;
|
||
for (int i = 0; i < gridView.RowCount; i++)
|
||
{
|
||
string DisplayText = gridView.GetRowCellDisplayText(i, gridColumn.FieldName) + "";
|
||
if (!string.IsNullOrWhiteSpace(DisplayText)) value += double.Parse(DisplayText);
|
||
}
|
||
e.TotalValue = value;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:创建列</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-08-21 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="item">The dr row.</param>
|
||
protected void InitEditColumns(GridColumn column, GridColumnModel model)
|
||
{
|
||
if (this.DisableFieldSources && model.isVislble)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(model.SqlSource) && !ControlType.IsNotLoadData(model.FieldType))
|
||
{
|
||
Task<DataTable> sourceTask = new Task<DataTable>(() =>
|
||
{
|
||
DataTable dataTable = new DataTable();
|
||
|
||
using (DbConnection sqlConnection = SqlHelper.dbFactory.CreateConnection())
|
||
{
|
||
sqlConnection.ConnectionString = SqlHelper._connection.ConnectionString;
|
||
using (DbCommand cmd = SqlHelper.dbFactory.CreateCommand())
|
||
{
|
||
try
|
||
{
|
||
string sqlValue = BaseImpl.GetDefaultValue(model.SqlSource);
|
||
sqlValue = ReplaceHelper.ReplaceParam(sqlValue);
|
||
if (sqlConnection.State != ConnectionState.Open)
|
||
{
|
||
sqlConnection.Open();
|
||
}
|
||
cmd.Connection = sqlConnection;
|
||
cmd.CommandTimeout = 0;
|
||
cmd.CommandText = sqlValue;
|
||
cmd.CommandType = CommandType.Text;
|
||
DbDataAdapter adapter = SqlHelper.dbFactory.CreateDataAdapter();
|
||
adapter.SelectCommand = cmd;
|
||
adapter.Fill(dataTable);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Console.WriteLine(ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
sqlConnection.Close();
|
||
cmd.Dispose();
|
||
}
|
||
}
|
||
}
|
||
return dataTable;
|
||
});
|
||
sourceTask.Start(DataTableExtend.SchedulerUtil);
|
||
mControlSourceDic.Add(model, sourceTask);
|
||
}
|
||
switch (model.FieldType)
|
||
{
|
||
case ControlType.LabAutoLinefeedText:
|
||
InitAutoLinefeedEdit(column, model);
|
||
break;
|
||
case ControlType.LabPassWordValue:
|
||
InitPasswordEdit(column, model);
|
||
break;
|
||
case ControlType.LabComboxValue:
|
||
case ControlType.LabComboxText:
|
||
case ControlType.LabComboxValueParam:
|
||
case ControlType.LabComboxTextParam:
|
||
InitComboxEdit(column, model);
|
||
break;
|
||
case ControlType.LabProgressBar:
|
||
InitProgressEdit(column);
|
||
break;
|
||
case ControlType.LabCheckBox:
|
||
InitCheckEdit(column);
|
||
break;
|
||
case ControlType.LabAutoCompleteValue:
|
||
case ControlType.LabAutoCompleteText:
|
||
case ControlType.LabAutoCompleteValueParam:
|
||
case ControlType.LabAutoCompleteTextParam:
|
||
case ControlType.LabAutoGridValue:
|
||
case ControlType.LabAutoGridText:
|
||
case ControlType.LabAutoGridValueParam:
|
||
case ControlType.LabAutoGridTextParam:
|
||
InitAutoSearchEdit(column, model);
|
||
break;
|
||
case ControlType.LabDate:
|
||
case ControlType.LabDateTime:
|
||
case ControlType.LabDateTimeShort:
|
||
case ControlType.LabShortDate:
|
||
InitDateTimeEdit(column, model.FieldType);
|
||
break;
|
||
case ControlType.LabDateHalfDay:
|
||
InitSpecialDate(column, model);
|
||
break;
|
||
case ControlType.LabTime:
|
||
case ControlType.LabShortTime:
|
||
InitTimeEdit(column, model.FieldType);
|
||
break;
|
||
case ControlType.LabCalcText:
|
||
InitCalcEdit(column);
|
||
break;
|
||
case ControlType.LabMemoEdit:
|
||
InitMemoEdit(column);
|
||
break;
|
||
case ControlType.LabRemark:
|
||
InitRemarkEdit(column);
|
||
break;
|
||
case ControlType.LabAccount:
|
||
this.cellHelper.AddAmountColumn(column, 11);
|
||
break;
|
||
case ControlType.LabMultiSelectValue:
|
||
case ControlType.LabMultiSelectValueNew:
|
||
case ControlType.LabMultiSelectValueParam:
|
||
case ControlType.LabMultiSelectText:
|
||
case ControlType.LabMultiSelectTextNew:
|
||
case ControlType.LabMultiSelectTextParam:
|
||
InitMutilEdit(column, model);
|
||
break;
|
||
case ControlType.LabMulitTreeText:
|
||
case ControlType.LabMulitTreeTextParam:
|
||
case ControlType.LabMulitTreeValue:
|
||
case ControlType.LabMulitTreeValueParam:
|
||
InitAutoTreeSearchEdit(column, model, true, false);
|
||
break;
|
||
case ControlType.LabMultiComTreeboxValue:
|
||
case ControlType.LabMultiComTreeboxText:
|
||
case ControlType.LabMultiComTreeboxValueParam:
|
||
case ControlType.LabMultiComTreeboxTextParam:
|
||
InitAutoTreeSearchEdit(column, model, true, true);
|
||
break;
|
||
|
||
case ControlType.LabTreeLastlevelValue:
|
||
case ControlType.LabTreeLastlevelText:
|
||
case ControlType.LabCheckTreeLastlevelValue:
|
||
case ControlType.LabCheckTreeLastlevelText:
|
||
InitAutoTreeSearchEdit(column, model, false, false);
|
||
break;
|
||
case ControlType.LabTreeLookValue:
|
||
case ControlType.LabTreeLookText:
|
||
case ControlType.LabCheckTreeLookValue:
|
||
case ControlType.LabCheckTreeLookText:
|
||
InitAutoTreeSearchEdit(column, model, false, true);
|
||
break;
|
||
|
||
case ControlType.LabComboxCheckListValue:
|
||
case ControlType.LabComboxCheckListText:
|
||
InitMutilComboxEdit(column, model);
|
||
break;
|
||
//case ControlType.LabQQ:
|
||
// column.Tag = "QQ";
|
||
// break;
|
||
//case ControlType.LabWWW:
|
||
// column.Tag = "Brower";
|
||
// break;
|
||
case ControlType.LabRichEdit:
|
||
InitRichEdit(column);
|
||
break;
|
||
case ControlType.LabPic:
|
||
InitPicEdit(column);
|
||
break;
|
||
case ControlType.LabPicUrl:
|
||
//InitPicEditUrl(column, model);
|
||
// 用工具类创建图片列(绑定 Tag、Repository、UnboundType)
|
||
LabPicUrlPreview.InitPicColumn(this.gridControl, column, model);
|
||
break;
|
||
case ControlType.LabSelectReturnId:
|
||
case ControlType.LabSelectReturnText:
|
||
InitSelectReturnId(column, model);
|
||
break;
|
||
case ControlType.LabSelectReturnIdNew:
|
||
case ControlType.LabSelectReturnTextNew:
|
||
InitSelectReturnIdNew(column, model);
|
||
break;
|
||
case ControlType.LabSelectReturnRows:
|
||
InitSelectReturnRows(column, model);
|
||
break;
|
||
case ControlType.LabSelectReturnRowsNew:
|
||
InitSelectReturnRowsNew(column, model);
|
||
break;
|
||
case ControlType.DynamicallyGeneratedSql:
|
||
InitSqlGenerate(column, model);
|
||
break;
|
||
case ControlType.HighShotMeter:
|
||
InitHighShotMeterEdit(column, model);
|
||
break;
|
||
case ControlType.BarCode128B:
|
||
InitBarCode128BEdit(column, model);
|
||
break;
|
||
case ControlType.LabHyperlink:
|
||
InitHyperlink(column, model);
|
||
break;
|
||
case ControlType.LabRightlink:
|
||
InitRightlink(column, model);
|
||
break;
|
||
case ControlType.LabComboxPopupValue:
|
||
case ControlType.LabComboxPopupText:
|
||
InitComboxPopup(column, model);
|
||
break;
|
||
case ControlType.LabGridPopupValue:
|
||
case ControlType.LabGridPopupText:
|
||
//case ControlType.LabGridPopupMutilValue:
|
||
//case ControlType.LabGridPopupMutilText:
|
||
InitGridPopup(column, model);
|
||
break;
|
||
case ControlType.LabModuleAddRowsID:
|
||
case ControlType.LabModuleAddRowsText:
|
||
InitModuleReturnLine(column, model);
|
||
break;
|
||
case ControlType.LabModuleSelectReturnIdExtended:
|
||
case ControlType.LabSearchReturnIdExtended:
|
||
InitExtendedReturn(column, model);
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
// 特殊处理
|
||
if (ControlType.LabTreeType == model.FieldType && !IsSpecModel)
|
||
{
|
||
InitComboxEdit(column, model);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:设置列格式化</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-03-21 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
/// <param name="model">The model.</param>
|
||
protected virtual void SetColumnFormat(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
if (gridColumn == null || model == null) return;
|
||
|
||
// 格式化数字
|
||
if (!string.IsNullOrEmpty(model.DataFormat))
|
||
{
|
||
if (model.FieldType == ControlType.LabTextInt || model.FieldType == ControlType.LabCalcText || model.FieldType == ControlType.LabAccount)
|
||
{
|
||
gridColumn.DisplayFormat.FormatType = FormatType.Numeric;
|
||
gridColumn.DisplayFormat.FormatString = model.DataFormat;
|
||
}
|
||
else
|
||
{
|
||
gridColumn.DisplayFormat.FormatType = FormatType.Custom;
|
||
gridColumn.DisplayFormat.FormatString = model.DataFormat;
|
||
}
|
||
}
|
||
// 特殊字段格式化
|
||
if (model.CanAccuracy)
|
||
{
|
||
gridColumn.DisplayFormat.FormatType = FormatType.Numeric;
|
||
gridColumn.DisplayFormat.FormatString = "F2";
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:设置列汇总</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-03-21 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
/// <param name="model">The model.</param>
|
||
protected virtual void SetColumnSumming(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
// 设置底部合计
|
||
if (gridColumn.VisibleIndex >= 0 && this.isFirstVisableCol)
|
||
{
|
||
gridView.OptionsView.ShowFooter = true;
|
||
gridColumn.Summary.AddRange(new GridSummaryItem[] { new GridColumnSummaryItem(DevExpress.Data.SummaryItemType.Count, gridColumn.FieldName, TotalFormat) });
|
||
if (SystemInfo.Instance.GroupSpecialMode)
|
||
{
|
||
//gridView.GroupSummary.Add(new GridGroupSummaryItem(DevExpress.Data.SummaryItemType.Count, gridColumn.FieldName, null, "合计: {0:#,###}行"));
|
||
gridView.OptionsView.GroupFooterShowMode = GroupFooterShowMode.VisibleAlways;
|
||
}
|
||
else
|
||
{
|
||
gridView.GroupSummary.AddRange(new GridSummaryItem[] { new GridGroupSummaryItem(DevExpress.Data.SummaryItemType.Count, gridColumn.FieldName, null, TotalFormat) });
|
||
}
|
||
|
||
|
||
|
||
isFirstVisableCol = false;
|
||
}
|
||
else
|
||
{
|
||
if (model.CanSum)
|
||
{
|
||
gridColumn.Summary.AddRange(new GridSummaryItem[] { new GridColumnSummaryItem((!string.IsNullOrEmpty(model.sumCalc) || !string.IsNullOrEmpty(model.SumCond) || model.isSumMerge) ? SummaryItemType.Custom : SummaryItemType.Sum, gridColumn.FieldName, model.SumText + "{0:" + model.DataFormat + "}") });
|
||
if (SystemInfo.Instance.GroupSpecialMode)
|
||
{
|
||
gridView.GroupSummary.Add(new GridGroupSummaryItem((!string.IsNullOrEmpty(model.sumCalc) || !string.IsNullOrEmpty(model.SumCond) || model.isSumMerge) ? SummaryItemType.Custom : SummaryItemType.Sum, gridColumn.FieldName, gridColumn, model.SumText + "{0:" + model.DataFormat + "}"));
|
||
gridView.OptionsView.GroupFooterShowMode = GroupFooterShowMode.VisibleAlways;
|
||
}
|
||
else
|
||
{
|
||
gridView.GroupSummary.AddRange(new GridSummaryItem[] { new GridGroupSummaryItem((!string.IsNullOrEmpty(model.sumCalc) || !string.IsNullOrEmpty(model.SumCond) || model.isSumMerge) ? SummaryItemType.Custom : SummaryItemType.Sum, gridColumn.FieldName, null, model.SumText + "{0:" + model.DataFormat + "}") });
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 行转列多表头列合计。动态列创建在独立的BandedGridView里,不能直接复用主表格的SetColumnSumming。
|
||
/// </summary>
|
||
private void SetDynamicBandedColumnSumming(BandedGridView view, BandedGridColumn gridColumn, GridColumnModel model, ref bool isFirstVisibleColumn, bool useSimpleSum)
|
||
{
|
||
if (view == null || gridColumn == null || model == null || !gridColumn.Visible) return;
|
||
|
||
if (isFirstVisibleColumn)
|
||
{
|
||
view.OptionsView.ShowFooter = true;
|
||
gridColumn.Summary.AddRange(new GridSummaryItem[] { new GridColumnSummaryItem(DevExpress.Data.SummaryItemType.Count, gridColumn.FieldName, TotalFormat) });
|
||
if (SystemInfo.Instance.GroupSpecialMode)
|
||
{
|
||
view.OptionsView.GroupFooterShowMode = GroupFooterShowMode.VisibleAlways;
|
||
}
|
||
else
|
||
{
|
||
view.GroupSummary.AddRange(new GridSummaryItem[] { new GridGroupSummaryItem(DevExpress.Data.SummaryItemType.Count, gridColumn.FieldName, null, TotalFormat) });
|
||
}
|
||
isFirstVisibleColumn = false;
|
||
return;
|
||
}
|
||
|
||
if (!model.CanSum) return;
|
||
|
||
SummaryItemType summaryType = useSimpleSum ? SummaryItemType.Sum : ((!string.IsNullOrEmpty(model.sumCalc) || !string.IsNullOrEmpty(model.SumCond) || model.isSumMerge) ? SummaryItemType.Custom : SummaryItemType.Sum);
|
||
string format = model.SumText + "{0:" + model.DataFormat + "}";
|
||
view.OptionsView.ShowFooter = true;
|
||
gridColumn.Summary.AddRange(new GridSummaryItem[] { new GridColumnSummaryItem(summaryType, gridColumn.FieldName, format) });
|
||
if (SystemInfo.Instance.GroupSpecialMode)
|
||
{
|
||
view.GroupSummary.Add(new GridGroupSummaryItem(summaryType, gridColumn.FieldName, gridColumn, format));
|
||
view.OptionsView.GroupFooterShowMode = GroupFooterShowMode.VisibleAlways;
|
||
}
|
||
else
|
||
{
|
||
view.GroupSummary.AddRange(new GridSummaryItem[] { new GridGroupSummaryItem(summaryType, gridColumn.FieldName, null, format) });
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 行转列树形多表头列合计。TreeList使用SummaryFooter,需单独设置。
|
||
/// </summary>
|
||
private void SetDynamicTreeColumnSumming(DevExpress.XtraTreeList.TreeList treeList, DevExpress.XtraTreeList.Columns.TreeListColumn gridColumn, GridColumnModel model, ref bool isFirstVisibleColumn)
|
||
{
|
||
if (treeList == null || gridColumn == null || model == null || !gridColumn.Visible) return;
|
||
|
||
if (isFirstVisibleColumn)
|
||
{
|
||
treeList.OptionsView.ShowSummaryFooter = true;
|
||
gridColumn.AllNodesSummary = true;
|
||
gridColumn.SummaryFooter = DevExpress.XtraTreeList.SummaryItemType.Count;
|
||
gridColumn.RowFooterSummaryStrFormat = TotalFormat;
|
||
isFirstVisibleColumn = false;
|
||
return;
|
||
}
|
||
|
||
if (!model.CanSum) return;
|
||
|
||
treeList.OptionsView.ShowSummaryFooter = true;
|
||
gridColumn.AllNodesSummary = true;
|
||
gridColumn.SummaryFooter = DevExpress.XtraTreeList.SummaryItemType.Sum;
|
||
gridColumn.RowFooterSummaryStrFormat = model.SumText + "{0:" + model.DataFormat + "}";
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:创建只读列</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-08-21 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="table">The table.</param>
|
||
/// <param name="customEnum">需要显示表格列右键菜单(保存列属性、重置列属性)则传递此值.</param>
|
||
public virtual void SetReadOnlyColumns(DataTable table, string customColumKey = "")
|
||
{
|
||
Dictionary<object, Hashtable> dataCaches = Model != null ? Model.DataCaches : null;
|
||
this.mLoading = false;
|
||
this.InitGridColumsTab = table;
|
||
this.CustomColumKey = customColumKey;
|
||
this.GridView.Columns.Clear();
|
||
this.ColumnList.Clear();
|
||
if (table == null) return;
|
||
this.gridView.BeginUpdate();
|
||
for (int i = 0; i < table.Rows.Count; i++)
|
||
{
|
||
GridColumnModel model = new GridColumnModel(table.Rows[i], false);
|
||
|
||
GridColumn gridColumn = new GridColumn();
|
||
gridColumn.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
|
||
|
||
gridColumn.FieldName = model.FieldName;
|
||
gridColumn.Name = model.FieldName;
|
||
gridColumn.Caption = model.FieldText;
|
||
gridColumn.Width = model.Width;
|
||
gridColumn.Tag = model;
|
||
gridColumn.VisibleIndex = i;
|
||
gridColumn.Visible = model.Visible && model.Width > 0;
|
||
gridColumn.OptionsFilter.FilterPopupMode = FilterPopupMode.CheckedList;
|
||
gridColumn.OptionsColumn.AllowEdit = false;
|
||
gridColumn.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
|
||
|
||
gridColumn.OptionsColumn.AllowMerge = model.CanMerge ? DefaultBoolean.True : DefaultBoolean.False;
|
||
if (model.CanMerge) gridView.OptionsView.AllowCellMerge = true;
|
||
|
||
if (model.FieldType == ControlType.LabPic)
|
||
{
|
||
ImageList.Add(model.FieldName);
|
||
}
|
||
if (EnabledChangeColor)
|
||
{
|
||
if (!model.Edit)
|
||
{
|
||
gridColumn.AppearanceHeader.Options.UseForeColor = true;
|
||
gridColumn.AppearanceHeader.ForeColor = ColorTranslator.FromHtml(HeaderColor);
|
||
}
|
||
if (model.CanNull)
|
||
{
|
||
gridColumn.AppearanceHeader.Options.UseForeColor = true;
|
||
gridColumn.AppearanceHeader.ForeColor = RequiredForceColor;
|
||
}
|
||
}
|
||
|
||
if (model.DataAlignment > 0)
|
||
{
|
||
gridColumn.AppearanceCell.Options.UseTextOptions = true;
|
||
gridColumn.AppearanceCell.TextOptions.HAlignment = model.DataAlignment == 1 ? DevExpress.Utils.HorzAlignment.Center : DevExpress.Utils.HorzAlignment.Far;
|
||
}
|
||
if (!string.IsNullOrEmpty(model.FontName) || model.FontSize != 0)
|
||
{
|
||
//gridColumn.AppearanceCell.Options.UseFont = true;//设置后数值和英文会加粗,2026-3-17 注释
|
||
//gridColumn.AppearanceCell.Font = new System.Drawing.Font(model.FontName, gridColumn.AppearanceCell.Font.Size);
|
||
gridColumn.AppearanceCell.Font = new System.Drawing.Font(string.IsNullOrEmpty(model.FontName) ? gridColumn.AppearanceCell.Font.Name : model.FontName, model.FontSize == 0 ? gridColumn.AppearanceCell.Font.Size : model.FontSize);
|
||
|
||
}
|
||
|
||
this.SetColumnFormat(gridColumn, model);
|
||
this.SetColumnSumming(gridColumn, model);
|
||
// 创建列
|
||
this.InitEditColumns(gridColumn, model);
|
||
this.gridView.Columns.Add(gridColumn);
|
||
this.ColumnList.Add(model);
|
||
if (model.RepeatedVerification)
|
||
{
|
||
this.RepeatedVerificationNames.Add(model.FieldName);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(model.PromptText))
|
||
{
|
||
PromptMessage.Add(model.FieldName, model.PromptText);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(model.ColumnAnnotation))
|
||
{
|
||
gridColumn.ToolTip = model.ColumnAnnotation;
|
||
}
|
||
|
||
}
|
||
|
||
//创建右键菜单列
|
||
if (!dataCaches.GetValue(this, "RightMenuBtn", out DataTable rightMentTab))
|
||
{
|
||
if (this.Model != null)
|
||
{
|
||
rightMentTab = BaseModuleImpl.GetBaseGridRightMenus(this.Model.ModuleCode);
|
||
}
|
||
}
|
||
//左侧如果配置表格,也和出现和主表一样的操作列。先限制为左侧固定不加载(要加载的话要获取左侧的fieldKey)
|
||
if (this.Model != null && BaseModuleImpl.IsGridViewRightMenuBtnEdit(rightMentTab) && !customColumKey.Contains("BaseLeftGridView_"))
|
||
{
|
||
this.InitRightMenuBtnEdit();
|
||
}
|
||
if (!dataCaches.GetValue(this, "CustomColumnByDatabase", out DataTable customTable))
|
||
{
|
||
customTable = this.gridView.GetCustomColumnByDatabase(this.CustomColumKey);
|
||
}
|
||
this.SetCustomColumns(customTable);
|
||
|
||
////创建右键菜单列
|
||
//if (this.Model != null && BaseModuleImpl.IsGridViewRightMenuBtnEdit(this.Model.ModuleCode)) this.InitRightMenuBtnEdit();
|
||
//this.SetCustomColumns();
|
||
this.gridView.EndUpdate();
|
||
//延迟加载数据源
|
||
this.mLoading = false;
|
||
this.mTimer.Tick += new EventHandler(mTimerTick);
|
||
this.mTimer.Start();
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:延迟加载数据源</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期: </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected void mTimerTick(object sender, EventArgs e)
|
||
{
|
||
if (!mLoading)
|
||
{
|
||
mLoading = true;
|
||
try
|
||
{
|
||
if (this.OnDataSourceBindCallBack != null)
|
||
{
|
||
this.OnDataSourceBindCallBack(null, null);
|
||
}
|
||
SetColumnsSource();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Console.WriteLine(ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
mControlSourceDic.Clear();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
this.mTimer.Stop();
|
||
this.mTimer.Dispose();
|
||
}
|
||
}
|
||
private void SetColumnsSource(bool UpdateColumnRefresh = false)
|
||
{
|
||
foreach (GridColumnModel item in mControlList)
|
||
{
|
||
if (this.DisableFieldSources && item.isVislble) continue;
|
||
if (ControlType.IsNotLoadData(item.FieldType)) continue;
|
||
if (UpdateColumnRefresh && !string.IsNullOrWhiteSpace(UpdateColumns) && !UpdateColumns.Split(',').Contains(item.FieldName)) continue;
|
||
if (!string.IsNullOrWhiteSpace(item.SqlSource))
|
||
{
|
||
DataTable dataTable = new DataTable();
|
||
if (mControlSourceDic.ContainsKey(item))
|
||
{
|
||
dataTable = mControlSourceDic[item].Result;
|
||
}
|
||
else
|
||
{
|
||
dataTable = BaseImpl.GetDataTableResult(item.SqlSource);
|
||
}
|
||
Application.DoEvents();
|
||
if (!item.Visible) continue;
|
||
switch (item.FieldType)
|
||
{
|
||
case ControlType.LabComboxValue:
|
||
case ControlType.LabComboxText:
|
||
case ControlType.LabComboxValueParam:
|
||
case ControlType.LabComboxTextParam:
|
||
case ControlType.LabTreeType:
|
||
RepositoryItemLookUpEdit lookUp = GridView.Columns[item.FieldName].ColumnEdit as RepositoryItemLookUpEdit;
|
||
//if (false)
|
||
//{
|
||
// //设置有下划线不显示,其余的显示
|
||
// foreach (LookUpColumnInfo lookUpColumnInfo in lookUp.Columns)
|
||
// {
|
||
// if(lookUpColumnInfo.FieldName.Substring(0, 1) == "_") lookUpColumnInfo.Visible = false;
|
||
// }
|
||
// foreach (DataColumn dcol in dataTable.Columns)
|
||
// {
|
||
// if ((dcol.ColumnName.Substring(0, 1) != "_") && (dcol.ColumnName.ToLower() != item.ValueMember.ToLower()) && (dcol.ColumnName.ToLower() != item.TextMember.ToLower()) && (dcol.ColumnName.ToLower() != "remark") && ((int)dcol.ColumnName[0] > 127))
|
||
// {
|
||
// LookUpColumnInfo textColumn = new LookUpColumnInfo();
|
||
// textColumn.Caption = textColumn.FieldName = dcol.ColumnName;
|
||
// textColumn.Visible = true;
|
||
// lookUp.Columns.Add(textColumn);
|
||
// }
|
||
// }
|
||
//}
|
||
lookUp.DataSource = dataTable;
|
||
break;
|
||
case ControlType.LabAutoCompleteValue:
|
||
case ControlType.LabAutoCompleteText:
|
||
case ControlType.LabAutoCompleteValueParam:
|
||
case ControlType.LabAutoCompleteTextParam:
|
||
case ControlType.LabAutoGridValue:
|
||
case ControlType.LabAutoGridText:
|
||
case ControlType.LabAutoGridValueParam:
|
||
case ControlType.LabAutoGridTextParam:
|
||
int popWidth = 0;
|
||
RepositoryItemGridLookUpEdit lookGridUp = GridView.Columns[item.FieldName].ColumnEdit as RepositoryItemGridLookUpEdit;
|
||
DataTable table = dataTable;
|
||
lookGridUp.DataSource = table;
|
||
//Type dataType = table.Columns[item.ValueMember].DataType;
|
||
//if (dataType.Name == "Int32")
|
||
//{
|
||
// lookGridUp.View.Columns[item.ValueMember].Tag = table.AsEnumerable().Select(t => t.Field<int>(item.ValueMember)).Max();
|
||
//}
|
||
//else if(dataType.Name == "String")
|
||
//{
|
||
//}
|
||
if (table.Columns.Contains("remark") && lookGridUp.View.Columns.FirstOrDefault(x => x.FieldName == "remark") == null)
|
||
{
|
||
GridColumn remarkColumn = new GridColumn();
|
||
remarkColumn.Caption = "备注";
|
||
remarkColumn.Name = remarkColumn.FieldName = "remark";
|
||
remarkColumn.Visible = true;
|
||
lookGridUp.View.Columns.Add(remarkColumn);
|
||
}
|
||
//if (false)
|
||
//{
|
||
// //设置有下划线不显示,其余的显示
|
||
// foreach (GridColumn gridColumn in lookGridUp.View.Columns)
|
||
// {
|
||
// if (gridColumn.FieldName.Substring(0, 1) == "_") gridColumn.Visible = false;
|
||
// }
|
||
// foreach (DataColumn dcol in dataTable.Columns)
|
||
// {
|
||
// if ((dcol.ColumnName.Substring(0, 1) != "_") && (dcol.ColumnName.ToLower() != item.ValueMember.ToLower()) && (dcol.ColumnName.ToLower() != item.TextMember.ToLower()) && (dcol.ColumnName.ToLower() != "remark") && ((int)dcol.ColumnName[0] > 127))
|
||
// {
|
||
// GridColumn otherColumn = new GridColumn();
|
||
// otherColumn.Name = otherColumn.FieldName = otherColumn.Caption = dcol.ColumnName;
|
||
// otherColumn.Visible = true;
|
||
// lookGridUp.View.Columns.Add(otherColumn);
|
||
|
||
// }
|
||
// }
|
||
//}
|
||
foreach (DataColumn dcol in table.Columns)
|
||
{
|
||
if ((dcol.ColumnName.Substring(0, 1) != "_") && lookGridUp.View.Columns.FirstOrDefault(x => x.FieldName == dcol.ColumnName) == null)
|
||
{
|
||
if ((dcol.ColumnName.ToLower() != item.ValueMember.ToLower()) && (dcol.ColumnName.ToLower() != item.TextMember.ToLower()) && (dcol.ColumnName.ToLower() != "remark") && ((int)dcol.ColumnName[0] > 127))
|
||
{
|
||
GridColumn otherColumn = new GridColumn();
|
||
otherColumn.Name = otherColumn.FieldName = otherColumn.Caption = dcol.ColumnName;
|
||
otherColumn.Visible = true;
|
||
lookGridUp.View.Columns.Add(otherColumn);
|
||
}
|
||
if (lookGridUp.View.Columns.FirstOrDefault(x => x.FieldName == dcol.ColumnName) != null)
|
||
{
|
||
GridColumn gCol = lookGridUp.View.Columns[dcol.ColumnName];
|
||
gCol.Width = CalcMaxColumnWidth(table, gCol.Name);
|
||
popWidth += gCol.Width;
|
||
}
|
||
}
|
||
}
|
||
lookGridUp.PopupFormSize = new System.Drawing.Size(popWidth, lookGridUp.PopupFormSize.Height);
|
||
break;
|
||
//case ControlType.LabMultiSelectValue:
|
||
//case ControlType.LabMultiSelectValueParam:
|
||
//case ControlType.LabMultiSelectText:
|
||
//case ControlType.LabMultiSelectTextParam:
|
||
// RepositoryItemCheckedComboBoxEdit checkCombox = GridView.Columns[item.FieldName].ColumnEdit as RepositoryItemCheckedComboBoxEdit;
|
||
// checkCombox.DataSource = BaseImpl.GetDataTableResult(item.SqlSource);
|
||
// break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:创建只读列</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-11-14 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="table">The table.</param>
|
||
/// <param name="customColumKey">The custom colum key.</param>
|
||
/// <param name="font">The font.</param>
|
||
public virtual void SetReadOnlyColumns(DataTable table, string customColumKey, Font font, DefaultBoolean allSort)
|
||
{
|
||
this.CustomColumKey = customColumKey;
|
||
this.GridView.Columns.Clear();
|
||
this.ColumnList.Clear();
|
||
if (table == null) return;
|
||
for (int i = 0; i < table.Rows.Count; i++)
|
||
{
|
||
GridColumnModel model = new GridColumnModel(table.Rows[i], false);
|
||
|
||
GridColumn gridColumn = new GridColumn();
|
||
gridColumn.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
|
||
gridColumn.FieldName = model.FieldName;
|
||
gridColumn.Name = model.FieldName;
|
||
gridColumn.Caption = model.FieldText;
|
||
gridColumn.Width = model.Width;
|
||
gridColumn.Tag = model;
|
||
gridColumn.VisibleIndex = i;
|
||
gridColumn.Visible = model.Visible && model.Width > 0;
|
||
gridColumn.OptionsFilter.FilterPopupMode = FilterPopupMode.CheckedList;
|
||
gridColumn.OptionsColumn.AllowEdit = false;
|
||
gridColumn.OptionsColumn.AllowSort = allSort;
|
||
gridColumn.AppearanceHeader.Options.UseFont = true;
|
||
gridColumn.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
|
||
gridColumn.AppearanceHeader.Font = font;
|
||
gridColumn.OptionsColumn.AllowMerge = model.CanMerge ? DefaultBoolean.True : DefaultBoolean.False;
|
||
if (model.CanMerge) gridView.OptionsView.AllowCellMerge = true;
|
||
|
||
if (model.DataAlignment > 0)
|
||
{
|
||
gridColumn.AppearanceCell.Options.UseTextOptions = true;
|
||
gridColumn.AppearanceCell.TextOptions.HAlignment = model.DataAlignment == 1 ? DevExpress.Utils.HorzAlignment.Center : DevExpress.Utils.HorzAlignment.Far;
|
||
}
|
||
|
||
if (model.FieldType == ControlType.LabPic)
|
||
{
|
||
ImageList.Add(model.FieldName);
|
||
}
|
||
|
||
//if (model.FieldText.Contains("\\r\\n"))
|
||
//{
|
||
// gridColumn.AppearanceHeader.Options.UseTextOptions = true;
|
||
// gridColumn.AppearanceHeader.TextOptions.WordWrap = WordWrap.Wrap;
|
||
// gridColumn.Caption = model.FieldText.Replace("\\r\\n", " ");
|
||
// gridView.ColumnPanelRowHeight = 35;
|
||
//}
|
||
|
||
this.SetColumnFormat(gridColumn, model);
|
||
this.SetColumnSumming(gridColumn, model);
|
||
// 创建列
|
||
this.InitEditColumns(gridColumn, model);
|
||
this.gridView.Columns.Add(gridColumn);
|
||
this.ColumnList.Add(model);
|
||
if (model.RepeatedVerification)
|
||
{
|
||
this.RepeatedVerificationNames.Add(model.FieldName);
|
||
}
|
||
|
||
|
||
if (model.FieldType == 9)
|
||
{
|
||
gridColumn.AppearanceCell.TextOptions.VAlignment = VertAlignment.Center;
|
||
gridColumn.AppearanceCell.TextOptions.WordWrap = WordWrap.Wrap;
|
||
}
|
||
|
||
if (!string.IsNullOrWhiteSpace(model.PromptText))
|
||
{
|
||
PromptMessage.Add(model.FieldName, model.PromptText);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(model.ColumnAnnotation))
|
||
{
|
||
gridColumn.ToolTip = model.ColumnAnnotation;
|
||
}
|
||
}
|
||
DataTable customTable = this.gridView.GetCustomColumnByDatabase(this.CustomColumKey);
|
||
this.SetCustomColumns(customTable);
|
||
|
||
// 延迟加载数据源
|
||
this.mTimer.Tick += new EventHandler(mTimerTick);
|
||
this.mTimer.Start();
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:设置可编辑列</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-08-21 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="table">The table.</param>
|
||
/// <param name="customKey">需要显示表格列右键菜单(保存列属性、重置列属性)则传递此值.</param>
|
||
public virtual void SetEditColumns(DataTable table, string customColumKey = "")
|
||
{
|
||
this.mLoading = false;
|
||
this.InitGridColumsTab = table;
|
||
this.CustomColumKey = customColumKey;
|
||
this.GridView.Columns.Clear();
|
||
this.ColumnList.Clear();
|
||
if (table == null) return;
|
||
|
||
Console.WriteLine(DateTime.Now);
|
||
int index = 0;
|
||
foreach (DataRow item in table.Rows)
|
||
{
|
||
GridColumnModel model = new GridColumnModel(item);
|
||
GridColumn gridColumn = new GridColumn();
|
||
gridColumn.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
|
||
gridColumn.FieldName = model.FieldName;
|
||
gridColumn.Name = model.FieldName;
|
||
gridColumn.Caption = model.FieldText;
|
||
gridColumn.Width = model.Width;
|
||
gridColumn.Tag = model;
|
||
gridColumn.VisibleIndex = index++;
|
||
gridColumn.Visible = model.Visible && model.Width > 0;
|
||
gridColumn.OptionsColumn.AllowEdit = model.Edit;
|
||
//gridColumn.OptionsColumn.AllowMerge = model.CanMerge ? DefaultBoolean.True : DefaultBoolean.False;
|
||
gridColumn.OptionsColumn.ShowInCustomizationForm = model.Width == 0 ? false : true;
|
||
|
||
gridColumn.OptionsFilter.FilterPopupMode = FilterPopupMode.CheckedList;
|
||
|
||
gridColumn.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
|
||
gridColumn.OptionsColumn.AllowMerge = model.CanMerge ? DefaultBoolean.True : DefaultBoolean.False;
|
||
//gridView.OptionsSelection.MultiSelect=true;
|
||
if (model.CanMerge) gridView.OptionsView.AllowCellMerge = true;
|
||
|
||
|
||
if (model.FieldType == ControlType.LabPic)
|
||
{
|
||
ImageList.Add(model.FieldName);
|
||
}
|
||
|
||
//gridView.OptionsView.AllowCellMerge = gridView.OptionsView.AllowCellMerge;
|
||
if (!string.IsNullOrWhiteSpace(model.TitleColor))
|
||
{
|
||
gridColumn.AppearanceHeader.Options.UseForeColor = true;
|
||
gridColumn.AppearanceHeader.ForeColor = ColorTranslator.FromHtml(model.TitleColor);
|
||
}
|
||
|
||
if (EnabledChangeColor)
|
||
{
|
||
if (!model.Edit)
|
||
{
|
||
gridColumn.AppearanceHeader.Options.UseForeColor = true;
|
||
gridColumn.AppearanceHeader.ForeColor = ColorTranslator.FromHtml(HeaderColor);
|
||
}
|
||
if (model.CanNull)
|
||
{
|
||
gridColumn.AppearanceHeader.Options.UseForeColor = true;
|
||
gridColumn.AppearanceHeader.ForeColor = RequiredForceColor;
|
||
}
|
||
}
|
||
if (model.DataAlignment > 0)
|
||
{
|
||
gridColumn.AppearanceCell.Options.UseTextOptions = true;
|
||
gridColumn.AppearanceCell.TextOptions.HAlignment = model.DataAlignment == 1 ? DevExpress.Utils.HorzAlignment.Center : DevExpress.Utils.HorzAlignment.Far;
|
||
}
|
||
//if (!string.IsNullOrEmpty(model.FontName))
|
||
//{
|
||
// gridColumn.AppearanceCell.Options.UseFont = true;
|
||
// gridColumn.AppearanceCell.Font = new System.Drawing.Font(model.FontName, gridColumn.AppearanceCell.Font.Size);
|
||
//}
|
||
//修改字体控制
|
||
if (!string.IsNullOrEmpty(model.FontName) || model.FontSize != 0)
|
||
{
|
||
//gridColumn.AppearanceCell.Options.UseFont = true;//设置后数值和英文会加粗,2026-3-17 注释
|
||
//gridColumn.AppearanceCell.Font = new System.Drawing.Font(model.FontName, gridColumn.AppearanceCell.Font.Size);
|
||
gridColumn.AppearanceCell.Font = new System.Drawing.Font(string.IsNullOrEmpty(model.FontName) ? gridColumn.AppearanceCell.Font.Name : model.FontName, model.FontSize == 0 ? gridColumn.AppearanceCell.Font.Size : model.FontSize);
|
||
|
||
gridColumn.AppearanceHeader.Font = new System.Drawing.Font(string.IsNullOrEmpty(model.FontName) ?
|
||
gridColumn.AppearanceHeader.Font.Name : model.FontName, model.FontSize == 0 ? gridColumn.AppearanceHeader.Font.Size : model.FontSize);
|
||
gridColumn.AppearanceHeader.Options.UseFont = true;
|
||
}
|
||
if (model.IsFixColumn == 1)
|
||
{
|
||
gridColumn.Fixed = FixedStyle.Left;
|
||
}
|
||
//工具中设置的冻结列
|
||
if (model.FrozenFlag)
|
||
{
|
||
FrozenColumns.Add(gridColumn);
|
||
}
|
||
if (!string.IsNullOrEmpty(model.AutoPadDataReleColName))
|
||
{
|
||
AutoPadDataReleColList.Add(model);
|
||
}
|
||
// 创建列
|
||
this.InitEditColumns(gridColumn, model);
|
||
// 设置列格式化、汇总
|
||
this.SetColumnFormat(gridColumn, model);
|
||
this.SetColumnSumming(gridColumn, model);
|
||
this.gridView.Columns.Add(gridColumn);
|
||
this.ColumnList.Add(model);
|
||
if (model.RepeatedVerification)
|
||
{
|
||
this.RepeatedVerificationNames.Add(model.FieldName);
|
||
}
|
||
|
||
|
||
if (model.FieldType == 9)
|
||
{
|
||
gridColumn.AppearanceCell.TextOptions.VAlignment = VertAlignment.Center;
|
||
gridColumn.AppearanceCell.TextOptions.WordWrap = WordWrap.Wrap;
|
||
}
|
||
|
||
if (!string.IsNullOrWhiteSpace(model.PromptText))
|
||
{
|
||
PromptMessage.Add(model.FieldName, model.PromptText);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(model.ColumnAnnotation))
|
||
{
|
||
gridColumn.ToolTip = model.ColumnAnnotation;
|
||
}
|
||
}
|
||
|
||
if (Model != null)
|
||
{
|
||
if (!Model.DataCaches.GetValue(this, "RightMenuBtn", out DataTable rightMentTab))
|
||
{
|
||
if (this.Model != null)
|
||
{
|
||
rightMentTab = BaseModuleImpl.GetBaseGridRightMenus(this.Model.ModuleCode);
|
||
}
|
||
}
|
||
//左侧如果配置表格,也和出现和主表一样的操作列。先限制为左侧固定不加载(要加载的话要获取左侧的fieldKey)
|
||
if (this.Model != null && BaseModuleImpl.IsGridViewRightMenuBtnEdit(rightMentTab) && !customColumKey.Contains("BaseLeftGridView_"))
|
||
{
|
||
this.InitRightMenuBtnEdit();
|
||
}
|
||
}
|
||
|
||
if (Model != null && !Model.DataCaches.GetValue(this, "CustomColumnByDatabase", out DataTable customTable))
|
||
{
|
||
customTable = this.gridView.GetCustomColumnByDatabase(this.CustomColumKey);
|
||
this.SetCustomColumns(customTable);
|
||
}
|
||
else
|
||
{
|
||
DataTable customTableNew = this.gridView.GetCustomColumnByDatabase(this.CustomColumKey);
|
||
this.SetCustomColumns(customTableNew);
|
||
}
|
||
|
||
|
||
|
||
|
||
//冻结
|
||
foreach (GridColumn item in FrozenColumns)
|
||
{
|
||
item.Fixed = FixedStyle.Left;
|
||
}
|
||
|
||
Console.WriteLine(DateTime.Now);
|
||
|
||
// 延迟加载数据源
|
||
this.mTimer.Tick += new EventHandler(mTimerTick);
|
||
this.mTimer.Start();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取数据源缓存
|
||
/// </summary>
|
||
/// <param name="cachesDic"></param>
|
||
/// <param name="customColumKey"></param>
|
||
public void GetDataCaches(Dictionary<object, Hashtable> cachesDic, string customColumKey = "")
|
||
{
|
||
Task<DynamicModel> dynamicModelTask = cachesDic.GetTask<DynamicModel>(this, "DynamicModel");
|
||
//Task<bool> existsSettingTableTask = cachesDic.AddTask(this, "HasExistsSettingTable", new Task<bool>(() =>
|
||
//{
|
||
// return BaseImpl.HasExistsTable(ResourceKeys.SettingTableName);
|
||
//}));
|
||
Task<DataTable> setBaseGridRightMenusTask = cachesDic.AddTask(this, "RightMenuBtn", new Task<DataTable>(() =>
|
||
{
|
||
DataTable dataTable = null;
|
||
if (dynamicModelTask != null)
|
||
{
|
||
dataTable = BaseModuleImpl.GetBaseGridRightMenus(dynamicModelTask.Result.ModuleCode);
|
||
}
|
||
return dataTable;
|
||
}));
|
||
Task<DataTable> customColumnByDatabaseTask = cachesDic.AddTask(this, "CustomColumnByDatabase", new Task<DataTable>(() =>
|
||
{
|
||
return this.GridView.GetCustomColumnByDatabase(customColumKey);
|
||
}));
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:设置表格数据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-01-02 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="table">The table.</param>
|
||
public virtual void SetGridViewDataSource(DataTable table, bool selectRowHandler = true)
|
||
{
|
||
try
|
||
{
|
||
if (AllowClearColumns && (this.ColumnList == null || this.ColumnList.Count == 0))
|
||
{
|
||
if (this is BandedGridControlEx)
|
||
{
|
||
BandedGridView bandedGridView = this.GridView as BandedGridView;
|
||
bandedGridView.Bands.Clear();
|
||
bandedGridView.Columns.Clear();
|
||
}
|
||
else
|
||
{
|
||
this.gridView.Columns.Clear();
|
||
}
|
||
}
|
||
|
||
|
||
if (table != null && this.gridView.Columns.Count > 0)
|
||
{
|
||
foreach (DataColumn column in table.Columns)
|
||
{
|
||
GridColumn gcolum = this.gridView.Columns.FirstOrDefault(x => x.FieldName.Equals(column.ColumnName, StringComparison.OrdinalIgnoreCase));
|
||
if (gcolum != null) column.ColumnName = gcolum.FieldName;
|
||
}
|
||
}
|
||
//多表格设置数据源列名大小写
|
||
if (this is BandedGridControlEx)
|
||
{
|
||
BandedGridView bandedGridView = this.GridView as BandedGridView;
|
||
if (table != null && bandedGridView.Columns.Count > 0)
|
||
{
|
||
foreach (DataColumn column in table.Columns)
|
||
{
|
||
GridColumn gcolum = bandedGridView.Columns.FirstOrDefault(x => x.FieldName.Equals(column.ColumnName, StringComparison.OrdinalIgnoreCase));
|
||
if (gcolum != null) column.ColumnName = gcolum.FieldName;
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
if (table != null && !table.Columns.Contains("RightMenuBtnEdit") && this.gridView.Columns.Where(n => n.FieldName.Equals("RightMenuBtnEdit")).Count() > 0)
|
||
{
|
||
table.Columns.Add("RightMenuBtnEdit");
|
||
}
|
||
|
||
if (ParentControl != null)//刷新mrp按钮状态
|
||
{
|
||
foreach (GridRightMenuModel menuModel in ParentControl.mrpBtnDic.Keys)
|
||
{
|
||
SimpleButton simpleButton = ParentControl.mrpBtnDic[menuModel];
|
||
if (menuModel.PrivilegeOper.Length > 1 && !menuModel.PrivilegeOper.Contains(ERPInfo.Instance.UserName + ","))
|
||
{
|
||
simpleButton.Enabled = false;
|
||
}
|
||
else
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(menuModel.MenuCond))
|
||
{
|
||
try
|
||
{
|
||
string cond = ReplaceHelper.ReplaceUserInfo(menuModel.MenuCond);
|
||
if (ParentControl != null)
|
||
cond = ParentControl.ReplaceParentControlValue(cond);
|
||
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);
|
||
}
|
||
}
|
||
simpleButton.Enabled = ReplaceHelper.EvalCond(cond);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||
MessageUtil.Show(ResourceKeys.SetRightMenuCondFault + "\r\n" + Message);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
this.ClearImage();
|
||
this.GridControl.DataSource = table;
|
||
this.AdjustIndicatorWidthSmart();
|
||
//modifyThePosition.Clear();
|
||
this.SetAutoColumns();
|
||
if (selectRowHandler)
|
||
this.gridView.SelectRowHandler(this.gridView.FocusedRowHandle);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogUtil.WriteError("设置审核表格数据出错!", ex);
|
||
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:设置表格数据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-10-10 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="adapter">The adapter.</param>
|
||
/// <param name="selectRowHandler">if set to <c>true</c> [select row handler].</param>
|
||
/// <returns>System.Int32.</returns>
|
||
public virtual int SetGridViewDataSource(DbDataAdapter adapter, bool selectRowHandler = true)
|
||
{
|
||
if (adapter == null) return 0;
|
||
|
||
try
|
||
{
|
||
|
||
|
||
this.AdapterObj = adapter;
|
||
DataSet dataSet = new DataSet();
|
||
|
||
// 重连配置
|
||
int maxRetryCount = 2; // 次数
|
||
int retryDelay = 1000; // 等待时间
|
||
for (int i = 0; i < maxRetryCount; i++)
|
||
{
|
||
try
|
||
{
|
||
adapter.Fill(dataSet, "SetGridViewDataSource");
|
||
break;//连接成功
|
||
}
|
||
catch (SqlException ex)
|
||
{
|
||
// 判断是否是连接相关错误
|
||
if (IsConnectionError(ex.Number) ||
|
||
ex.Message.Contains("物理连接不可用") ||
|
||
ex.Message.Contains("传输级错误"))
|
||
{
|
||
if (i < maxRetryCount - 1)
|
||
{
|
||
SqlConnection.ClearAllPools();
|
||
System.Threading.Thread.Sleep(retryDelay);
|
||
continue; // 重试
|
||
}
|
||
else
|
||
{
|
||
// 最后一次重试失败,抛出错误
|
||
throw new Exception($"经过 {maxRetryCount} 次重试后仍无法连接到数据库: {ex.Message}", ex);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// 其他SQL错误直接抛出
|
||
throw;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
if (this.ColumnList == null || this.ColumnList.Count == 0)
|
||
{
|
||
if (this is BandedGridControlEx)
|
||
{
|
||
BandedGridView bandedGridView = this.GridView as BandedGridView;
|
||
bandedGridView.Bands.Clear();
|
||
bandedGridView.Columns.Clear();
|
||
}
|
||
else
|
||
{
|
||
this.gridView.Columns.Clear();
|
||
}
|
||
}
|
||
DbCommandBuilder cb = SqlHelper.dbFactory.CreateCommandBuilder();
|
||
cb.DataAdapter = this.AdapterObj;
|
||
//this.GridControl.DataSource = dataSet.Tables[0];
|
||
|
||
//解决大小写问题后在赋值
|
||
DataTable dt = dataSet.Tables[0];
|
||
if (dt != null && this.gridView.Columns.Count > 0)
|
||
{
|
||
foreach (DataColumn column in dt.Columns)
|
||
{
|
||
GridColumn gcolum = this.gridView.Columns.FirstOrDefault(x => x.FieldName.Equals(column.ColumnName, StringComparison.OrdinalIgnoreCase));
|
||
if (gcolum != null) column.ColumnName = gcolum.FieldName;
|
||
}
|
||
}
|
||
//多表格设置数据源列名大小写
|
||
if (this is BandedGridControlEx)
|
||
{
|
||
BandedGridView bandedGridView = this.GridView as BandedGridView;
|
||
if (dt != null && bandedGridView.Columns.Count > 0)
|
||
{
|
||
foreach (DataColumn column in dt.Columns)
|
||
{
|
||
GridColumn gcolum = bandedGridView.Columns.FirstOrDefault(x => x.FieldName.Equals(column.ColumnName, StringComparison.OrdinalIgnoreCase));
|
||
if (gcolum != null) column.ColumnName = gcolum.FieldName;
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
|
||
if (dt != null && !dt.Columns.Contains("RightMenuBtnEdit") && this.gridView.Columns.Where(n => n.FieldName.Equals("RightMenuBtnEdit")).Count() > 0)
|
||
{
|
||
dt.Columns.Add("RightMenuBtnEdit");
|
||
}
|
||
|
||
|
||
this.ClearImage();
|
||
this.GridControl.DataSource = dt;
|
||
|
||
|
||
this.AdjustIndicatorWidthSmart();
|
||
//modifyThePosition.Clear();
|
||
// 动态列处理
|
||
this.SetAutoColumns();
|
||
if (selectRowHandler)
|
||
this.gridView.SelectRowHandler(this.gridView.FocusedRowHandle);
|
||
return dataSet.Tables[0] != null ? dataSet.Tables[0].Rows.Count : 0;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageUtil.Show(ex);
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 判断是否是连接相关的错误代码
|
||
/// </summary>
|
||
protected virtual bool IsConnectionError(int errorNumber)
|
||
{
|
||
// 常见的连接相关错误代码
|
||
int[] connectionErrorNumbers = {
|
||
10053, 10054, 10060, 10061, // 网络相关错误
|
||
4060, 18456, // 登录相关错误
|
||
2, 53 // 服务器不存在或无法访问
|
||
};
|
||
|
||
return Array.IndexOf(connectionErrorNumbers, errorNumber) >= 0;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:计算列关联字段</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-18 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="model">The model.</param>
|
||
/// <param name="fieldValue">The field value.</param>
|
||
protected virtual void SetUnionValue(GridColumnModel model, string fieldValue, int RowHandle)
|
||
{
|
||
DataTable table = this.gridControl.DataSourceTable();
|
||
//DataRow rowItem = this.gridView.FocusedRowHandle == RowHandle || RowHandle < 0 ? this.gridView.GetFocusedDataRow() : table.Rows[RowHandle];
|
||
DataRow rowItem = table.Rows.Count == 0 || this.gridView.FocusedRowHandle < 0 ? this.gridView.GetFocusedDataRow() : this.gridView.FocusedRowHandle == RowHandle || RowHandle < 0 ? this.gridView.GetFocusedDataRow() : table.Rows[RowHandle];
|
||
|
||
|
||
//DataRow rowItem = this.gridView.GetFocusedDataRow();
|
||
string unionValues = model.UnionValues;
|
||
if (rowItem != null && model != null)
|
||
{
|
||
unionValues = ReplaceHelper.ReplaceRowParam(rowItem, unionValues.Replace("{" + model.FieldName + "}", fieldValue));
|
||
if (this.ParentControl != null)
|
||
unionValues = ParentControl.ReplaceParentControlValue(unionValues);
|
||
try
|
||
{
|
||
string[] fields = model.UnionFields.Trim().Trim(',').Split(',');
|
||
DataRow rowResult = BaseImpl.GetDataRowResult(unionValues);
|
||
if (rowResult != null)
|
||
{
|
||
for (int i = 0; i < fields.Length; i++)
|
||
{
|
||
string field = fields[i];
|
||
string value = rowResult.Table.Columns.Contains(field) ? rowResult[field] + "" : null;
|
||
rowItem[field] = value;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// 设置为空
|
||
for (int i = 0; i < fields.Length; i++)
|
||
{
|
||
string field = fields[i];
|
||
rowItem[field] = DBNull.Value;
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
LogUtil.WriteError("计算列关联字段--错误-->" + unionValues, ex);
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:计算列计算公式</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-18 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="model">The model.</param>
|
||
/// <param name="fieldValue">The field value.</param>
|
||
protected virtual void SetCalcValue(GridColumnModel model, string fieldValue, int RowHandle)
|
||
{
|
||
if (this.GridSumming) return;
|
||
this.GridSumming = true;
|
||
try
|
||
{
|
||
DataTable table = this.gridControl.DataSourceTable();//this.gridView.FocusedRowHandle == RowHandle || RowHandle < 0 ? this.gridView.GetFocusedDataRow() : table.Rows[RowHandle];
|
||
DataRow rowItem = table.Rows.Count == 0 || this.gridView.FocusedRowHandle < 0 ? this.gridView.GetFocusedDataRow() : this.gridView.FocusedRowHandle == RowHandle || RowHandle < 0 ? this.gridView.GetFocusedDataRow() : table.Rows[RowHandle];
|
||
|
||
|
||
if (rowItem != null && model != null)
|
||
{
|
||
foreach (GridColumn col in this.gridView.Columns)
|
||
{
|
||
GridColumnModel colModel = col.Tag as GridColumnModel;
|
||
if (colModel == null) continue;
|
||
string defultValue = colModel.DefaultValue;
|
||
if (colModel.FieldType == 7 && rowItem.Table.Columns.Contains(col.FieldName) && string.IsNullOrEmpty(rowItem[col.FieldName] + "") && !string.IsNullOrEmpty(colModel.DefaultValue))
|
||
{
|
||
defultValue = ReplaceHelper.ReplaceUserInfo(colModel.DefaultValue);
|
||
if (ParentControl != null) defultValue = ParentControl.ReplaceParentControlValue(defultValue);
|
||
if (defultValue.StartsWith("@"))
|
||
{
|
||
defultValue = BaseImpl.GetDefaultValue(ReplaceHelper.ReplaceRowParam(rowItem, defultValue));
|
||
}
|
||
|
||
if (IsNumberic(defultValue)) rowItem[col.FieldName] = defultValue;//colModel.DefaultValue;
|
||
|
||
}
|
||
}
|
||
List<GridColumnModel> calcModels = this.ColumnList.FindAll(x => !string.IsNullOrEmpty(x.CalcExpr)).OrderBy(y => y.CalcOrder).ToList();
|
||
foreach (GridColumnModel gridModel in calcModels)
|
||
{
|
||
// 计算顺序小于当前控件则不计算
|
||
if (gridModel.CalcOrder < model.CalcOrder) continue;
|
||
|
||
if (!gridModel.FieldName.Equals(model.FieldName, StringComparison.OrdinalIgnoreCase))
|
||
{
|
||
bool isTruncate = false;
|
||
string calcExpr = gridModel.CalcExpr;
|
||
if (calcExpr.StartsWith("@truncate:"))
|
||
{
|
||
calcExpr = calcExpr.Substring(10);
|
||
isTruncate = true;
|
||
}
|
||
|
||
try
|
||
{
|
||
if (this.ParentControl != null)
|
||
calcExpr = ParentControl.ReplaceParentControlValue(calcExpr);
|
||
|
||
string result = string.Empty;
|
||
if (calcExpr.StartsWith("@"))
|
||
{
|
||
result = BaseImpl.GetDefaultValue(ReplaceHelper.ReplaceRowParam(rowItem, calcExpr));
|
||
}
|
||
else
|
||
{
|
||
|
||
calcExpr = ReplaceHelper.ReplaceRowParam(rowItem, calcExpr);
|
||
//EvalHelper.Eval2(ReplaceHelper.ReplaceEvalCond(calcExpr)) + ""
|
||
|
||
object evalResult = EvalHelper.Eval2(ReplaceHelper.ReplaceEvalCond(calcExpr));
|
||
result = JsonConvert.SerializeObject(evalResult);
|
||
|
||
|
||
if (result.Contains("E") || result.Contains("e"))
|
||
{
|
||
|
||
result = ChangeDataToD(result).ToString("0.########");
|
||
}
|
||
}
|
||
if (isTruncate)
|
||
{
|
||
result += result.Contains(".") ? "0000000000" : ".0000000000";
|
||
rowItem[gridModel.FieldName] = result.Substring(0, result.IndexOf(".")) + result.Substring(result.IndexOf("."), model.Decimals + 1);
|
||
//this.gridView.SetRowCellValue(this.gridView.FocusedRowHandle, this.gridView.Columns[gridModel.FieldName], result.Substring(0, result.IndexOf(".")) + result.Substring(result.IndexOf("."), model.Decimals + 1));
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
double d = 0;
|
||
if (!string.IsNullOrEmpty(result) &&
|
||
!"NaN".Equals(result, StringComparison.OrdinalIgnoreCase) &&
|
||
!"非数字".Equals(result, StringComparison.OrdinalIgnoreCase) &&
|
||
!"undefined".Equals(result, StringComparison.OrdinalIgnoreCase) &&
|
||
result != "∞" && result != "-∞" &&
|
||
!"正无穷大".Equals(result, StringComparison.OrdinalIgnoreCase) &&
|
||
!"负无穷大".Equals(result, StringComparison.OrdinalIgnoreCase) &&
|
||
double.TryParse(result, out d))
|
||
{
|
||
if (string.IsNullOrEmpty(gridModel.DataFormat))
|
||
{
|
||
result = Math.Round(Convert.ToDouble(d), model.Decimals, MidpointRounding.AwayFromZero) + "";
|
||
}
|
||
else
|
||
{
|
||
//计算后先执行保存小数位数
|
||
if (SystemInfo.Instance.ComputeFormatting) result = string.Format("{0:" + gridModel.DataFormat + "}", Convert.ToDecimal(result));
|
||
}
|
||
if (model.FieldType == 7 && result.Contains('%'))
|
||
{
|
||
result = (double.Parse(result.Replace("%", "")) * 0.01).ToString();
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(result))
|
||
{
|
||
rowItem[gridModel.FieldName] = DBNull.Value;
|
||
}
|
||
else
|
||
{
|
||
rowItem[gridModel.FieldName] = result;
|
||
}
|
||
|
||
// 判断计算列有无关联值
|
||
GridColumnModel UnionModel = calcModels.FirstOrDefault(x => x.FieldName == gridModel.FieldName);
|
||
if (!string.IsNullOrEmpty(UnionModel.UnionFields))
|
||
{
|
||
this.SetUnionValue(UnionModel, rowItem[gridModel.FieldName] + "", RowHandle);
|
||
}
|
||
//this.gridView.SetRowCellValue(this.gridView.FocusedRowHandle, this.gridView.Columns[gridModel.FieldName], result);
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
LogUtil.WriteError("计算列计算公式--错误-->" + rowItem[gridModel.FieldName], ex);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
// MessageUtil.Show(Message,ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
this.GridSumming = false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:把科学计数转换为小数格式</para>
|
||
/// <para>创建人:曹屹峰</para>
|
||
/// <para>创建日期:2021-10-14 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private Decimal ChangeDataToD(string strData)
|
||
{
|
||
Decimal dData = 0.0M;
|
||
if (strData.Contains("E"))
|
||
{
|
||
dData = Decimal.Parse(strData, System.Globalization.NumberStyles.Float);
|
||
}
|
||
return dData;
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:默认取上一行某字段值</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2020-07-03 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="model">The model.</param>
|
||
/// <param name="fieldValue">The field value.</param>
|
||
protected virtual void SetUpperValue(GridColumnModel model, int RowHandle, string fieldValue, bool isUpperChage = true)
|
||
{
|
||
try
|
||
{
|
||
string ItemValue = string.Empty;
|
||
string UpperFieldName = string.Empty;
|
||
if (model != null)
|
||
{
|
||
List<GridColumnModel> calcModels = this.ColumnList.FindAll(x => (x.DefaultValue + "").Contains("{ROW_")).OrderBy(y => y.CalcOrder).ToList();
|
||
|
||
foreach (GridColumnModel gridModel in calcModels)
|
||
{
|
||
this.UpperChange(model, gridModel, RowHandle);
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:取得</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2020-07-03 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="model">The model.</param>
|
||
/// <param name="fieldValue">The field value.</param>
|
||
public void UpperChange(GridColumnModel model, GridColumnModel gridModel, int RowHandle)
|
||
{
|
||
DataTable Table = this.gridControl.DataSourceTable();
|
||
DataRow rowItem = this.GridView.GetDataRow(RowHandle);
|
||
string UpperFieldName = ReplaceHelper.GetParamFields(gridModel.DefaultValue)[0];
|
||
UpperFieldName = UpperFieldName.Replace("}", "").Replace("{", "");
|
||
UpperFieldName = UpperFieldName.Substring(UpperFieldName.IndexOf('_') + 1);
|
||
if (string.IsNullOrWhiteSpace(rowItem[gridModel.FieldName] + "") || this.gridView.FocusedRowHandle != RowHandle)
|
||
{
|
||
if (Table.Rows.Count > 0 && Table.Columns.Contains(ERPInfo.Instance.isAddRows))
|
||
{
|
||
DataRow lastRow = Table.Rows[Table.Rows.Count - 1];
|
||
if (RowHandle > 0)
|
||
{
|
||
lastRow = Table.Rows[RowHandle - 1];
|
||
}
|
||
if (rowItem[ERPInfo.Instance.isAddRows] + "" != "1")
|
||
{
|
||
rowItem[gridModel.FieldName] = gridModel.DefaultValue.StartsWith("@") ? BaseImpl.GetDefaultValue(ReplaceHelper.ReplaceParamToValue(gridModel.DefaultValue, lastRow[UpperFieldName] + "")) : rowItem[gridModel.FieldName] = lastRow[UpperFieldName] + "";
|
||
}
|
||
rowItem[ERPInfo.Instance.isAddRows] = "1";
|
||
}
|
||
if (!string.IsNullOrEmpty(gridModel.UnionFields))
|
||
{
|
||
this.SetUnionValue(gridModel, rowItem[gridModel.FieldName] + "", RowHandle);
|
||
}
|
||
|
||
// 计算规则配置在结果字段上,所以无需验证当前操作控件
|
||
this.SetCalcValue(model, rowItem[gridModel.FieldName] + "", RowHandle);
|
||
}
|
||
string[] fields = !string.IsNullOrEmpty(gridModel.UnionFields) ? gridModel.UnionFields.Trim(',').Split(',') : new string[] { };
|
||
if (RowHandle >= 0 && RowHandle < Table.Rows.Count - 1 && ((fields.Contains(model.FieldName)) || model.FieldName == UpperFieldName || model.FieldName == gridModel.FieldName))
|
||
{
|
||
if (Table.Columns.Contains(ERPInfo.Instance.isAddRows))
|
||
{
|
||
Table.Rows[RowHandle + 1][ERPInfo.Instance.isAddRows] = 0;
|
||
}
|
||
this.OnGridViewtUpperValueChanged(this.gridView.Columns[gridModel.FieldName], Table.Rows[RowHandle + 1][gridModel.FieldName] + "", RowHandle + 1, gridModel);
|
||
//this.OnGridViewCellValueChanged(this.gridControl, new CellValueChangedEventArgs(RowHandle + 1, this.gridView.Columns[gridModel.FieldName], Table.Rows[RowHandle + 1][gridModel.FieldName] + ""));
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:禁用控件条件</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-01-22 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="model">The model.</param>
|
||
/// <param name="fieldValue">The field value.</param>
|
||
protected virtual void SetDisableColumn(GridColumnModel model, int rowHandler, string fieldValue)
|
||
{
|
||
//if (model.DisableCond != null)
|
||
//{
|
||
// GridColumnModel[] columns = this.ColumnList.Where(x => x.DisableCond.Contains("{" + model.FieldName + "}")).ToArray();
|
||
// DataRow rowItem = this.gridView.GetDataRow(rowHandler);
|
||
// foreach (GridColumnModel item in columns)
|
||
// {
|
||
// try
|
||
// {
|
||
// string disableCond = ReplaceHelper.ReplaceRowParam(rowItem, item.DisableCond.Replace("{" + model.FieldName + "}", fieldValue));
|
||
// string diaableType = item.DisableType;
|
||
|
||
// //this.gridView.Columns.ColumnByFieldName(model.FieldName).OptionsColumn.AllowEdit = ("true".Equals(EvalHelper.Eval(ReplaceHelper.ReplaceEvalCond(disableCond)) + "", StringComparison.OrdinalIgnoreCase));
|
||
// this.gridView.Columns.ColumnByFieldName(model.FieldName).OptionsColumn.AllowEdit = ("true".Equals(ValidateCond(disableCond, null) + "", StringComparison.OrdinalIgnoreCase));
|
||
// }
|
||
// catch (Exception)
|
||
// {
|
||
// }
|
||
// }
|
||
//}
|
||
if (!string.IsNullOrEmpty(model.EnableCond))
|
||
{
|
||
GridColumnModel[] columns = this.ColumnList.Where(x => x.EnableCond.Contains("{" + model.FieldName + "}")).ToArray();
|
||
DataRow rowItem = this.gridView.GetDataRow(rowHandler);
|
||
foreach (GridColumnModel item in columns)
|
||
{
|
||
try
|
||
{
|
||
string disableCond = ReplaceHelper.ReplaceRowParam(rowItem, item.EnableCond.Replace("{" + model.FieldName + "}", fieldValue));
|
||
string diaableType = item.DisableType;
|
||
//this.gridView.Columns.ColumnByFieldName(model.FieldName).Visible = ("true".Equals(EvalHelper.Eval(ReplaceHelper.ReplaceEvalCond(disableCond)) + "", StringComparison.OrdinalIgnoreCase));
|
||
this.gridView.Columns.ColumnByFieldName(model.FieldName).Visible = ("true".Equals(ValidateCond(disableCond, null) + "", StringComparison.OrdinalIgnoreCase));
|
||
//设置编辑状态
|
||
//this.gridView.Columns.ColumnByFieldName("").OptionsColumn.AllowEdit = true;
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:设置自定义列</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-02-01 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
protected virtual void SetCustomColumns(DataTable customTable, bool isInit = true)
|
||
{
|
||
Dictionary<object, Hashtable> dataCaches = Model != null ? Model.DataCaches : null;
|
||
//if (!dataCaches.GetValue(this, "HasExistsSettingTable", out bool hasExistsSettingTable))
|
||
//{
|
||
// hasExistsSettingTable = BaseImpl.HasExistsTable(ResourceKeys.SettingTableName);
|
||
//}
|
||
|
||
if (string.IsNullOrEmpty(this.CustomColumKey) || customTable.Columns.Count == 0)//!hasExistsSettingTable
|
||
{
|
||
return;
|
||
}
|
||
if (customTable != null && customTable.Rows.Count > 0)
|
||
{
|
||
int MaxIndex = customTable.Columns.Count;
|
||
foreach (DataRow rowItem in customTable.Rows)
|
||
{
|
||
string fieldName = rowItem["fieldName"] + "";
|
||
int.TryParse(rowItem["fieldWidth"] + "", out int fieldWidth);
|
||
//int.TryParse(rowItem["orderid"] + "", out int index);
|
||
//2025-02-20 依米康把orderid字段类型改成了decimal(18, 2),不能int.TryParse直接转换
|
||
int index = Convert.ToInt32(Math.Round(double.Parse(rowItem["orderid"] + "")));
|
||
bool visible = "1".Equals(rowItem["isVisible"] + "") && fieldWidth > 0;
|
||
bool isFix = "True".Equals(rowItem["IfFixColumn"] + "", StringComparison.OrdinalIgnoreCase);
|
||
string FilterInfo = rowItem.Table.Columns.Contains("FilterInfo") ? rowItem["FilterInfo"] + "" : "";//列筛选条件
|
||
GridColumnModel column = this.ColumnList.Find(x => x.FieldName == fieldName);
|
||
GridColumn gridColumn = this.gridView.Columns.ColumnByName(fieldName);
|
||
if (column != null && !string.IsNullOrEmpty(fieldName) && gridColumn != null && gridColumn.Visible && gridColumn.Width > 0)
|
||
{
|
||
GridColumn colObj = this.gridView.Columns[fieldName];
|
||
colObj.VisibleIndex = index;
|
||
colObj.Width = fieldWidth;
|
||
colObj.Visible = visible;
|
||
colObj.Fixed = isFix ? FixedStyle.Left : FixedStyle.None;
|
||
if (!string.IsNullOrWhiteSpace(FilterInfo)) colObj.FilterInfo = new ColumnFilterInfo(FilterInfo);
|
||
}
|
||
}
|
||
//是否显示筛选器行
|
||
if (customTable.Columns.Contains("DisplayFiltering") && "1".Equals(customTable.Rows[0]["DisplayFiltering"] + "")) this.gridView.OptionsView.ShowAutoFilterRow = true;
|
||
//分组序号
|
||
if (customTable.Columns.Contains("GroupIndex"))
|
||
{
|
||
DataRow[] dataRows = customTable.Select("GroupIndex>-1");
|
||
|
||
for (int i = 0; i < dataRows.Length; i++)
|
||
{
|
||
DataRow row = dataRows.Cast<DataRow>().FirstOrDefault(x => Convert.ToInt32(x["GroupIndex"] + "") == i);
|
||
if (row != null)
|
||
{
|
||
string fieldName = row["fieldName"] + "";
|
||
int GroupIndex = row.Table.Columns.Contains("GroupIndex") ? Convert.ToInt32(row["GroupIndex"] + "") : -1;
|
||
GridColumnModel column = this.ColumnList.Find(x => x.FieldName == fieldName);
|
||
GridColumn gridColumn = this.gridView.Columns.ColumnByName(fieldName);
|
||
if (column != null && !string.IsNullOrEmpty(fieldName) && gridColumn != null && gridColumn.Visible && gridColumn.Width > 0)
|
||
{
|
||
GridColumn colObj = this.gridView.Columns[fieldName];
|
||
if (GroupIndex > -1)
|
||
{
|
||
colObj.GroupIndex = GroupIndex;
|
||
this.gridView.OptionsView.ShowGroupPanel = true;
|
||
}
|
||
}
|
||
}
|
||
// 隐藏分组面板
|
||
this.gridView.OptionsView.ShowGroupPanel = false;
|
||
// 展开所有分组
|
||
this.gridView.OptionsBehavior.AutoExpandAllGroups = true;//展开所有分组
|
||
}
|
||
}
|
||
foreach (GridColumn col in this.gridView.Columns)
|
||
{
|
||
DataRow a = customTable.Rows.Cast<DataRow>().FirstOrDefault(x => col.Name.Equals(x["fieldName"] + "", StringComparison.OrdinalIgnoreCase));
|
||
if (a == null)
|
||
{
|
||
bool visible = col.Visible;//获取设置VisibleIndex之前列的状态
|
||
col.VisibleIndex = MaxIndex;
|
||
MaxIndex += 1;
|
||
col.Visible = visible;
|
||
}
|
||
}
|
||
}
|
||
if (!isInit)
|
||
{
|
||
// 非初始化,假如未配置则初始化到系统配置
|
||
for (int i = 0; i < this.ColumnList.Count; i++)
|
||
{
|
||
GridColumnModel column = this.ColumnList[i];
|
||
if (this.gridView.Columns.ColumnByName(column.FieldName) != null)
|
||
{
|
||
GridColumn colObj = this.gridView.Columns[column.FieldName];
|
||
colObj.VisibleIndex = i;
|
||
colObj.Width = column.Width;
|
||
colObj.Visible = column.Visible;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:设置动态列</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-06-03 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
protected virtual void SetAutoColumns()
|
||
{
|
||
if (this.ColumnList == null || this.ColumnList.Count == 0)
|
||
{
|
||
bool isShowFooter = false;
|
||
List<GridColumn> autoFixColumns = new List<GridColumn>();
|
||
for (int i = 0; i < gridView.Columns.Count; i++)
|
||
{
|
||
try
|
||
{
|
||
GridColumn col = gridView.Columns[i];
|
||
col.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
|
||
col.OptionsFilter.FilterPopupMode = FilterPopupMode.CheckedList;
|
||
|
||
if (col.FieldName.Contains("_"))
|
||
{
|
||
string[] colSplit = col.FieldName.Split('_');
|
||
if (colSplit.Length >= 2)
|
||
{
|
||
col.Caption = colSplit[0];
|
||
col.Width = Convert.ToInt32(colSplit[1]);
|
||
if (Convert.ToInt32(colSplit[1]) == 0)
|
||
col.Visible = false;
|
||
if (colSplit.Length > 2)
|
||
{
|
||
bool visible = "1".Equals(colSplit[2]);
|
||
// 设置底部合计
|
||
if (col.VisibleIndex == 0)
|
||
{
|
||
isShowFooter = true;
|
||
col.Summary.AddRange(new GridSummaryItem[] { new GridColumnSummaryItem(DevExpress.Data.SummaryItemType.Count, col.FieldName, TotalFormat) });
|
||
|
||
if (SystemInfo.Instance.GroupSpecialMode)
|
||
{
|
||
//gridView.GroupSummary.Add(new GridGroupSummaryItem(DevExpress.Data.SummaryItemType.Count, col.FieldName, null, "合计: {0:#,###}行"));
|
||
gridView.OptionsView.GroupFooterShowMode = GroupFooterShowMode.VisibleAlways;
|
||
}
|
||
else
|
||
{
|
||
gridView.GroupSummary.AddRange(new GridSummaryItem[] { new GridGroupSummaryItem(DevExpress.Data.SummaryItemType.Count, col.FieldName, null, TotalFormat) });
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (visible)
|
||
{
|
||
isShowFooter = true;
|
||
string dataFormat = colSplit.Length > 3 ? colSplit[3] : "";
|
||
col.Summary.AddRange(new GridSummaryItem[] { new GridColumnSummaryItem(SummaryItemType.Sum, col.FieldName, "{0:" + dataFormat + "}") });
|
||
|
||
if (SystemInfo.Instance.GroupSpecialMode)
|
||
{
|
||
gridView.GroupSummary.Add(new GridGroupSummaryItem(DevExpress.Data.SummaryItemType.Sum, col.FieldName, col, "{0:" + dataFormat + "}"));
|
||
gridView.OptionsView.GroupFooterShowMode = GroupFooterShowMode.VisibleAlways;
|
||
}
|
||
else
|
||
{
|
||
gridView.GroupSummary.AddRange(new GridSummaryItem[] { new GridGroupSummaryItem(SummaryItemType.Sum, col.FieldName, null, "{0:" + dataFormat + "}") });
|
||
}
|
||
|
||
}
|
||
}
|
||
if (colSplit.Length > 3)
|
||
{
|
||
string dataFormat = colSplit[3];
|
||
|
||
if (!string.IsNullOrWhiteSpace(dataFormat))
|
||
{
|
||
col.DisplayFormat.FormatType = FormatType.Custom;
|
||
col.DisplayFormat.FormatString = dataFormat;
|
||
}
|
||
}
|
||
if (colSplit.Length > 4)
|
||
{
|
||
// 是否冻结列:1冻结
|
||
if ("1".Equals(colSplit[4]))
|
||
{
|
||
autoFixColumns.Add(col);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
col.Width = 150;
|
||
}
|
||
gridView.OptionsView.ShowFooter = isShowFooter;
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
}
|
||
}
|
||
foreach (GridColumn col in autoFixColumns.Where(x => x.Visible && x.Width > 0))
|
||
{
|
||
col.Fixed = FixedStyle.Left;
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:设置表格提示框(自带提示框有提示信息不全的问题)</para>
|
||
/// <para>创建人:曹屹峰</para>
|
||
/// <para>创建日期:2021-11-11 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void MainGvTool_BeforeShow(object sender, ToolTipControllerShowEventArgs e)
|
||
{
|
||
DevExpress.Utils.ToolTipController toolTipController = (DevExpress.Utils.ToolTipController)sender;
|
||
GridControl control = toolTipController.ActiveControlClient as GridControl;
|
||
if (control == null) return;
|
||
GridView gridView = control.MainView as GridView;
|
||
GridHitInfo hitInfo = GridView.CalcHitInfo(gridView.GridControl.PointToClient(System.Windows.Forms.Control.MousePosition));
|
||
if (hitInfo.RowHandle < 0 || hitInfo.Column == null || hitInfo.HitTest != GridHitTest.RowCell)
|
||
{
|
||
return;
|
||
}
|
||
if (hitInfo.Column.FieldName.Equals("RightMenuBtnEdit"))//操作列提示信息显示
|
||
{
|
||
e.ToolTip = e.ToolTip;
|
||
}
|
||
else//否则显示单元格值
|
||
{
|
||
DataRow row = this.GridView.GetDataRow(hitInfo.RowHandle);
|
||
e.ToolTip = row[hitInfo.Column.FieldName].ToString();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:设置表格行高、行字体大小(默认微软雅黑)</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-11-11 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
protected void SetGridRowHeightAndFont()
|
||
{
|
||
if (SystemInfo.Instance.GridRowFontSize > 0)
|
||
{
|
||
this.gridView.Appearance.Row.Font = new Font(this.gridView.Appearance.Row.Font.Name, SystemInfo.Instance.GridRowFontSize);
|
||
this.gridView.Appearance.HeaderPanel.Font = new Font(this.gridView.Appearance.HeaderPanel.Font.Name, SystemInfo.Instance.GridRowFontSize);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(SystemInfo.Instance.GridFontName))
|
||
{
|
||
this.gridView.Appearance.Row.Font = new Font(SystemInfo.Instance.GridFontName, this.gridView.Appearance.Row.Font.Size);
|
||
this.gridView.Appearance.HeaderPanel.Font = new Font(SystemInfo.Instance.GridFontName, this.gridView.Appearance.HeaderPanel.Font.Size);
|
||
}
|
||
if (SystemInfo.Instance.GridRowHeight > 0)
|
||
{
|
||
this.gridView.ColumnPanelRowHeight = this.gridView.RowHeight = SystemInfo.Instance.GridRowHeight;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:验证表格列是否有为空的值</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-08 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
||
public virtual bool VerifyNull()
|
||
{
|
||
DataTable table = this.GridControl.DataSourceTable().TrimEmptyRows();
|
||
List<GridColumnModel> columns = this.ColumnList.FindAll(x => x.CanNull);
|
||
|
||
foreach (DataRow item in table.Rows)
|
||
{
|
||
foreach (GridColumnModel model in columns)
|
||
{
|
||
GridColumn column = this.gridView.Columns[model.FieldName];
|
||
string value = item[model.FieldName] + "";
|
||
string displayText = this.gridView.GetDisplayTextByColumnValue(column, item[model.FieldName]);
|
||
if (string.IsNullOrWhiteSpace(value) || string.IsNullOrWhiteSpace(displayText))
|
||
{
|
||
MessageUtil.Show(string.Format(ResourceKeys.NullField, model.FieldText));
|
||
this.gridView.Focus();
|
||
this.gridView.SelectRowHandler(table.Rows.IndexOf(item));
|
||
this.gridView.FocusedColumn = this.gridView.Columns[model.FieldName];
|
||
this.gridView.SelectCell(gridView.FocusedRowHandle, this.gridView.Columns[model.FieldName]);
|
||
this.gridView.ShowEditorByMouse();
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:冻结某一列</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-02-01 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected virtual void FixLeftItemClick(object sender, EventArgs e)
|
||
{
|
||
DXMenuItem item = sender as DXMenuItem;
|
||
GridColumn column = item.Tag as GridColumn;
|
||
column.Fixed = FixedStyle.Left;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:冻结所有列</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-02-01 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected virtual void FixLeftAllItemClick(object sender, EventArgs e)
|
||
{
|
||
DXMenuItem item = sender as DXMenuItem;
|
||
GridColumn column = item.Tag as GridColumn;
|
||
|
||
foreach (GridColumn col in gridView.Columns)
|
||
{
|
||
if (col.AbsoluteIndex <= column.AbsoluteIndex)
|
||
{
|
||
col.Fixed = FixedStyle.Left;
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:取消冻结列</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-02-01 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected virtual void UnFixItemClick(object sender, EventArgs e)
|
||
{
|
||
DXMenuItem item = sender as DXMenuItem;
|
||
GridColumn column = item.Tag as GridColumn;
|
||
column.Fixed = FixedStyle.None;
|
||
column.VisibleIndex = column.AbsoluteIndex;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 清除冻结(全部列)
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected virtual void itemUnFixAllClick(object sender, EventArgs e)
|
||
{
|
||
foreach (GridColumn column in this.gridView.Columns)
|
||
{
|
||
column.Fixed = FixedStyle.None;
|
||
}
|
||
foreach (GridColumn column in this.gridView.Columns)
|
||
{
|
||
column.VisibleIndex = column.AbsoluteIndex;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:保存表格属性</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-02-01 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected virtual void SaveItemClick(object sender, EventArgs e)
|
||
{
|
||
if (string.IsNullOrEmpty(this.CustomColumKey))
|
||
{
|
||
MessageUtil.Show(ResourceKeys.NotSettingResetColumn);
|
||
return;
|
||
}
|
||
|
||
if (this.ColumnList == null || this.ColumnList.Count == 0)
|
||
{
|
||
MessageUtil.Show("动态列无法保存属性");
|
||
return;
|
||
}
|
||
|
||
DataRow rowItem = null;
|
||
bool success = BaseImpl.HasExistsDataRow(ResourceKeys.SettingTableName, "formKey", CustomColumKey.ToString(), string.Format(" and OperatorId='{0}' ", ERPInfo.Instance.UserId), out rowItem);
|
||
if (!success)
|
||
{
|
||
MessageUtil.Show(ResourceKeys.NotFoundSettingColumnTable);
|
||
return;
|
||
}
|
||
|
||
if (MessageUtil.Show(ResourceKeys.IsSaveColumn, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
{
|
||
try
|
||
{
|
||
if (rowItem == null)
|
||
{
|
||
success = this.gridView.SaveCustomColumnToDatabase(this.CustomColumKey);
|
||
}
|
||
else
|
||
{
|
||
success = this.gridView.UpdateCustomColumnToDatabase(this.CustomColumKey);
|
||
}
|
||
#region old
|
||
if (ERPInfo.Instance.UserName == "管理员")
|
||
{
|
||
string[] keys = CustomColumKey.Split('_');
|
||
if (keys.Count() > 1)
|
||
{
|
||
string ModuleTypes = keys[0];
|
||
string ModuleKey = keys[1];
|
||
int ModelType = ControlType.ModelType(ModuleTypes);
|
||
string tmpsql = string.Empty;
|
||
string colTable = string.Empty;
|
||
string keyField = string.Empty;
|
||
string stepCode = string.Empty;
|
||
int keyOrder = 0;
|
||
//DXMenuItem item = sender as DXMenuItem;
|
||
//GridView grv = item.Tag as GridView;
|
||
//基础档案主表
|
||
if (ModelType == 1 || ModelType == 2)
|
||
{
|
||
colTable = "p_systemwordbooktab";
|
||
tmpsql = "select top 1 orderid from p_systemwordbooktab where formKey='" + ModuleKey + "' order by orderid";
|
||
object obj = SqlHelper.ExecuteScalar(CommandType.Text, tmpsql);
|
||
if (obj != null)
|
||
{
|
||
keyField = "formKey";
|
||
keyOrder = Convert.ToInt32(obj);
|
||
}
|
||
}
|
||
if (ModelType == 2 && string.IsNullOrEmpty(keyField))
|
||
{
|
||
colTable = "p_systemDlltabDetailGrid";
|
||
tmpsql = "select top 1 orderid from p_systemDlltabDetailGrid where detailKey='" + ModuleKey + "' order by orderid";
|
||
object obj = SqlHelper.ExecuteScalar(CommandType.Text, tmpsql);
|
||
if (obj != null)
|
||
{
|
||
keyField = "detailKey";
|
||
keyOrder = Convert.ToInt32(obj);
|
||
}
|
||
}
|
||
////单据明细
|
||
if (ModelType == 3)
|
||
{
|
||
colTable = "p_systembillDetail";
|
||
keyField = "typecode";
|
||
ModuleKey = Model.ModuleCode;
|
||
}
|
||
////单据来源主信息
|
||
if (ModelType == 4)
|
||
{
|
||
colTable = "p_systembillsourcegrid";
|
||
keyField = "sourcekey";
|
||
}
|
||
////单据来源明细信息
|
||
if (ModelType == 5)
|
||
{
|
||
colTable = "p_systembillsourcedetail";
|
||
keyField = "sourcekey";
|
||
}
|
||
//单据审核列表
|
||
if (ModelType == 6)
|
||
{
|
||
colTable = "p_systembillstepgrid";
|
||
keyField = "typeCode";
|
||
if (!string.IsNullOrEmpty(ModuleKey) && keys.Length == 5)
|
||
{
|
||
ModuleKey = keys[2];
|
||
stepCode = keys[3];
|
||
}
|
||
}
|
||
//基础档案审核列表
|
||
if (ModelType == 7)
|
||
{
|
||
colTable = "p_systemdlltabflowstepgrid";
|
||
keyField = "typeCode";
|
||
if (!string.IsNullOrEmpty(ModuleKey) && keys.Length == 5)
|
||
{
|
||
ModuleKey = keys[2];
|
||
stepCode = keys[3];
|
||
}
|
||
}
|
||
// 单据审核附加信息
|
||
if (ModelType == 8)
|
||
{
|
||
colTable = "p_systembillauditAttachDetail";
|
||
keyField = "attachKey";
|
||
}
|
||
tmpsql = "";
|
||
if (ModelType != 0 && !string.IsNullOrEmpty(keyField))
|
||
{
|
||
foreach (GridColumn col in gridView.Columns)
|
||
{
|
||
//+ ((ModelType == 1) && (col.VisibleIndex == -1) ? " ,vislble=1" : "")
|
||
tmpsql = tmpsql + "update " + colTable + " set width=" + col.Width.ToString() + (col.VisibleIndex != -1 ? ",orderid=" + (col.VisibleIndex + keyOrder + (ModelType == 1 ? 1 : 0)).ToString() : "") +
|
||
" where " + keyField + "='" + ModuleKey + "' and fieldname='" + col.FieldName + "'";
|
||
if (ModelType == 1 || ModelType == 2)
|
||
tmpsql = tmpsql + " and orderid<>" + keyOrder.ToString();
|
||
if (ModelType == 7 || ModelType == 6)
|
||
tmpsql = tmpsql + " and stepCode=" + stepCode;
|
||
tmpsql = tmpsql + ";";
|
||
}
|
||
//MessageBox.Show(tmpsql);
|
||
SqlHelper.ExecuteNonQuery(tmpsql);
|
||
}
|
||
|
||
|
||
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
MessageUtil.Show(success ? ResourceKeys.SaveSuccess : ResourceKeys.SaveFault);
|
||
}
|
||
catch (SqlException sex)
|
||
{
|
||
if (sex.Message.Contains(ResourceKeys.FieldLenIsShort) &&
|
||
MessageUtil.Show(ResourceKeys.SaveFault + "\r\n" + ResourceKeys.CanUpgradeTable, MessageBoxButtons.YesNo) == DialogResult.Yes &&
|
||
BaseImpl.UpdateTableField(ResourceKeys.SettingTableName, "formKey", "varchar(200)"))
|
||
{
|
||
MessageUtil.Show(ResourceKeys.UpdateSuccess);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:保存表格属性</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-02-01 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected virtual void SaveItemClick2(object sender, EventArgs e)
|
||
{
|
||
if (this.ColumnList == null || this.ColumnList.Count == 0)
|
||
{
|
||
MessageUtil.Show("动态列无法保存属性");
|
||
return;
|
||
}
|
||
DataRow rowItem = null;
|
||
bool success = BaseImpl.HasExistsDataRow(ResourceKeys.SettingTableName, "formKey", CurrentOperColumnKey, string.Format(" and OperatorId='{0}' ", ERPInfo.Instance.UserId), out rowItem);
|
||
if (!success)
|
||
{
|
||
MessageUtil.Show(ResourceKeys.NotFoundSettingColumnTable);
|
||
return;
|
||
}
|
||
|
||
if (MessageUtil.Show(ResourceKeys.IsSaveColumn, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
{
|
||
try
|
||
{
|
||
if (rowItem == null)
|
||
{
|
||
success = this.CurrentOperGridView.SaveCustomColumnToDatabase(this.CurrentOperColumnKey);
|
||
}
|
||
else
|
||
{
|
||
success = this.CurrentOperGridView.UpdateCustomColumnToDatabase(this.CurrentOperColumnKey);
|
||
}
|
||
|
||
MessageUtil.Show(success ? ResourceKeys.SaveSuccess : ResourceKeys.SaveFault);
|
||
}
|
||
catch (SqlException sex)
|
||
{
|
||
if (sex.Message.Contains(ResourceKeys.FieldLenIsShort) &&
|
||
MessageUtil.Show(ResourceKeys.SaveFault + "\r\n" + ResourceKeys.CanUpgradeTable, MessageBoxButtons.YesNo) == DialogResult.Yes &&
|
||
BaseImpl.UpdateTableField(ResourceKeys.SettingTableName, "formKey", "varchar(200)"))
|
||
{
|
||
MessageUtil.Show(ResourceKeys.UpdateSuccess);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
}
|
||
CurrentOperColumnKey = "";
|
||
CurrentOperGridView = null;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:重置表格属性</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-02-01 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected virtual void ResetItemClick(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (string.IsNullOrEmpty(this.CustomColumKey))
|
||
{
|
||
MessageUtil.Show(ResourceKeys.NotSettingResetColumn);
|
||
return;
|
||
}
|
||
if (!BaseImpl.HasExistsTable(ResourceKeys.SettingTableName))
|
||
{
|
||
MessageUtil.Show(ResourceKeys.NotFoundSettingColumnTable);
|
||
return;
|
||
}
|
||
if (MessageUtil.Show(ResourceKeys.IsResetColumn, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
{
|
||
bool success = this.gridView.ResetCustomColumnToDatabase(this.CustomColumKey);
|
||
DataTable customTable = this.gridView.GetCustomColumnByDatabase(this.CustomColumKey);
|
||
this.SetCustomColumns(customTable, false);
|
||
MessageUtil.Show(success ? ResourceKeys.ResetSuccess : ResourceKeys.ResetFault);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:重置表格属性</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-02-01 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected virtual void ResetItemClick2(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (!BaseImpl.HasExistsTable(ResourceKeys.SettingTableName))
|
||
{
|
||
MessageUtil.Show(ResourceKeys.NotFoundSettingColumnTable);
|
||
return;
|
||
}
|
||
if (MessageUtil.Show(ResourceKeys.IsResetColumn, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
{
|
||
bool success = this.CurrentOperGridView.ResetCustomColumnToDatabase(CurrentOperColumnKey);
|
||
GridColumn gridColumn = gridView.Columns[CurrentOperModel.FieldName];
|
||
InitAutoSearchEdit(gridColumn, CurrentOperModel);
|
||
MessageUtil.Show(success ? ResourceKeys.ResetSuccess : ResourceKeys.ResetFault);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 设置导出列
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected virtual void SetExportItemClick(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (string.IsNullOrEmpty(this.CustomColumKey))
|
||
{
|
||
MessageUtil.Show("未实现设置导出列功能,请联系朗速!");
|
||
return;
|
||
}
|
||
//导出设置表列名
|
||
Dictionary<string, string> colDic = new Dictionary<string, string>();
|
||
colDic.Add("formkey", "varchar(200)");
|
||
colDic.Add("fieldName", "varchar(50)");
|
||
colDic.Add("userName", "varchar(50)");
|
||
colDic.Add("OperatorId", "int");
|
||
colDic.Add("OperatorName", "varchar(50)");
|
||
colDic.Add("OperateDate", "datetime");
|
||
colDic.Add("isExport", "int");
|
||
string isExitTabSql = "select top 1 * from sysObjects where Id=OBJECT_ID(N'{0}') and xtype='U'";
|
||
isExitTabSql = string.Format(isExitTabSql, ResourceKeys.SettingExportTableName);
|
||
DataTable isExitTab = SqlHelper.ExecuteDataTable(isExitTabSql);
|
||
if (isExitTab.Rows.Count == 0)//不存在导出设置表
|
||
{
|
||
string createTabSql = "create table {0} (id int IDENTITY(1,1) NOT NULL,{1})";
|
||
string createCol = string.Empty;
|
||
foreach (KeyValuePair<string, string> colunmField in colDic)
|
||
{
|
||
createCol += string.Format("{0} {1},", colunmField.Key, colunmField.Value);
|
||
}
|
||
createTabSql = string.Format(createTabSql, ResourceKeys.SettingExportTableName, createCol.TrimEnd(','));
|
||
SqlHelper.ExecuteNonQuery(createTabSql);//创建表
|
||
}
|
||
if (!BaseImpl.HasExistsColumn(ResourceKeys.SettingExportTableName, "isExport"))//如果不存在isExport列
|
||
{
|
||
string addColSql = string.Format("alter table {0} add {1} {2}", ResourceKeys.SettingExportTableName, "isExport", "int");
|
||
SqlHelper.ExecuteNonQuery(addColSql);//添加isExport列
|
||
}
|
||
FrmSetExport frmSetExport = new FrmSetExport(this);
|
||
frmSetExport.CustomColumKey = this.CustomColumKey;
|
||
frmSetExport.ShowDialog();
|
||
frmSetExport.Dispose();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:导出表格数据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-02-01 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected virtual void ExportItemClick(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
this.gridControl.ToExcel(this.Model.FormText, false, this.CustomColumKey);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:打印表格数据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-02-01 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected virtual void PrintItemClick(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
PrintUtil.Print(this.gridControl);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:清除全部列排序</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-02-01 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected virtual void ClearSortItemClick(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
this.gridView.Columns.ClearAllSort();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:设置条件筛选列弹出设置</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2021-08-02 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected virtual void InstColumnSift(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
DXMenuItem item = sender as DXMenuItem;
|
||
GridColumn gridColumn = item.Tag as GridColumn;
|
||
// 保存流转步骤
|
||
FilterState filterState = new FilterState();
|
||
filterState.LabelObj.Text = string.Format("设置列{0}筛选条件:", gridColumn.Caption);
|
||
if (filterState.ShowDialog() == DialogResult.OK)
|
||
{
|
||
HeaderColumnSift = gridColumn;
|
||
SiftEnumObj = filterState.SiftEnumObj;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:多功能设置列条件筛选</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2021-08-02 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected virtual void Multifunction(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
//DataTable newDt = this.SetDealWithValueTab();
|
||
FrmGridSift frmGridSift = new FrmGridSift();
|
||
frmGridSift.CustomColumKey = this.CustomColumKey;
|
||
//frmGridSift.source = newDt;
|
||
frmGridSift.ParentGridEx = this;
|
||
DllModule module = new DllModule
|
||
{
|
||
DllName = "",
|
||
Id = this.Model.ModuleCode,
|
||
Name = this.Model.FormText,
|
||
BeforePage = ERPInfo.Instance.PageControl.SelectedTabPage
|
||
};
|
||
module.ModuleForm = frmGridSift;
|
||
string guid = Guid.NewGuid().ToString();
|
||
DevExpress.XtraTab.XtraTabPage tp = new DevExpress.XtraTab.XtraTabPage();
|
||
tp.Tag = guid;
|
||
// 这个必须有不然会提示:"不能向tabControl中添加顶级控件"
|
||
frmGridSift.TopLevel = false;
|
||
frmGridSift.Location = new Point(0, 0);
|
||
frmGridSift.Dock = DockStyle.Fill;
|
||
frmGridSift.FormBorderStyle = FormBorderStyle.None;
|
||
tp.Text = this.Model.FormText + "分组统计";
|
||
tp.AutoScroll = true;
|
||
tp.AutoScroll = true;
|
||
tp.Controls.Add(frmGridSift);
|
||
tp.ShowCloseButton = DefaultBoolean.True;
|
||
tp.Dock = DockStyle.Fill;
|
||
ERPInfo.Instance.PageControl.TabPages.Add(tp);
|
||
ERPInfo.Instance.PageControl.SelectedTabPage = tp;
|
||
ERPInfo.Instance.ModuleForms.Add(guid, module);
|
||
frmGridSift.Show();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:根据显示值获取隐藏Value</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2022-11-04 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public DataTable SetDealWithValueTab()
|
||
{
|
||
Dictionary<GridColumnModel, DataTable> ValueGridColumnTable = new Dictionary<GridColumnModel, DataTable>();
|
||
Dictionary<string, string> LookupParentKey = new Dictionary<string, string>();
|
||
DataTable dataTable = this.gridView.GetGridViewFilteredAndSortedDataToDataTable();
|
||
DataTable dtResult = new DataTable();
|
||
if (dataTable != null)
|
||
{
|
||
DataTable nowDt = dataTable.Copy();
|
||
foreach (DataColumn dataCol in nowDt.Columns)
|
||
{
|
||
GridColumn newColumn = this.gridView.Columns.FirstOrDefault(x => (dataCol.ColumnName + "").Equals(x.FieldName + ""));
|
||
DataColumn newDataColumn = dataTable.Columns.Cast<DataColumn>().FirstOrDefault(x => (dataCol.ColumnName + "").Equals(x.ColumnName + ""));
|
||
if (newColumn == null)
|
||
{
|
||
dataTable.Columns.Remove(newDataColumn);
|
||
}
|
||
else
|
||
{
|
||
GridColumnModel model = newColumn.Tag as GridColumnModel;
|
||
if (model.Visible)
|
||
{
|
||
dataTable.Columns[newDataColumn.ColumnName].ColumnName = newColumn.FieldName;
|
||
dataTable.Columns[newDataColumn.ColumnName].Caption = newColumn.Caption;
|
||
if (ControlType.IsValue(model.FieldType))
|
||
{
|
||
string sqlValue = model.SqlSource;
|
||
if (sqlValue.Contains(" #"))
|
||
{
|
||
//sqlValue = sqlValue.Replace("#", "");
|
||
Match m = Regex.Match(sqlValue, @"#([\s\S]*?)#");
|
||
//处理带参数上一级编码过滤问题,需在带参数sql中增加名称的父级字段
|
||
if (m.Success)
|
||
{
|
||
sqlValue = Regex.Replace(sqlValue, "#[^##]+#", " 1=1 ");
|
||
LookupParentKey.Add(model.FieldName, m.Value.Replace("#", ""));
|
||
}
|
||
}
|
||
ValueGridColumnTable.Add(model, BaseImpl.GetDataTableResult(sqlValue));
|
||
|
||
}
|
||
}
|
||
else
|
||
{
|
||
dataTable.Columns.Remove(newDataColumn);
|
||
}
|
||
}
|
||
}
|
||
//克隆表结构
|
||
dtResult = dataTable.Clone();
|
||
//修改数据列类型
|
||
foreach (DataColumn col in dtResult.Columns)
|
||
{
|
||
col.DataType = typeof(string);
|
||
}
|
||
foreach (DataRow dataRow in dataTable.Rows)
|
||
{
|
||
DataRow rowNew = dtResult.NewRow();
|
||
foreach (DataColumn datacol in dataTable.Columns)
|
||
{
|
||
rowNew[datacol.ColumnName] = dataRow[datacol.ColumnName] + "";
|
||
|
||
}
|
||
dtResult.Rows.Add(rowNew);
|
||
}
|
||
foreach (DataRow dataRow in dtResult.Rows)
|
||
{
|
||
foreach (GridColumnModel item in ValueGridColumnTable.Keys)
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(dataRow[item.FieldName] + ""))
|
||
{
|
||
DataTable table = ValueGridColumnTable[item];
|
||
DataRow rowItemValue = table.Rows.Cast<DataRow>().FirstOrDefault(x => x[item.ValueMember] + "" == dataRow[item.FieldName + ""] + "");
|
||
DataRow rowItemText = table.Rows.Cast<DataRow>().FirstOrDefault(x => x[item.ValueMember] + "" == dataRow[item.FieldName + ""] + "");
|
||
dataRow[item.FieldName + ""] = rowItemValue != null ? rowItemValue[item.TextMember] + "" : rowItemText != null ? rowItemText[item.TextMember] + "" : "";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return dtResult;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:调用bs展示图表模块</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2020-07-27 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected virtual void ChartShowClick(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
// 其它处理(如绑定左侧树结构数据)
|
||
if (OnGridColumnCallDLL != null) this.OnGridColumnCallDLL("1");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:调用bs展示图表模块</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2020-07-27 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected virtual void BsChartShowClick(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
// 其它处理(如绑定左侧树结构数据)
|
||
if (OnGridColumnCallDLL != null) this.OnGridColumnCallDLL("0");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:所有表格属性设置</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2020-12-29 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected virtual void InstAllColumn(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
string[] defaultArgs = string.Format(ModuleArgs.DefaultArgs, this.Model.FormText, ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, this.Model.Privilege, this.Model.ModuleCode).Split('~');
|
||
string[] menuArgs = new string[] { Model.ModuleCode, CustomColumKey };
|
||
string[] args = defaultArgs.Concat(menuArgs).ToArray();
|
||
IForm form = FormHelper.LoadDllForm("Lskj.ToolSetNew.dll", args);
|
||
DialogResult result = form.SubForm.ShowDialog();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 查找指定列(定位到弹窗选中列)
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected virtual void LookUpColumn(object sender, EventArgs e)
|
||
{
|
||
|
||
Dictionary<string, string> columnInformation = new Dictionary<string, string>();
|
||
foreach (GridColumn column in this.gridView.Columns)
|
||
{
|
||
if (column.Visible)
|
||
{
|
||
columnInformation.Add(column.FieldName, column.Caption);
|
||
}
|
||
}
|
||
FrmPositioningColumn frmPositioningColumn = new FrmPositioningColumn(columnInformation);
|
||
if (frmPositioningColumn.ShowDialog() == DialogResult.OK)
|
||
{
|
||
string columnNameToFind = frmPositioningColumn.FindName;
|
||
GridColumn column = this.gridView.Columns.ColumnByFieldName(columnNameToFind);
|
||
if (column != null)
|
||
{
|
||
this.gridView.FocusedColumn = column; // 让指定列获得焦点
|
||
if (this.gridView.FocusedRowHandle >= 0)
|
||
{
|
||
this.gridView.MakeRowVisible(this.gridView.FocusedRowHandle);
|
||
//this.gridView.ClearSelection();
|
||
//this.gridView.SelectCell(this.gridView.FocusedRowHandle, column);
|
||
}
|
||
this.gridView.MakeColumnVisible(column);
|
||
this.gridView.Invalidate(); // 重绘视图
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:根据显示值获取隐藏Value</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-06-03 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="columnEdit">The column edit.</param>
|
||
/// <returns>System.Object.</returns>
|
||
protected virtual object GetValueByCaption(GridColumnModel model, RepositoryItem columnEdit, object text, out bool result)
|
||
{
|
||
DataTable table = new DataTable();
|
||
bool moduleReturnCheck = false;//模块选择框复选
|
||
if (string.IsNullOrEmpty(text + ""))
|
||
{
|
||
result = false;
|
||
return text;
|
||
}
|
||
|
||
if (columnEdit is RepositoryItemLookUpEdit)
|
||
{
|
||
RepositoryItemLookUpEdit item = columnEdit as RepositoryItemLookUpEdit;
|
||
table = item.DataSource as DataTable;
|
||
}
|
||
else if (columnEdit is RepositoryItemSearchLookUpEdit)
|
||
{
|
||
RepositoryItemSearchLookUpEdit item = columnEdit as RepositoryItemSearchLookUpEdit;
|
||
table = item.DataSource as DataTable;
|
||
}
|
||
else if (columnEdit is RepositoryItemGridLookUpEdit)
|
||
{
|
||
RepositoryItemGridLookUpEdit item = columnEdit as RepositoryItemGridLookUpEdit;
|
||
table = item.DataSource as DataTable;
|
||
}
|
||
else if (columnEdit is RepositoryItemCheckedComboBoxEdit)
|
||
{
|
||
RepositoryItemCheckedComboBoxEdit rccbe = columnEdit as RepositoryItemCheckedComboBoxEdit;
|
||
FrmModelLookUp modelLookUp = rccbe.Buttons[1].Tag as FrmModelLookUp;
|
||
if (!modelLookUp.SingleChoiceMode) moduleReturnCheck = true;
|
||
table = rccbe.DataSource as DataTable;
|
||
}
|
||
if (table != null && table.Rows.Count > 0 && table.Columns.Count > 0)
|
||
{
|
||
if ((model.FieldType == ControlType.LabMultiSelectValue || model.FieldType == ControlType.LabMultiSelectValueNew || model.FieldType == ControlType.LabMultiSelectValueParam || moduleReturnCheck))
|
||
{
|
||
string[] values = (text + "").Trim(',').Split(',');
|
||
string textNew = string.Empty;
|
||
foreach (string value in values)
|
||
{
|
||
DataRow rowItemNew = table.Select("1=1").FirstOrDefault(x => (value + "").Equals(x[model.TextMember] + ""));
|
||
if (rowItemNew != null)
|
||
{
|
||
textNew += rowItemNew[model.ValueMember] + ",";
|
||
}
|
||
}
|
||
result = !string.IsNullOrEmpty(textNew) ? textNew == text + "" : false;
|
||
return !string.IsNullOrEmpty(textNew) ? textNew : text;
|
||
}
|
||
DataRow rowItem = table.Select("1=1").FirstOrDefault(x => (text + "").Equals(x[model.TextMember] + ""));
|
||
result = rowItem != null ? rowItem[model.ValueMember] + "" == text + "" : false;
|
||
return rowItem != null ? rowItem[model.ValueMember] + "" : text;
|
||
}
|
||
result = false;
|
||
return text;
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 模块返回框验证(外部粘贴时验证值是否正确)
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
/// <param name="columnEdit"></param>
|
||
/// <param name="text"></param>
|
||
/// <param name="result"></param>
|
||
/// <returns></returns>
|
||
protected virtual object ModuleReturnVerify(GridColumnModel model, RepositoryItem columnEdit, object text, out bool result)
|
||
{
|
||
DataTable table = new DataTable();
|
||
bool moduleReturnCheck = false;//多选模式
|
||
if (string.IsNullOrEmpty(text + ""))
|
||
{
|
||
result = false;
|
||
return text;
|
||
}
|
||
if (columnEdit is RepositoryItemCheckedComboBoxEdit)
|
||
{
|
||
RepositoryItemCheckedComboBoxEdit rccbe = columnEdit as RepositoryItemCheckedComboBoxEdit;
|
||
if (rccbe.Buttons[1].Tag is FrmModelLookUp)
|
||
{
|
||
FrmModelLookUp modelLookUp = rccbe.Buttons[1].Tag as FrmModelLookUp;
|
||
if (!modelLookUp.SingleChoiceMode) moduleReturnCheck = true;
|
||
table = rccbe.DataSource as DataTable;
|
||
}
|
||
if (rccbe.Buttons[1].Tag is FrmModelLookUp2)
|
||
{
|
||
FrmModelLookUp2 modelLookUp = rccbe.Buttons[1].Tag as FrmModelLookUp2;
|
||
if (!modelLookUp.SingleChoiceMode) moduleReturnCheck = true;
|
||
table = rccbe.DataSource as DataTable;
|
||
}
|
||
|
||
|
||
}
|
||
if (table != null && table.Rows.Count > 0 && table.Columns.Count > 0)
|
||
{
|
||
if (moduleReturnCheck)
|
||
{
|
||
string[] values = (text + "").Trim(',').Split(',');
|
||
string textNew = string.Empty;
|
||
foreach (string value in values)
|
||
{
|
||
DataRow rowItemNew = table.Select("1=1").FirstOrDefault(x => (value + "").Equals(x[model.TextMember] + ""));
|
||
if (rowItemNew != null)
|
||
{
|
||
textNew += rowItemNew[model.ValueMember] + ",";
|
||
}
|
||
}
|
||
result = !string.IsNullOrEmpty(textNew) ? textNew == text + "" : false;
|
||
return !string.IsNullOrEmpty(textNew) ? textNew : text;
|
||
}
|
||
DataRow rowItem = table.Select("1=1").FirstOrDefault(x => (text + "").Equals(x[model.TextMember] + ""));
|
||
result = rowItem != null ? rowItem[model.ValueMember] + "" == text + "" : false;
|
||
return rowItem != null ? rowItem[model.ValueMember] + "" : text;
|
||
}
|
||
result = false;
|
||
return text;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 去除多选框中的空格
|
||
/// </summary>
|
||
private object ReplaceMultiSpace(object text)
|
||
{
|
||
if (string.IsNullOrEmpty(text + ""))
|
||
{
|
||
return text;
|
||
}
|
||
string[] keyValues = (text + "").Split(',');
|
||
string returnText = "";
|
||
foreach (string keyValue in keyValues)
|
||
{
|
||
string newKeyValue = keyValue.Trim();
|
||
returnText += string.Format("{0},", newKeyValue);
|
||
}
|
||
returnText = returnText.TrimEnd(',');
|
||
return returnText + ",";
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:创建DateTime控件</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-08-21 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
/// <param name="fieldType">Type of the field.</param>
|
||
public void InitDateTimeEdit(GridColumn gridColumn, int fieldType)
|
||
{
|
||
RepositoryItemDateEdit dateEdit = new RepositoryItemDateEdit();
|
||
dateEdit.DisplayFormat.FormatString = dateEdit.EditFormat.FormatString = dateEdit.Mask.EditMask = DateFormat.Format(fieldType);
|
||
dateEdit.DisplayFormat.FormatType = dateEdit.EditFormat.FormatType = DevExpress.Utils.FormatType.Custom;
|
||
|
||
if (fieldType == ControlType.LabDateTime)
|
||
{
|
||
dateEdit.Properties.VistaDisplayMode = DevExpress.Utils.DefaultBoolean.True;
|
||
dateEdit.Properties.VistaEditTime = DevExpress.Utils.DefaultBoolean.True;
|
||
}
|
||
|
||
if (fieldType == ControlType.LabShortDate)
|
||
{
|
||
dateEdit.Properties.Mask.UseMaskAsDisplayFormat = true;//掩码属性使用掩码作为显示格式
|
||
dateEdit.Properties.DisplayFormat.FormatType = dateEdit.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.Custom;
|
||
dateEdit.Properties.VistaCalendarInitialViewStyle = DevExpress.XtraEditors.VistaCalendarInitialViewStyle.YearView;
|
||
dateEdit.Properties.VistaCalendarViewStyle = DevExpress.XtraEditors.VistaCalendarViewStyle.YearView;
|
||
}
|
||
//dateEdit.Closed += new ClosedEventHandler(dateEdit_Closed);
|
||
|
||
gridControl.RepositoryItems.Add(dateEdit);
|
||
gridColumn.ColumnEdit = dateEdit;
|
||
}
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 初始化表格专用日期半天选择列,保存值格式为 yyyy-MM-dd 上午/下午。
|
||
/// </summary>
|
||
private void InitSpecialDate(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
SpecialDatePopup specialDatePopup = new SpecialDatePopup();
|
||
specialDatePopup.Dock = DockStyle.Fill;
|
||
|
||
PopupContainerControl popupControl = new PopupContainerControl();
|
||
popupControl.Controls.Add(specialDatePopup);
|
||
popupControl.Size = specialDatePopup.Size;
|
||
// 通过 PopupControl.Tag 保存弹出层实例,QueryPopUp 时可取回并同步当前单元格值。
|
||
popupControl.Tag = specialDatePopup;
|
||
|
||
RepositoryItemPopupContainerEdit dateEdit = new RepositoryItemPopupContainerEdit();
|
||
dateEdit.NullText = "";
|
||
dateEdit.Buttons.Clear();
|
||
dateEdit.Buttons.Add(new EditorButton(ButtonPredefines.Combo));
|
||
// 允许手工修改文本,同时保留下拉选择。
|
||
//dateEdit.TextEditStyle = TextEditStyles.Standard;
|
||
// 只能下拉选择
|
||
dateEdit.TextEditStyle = TextEditStyles.DisableTextEditor;
|
||
dateEdit.PopupControl = popupControl;
|
||
// 下拉打开前,把当前单元格值回填到弹出层。
|
||
dateEdit.QueryPopUp += OnSpecialDateQueryPopUp;
|
||
dateEdit.Tag = model;
|
||
|
||
// 弹出层只抛出按钮动作,真正写入表格单元格由 GridControlEx 统一处理。
|
||
specialDatePopup.ConfirmClick += OnSpecialDateConfirmClick;
|
||
specialDatePopup.ClearClick += OnSpecialDateClearClick;
|
||
specialDatePopup.CancelClick += OnSpecialDateCancelClick;
|
||
|
||
gridControl.RepositoryItems.Add(dateEdit);
|
||
gridColumn.ColumnEdit = dateEdit;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 下拉框弹出前,同步当前编辑器和当前单元格值到 SpecialDatePopup。
|
||
/// </summary>
|
||
private void OnSpecialDateQueryPopUp(object sender, CancelEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
PopupContainerEdit popupEdit = sender as PopupContainerEdit;
|
||
if (popupEdit == null) return;
|
||
|
||
SpecialDatePopup specialDatePopup = popupEdit.Properties.PopupControl.Tag as SpecialDatePopup;
|
||
if (specialDatePopup == null) return;
|
||
|
||
popupEdit.Properties.PopupControl.Size = specialDatePopup.Size;
|
||
// 记录本次正在编辑的 PopupContainerEdit,确定/清空/取消时需要回写或关闭它。
|
||
specialDatePopup.OwnerEdit = popupEdit;
|
||
specialDatePopup.SetValue(popupEdit.EditValue + "");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 用户点击确定,把弹出层选择的日期和上午/下午写回当前单元格。
|
||
/// </summary>
|
||
private void OnSpecialDateConfirmClick(object sender, EventArgs e)
|
||
{
|
||
SpecialDatePopup specialDatePopup = sender as SpecialDatePopup;
|
||
if (specialDatePopup == null) return;
|
||
SpecialDateSetEditValue(sender, specialDatePopup.SelectedValue);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 用户点击清除,清空当前单元格值。
|
||
/// </summary>
|
||
private void OnSpecialDateClearClick(object sender, EventArgs e)
|
||
{
|
||
SpecialDateSetEditValue(sender, string.Empty);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 用户点击取消,只关闭下拉框,不修改当前单元格值。
|
||
/// </summary>
|
||
private void OnSpecialDateCancelClick(object sender, EventArgs e)
|
||
{
|
||
PopupContainerEdit popupEdit = GetSpecialDateOwnerEdit(sender);
|
||
if (popupEdit != null)
|
||
{
|
||
popupEdit.ClosePopup();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 统一设置当前单元格值,并提交编辑器,让 GridView 后续保存流程能取到新值。
|
||
/// </summary>
|
||
private void SpecialDateSetEditValue(object sender, string value)
|
||
{
|
||
PopupContainerEdit popupEdit = GetSpecialDateOwnerEdit(sender);
|
||
if (popupEdit == null) return;
|
||
|
||
popupEdit.EditValue = value;
|
||
popupEdit.ClosePopup();
|
||
this.gridView.PostEditor();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 从弹出层取回本次正在编辑的 PopupContainerEdit。
|
||
/// </summary>
|
||
private PopupContainerEdit GetSpecialDateOwnerEdit(object sender)
|
||
{
|
||
SpecialDatePopup specialDatePopup = sender as SpecialDatePopup;
|
||
return specialDatePopup == null ? null : specialDatePopup.OwnerEdit;
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:创建Time控件</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-08-21 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
/// <param name="fieldType">Type of the field.</param>
|
||
public void InitTimeEdit(GridColumn gridColumn, int fieldType)
|
||
{
|
||
RepositoryItemTimeEdit timeEdit = new RepositoryItemTimeEdit();
|
||
timeEdit.DisplayFormat.FormatString = timeEdit.EditFormat.FormatString = timeEdit.Mask.EditMask = DateFormat.Format(fieldType);
|
||
timeEdit.DisplayFormat.FormatType = timeEdit.EditFormat.FormatType = DevExpress.Utils.FormatType.Custom;
|
||
|
||
|
||
|
||
gridControl.RepositoryItems.Add(timeEdit);
|
||
gridColumn.ColumnEdit = timeEdit;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:创建计算器控件</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-08-21 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
public void InitCalcEdit(GridColumn gridColumn)
|
||
{
|
||
RepositoryItemCalcEdit calcEdit = new RepositoryItemCalcEdit();
|
||
calcEdit.AllowMouseWheel = false;
|
||
|
||
gridControl.RepositoryItems.Add(calcEdit);
|
||
gridColumn.ColumnEdit = calcEdit;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:创建备注框</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-08-21 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
public void InitMemoEdit(GridColumn gridColumn)
|
||
{
|
||
RepositoryItemMemoExEdit memoEdit = new RepositoryItemMemoExEdit();
|
||
memoEdit.WordWrap = true;
|
||
memoEdit.ShowIcon = false;
|
||
if (!gridColumn.OptionsColumn.AllowEdit)
|
||
{
|
||
gridColumn.OptionsColumn.AllowEdit = true;
|
||
//设置只读
|
||
memoEdit.ReadOnly = true;
|
||
//只读状态允许下拉列表
|
||
memoEdit.AllowDropDownWhenReadOnly = DefaultBoolean.True;
|
||
}
|
||
gridControl.RepositoryItems.Add(memoEdit);
|
||
gridColumn.ColumnEdit = memoEdit;
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:创建备注框</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2019-08-15 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
public void InitRemarkEdit(GridColumn gridColumn)
|
||
{
|
||
RepositoryItemMemoEdit memo = new RepositoryItemMemoEdit();
|
||
memo.Appearance.TextOptions.WordWrap = WordWrap.Wrap;//自动换行
|
||
gridControl.RepositoryItems.Add(memo);
|
||
gridColumn.ColumnEdit = memo;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:富文本编辑框</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-06-01 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
/// <param name="model">The model.</param>
|
||
public void InitRichEdit(GridColumn gridColumn)
|
||
{
|
||
//gridColumn.AppearanceCell.Options.UseFont = true;
|
||
//gridColumn.AppearanceCell.Font = new Font("宋体", 15f);
|
||
RepositoryItemRichTextEdit richEdit = new RepositoryItemRichTextEdit();
|
||
richEdit.Encoding = Encoding.UTF8;//乱码问题
|
||
//richEdit.Appearance.Font = new Font("宋体", 15f);
|
||
gridControl.RepositoryItems.Add(richEdit);
|
||
gridColumn.ColumnEdit = richEdit;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:创建进度条控件</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-08-21 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
public void InitProgressEdit(GridColumn gridColumn)
|
||
{
|
||
RepositoryItemProgressBar progressEdit = new RepositoryItemProgressBar();
|
||
progressEdit.ShowTitle = true;
|
||
|
||
//progressEdit.Maximum = 200;
|
||
|
||
this.ProgressBarColumn.Add(gridColumn.FieldName);
|
||
gridControl.RepositoryItems.Add(progressEdit);
|
||
gridColumn.ColumnEdit = progressEdit;
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:创建CheckBoxEdit</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-08-21 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
public void InitCheckEdit(GridColumn gridColumn)
|
||
{
|
||
RepositoryItemCheckEdit checkEdit = new RepositoryItemCheckEdit();
|
||
checkEdit.ValueChecked = 1;
|
||
checkEdit.ValueUnchecked = 0;
|
||
|
||
gridControl.RepositoryItems.Add(checkEdit);
|
||
gridColumn.ColumnEdit = checkEdit;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:创建自动换行文本框</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-08-21 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
public void InitAutoLinefeedEdit(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
DevExpress.XtraEditors.Repository.RepositoryItemMemoEdit AutoLinefeedEdit = new DevExpress.XtraEditors.Repository.RepositoryItemMemoEdit();
|
||
gridColumn.ColumnEdit = AutoLinefeedEdit;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:创建下拉列表框</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-08-21 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
public void InitPasswordEdit(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
RepositoryItemTextEdit passEdit = new RepositoryItemTextEdit();
|
||
passEdit.UseSystemPasswordChar = true;
|
||
passEdit.PasswordChar = '*';
|
||
gridColumn.ColumnEdit = passEdit;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:创建下拉列表框</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-08-21 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
public void InitComboxEdit(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
RepositoryItemLookUpEdit comboxEdit = new RepositoryItemLookUpEdit();
|
||
if (model.FontSize > 0) comboxEdit.Appearance.Font = new Font("微软雅黑", model.FontSize);
|
||
comboxEdit.SearchMode = SearchMode.AutoFilter;
|
||
//comboxEdit.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//允许编辑
|
||
comboxEdit.ShowHeader = false;
|
||
comboxEdit.ImmediatePopup = false;
|
||
comboxEdit.NullText = "";
|
||
comboxEdit.PopupBorderStyle = PopupBorderStyles.Flat;
|
||
comboxEdit.AllowNullInput = DefaultBoolean.False;
|
||
comboxEdit.DisplayMember = model.TextMember;
|
||
comboxEdit.ValueMember = ControlType.LabComboxText == model.FieldType || ControlType.LabComboxTextParam == model.FieldType ? model.TextMember : model.ValueMember;
|
||
//comboxEdit.DataSource = MainImpl.GetDataTableResult(model.SqlSource);
|
||
comboxEdit.Tag = model;
|
||
comboxEdit.QueryPopUp += ComboxEdit_QueryPopUp;
|
||
|
||
LookUpColumnInfo valueColumn = new LookUpColumnInfo();
|
||
valueColumn.Caption = "编码";
|
||
valueColumn.FieldName = model.ValueMember;
|
||
valueColumn.Visible = false;
|
||
|
||
LookUpColumnInfo textColumn = new LookUpColumnInfo();
|
||
textColumn.Caption = "名称";
|
||
textColumn.FieldName = model.TextMember;
|
||
|
||
comboxEdit.Columns.AddRange(new LookUpColumnInfo[] { valueColumn, textColumn });
|
||
|
||
if (model.SourceRow.Table.Columns.Contains("remark"))
|
||
{
|
||
LookUpColumnInfo remarkColumn = new LookUpColumnInfo();
|
||
remarkColumn.Caption = "备注";
|
||
remarkColumn.FieldName = "remark";
|
||
remarkColumn.Visible = false;
|
||
|
||
comboxEdit.Columns.Add(remarkColumn);
|
||
}
|
||
|
||
gridControl.RepositoryItems.Add(comboxEdit);
|
||
gridColumn.ColumnEdit = comboxEdit;
|
||
|
||
this.mControlList.Add(model);
|
||
}
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:创建树节点自动搜索框</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2021-03-23 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
public void InitAutoTreeSearchEdit(GridColumn gridColumn, GridColumnModel model, bool isMulitClick = true, bool isRootNode = true)
|
||
{
|
||
PubTreeLookUp _popup = new PubTreeLookUp();
|
||
//_popup.LookUp = gridColumn;
|
||
//_popup.ValueMember = ControlType.LabTreeLookValue == model.FieldType || ControlType.LabCheckTreeLookValue == model.FieldType || ControlType.LabTreeLastlevelValue == model.FieldType || ControlType.LabCheckTreeLastlevelValue == model.FieldType ? model.ValueMember : model.TextMember;
|
||
_popup.ValueMember = ControlType.LabMultiComTreeboxValueParam == model.FieldType || ControlType.LabMultiComTreeboxValue == model.FieldType || ControlType.LabMulitTreeValue == model.FieldType || ControlType.LabMulitTreeValueParam == model.FieldType || ControlType.LabTreeLookValue == model.FieldType || ControlType.LabCheckTreeLookValue == model.FieldType || ControlType.LabTreeLastlevelValue == model.FieldType || ControlType.LabCheckTreeLastlevelValue == model.FieldType ? model.ValueMember : model.TextMember;
|
||
_popup.ValueField = model.ValueMember;
|
||
_popup.TextMember = model.TextMember;
|
||
_popup.SourceSQL = model.SqlSource;
|
||
_popup.TreeViewObj.CheckBoxes = _popup.isMultiClick = isMulitClick;
|
||
DataTable table = MainImpl.GetDataTableResult(model.SqlSource);
|
||
_popup.SetDataSource(table);
|
||
_popup.Dock = DockStyle.Fill;
|
||
_popup.model = model;
|
||
_popup.TreeViewExObj.TreeCheckModel = model.TreeCheckModel;
|
||
_popup.isRootNode = isRootNode;
|
||
RepositoryItemPopupContainerEdit btnEdit = new RepositoryItemPopupContainerEdit();
|
||
btnEdit.NullText = "";
|
||
btnEdit.Buttons.Clear();
|
||
btnEdit.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//文本框可输入
|
||
btnEdit.MouseDown += new MouseEventHandler(OnAutoGridLookUpGotFocus);
|
||
btnEdit.KeyUp += new KeyEventHandler(OnAutoGridLookUpKeyUp);
|
||
btnEdit.PopupControl = new PopupContainerControl();
|
||
btnEdit.PopupControl.AllowDrop = true;
|
||
btnEdit.PopupControl.Controls.Add(_popup);
|
||
if (isMulitClick) _popup.TreeViewExObj.OnGridViewEnter += OnPopupGridViewEnter;
|
||
if (!isMulitClick) _popup.TreeViewExObj.OnTreeNodeMouseClick += OnPopupGridMouseClick;
|
||
btnEdit.PopupControl.Tag = _popup;
|
||
btnEdit.QueryPopUp += OnQueryPopUp;
|
||
if (ControlType.LabMultiComTreeboxValueParam == model.FieldType || ControlType.LabMultiComTreeboxValue == model.FieldType || ControlType.LabMulitTreeValue == model.FieldType || ControlType.LabMulitTreeValueParam == model.FieldType || model.FieldType == ControlType.LabTreeLookValue || model.FieldType == ControlType.LabCheckTreeLookValue || ControlType.LabTreeLastlevelValue == model.FieldType || ControlType.LabCheckTreeLastlevelValue == model.FieldType)
|
||
{
|
||
btnEdit.QueryDisplayText += OnQueryDisplayText;
|
||
}
|
||
btnEdit.Tag = model;
|
||
gridControl.RepositoryItems.Add(btnEdit);
|
||
//gridColumn.OptionsColumn.ReadOnly = true;
|
||
gridColumn.ColumnEdit = btnEdit;
|
||
this.mControlList.Add(model);
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:自定义设置其弹出框宽度</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2021-03-29 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
private void OnQueryPopUp(object sender, CancelEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
PopupContainerEdit popupedit = (PopupContainerEdit)sender;
|
||
PubTreeLookUp pubTreeLookUp = popupedit.Properties.PopupControl.Tag as PubTreeLookUp;
|
||
if (pubTreeLookUp.isMultiClick)
|
||
{
|
||
popupedit.Properties.PopupControl.Height = 200;
|
||
}
|
||
else
|
||
{
|
||
popupedit.Properties.PopupControl.Height = 150;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:自定义设置其显示值</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2021-03-29 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
private void OnQueryDisplayText(object sender, QueryDisplayTextEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
RepositoryItemPopupContainerEdit PopupEdit = sender as RepositoryItemPopupContainerEdit;
|
||
if (PopupEdit != null)
|
||
{
|
||
PubTreeLookUp popup = (PopupEdit.PopupControl.Tag) as PubTreeLookUp;
|
||
if (e.EditValue == null) return;
|
||
string[] values = e.EditValue.ToString().Trim(',').Split(',');
|
||
string text = string.Empty;
|
||
foreach (string item in values)
|
||
{
|
||
//if (e.Node.Nodes.Count > 0 && !popup.isRootNode)
|
||
//{
|
||
// return;
|
||
//}
|
||
DataRow rowItem = popup.DataSourceTable.Rows.Cast<DataRow>().FirstOrDefault(x => x[popup.ValueMember] + "" == item);
|
||
if (rowItem != null)
|
||
{
|
||
text += rowItem[popup.TextMember] + ",";
|
||
}
|
||
}
|
||
e.DisplayText = text.Trim(',');
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:创建自动搜索框</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-08-21 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
public void InitAutoSearchEdit(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
int popWidth = 0;
|
||
|
||
//DataTable table = MainImpl.GetDataTableResult(ReplaceHelper.ReplaceWhereCond(model.SqlSource) + " and 1<>1");
|
||
RepositoryItemGridLookUpEdit searchEdit = new RepositoryItemGridLookUpEdit();
|
||
if (model.FontSize > 0) searchEdit.View.Appearance.Row.Font = new Font("微软雅黑", model.FontSize);
|
||
searchEdit.View.OptionsView.ShowIndicator = false;
|
||
searchEdit.View.OptionsView.ColumnAutoWidth = false;
|
||
searchEdit.PopupSizeable = true;
|
||
searchEdit.PopupResizeMode = ResizeMode.Default;
|
||
|
||
searchEdit.AllowFocused = true;
|
||
searchEdit.ImmediatePopup = true;
|
||
|
||
searchEdit.ShowFooter = false;
|
||
searchEdit.NullText = "";
|
||
searchEdit.TextEditStyle = TextEditStyles.Standard;
|
||
searchEdit.PopupBorderStyle = PopupBorderStyles.Flat;
|
||
searchEdit.AllowNullInput = DefaultBoolean.False;
|
||
searchEdit.ShowPopupShadow = true;
|
||
searchEdit.DisplayMember = model.TextMember;
|
||
searchEdit.ValueMember = ControlType.LabAutoCompleteText == model.FieldType || ControlType.LabAutoCompleteTextParam == model.FieldType ||
|
||
ControlType.LabAutoGridText == model.FieldType || ControlType.LabAutoGridTextParam == model.FieldType
|
||
? model.TextMember : model.ValueMember;
|
||
//searchEdit.DataSource = table;
|
||
searchEdit.Tag = model;
|
||
searchEdit.View.Appearance.HeaderPanel.TextOptions.HAlignment = HorzAlignment.Center;
|
||
searchEdit.View.PopupMenuShowing += new PopupMenuShowingEventHandler(OnAutoSearchEditPopupMenuShowing);
|
||
searchEdit.KeyDown += OnsearchEditKeyDown;
|
||
searchEdit.QueryPopUp += new CancelEventHandler(OnSearchEditQueryPopUp);
|
||
DataTable cusTable = new DataTable();
|
||
|
||
GridColumn valueColumn = new GridColumn();
|
||
valueColumn.Name = valueColumn.FieldName = model.ValueMember;
|
||
valueColumn.Caption = "编码";
|
||
valueColumn.Visible = model.ValueMember.Substring(0, 1) != "_";
|
||
|
||
GridColumn textColumn = new GridColumn();
|
||
textColumn.Name = textColumn.FieldName = model.TextMember;
|
||
textColumn.Caption = "名称";
|
||
textColumn.Visible = model.TextMember.Substring(0, 1) != "_";
|
||
|
||
searchEdit.View.Columns.AddRange(new GridColumn[] { valueColumn, textColumn });
|
||
|
||
searchEdit.PopupFormSize = new System.Drawing.Size(popWidth, searchEdit.PopupFormSize.Height);
|
||
gridControl.RepositoryItems.Add(searchEdit);
|
||
gridColumn.ColumnEdit = searchEdit;
|
||
searchEdit.View.Tag = searchEdit;
|
||
|
||
if (model.SearchBoxAddition && (ControlType.LabAutoCompleteText == model.FieldType || ControlType.LabAutoCompleteTextParam == model.FieldType ||
|
||
ControlType.LabAutoGridText == model.FieldType || ControlType.LabAutoGridTextParam == model.FieldType))
|
||
{
|
||
searchEdit.ProcessNewValue += SearchEdit_ProcessNewValue;
|
||
searchEdit.CustomDisplayText += SearchEdit_CustomDisplayText;
|
||
|
||
}
|
||
|
||
searchEdit.EditValueChanging += gridLookUpEdit1_EditValueChanging;
|
||
//if ((ControlType.LabAutoCompleteText == model.FieldType || ControlType.LabAutoGridText == model.FieldType || ControlType.LabAutoGridTextParam == model.FieldType))
|
||
//{
|
||
// searchEdit.EditValueChanging += gridLookUpEdit1_EditValueChangingAdd;
|
||
//}
|
||
//else
|
||
//{
|
||
// searchEdit.EditValueChanging += gridLookUpEdit1_EditValueChanging;
|
||
//}
|
||
searchEdit.View.CustomDrawFilterPanel += OnCustomDrawFilterPanel;
|
||
searchEdit.View.Click += new EventHandler(View_Click);
|
||
this.mControlList.Add(model);
|
||
|
||
}
|
||
/// <summary>
|
||
/// 搜索框允许新增时,将用户输入的文本临时加入下拉数据源。
|
||
/// 这里只处理“显示文本、保存文本”的控件类型,避免给保存ID的控件自动生成不存在的ID。
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void SearchEdit_ProcessNewValue(object sender, ProcessNewValueEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
|
||
GridLookUpEdit edit = sender as GridLookUpEdit;
|
||
if (edit == null) return;
|
||
GridColumnModel model = edit.Properties.Tag as GridColumnModel;
|
||
if (model == null || !model.SearchBoxAddition) return;
|
||
|
||
if (!(ControlType.LabAutoCompleteText == model.FieldType || ControlType.LabAutoCompleteTextParam == model.FieldType ||
|
||
ControlType.LabAutoGridText == model.FieldType || ControlType.LabAutoGridTextParam == model.FieldType)) return;
|
||
|
||
string displayValue = e.DisplayValue + "";
|
||
if (string.IsNullOrWhiteSpace(displayValue)) return;
|
||
|
||
BeginInvoke(new MethodInvoker(delegate ()
|
||
{
|
||
FilterLookup(sender, displayValue);
|
||
}));
|
||
|
||
RepositoryItemGridLookUpEdit searchEdit = GridView.Columns[model.FieldName].ColumnEdit as RepositoryItemGridLookUpEdit;
|
||
if (searchEdit == null) return;
|
||
|
||
DataTable dt = searchEdit.DataSource as DataTable;
|
||
if (dt == null) return;
|
||
|
||
string valueName = searchEdit.ValueMember;
|
||
string textName = !string.IsNullOrWhiteSpace(searchEdit.DisplayMember) ? searchEdit.DisplayMember : model.TextMember;
|
||
if (string.IsNullOrWhiteSpace(valueName) || !dt.Columns.Contains(valueName)) return;
|
||
|
||
Type dataType = dt.Columns[valueName].DataType;
|
||
if (dataType != typeof(string)) return;
|
||
|
||
bool exists = dt.Rows.Cast<DataRow>().Any(x =>
|
||
(x[valueName] + "").Equals(displayValue) ||
|
||
(!string.IsNullOrWhiteSpace(textName) && dt.Columns.Contains(textName) && (x[textName] + "").Equals(displayValue)));
|
||
if (exists) return;
|
||
|
||
DataRow newRow = dt.NewRow();
|
||
newRow[valueName] = displayValue;
|
||
if (!string.IsNullOrWhiteSpace(textName) && dt.Columns.Contains(textName))
|
||
{
|
||
newRow[textName] = displayValue;
|
||
}
|
||
|
||
if (model.FieldType == ControlType.LabAutoGridTextParam || model.FieldType == ControlType.LabAutoCompleteTextParam)
|
||
{
|
||
if (this.ManuallyAddData.ContainsKey(model.FieldName))
|
||
{
|
||
this.ManuallyAddData[model.FieldName].Add(newRow);
|
||
}
|
||
else
|
||
{
|
||
this.ManuallyAddData.Add(model.FieldName, new List<DataRow>() { newRow });
|
||
}
|
||
}
|
||
|
||
dt.Rows.Add(newRow.ItemArray);
|
||
e.Handled = true;
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 搜索框新增值未持久化到下拉SQL数据源时,直接用单元格保存的文本作为显示值。
|
||
/// 这样重新打开模块后,即使下拉数据源查不到该文本,界面也不会显示为空白。
|
||
/// </summary>
|
||
private void SearchEdit_CustomDisplayText(object sender, CustomDisplayTextEventArgs e)
|
||
{
|
||
if (e.Value == null) return;
|
||
|
||
RepositoryItemGridLookUpEdit edit = sender as RepositoryItemGridLookUpEdit;
|
||
if (edit == null) return;
|
||
|
||
GridColumnModel model = edit.Tag as GridColumnModel;
|
||
if (model == null || !model.SearchBoxAddition) return;
|
||
|
||
if (!(model.FieldType == ControlType.LabAutoCompleteText ||
|
||
model.FieldType == ControlType.LabAutoCompleteTextParam ||
|
||
model.FieldType == ControlType.LabAutoGridText ||
|
||
model.FieldType == ControlType.LabAutoGridTextParam)) return;
|
||
|
||
string value = e.Value + "";
|
||
if (string.IsNullOrWhiteSpace(value)) return;
|
||
|
||
DataTable dt = edit.DataSource as DataTable;
|
||
string valueName = edit.ValueMember;
|
||
string textName = !string.IsNullOrWhiteSpace(edit.DisplayMember) ? edit.DisplayMember : model.TextMember;
|
||
if (dt == null ||
|
||
(string.IsNullOrWhiteSpace(valueName) || !dt.Columns.Contains(valueName)) &&
|
||
(string.IsNullOrWhiteSpace(textName) || !dt.Columns.Contains(textName)))
|
||
{
|
||
e.DisplayText = value;
|
||
return;
|
||
}
|
||
|
||
bool exists = dt.Rows.Cast<DataRow>().Any(x =>
|
||
(!string.IsNullOrWhiteSpace(valueName) && dt.Columns.Contains(valueName) && (x[valueName] + "") == value) ||
|
||
(!string.IsNullOrWhiteSpace(textName) && dt.Columns.Contains(textName) && (x[textName] + "") == value));
|
||
|
||
if (!exists)
|
||
{
|
||
e.DisplayText = value;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 数据源中点击将数据源更新
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void View_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
GridView gridView = sender as GridView;
|
||
DataRow rt = gridView.GetFocusedDataRow();
|
||
|
||
RepositoryItemGridLookUpEdit searchEdit = gridView.Tag as RepositoryItemGridLookUpEdit;
|
||
if (rt == null) return;
|
||
DataTable dt = (searchEdit.DataSource as DataTable);
|
||
if (dt.Rows.Cast<DataRow>().FirstOrDefault(x => x == rt) == null && dt != null && dt.Rows.Count > 0)
|
||
{
|
||
dt.Rows.Add(rt.ItemArray);
|
||
gridView.UpdateCurrentRow();
|
||
gridView.ShowEditor();
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
}
|
||
|
||
private void FilterLookup(object sender, string NewValue)
|
||
{
|
||
try
|
||
{
|
||
GridLookUpEdit edit = sender as GridLookUpEdit;
|
||
GridView gridView = edit.Properties.View as GridView;
|
||
GridColumnModel model = edit.Properties.Tag as GridColumnModel;
|
||
DataTable table = edit.Properties.DataSource as DataTable;
|
||
FieldInfo fi = gridView.GetType().GetField("extraFilter", BindingFlags.NonPublic | BindingFlags.Instance);
|
||
List<CriteriaOperator> strList = new List<CriteriaOperator>();
|
||
foreach (GridColumn colum in gridView.Columns)
|
||
{
|
||
string AutoSearchText = string.IsNullOrEmpty(edit.AutoSearchText) ? NewValue : edit.AutoSearchText;
|
||
BinaryOperator op1 = new BinaryOperator(colum.FieldName, "%" + AutoSearchText + "%", BinaryOperatorType.Like);
|
||
strList.Add(op1);
|
||
}
|
||
string isPopShow = edit.Tag + "";
|
||
if (isPopShow == "1") edit.ShowPopup();
|
||
string filterCondition = new GroupOperator(GroupOperatorType.Or, strList.ToArray()).ToString();
|
||
fi.SetValue(gridView, filterCondition);
|
||
MethodInfo mi = gridView.GetType().GetMethod("ApplyColumnsFilterEx", BindingFlags.NonPublic | BindingFlags.Instance);
|
||
edit.Tag = "0";
|
||
mi.Invoke(gridView, null);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
private void gridLookUpEdit1_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
|
||
|
||
GridLookUpEdit edit = sender as GridLookUpEdit;
|
||
if (SystemInfo.Instance.DisableCellAutoFiltering && edit.Properties != null) edit.Properties.AutoComplete = false;//设置是否启用自动完成功能
|
||
RepositoryItemGridLookUpEdit searchEdit = edit.Properties;
|
||
DataTable dt = (searchEdit.DataSource as DataTable);
|
||
BeginInvoke(new MethodInvoker(delegate ()
|
||
{
|
||
FilterLookup(sender, e.NewValue + "");
|
||
}));
|
||
if (string.IsNullOrWhiteSpace(edit.AutoSearchText) && e.NewValue == "")
|
||
{
|
||
DataRow newRow = dt.NewRow();
|
||
if (dt.Rows.Cast<DataRow>().FirstOrDefault(x => x == newRow) == null)
|
||
{
|
||
dt.Rows.Add(newRow.ItemArray);
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 把输入值添加到数据源中
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void gridLookUpEdit1_EditValueChangingAdd(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
GridLookUpEdit edit = sender as GridLookUpEdit;
|
||
RepositoryItemGridLookUpEdit searchEdit = edit.Properties;
|
||
DataTable dt = (searchEdit.DataSource as DataTable);
|
||
BeginInvoke(new MethodInvoker(delegate ()
|
||
{
|
||
FilterLookup(sender, e.NewValue + "");
|
||
}));
|
||
|
||
//if (true)
|
||
//{
|
||
// if (string.IsNullOrWhiteSpace(e.NewValue + "")) return;
|
||
// string ValueName = searchEdit.View.Columns[0].FieldName;
|
||
// string TextName = searchEdit.View.Columns[1].FieldName;
|
||
// Type dataType = dt.Columns[ValueName].DataType;
|
||
// DataRow newRow = dt.NewRow();
|
||
// if (dataType.Name == "Int32")
|
||
// {
|
||
// int maxdm = Convert.ToInt32(searchEdit.View.Columns[ValueName].Tag);
|
||
// edit.Properties.View.ActiveFilterString = string.Format(ValueName + "< {0}", maxdm);
|
||
|
||
// int maxdmIndex = dt.AsEnumerable().Select(t => t.Field<int>(ValueName)).Max();
|
||
// newRow[ValueName] = maxdmIndex + 1;
|
||
// newRow[TextName] = e.NewValue + "";
|
||
// if (dt.Rows.Cast<DataRow>().FirstOrDefault(x => (x[ValueName] + "").Equals(e.NewValue + "")) == null)
|
||
// {
|
||
// dt.Rows.Add(newRow.ItemArray);
|
||
// }
|
||
// }
|
||
// else if (dataType.Name == "String")
|
||
// {
|
||
// newRow[ValueName] = e.NewValue + "";
|
||
// newRow[TextName] = e.NewValue + "";
|
||
// if (dt.Rows.Cast<DataRow>().FirstOrDefault(x => (x[TextName] + "").Equals(e.NewValue + "")) == null)
|
||
// {
|
||
// dt.Rows.Add(newRow.ItemArray);
|
||
// }
|
||
// }
|
||
//}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:创建多选框</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-08-21 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
public void InitMutilEdit(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
FrmLookUp mutilLookUp = new FrmLookUp();
|
||
mutilLookUp.ValueField = model.ValueMember;
|
||
mutilLookUp.TextField = model.TextMember;
|
||
mutilLookUp.SourceSQL = model.SqlSource;
|
||
mutilLookUp.IsType = model.FieldType;
|
||
mutilLookUp.ValueMember = (model.FieldType == ControlType.LabMultiSelectValue || model.FieldType == ControlType.LabMultiSelectValueNew) ||
|
||
model.FieldType == ControlType.LabMultiSelectValueParam ? model.ValueMember : model.TextMember;
|
||
mutilLookUp.Tag = model;
|
||
|
||
RepositoryItemCheckedComboBoxEdit btnEdit = new RepositoryItemCheckedComboBoxEdit();
|
||
//btnEdit.CustomDisplayText += BtnEdit_CustomDisplayText;//返回id速度慢的根本原因是显示值筛选转换速度慢,可通过该事件实现自定义获取值进行改善,未实现
|
||
btnEdit.NullText = "";
|
||
btnEdit.PopupBorderStyle = PopupBorderStyles.Flat;
|
||
btnEdit.AllowNullInput = DefaultBoolean.False;
|
||
btnEdit.DisplayMember = model.TextMember;
|
||
btnEdit.SeparatorChar = ',';
|
||
btnEdit.ValueMember = model.FieldType == ControlType.LabMultiSelectValue || model.FieldType == ControlType.LabMultiSelectValueNew || model.FieldType == ControlType.LabMultiSelectValueParam ? model.ValueMember : model.TextMember;
|
||
if (!(model.FieldType == ControlType.LabMultiSelectTextParam || model.FieldType == ControlType.LabMultiSelectText || model.FieldType == ControlType.LabMultiSelectTextNew))
|
||
{
|
||
btnEdit.DataSource = MainImpl.GetDataTableResult(model.SqlSource);
|
||
}
|
||
btnEdit.Buttons[0].Visible = false; // 不能移除,移除后事件不起作用.
|
||
btnEdit.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] { new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Ellipsis) });
|
||
|
||
btnEdit.Tag = model;
|
||
btnEdit.Buttons[1].Tag = mutilLookUp;
|
||
btnEdit.ButtonClick += new ButtonPressedEventHandler(OnButtonEditClick);
|
||
gridControl.RepositoryItems.Add(btnEdit);
|
||
gridColumn.OptionsColumn.ReadOnly = true;
|
||
gridColumn.ColumnEdit = btnEdit;
|
||
|
||
this.mControlList.Add(model);
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:创建sql生成组件</para>
|
||
/// <para>创建人:曹屹峰</para>
|
||
/// <para>创建日期:2021-09-219</para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
public void InitSqlGenerate(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
FrmAutoSqlLoad sqlGenerator = new FrmAutoSqlLoad();
|
||
|
||
RepositoryItemCheckedComboBoxEdit btnEdit = new RepositoryItemCheckedComboBoxEdit();
|
||
btnEdit.NullText = "";
|
||
btnEdit.PopupBorderStyle = PopupBorderStyles.Flat;
|
||
btnEdit.AllowNullInput = DefaultBoolean.False;
|
||
// btnEdit.DisplayMember = model.TextMember;
|
||
btnEdit.SeparatorChar = ',';
|
||
//btnEdit.ValueMember = model.TextMember;
|
||
btnEdit.Buttons[0].Visible = false; // 不能移除,移除后事件不起作用.
|
||
btnEdit.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] { new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Ellipsis) });
|
||
btnEdit.Tag = model;
|
||
btnEdit.Buttons[1].Tag = sqlGenerator;
|
||
btnEdit.ButtonClick += new ButtonPressedEventHandler(OnSqlGenerate);
|
||
|
||
gridControl.RepositoryItems.Add(btnEdit);
|
||
gridColumn.OptionsColumn.ReadOnly = true;
|
||
gridColumn.ColumnEdit = btnEdit;
|
||
|
||
this.mControlList.Add(model);
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:创建 打开高拍仪</para>
|
||
/// <para>创建人:曹屹峰</para>
|
||
/// <para>创建日期:2021-12-10 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void InitHighShotMeterEdit(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
FrmHighBeater highBeater = new FrmHighBeater();
|
||
|
||
RepositoryItemCheckedComboBoxEdit btnEdit = new RepositoryItemCheckedComboBoxEdit();
|
||
btnEdit.NullText = "";
|
||
btnEdit.PopupBorderStyle = PopupBorderStyles.Flat;
|
||
btnEdit.AllowNullInput = DefaultBoolean.False;
|
||
// btnEdit.DisplayMember = model.TextMember;
|
||
btnEdit.SeparatorChar = ',';
|
||
//btnEdit.ValueMember = model.TextMember;
|
||
btnEdit.Buttons[0].Visible = false; // 不能移除,移除后事件不起作用.
|
||
btnEdit.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] { new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Ellipsis) });
|
||
btnEdit.Tag = model;
|
||
btnEdit.Buttons[1].Tag = highBeater;
|
||
btnEdit.ButtonClick += new ButtonPressedEventHandler(OnHighBeater);
|
||
|
||
gridControl.RepositoryItems.Add(btnEdit);
|
||
gridColumn.OptionsColumn.ReadOnly = true;
|
||
gridColumn.ColumnEdit = btnEdit;
|
||
|
||
this.mControlList.Add(model);
|
||
|
||
}
|
||
/// <summary>
|
||
/// 创建一维条码控件
|
||
/// </summary>
|
||
private void InitBarCode128BEdit(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
RepositoryItemPictureEdit ItemPictureEdit = new RepositoryItemPictureEdit();
|
||
ItemPictureEdit.FormatEditValue += new ConvertEditValueEventHandler(OnTextEdit_FormatEditValue);
|
||
gridControl.RepositoryItems.Add(ItemPictureEdit);
|
||
gridColumn.ColumnEdit = ItemPictureEdit;
|
||
gridColumn.MinWidth = 400;
|
||
gridColumn.Width = 400;
|
||
//byte[] fontdata = global::Lskj.Control.Properties.Resources.code128;
|
||
//unsafe //打开"允许不安全代码编译"开关,此句才不报错
|
||
//{
|
||
// fixed (byte* pFontData = fontdata)
|
||
// {
|
||
// customFont.AddMemoryFont((System.IntPtr)pFontData, fontdata.Length);
|
||
// }
|
||
//}
|
||
//try
|
||
//{
|
||
// if (!File.Exists("code128.ttf"))
|
||
// {
|
||
// FileStream pFileStream = new FileStream("code128.ttf", FileMode.Create);
|
||
// pFileStream.Write(fontdata, 0, fontdata.Length);
|
||
// pFileStream.Close();
|
||
// pFileStream.Dispose();
|
||
// }
|
||
// Lskj.Util.FontHelper.InstallFont("code128.ttf");
|
||
//}
|
||
//catch (Exception ex)
|
||
//{
|
||
//}
|
||
//Font font = new Font(customFont.Families[0], 36);
|
||
//this.gridView.RowHeight = 30;
|
||
//gridColumn.AppearanceCell.Font = font;
|
||
//gridColumn.AppearanceCell.Options.UseFont = true;
|
||
//RepositoryItemTextEdit textEdit = new RepositoryItemTextEdit();
|
||
////textEdit.Appearance.Font = font;
|
||
////textEdit.Appearance.Options.UseFont = true;
|
||
//textEdit.FormatEditValue += new ConvertEditValueEventHandler(OnTextEdit_FormatEditValue);
|
||
//gridControl.RepositoryItems.Add(textEdit);
|
||
//gridColumn.ColumnEdit = textEdit;
|
||
//this.mControlList.Add(model);
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 创建下拉列表框弹出框
|
||
/// </summary>
|
||
/// <param name="gridColumn"></param>
|
||
/// <param name="model"></param>
|
||
public void InitComboxPopup(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
FrmComboxPopup mutilLookUp = new FrmComboxPopup(model);
|
||
mutilLookUp.Tag = model;
|
||
|
||
RepositoryItemCheckedComboBoxEdit btnEdit = new RepositoryItemCheckedComboBoxEdit();
|
||
btnEdit.NullText = "";
|
||
btnEdit.PopupBorderStyle = PopupBorderStyles.Flat;
|
||
btnEdit.AllowNullInput = DefaultBoolean.False;
|
||
btnEdit.DisplayMember = model.TextMember;
|
||
btnEdit.SeparatorChar = ',';
|
||
btnEdit.ValueMember = model.FieldType == ControlType.LabComboxPopupValue ? model.ValueMember : model.TextMember;
|
||
if (model.FieldType == ControlType.LabComboxPopupValue)
|
||
{
|
||
btnEdit.DataSource = MainImpl.GetDataTableResult(model.SqlSource);
|
||
}
|
||
btnEdit.Buttons[0].Visible = false; // 不能移除,移除后事件不起作用.
|
||
btnEdit.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] { new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Ellipsis) });
|
||
|
||
btnEdit.Tag = model;
|
||
btnEdit.Buttons[1].Tag = mutilLookUp;
|
||
btnEdit.ButtonClick += new ButtonPressedEventHandler(OnComboxPopupClick);
|
||
gridControl.RepositoryItems.Add(btnEdit);
|
||
gridColumn.OptionsColumn.ReadOnly = true;
|
||
gridColumn.ColumnEdit = btnEdit;
|
||
|
||
this.mControlList.Add(model);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 下拉列表框弹出框点击
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnComboxPopupClick(object sender, ButtonPressedEventArgs e)
|
||
{
|
||
CheckedComboBoxEdit btnEdit = (CheckedComboBoxEdit)sender;
|
||
FrmComboxPopup comboxPopup = e.Button.Tag as FrmComboxPopup;
|
||
GridColumnModel model = comboxPopup.Tag as GridColumnModel;
|
||
|
||
string sql = ReplaceHelper.ReplaceRowParam(this.GridView.GetFocusedDataRow(), model.SqlSource);
|
||
comboxPopup.OnLoadnew(sql);
|
||
DialogResult result = comboxPopup.ShowDialog();
|
||
if (result == DialogResult.OK)
|
||
{
|
||
btnEdit.EditValue = comboxPopup.ShowValue;
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 创建下拉表格框弹出框
|
||
/// </summary>
|
||
/// <param name="gridColumn"></param>
|
||
/// <param name="model"></param>
|
||
public void InitGridPopup(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
FrmGridSelectPopup mutilLookUp = new FrmGridSelectPopup(model);
|
||
mutilLookUp.Tag = model;
|
||
|
||
RepositoryItemCheckedComboBoxEdit btnEdit = new RepositoryItemCheckedComboBoxEdit();
|
||
btnEdit.NullText = "";
|
||
btnEdit.PopupBorderStyle = PopupBorderStyles.Flat;
|
||
btnEdit.AllowNullInput = DefaultBoolean.False;
|
||
btnEdit.DisplayMember = model.TextMember;
|
||
btnEdit.SeparatorChar = ',';
|
||
btnEdit.ValueMember = model.FieldType == ControlType.LabGridPopupValue || model.FieldType == ControlType.LabGridPopupMutilValue ? model.ValueMember : model.TextMember;
|
||
if (model.FieldType == ControlType.LabGridPopupValue || model.FieldType == ControlType.LabGridPopupMutilValue)
|
||
{
|
||
btnEdit.DataSource = MainImpl.GetDataTableResult(model.SqlSource);
|
||
}
|
||
btnEdit.Buttons[0].Visible = false; // 不能移除,移除后事件不起作用.
|
||
btnEdit.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] { new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Ellipsis) });
|
||
|
||
btnEdit.Tag = model;
|
||
btnEdit.Buttons[1].Tag = mutilLookUp;
|
||
btnEdit.ButtonClick += new ButtonPressedEventHandler(OnGridPopupClick);
|
||
gridControl.RepositoryItems.Add(btnEdit);
|
||
gridColumn.OptionsColumn.ReadOnly = true;
|
||
gridColumn.ColumnEdit = btnEdit;
|
||
|
||
this.mControlList.Add(model);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 下拉列表表格点击
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnGridPopupClick(object sender, ButtonPressedEventArgs e)
|
||
{
|
||
CheckedComboBoxEdit btnEdit = (CheckedComboBoxEdit)sender;
|
||
FrmGridSelectPopup frmGridSelectPopup = e.Button.Tag as FrmGridSelectPopup;
|
||
GridColumnModel model = frmGridSelectPopup.Tag as GridColumnModel;
|
||
|
||
string sql = ReplaceHelper.ReplaceRowParam(this.GridView.GetFocusedDataRow(), model.SqlSource);
|
||
frmGridSelectPopup.InitNew(sql, btnEdit.Text, btnEdit.EditValue + "");
|
||
DialogResult result = frmGridSelectPopup.ShowDialog();
|
||
if (result == DialogResult.OK)
|
||
{
|
||
btnEdit.EditValue = frmGridSelectPopup.ShowValue;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:超链接</para>
|
||
/// <para>创建人:曹屹峰</para>
|
||
/// <para>创建日期:2025-06-13 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void InitHyperlink(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
// 创建超链接编辑器
|
||
RepositoryItemHyperLinkEdit hyperLinkEdit = new RepositoryItemHyperLinkEdit();
|
||
hyperLinkEdit.LinkColor = System.Drawing.Color.Blue;
|
||
hyperLinkEdit.NullText = "";
|
||
hyperLinkEdit.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
|
||
|
||
hyperLinkEdit.SingleClick = true;
|
||
hyperLinkEdit.Tag = model;
|
||
|
||
// 注册编辑器
|
||
gridControl.RepositoryItems.Add(hyperLinkEdit);
|
||
gridColumn.OptionsColumn.ReadOnly = true;
|
||
gridColumn.ColumnEdit = hyperLinkEdit;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:超链接右键列</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2025-06-13 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void InitRightlink(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
// 创建超链接编辑器
|
||
RepositoryItemHyperLinkEdit hyperLinkEdit = new RepositoryItemHyperLinkEdit();
|
||
hyperLinkEdit.LinkColor = System.Drawing.Color.Blue;
|
||
hyperLinkEdit.NullText = "";
|
||
hyperLinkEdit.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
|
||
hyperLinkEdit.SingleClick = true;
|
||
hyperLinkEdit.Tag = model;
|
||
|
||
// 注册编辑器
|
||
gridControl.RepositoryItems.Add(hyperLinkEdit);
|
||
gridColumn.OptionsColumn.ReadOnly = true;
|
||
gridColumn.ColumnEdit = hyperLinkEdit;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 点击超链接右键
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnRightClick(object sender, EventArgs e)
|
||
{
|
||
string unionright = string.Empty;
|
||
if (sender is RepositoryItemHyperLinkEdit repositoryItem)
|
||
{
|
||
if (repositoryItem != null)
|
||
{
|
||
GridColumnModel model = repositoryItem.Tag as GridColumnModel;
|
||
unionright = model.ValueMember;
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(unionright))
|
||
{
|
||
// 获取当前选中的行和列
|
||
|
||
//int rowHandle = this.gridView.FocusedRowHandle;
|
||
//string rightid = this.gridView.GetRowCellValue(rowHandle, unionright) + "";
|
||
|
||
if (!string.IsNullOrEmpty(unionright))
|
||
{
|
||
if (OnAfterLinkCilk != null)
|
||
{
|
||
this.OnAfterLinkCilk(unionright, null);//直接调用新增行方法,添加关联数据
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 点击超链接
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void HyperLinkEdit_Click(object sender, EventArgs e)
|
||
{
|
||
string urlName = string.Empty;
|
||
if (sender is RepositoryItemHyperLinkEdit repositoryItem)
|
||
{
|
||
if (repositoryItem != null)
|
||
{
|
||
GridColumnModel model = repositoryItem.Tag as GridColumnModel;
|
||
urlName = model.ValueMember;
|
||
}
|
||
}
|
||
|
||
if (string.IsNullOrWhiteSpace(urlName)) return;
|
||
// 获取当前选中的行和列
|
||
int rowHandle = this.gridView.FocusedRowHandle;
|
||
string url = this.gridView.GetRowCellValue(rowHandle, urlName) as string;
|
||
|
||
if (!string.IsNullOrEmpty(url))
|
||
{
|
||
// 打开默认浏览器访问URL
|
||
System.Diagnostics.Process.Start(url);
|
||
}
|
||
|
||
}
|
||
|
||
private void InitRightMenuBtnEdit()
|
||
{
|
||
GridColumn gridColumn = new GridColumn();
|
||
gridColumn.FieldName = "RightMenuBtnEdit";
|
||
gridColumn.Name = "RightMenuBtnEdit";
|
||
gridColumn.Caption = "操作列";
|
||
//gridColumn.OptionsColumn.ShowCaption = false;
|
||
gridColumn.Visible = true;
|
||
gridColumn.OptionsColumn.AllowEdit = true;
|
||
RepositoryItemButtonEdit ItemButtonEdit = new RepositoryItemButtonEdit();
|
||
ItemButtonEdit.Buttons.Clear();
|
||
ItemButtonEdit.AppearanceDisabled.Options.UseTextOptions = true;
|
||
ItemButtonEdit.AppearanceDisabled.TextOptions.HAlignment = HorzAlignment.Center;
|
||
ItemButtonEdit.TextEditStyle = TextEditStyles.HideTextEditor;
|
||
ItemButtonEdit.ButtonsStyle = BorderStyles.UltraFlat;
|
||
ItemButtonEdit.BorderStyle = BorderStyles.NoBorder;
|
||
ItemButtonEdit.ButtonClick += new ButtonPressedEventHandler(OnItemButtonEdit_ButtonClick);
|
||
DataTable rightMenuTab = BaseModuleImpl.GetBaseGridRightMenus(this.Model.ModuleCode);
|
||
int ColumnWidth = 0;
|
||
if (rightMenuTab.Columns.Contains("IcoName"))
|
||
{
|
||
// 创建只显示图片的按钮
|
||
DataRow[] rightMenuBtns = rightMenuTab.Select().Where(n => !string.IsNullOrEmpty(n["IcoName"] + "")).ToArray();
|
||
int picWidth = 30;
|
||
foreach (DataRow rightMenu in rightMenuBtns)
|
||
{
|
||
GridRightMenuModel menuModel = new GridRightMenuModel(rightMenu);
|
||
if (!string.IsNullOrWhiteSpace(menuModel.MenuName))
|
||
{
|
||
EditorButton editorButton = new EditorButton();
|
||
editorButton.Appearance.BackColor = Color.Transparent;
|
||
if (!string.IsNullOrEmpty(menuModel.IcoName))
|
||
{
|
||
Image image = null;
|
||
try
|
||
{
|
||
image = Image.FromFile(Util.PubUtil.GridColumnIco + menuModel.IcoName);
|
||
if (image.Width > 30)
|
||
{
|
||
picWidth = image.Width;
|
||
}
|
||
editorButton.Image = image;
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
editorButton.ToolTip = menuModel.MenuName;
|
||
editorButton.Kind = ButtonPredefines.Glyph;
|
||
editorButton.Width = picWidth;
|
||
editorButton.Tag = menuModel;
|
||
ItemButtonEdit.Buttons.Add(editorButton);
|
||
}
|
||
}
|
||
ColumnWidth = rightMenuBtns.Length * picWidth;
|
||
}
|
||
if (rightMenuTab.Columns.Contains("showtoolbar"))
|
||
{
|
||
// 创建只显示文本的按钮
|
||
DataRow[] rightMenuBtnsText = rightMenuTab.Select().Where(n => "1".Equals(n["showtoolbar"] + "")).ToArray();
|
||
EditorButton textOnlyButton = new EditorButton();
|
||
foreach (DataRow rightMenu in rightMenuBtnsText)
|
||
{
|
||
GridRightMenuModel menuModel = new GridRightMenuModel(rightMenu);
|
||
if (!string.IsNullOrWhiteSpace(menuModel.MenuName))
|
||
{
|
||
EditorButton editorButton = new EditorButton();
|
||
editorButton.Caption = menuModel.MenuName + "";
|
||
//editorButton.GlyphAlignment = HorzAlignment.Center;
|
||
editorButton.ToolTip = menuModel.MenuName;
|
||
editorButton.Kind = ButtonPredefines.Glyph;
|
||
editorButton.Width = this.CalculateTextWidth(editorButton.Caption, editorButton.Appearance.Font);
|
||
editorButton.Tag = menuModel;
|
||
|
||
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;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
gridColumn.ColumnEdit = ItemButtonEdit;
|
||
this.gridView.Columns.Add(gridColumn);
|
||
this.gridView.OptionsBehavior.EditorShowMode = EditorShowMode.MouseDown;
|
||
gridColumn.MaxWidth = ColumnWidth;
|
||
gridColumn.MinWidth = ColumnWidth;
|
||
gridColumn.Width = ColumnWidth;
|
||
}
|
||
|
||
|
||
private void OnHighBeater(object sender, ButtonPressedEventArgs e)
|
||
{
|
||
FrmHighBeater highBeater = new FrmHighBeater();
|
||
DataTable dt = (this.GridView.GridControl.DataSource as DataTable).Clone();
|
||
DataRow dr = this.GridView.GetFocusedDataRow();
|
||
dt.Rows.Add(dr);
|
||
highBeater.dataSource = dt;
|
||
DialogResult result = highBeater.ShowDialog();
|
||
if (result == DialogResult.OK)
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:创建 模块返回ID</para>
|
||
/// <para>创建人:曹屹峰</para>
|
||
/// <para>创建日期:2021-08-23 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void InitSelectReturnId(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
FrmModelLookUp modelLookUp = new FrmModelLookUp(model.addModuleld, model.IsRadio);
|
||
modelLookUp.ConfigureColumnMode = model.ConfigureColumnMode;
|
||
modelLookUp.ValueField = model.ValueMember;
|
||
modelLookUp.TextField = model.TextMember;
|
||
modelLookUp.SourceSQL = model.SqlSource;
|
||
modelLookUp.IsType = model.FieldType;
|
||
modelLookUp.ValueMember = model.FieldType == ControlType.LabSelectReturnId ? model.ValueMember : model.TextMember;
|
||
modelLookUp.Tag = model;
|
||
|
||
RepositoryItemCheckedComboBoxEdit btnEdit = new RepositoryItemCheckedComboBoxEdit();
|
||
btnEdit.NullText = "";
|
||
btnEdit.PopupBorderStyle = PopupBorderStyles.Flat;
|
||
btnEdit.AllowNullInput = DefaultBoolean.False;
|
||
btnEdit.DisplayMember = model.TextMember;
|
||
btnEdit.SeparatorChar = ',';
|
||
btnEdit.ValueMember = model.FieldType == ControlType.LabSelectReturnId ? model.ValueMember : model.TextMember;
|
||
DataTable dataTable = MainImpl.GetDataTableResult(modelLookUp.SingleChoiceMode ? modelLookUp.SysModel.MenuSql : model.SqlSource);
|
||
//ModuleEnclosure.Add(model.FieldName, dataTable);
|
||
btnEdit.DataSource = dataTable;
|
||
btnEdit.Buttons[0].Visible = false; // 不能移除,移除后事件不起作用.
|
||
btnEdit.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] { new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Ellipsis) });
|
||
|
||
btnEdit.Tag = model;
|
||
btnEdit.Buttons[1].Tag = modelLookUp;
|
||
btnEdit.ButtonClick += new ButtonPressedEventHandler(OnModuleChoice);
|
||
btnEdit.KeyDown += BtnEdit_KeyDown;
|
||
gridControl.RepositoryItems.Add(btnEdit);
|
||
gridColumn.OptionsColumn.ReadOnly = true;
|
||
gridColumn.ColumnEdit = btnEdit;
|
||
|
||
gridColumn.FilterMode = ColumnFilterMode.DisplayText;//筛选行匹配文本值(模块返回ID不像下拉框,不进入弹出框,只能看到文本值。所以把筛选改成按文本筛选)
|
||
|
||
this.mControlList.Add(model);
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:创建 模块返回ID 新版</para>
|
||
/// <para>创建人:曹屹峰</para>
|
||
/// <para>创建日期:2021-08-23 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void InitSelectReturnIdNew(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
FrmModelLookUp2 modelLookUp = new FrmModelLookUp2(model.addModuleld, model.IsRadio);
|
||
modelLookUp.ConfigureColumnMode = model.ConfigureColumnMode;
|
||
modelLookUp.ValueField = model.ValueMember;
|
||
modelLookUp.TextField = model.TextMember;
|
||
modelLookUp.SourceSQL = model.SqlSource;
|
||
modelLookUp.IsType = model.FieldType;
|
||
modelLookUp.ValueMember = model.FieldType == ControlType.LabSelectReturnIdNew ? model.ValueMember : model.TextMember;
|
||
modelLookUp.Tag = model;
|
||
|
||
RepositoryItemCheckedComboBoxEdit btnEdit = new RepositoryItemCheckedComboBoxEdit();
|
||
btnEdit.NullText = "";
|
||
btnEdit.PopupBorderStyle = PopupBorderStyles.Flat;
|
||
btnEdit.AllowNullInput = DefaultBoolean.False;
|
||
btnEdit.DisplayMember = model.TextMember;
|
||
btnEdit.SeparatorChar = ',';
|
||
btnEdit.ValueMember = model.FieldType == ControlType.LabSelectReturnIdNew ? model.ValueMember : model.TextMember;
|
||
|
||
if (model.ModuleFrameDisplayText && model.FieldType == ControlType.LabSelectReturnIdNew)
|
||
{
|
||
DataTable dataTable = MainImpl.GetDataTableResult(modelLookUp.SysModel.MenuSql);
|
||
btnEdit.DataSource = dataTable;
|
||
}
|
||
|
||
|
||
btnEdit.Buttons[0].Visible = false; // 不能移除,移除后事件不起作用.
|
||
btnEdit.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] { new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Ellipsis) });
|
||
|
||
btnEdit.Tag = model;
|
||
btnEdit.Buttons[1].Tag = modelLookUp;
|
||
btnEdit.ButtonClick += new ButtonPressedEventHandler(OnModuleChoiceNew);
|
||
btnEdit.KeyDown += BtnEdit_KeyDown;
|
||
gridControl.RepositoryItems.Add(btnEdit);
|
||
gridColumn.OptionsColumn.ReadOnly = true;
|
||
gridColumn.ColumnEdit = btnEdit;
|
||
|
||
|
||
this.mControlList.Add(model);
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:创建 模块返回行 </para>
|
||
/// <para>创建人:曹屹峰</para>
|
||
/// <para>创建日期:2021-08-23 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void InitModuleReturnLine(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
FrmModelLookUp2 modelLookUp = new FrmModelLookUp2(model.addModuleld, false);//model.IsRadio 必定多选
|
||
modelLookUp.ReturnCollection = true;
|
||
modelLookUp.ConfigureColumnMode = model.ConfigureColumnMode;
|
||
modelLookUp.ValueField = model.ValueMember;
|
||
modelLookUp.TextField = model.TextMember;
|
||
modelLookUp.SourceSQL = model.SqlSource;
|
||
modelLookUp.IsType = model.FieldType;
|
||
modelLookUp.ValueMember = model.FieldType == ControlType.LabModuleAddRowsID ? model.ValueMember : model.TextMember;
|
||
modelLookUp.Tag = model;
|
||
|
||
RepositoryItemCheckedComboBoxEdit btnEdit = new RepositoryItemCheckedComboBoxEdit();
|
||
btnEdit.NullText = "";
|
||
btnEdit.PopupBorderStyle = PopupBorderStyles.Flat;
|
||
btnEdit.AllowNullInput = DefaultBoolean.False;
|
||
btnEdit.DisplayMember = model.TextMember;
|
||
btnEdit.SeparatorChar = ',';
|
||
btnEdit.ValueMember = model.FieldType == ControlType.LabModuleAddRowsText ? model.ValueMember : model.TextMember;
|
||
DataTable dataTable = MainImpl.GetDataTableResult(modelLookUp.SysModel.MenuSql);
|
||
btnEdit.DataSource = dataTable;
|
||
//if (model.ModuleFrameDisplayText)
|
||
//{
|
||
// DataTable dataTable = MainImpl.GetDataTableResult(modelLookUp.SysModel.MenuSql);
|
||
// btnEdit.DataSource = dataTable;
|
||
//}
|
||
btnEdit.Buttons[0].Visible = false; // 不能移除,移除后事件不起作用.
|
||
btnEdit.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] { new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Ellipsis) });
|
||
|
||
btnEdit.Tag = model;
|
||
btnEdit.Buttons[1].Tag = modelLookUp;
|
||
btnEdit.ButtonClick += new ButtonPressedEventHandler(OnModuleAddLine);
|
||
btnEdit.KeyDown += BtnEdit_KeyDown;
|
||
gridControl.RepositoryItems.Add(btnEdit);
|
||
gridColumn.OptionsColumn.ReadOnly = true;
|
||
gridColumn.ColumnEdit = btnEdit;
|
||
|
||
|
||
this.mControlList.Add(model);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:创建 模块返回行数据</para>
|
||
/// <para>创建人:唐德馨</para>
|
||
/// <para>创建日期:2022-10-4 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void InitSelectReturnRows(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
FrmRowsModelLookUp modelLookUp = new FrmRowsModelLookUp();
|
||
modelLookUp.UnionModuleCodel = model.addModuleld;
|
||
modelLookUp.gridColumnModel = model;
|
||
modelLookUp.ValueField = model.ValueMember;
|
||
modelLookUp.TextField = model.TextMember;
|
||
modelLookUp.SourceSQL = model.SqlSource;
|
||
modelLookUp.IsType = model.FieldType;
|
||
modelLookUp.ValueMember = model.FieldType == ControlType.LabSelectReturnId ? model.ValueMember : model.TextMember;
|
||
modelLookUp.selectField = gridColumn.FieldName;
|
||
modelLookUp.Tag = model;
|
||
|
||
RepositoryItemButtonEdit btnEdit = new RepositoryItemButtonEdit();
|
||
btnEdit.NullText = "";
|
||
btnEdit.AllowNullInput = DefaultBoolean.False;
|
||
btnEdit.Buttons[0].Visible = false; // 不能移除,移除后事件不起作用.
|
||
btnEdit.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] { new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Ellipsis) });
|
||
|
||
btnEdit.Tag = model;
|
||
btnEdit.Buttons[1].Tag = modelLookUp;
|
||
btnEdit.ButtonClick += new ButtonPressedEventHandler(OnModuleRowsChoice);
|
||
|
||
gridControl.RepositoryItems.Add(btnEdit);
|
||
gridColumn.OptionsColumn.ReadOnly = true;
|
||
gridColumn.ColumnEdit = btnEdit;
|
||
|
||
this.mControlList.Add(model);
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:创建模块返回行数据(优化)</para>
|
||
/// <para>创建人:唐德馨</para>
|
||
/// <para>创建日期:2022-10-4 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void InitSelectReturnRowsNew(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
FrmRowsModelLookUpNew modelLookUp = new FrmRowsModelLookUpNew();
|
||
modelLookUp.UnionModuleCodel = model.addModuleld;
|
||
modelLookUp.SingleChoiceMode = model.IsRadio;
|
||
modelLookUp.gridColumnModel = model;
|
||
modelLookUp.ValueField = model.ValueMember;
|
||
modelLookUp.TextField = model.TextMember;
|
||
modelLookUp.SourceSQL = model.SqlSource;
|
||
modelLookUp.IsType = model.FieldType;
|
||
modelLookUp.ValueMember = model.FieldType == ControlType.LabSelectReturnId ? model.ValueMember : model.TextMember;
|
||
modelLookUp.selectField = gridColumn.FieldName;
|
||
modelLookUp.Tag = model;
|
||
RepositoryItemButtonEdit btnEdit = new RepositoryItemButtonEdit();
|
||
btnEdit.NullText = "";
|
||
btnEdit.AllowNullInput = DefaultBoolean.False;
|
||
btnEdit.Buttons[0].Visible = false; //不能移除,移除后事件不起作用.
|
||
btnEdit.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Ellipsis) });
|
||
|
||
btnEdit.Tag = model;
|
||
btnEdit.Buttons[1].Tag = modelLookUp;
|
||
btnEdit.ButtonClick += new ButtonPressedEventHandler(OnModuleRowsChoiceNew);
|
||
|
||
gridControl.RepositoryItems.Add(btnEdit);
|
||
gridColumn.OptionsColumn.ReadOnly = true;
|
||
gridColumn.ColumnEdit = btnEdit;
|
||
|
||
this.mControlList.Add(model);
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期: </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
/// <param name="model">The model.</param>
|
||
public void InitMutilComboxEdit(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
RepositoryItemCheckedComboBoxEdit comboxEdit = new RepositoryItemCheckedComboBoxEdit();
|
||
comboxEdit.AllowFocused = true;
|
||
comboxEdit.DataSource = MainImpl.GetDataTableResult(model.SqlSource);
|
||
comboxEdit.DisplayMember = model.TextMember;
|
||
comboxEdit.ValueMember = model.FieldType == ControlType.LabComboxCheckListValue ? model.ValueMember : model.TextMember;
|
||
comboxEdit.NullText = "";
|
||
|
||
gridControl.RepositoryItems.Add(comboxEdit);
|
||
gridColumn.ColumnEdit = comboxEdit;
|
||
|
||
this.mControlList.Add(model);
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:表格图片</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-08-02 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
public void InitPicEdit(GridColumn gridColumn)
|
||
{
|
||
RepositoryItemPictureEdit picEdit = new RepositoryItemPictureEdit();
|
||
picEdit.AutoHeight = true;
|
||
picEdit.SizeMode = PictureSizeMode.Zoom;
|
||
picEdit.BestFitWidth = 16;
|
||
picEdit.CustomHeight = 16;
|
||
gridColumn.ColumnEdit = picEdit;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:表格图片</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-08-02 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
public void InitPicEditUrl(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
gridColumn.AppearanceCell.Options.UseTextOptions = true;
|
||
gridColumn.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Center;
|
||
gridColumn.OptionsColumn.AllowEdit = false;
|
||
gridColumn.FieldName = $"{model.FieldName}{Guid.NewGuid()}";
|
||
RepositoryItemPictureEdit pictureEdit = new RepositoryItemPictureEdit();
|
||
pictureEdit.ShowMenu = false;
|
||
pictureEdit.NullText = " ";
|
||
pictureEdit.SizeMode = PictureSizeMode.Zoom;
|
||
gridControl.RepositoryItems.Add(pictureEdit);
|
||
gridColumn.UnboundType = UnboundColumnType.Object;
|
||
gridColumn.ColumnEdit = pictureEdit;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-06-10 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="dTable">The d table.</param>
|
||
/// <param name="columnName">Name of the column.</param>
|
||
/// <returns>System.Int32.</returns>
|
||
public int CalcMaxColumnWidth(DataTable dTable, string columnName)
|
||
{
|
||
int maxWidth = 0, maxRow = 50;
|
||
for (int i = 0; i < dTable.Rows.Count; i++)
|
||
{
|
||
if (i < maxRow)
|
||
{
|
||
DataRow row = dTable.Rows[i];
|
||
int columnWidth = GraphicsText.GetTextWidth(row[columnName] + "");
|
||
if (columnWidth > maxWidth)
|
||
{
|
||
maxWidth = columnWidth;
|
||
}
|
||
}
|
||
}
|
||
return maxWidth;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:获取焦点行数据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-10-18 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <returns>DataRow.</returns>
|
||
public virtual DataRow GetViewFocusedDataRow()
|
||
{
|
||
return gridView.GetFocusedDataRow();
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:获取选中行数据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-10-18 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <returns>DataRow[].</returns>
|
||
public virtual DataRow[] GetViewFocusedDataRows()
|
||
{
|
||
int[] rows = gridView.GetSelectedRows();
|
||
DataRow[] dataRows = new DataRow[rows.Length];
|
||
for (int i = 0; i < rows.Length; i++)
|
||
{
|
||
dataRows[i] = gridView.GetDataRow(rows[i]);
|
||
}
|
||
return dataRows;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:设置表格颜色</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-12 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="table">The table.</param>
|
||
public virtual void SetGridRowColors(DataTable table)
|
||
{
|
||
this.GridRowColorsTable = table;
|
||
|
||
if (table != null && table.Rows.Count > 0)
|
||
{
|
||
DataRow rowItem = table.Select("1=1").FirstOrDefault(x => (x["condition"] + "").Contains("COLUMN_"));
|
||
if (rowItem != null)
|
||
{
|
||
this.gridView.RowCellStyle -= new RowCellStyleEventHandler(OnGridViewRowCellStyle);
|
||
this.gridView.RowCellStyle += new RowCellStyleEventHandler(OnGridViewRowCellStyle);
|
||
}
|
||
else
|
||
{
|
||
if (!SystemInfo.Instance.ConditionalStylePriority)
|
||
{
|
||
this.gridView.RowStyle -= new RowStyleEventHandler(OnGridViewRowStyle);
|
||
this.gridView.RowStyle += new RowStyleEventHandler(OnGridViewRowStyle);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:生成序号</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-09-14 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="RowIndicatorCustomDrawEventArgs"/> instance containing the event data.</param>
|
||
protected virtual void OnGridViewCustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
e.Appearance.TextOptions.HAlignment = HorzAlignment.Center;
|
||
if (e.Info.IsRowIndicator)
|
||
{
|
||
if (e.RowHandle >= 0)
|
||
{
|
||
e.Info.DisplayText = (e.RowHandle + 1).ToString();
|
||
}
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置序号列宽度
|
||
/// </summary>
|
||
public void AdjustIndicatorWidthSmart()
|
||
{
|
||
try
|
||
{
|
||
int rowCount = this.gridView.RowCount;
|
||
if (rowCount == 0) return;
|
||
|
||
// 获取网格实际使用的行字体
|
||
Font rowFont = this.gridView.Appearance.Row.Font
|
||
?? this.gridView.GridControl?.Font
|
||
?? SystemFonts.DefaultFont;
|
||
|
||
// 用最大行号实测文本宽度(而非估算)
|
||
string maxNumber = rowCount.ToString();
|
||
int textWidth = TextRenderer.MeasureText(maxNumber, rowFont).Width;
|
||
|
||
// 附加宽度:行指示器图标(~12px) + 左右间距(~10px) + 边框
|
||
int indicatorWidth = textWidth + 14;
|
||
|
||
// 限制范围 40-80px
|
||
this.gridView.IndicatorWidth = Math.Max(40, Math.Min(80, indicatorWidth));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
// 这里可以加日志
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:拖拽列</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-02-06 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="DragObjectDropEventArgs"/> instance containing the event data.</param>
|
||
protected virtual void OnGridViewDragObjectDrop(object sender, DragObjectDropEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (e.DragObject is GridColumn)
|
||
{
|
||
GridColumn gridColumn = e.DragObject as GridColumn;
|
||
GridColumnModel gridModel = gridColumn.Tag as GridColumnModel;
|
||
|
||
if (gridModel != null && !this.gridView.OptionsView.ShowGroupPanel)
|
||
{
|
||
if (gridColumn.Visible && gridModel.Width == 0)
|
||
{
|
||
MessageUtil.Show(ResourceKeys.DefaultForHide);
|
||
gridColumn.Visible = false;
|
||
}
|
||
else
|
||
{
|
||
if (!gridColumn.Visible && gridModel.OnlyCanNull)
|
||
{
|
||
MessageUtil.Show(ResourceKeys.NotNullForDelete);
|
||
gridColumn.Visible = true;
|
||
}
|
||
}
|
||
}
|
||
if (BaseImpl.HasExistsTable(ResourceKeys.SettingGrouprptab))
|
||
{
|
||
this.ChartTable = new DataTable();
|
||
ChartTable.Columns.Add("key");
|
||
ChartTable.Columns.Add("value");
|
||
string sqlValue = string.Format("DELETE FROM {0} WHERE operatorid = '{1}' ", ResourceKeys.SettingGrouprptab, ERPInfo.Instance.UserId);
|
||
SqlHelper.ExecuteNonQuery(sqlValue);
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:分组列获取数据</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2020-07-27 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="DragObjectDropEventArgs"/> instance containing the event data.</param>
|
||
private void OnGridCustomDrawGroupRow(object sender, DevExpress.XtraGrid.Views.Base.RowObjectCustomDrawEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
GridGroupRowInfo GridGroupRowInfo = e.Info as GridGroupRowInfo;
|
||
GridColumn gridColumn = GridGroupRowInfo.Column as GridColumn;
|
||
|
||
if (gridColumn.Tag == null)
|
||
{
|
||
//动态列没有设置tag
|
||
string ColumnSiftValue = string.Empty;
|
||
int startindex = GridGroupRowInfo.GroupText.LastIndexOf(":");
|
||
string[] GroupText = GridGroupRowInfo.GroupText.Substring(startindex + 1).Trim().Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
|
||
string newGroupText = GroupText[0] + ", ";
|
||
GridGroupRowInfo.GroupText = GridGroupRowInfo.GroupText.Substring(0, startindex + 1) + newGroupText.TrimEnd(' ').TrimEnd(',');
|
||
}
|
||
else
|
||
{
|
||
GridColumnModel model = gridColumn.Tag as GridColumnModel;
|
||
string ColumnSiftValue = string.Empty;
|
||
string editValue = ControlType.IsValue(model.FieldType) ? GridGroupRowInfo.GroupValueText : GridGroupRowInfo.EditValue + "";
|
||
int startindex = GridGroupRowInfo.GroupText.LastIndexOf(":");
|
||
string[] GroupText = GridGroupRowInfo.GroupText.Substring(startindex + 1).Trim().Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
|
||
int i = 0; string newGroupText = GroupText[0] + ", ";
|
||
foreach (GridColumn newColumn in this.gridView.Columns)
|
||
{
|
||
GridColumnModel Newmodel = newColumn.Tag as GridColumnModel;
|
||
if (Newmodel.Visible && Newmodel.CanSum && !SystemInfo.Instance.GroupSpecialMode)
|
||
{
|
||
|
||
if (i != GroupText.Count() - 1) i++;
|
||
string newGroupValue = GroupText[i].Replace(newColumn.Caption, "");
|
||
if (newColumn == HeaderColumnSift)
|
||
{
|
||
ColumnSiftValue = newGroupValue.Replace(",", "");
|
||
}
|
||
newGroupText += newColumn.Caption + newGroupValue + ", ";
|
||
}
|
||
}
|
||
GridGroupRowInfo.GroupText = GridGroupRowInfo.GroupText.Substring(0, startindex + 1) + newGroupText.TrimEnd(' ').TrimEnd(',');
|
||
if (!string.IsNullOrWhiteSpace(editValue) && ChartTable.Columns.Count > 0)
|
||
{
|
||
string groupText = GridGroupRowInfo.GroupText;
|
||
int endindex = groupText.LastIndexOf("行");
|
||
if (!SystemInfo.Instance.GroupSpecialMode) groupText = groupText.Substring(startindex + 1, endindex - startindex - 1).Trim();
|
||
if (!(this.ChartTable.Rows.Cast<DataRow>().FirstOrDefault(x => x["key"] == GridGroupRowInfo.EditValue + "") != null))
|
||
{
|
||
if (BaseImpl.HasExistsTable(ResourceKeys.SettingGrouprptab))
|
||
{
|
||
float vsNum = 0;
|
||
bool isNum = float.TryParse(ColumnSiftValue, out vsNum);
|
||
ChartTable.Rows.Add(GridGroupRowInfo.EditValue + "", groupText);
|
||
if (isNum)
|
||
{
|
||
if (SiftEnumObj == HeaderSiftEnum.Sum)
|
||
{
|
||
groupText = vsNum.ToString();
|
||
}
|
||
if (SiftEnumObj == HeaderSiftEnum.Avg)
|
||
{
|
||
groupText = (vsNum / float.Parse(groupText)) + "";
|
||
}
|
||
if (SiftEnumObj == HeaderSiftEnum.Max)
|
||
{
|
||
|
||
//gridView.GroupSummary.Add(DevExpress.Data.SummaryItemType.Max, "数据", HeaderColumnSift, "组计:{0}");
|
||
|
||
}
|
||
if (SiftEnumObj == HeaderSiftEnum.Min)
|
||
{
|
||
|
||
}
|
||
}
|
||
string tempSql = string.Format(@"insert into {3}(GroupName,GroupAmount,OperAtorId) values('{0}','{1}','{2}');", editValue, groupText, ERPInfo.Instance.UserId, ResourceKeys.SettingGrouprptab);
|
||
SqlHelper.ExecuteNonQuery(tempSql);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:监听键盘事件</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-05-31 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="KeyEventArgs"/> instance containing the event data.</param>
|
||
protected virtual void OnGridViewKeyDown(object sender, KeyEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
// 替换本列下所有数据为当前单元格数据
|
||
if (e.KeyCode == Keys.F6 || e.KeyCode == Keys.F7)
|
||
{
|
||
GridColumn column = this.gridView.FocusedColumn;
|
||
GridColumnModel model = column.Tag as GridColumnModel;
|
||
if (column != null &&
|
||
column.OptionsColumn.AllowEdit &&
|
||
this.gridView.RowCount > 0 &&
|
||
this.gridView.OptionsBehavior.Editable)
|
||
{
|
||
// 允许操作
|
||
int focusedRowHandle = this.gridView.FocusedRowHandle;
|
||
//int totalRowCount = this.gridView.RowCount;
|
||
DataTable FilteredTable = this.gridView.GetGridViewFilteredAndSortedDataToDataTable();
|
||
int totalRowCount = FilteredTable.Rows.Count;
|
||
//GridCell[] cells = this.gridView.GetSelectedCells();
|
||
int[] SelectRows = this.gridView.GetSelectedRows();//之前根据选中单元格判断是否选中多行,选中改成根据选中行数量判断
|
||
if (((SelectRows.Length == 1 || gridView.OptionsView.AllowCellMerge) || this.gridView.OptionsSelection.MultiSelectMode == GridMultiSelectMode.CheckBoxRowSelect) && focusedRowHandle + 1 < totalRowCount)
|
||
{
|
||
if (MessageUtil.Show(e.KeyCode == Keys.F6 ? ResourceKeys.IsReplaceAllEmptyColumn : ResourceKeys.IsReplaceAllColumn, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
{
|
||
WaitForm.ShowForm("数据填充中");
|
||
object obj = this.gridView.GetFocusedRowCellValue(column);
|
||
bool isFilterContain = gridView.ActiveFilter.Cast<ViewColumnFilterInfo>().Where(n => n.Column.FieldName.Equals(column.FieldName)).Count() > 0 ? true : false;
|
||
isFilterContain = isFilterContain && FilteredTable.AsEnumerable().Where(n => !n[column.FieldName].Equals(obj)).Count() > 0 ? true : false;
|
||
if (obj != null)
|
||
{
|
||
Dictionary<int, DataRow> updateDatas = new Dictionary<int, DataRow>();
|
||
for (int i = focusedRowHandle; i < totalRowCount; i++)
|
||
{
|
||
int dataSourceIndex = this.gridView.GetDataSourceRowIndex(i);
|
||
//如果有修改提交就验证,不合的就不会改变值
|
||
if (!string.IsNullOrWhiteSpace(ModifyCond))
|
||
{
|
||
DataRow dr = this.gridView.GetDataRow(i);
|
||
// 检查条件
|
||
if (!ValidateCond(ModifyCond, dr)) continue;
|
||
}
|
||
|
||
updateDatas.Add(dataSourceIndex, this.gridView.GetDataRow(i)); ;
|
||
}
|
||
foreach (int index in updateDatas.Keys)
|
||
{
|
||
DataRow row = updateDatas[index];
|
||
if (e.KeyCode == Keys.F6)
|
||
{
|
||
object obj2 = row[column.FieldName];
|
||
// F6 覆盖当前列下所有为空的列
|
||
if (string.IsNullOrEmpty(obj2 + ""))
|
||
{
|
||
row[column.FieldName] = obj;
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, obj + "", index);
|
||
}
|
||
//计算规则配置在结果字段上,所以无需验证当前操作控件
|
||
this.SetCalcValue(model, obj + "", index);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// F7 覆盖当前列下所有列
|
||
row[column.FieldName] = obj;
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, obj + "", index);
|
||
}
|
||
//计算规则配置在结果字段上,所以无需验证当前操作控件
|
||
this.SetCalcValue(model, obj + "", index);
|
||
}
|
||
}
|
||
gridView.PostEditor();
|
||
if (isFilterContain)
|
||
{
|
||
gridView.FocusedRowHandle = gridView.FocusedRowHandle - 1;
|
||
}
|
||
e.Handled = true;
|
||
}
|
||
WaitForm.HideForm();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
e.Handled = true;
|
||
}
|
||
}
|
||
}
|
||
// 已当前列为基准,按顺序生成本列数据
|
||
if (e.KeyCode == Keys.F8)
|
||
{
|
||
GridColumn column = this.gridView.FocusedColumn;
|
||
if (column != null &&
|
||
column.OptionsColumn.AllowEdit &&
|
||
this.gridView.RowCount > 0 &&
|
||
this.gridView.OptionsBehavior.Editable)
|
||
{
|
||
// 允许操作
|
||
int focusedRowHandle = this.gridView.FocusedRowHandle;
|
||
int totalRowCount = this.gridView.RowCount;
|
||
// GridCell[] cells = this.gridView.GetSelectedCells();
|
||
int[] SelectRows = this.gridView.GetSelectedRows();
|
||
if ((SelectRows.Length == 1 || this.gridView.OptionsSelection.MultiSelectMode == GridMultiSelectMode.CheckBoxRowSelect) && focusedRowHandle + 1 < totalRowCount)
|
||
{
|
||
if (MessageUtil.Show(ResourceKeys.IsGenerateAllColumn, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
{
|
||
bool isExec = false;
|
||
long value = 0;
|
||
int valueNum = 0;
|
||
object obj = this.gridView.GetFocusedRowCellValue(column);
|
||
|
||
if (!string.IsNullOrEmpty(obj + ""))
|
||
{
|
||
//isExec = Int64.TryParse(obj + "", out value);
|
||
Regex regex = new Regex(@"\D", RegexOptions.RightToLeft);
|
||
Regex regexNum = new Regex(@"\d", RegexOptions.RightToLeft);
|
||
int lastIndex = regex.Match(obj.ToString()).Index;
|
||
string leftString = string.Empty;
|
||
string rightString = string.Empty;
|
||
if (lastIndex == 0 && regex.Match(obj.ToString()).Success == false)
|
||
{
|
||
leftString = "";
|
||
rightString = obj.ToString();
|
||
}
|
||
else
|
||
{
|
||
leftString = obj.ToString().Substring(0, lastIndex + 1);
|
||
rightString = obj.ToString().Substring(lastIndex + 1, obj.ToString().Length - lastIndex - 1);
|
||
}
|
||
if (regexNum.Match(rightString).Success == false)
|
||
{
|
||
if (MessageUtil.Show(ResourceKeys.SelectColumnValueNotNumber, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
{
|
||
rightString = "1";
|
||
}
|
||
}
|
||
valueNum = rightString.Length;
|
||
value = Convert.ToInt64(rightString);
|
||
this.gridView.BeginUpdate();
|
||
this.gridView.BeginDataUpdate();
|
||
for (int i = focusedRowHandle; i < totalRowCount; i++)
|
||
{
|
||
gridView.SetRowCellValue(i, column, leftString + value.ToString().PadLeft(valueNum, '0'));
|
||
//gridView.PostEditor()
|
||
value++;
|
||
}
|
||
this.gridView.EndDataUpdate();
|
||
this.gridView.EndUpdate();
|
||
gridView.FocusedRowHandle = totalRowCount - 1;
|
||
e.Handled = true;
|
||
}
|
||
else
|
||
{
|
||
if (MessageUtil.Show(ResourceKeys.SelectColumnValueTypeNotNumber, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
{
|
||
value = 1;
|
||
this.gridView.BeginUpdate();
|
||
this.gridView.BeginDataUpdate();
|
||
for (int i = focusedRowHandle; i <= totalRowCount; i++)
|
||
{
|
||
//gridView.FocusedRowHandle = i;
|
||
gridView.SetRowCellValue(i, column, value);
|
||
//gridView.PostEditor();
|
||
value++;
|
||
}
|
||
this.gridView.EndDataUpdate();
|
||
this.gridView.EndUpdate();
|
||
gridView.FocusedRowHandle = totalRowCount - 1;
|
||
e.Handled = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
e.Handled = true;
|
||
}
|
||
}
|
||
}
|
||
if (e.Modifiers.CompareTo(Keys.Control) == 0 && e.KeyCode == Keys.V)
|
||
{
|
||
|
||
// 清除排序
|
||
if (!SystemInfo.Instance.CancelPasteClearSort)
|
||
{
|
||
this.gridView.Columns.ClearAllSort();
|
||
}
|
||
|
||
|
||
//if (this.gridView.IsFindPanelVisible)
|
||
//{
|
||
// MessageUtil.Show("搜索模式下无法粘贴行.");
|
||
// return;
|
||
//}
|
||
|
||
object _objData = null;
|
||
IDataObject dataObj = Clipboard.GetDataObject();
|
||
bool IsNewPost = SysModel != null ? SysModel.IsNewPost : false;
|
||
if (dataObj.GetDataPresent(DataFormats.Text))
|
||
_objData = dataObj.GetData(DataFormats.Text);
|
||
if ((!IsNewPost && SystemInfo.Instance.IsOldPost) || (this.Tag != null && this.Tag.ToString() == "IsOldPost"))
|
||
{
|
||
OldPasteMethod(e, _objData);
|
||
}
|
||
else
|
||
{
|
||
//OldPasteMethod(e, _objData);
|
||
NewPasteMethod(e, _objData);
|
||
}
|
||
if (OnAllAfterParseCallBack != null)
|
||
{
|
||
OnAllAfterParseCallBack(null, null);
|
||
}
|
||
}
|
||
// 向下复制整行
|
||
if (e.Control && e.Shift && e.KeyCode == Keys.C)
|
||
{
|
||
DataRow rt = this.gridView.GetDataRow(gridView.FocusedRowHandle);
|
||
if (rt != null)
|
||
{
|
||
DataTable dt = (DataTable)this.GridControl.DataSource;
|
||
//dt.Rows.Add(rt.ItemArray);
|
||
DataRow newRow = dt.NewRow();
|
||
newRow.ItemArray = rt.ItemArray;
|
||
dt.Rows.InsertAt(newRow, gridView.FocusedRowHandle + 1);
|
||
GridControl.DataSource = dt;
|
||
}
|
||
|
||
}
|
||
// 复制单元格
|
||
if (e.Control && e.KeyCode == Keys.C)
|
||
{
|
||
GridCell[] cells;
|
||
//复选框状态
|
||
if (gridView.OptionsSelection.MultiSelect == true && gridView.OptionsSelection.MultiSelectMode == GridMultiSelectMode.CheckBoxRowSelect && gridView.OptionsSelection.EnableAppearanceFocusedCell == false && this.gridView.GetSelectedRows().Length == 0)
|
||
{
|
||
//GridViewInfo info = gridView.GetViewInfo() as GridViewInfo;
|
||
//GridCellInfo cellInfo = info.GetGridCellInfo(gridView.FocusedRowHandle, gridView.FocusedColumn);
|
||
GridCell cell = new GridCell(gridView.FocusedRowHandle, gridView.FocusedColumn);
|
||
cells = new GridCell[] { cell };
|
||
}
|
||
else
|
||
cells = this.gridView.GetSelectedCells();
|
||
if (cells.Length == 1 || gridView.OptionsView.AllowCellMerge)
|
||
{
|
||
//object obj = gridView.GetFocusedRowCellValue(gridView.FocusedColumn);
|
||
object obj = gridView.GetFocusedRowCellDisplayText(gridView.FocusedColumn);
|
||
if (obj != null)
|
||
{
|
||
Clipboard.SetDataObject(obj + "");
|
||
e.Handled = true;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (!ExportPermission)
|
||
{
|
||
//没有导出权限,不能多格复制
|
||
Clipboard.SetData(DataFormats.Text, "");
|
||
e.Handled = true;
|
||
return;
|
||
}
|
||
gridView.CopyToClipboard();
|
||
e.Handled = true;
|
||
}
|
||
}
|
||
//if (e.Control && e.KeyCode == Keys.F)
|
||
//{
|
||
// //this.gridView.OptionsFind.AlwaysVisible = false;
|
||
//}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:新版版粘贴功能(速度快不会触发关联计算等方法)</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2021-03-16 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="PopupMenuShowingEventArgs"/> instance containing the event data.</param>
|
||
private void NewPasteMethod(KeyEventArgs e, object _objData)
|
||
{
|
||
if (_objData != null)
|
||
{
|
||
string _tempStr = _objData.ToString();
|
||
_tempStr = Regex.Replace(_tempStr, "\"[^\"]*(?:\"\"[^\"]*)*\"", m => m.Value.Replace("\r\n", "{lskj}").Replace("\"", ""));
|
||
|
||
int _rowNumber = 1;
|
||
int _pasteRowCount = 1;
|
||
string[] _split = { "\r\n" };
|
||
string[] _arrayRowStr = _tempStr.Split(_split, StringSplitOptions.None);
|
||
if (_arrayRowStr.Length < 1)
|
||
return;
|
||
GridColumn focColumn = this.gridView.FocusedColumn;
|
||
focColumn = focColumn == null ? this.gridView.Columns[0] : focColumn;
|
||
if (focColumn != null)
|
||
{
|
||
DataTable table = gridView.GridControl.DataSourceTable();
|
||
int beforeNumber = table.Rows.Count;
|
||
_rowNumber = this.gridView.FocusedRowHandle;
|
||
if (_rowNumber < 0)
|
||
{
|
||
// _rowNumber = 0;
|
||
//小于0就是焦点不在数据源存在的行中,默认新增
|
||
_rowNumber = table.Rows.Count;
|
||
}
|
||
if (_arrayRowStr.Length != gridView.SelectedRowsCount)
|
||
{
|
||
//选择区域与粘贴行数不匹配
|
||
}
|
||
_pasteRowCount = _arrayRowStr.Length;
|
||
for (int i = 0; i < _pasteRowCount; i++)
|
||
{
|
||
string[] _arrayStr2 = _arrayRowStr[i].Split('\t');
|
||
if (IgnoreTab)
|
||
{
|
||
_arrayStr2 = new string[] { _arrayRowStr[i] };
|
||
}
|
||
|
||
if ((i == _pasteRowCount - 1 && _arrayRowStr[_pasteRowCount - 1].Replace("\r\n", "").Trim() == ""))
|
||
continue;
|
||
DataRow newRow = null;
|
||
if (_rowNumber + 1 > table.Rows.Count)
|
||
{
|
||
newRow = table.NewRow();
|
||
//table.Rows.Add(newRow);
|
||
GridColumnCollection gridColumns = this.GridView.Columns;
|
||
this.gridView.FocusedRowHandle = _rowNumber;
|
||
foreach (GridColumn col in gridColumns)
|
||
{
|
||
GridColumnModel model = col.Tag as GridColumnModel;
|
||
string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue);
|
||
|
||
if (model.DefaultValue != null && model.DefaultValue.Contains("{#") && this.ParentControl != null)
|
||
{
|
||
fieldValue = this.ParentControl.ReplaceParentControlValue(model.DefaultValue);
|
||
if (!string.IsNullOrEmpty(fieldValue))
|
||
{
|
||
newRow[col.FieldName] = fieldValue;
|
||
}
|
||
}
|
||
else if (!string.IsNullOrEmpty(model.DefaultValue) && !model.DefaultValue.Contains("{ROW_"))
|
||
{
|
||
newRow[col.FieldName] = fieldValue;
|
||
}
|
||
}
|
||
}
|
||
this.gridView.FocusedRowHandle = _rowNumber;
|
||
if (_arrayStr2.Length == 0)
|
||
_arrayStr2[0] = _arrayRowStr[i];
|
||
//int _colNumber = beforeNumber == 0 ? 0 : focColumn.VisibleIndex;
|
||
//如果设置了最后有空白行,这以空白行选中的列为准
|
||
int _colNumber = beforeNumber == 0 && this.GridView.OptionsView.NewItemRowPosition != NewItemRowPosition.Bottom ? 0 : focColumn.VisibleIndex;
|
||
for (int j = 0; j < _arrayStr2.Length; j++)//j = _colNumber
|
||
{
|
||
|
||
GridColumn col = gridView.VisibleColumns[_colNumber];
|
||
|
||
GridColumnModel model = col.Tag as GridColumnModel;
|
||
if (!string.IsNullOrWhiteSpace(model.DisableCond))
|
||
{
|
||
DataRow FocusedRow = newRow == null ? this.gridView.GetFocusedDataRow() : newRow;
|
||
string UpdateCond = model.DisableCond;
|
||
if (this.ParentControl != null) UpdateCond = this.ParentControl.ReplaceParentControlValue(model.DisableCond);
|
||
UpdateCond = ReplaceHelper.ReplaceRowParam(FocusedRow, UpdateCond);
|
||
if (!ReplaceHelper.EvalCond(UpdateCond))
|
||
{
|
||
_colNumber += 1;
|
||
continue;
|
||
}
|
||
}
|
||
if (model != null && !model.ProhibitPaste && (model.CanCopy || ((gridView.OptionsBehavior.Editable) && (gridView.VisibleColumns[_colNumber].OptionsColumn.AllowEdit))))
|
||
{
|
||
// 返回ID类型特殊处理
|
||
string cellValue = _arrayStr2[j];
|
||
if (!string.IsNullOrEmpty(cellValue)) cellValue = cellValue.Replace("{lskj}", "\n");
|
||
|
||
bool IsTextEqualValue = false;
|
||
object value = model != null && ControlType.IsValue(model.FieldType) ? GetValueByCaption(model, col.ColumnEdit, cellValue, out IsTextEqualValue) : cellValue;
|
||
value = model != null && model.FieldType == 14 ? ReplaceMultiSpace(value) : value;
|
||
if (model != null && model.FieldType == 17)
|
||
{
|
||
value = value.Equals("非校验") ? 0 : value.Equals("校验") ? 1 : value;
|
||
if (value.Equals("不确定"))
|
||
{
|
||
_colNumber += 1;
|
||
continue;
|
||
}
|
||
}
|
||
if (model.FieldType == 116 || model.FieldType == 117)
|
||
{
|
||
RepositoryItemCheckedComboBoxEdit rccbe = col.ColumnEdit as RepositoryItemCheckedComboBoxEdit;
|
||
FrmModelLookUp modelLookUp = rccbe.Buttons[1].Tag as FrmModelLookUp;
|
||
value = ModuleReturnVerify(model, col.ColumnEdit, cellValue, out IsTextEqualValue);
|
||
//// 避免下拉框值替换失败提示错误
|
||
if (model != null && !IsTextEqualValue && cellValue == value + "")
|
||
{
|
||
_colNumber += 1;
|
||
continue;
|
||
}
|
||
}
|
||
if (model.FieldType == 160 || model.FieldType == 161)
|
||
{
|
||
RepositoryItemCheckedComboBoxEdit rccbe = col.ColumnEdit as RepositoryItemCheckedComboBoxEdit;
|
||
FrmModelLookUp2 modelLookUp = rccbe.Buttons[1].Tag as FrmModelLookUp2;
|
||
value = ModuleReturnVerify(model, col.ColumnEdit, cellValue, out IsTextEqualValue);
|
||
//// 避免下拉框值替换失败提示错误
|
||
if (model != null && !IsTextEqualValue && cellValue == value + "")
|
||
{
|
||
_colNumber += 1;
|
||
continue;
|
||
}
|
||
|
||
}
|
||
|
||
DateTime dateValue = new DateTime();
|
||
|
||
// 避免下拉框值替换失败提示错误
|
||
if (model != null && !IsTextEqualValue && ((ControlType.IsValue(model.FieldType) && cellValue == value + "") ||
|
||
(ControlType.LabTextInt == model.FieldType && (value + "").IsChinese()) ||
|
||
(ControlType.IsDate(model.FieldType) && !DateTime.TryParse(value + "", out dateValue))))
|
||
{
|
||
_colNumber += 1;
|
||
continue;
|
||
}
|
||
|
||
if (newRow == null)
|
||
{
|
||
gridView.SetRowCellValue(_rowNumber, col, value);
|
||
}
|
||
else
|
||
{
|
||
if (string.IsNullOrEmpty(value + ""))
|
||
{
|
||
if (string.IsNullOrWhiteSpace(newRow[col.FieldName] + ""))
|
||
{
|
||
if (col.ColumnType.Name.ToLower() == "string")
|
||
newRow[col.FieldName] = "";
|
||
if (col.ColumnType.Name.ToLower().IndexOf("char") >= 0)
|
||
newRow[col.FieldName] = "";
|
||
if (col.ColumnType.Name.ToLower().IndexOf("int") >= 0)
|
||
newRow[col.FieldName] = 0;
|
||
if (col.ColumnType.Name.ToLower() == "decimal")
|
||
newRow[col.FieldName] = 0;
|
||
//if (dc.DataType.Name.ToLower().IndexOf("date") >= 0)
|
||
// tmpRow[dc] = DateTime.Now;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
newRow[col.FieldName] = value;
|
||
}
|
||
|
||
}
|
||
//gridView.SetRowCellValue(_rowNumber, col, value);
|
||
}
|
||
_colNumber += 1;
|
||
|
||
|
||
}
|
||
_rowNumber += 1;
|
||
if (newRow != null)
|
||
{
|
||
// 其它处理(如绑定左侧树结构数据)
|
||
if (OnParseGridDataCallBack != null) this.OnParseGridDataCallBack(newRow);
|
||
for (int j = 0; j < gridView.Columns.Count; j++)
|
||
{
|
||
if (this.gridView.Columns[j].Tag == null) continue;
|
||
if ((this.gridView.Columns[j].Tag as GridColumnModel).LimitLength > 0)
|
||
{
|
||
int MaxInputLength = System.Text.Encoding.Default.GetBytes(newRow[gridView.Columns[j].FieldName].ToString()).Length;
|
||
if (MaxInputLength > (this.gridView.Columns[j].Tag as GridColumnModel).LimitLength)
|
||
{
|
||
newRow.SetColumnError(newRow.Table.Columns[gridView.Columns[j].FieldName], "当前输入文本超过设定长度!");//不满足条件设置错误信息
|
||
}
|
||
}
|
||
}
|
||
table.Rows.Add(newRow);
|
||
//this.gridView.FocusedRowHandle = _rowNumber - 1;
|
||
}
|
||
else
|
||
{
|
||
gridView.UpdateCurrentRow();
|
||
}
|
||
}
|
||
this.gridView.ShowEditor();
|
||
e.Handled = true;
|
||
//SendKeys.Send("{Esc}");
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:老版粘贴功能(会影响复制粘贴速度)</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2021-03-16 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="PopupMenuShowingEventArgs"/> instance containing the event data.</param>
|
||
private void OldPasteMethod(KeyEventArgs e, object _objData)
|
||
{
|
||
if (_objData != null)
|
||
{
|
||
string _tempStr = _objData.ToString();
|
||
_tempStr = Regex.Replace(_tempStr, "\"[^\"]*(?:\"\"[^\"]*)*\"", m => m.Value.Replace("\r\n", "{lskj}").Replace("\"", ""));
|
||
|
||
int _rowNumber = 1;
|
||
int _pasteRowCount = 1;
|
||
string[] _split = { "\r\n" };
|
||
string[] _arrayRowStr = _tempStr.Split(_split, StringSplitOptions.None);
|
||
if (_arrayRowStr.Length < 1)
|
||
return;
|
||
GridColumn focColumn = this.gridView.FocusedColumn;
|
||
focColumn = focColumn == null ? this.gridView.Columns[0] : focColumn;
|
||
if (focColumn != null)
|
||
{
|
||
DataTable table = gridView.GridControl.DataSourceTable();
|
||
int beforeNumber = table.Rows.Count;
|
||
_rowNumber = this.gridView.FocusedRowHandle;
|
||
if (_rowNumber < 0)
|
||
{
|
||
//_rowNumber = 0;
|
||
//小于0就是焦点不在数据源存在的行中,默认新增
|
||
_rowNumber = table.Rows.Count;
|
||
}
|
||
if (_arrayRowStr.Length != gridView.SelectedRowsCount)
|
||
{
|
||
//选择区域与粘贴行数不匹配
|
||
}
|
||
_pasteRowCount = _arrayRowStr.Length;
|
||
for (int i = 0; i < _pasteRowCount; i++)
|
||
{
|
||
string[] _arrayStr2 = _arrayRowStr[i].Split('\t');
|
||
|
||
if (IgnoreTab)
|
||
{
|
||
_arrayStr2 = new string[] { _arrayRowStr[i] };
|
||
}
|
||
|
||
if ((i == _pasteRowCount - 1 && _arrayRowStr[_pasteRowCount - 1].Replace("\r\n", "").Trim() == ""))
|
||
continue;
|
||
|
||
if (_rowNumber + 1 > table.Rows.Count)
|
||
{
|
||
if (OnAfterPasting != null)
|
||
{
|
||
this.OnAfterPasting(null, null);//直接调用新增行方法,添加关联数据
|
||
}
|
||
else
|
||
{
|
||
DataRow newRow = table.NewRow();
|
||
table.Rows.Add(newRow);
|
||
GridColumnCollection gridColumns = this.GridView.Columns;
|
||
this.gridView.FocusedRowHandle = _rowNumber;
|
||
foreach (GridColumn col in gridColumns)
|
||
{
|
||
GridColumnModel model = col.Tag as GridColumnModel;
|
||
string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue);
|
||
|
||
if (model.DefaultValue.Contains("{#") && this.ParentControl != null)
|
||
{
|
||
fieldValue = this.ParentControl.ReplaceParentControlValue(model.DefaultValue);
|
||
if (!string.IsNullOrEmpty(fieldValue))
|
||
{
|
||
newRow[col.FieldName] = fieldValue;
|
||
this.gridView.SetFocusedRowCellValue(col, fieldValue);
|
||
}
|
||
}
|
||
else if (!string.IsNullOrEmpty(model.DefaultValue) && !model.DefaultValue.Contains("{ROW_"))
|
||
{
|
||
newRow[col.FieldName] = fieldValue;
|
||
this.gridView.SetFocusedRowCellValue(col, fieldValue);
|
||
}
|
||
}
|
||
|
||
//其它处理(如绑定左侧树结构数据)
|
||
if (OnParseGridDataCallBack != null) this.OnParseGridDataCallBack(newRow);
|
||
}
|
||
}
|
||
|
||
this.gridView.FocusedRowHandle = _rowNumber;
|
||
if (_arrayStr2.Length == 0)
|
||
_arrayStr2[0] = _arrayRowStr[i];
|
||
//int _colNumber = beforeNumber == 0 ? 0 : focColumn.VisibleIndex;
|
||
//如果设置了最后有空白行,这以空白行选中的列为准
|
||
int _colNumber = beforeNumber == 0 && this.GridView.OptionsView.NewItemRowPosition != NewItemRowPosition.Bottom ? 0 : focColumn.VisibleIndex;
|
||
for (int j = 0; j < _arrayStr2.Length; j++)
|
||
{
|
||
GridColumn col = gridView.VisibleColumns[_colNumber];
|
||
GridColumnModel model = col.Tag as GridColumnModel;
|
||
|
||
if (!string.IsNullOrWhiteSpace(model.DisableCond))
|
||
{
|
||
DataRow FocusedRow = this.gridView.GetFocusedDataRow();
|
||
string UpdateCond = model.DisableCond;
|
||
if (this.ParentControl != null) UpdateCond = this.ParentControl.ReplaceParentControlValue(model.DisableCond);
|
||
UpdateCond = ReplaceHelper.ReplaceRowParam(FocusedRow, UpdateCond);
|
||
if (!ReplaceHelper.EvalCond(UpdateCond))
|
||
{
|
||
_colNumber += 1;
|
||
continue;
|
||
}
|
||
}
|
||
|
||
if (model != null && !model.ProhibitPaste && (model.CanCopy || ((gridView.OptionsBehavior.Editable) && (gridView.VisibleColumns[_colNumber].OptionsColumn.AllowEdit)))) //if ((gridView.OptionsBehavior.Editable) && (gridView.VisibleColumns[_colNumber].OptionsColumn.AllowEdit))
|
||
{
|
||
// 返回ID类型特殊处理
|
||
string cellValue = _arrayStr2[j];
|
||
if (!string.IsNullOrEmpty(cellValue)) cellValue = cellValue.Replace("{lskj}", "\n");
|
||
|
||
bool IsTextEqualValue = false;
|
||
object value = model != null && ControlType.IsValue(model.FieldType) ? GetValueByCaption(model, col.ColumnEdit, cellValue, out IsTextEqualValue) : cellValue;
|
||
if (model != null && model.FieldType == 17)
|
||
{
|
||
value = value.Equals("非校验") ? 0 : value.Equals("校验") ? 1 : value;
|
||
if (value.Equals("不确定"))
|
||
{
|
||
_colNumber += 1;
|
||
continue;
|
||
}
|
||
}
|
||
|
||
if (model.FieldType == 116 || model.FieldType == 117)
|
||
{
|
||
RepositoryItemCheckedComboBoxEdit rccbe = col.ColumnEdit as RepositoryItemCheckedComboBoxEdit;
|
||
FrmModelLookUp modelLookUp = rccbe.Buttons[1].Tag as FrmModelLookUp;
|
||
|
||
value = ModuleReturnVerify(model, col.ColumnEdit, cellValue, out IsTextEqualValue);
|
||
//// 避免下拉框值替换失败提示错误
|
||
if (model != null && !IsTextEqualValue && cellValue == value + "")
|
||
{
|
||
_colNumber += 1;
|
||
continue;
|
||
}
|
||
|
||
}
|
||
if (model.FieldType == 160 || model.FieldType == 161)
|
||
{
|
||
RepositoryItemCheckedComboBoxEdit rccbe = col.ColumnEdit as RepositoryItemCheckedComboBoxEdit;
|
||
FrmModelLookUp2 modelLookUp = rccbe.Buttons[1].Tag as FrmModelLookUp2;
|
||
value = ModuleReturnVerify(model, col.ColumnEdit, cellValue, out IsTextEqualValue);
|
||
//// 避免下拉框值替换失败提示错误
|
||
if (model != null && !IsTextEqualValue && cellValue == value + "")
|
||
{
|
||
_colNumber += 1;
|
||
continue;
|
||
}
|
||
|
||
}
|
||
|
||
DateTime dateValue = new DateTime();
|
||
|
||
// 避免下拉框值替换失败提示错误
|
||
if (model != null && !IsTextEqualValue && ((ControlType.IsValue(model.FieldType) && cellValue == value + "") ||
|
||
(ControlType.LabTextInt == model.FieldType && (value + "").IsChinese()) ||
|
||
(ControlType.IsDate(model.FieldType) && !DateTime.TryParse(value + "", out dateValue))))
|
||
{
|
||
_colNumber += 1;
|
||
continue;
|
||
}
|
||
gridView.SetRowCellValue(_rowNumber, col, value);
|
||
}
|
||
_colNumber += 1;
|
||
}
|
||
_rowNumber += 1;
|
||
gridView.UpdateCurrentRow();
|
||
}
|
||
this.gridView.ShowEditor();
|
||
e.Handled = true;
|
||
//SendKeys.Send("{Esc}");
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:自动搜索框弹出时</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-06-10 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="PopupMenuShowingEventArgs"/> instance containing the event data.</param>
|
||
protected void OnAutoSearchEditPopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (e.MenuType == GridMenuType.Column)
|
||
{
|
||
CurrentOperGridView = e.HitInfo.View;
|
||
|
||
GridViewColumnMenu columnMenu = e.Menu as GridViewColumnMenu;
|
||
//Model.ModuleCode+ e.HitInfo.Column.FieldName
|
||
DXMenuItem itemSaveColumn = new DXMenuItem("保存表格属性", SaveItemClick2);
|
||
DXMenuItem itemResetColumn = new DXMenuItem("重置表格属性", ResetItemClick2);
|
||
|
||
itemSaveColumn.BeginGroup = true;
|
||
itemSaveColumn.Tag = itemResetColumn.Tag = e.HitInfo.Column;
|
||
|
||
columnMenu.Items.AddRange(new DXMenuItem[] { itemSaveColumn, itemResetColumn });
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:自动搜索框弹出时</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-06-10 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="PopupMenuShowingEventArgs"/> instance containing the event data.</param>
|
||
protected void OnsearchEditKeyDown(object sender, KeyEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (e.Modifiers.CompareTo(Keys.Control) == 0 && e.KeyCode == Keys.V)
|
||
{
|
||
GridLookUpEdit edit = sender as GridLookUpEdit;
|
||
edit.Tag = "1";
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:设置表格单元格颜色</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-10-27 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs"/> instance containing the event data.</param>
|
||
/// <exception cref="System.NotImplementedException"></exception>
|
||
protected void OnGridViewRowCellStyle(object sender, RowCellStyleEventArgs e)
|
||
{
|
||
if (e.RowHandle >= 0 && this.GridRowColorsTable != null && this.GridRowColorsTable.Rows.Count > 0 && (!string.IsNullOrEmpty(e.CellValue + "") || SystemInfo.Instance.isBlankCellColor))
|
||
{
|
||
// 渲染界面数据量过多界面刷新会很慢
|
||
//DataTable table = this.gridControl.DataSourceTable();
|
||
//DataRow gridRow = table.Rows[e.RowHandle];
|
||
DataRow gridRow = this.gridView.GetDataRow(e.RowHandle);
|
||
foreach (DataRow item in this.GridRowColorsTable.Rows)
|
||
{
|
||
// string cond = ReplaceHelper.ReplaceRowParam(gridRow, item["condition"] + "").ReplaceColumnParam(e.Column.Name, e.Column.Caption, e.CellValue + "");
|
||
string cond = ReplaceHelper.ReplaceRowParamEmptyWrapQuote(gridRow, item["condition"] + "").ReplaceColumnParam(e.Column.Name, e.Column.Caption, e.CellValue + "");
|
||
try
|
||
{
|
||
|
||
|
||
if (!string.IsNullOrWhiteSpace(cond) && ReplaceHelper.EvalCond(cond))
|
||
{
|
||
GridRowColorModel model = new GridRowColorModel(item);
|
||
|
||
// 判断单元格是否被选中
|
||
bool isCellSelected = gridView.IsCellSelected(e.RowHandle, e.Column);
|
||
if (!isCellSelected)
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(model.BackColor))
|
||
{
|
||
e.Appearance.BackColor = ColorTranslator.FromHtml(model.BackColor);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(model.ForceColor))
|
||
{
|
||
e.Appearance.ForeColor = ColorTranslator.FromHtml(model.ForceColor);
|
||
}
|
||
}
|
||
|
||
|
||
FontStyle fontStyle = FontStyle.Regular;
|
||
|
||
if (model.IsBold) fontStyle |= FontStyle.Bold;
|
||
if (model.IsItalic) fontStyle |= FontStyle.Italic;
|
||
if (model.IsStrickOut) fontStyle |= FontStyle.Strikeout;
|
||
if (model.IsUnderLine) fontStyle |= FontStyle.Underline;
|
||
|
||
e.Appearance.FontStyleDelta = fontStyle;
|
||
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
//LogHelper.Instance.WriteLog("GridView RowCellStyle Error. Condition:" + model.Condition + ";EvalCondtion:" + cond);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:设置表格行颜色</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-06-10 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="RowStyleEventArgs"/> instance containing the event data.</param>
|
||
protected void OnGridViewRowStyle(object sender, RowStyleEventArgs e)
|
||
{
|
||
if (e.RowHandle >= 0 && this.GridRowColorsTable != null && this.GridRowColorsTable.Rows.Count > 0)
|
||
{
|
||
// 渲染界面数据量过多界面刷新会很慢
|
||
DataRow gridRow = this.gridView.GetDataRow(e.RowHandle);
|
||
foreach (DataRow item in this.GridRowColorsTable.Rows)
|
||
{
|
||
//string cond = ReplaceHelper.ReplaceRowParam(gridRow, item["condition"] + "");
|
||
string cond = ReplaceHelper.ReplaceRowParamEmptyWrapQuote(gridRow, item["condition"] + "");
|
||
try
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(cond) && ReplaceHelper.EvalCond(cond))
|
||
{
|
||
GridRowColorModel model = new GridRowColorModel(item);
|
||
if (!string.IsNullOrWhiteSpace(model.BackColor))
|
||
{
|
||
e.Appearance.BackColor = ColorTranslator.FromHtml(model.BackColor);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(model.ForceColor))
|
||
{
|
||
e.Appearance.ForeColor = ColorTranslator.FromHtml(model.ForceColor);
|
||
}
|
||
|
||
FontStyle fontStyle = FontStyle.Regular;
|
||
|
||
if (model.IsBold) fontStyle |= FontStyle.Bold;
|
||
if (model.IsItalic) fontStyle |= FontStyle.Italic;
|
||
if (model.IsStrickOut) fontStyle |= FontStyle.Strikeout;
|
||
if (model.IsUnderLine) fontStyle |= FontStyle.Underline;
|
||
|
||
e.Appearance.FontStyleDelta = fontStyle;
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
//LogHelper.Instance.WriteLog("GridView RowCellStyle Error. Condition:" + model.Condition + ";EvalCondtion:" + cond);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:选中单元格颜色突出显示</para>
|
||
/// <para>创建人:曹屹峰</para>
|
||
/// <para>创建日期:2024-03-05 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void GridView_RowCellStyle(object sender, RowCellStyleEventArgs e)
|
||
{
|
||
GridCell[] gridCells = this.GridView.GetSelectedCells();
|
||
foreach (GridCell cell in gridCells)
|
||
{
|
||
if (e.Column.Name == cell.Column.Name && e.RowHandle == cell.RowHandle)
|
||
{
|
||
e.Appearance.BackColor = ColorTranslator.FromHtml(SystemInfo.Instance.SelectRowBackColor);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:Enables data cells to be painted manually.</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-04 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs"/> instance containing the event data.</param>
|
||
protected virtual void OnGridViewCustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
//DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo gridViewInfo = gridView.GetViewInfo() as DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo;
|
||
//DevExpress.XtraGrid.Views.Grid.ViewInfo.GridCellInfo cellInfo = gridViewInfo.GetGridCellInfo(gridView.FocusedRowHandle, gridView.FocusedColumn);
|
||
//List<int> mergedRowHandle = new List<int>();
|
||
//if (cellInfo.IsMerged && cellInfo.MergedCell != null)
|
||
//{
|
||
// DevExpress.XtraGrid.Views.Grid.ViewInfo.GridMergedCellInfo gridMergedCellInfo = cellInfo.MergedCell as DevExpress.XtraGrid.Views.Grid.ViewInfo.GridMergedCellInfo;
|
||
// foreach (var item in gridMergedCellInfo.MergedCells)
|
||
// {
|
||
// mergedRowHandle.Add(item.RowHandle);
|
||
// }
|
||
//}
|
||
if (gridView.OptionsSelection.MultiSelect == true && gridView.OptionsSelection.MultiSelectMode == GridMultiSelectMode.CheckBoxRowSelect)
|
||
{
|
||
int[] selectRows = gridView.GetSelectedRows();
|
||
foreach (int selectRow in selectRows)
|
||
{//#9feb6a
|
||
if (e.RowHandle == selectRow)
|
||
{
|
||
e.Appearance.BackColor = ColorTranslator.FromHtml(SystemInfo.Instance.SelectRowBackColor);
|
||
if (!string.IsNullOrWhiteSpace(SystemInfo.Instance.SelectRowForeColor))
|
||
{
|
||
e.Appearance.ForeColor = ColorTranslator.FromHtml(SystemInfo.Instance.SelectRowForeColor);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else if (e.RowHandle == gridView.FocusedRowHandle)//|| mergedRowHandle.Contains(e.RowHandle)
|
||
{
|
||
e.Appearance.BackColor = ColorTranslator.FromHtml(SystemInfo.Instance.SelectRowBackColor);
|
||
if (!string.IsNullOrWhiteSpace(SystemInfo.Instance.SelectRowForeColor))
|
||
{
|
||
e.Appearance.ForeColor = ColorTranslator.FromHtml(SystemInfo.Instance.SelectRowForeColor);
|
||
}
|
||
|
||
//// 如果当前单元格被选中 → 画虚线
|
||
//if (gridView.IsCellSelected(e.RowHandle, e.Column))
|
||
//{
|
||
// // 先绘制默认内容(文字、背景、行颜色不变)
|
||
// e.DefaultDraw();
|
||
|
||
// // 创建虚线笔
|
||
// using (Pen pen = new Pen(Color.Black, 1))
|
||
// {
|
||
// pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; // 虚线样式
|
||
|
||
// // 在单元格内部画一圈虚线边框
|
||
// Rectangle rect = e.Bounds;
|
||
// rect.Width -= 1;
|
||
// rect.Height -= 1;
|
||
// e.Graphics.DrawRectangle(pen, rect);
|
||
// }
|
||
|
||
// // 标记已处理,防止被覆盖
|
||
// e.Handled = true;
|
||
//}
|
||
|
||
}
|
||
|
||
//选中行不改变颜色条件设置的颜色
|
||
if (SystemInfo.Instance.ConditionalStylePriority)
|
||
{
|
||
if (e.RowHandle >= 0 && this.GridRowColorsTable != null && this.GridRowColorsTable.Rows.Count > 0)
|
||
{
|
||
// 渲染界面数据量过多界面刷新会很慢
|
||
DataRow gridRow = this.gridView.GetDataRow(e.RowHandle);
|
||
foreach (DataRow item in this.GridRowColorsTable.Rows)
|
||
{
|
||
string cond = ReplaceHelper.ReplaceRowParam(gridRow, item["condition"] + "");
|
||
try
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(cond) && ReplaceHelper.EvalCond(cond))
|
||
{
|
||
GridRowColorModel model = new GridRowColorModel(item);
|
||
if (!string.IsNullOrWhiteSpace(model.BackColor) && !this.gridView.GetSelectedRows().Contains(e.RowHandle))
|
||
{
|
||
e.Appearance.BackColor = ColorTranslator.FromHtml(model.BackColor);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(model.ForceColor))
|
||
{
|
||
e.Appearance.ForeColor = ColorTranslator.FromHtml(model.ForceColor);
|
||
}
|
||
|
||
FontStyle fontStyle = FontStyle.Regular;
|
||
|
||
if (model.IsBold) fontStyle |= FontStyle.Bold;
|
||
if (model.IsItalic) fontStyle |= FontStyle.Italic;
|
||
if (model.IsStrickOut) fontStyle |= FontStyle.Strikeout;
|
||
if (model.IsUnderLine) fontStyle |= FontStyle.Underline;
|
||
|
||
e.Appearance.FontStyleDelta = fontStyle;
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
//LogHelper.Instance.WriteLog("GridView RowCellStyle Error. Condition:" + model.Condition + ";EvalCondtion:" + cond);
|
||
}
|
||
}
|
||
}
|
||
if (gridView.OptionsSelection.MultiSelect == true && gridView.OptionsSelection.MultiSelectMode == GridMultiSelectMode.CheckBoxRowSelect)
|
||
{
|
||
int[] selectRows = gridView.GetSelectedRows();
|
||
foreach (int selectRow in selectRows)
|
||
{//#9feb6a
|
||
if (e.RowHandle == selectRow)
|
||
e.Appearance.BackColor = ColorTranslator.FromHtml(SystemInfo.Instance.SelectRowBackColor);
|
||
}
|
||
}
|
||
else if (e.RowHandle == gridView.FocusedRowHandle)
|
||
{
|
||
e.Appearance.BackColor = ColorTranslator.FromHtml(SystemInfo.Instance.SelectRowBackColor);
|
||
}
|
||
}
|
||
|
||
string PromptText = string.Empty;
|
||
// 判断单元格值是否为 null 或空
|
||
if ((e.CellValue == null || string.IsNullOrEmpty(e.CellValue.ToString())) && PromptMessage.TryGetValue(e.Column.FieldName, out PromptText))
|
||
{
|
||
// 绘制默认单元格背景
|
||
e.DefaultDraw();
|
||
|
||
// 绘制提示文本(灰色、斜体)
|
||
var appearance = e.Appearance;
|
||
appearance.ForeColor = Color.Gray;
|
||
appearance.FontStyleDelta = FontStyle.Italic;
|
||
e.Graphics.DrawString(PromptText, appearance.Font,
|
||
new SolidBrush(appearance.ForeColor), e.Bounds,
|
||
new StringFormat { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center });
|
||
|
||
// 标记事件已处理,避免默认绘制覆盖
|
||
e.Handled = true;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:表格值改变时,处理关联字段和计算公式</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-15 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs"/> instance containing the event data.</param>
|
||
public void OnGridViewCellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (e.Column.Tag == null) return;
|
||
GridColumnModel model = e.Column.Tag as GridColumnModel;
|
||
if (model == null) return;
|
||
DataRow rowHandleRow = this.GridView.GetDataRow(e.RowHandle);
|
||
|
||
|
||
//值改变时,如果是验证是否重复的列报错就清除
|
||
if (RepeatedVerificationNames.Count > 0)
|
||
{
|
||
DataColumn[] datas = this.GridView.GetDataRow(e.RowHandle).GetColumnsInError();
|
||
foreach (DataColumn item in datas)
|
||
{
|
||
if (rowHandleRow.GetColumnError(item.ColumnName).Equals("数据重复"))
|
||
{
|
||
rowHandleRow.ClearErrors();
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
//计算列
|
||
if (model.FieldType == 158)
|
||
{
|
||
string result = EvalHelper.Eval2(ReplaceHelper.ReplaceEvalCond(e.Value + "")) + "";
|
||
this.gridView.SetRowCellValue(e.RowHandle, e.Column, result);
|
||
}
|
||
|
||
|
||
GridView gridView = this.gridControl.MainView as GridView;
|
||
DataTable dataTable = this.gridControl.DataSourceTable();
|
||
//根据某一列的值自动填充对应值
|
||
if (this.AutoPadDataReleColList.Count > 0)
|
||
{
|
||
foreach (GridColumnModel selectColumnModel in AutoPadDataReleColList)
|
||
{
|
||
if (!string.IsNullOrEmpty(selectColumnModel.AutoPadDataReleColName))
|
||
{
|
||
string value = rowHandleRow[selectColumnModel.FieldName] + "";
|
||
string[] dataReleColNames = selectColumnModel.AutoPadDataReleColName.TrimEnd(',').Split(',');
|
||
if (dataReleColNames.Contains(e.Column.FieldName))
|
||
{
|
||
DataRow[] selectRows = dataTable.Select().Where(n => (n[selectColumnModel.FieldName] + "").Equals(value)).ToArray();
|
||
foreach (DataRow selectRow in selectRows)
|
||
{
|
||
int dataSourceIndex = dataTable.Rows.IndexOf(selectRow);
|
||
int index = this.gridView.GetRowHandle(dataSourceIndex);
|
||
selectRow[e.Column.FieldName] = e.Value;
|
||
//关联
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, e.Value + "", index);
|
||
}
|
||
//计算规则配置在结果字段上,所以无需验证当前操作控件
|
||
this.SetCalcValue(model, e.Value + "", index);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//关联
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, e.Value + "", e.RowHandle);
|
||
}
|
||
//计算规则配置在结果字段上,所以无需验证当前操作控件
|
||
this.SetCalcValue(model, e.Value + "", e.RowHandle);
|
||
this.SetUpperValue(model, e.RowHandle, e.Value + "");
|
||
this.SetDisableColumn(model, e.RowHandle, e.Value + "");
|
||
//验证数据长度
|
||
if (model.LimitLength > 0 && e.Value != null)
|
||
{
|
||
int MaxInputLength = System.Text.Encoding.Default.GetBytes(e.Value.ToString()).Length;
|
||
if (model.LimitLength < MaxInputLength)
|
||
rowHandleRow.SetColumnError(rowHandleRow.Table.Columns[e.Column.ColumnHandle], "当前输入文本超过设定长度!");//满足条件设置错误信息
|
||
else
|
||
rowHandleRow.ClearErrors();//清除错误信息
|
||
}
|
||
|
||
//var rows = this.gridControl.DataSourceTable().Select().ToList().Where(n => n[e.Column.FieldName].Equals(Convert.ChangeType(e.Value, e.Column.ColumnType)));
|
||
//if (!string.IsNullOrEmpty(e.Value.ToString()) && rows.Count() > 0)
|
||
//{
|
||
// MessageUtil.Show("不能输入重复值!");
|
||
// this.gridView.SetRowCellValue(e.RowHandle, e.Column, string.Empty);
|
||
// this.gridView.FocusedRowHandle = e.RowHandle;
|
||
// this.gridView.FocusedColumn = e.Column;
|
||
//}
|
||
|
||
if (RefreshTotal) this.gridView.UpdateSummary();//合计列值改变后更新合计计算
|
||
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:取上一行值改变时</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2020-10-23 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs"/> instance containing the event data.</param>
|
||
public void OnGridViewtUpperValueChanged(GridColumn Newcolumn, string value, int rowhandle, GridColumnModel gridModel)
|
||
{
|
||
if (Newcolumn == null) return;
|
||
GridColumnModel model = Newcolumn.Tag as GridColumnModel;
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, value, rowhandle);
|
||
}
|
||
|
||
// 计算规则配置在结果字段上,所以无需验证当前操作控件
|
||
this.SetCalcValue(model, value, rowhandle);
|
||
this.UpperChange(model, gridModel, rowhandle);
|
||
this.SetDisableColumn(model, rowhandle, value);
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:单元格</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-03-22 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="SelectionChangedEventArgs"/> instance containing the event data.</param>
|
||
protected void OnGridViewSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
GridCell[] cells = this.gridView.GetSelectedCells();
|
||
int[] rows = this.gridView.GetSelectedRows();
|
||
|
||
this.pl_buttom.Visible = cells.Length > 1 && rows.Length > 1;
|
||
if (this.pl_buttom.Visible)
|
||
{
|
||
|
||
// 分别计算求和、平均值、最大值、最小值、计数
|
||
double sum = 0, avg = 0, max = 0, min = 0;
|
||
int count = 0;
|
||
string dataFormat = string.Empty;
|
||
foreach (GridCell cell in cells)
|
||
{
|
||
if (count == 0 && !string.IsNullOrWhiteSpace(cell.Column.DisplayFormat.FormatString)) dataFormat = cell.Column.DisplayFormat.FormatString;
|
||
double cellNumber = 0;
|
||
string cellValue = this.gridView.GetRowCellValue(cell.RowHandle, cell.Column) + "";
|
||
if (double.TryParse(cellValue, out cellNumber))
|
||
{
|
||
cellNumber = Convert.ToDouble(cellValue);
|
||
|
||
if (max < cellNumber)
|
||
max = cellNumber;
|
||
if (min == 0 || min > cellNumber)
|
||
min = cellNumber;
|
||
|
||
count++;
|
||
sum += cellNumber;
|
||
}
|
||
}
|
||
avg = count == 0 || count == 0 ? 0 : sum / count;
|
||
|
||
this.lblTotal.Text = string.Format(ResourceKeys.GridTotalDisplayText, count, Math.Round(sum, 2), Math.Round(avg, 2), Math.Round(max, 2), Math.Round(min, 2));
|
||
if (!string.IsNullOrWhiteSpace(dataFormat))
|
||
{
|
||
if (dataFormat.StartsWith("{0:"))
|
||
{
|
||
this.lblTotal.Text = string.Format(ResourceKeys.GridTotalDisplayText, count, string.Format(dataFormat, Convert.ToDecimal(sum)), string.Format(dataFormat, Convert.ToDecimal(avg)), string.Format(dataFormat, Convert.ToDecimal(max)), string.Format(dataFormat, Convert.ToDecimal(min)));
|
||
}
|
||
else
|
||
{
|
||
this.lblTotal.Text = string.Format(ResourceKeys.GridTotalDisplayText, count, string.Format("{0:" + dataFormat + "}", Convert.ToDecimal(sum)), string.Format("{0:" + dataFormat + "}", Convert.ToDecimal(avg)), string.Format("{0:" + dataFormat + "}", Convert.ToDecimal(max)), string.Format("{0:" + dataFormat + "}", Convert.ToDecimal(min)));
|
||
}
|
||
|
||
}
|
||
if (this.TotalQuantity) this.lblTotal.Text = string.Format("已选中 {0} 行", rows.Length);
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
this.SelectedRows = this.gridView.GetSelectedRows();
|
||
if (gridView.OptionsSelection.MultiSelect == true && gridView.OptionsSelection.MultiSelectMode == GridMultiSelectMode.CheckBoxRowSelect && gridView.OptionsSelection.EnableAppearanceFocusedCell == false) this.gridView.UpdateSummary();
|
||
|
||
if (SystemInfo.Instance.DisplayCheckboxSelection && !string.IsNullOrWhiteSpace(this.MultiplePrimary) && gridView.OptionsSelection.MultiSelect == true && gridView.OptionsSelection.MultiSelectMode == GridMultiSelectMode.CheckBoxRowSelect && gridView.OptionsSelection.EnableAppearanceFocusedCell == false)
|
||
{
|
||
SelectedDataSource.Clear();
|
||
DataRow[] dataRows = this.GetViewFocusedDataRows();
|
||
if (dataRows.Length > 0 && dataRows[0].Table.Columns.Contains(this.MultiplePrimary))
|
||
{
|
||
// 遍历勾选的行索引,并获取它们在数据源中的索引
|
||
foreach (DataRow row in GetViewFocusedDataRows())
|
||
{
|
||
SelectedDataSource.Add(row[this.MultiplePrimary] + "");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:单元格选中计算</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-06-10 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="FocusedRowObjectChangedEventArgs"/> instance containing the event data.</param>
|
||
protected void OnGridViewFocusedRowObjectChanged(object sender, FocusedRowObjectChangedEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
GridCell[] cells = this.gridView.GetSelectedCells();
|
||
int[] rows = this.gridView.GetSelectedRows();
|
||
|
||
this.pl_buttom.Visible = cells.Length > 1 && rows.Length > 1;
|
||
if (this.pl_buttom.Visible)
|
||
{
|
||
|
||
// 分别计算求和、平均值、最大值、最小值、计数
|
||
double sum = 0, avg = 0, max = 0, min = 0;
|
||
int count = 0;
|
||
|
||
foreach (GridCell cell in cells)
|
||
{
|
||
double cellNumber = 0;
|
||
string cellValue = this.gridView.GetRowCellValue(cell.RowHandle, cell.Column) + "";
|
||
if (double.TryParse(cellValue, out cellNumber))
|
||
{
|
||
cellNumber = Convert.ToDouble(cellValue);
|
||
|
||
if (max < cellNumber)
|
||
max = cellNumber;
|
||
if (min == 0 || min > cellNumber)
|
||
min = cellNumber;
|
||
|
||
count++;
|
||
sum += cellNumber;
|
||
}
|
||
}
|
||
|
||
avg = count == 0 || count == 0 ? 0 : sum / count;
|
||
this.lblTotal.Text = string.Format(ResourceKeys.GridTotalDisplayText, count, Math.Round(sum, 2), Math.Round(avg, 2), Math.Round(max, 2), Math.Round(min, 2));
|
||
if (this.TotalQuantity) this.lblTotal.Text = string.Format("已选中 {0} 行", rows.Length);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 单元格修改
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
//protected void OnCellValueChanged(object sender, CellValueChangedEventArgs e)
|
||
//{
|
||
// int index = this.GridView.GetFocusedDataSourceRowIndex();
|
||
// string columnName =e.Column.FieldName;
|
||
// if (!modifyThePosition.ContainsKey(index))
|
||
// {
|
||
// modifyThePosition.Add(index, columnName);
|
||
// }
|
||
// else {
|
||
// if (!modifyThePosition[index].Equals(columnName)) modifyThePosition[index] = modifyThePosition[index] + "," + columnName;
|
||
// }
|
||
//}
|
||
|
||
/// <summary>
|
||
/// <para>说明:列右键菜单扩展</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-02-01 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="PopupMenuShowingEventArgs"/> instance containing the event data.</param>
|
||
protected void OnGridViewPopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
//没有设置右键时,ContextMenuStrip为空。右键菜单可能会必须选中才能关闭,设置空ContextMenuStrip可用解决
|
||
if (this.gridControl.ContextMenuStrip == null)
|
||
{
|
||
ContextMenuStrip MenuStrip = new ContextMenuStrip();
|
||
this.gridControl.ContextMenuStrip = MenuStrip;
|
||
}
|
||
|
||
|
||
if (e.MenuType == GridMenuType.Column)
|
||
{
|
||
GridViewColumnMenu columnMenu = e.Menu as GridViewColumnMenu;
|
||
|
||
|
||
DXMenuItem itemFixLeft = new DXMenuItem("冻结列", FixLeftItemClick);
|
||
DXMenuItem itemFixLeftAll = new DXMenuItem("冻结列(所有列)", FixLeftAllItemClick);
|
||
DXMenuItem itemUnFix = new DXMenuItem("清除冻结", UnFixItemClick);
|
||
DXMenuItem itemUnFixAll = new DXMenuItem("清除冻结(所有列)", itemUnFixAllClick);
|
||
DXMenuItem itemSaveColumn = new DXMenuItem("保存表格属性", SaveItemClick);
|
||
DXMenuItem itemResetColumn = new DXMenuItem("重置表格属性", ResetItemClick);
|
||
DXMenuItem itemSetExportColumn = new DXMenuItem("设置导出列", SetExportItemClick);
|
||
DXMenuItem itemExportColumn = new DXMenuItem("导出表格数据", ExportItemClick);
|
||
DXMenuItem itemPrintColumn = new DXMenuItem("打印表格数据", PrintItemClick);
|
||
DXMenuItem itemSortColumn = new DXMenuItem("清除全部列排序", ClearSortItemClick);
|
||
DXMenuItem itemMultifunction = new DXMenuItem("多功能设置分组", Multifunction);
|
||
DXMenuItem itemLookUpColumn = new DXMenuItem("查找列", LookUpColumn);
|
||
DXMenuItem itemColumnSift = new DXMenuItem("一键设置列筛选条件", InstColumnSift);
|
||
DXMenuItem itemChartColumn = new DXMenuItem("一键图表展示", ChartShowClick);
|
||
DXMenuItem itemBsChartColumn = new DXMenuItem("一键Bs图表展示", BsChartShowClick);
|
||
DXMenuItem itemBsChartShowClick = new DXMenuItem("一键所有列属性设置", InstAllColumn);
|
||
|
||
itemChartColumn.Visible = this.ChartTable.Rows.Count > 0;
|
||
itemBsChartColumn.Visible = this.ChartTable.Rows.Count > 0;
|
||
itemBsChartShowClick.Visible = ERPInfo.Instance.UserName == "管理员" && Model != null;
|
||
itemSaveColumn.BeginGroup = itemFixLeft.BeginGroup = true;
|
||
itemUnFixAll.Tag = itemFixLeft.Tag = itemFixLeftAll.Tag = itemUnFix.Tag = itemColumnSift.Tag = e.HitInfo.Column;
|
||
itemSaveColumn.Tag = itemResetColumn.Tag = itemExportColumn.Tag = itemPrintColumn.Tag = itemSortColumn.Tag = itemChartColumn.Tag = itemBsChartColumn.Tag = itemBsChartShowClick.Tag = itemSetExportColumn.Tag = e.HitInfo.Column;
|
||
columnMenu.Items.AddRange(new DXMenuItem[] { itemFixLeft, itemFixLeftAll, itemUnFix, itemUnFixAll, itemLookUpColumn });
|
||
if (!string.IsNullOrEmpty(CustomColumKey)) columnMenu.Items.AddRange(new DXMenuItem[] { itemSaveColumn, itemResetColumn, itemSetExportColumn });
|
||
if (ExportPermission) columnMenu.Items.Add(itemExportColumn);
|
||
columnMenu.Items.AddRange(new DXMenuItem[] { itemPrintColumn, itemMultifunction, itemSortColumn, itemColumnSift, itemChartColumn, itemBsChartColumn, itemBsChartShowClick });
|
||
}
|
||
else if (e.MenuType == GridMenuType.Summary)
|
||
{
|
||
GridHitInfo info;
|
||
Point pt = this.gridView.GridControl.PointToClient(System.Windows.Forms.Control.MousePosition);
|
||
info = this.gridView.CalcHitInfo(pt);
|
||
if (e.Menu is DevExpress.XtraGrid.Menu.GridViewFooterMenu)//如果是Footer菜单则增加复制行选项
|
||
{
|
||
DXMenuCheckItem menuItemCell = new DXMenuCheckItem();
|
||
menuItemCell.Tag = info;
|
||
menuItemCell.Caption = "复制合计";
|
||
menuItemCell.Click += new EventHandler(OnMenuItem_Click);
|
||
DXMenuCheckItem menuItemRow = new DXMenuCheckItem();
|
||
menuItemRow.Caption = "复制合计行";
|
||
menuItemRow.Tag = info;
|
||
menuItemRow.Click += new EventHandler(OnMenuItem_Click);
|
||
e.Menu.Items.AddRange(new DXMenuCheckItem[] { menuItemCell, menuItemRow });
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:带参数自动搜索框</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-04-28 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="CancelEventArgs"/> instance containing the event data.</param>
|
||
protected void OnSearchEditQueryPopUp(object sender, CancelEventArgs e)
|
||
{
|
||
if (sender is GridLookUpEdit)
|
||
{
|
||
try
|
||
{
|
||
int popWidth = 0;
|
||
GridLookUpEdit edit = (sender as GridLookUpEdit);
|
||
GridColumnModel model = edit.Properties.Tag as GridColumnModel;
|
||
CurrentOperColumnKey = Model.ModuleCode + "_" + model.FieldName;
|
||
CurrentOperModel = model;
|
||
DataRow[] dataRows = this.GetViewFocusedDataRows();
|
||
DataRow rowItem = dataRows.Count() > 0 ? dataRows[0] : this.gridView.GetFocusedDataRow();
|
||
if (model.FieldType == ControlType.LabAutoGridValueParam || model.FieldType == ControlType.LabAutoGridTextParam || model.FieldType == ControlType.LabAutoCompleteTextParam || model.FieldType == ControlType.LabAutoCompleteValueParam)
|
||
{
|
||
if (model != null && (rowItem != null || this.ParentControl != null))
|
||
{
|
||
string sqlValue = model.SqlSource;
|
||
|
||
if (this.ParentControl != null)
|
||
sqlValue = this.ParentControl.ReplaceParentControlValue(sqlValue);
|
||
sqlValue = sqlValue.Replace("#", "");
|
||
|
||
if (rowItem != null)
|
||
{
|
||
sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, sqlValue);
|
||
}
|
||
|
||
|
||
DataTable table = MainImpl.GetDataTableResult(sqlValue);
|
||
|
||
|
||
if (model.SearchBoxAddition && (model.FieldType == ControlType.LabAutoGridTextParam || model.FieldType == ControlType.LabAutoCompleteTextParam))
|
||
{
|
||
if (this.ManuallyAddData.ContainsKey(model.FieldName))
|
||
{
|
||
List<DataRow> DataRows = this.ManuallyAddData[model.FieldName];
|
||
foreach (DataRow row in DataRows)
|
||
{
|
||
DataRow newrow = table.NewRow();
|
||
newrow.ItemArray = row.ItemArray;
|
||
table.Rows.Add(newrow);
|
||
}
|
||
}
|
||
}
|
||
|
||
edit.Properties.DataSource = table;
|
||
|
||
string[] columnsWidth = model != null ? model.LookUpFieldsWidth.Trim().TrimEnd(',').Split(',') : null;
|
||
if (model != null && !string.IsNullOrWhiteSpace(model.LookUpFieldsWidth) && columnsWidth.Length > 0)
|
||
{
|
||
int columnWidthIndex = 0;
|
||
foreach (DataColumn dcol in table.Columns)
|
||
{
|
||
if ((dcol.ColumnName.Substring(0, 1) != "_"))
|
||
{
|
||
if (edit.Properties.View.Columns.FirstOrDefault(x => x.FieldName == dcol.ColumnName) != null)
|
||
{
|
||
GridColumn gCol = edit.Properties.View.Columns[dcol.ColumnName];
|
||
int width = 0;
|
||
if (columnWidthIndex < columnsWidth.Length)
|
||
{
|
||
string widthStr = columnsWidth[columnWidthIndex];
|
||
width = int.TryParse(widthStr, out width) ? width : GraphicsText.GetTextWidth(gCol.Caption);
|
||
}
|
||
else
|
||
{
|
||
width = GraphicsText.GetTextWidth(gCol.Caption);
|
||
int maxWidth = CalcMaxColumnWidth(table, gCol.Name);
|
||
width = width > maxWidth ? width : maxWidth;
|
||
}
|
||
gCol.Width = width;
|
||
popWidth += gCol.Width;
|
||
}
|
||
}
|
||
columnWidthIndex++;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
foreach (DataColumn dcol in table.Columns)
|
||
{
|
||
int columnWidth = 0;
|
||
if ((dcol.ColumnName.Substring(0, 1) != "_"))
|
||
{
|
||
if (edit.Properties.View.Columns.FirstOrDefault(x => x.FieldName == dcol.ColumnName) != null)
|
||
{
|
||
GridColumn gCol = edit.Properties.View.Columns[dcol.ColumnName];
|
||
columnWidth = GraphicsText.GetTextWidth(gCol.Caption);
|
||
gCol.Width = CalcMaxColumnWidth(table, gCol.Name);
|
||
gCol.Width = columnWidth > gCol.Width ? columnWidth : gCol.Width;
|
||
popWidth += gCol.Width;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (model != null && model.LookUpWidth > 0)
|
||
{
|
||
popWidth = model.LookUpWidth + 5;
|
||
}
|
||
edit.Properties.PopupFormSize = new Size(popWidth, edit.Properties.PopupFormSize.Height);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
DataTable table = edit.Properties.DataSource != null ? (DataTable)edit.Properties.DataSource : new DataTable();
|
||
string[] columnsWidth = model != null ? model.LookUpFieldsWidth.Trim().TrimEnd(',').Split(',') : null;
|
||
if (model != null && !string.IsNullOrWhiteSpace(model.LookUpFieldsWidth) && columnsWidth.Length > 0)
|
||
{
|
||
int columnWidthIndex = 0;
|
||
foreach (GridColumn dcol in edit.Properties.View.Columns)
|
||
{
|
||
if ((dcol.FieldName.Substring(0, 1) != "_"))
|
||
{
|
||
int width = 0;
|
||
if (columnWidthIndex < columnsWidth.Length)
|
||
{
|
||
string widthStr = columnsWidth[columnWidthIndex];
|
||
width = int.TryParse(widthStr, out width) ? width : GraphicsText.GetTextWidth(dcol.Caption);
|
||
}
|
||
else
|
||
{
|
||
width = GraphicsText.GetTextWidth(dcol.Caption);
|
||
int maxWidth = CalcMaxColumnWidth(table, dcol.Name);
|
||
width = width > maxWidth ? width : maxWidth;
|
||
}
|
||
dcol.Width = width;
|
||
popWidth += dcol.Width;
|
||
}
|
||
columnWidthIndex++;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
foreach (GridColumn dcol in edit.Properties.View.Columns)
|
||
{
|
||
int columnWidth = 0;
|
||
if ((dcol.FieldName.Substring(0, 1) != "_"))
|
||
{
|
||
columnWidth = GraphicsText.GetTextWidth(dcol.Caption);
|
||
dcol.Width = CalcMaxColumnWidth(table, dcol.Name);
|
||
dcol.Width = columnWidth > dcol.Width ? columnWidth : dcol.Width;
|
||
popWidth += dcol.Width;
|
||
}
|
||
}
|
||
}
|
||
if (model != null && model.LookUpWidth > 0)
|
||
{
|
||
popWidth = model.LookUpWidth;
|
||
}
|
||
edit.Properties.PopupFormSize = new Size(popWidth, edit.Properties.PopupFormSize.Height);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
if (sender is SearchLookUpEdit)
|
||
{
|
||
try
|
||
{
|
||
SearchLookUpEdit edit = (sender as SearchLookUpEdit);
|
||
GridColumnModel model = edit.Properties.Tag as GridColumnModel;
|
||
|
||
CurrentOperColumnKey = Model.ModuleCode + "_" + model.FieldName;
|
||
CurrentOperModel = model;
|
||
DataRow[] dataRows = this.GetViewFocusedDataRows();
|
||
DataRow rowItem = dataRows != null ? dataRows[0] : null;
|
||
//DataRow rowItem = this.gridView.GetFocusedDataRow();
|
||
|
||
if (model.FieldType == ControlType.LabAutoCompleteTextParam || model.FieldType == ControlType.LabAutoCompleteValueParam)
|
||
{
|
||
if (model != null && rowItem != null)
|
||
{
|
||
string sqlValue = model.SqlSource;
|
||
|
||
if (this.ParentControl != null)
|
||
sqlValue = this.ParentControl.ReplaceParentControlValue(sqlValue);
|
||
sqlValue = sqlValue.Replace("#", "");
|
||
|
||
sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, sqlValue);
|
||
|
||
edit.Properties.DataSource = MainImpl.GetDataTableResult(sqlValue);
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 下拉列表框(带参数)。打开时更新下拉框数据
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ComboxEdit_QueryPopUp(object sender, CancelEventArgs e)
|
||
{
|
||
if (sender is LookUpEdit)
|
||
{
|
||
try
|
||
{
|
||
int popWidth = 0;
|
||
LookUpEdit edit = (sender as LookUpEdit);
|
||
GridColumnModel model = edit.Properties.Tag as GridColumnModel;
|
||
CurrentOperColumnKey = Model.ModuleCode + "_" + model.FieldName;
|
||
CurrentOperModel = model;
|
||
DataRow[] dataRows = this.GetViewFocusedDataRows();
|
||
DataRow rowItem = dataRows.Count() > 0 ? dataRows[0] : this.gridView.GetFocusedDataRow();
|
||
if (model.FieldType == ControlType.LabComboxValueParam || model.FieldType == ControlType.LabComboxTextParam)
|
||
{
|
||
if (model != null && (rowItem != null || this.ParentControl != null))
|
||
{
|
||
string sqlValue = model.SqlSource;
|
||
|
||
if (this.ParentControl != null)
|
||
sqlValue = this.ParentControl.ReplaceParentControlValue(sqlValue);
|
||
sqlValue = sqlValue.Replace("#", "");
|
||
if (rowItem != null)
|
||
{
|
||
sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, sqlValue);
|
||
}
|
||
DataTable table = MainImpl.GetDataTableResult(sqlValue);
|
||
edit.Properties.DataSource = table;
|
||
}
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:打开多选控件</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-03-20 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="ButtonPressedEventArgs"/> instance containing the event data.</param>
|
||
protected void OnButtonEditClick(object sender, ButtonPressedEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
CheckedComboBoxEdit btnEdit = (CheckedComboBoxEdit)sender;
|
||
FrmLookUp frmMain = e.Button.Tag as FrmLookUp;
|
||
GridColumnModel model = frmMain.Tag as GridColumnModel;
|
||
frmMain.EditText = btnEdit.Text;
|
||
frmMain.CurrentOperColumnKey = Model.ModuleCode + "_" + model.FieldName;
|
||
if (model.FieldType == ControlType.LabMultiSelectValue || model.FieldType == ControlType.LabMultiSelectValueNew || model.FieldType == ControlType.LabMultiSelectValueParam)
|
||
{
|
||
frmMain.EditValue = btnEdit.EditValue + "";
|
||
frmMain.EditText = string.Empty;
|
||
}
|
||
else
|
||
{
|
||
frmMain.EditText = btnEdit.Text;
|
||
frmMain.EditValue = string.Empty;
|
||
}
|
||
|
||
//多选关联单据头
|
||
frmMain.SourceSQL = model.SqlSource.Replace("#", "");
|
||
//单据头关联取值
|
||
if (this.ParentControl != null)
|
||
{
|
||
frmMain.SourceSQL = this.ParentControl.ReplaceControlValue(frmMain.SourceSQL);
|
||
}
|
||
|
||
frmMain.SourceSQL = ReplaceHelper.ReplaceRowParam(this.GridView.GetFocusedDataRow(), frmMain.SourceSQL);
|
||
//frmMain.SourceSQL = ReplaceHelper.ReplaceRowParam(this.gridView.GetFocusedDataRow(), frmMain.SourceSQL);
|
||
frmMain.DataSource = BaseImpl.GetDataTableResult(frmMain.SourceSQL);
|
||
|
||
DialogResult result = frmMain.ShowDialog();
|
||
if (result == DialogResult.OK)
|
||
{
|
||
btnEdit.EditValue = frmMain.EditValue;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:表格打开模块返回id</para>
|
||
/// <para>创建人:曹屹峰</para>
|
||
/// <para>创建日期:2021-08-23 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
protected void OnModuleChoice(object sender, ButtonPressedEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
CheckedComboBoxEdit btnEdit = (CheckedComboBoxEdit)sender;
|
||
FrmModelLookUp modelLookUp = e.Button.Tag as FrmModelLookUp;
|
||
|
||
GridColumnModel model = modelLookUp.Tag as GridColumnModel;
|
||
modelLookUp.EditText = btnEdit.Text;
|
||
modelLookUp.CurrentOperColumnKey = Model.ModuleCode + "_" + model.FieldName;
|
||
//if (model.FieldType == ControlType.LabMultiSelectValue || model.FieldType == ControlType.LabMultiSelectValueParam)
|
||
//{
|
||
// modelLookUp.EditValue = btnEdit.EditValue + "";
|
||
// modelLookUp.EditText = string.Empty;
|
||
//}
|
||
//else
|
||
//{
|
||
// modelLookUp.EditText = btnEdit.Text;
|
||
// modelLookUp.EditValue = string.Empty;
|
||
//}
|
||
|
||
modelLookUp.EditText = btnEdit.Text;
|
||
modelLookUp.EditValue = btnEdit.EditValue + "";
|
||
|
||
//多选关联单据头
|
||
modelLookUp.SourceSQL = model.SqlSource.Replace("#", "");
|
||
//单据头关联取值
|
||
if (this.ParentControl != null)
|
||
{
|
||
modelLookUp.SourceSQL = this.ParentControl.ReplaceControlValue(modelLookUp.SourceSQL);
|
||
}
|
||
|
||
modelLookUp.SourceSQL = ReplaceHelper.ReplaceRowParam(this.gridView.GetFocusedDataRow(), modelLookUp.SourceSQL);
|
||
//modelLookUp.DataSource = BaseImpl.GetDataTableResult(modelLookUp.SourceSQL);
|
||
modelLookUp.InitControls(modelLookUp.UnionModuleCodel);
|
||
DialogResult result = modelLookUp.ShowDialog();
|
||
if (result == DialogResult.OK)
|
||
{
|
||
btnEdit.EditValue = modelLookUp.EditValue;
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:表格打开模块返回id 新版</para>
|
||
/// <para>创建人:曹屹峰</para>
|
||
/// <para>创建日期:2021-08-23 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
protected void OnModuleChoiceNew(object sender, ButtonPressedEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
CheckedComboBoxEdit btnEdit = (CheckedComboBoxEdit)sender;
|
||
FrmModelLookUp2 modelLookUp = e.Button.Tag as FrmModelLookUp2;
|
||
|
||
GridColumnModel model = modelLookUp.Tag as GridColumnModel;
|
||
modelLookUp.EditText = btnEdit.Text;
|
||
modelLookUp.CurrentOperColumnKey = Model.ModuleCode + "_" + model.FieldName;
|
||
modelLookUp.EditText = btnEdit.Text;
|
||
modelLookUp.EditValue = btnEdit.EditValue + "";
|
||
|
||
//多选关联单据头
|
||
string SourceSQL = modelLookUp.SysModel.MenuSql.Replace("#", "") + model.SplicingConditions;
|
||
//单据头关联取值
|
||
if (this.ParentControl != null)
|
||
{
|
||
SourceSQL = this.ParentControl.ReplaceControlValue(SourceSQL);
|
||
}
|
||
|
||
modelLookUp.NewSourceSQL = ReplaceHelper.ReplaceRowParam(this.gridView.GetFocusedDataRow(), SourceSQL);
|
||
modelLookUp.AddModuleResult = model.addModuleResult;
|
||
//modelLookUp.DataSource = BaseImpl.GetDataTableResult(modelLookUp.SourceSQL);
|
||
modelLookUp.InitControls(modelLookUp.UnionModuleCodel);
|
||
DialogResult result = modelLookUp.ShowDialog();
|
||
if (result == DialogResult.OK)
|
||
{
|
||
btnEdit.EditValue = modelLookUp.EditValue;
|
||
string[] resultFields = model.addModuleResult.Trim().Split(',');
|
||
DataRow focusedRow = this.gridView.GetFocusedDataRow();
|
||
if (focusedRow != null)
|
||
{
|
||
foreach (string resultKey in modelLookUp.ModuleResultDic.Keys)
|
||
{
|
||
string resultValue = modelLookUp.ModuleResultDic[resultKey];
|
||
if (focusedRow.Table.Columns.Contains(resultKey))
|
||
{
|
||
focusedRow[resultKey] = resultValue;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:表格打开模块添加行</para>
|
||
/// <para>创建人:曹屹峰</para>
|
||
/// <para>创建日期:2021-08-23 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
protected void OnModuleAddLine(object sender, ButtonPressedEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
CheckedComboBoxEdit btnEdit = (CheckedComboBoxEdit)sender;
|
||
FrmModelLookUp2 modelLookUp = e.Button.Tag as FrmModelLookUp2;
|
||
|
||
GridColumnModel model = modelLookUp.Tag as GridColumnModel;
|
||
modelLookUp.EditText = btnEdit.Text;
|
||
modelLookUp.CurrentOperColumnKey = Model.ModuleCode + "_" + model.FieldName;
|
||
modelLookUp.EditText = btnEdit.Text;
|
||
modelLookUp.EditValue = btnEdit.EditValue + "";
|
||
|
||
//多选关联单据头
|
||
string SourceSQL = modelLookUp.SysModel.MenuSql.Replace("#", "") + model.SplicingConditions;
|
||
//单据头关联取值
|
||
if (this.ParentControl != null)
|
||
{
|
||
SourceSQL = this.ParentControl.ReplaceControlValue(SourceSQL);
|
||
}
|
||
|
||
modelLookUp.NewSourceSQL = ReplaceHelper.ReplaceRowParam(this.gridView.GetFocusedDataRow(), SourceSQL);
|
||
modelLookUp.AddModuleResult = model.addModuleResult;
|
||
modelLookUp.InitControls(modelLookUp.UnionModuleCodel);
|
||
DialogResult result = modelLookUp.ShowDialog();
|
||
if (result == DialogResult.OK)
|
||
{
|
||
|
||
btnEdit.EditValue = modelLookUp.EditValue;
|
||
this.GridView.SetFocusedRowCellValue(model.FieldName, modelLookUp.EditValue);
|
||
|
||
if (OnNewLine != null && modelLookUp.EditValueList.Count > 0)
|
||
{
|
||
OnNewLine(model.FieldName, modelLookUp.EditValueList);
|
||
}
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 模块返回框清空
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void BtnEdit_KeyDown(object sender, KeyEventArgs e)
|
||
{
|
||
|
||
if (e.KeyCode == Keys.Back)
|
||
{
|
||
CheckedComboBoxEdit btnEdit = (CheckedComboBoxEdit)sender;
|
||
btnEdit.EditValue = string.Empty;
|
||
btnEdit.Text = string.Empty;
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:表格打开模块返回数据源行</para>
|
||
/// <para>创建人:唐德馨</para>
|
||
/// <para>创建日期:2022-10-4 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
protected void OnModuleRowsChoice(object sender, ButtonPressedEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
ButtonEdit btnEdit = (ButtonEdit)sender;
|
||
FrmRowsModelLookUp modelLookUp = e.Button.Tag as FrmRowsModelLookUp;
|
||
|
||
GridColumnModel model = modelLookUp.Tag as GridColumnModel;
|
||
modelLookUp.EditText = btnEdit.Text;
|
||
modelLookUp.CurrentOperColumnKey = Model.ModuleCode + "_" + model.FieldName;
|
||
if (model.FieldType == ControlType.LabMultiSelectValue || model.FieldType == ControlType.LabMultiSelectValueNew || model.FieldType == ControlType.LabMultiSelectValueParam)
|
||
{
|
||
modelLookUp.EditValue = btnEdit.EditValue + "";
|
||
modelLookUp.EditText = string.Empty;
|
||
}
|
||
else
|
||
{
|
||
modelLookUp.EditText = btnEdit.Text;
|
||
modelLookUp.EditValue = string.Empty;
|
||
}
|
||
////多选关联单据头
|
||
//modelLookUp.SourceSQL = model.SqlSource.Replace("#", "");
|
||
////单据头关联取值
|
||
//if (this.ParentControl != null)
|
||
//{
|
||
// modelLookUp.SourceSQL = this.ParentControl.ReplaceControlValue(modelLookUp.SourceSQL);
|
||
//}
|
||
|
||
//modelLookUp.SourceSQL = ReplaceHelper.ReplaceRowParam(this.gridView.GetFocusedDataRow(), modelLookUp.SourceSQL);
|
||
//modelLookUp.DataSource = BaseImpl.GetDataTableResult(modelLookUp.SourceSQL);
|
||
string sourceSql = string.Empty;
|
||
if (!string.IsNullOrEmpty(model.SqlSource))
|
||
{
|
||
sourceSql = model.SqlSource;
|
||
}
|
||
else
|
||
{
|
||
DataRow modelRow = MainImpl.GetSystemdllTab(model.addModuleld);//获取单个模块信息
|
||
if (modelRow == null)
|
||
{
|
||
MessageUtil.Show("模块编号[" + model.addModuleld + "],配置错误!\r\n该模块信息未找到!");
|
||
return;
|
||
}
|
||
ModuleModel moduleModel = new ModuleModel(modelRow);// 系统模块实体对象
|
||
sourceSql = moduleModel.MenuSql;
|
||
}
|
||
|
||
//多选关联单据头
|
||
modelLookUp.SourceSQL = sourceSql.Replace("#", "");
|
||
//单据头关联取值
|
||
if (this.ParentControl != null)
|
||
{
|
||
modelLookUp.SourceSQL = this.ParentControl.ReplaceControlValue(modelLookUp.SourceSQL);
|
||
}
|
||
|
||
modelLookUp.SourceSQL = ReplaceHelper.ReplaceRowParam(this.gridView.GetFocusedDataRow(), modelLookUp.SourceSQL);
|
||
//modelLookUp.DataSource = BaseImpl.GetDataTableResult(modelLookUp.SourceSQL);
|
||
|
||
modelLookUp.InitControls();
|
||
DialogResult result = modelLookUp.ShowDialog();
|
||
modelLookUp.DataSource = null;
|
||
if (result == DialogResult.OK)
|
||
{
|
||
//btnEdit.EditValue = modelLookUp.EditValue;
|
||
DataRow returnRow = modelLookUp.selectRowsEditValue;
|
||
DataRow dataRow = this.gridView.GetFocusedDataRow();
|
||
if (!string.IsNullOrEmpty(model.SqlSource))
|
||
{
|
||
foreach (GridColumn gridColumn in this.gridView.Columns)
|
||
{
|
||
GridColumnModel colModel = gridColumn.Tag as GridColumnModel;
|
||
if (!string.IsNullOrEmpty(colModel.unionCompare) && colModel.unionCompare.Trim().Split('^').Length == 2)
|
||
{
|
||
string[] fields = colModel.unionCompare.Trim().Split('^');
|
||
string inField = fields[0];
|
||
string outField = fields[1];
|
||
if (returnRow.Table.Columns.Contains(inField))
|
||
{
|
||
dataRow[outField] = returnRow[inField] + "";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//btnEdit.EditValue = modelLookUp.EditValue;
|
||
foreach (DataColumn col in returnRow.Table.Columns)
|
||
{
|
||
if (dataRow.Table.Columns.Contains(col.ColumnName))
|
||
{
|
||
dataRow[col.ColumnName] = returnRow[col.ColumnName] + "";
|
||
}
|
||
}
|
||
}
|
||
SendKeys.Send("{Esc}");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:表格打开模块返回数据源行(优化)</para>
|
||
/// <para>创建人:唐德馨</para>
|
||
/// <para>创建日期:2022-10-4 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
protected void OnModuleRowsChoiceNew(object sender, ButtonPressedEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
ButtonEdit btnEdit = (ButtonEdit)sender;
|
||
FrmRowsModelLookUpNew modelLookUp = e.Button.Tag as FrmRowsModelLookUpNew;
|
||
|
||
GridColumnModel model = modelLookUp.Tag as GridColumnModel;
|
||
modelLookUp.EditText = btnEdit.Text;
|
||
modelLookUp.CurrentOperColumnKey = Model.ModuleCode + "_" + model.FieldName;
|
||
if (model.FieldType == ControlType.LabMultiSelectValue || model.FieldType == ControlType.LabMultiSelectValueNew || model.FieldType == ControlType.LabMultiSelectValueParam)
|
||
{
|
||
modelLookUp.EditValue = btnEdit.EditValue + "";
|
||
modelLookUp.EditText = string.Empty;
|
||
}
|
||
else
|
||
{
|
||
modelLookUp.EditText = btnEdit.Text;
|
||
modelLookUp.EditValue = string.Empty;
|
||
}
|
||
string sourceSql = string.Empty;
|
||
if (!string.IsNullOrEmpty(model.SqlSource))
|
||
{
|
||
sourceSql = model.SqlSource;
|
||
}
|
||
else
|
||
{
|
||
DataRow modelRow = MainImpl.GetSystemdllTab(model.addModuleld);//获取单个模块信息
|
||
if (modelRow == null)
|
||
{
|
||
MessageUtil.Show("模块编号[" + model.addModuleld + "],配置错误!\r\n该模块信息未找到!");
|
||
return;
|
||
}
|
||
ModuleModel moduleModel = new ModuleModel(modelRow);// 系统模块实体对象
|
||
sourceSql = moduleModel.MenuSql;
|
||
}
|
||
//多选关联单据头
|
||
modelLookUp.SourceSQL = sourceSql.Replace("#", "");
|
||
//单据头关联取值
|
||
if (this.ParentControl != null)
|
||
{
|
||
modelLookUp.SourceSQL = this.ParentControl.ReplaceControlValue(modelLookUp.SourceSQL);
|
||
}
|
||
|
||
modelLookUp.SourceSQL = ReplaceHelper.ReplaceRowParam(this.gridView.GetFocusedDataRow(), modelLookUp.SourceSQL);
|
||
modelLookUp.InitControls();
|
||
DialogResult result = modelLookUp.ShowDialog();
|
||
modelLookUp.DataSource = null;
|
||
if (result == DialogResult.OK)
|
||
{
|
||
DataRow returnRow = modelLookUp.selectRowsEditValue;
|
||
DataRow dataRow = this.gridView.GetFocusedDataRow();
|
||
if (!string.IsNullOrEmpty(model.SqlSource))
|
||
{
|
||
foreach (GridColumn gridColumn in this.gridView.Columns)
|
||
{
|
||
GridColumnModel colModel = gridColumn.Tag as GridColumnModel;
|
||
if (!string.IsNullOrEmpty(colModel.unionCompare) && colModel.unionCompare.Trim().Split('^').Length == 2)
|
||
{
|
||
string[] fields = colModel.unionCompare.Trim().Split('^');
|
||
string inField = fields[0];
|
||
string outField = fields[1];
|
||
if (returnRow.Table.Columns.Contains(inField))
|
||
{
|
||
dataRow[outField] = returnRow[inField] + "";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
foreach (DataColumn col in returnRow.Table.Columns)
|
||
{
|
||
if (dataRow.Table.Columns.Contains(col.ColumnName))
|
||
{
|
||
dataRow[col.ColumnName] = returnRow[col.ColumnName] + "";
|
||
}
|
||
}
|
||
}
|
||
SendKeys.Send("{Esc}");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:打开sql生成组件</para>
|
||
/// <para>创建人:曹屹峰</para>
|
||
/// <para>创建日期:2021-09-29 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
private void OnSqlGenerate(object sender, ButtonPressedEventArgs e)
|
||
{
|
||
CheckedComboBoxEdit btnEdit = (CheckedComboBoxEdit)sender;
|
||
FrmAutoSqlLoad sqlGenerator = new FrmAutoSqlLoad();
|
||
GridColumnModel model = sqlGenerator.Tag as GridColumnModel;
|
||
sqlGenerator.EditText = btnEdit.Text;
|
||
DialogResult result = sqlGenerator.ShowDialog();
|
||
if (result == DialogResult.OK)
|
||
{
|
||
btnEdit.EditValue = sqlGenerator.EditText;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:表格双击打开模块配置</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-08-13 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
protected void OnGridViewDoubleClick(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
DataRow mSelectRow = this.gridView.GetFocusedDataRow();
|
||
if (this.gridControl.ContextMenuStrip != null)
|
||
{
|
||
Dictionary<ToolStripItem, GridRightMenuModel> DbClickItemDic = new Dictionary<ToolStripItem, GridRightMenuModel>();
|
||
foreach (ToolStripItem cms in this.gridControl.ContextMenuStrip.Items)
|
||
{
|
||
GridRightMenuModel model = cms.Tag as GridRightMenuModel;
|
||
if (model != null && model.DbClick)
|
||
{
|
||
DbClickItemDic.Add(cms, model);
|
||
}
|
||
}
|
||
// 判断右键菜单是否可用
|
||
foreach (ToolStripItem cms in DbClickItemDic.Keys)
|
||
{
|
||
GridRightMenuModel model = DbClickItemDic[cms];
|
||
if (model != null && model.DbClick)
|
||
{
|
||
if (model.PrivilegeOper.Length > 1 && !model.PrivilegeOper.Contains(ERPInfo.Instance.UserName + ","))
|
||
{
|
||
cms.Enabled = false;
|
||
}
|
||
else
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(model.MenuCond))
|
||
{
|
||
try
|
||
{
|
||
string cond = ReplaceHelper.ReplaceRowParam(mSelectRow, model.MenuCond);
|
||
if (ParentControl != null)
|
||
cond = ParentControl.ReplaceParentControlValue(cond);
|
||
cms.Enabled = ReplaceHelper.EvalCond(cond);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
MessageUtil.Show(ResourceKeys.SetRightMenuCondFault);
|
||
}
|
||
}
|
||
}
|
||
if (cms.Enabled)
|
||
{
|
||
cms.PerformClick();
|
||
}
|
||
else
|
||
{
|
||
//MessageUtil.Show(ResourceKeys.CondtionNotSatisfiable);
|
||
continue;
|
||
}
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 表格单击逻辑
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void OnGridViewClick(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
Point gcPoint = gridControl.PointToScreen(gridControl.Location);
|
||
Point pt = new Point(MousePosition.X - gcPoint.X, MousePosition.Y - gcPoint.Y);
|
||
GridHitInfo _hitInfo = GridView.CalcHitInfo(pt);
|
||
if (_hitInfo != null && _hitInfo.InRowCell && _hitInfo.Column.ColumnEdit is RepositoryItemHyperLinkEdit hyperLinkEdit)
|
||
{
|
||
if (_hitInfo.Column.Tag is GridColumnModel gridColumnModel)
|
||
{
|
||
if (gridColumnModel.FieldType == ControlType.LabHyperlink)
|
||
{
|
||
HyperLinkEdit_Click(hyperLinkEdit, null);
|
||
}
|
||
else if (gridColumnModel.FieldType == ControlType.LabRightlink)
|
||
{
|
||
OnRightClick(hyperLinkEdit, null);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-06-10 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected void OnGridViewEndSorting(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
this.gridView.MoveFirst();
|
||
//this.gridView.SmoothScroll(0);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
//this.gridView.SelectRowHandler(0);
|
||
}
|
||
#region 表格数据源改变时进行字段长度判断
|
||
/// <summary>
|
||
/// <para>说明:表格数据源改变时进行字段长度判断</para>
|
||
/// <para>创建人:唐德馨</para>
|
||
/// <para>创建日期:2021-10-09 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void OnGridDataSourceChanged(object sender, EventArgs e)
|
||
{
|
||
GridView gridView = (GridView)sender;
|
||
foreach (GridColumn col in gridView.Columns)
|
||
{
|
||
if (col.Tag != null && col.Tag is GridColumnModel)
|
||
{
|
||
GridColumnModel model = col.Tag as GridColumnModel;
|
||
if (model.LimitLength > 0)
|
||
{
|
||
for (int i = 0; i < gridView.DataRowCount; i++)
|
||
{
|
||
DataRow HandleRow = (gridView.GetRow(i) as DataRowView).Row;
|
||
int MaxInputLength = System.Text.Encoding.Default.GetBytes(gridView.GetRowCellValue(i, col) + "").Length;
|
||
if (model.LimitLength < MaxInputLength)
|
||
HandleRow.SetColumnError(HandleRow.Table.Columns[col.ColumnHandle], "当前输入文本超过设定长度!");//满足条件设置错误信息
|
||
}
|
||
}
|
||
}
|
||
}
|
||
// 调用动态构建方法
|
||
if (CustomGroupBandEx != null || CustomGroupTreeBandEx != null)
|
||
{
|
||
DataTable currentDataSource = gridView.GridControl.DataSource as DataTable;
|
||
if (CustomGroupBandEx != null && currentDataSource != null)
|
||
{
|
||
BuildDynamicGroupedColumns(CustomGroupBandEx, currentDataSource);
|
||
}
|
||
if (CustomGroupTreeBandEx != null && currentDataSource != null)
|
||
{
|
||
BuildDynamicGroupedColumns(CustomGroupTreeBandEx, currentDataSource);
|
||
}
|
||
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 构建多表头格式
|
||
/// </summary>
|
||
/// <param name="bandedGridControlEx"></param>
|
||
/// <param name="originalDataSource"></param>
|
||
private void BuildDynamicGroupedColumns(BandedGridControlEx bandedGridControlEx, DataTable originalDataSource)
|
||
{
|
||
bandedGridControlEx.BandedView.BeginUpdate();
|
||
bandedGridControlEx.BandedView.OptionsView.ColumnAutoWidth = false;
|
||
|
||
/* ========= 0. 取列定义 ========= */
|
||
GridColumnModel GroupPrimary = ColumnList.FirstOrDefault(o => o.IsCustomGroupPrimary);
|
||
GridColumnModel GroupFieldprimary = ColumnList.FirstOrDefault(o => o.IsCustomGroupField == 1);
|
||
List<GridColumnModel> GroupField = ColumnList.Where(o => o.IsCustomGroupField == 2 || o.IsCustomGroupField == 4).ToList(); // 4 = 特殊字段
|
||
List<GridColumnModel> sumField = ColumnList.Where(o => o.IsCustomGroupField == 3).ToList();
|
||
if (GroupPrimary == null || GroupFieldprimary == null || !GroupField.Any()) return;
|
||
|
||
/* ========= 1. 清空现有列 ========= */
|
||
bandedGridControlEx.BandedView.Bands.Clear();
|
||
bandedGridControlEx.BandedView.Columns.Clear();
|
||
bandedGridControlEx.BandedView.GroupSummary.Clear();
|
||
bandedGridControlEx.BandedView.OptionsView.ShowFooter = false;
|
||
|
||
/* ========= 2. 创建“基本信息”Band ========= */
|
||
List<GridColumnModel> normalColumns = ColumnList.Where(o => o.IsCustomGroupField == 0 || o.IsCustomGroupField == 3).ToList();
|
||
bool bandedFirstVisibleColumn = true;
|
||
|
||
GridBand normalBand = new GridBand { Caption = "基本信息" };
|
||
|
||
if (this.AggregationFreeze) normalBand.Fixed = FixedStyle.Left;
|
||
|
||
|
||
bandedGridControlEx.BandedView.Bands.Add(normalBand);
|
||
|
||
foreach (var normalCol in normalColumns)
|
||
{
|
||
if (!originalDataSource.Columns.Contains(normalCol.FieldName)) continue;
|
||
|
||
BandedGridColumn col = new BandedGridColumn
|
||
{
|
||
FieldName = normalCol.FieldName,
|
||
Caption = normalCol.FieldText,
|
||
Width = normalCol.Width,
|
||
Visible = normalCol.Visible,
|
||
Tag = normalCol,
|
||
OptionsColumn = { AllowEdit = normalCol.Edit, FixedWidth = true }
|
||
};
|
||
col.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
|
||
col.OptionsFilter.FilterPopupMode = FilterPopupMode.CheckedList;
|
||
if (!normalCol.Edit)
|
||
{
|
||
col.AppearanceHeader.Options.UseForeColor = true;
|
||
col.AppearanceHeader.ForeColor = ColorTranslator.FromHtml(HeaderColor);
|
||
}
|
||
if (normalCol.CanNull)
|
||
{
|
||
col.AppearanceHeader.Options.UseForeColor = true;
|
||
col.AppearanceHeader.ForeColor = RequiredForceColor;
|
||
}
|
||
bandedGridControlEx.SetColumnFormat(col, normalCol);
|
||
SetDynamicBandedColumnSumming(bandedGridControlEx.BandedView, col, normalCol, ref bandedFirstVisibleColumn, false);
|
||
normalBand.Columns.Add(col);
|
||
bandedGridControlEx.BandedView.Columns.Add(col);
|
||
}
|
||
|
||
/* ========= 3. 生成动态表头列表 ========= */
|
||
var dynamicHeaders = originalDataSource.AsEnumerable()
|
||
.Select(r => r[GroupFieldprimary.FieldName])
|
||
.Where(v => v != null && v != DBNull.Value)
|
||
.Select(v => v is DateTime dt ? dt.ToString("yyyy-MM-dd") : v.ToString())
|
||
.Distinct()
|
||
.ToList();
|
||
|
||
/* ========= 4. 生成动态 Band + 子列 ========= */
|
||
foreach (string headerName in dynamicHeaders)
|
||
{
|
||
GridBand dynamicBand = new GridBand { Caption = headerName };
|
||
bandedGridControlEx.BandedView.Bands.Add(dynamicBand);
|
||
|
||
// 尝试把 headerName 解析成日期,以便下面用星期几
|
||
DateTime headerDate;
|
||
bool isDateHeader = DateTime.TryParse(headerName, out headerDate);
|
||
|
||
foreach (var subField in GroupField)
|
||
{
|
||
string dynamicFieldName = $"{headerName}_{subField.FieldName}";
|
||
|
||
/* —— 计算子列 Caption —— */
|
||
string subCaption = subField.FieldText; // 默认
|
||
if (subField.IsCustomGroupField == 4 && isDateHeader)
|
||
{
|
||
// 将星期几转成中文“日一二三四五六”,根据需要可自行改动
|
||
string[] cnWeek = { "日", "一", "二", "三", "四", "五", "六" };
|
||
subCaption = cnWeek[(int)headerDate.DayOfWeek]; // 0=Sunday
|
||
}
|
||
|
||
BandedGridColumn subColumn = new BandedGridColumn
|
||
{
|
||
Name = dynamicFieldName,
|
||
FieldName = dynamicFieldName,
|
||
Caption = subCaption,
|
||
Width = subField.Width,
|
||
Visible = subField.Visible,
|
||
Tag = subField,
|
||
MinWidth = subField.Width,
|
||
MaxWidth = subField.Width,
|
||
OptionsColumn = { AllowEdit = subField.Edit, FixedWidth = true }
|
||
};
|
||
subColumn.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
|
||
subColumn.OptionsFilter.FilterPopupMode = FilterPopupMode.CheckedList;
|
||
if (!subField.Edit)
|
||
{
|
||
subColumn.AppearanceHeader.Options.UseForeColor = true;
|
||
subColumn.AppearanceHeader.ForeColor = ColorTranslator.FromHtml(HeaderColor);
|
||
}
|
||
if (subField.CanNull)
|
||
{
|
||
subColumn.AppearanceHeader.Options.UseForeColor = true;
|
||
subColumn.AppearanceHeader.ForeColor = RequiredForceColor;
|
||
}
|
||
bandedGridControlEx.SetColumnFormat(subColumn, subField);
|
||
SetDynamicBandedColumnSumming(bandedGridControlEx.BandedView, subColumn, subField, ref bandedFirstVisibleColumn, true);
|
||
dynamicBand.Columns.Add(subColumn);
|
||
bandedGridControlEx.BandedView.Columns.Add(subColumn);
|
||
}
|
||
}
|
||
|
||
bandedGridControlEx.BandedView.EndUpdate();
|
||
|
||
/* ========= 5. 构建最终数据源并绑定 ========= */
|
||
DataTable dynamicDataTable = BuildDynamicDataSource(
|
||
originalDataSource,
|
||
GroupPrimary,
|
||
GroupFieldprimary,
|
||
GroupField,
|
||
normalColumns,
|
||
sumField,
|
||
dynamicHeaders);
|
||
|
||
bandedGridControlEx.gridControl.DataSource = dynamicDataTable;
|
||
if (OnBuildGroupedColumnCallBack != null)
|
||
{
|
||
OnBuildGroupedColumnCallBack(bandedGridControlEx.BandedView, null);
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 构建多表头格式
|
||
/// </summary>
|
||
/// <param name="bandedGridControlEx"></param>
|
||
/// <param name="originalDataSource"></param>
|
||
private void BuildDynamicGroupedColumns(TreeBandedGridControlEx TreeBandedGridControlEx, DataTable originalDataSource)
|
||
{
|
||
TreeBandedGridControlEx.TreeListObj.BeginUpdate();
|
||
TreeBandedGridControlEx.TreeListObj.OptionsView.AutoWidth = false;
|
||
|
||
/* ========= 0. 取列定义 ========= */
|
||
GridColumnModel GroupPrimary = ColumnList.FirstOrDefault(o => o.IsCustomGroupPrimary);
|
||
GridColumnModel GroupFieldprimary = ColumnList.FirstOrDefault(o => o.IsCustomGroupField == 1);
|
||
List<GridColumnModel> GroupField = ColumnList.Where(o => o.IsCustomGroupField == 2 || o.IsCustomGroupField == 4).ToList(); // 4 = 特殊字段
|
||
List<GridColumnModel> sumField = ColumnList.Where(o => o.IsCustomGroupField == 3).ToList();
|
||
if (GroupPrimary == null || GroupFieldprimary == null || !GroupField.Any()) return;
|
||
|
||
/* ========= 1. 清空现有列 ========= */
|
||
TreeBandedGridControlEx.TreeListObj.Bands.Clear();
|
||
TreeBandedGridControlEx.TreeListObj.Columns.Clear();
|
||
TreeBandedGridControlEx.TreeListObj.OptionsView.ShowSummaryFooter = false;
|
||
|
||
/* ========= 2. 创建“基本信息”Band ========= */
|
||
List<GridColumnModel> normalColumns = ColumnList.Where(o => o.IsCustomGroupField == 0 || o.IsCustomGroupField == 3).ToList();
|
||
bool treeFirstVisibleColumn = true;
|
||
|
||
DevExpress.XtraTreeList.Columns.TreeListBand normalBand = new DevExpress.XtraTreeList.Columns.TreeListBand { Caption = "基本信息" };
|
||
if (this.AggregationFreeze) normalBand.Fixed = DevExpress.XtraTreeList.Columns.FixedStyle.Left;
|
||
|
||
normalBand.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
|
||
normalBand.AppearanceHeader.Options.UseTextOptions = true;
|
||
TreeBandedGridControlEx.TreeListObj.Bands.Add(normalBand);
|
||
|
||
foreach (var normalCol in normalColumns)
|
||
{
|
||
if (!originalDataSource.Columns.Contains(normalCol.FieldName)) continue;
|
||
|
||
DevExpress.XtraTreeList.Columns.TreeListColumn col = new DevExpress.XtraTreeList.Columns.TreeListColumn
|
||
{
|
||
FieldName = normalCol.FieldName,
|
||
Caption = normalCol.FieldText,
|
||
Width = normalCol.Width,
|
||
Visible = normalCol.Visible,
|
||
Tag = normalCol,
|
||
OptionsColumn = { AllowEdit = normalCol.Edit, FixedWidth = true }
|
||
};
|
||
col.OptionsFilter.AutoFilterCondition = DevExpress.XtraTreeList.Columns.AutoFilterCondition.Contains;
|
||
col.OptionsFilter.FilterPopupMode = DevExpress.XtraTreeList.FilterPopupMode.CheckedList;
|
||
if (!normalCol.Edit)
|
||
{
|
||
col.AppearanceHeader.Options.UseForeColor = true;
|
||
col.AppearanceHeader.ForeColor = ColorTranslator.FromHtml(HeaderColor);
|
||
}
|
||
if (normalCol.CanNull)
|
||
{
|
||
col.AppearanceHeader.Options.UseForeColor = true;
|
||
col.AppearanceHeader.ForeColor = RequiredForceColor;
|
||
}
|
||
|
||
col.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
|
||
col.AppearanceHeader.Options.UseTextOptions = true;
|
||
TreeBandedGridControlEx.SetColumnFormat(col, normalCol);
|
||
SetDynamicTreeColumnSumming(TreeBandedGridControlEx.TreeListObj, col, normalCol, ref treeFirstVisibleColumn);
|
||
normalBand.Columns.Add(col);
|
||
TreeBandedGridControlEx.TreeListObj.Columns.Add(col);
|
||
}
|
||
|
||
/* ========= 3. 生成动态表头列表 ========= */
|
||
var dynamicHeaders = originalDataSource.AsEnumerable()
|
||
.Select(r => r[GroupFieldprimary.FieldName])
|
||
.Where(v => v != null && v != DBNull.Value)
|
||
.Select(v => v is DateTime dt ? dt.ToString("yyyy-MM-dd") : v.ToString())
|
||
.Distinct()
|
||
.ToList();
|
||
|
||
/* ========= 4. 生成动态 Band + 子列 ========= */
|
||
foreach (string headerName in dynamicHeaders)
|
||
{
|
||
DevExpress.XtraTreeList.Columns.TreeListBand dynamicBand = new DevExpress.XtraTreeList.Columns.TreeListBand { Caption = headerName };
|
||
dynamicBand.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
|
||
dynamicBand.AppearanceHeader.Options.UseTextOptions = true;
|
||
TreeBandedGridControlEx.TreeListObj.Bands.Add(dynamicBand);
|
||
|
||
// 尝试把 headerName 解析成日期,以便下面用星期几
|
||
DateTime headerDate;
|
||
bool isDateHeader = DateTime.TryParse(headerName, out headerDate);
|
||
|
||
foreach (var subField in GroupField)
|
||
{
|
||
string dynamicFieldName = $"{headerName}_{subField.FieldName}";
|
||
|
||
/* —— 计算子列 Caption —— */
|
||
string subCaption = subField.FieldText; // 默认
|
||
if (subField.IsCustomGroupField == 4 && isDateHeader)
|
||
{
|
||
// 将星期几转成中文“日一二三四五六”,根据需要可自行改动
|
||
string[] cnWeek = { "日", "一", "二", "三", "四", "五", "六" };
|
||
subCaption = cnWeek[(int)headerDate.DayOfWeek]; // 0=Sunday
|
||
}
|
||
|
||
DevExpress.XtraTreeList.Columns.TreeListColumn subColumn = new DevExpress.XtraTreeList.Columns.TreeListColumn
|
||
{
|
||
Name = dynamicFieldName,
|
||
FieldName = dynamicFieldName,
|
||
Caption = subCaption,
|
||
Width = subField.Width,
|
||
Visible = subField.Visible,
|
||
Tag = subField,
|
||
MinWidth = subField.Width,
|
||
OptionsColumn = { AllowEdit = subField.Edit, FixedWidth = true }
|
||
};
|
||
subColumn.OptionsFilter.AutoFilterCondition = DevExpress.XtraTreeList.Columns.AutoFilterCondition.Contains;
|
||
subColumn.OptionsFilter.FilterPopupMode = DevExpress.XtraTreeList.FilterPopupMode.CheckedList;
|
||
if (!subField.Edit)
|
||
{
|
||
subColumn.AppearanceHeader.Options.UseForeColor = true;
|
||
subColumn.AppearanceHeader.ForeColor = ColorTranslator.FromHtml(HeaderColor);
|
||
}
|
||
if (subField.CanNull)
|
||
{
|
||
subColumn.AppearanceHeader.Options.UseForeColor = true;
|
||
subColumn.AppearanceHeader.ForeColor = RequiredForceColor;
|
||
}
|
||
subColumn.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
|
||
subColumn.AppearanceHeader.Options.UseTextOptions = true;
|
||
|
||
TreeBandedGridControlEx.SetColumnFormat(subColumn, subField);
|
||
SetDynamicTreeColumnSumming(TreeBandedGridControlEx.TreeListObj, subColumn, subField, ref treeFirstVisibleColumn);
|
||
dynamicBand.Columns.Add(subColumn);
|
||
TreeBandedGridControlEx.TreeListObj.Columns.Add(subColumn);
|
||
}
|
||
}
|
||
|
||
TreeBandedGridControlEx.TreeListObj.EndUpdate();
|
||
|
||
/* ========= 5. 构建最终数据源并绑定 ========= */
|
||
DataTable dynamicDataTable = BuildDynamicDataSource(
|
||
originalDataSource,
|
||
GroupPrimary,
|
||
GroupFieldprimary,
|
||
GroupField,
|
||
normalColumns,
|
||
sumField,
|
||
dynamicHeaders);
|
||
|
||
TreeBandedGridControlEx.TreeListObj.DataSource = dynamicDataTable;
|
||
if (OnBuildGroupedColumnCallBack != null)
|
||
{
|
||
OnBuildGroupedColumnCallBack(TreeBandedGridControlEx.TreeListObj, null);
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 构建数据源
|
||
/// </summary>
|
||
/// <param name="originalDataSource"></param>
|
||
/// <param name="GroupPrimary"></param>
|
||
/// <param name="GroupFieldprimary"></param>
|
||
/// <param name="GroupField"></param>
|
||
/// <param name="normalColumns"></param>
|
||
/// <param name="dynamicHeaders"></param>
|
||
/// <returns></returns>
|
||
/// <summary>
|
||
/// 把行转列、动态列拼接,并对指定列做求和
|
||
/// </summary>
|
||
/// <summary>
|
||
/// 把行转列、动态列拼接,并对指定列做求和(兼容 DateTime 作为 Header 列)
|
||
/// </summary>
|
||
private DataTable BuildDynamicDataSource(
|
||
DataTable original, // 原始数据
|
||
GridColumnModel keyCol, // 分组主键
|
||
GridColumnModel headerCol, // 动态列的“Header”列(可能是 DateTime)
|
||
List<GridColumnModel> subCols, // Header 后要展开的子列
|
||
List<GridColumnModel> normalCols, // 普通列(取首行值)
|
||
List<GridColumnModel> sumColumns, // 需要求和的列
|
||
List<string> headers) // Header 值集合(建议已格式化为 yyyy-MM-dd 等字符串)
|
||
{
|
||
// 统一把 Header 的原始值转成用于匹配/建列的键(string)
|
||
string formatKey(object v)
|
||
{
|
||
if (v == null || v == DBNull.Value) return null;
|
||
if (v is DateTime) return ((DateTime)v).ToString("yyyy-MM-dd"); // 如需其它格式,修改此处
|
||
return v.ToString();
|
||
}
|
||
string keyOf(object v) => formatKey(v) ?? string.Empty; // 避免 null 键
|
||
|
||
var dt = new DataTable();
|
||
|
||
/* ============ 1. 建列 ============ */
|
||
// 主键列
|
||
dt.Columns.Add(keyCol.FieldName, original.Columns[keyCol.FieldName].DataType);
|
||
|
||
// 辅助:原表已有列名
|
||
var exist = new HashSet<string>(original.Columns.Cast<DataColumn>().Select(c => c.ColumnName));
|
||
|
||
// 普通列:不重复、不覆盖主键
|
||
foreach (var col in normalCols)
|
||
{
|
||
if (col.FieldName == keyCol.FieldName) continue;
|
||
if (!exist.Contains(col.FieldName)) continue;
|
||
if (!dt.Columns.Contains(col.FieldName))
|
||
dt.Columns.Add(col.FieldName, original.Columns[col.FieldName].DataType);
|
||
}
|
||
|
||
// 求和列:类型沿用原列
|
||
foreach (var col in sumColumns)
|
||
{
|
||
if (!exist.Contains(col.FieldName)) continue;
|
||
if (!dt.Columns.Contains(col.FieldName))
|
||
dt.Columns.Add(col.FieldName, original.Columns[col.FieldName].DataType);
|
||
}
|
||
|
||
// 动态列:以 headers × subCols 展开;类型沿用子列类型
|
||
foreach (var h in headers)
|
||
{
|
||
foreach (var s in subCols)
|
||
{
|
||
if (!exist.Contains(s.FieldName)) continue;
|
||
string dyn = $"{h}_{s.FieldName}";
|
||
if (!dt.Columns.Contains(dyn))
|
||
dt.Columns.Add(dyn, original.Columns[s.FieldName].DataType);
|
||
}
|
||
}
|
||
|
||
/* ============ 2. 分组聚合 ============ */
|
||
foreach (var grp in original.AsEnumerable().GroupBy(r => r[keyCol.FieldName]))
|
||
{
|
||
var newRow = dt.NewRow();
|
||
var first = grp.First();
|
||
|
||
// 主键值
|
||
newRow[keyCol.FieldName] = first[keyCol.FieldName];
|
||
|
||
// 普通列:取首行
|
||
foreach (var col in normalCols)
|
||
{
|
||
if (!exist.Contains(col.FieldName)) continue;
|
||
if (!dt.Columns.Contains(col.FieldName)) continue;
|
||
newRow[col.FieldName] = first[col.FieldName];
|
||
}
|
||
|
||
// 求和列:以“当前分组中的第一个 Header 键”为准,仅汇总这一组
|
||
string firstHeader = grp.Select(r => keyOf(r[headerCol.FieldName])).FirstOrDefault();
|
||
|
||
foreach (var col in sumColumns)
|
||
{
|
||
if (!exist.Contains(col.FieldName)) continue;
|
||
if (!dt.Columns.Contains(col.FieldName)) continue;
|
||
|
||
decimal sum = 0m;
|
||
foreach (var r in grp)
|
||
{
|
||
if (keyOf(r[headerCol.FieldName]) != firstHeader) continue;
|
||
var v = r[col.FieldName];
|
||
if (v == null || v == DBNull.Value) continue;
|
||
sum += Convert.ToDecimal(v);
|
||
}
|
||
|
||
// 把 decimal 结果转换成目标列的数据类型再写入
|
||
var targetType = dt.Columns[col.FieldName].DataType;
|
||
object sumValue;
|
||
if (targetType == typeof(decimal)) sumValue = sum;
|
||
else if (targetType == typeof(int)) sumValue = Convert.ToInt32(sum);
|
||
else if (targetType == typeof(long)) sumValue = Convert.ToInt64(sum);
|
||
else if (targetType == typeof(double)) sumValue = Convert.ToDouble(sum);
|
||
else if (targetType == typeof(float)) sumValue = Convert.ToSingle(sum);
|
||
else sumValue = sum; // 兜底:直接写 decimal
|
||
|
||
newRow[col.FieldName] = sumValue;
|
||
}
|
||
|
||
// 动态列:用统一的键做命中
|
||
var lookup = grp.ToLookup(r => keyOf(r[headerCol.FieldName]));
|
||
foreach (var h in headers)
|
||
{
|
||
foreach (var s in subCols)
|
||
{
|
||
if (!exist.Contains(s.FieldName)) continue;
|
||
string dyn = $"{h}_{s.FieldName}";
|
||
if (!dt.Columns.Contains(dyn)) continue;
|
||
|
||
var hit = lookup[keyOf(h)].FirstOrDefault(); // headers 已是 string
|
||
newRow[dyn] = hit == null ? DBNull.Value : hit[s.FieldName];
|
||
}
|
||
}
|
||
|
||
dt.Rows.Add(newRow);
|
||
}
|
||
|
||
return dt;
|
||
}
|
||
#endregion
|
||
|
||
#region 绑定表格树结构弹出框
|
||
/// <summary>
|
||
/// <para>说明:值为空时弹出搜索界面</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2021-03-23 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected void OnAutoGridLookUpGotFocus(object sender, MouseEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
PopupContainerEdit btnEdit = sender as PopupContainerEdit;
|
||
PubTreeLookUp popup = (btnEdit.Properties.PopupControl.Tag) as PubTreeLookUp;
|
||
popup.popupContainerEdit = btnEdit;
|
||
if (!btnEdit.IsPopupOpen)
|
||
{
|
||
btnEdit.ShowPopup();
|
||
btnEdit.Focus();
|
||
PopupEdit = btnEdit;
|
||
//if (popup.model.FieldType == ControlType.LabCheckTreeLookText || popup.model.FieldType == ControlType.LabCheckTreeLookValue)
|
||
//{
|
||
// if (model != null && rowItem != null)
|
||
// {
|
||
// string sqlValue = model.SqlSource;
|
||
|
||
// if (this.ParentControl != null)
|
||
// sqlValue = this.ParentControl.ReplaceParentControlValue(sqlValue);
|
||
// sqlValue = sqlValue.Replace("#", "");
|
||
|
||
// sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, sqlValue);
|
||
// DataTable table = MainImpl.GetDataTableResult(sqlValue);
|
||
// edit.Properties.DataSource = table;
|
||
// foreach (DataColumn dcol in table.Columns)
|
||
// {
|
||
// int columnWidth = 0;
|
||
// if ((dcol.ColumnName.Substring(0, 1) != "_"))
|
||
// {
|
||
// if (edit.Properties.View.Columns.FirstOrDefault(x => x.FieldName == dcol.ColumnName) != null)
|
||
// {
|
||
// GridColumn gCol = edit.Properties.View.Columns[dcol.ColumnName];
|
||
// columnWidth = GraphicsText.GetTextWidth(gCol.Caption);
|
||
// gCol.Width = CalcMaxColumnWidth(table, gCol.Name);
|
||
// gCol.Width = columnWidth > gCol.Width ? columnWidth : gCol.Width;
|
||
// popWidth += gCol.Width;
|
||
// }
|
||
// }
|
||
// }
|
||
// edit.Properties.PopupFormSize = new System.Drawing.Size(popWidth, edit.Properties.PopupFormSize.Height);
|
||
// }
|
||
//}
|
||
this.RefreshPopupDataSource("", popup);
|
||
popup.TreeViewExObj.UnCheckAllNodes();
|
||
if (!string.IsNullOrWhiteSpace(btnEdit.Properties.OwnerEdit.Text))
|
||
{
|
||
GridColumnModel model = popup.model;
|
||
string[] spilts = btnEdit.Properties.OwnerEdit.Text.Trim().Replace(", ", ",").TrimEnd(',').Split(',');
|
||
for (int i = 0; i < spilts.Length; i++)
|
||
{
|
||
|
||
DataRow rowItem = rowItem = popup.TreeViewExObj.DataSource.Rows.Cast<DataRow>().FirstOrDefault(x => x[model.ValueMember] + "" == spilts[i].Trim());
|
||
if (rowItem != null)
|
||
{
|
||
string keyValue = rowItem[model.ValueMember] + "";
|
||
TreeNode[] nodes = popup.TreeViewObj.Nodes.Find(keyValue, true);
|
||
nodes[0].Checked = true;
|
||
popup.TreeViewExObj.tvMain_AfterCheck(popup.TreeViewExObj, new TreeViewEventArgs(nodes[0], TreeViewAction.ByMouse));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:鼠标弹起时刷新数据</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2021-03-23 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="KeyEventArgs"/> instance containing the event data.</param>
|
||
protected void OnAutoGridLookUpKeyUp(object sender, KeyEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
PopupContainerEdit btnEdit = sender as PopupContainerEdit;
|
||
PubTreeLookUp popup = (btnEdit.Properties.PopupControl.Tag) as PubTreeLookUp;
|
||
if (e.KeyCode == Keys.Enter)
|
||
{
|
||
btnEdit.Focus();
|
||
}
|
||
else
|
||
{
|
||
this.RefreshPopupDataSource(btnEdit.Properties.OwnerEdit.Text, popup);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:刷新树节点的数据源</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2018-03-21 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>;
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void RefreshPopupDataSource(string searchText, PubTreeLookUp popup)
|
||
{
|
||
if (string.IsNullOrEmpty(popup.SourceSQL))
|
||
{
|
||
// 本地搜索
|
||
}
|
||
else
|
||
{
|
||
// 数据库搜索
|
||
string sqlValue = string.Format("select * from ({0}) temp where {1} like '%{3}%' or {2} like '%{3}%' or dbo.P_getpy({2}) like '%{3}%'", popup.SourceSQL, popup.ValueField, popup.TextMember, searchText);
|
||
popup.DataSource = MainImpl.GetDataTableResult(sqlValue);
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-03-15 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected void OnPopupGridViewEnter(object sender, KeyEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
PubTreeLookUp popup = (PopupEdit.Properties.PopupControl.Tag) as PubTreeLookUp;
|
||
if (e.KeyCode == Keys.Enter)
|
||
{
|
||
GridColumnModel model = popup.model;
|
||
// string ids = popup.TreeViewExObj.GetCheckValues();
|
||
string ids = popup.isRootNode ? popup.TreeViewExObj.GetCheckValues(true) : popup.TreeViewExObj.GetCheckValues(false);
|
||
if (ids != null)
|
||
{
|
||
ids = ids.Replace("'", "");
|
||
if (model.FieldType == ControlType.LabTreeLookText || model.FieldType == ControlType.LabCheckTreeLookText)
|
||
{
|
||
string[] values = ids.Trim(',').Split(',');
|
||
string text = string.Empty;
|
||
foreach (string item in values)
|
||
{
|
||
DataRow rowItem = popup.TreeViewExObj.DataSource.Rows.Cast<DataRow>().FirstOrDefault(x => x[popup.ValueMember] + "" == item);
|
||
if (rowItem != null)
|
||
{
|
||
text += rowItem[popup.TextMember] + ",";
|
||
}
|
||
}
|
||
ids = text.Trim(',');
|
||
}
|
||
PopupEdit.Properties.OwnerEdit.EditValue = ids.Trim(',');
|
||
this.Focus();
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:自定义设置其弹出框宽度</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2021-03-29 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
private void OnPopupGridMouseClick(object sender, TreeNodeMouseClickEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
PubTreeLookUp popup = (PopupEdit.Properties.PopupControl.Tag) as PubTreeLookUp;
|
||
if (e.Node != null && e.Node.Bounds.Contains(e.Location))
|
||
{
|
||
if (e.Node.Nodes.Count > 0 && !popup.isRootNode)
|
||
{
|
||
return;
|
||
}
|
||
PopupEdit.Properties.OwnerEdit.EditValue = (popup.model.FieldType == ControlType.LabTreeLookText || popup.model.FieldType == ControlType.LabCheckTreeLookText) ? e.Node.Text.ToString() : e.Node.Name.ToString();
|
||
this.Focus();
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:修复筛选列是第二级目录后点击会重绘条件</para>
|
||
/// <para>创建人:唐德馨</para>
|
||
/// <para>创建日期:2021-07-08 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid columnFilterPopupChecke.</param>
|
||
|
||
public virtual void OnShowFilterPopupCheckedListBox(object sender, FilterPopupCheckedListBoxEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
GridView gridView = (GridView)sender;
|
||
string actStr = this.gridView.ActiveFilterString;//获取筛选条件
|
||
string[] actStr_list = actStr.Split(new string[] { "And" }, StringSplitOptions.None);
|
||
|
||
DataTable datatable = new DataTable();
|
||
|
||
if (actStr != "" && (!actStr_list[0].Contains(e.Column.FieldName) || (this.gridView.OptionsView.ShowAutoFilterRow && e.Column.FilterInfo.Type == ColumnFilterType.AutoFilter)))//
|
||
{
|
||
CriteriaOperator criteria_op = this.gridView.ActiveFilterCriteria;
|
||
GroupOperator group_op = new GroupOperator();
|
||
InOperator in_op = new InOperator();
|
||
if (this.gridView.ActiveFilterString != "")
|
||
{
|
||
if (!actStr_list[0].Contains(e.Column.FieldName) && this.gridView.ActiveFilterCriteria.GetType() == typeof(InOperator))
|
||
{
|
||
in_op = this.gridView.ActiveFilterCriteria as InOperator;//获取筛选规则信息
|
||
criteria_op = in_op as CriteriaOperator;
|
||
for (int i = 0; i < in_op.Operands.Count; i++)
|
||
{
|
||
if (in_op.Operands[i].ToString().Contains(e.Column.FieldName))
|
||
{
|
||
in_op.Operands.RemoveRange(i, in_op.Operands.Count - i);
|
||
break;
|
||
}
|
||
else
|
||
continue;
|
||
}
|
||
}
|
||
else if (!actStr_list[0].Contains(e.Column.FieldName) && this.gridView.ActiveFilterCriteria.GetType() == typeof(GroupOperator))
|
||
{
|
||
group_op = this.gridView.ActiveFilterCriteria as GroupOperator;//获取筛选规则信息
|
||
criteria_op = group_op as CriteriaOperator;
|
||
for (int i = 0; i < group_op.Operands.Count; i++)
|
||
{
|
||
if (group_op.Operands[i].ToString().Contains(e.Column.FieldName))
|
||
{
|
||
group_op.Operands.RemoveRange(i, group_op.Operands.Count - i);
|
||
break;
|
||
}
|
||
else
|
||
continue;
|
||
}
|
||
}
|
||
DataView filteredDataView = this.gridView.DataSource as DataView;
|
||
string RowFilter = string.Empty;
|
||
try
|
||
{
|
||
datatable = filteredDataView.Table.Select(DevExpress.Data.Filtering.CriteriaToWhereClauseHelper.GetDataSetWhere(criteria_op)).CopyToDataTable();
|
||
}
|
||
catch (Exception)
|
||
{
|
||
if (RowFilter.Split(new string[] { "And" }, StringSplitOptions.None)[0].Contains(" is null or "))
|
||
{
|
||
if (RowFilter.Contains("And"))
|
||
RowFilter = RowFilter.Substring(0, RowFilter.IndexOf(" or ")) + ")" + RowFilter.Substring(RowFilter.IndexOf(" And "), RowFilter.Length - RowFilter.IndexOf(" And "));
|
||
else if (actStr_list.Length == 1)
|
||
RowFilter = RowFilter.Substring(0, RowFilter.IndexOf(" or ")) + ")";
|
||
else if (actStr_list.Length > 1)
|
||
RowFilter = RowFilter.Substring(0, RowFilter.IndexOf(" or ")) + "))";
|
||
}
|
||
datatable = filteredDataView.Table.Select(RowFilter).CopyToDataTable();
|
||
}
|
||
//List<Object> list = datatable.AsEnumerable().Select(r => r[e.Column.FieldName]).ToList();//获取筛选后的值
|
||
List<Object> list = new List<object>();
|
||
foreach (DataRow row in datatable.Rows)
|
||
{
|
||
if (row[e.Column.FieldName].GetType() == typeof(DateTime))
|
||
list.Add(((DateTime)row[e.Column.FieldName]).ToShortDateString());
|
||
else
|
||
list.Add(row[e.Column.FieldName]);
|
||
}
|
||
CheckedListBoxItemCollection _Items = new CheckedListBoxItemCollection();
|
||
|
||
for (int i = 0; i < e.CheckedComboBox.Items.Count; i++)
|
||
{
|
||
var Item_value = e.CheckedComboBox.Items[i].Value as FilterItem;
|
||
if (Item_value.Value != null)
|
||
{
|
||
if (Item_value.Value.GetType() == typeof(DateTime) && list.Contains(((DateTime)Item_value.Value).ToShortDateString()))
|
||
_Items.Add(e.CheckedComboBox.Items[i]);
|
||
else if (list.Contains(Item_value.Value))
|
||
_Items.Add(e.CheckedComboBox.Items[i]);
|
||
}
|
||
else if (Item_value.Value == null)
|
||
{
|
||
if (list.Contains(null) || list.Contains("") || list.Contains(DBNull.Value))
|
||
_Items.Add(e.CheckedComboBox.Items[i]);
|
||
}
|
||
//if (Item_value.Value != null && Item_value.Value.GetType() == typeof(DateTime))
|
||
//{
|
||
// if (list.Contains(((DateTime)Item_value.Value).ToShortDateString()))
|
||
// {
|
||
// _Items.Add(e.CheckedComboBox.Items[i]);
|
||
// }
|
||
//}
|
||
//else if (list.Contains(Item_value.Value) && Item_value.Value != null)
|
||
//{
|
||
// _Items.Add(e.CheckedComboBox.Items[i]);
|
||
//}
|
||
//else if (list.Contains(null) && Item_value.Value == null || list.Contains("") && Item_value.Value == null)
|
||
//{
|
||
// _Items.Add(e.CheckedComboBox.Items[i]);
|
||
//}
|
||
}
|
||
e.CheckedComboBox.Items.Clear();
|
||
for (int i = 0; i < _Items.Count; i++)
|
||
{
|
||
e.CheckedComboBox.Items.Add(_Items[i]);
|
||
|
||
}
|
||
e.CheckedComboBox.HighlightedItemStyle = HighlightStyle.Skinned;
|
||
}
|
||
}
|
||
|
||
|
||
if (!SystemInfo.Instance.DisableFilteringQuantity)
|
||
{
|
||
DataTable filterTable = gridView.GetGridViewFilteredAndSortedDataToDataTable();
|
||
DataRow[] dataRowArray = filterTable.Select();
|
||
for (int i = 0; i < e.CheckedComboBox.Items.Count(); i++)
|
||
{
|
||
try
|
||
{
|
||
CheckedListBoxItem checkedListBoxItem = e.CheckedComboBox.Items[i];
|
||
if (checkedListBoxItem.Value is FilterItem)
|
||
{
|
||
FilterItem filterItem = (FilterItem)checkedListBoxItem.Value;
|
||
string text = filterItem.Text;
|
||
object value = filterItem.Value;
|
||
int count = dataRowArray.Where(n => (n[e.Column.FieldName] + "").Equals(value + "")).Count();
|
||
checkedListBoxItem.Description = $"{text} ({count})";
|
||
}
|
||
}
|
||
finally
|
||
{
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:输入文本长度限制事件</para>
|
||
/// <para>创建人:唐德馨</para>
|
||
/// <para>创建日期:2021-07-08 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid columnFilterPopupChecke.</param>
|
||
private void OnGridView_ValidateRow(object sender, ValidateRowEventArgs e)
|
||
{
|
||
GridView gridView = (GridView)sender;
|
||
DataRow row = gridView.GetDataRow(e.RowHandle);
|
||
for (int i = 0; i < gridView.Columns.Count; i++)
|
||
{
|
||
if (this.gridView.Columns[i].Tag == null) continue;
|
||
if ((this.gridView.Columns[i].Tag as GridColumnModel).LimitLength > 0)
|
||
{
|
||
int MaxInputLength = System.Text.Encoding.Default.GetBytes(row[gridView.Columns[i].FieldName].ToString()).Length;
|
||
if (MaxInputLength > (this.gridView.Columns[i].Tag as GridColumnModel).LimitLength)
|
||
{
|
||
row.SetColumnError(row.Table.Columns[gridView.Columns[i].FieldName], "当前输入文本超过设定长度!");//满足条件设置错误信息
|
||
}
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
/// <summary>
|
||
/// 操作列按钮点击事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnItemButtonEdit_ButtonClick(object sender, ButtonPressedEventArgs e)
|
||
{
|
||
EditorButton editorButton = e.Button as 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>
|
||
/// 点击Footer单元格复制信息
|
||
/// <para>创建人:tdx</para>
|
||
/// <para>创建日期:2022/9/26 </para>
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnGridView_Click(object sender, EventArgs e)
|
||
{
|
||
GridHitInfo info;
|
||
Point pt = this.gridView.GridControl.PointToClient(System.Windows.Forms.Control.MousePosition);
|
||
info = this.gridView.CalcHitInfo(pt);
|
||
if (info != null)
|
||
{
|
||
DevExpress.XtraGrid.Drawing.GridFooterCellInfoArgs footerCell = info.GetType().GetProperty("FooterCell").GetValue(info, null) as DevExpress.XtraGrid.Drawing.GridFooterCellInfoArgs;
|
||
if (footerCell != null)
|
||
{
|
||
string value = footerCell.DisplayText;
|
||
if (!string.IsNullOrWhiteSpace(value)) Clipboard.SetText(value);
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 添加右键菜单选项
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnGridView_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
|
||
{
|
||
GridHitInfo info;
|
||
Point pt = this.gridView.GridControl.PointToClient(System.Windows.Forms.Control.MousePosition);
|
||
info = this.gridView.CalcHitInfo(pt);
|
||
if (e.Menu is DevExpress.XtraGrid.Menu.GridViewFooterMenu)//如果是Footer菜单则增加复制行选项
|
||
{
|
||
DXMenuCheckItem menuItemCell = new DXMenuCheckItem();
|
||
menuItemCell.Tag = info;
|
||
menuItemCell.Caption = "复制合计";
|
||
menuItemCell.Click += new EventHandler(OnMenuItem_Click);
|
||
DXMenuCheckItem menuItemRow = new DXMenuCheckItem();
|
||
menuItemRow.Caption = "复制合计行";
|
||
menuItemRow.Tag = info;
|
||
menuItemRow.Click += new EventHandler(OnMenuItem_Click);
|
||
e.Menu.Items.AddRange(new DXMenuCheckItem[] { menuItemCell, menuItemRow });
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 合计行数据复制
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
DXMenuCheckItem menuItemCell = (DXMenuCheckItem)sender;
|
||
if (menuItemCell.Caption.Equals("复制合计行"))
|
||
{
|
||
string copyFooterRowStr = string.Empty;
|
||
foreach (GridColumn col in this.gridView.VisibleColumns)
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(copyFooterRowStr) && !string.IsNullOrWhiteSpace(col.SummaryText))
|
||
{
|
||
copyFooterRowStr += string.Format("\t{0}", col.SummaryText);
|
||
}
|
||
else if (string.IsNullOrWhiteSpace(copyFooterRowStr) && !string.IsNullOrWhiteSpace(col.SummaryText))
|
||
{
|
||
copyFooterRowStr += col.SummaryText;
|
||
}
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(copyFooterRowStr)) Clipboard.SetText(copyFooterRowStr);
|
||
}
|
||
else
|
||
{
|
||
GridHitInfo info = menuItemCell.Tag as GridHitInfo;
|
||
if (info != null)
|
||
{
|
||
DevExpress.XtraGrid.Drawing.GridFooterCellInfoArgs footerCell = info.GetType().GetProperty("FooterCell").GetValue(info, null) as DevExpress.XtraGrid.Drawing.GridFooterCellInfoArgs;
|
||
if (footerCell != null)
|
||
{
|
||
string value = footerCell.DisplayText;
|
||
if (!string.IsNullOrWhiteSpace(value)) Clipboard.SetText(value);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageUtil.Show(ex.Message);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:离开行事件,记录上次选中行</para>
|
||
/// <para>创建人:唐德馨/para>
|
||
/// <para>创建日期: </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="CellMergeEventArgs"/> instance containing the event data.</param>
|
||
private void OnGridView_BeforeLeaveRow(object sender, RowAllowEventArgs e)
|
||
{
|
||
this.LastFocusedRowHandle = e.RowHandle;
|
||
}
|
||
/// <summary>
|
||
/// 判断输入的字符串是否可以转换成数值类型
|
||
/// </summary>
|
||
/// <param name="str"></param>
|
||
/// <returns></returns>
|
||
public static bool IsNumberic(string str)
|
||
{
|
||
double vsNum;
|
||
bool isNum;
|
||
isNum = double.TryParse(str, System.Globalization.NumberStyles.Float,
|
||
System.Globalization.NumberFormatInfo.InvariantInfo, out vsNum);
|
||
return isNum;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 隐藏自动搜索框的过滤面板
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnCustomDrawFilterPanel(object sender, CustomDrawObjectEventArgs e)
|
||
{
|
||
GridFilterPanelInfoArgs info = e.Info as DevExpress.XtraGrid.Drawing.GridFilterPanelInfoArgs;
|
||
info.ShowCloseButton = false;
|
||
info.ShowCustomizeButton = false;
|
||
info.ShowActiveButton = false;
|
||
e.Handled = true;
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:检查可用条件</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-09 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="cond">The cond.</param>
|
||
/// <param name="dataRow">The data row.</param>
|
||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
||
private bool ValidateCond(string cond, DataRow dataRow)
|
||
{
|
||
bool result = false;
|
||
cond = ReplaceHelper.ReplaceRowParam(dataRow, cond);
|
||
if (cond.StartsWith("@") || cond.StartsWith("!"))
|
||
{
|
||
result = "1".Equals(BaseImpl.GetDefaultValue(cond));
|
||
}
|
||
else if (dataRow == null)
|
||
{
|
||
result = ReplaceHelper.EvalCond(cond);
|
||
}
|
||
else
|
||
{
|
||
result = ReplaceHelper.ReplaceRowParamCond(dataRow, cond);
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// 条码文本改变为code128B
|
||
/// </summary>
|
||
/// <param name="barcode"></param>
|
||
/// <returns></returns>
|
||
public string ExCode128B(string barcode)
|
||
{
|
||
string result = "";
|
||
int checksum = 104;
|
||
int j = 1;
|
||
for (int ii = 0; ii < barcode.Length; ii++)
|
||
{
|
||
if (barcode[ii] >= 32)
|
||
{
|
||
checksum += (barcode[ii] - 32) * (ii + 1);
|
||
}
|
||
else
|
||
{
|
||
checksum += (barcode[ii] + 64) * (ii + 1);
|
||
}
|
||
}
|
||
checksum = checksum % 103;
|
||
if (checksum < 95)
|
||
{
|
||
checksum += 32;
|
||
}
|
||
else
|
||
{
|
||
checksum += 100;
|
||
}
|
||
result = Convert.ToChar(204) + barcode.ToString() + Convert.ToChar(checksum) + Convert.ToChar(206);
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// 格式化条码文本
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnTextEdit_FormatEditValue(object sender, ConvertEditValueEventArgs e)
|
||
{
|
||
RepositoryItemPictureEdit ItemPictureEdit = sender as RepositoryItemPictureEdit;
|
||
//ItemPictureEdit.NullText = " ";
|
||
if (ItemPictureEdit != null && !string.IsNullOrWhiteSpace(e.Value + ""))
|
||
{
|
||
BarcodeSettings settings = new BarcodeSettings();
|
||
settings.X = 0.6f;//设置黑白条宽度
|
||
settings.ImageHeight = 40;//设置生成的条码图片高度
|
||
settings.ImageWidth = 100;//设置生成的条码图片宽度
|
||
settings.Type = BarCodeType.Code128;
|
||
settings.Data = e.Value + "";//设置条码数据
|
||
settings.ShowTextOnBottom = true;//设置数据文本显示在条码底部*/
|
||
settings.ShowText = true;//设置数据文本显示
|
||
BarCodeGenerator bargenerator = new BarCodeGenerator(settings);
|
||
Image barcodeimage = bargenerator.GenerateImage();
|
||
e.Value = barcodeimage;
|
||
}
|
||
// e.Value = e.Value + "";
|
||
e.Handled = true;
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:刷新数据源</para>
|
||
/// <para>创建人:曹屹峰</para>
|
||
/// <para>创建日期:2023-9-30 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="UpdateColumnRefresh">判断是否只刷新UpdateColumn中配置的列的数据源</param>
|
||
public void RefreshDataSource(bool UpdateColumnRefresh = false)
|
||
{
|
||
this.mLoading = false;
|
||
mControlSourceDic.Clear();
|
||
ResetExtendedReturnState();
|
||
SetColumnsSource(UpdateColumnRefresh);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 触发 重复验证列 的验证
|
||
/// </summary>
|
||
public bool VerifyDuplicateColumns()
|
||
{
|
||
|
||
DataTable dt = this.gridControl.DataSource as DataTable;
|
||
// 使用HashSet来存储每一行指定列的值的组合
|
||
HashSet<string> uniqueRows = new HashSet<string>();
|
||
foreach (DataRow row in dt.Rows)
|
||
{
|
||
// 将指定列的值组合成一个字符串
|
||
string combinedRow = string.Join("-", RepeatedVerificationNames.Select(col => row[col].ToString()).ToArray());
|
||
// 如果HashSet中已经存在这个组合的字符串,说明有重复行
|
||
if (uniqueRows.Contains(combinedRow))
|
||
{
|
||
foreach (string item in RepeatedVerificationNames)
|
||
{
|
||
row.SetColumnError(row.Table.Columns[item], "数据重复");//满足条件设置错误信息
|
||
}
|
||
|
||
return true;// 发现重复行,直接返回true
|
||
}
|
||
else
|
||
{
|
||
uniqueRows.Add(combinedRow); // 没有重复,则添加到HashSet中
|
||
}
|
||
}
|
||
// 遍历完毕,没有重复行
|
||
return false;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 全部列设置为禁编状态
|
||
/// </summary>
|
||
public virtual void SetReadOnlyAllColumn()
|
||
{
|
||
this.gridView.BeginUpdate();
|
||
GridColumnCollection gc = this.GridView.Columns;
|
||
foreach (GridColumn item in gc)
|
||
{
|
||
GridColumnModel model = item.Tag as GridColumnModel;
|
||
if (model == null) continue;
|
||
|
||
item.OptionsColumn.AllowEdit = false;
|
||
item.OptionsColumn.ReadOnly = !item.OptionsColumn.AllowEdit;
|
||
|
||
if (!item.OptionsColumn.AllowEdit)
|
||
{
|
||
item.AppearanceHeader.Options.UseForeColor = true;
|
||
item.AppearanceHeader.ForeColor = ColorTranslator.FromHtml(HeaderColor);
|
||
}
|
||
else
|
||
{
|
||
item.AppearanceHeader.Options.UseForeColor = true;
|
||
item.AppearanceHeader.ForeColor = ColorTranslator.FromHtml("#00000");
|
||
}
|
||
|
||
if (model.FieldType == ControlType.LabMemoEdit) item.OptionsColumn.AllowEdit = true;
|
||
}
|
||
this.gridView.EndUpdate();
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 重新设置表格的字段属性
|
||
/// </summary>
|
||
/// <param name="modifyFields">修改字段</param>
|
||
/// <param name="requiredFields">必填字段</param>
|
||
public virtual void SetFieldStatus(string modifyFields, string requiredFields, DataTable AuthorityTable = null)
|
||
{
|
||
this.ModifyFields = modifyFields;
|
||
this.RequiredFields = requiredFields;
|
||
GridColumnCollection gc = this.GridView.Columns;
|
||
bool Modify = false;
|
||
bool Required = false;
|
||
Color RequiredForceColor = string.IsNullOrEmpty(SystemInfo.Instance.ControlRequiredColor) ? Color.Blue : ColorTranslator.FromHtml(SystemInfo.Instance.ControlRequiredColor);
|
||
//修改字段
|
||
if (!string.IsNullOrEmpty(modifyFields) && modifyFields != "-1")
|
||
{
|
||
modifyFields = modifyFields + ",";
|
||
Modify = true;
|
||
modifyFields = modifyFields.ToLower();
|
||
}
|
||
if (!string.IsNullOrEmpty(requiredFields) && requiredFields != "-1")
|
||
{
|
||
Required = true;
|
||
requiredFields = requiredFields + ",";
|
||
requiredFields = requiredFields.ToLower();
|
||
}
|
||
this.gridView.BeginUpdate();
|
||
foreach (GridColumn item in gc)
|
||
{
|
||
GridColumnModel model = item.Tag as GridColumnModel;
|
||
|
||
//修改
|
||
if (Modify && modifyFields.Split(',').Contains(item.FieldName.ToLower()))
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(model.PrivilegeOper) && AuthorityTable != null)
|
||
{
|
||
List<int> targetPrivTypeIds = new List<int>();
|
||
foreach (string permission in model.PrivilegeOper.Split(','))
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(permission)) targetPrivTypeIds.Add(int.Parse(permission));
|
||
}
|
||
//获取权限对应的人员名称
|
||
string userString = string.Join(",", AuthorityTable.AsEnumerable()
|
||
.Where(row => targetPrivTypeIds.Contains(row.Field<int>("privTypeId")))
|
||
.Select(row => row.Field<string>("userList"))
|
||
.Where(value => value != null)
|
||
.ToList());
|
||
if (!userString.Split(',').Contains(ERPInfo.Instance.UserName)) continue;
|
||
|
||
}
|
||
|
||
|
||
item.OptionsColumn.AllowEdit = modifyFields.IndexOf(item.FieldName + ",", StringComparison.OrdinalIgnoreCase) != -1;
|
||
item.OptionsColumn.ReadOnly = !item.OptionsColumn.AllowEdit;
|
||
|
||
if (!item.OptionsColumn.AllowEdit)
|
||
{
|
||
item.AppearanceHeader.Options.UseForeColor = true;
|
||
item.AppearanceHeader.ForeColor = ColorTranslator.FromHtml(HeaderColor);
|
||
}
|
||
else
|
||
{
|
||
item.AppearanceHeader.Options.UseForeColor = true;
|
||
item.AppearanceHeader.ForeColor = ColorTranslator.FromHtml("#00000");
|
||
}
|
||
|
||
if (model.FieldType == ControlType.LabMemoEdit) item.OptionsColumn.AllowEdit = true;
|
||
}
|
||
|
||
//必填
|
||
if (Required && requiredFields.Split(',').Contains(item.FieldName.ToLower()))
|
||
{
|
||
item.AppearanceHeader.Options.UseForeColor = true;
|
||
item.AppearanceHeader.ForeColor = RequiredForceColor;
|
||
}
|
||
|
||
}
|
||
this.gridView.EndUpdate();
|
||
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 设置动态列显示和隐藏
|
||
/// </summary>
|
||
/// <param name="ColumnName"></param>
|
||
public void SetDisplayColumns(string ColumnName)
|
||
{
|
||
this.gridView.BeginUpdate();
|
||
string[] ColumnNames = ColumnName.Split(',');
|
||
int i = 0;
|
||
foreach (GridColumn item in gridView.Columns)
|
||
{
|
||
GridColumnModel model = item.Tag as GridColumnModel;
|
||
item.VisibleIndex = i;
|
||
if (model != null && model.isDynamic)
|
||
{
|
||
item.Visible = ColumnNames.Contains(model.FieldName) ? true : false;
|
||
}
|
||
i++;
|
||
//if (item.Visible)
|
||
//{
|
||
// item.VisibleIndex = i;
|
||
// i++;
|
||
//}
|
||
}
|
||
this.gridView.EndUpdate();
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 动态修改列名
|
||
/// </summary>
|
||
public void SetColumnName(DataRow dataRow)
|
||
{
|
||
this.gridView.BeginUpdate();
|
||
|
||
foreach (GridColumn item in gridView.Columns)
|
||
{
|
||
GridColumnModel model = item.Tag as GridColumnModel;
|
||
if (dataRow.Table.Columns.Contains(model.FieldName))
|
||
{
|
||
item.Caption = dataRow[model.FieldName] + "";
|
||
item.Visible = !string.IsNullOrWhiteSpace(item.Caption);
|
||
}
|
||
}
|
||
this.gridView.EndUpdate();
|
||
//this.gridView.RefreshData();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 表格有复选框的情况下,勾选的行在筛选后默认显示
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void GridView_CustomRowFilter(object sender, RowFilterEventArgs e)
|
||
{
|
||
if (SystemInfo.Instance.DisplayCheckboxSelection && !string.IsNullOrWhiteSpace(this.MultiplePrimary) && gridView.OptionsSelection.MultiSelect == true && gridView.OptionsSelection.MultiSelectMode == GridMultiSelectMode.CheckBoxRowSelect && gridView.OptionsSelection.EnableAppearanceFocusedCell == false)
|
||
{
|
||
DataRow dataRow = this.gridView.GetDataRow(e.ListSourceRow);
|
||
if (dataRow != null && dataRow.Table.Columns.Contains(this.MultiplePrimary) && SelectedDataSource.Contains(dataRow[this.MultiplePrimary] + ""))
|
||
{
|
||
e.Handled = true;
|
||
e.Visible = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 自定义表格数据
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnGridViewCustomUnboundColumnData(object sender, CustomColumnDataEventArgs e)
|
||
{
|
||
if (e.Column.Tag != null && e.Column.Tag is GridColumnModel columnModel)
|
||
{
|
||
if (columnModel.FieldType == ControlType.LabPicUrl && e.IsGetData)
|
||
{
|
||
string imageUrl = e.Row != null && e.Row is DataRowView dataRowView && dataRowView.Row.Table.Columns.Contains(columnModel.FieldName) ? dataRowView.Row[columnModel.FieldName] + "" : "";
|
||
if (!string.IsNullOrEmpty(imageUrl))
|
||
{
|
||
if (!imageUrl.StartsWith("http"))
|
||
{
|
||
string oaUrl = SystemInfo.Instance.OAUrl.EndsWith("/") ? SystemInfo.Instance.OAUrl : $"{SystemInfo.Instance.OAUrl}/";
|
||
imageUrl = $"{oaUrl}{imageUrl}";
|
||
}
|
||
if (columnModel.LabPicUrlImages == null)
|
||
{
|
||
columnModel.LabPicUrlImages = new Hashtable();
|
||
}
|
||
// 检查缓存中是否已存在该图片
|
||
if (!columnModel.LabPicUrlImages.ContainsKey(imageUrl))
|
||
{
|
||
Task.Factory.StartNew(() =>
|
||
{
|
||
try
|
||
{
|
||
using (WebClient webClient = new WebClient())
|
||
{
|
||
byte[] bytes = webClient.DownloadData(imageUrl);
|
||
using (MemoryStream memoryStream = new MemoryStream(bytes))
|
||
{
|
||
Bitmap bitmap = new Bitmap(memoryStream);
|
||
int height = columnModel.LabPicUrlHeight <= 18 ? 30 : columnModel.LabPicUrlHeight;
|
||
int newWidth = (int)((decimal)height / (decimal)bitmap.Height * (decimal)bitmap.Width);
|
||
Bitmap zoomBitmap = new Bitmap(bitmap, new Size(newWidth, height));
|
||
columnModel.LabPicUrlImages[imageUrl] = new KeyValuePair<Image, Image>(bitmap, zoomBitmap);
|
||
BeginInvoke(new Action(() =>
|
||
{
|
||
gridView.BeginUpdate();
|
||
e.Value = zoomBitmap;
|
||
gridView.EndUpdate();
|
||
}));
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Console.WriteLine(ex.Message);
|
||
}
|
||
});
|
||
}
|
||
else
|
||
{
|
||
gridView.BeginUpdate();
|
||
e.Value = ((KeyValuePair<Image, Image>)columnModel.LabPicUrlImages[imageUrl]).Value;
|
||
gridView.EndUpdate();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 点击单元格显示图片控件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnShowImageDoubleClick(object sender, EventArgs e)
|
||
{
|
||
GridView gridView = sender as GridView;
|
||
Point point = gridView.GridControl.PointToClient(MousePosition);
|
||
GridHitInfo gridHitInfo = gridView.CalcHitInfo(point);
|
||
if (gridHitInfo == null || !gridHitInfo.InRowCell || gridHitInfo.Column == null)
|
||
{
|
||
return;
|
||
}
|
||
GridColumn gridColumn = gridHitInfo.Column;
|
||
if (gridColumn.Tag == null || !(gridColumn.Tag is GridColumnModel columnModel))
|
||
{
|
||
return;
|
||
}
|
||
if (columnModel.FieldType == ControlType.LabPicUrl)
|
||
{
|
||
DataRow dataRow = gridView.GetDataRow(gridHitInfo.RowHandle);
|
||
string imageUrl = dataRow.Table.Columns.Contains(columnModel.FieldName) ? dataRow[columnModel.FieldName] + "" : "";
|
||
if (string.IsNullOrEmpty(imageUrl))
|
||
{
|
||
return;
|
||
}
|
||
if (!imageUrl.StartsWith("http"))
|
||
{
|
||
string oaUrl = SystemInfo.Instance.OAUrl.EndsWith("/") ? SystemInfo.Instance.OAUrl : $"{SystemInfo.Instance.OAUrl}/";
|
||
imageUrl = $"{oaUrl}{imageUrl}";
|
||
}
|
||
if (columnModel.LabPicUrlImages.ContainsKey(imageUrl))
|
||
{
|
||
using (FrmPicture frmPicture = new FrmPicture())
|
||
{
|
||
frmPicture.PicUrlColumns = gridView.Columns.Where(n => n.Tag != null && n.Tag is GridColumnModel model && model.FieldType == ControlType.LabPicUrl).ToList();
|
||
frmPicture.FocusedRow = gridView.GetFocusedDataRow();
|
||
frmPicture.FocusedColumn = gridView.FocusedColumn;
|
||
Image image = ((KeyValuePair<Image, Image>)columnModel.LabPicUrlImages[imageUrl]).Key;
|
||
frmPicture.Text = "预览";
|
||
frmPicture.Picture = image;
|
||
frmPicture.WindowState = FormWindowState.Maximized;
|
||
frmPicture.StartPosition = FormStartPosition.CenterScreen;
|
||
frmPicture.ShowDialog();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 清空url图片列缓存
|
||
/// </summary>
|
||
private void ClearImage()
|
||
{
|
||
GridColumnCollection gridColumns = this.GridView.Columns;
|
||
|
||
foreach (GridColumn col in gridColumns)
|
||
{
|
||
GridColumnModel model = col.Tag as GridColumnModel;
|
||
if (model != null && model.FieldType == ControlType.LabPicUrl)
|
||
{
|
||
model.LabPicUrlImages = new Hashtable();
|
||
}
|
||
}
|
||
}
|
||
|
||
#region 当前表格的拖拽方法
|
||
/// <summary>
|
||
/// <para>说明:自身表格的拖拽类</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2017-09-05 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
public class DragForm : DevExpress.Utils.Win.TopFormBase
|
||
{
|
||
Bitmap m_buff;
|
||
Graphics m_buffG;
|
||
/// <summary>
|
||
/// 拖拽方法
|
||
/// </summary>
|
||
/// <param name="_size"></param>
|
||
public DragForm(Rectangle _bound)
|
||
{
|
||
|
||
this.Text = "";
|
||
this.FormBorderStyle = FormBorderStyle.None;
|
||
this.ControlBox = false;
|
||
this.Size = _bound.Size;
|
||
this.ShowInTaskbar = false;
|
||
this.StartPosition = FormStartPosition.Manual;
|
||
|
||
this.Opacity = 0.0d; //TopFormBase已经有默认值了;
|
||
|
||
this.BackColor = ColorTranslator.FromHtml("#0078D7");
|
||
this.Location = _bound.Location;
|
||
|
||
}
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="e"></param>
|
||
protected override void OnPaint(PaintEventArgs e)
|
||
{
|
||
base.OnPaint(e);
|
||
// e.Graphics.DrawImage(m_buff, 0, 0);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:判断是否需要绑定拖拽</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2020-05-22 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
public void InitializedragState(string SortColumnName)
|
||
{
|
||
try
|
||
{
|
||
if (string.IsNullOrWhiteSpace(SortColumnName)) return;
|
||
//判断是否可拖拽
|
||
if (this.gridView.Columns.Where(n => n.FieldName.Equals(SortColumnName)).Count() > 0)
|
||
{
|
||
this.DetailOrderField = SortColumnName;
|
||
this.GridView.MouseDown += new MouseEventHandler(OnGridMouseDown);
|
||
this.GridView.MouseMove += new MouseEventHandler(OnGridMouseMove);
|
||
this.GridView.MouseUp += new MouseEventHandler(OnGridMouseUp);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:拖拽鼠标按下事件</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2020-05-22 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void OnGridMouseDown(object sender, MouseEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (e.Button == MouseButtons.Left)
|
||
{
|
||
isSortDrag = false;
|
||
var _hit = this.GridView.CalcHitInfo(e.Location);
|
||
if (_hit.RowHandle >= 0)
|
||
{
|
||
dragRowsIndex = this.GridView.GetSelectedRows();
|
||
|
||
m_dragHandle = _hit.RowHandle;
|
||
m_mouseDownLocation = e.Location;
|
||
}
|
||
else
|
||
{
|
||
m_dragHandle = -1;
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// 拖拽鼠标移动事件
|
||
/// </summary>
|
||
/// <param name="ev"></param>
|
||
private void OnGridMouseMove(object sender, MouseEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (e.Button == MouseButtons.Left && m_dragHandle >= 0)
|
||
{
|
||
isSortDrag = true;
|
||
if (m_dragRowShadow == null)
|
||
{
|
||
double _x2 = Math.Pow((e.Location.X - m_mouseDownLocation.X), 2);
|
||
double _y2 = Math.Pow((e.Location.Y - m_mouseDownLocation.Y), 2);
|
||
double _d2 = Math.Sqrt(_x2 + _y2);
|
||
if (_d2 > 3)
|
||
{
|
||
//执行拖拽;
|
||
this.BeginDrag(m_dragHandle);
|
||
//var _info = (DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo)gv22.GetViewInfo();
|
||
//_info.GetGridRowInfo(0).CalcRectangle
|
||
}
|
||
}
|
||
else
|
||
{
|
||
m_dragRowShadow.Location = new Point(m_dragRowShadow.Location.X, this.PointToScreen(e.Location).Y);
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 拖拽鼠标放开事件
|
||
/// </summary>
|
||
/// <param name="ev"></param>
|
||
private void OnGridMouseUp(object sender, MouseEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
int startIndex = this.m_dragHandle;
|
||
int endIndex = -1;
|
||
int[] selectSourceIndex = null;
|
||
if (m_dragRowShadow != null)
|
||
{
|
||
var _hit = this.GridView.CalcHitInfo(e.Location);
|
||
|
||
this.EndDrag(_hit.RowHandle, out selectSourceIndex);
|
||
endIndex = _hit.RowHandle;
|
||
}
|
||
if (!string.IsNullOrEmpty(DetailOrderField) && isSortDrag)
|
||
{
|
||
|
||
int sourceStartIndex = startIndex > 0 ? this.GridView.GetDataSourceRowIndex(startIndex) : startIndex;
|
||
int sourceEndIndex = endIndex > 0 ? this.GridView.GetDataSourceRowIndex(endIndex) : endIndex;
|
||
this.gridControl.DataSourceTable().OrderBy(this.DetailOrderField, sourceStartIndex, sourceEndIndex);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// 绑定拖拽
|
||
/// </summary>
|
||
/// <param name="_handle"></param>
|
||
private void BeginDrag(int _handle)
|
||
{
|
||
var _info = (DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo)this.GridView.GetViewInfo();
|
||
//_info.GetGridRowInfo(0).CalcRectangle
|
||
|
||
Rectangle _bound = _info.GetGridRowInfo(_handle).Bounds;
|
||
_bound.Location = this.PointToScreen(_bound.Location);
|
||
m_dragRowShadow = new DragForm(_bound);
|
||
m_dragRowShadow.Show();
|
||
}
|
||
/// <summary>
|
||
/// 停止拖拽
|
||
/// </summary>
|
||
/// <param name="_handle"></param>
|
||
private void EndDrag(int _handle, out int[] selectSourceIndex)
|
||
{
|
||
selectSourceIndex = null;
|
||
if (m_dragRowShadow != null)
|
||
{
|
||
m_dragRowShadow.Close();
|
||
m_dragRowShadow.Dispose();
|
||
m_dragRowShadow = null;
|
||
if (dragRowsIndex.Length > 1)
|
||
{
|
||
DataTable sourceTable = this.gridControl.DataSourceTable();
|
||
int _rowIndex = this.GridView.GetDataSourceRowIndex(_handle);
|
||
int[] selectRowsIndex = dragRowsIndex;
|
||
selectSourceIndex = new int[selectRowsIndex.Length];
|
||
List<DataRow> selectRows = new List<DataRow>();
|
||
List<DataRow> newRowSelectRows = new List<DataRow>();
|
||
|
||
for (int i = 0; i < selectRowsIndex.Length; i++)
|
||
{
|
||
int sourceIndex = this.GridView.GetDataSourceRowIndex(selectRowsIndex[i]);
|
||
selectSourceIndex[i] = sourceIndex;
|
||
selectRows.Add(sourceTable.Rows[sourceIndex]);
|
||
}
|
||
this.gridControl.BeginUpdate();
|
||
foreach (DataRow row in selectRows)
|
||
{
|
||
DataRow newRow = sourceTable.NewRow();
|
||
newRow.ItemArray = row.ItemArray;
|
||
newRowSelectRows.Add(newRow);
|
||
}
|
||
//移除目标行;
|
||
int IntermediateRow = 0;
|
||
for (int i = selectSourceIndex.Length - 1; i >= 0; i--)
|
||
{
|
||
((DataTable)this.gridControl.DataSource).Rows.RemoveAt(selectSourceIndex[i]);
|
||
if (_handle > selectSourceIndex[i]) IntermediateRow++;//拖动行如果在目标行上面,拖动行在删除后,插入行要跟着删一行
|
||
|
||
}
|
||
_handle = _handle - IntermediateRow;
|
||
if (_handle >= 0)
|
||
{
|
||
foreach (DataRow row in newRowSelectRows)
|
||
{
|
||
sourceTable.Rows.InsertAt(row, _handle);
|
||
//row.AcceptChanges();
|
||
//row.SetModified();
|
||
_handle += 1;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
foreach (DataRow row in newRowSelectRows)
|
||
{
|
||
sourceTable.Rows.Add(row);
|
||
//row.AcceptChanges();
|
||
//row.SetModified();
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
int _rowIndex = this.GridView.GetDataSourceRowIndex(m_dragHandle);
|
||
DataRow _row = ((DataTable)this.gridControl.DataSource).Rows[_rowIndex];
|
||
DataRow insertRow = ((DataTable)this.gridControl.DataSource).NewRow();
|
||
insertRow.ItemArray = _row.ItemArray;
|
||
this.gridControl.BeginUpdate();
|
||
((DataTable)this.gridControl.DataSource).Rows.RemoveAt(_rowIndex);
|
||
if (_handle > m_dragHandle) _handle = _handle - 1;//拖动行如果在目标行上面,拖动行在删除后,插入行要跟着删一行
|
||
if (_handle >= 0)
|
||
{
|
||
//插入指定位置;
|
||
//((DataTable)this.gridControl.DataSource).Rows.InsertAt(insertRow, _handle);
|
||
//this.GridView.FocusedRowHandle = _handle;
|
||
DataTable screenTable = this.GridView.GetGridViewFilteredAndSortedDataToDataTable();
|
||
DataTable AllTable = this.gridControl.DataSourceTable();
|
||
//行数不同,为筛选状态。传入行的行号要设置为数据源中的行号
|
||
if (screenTable.Rows.Count != AllTable.Rows.Count)
|
||
{
|
||
DataRow dataRow = screenTable.Rows[_handle];
|
||
IEqualityComparer<DataRow> comparer = DataRowComparer.Default;
|
||
DataRow dr = AllTable.Rows.Cast<DataRow>().Where(x => comparer.Equals(x, dataRow)).ToArray()[0];
|
||
int index = AllTable.Rows.IndexOf(dr);
|
||
((DataTable)this.gridControl.DataSource).Rows.InsertAt(insertRow, index);
|
||
this.GridView.FocusedRowHandle = _handle;
|
||
}
|
||
else
|
||
{
|
||
//插入指定位置;
|
||
((DataTable)this.gridControl.DataSource).Rows.InsertAt(insertRow, _handle);
|
||
this.GridView.FocusedRowHandle = _handle;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//添加;
|
||
((DataTable)this.gridControl.DataSource).Rows.Add(insertRow);
|
||
this.GridView.FocusedRowHandle = this.GridView.RowCount - 1;
|
||
}
|
||
//insertRow.AcceptChanges();
|
||
//insertRow.SetModified();
|
||
}
|
||
this.gridControl.EndUpdate();
|
||
this.GridView.ClearSelection();
|
||
}
|
||
}
|
||
private int GetDragEndRowIndex(DataTable sourceTab, int dragEndRowIndex, List<DataRow> selectRows, out bool isContain)
|
||
{
|
||
int returnIndex = 0;
|
||
isContain = false;
|
||
DataRow dragEndRow = sourceTab.Rows[dragEndRowIndex];
|
||
if (selectRows.Contains(dragEndRow))
|
||
{
|
||
isContain = true;
|
||
dragEndRowIndex = dragEndRowIndex - 1;
|
||
if (dragEndRowIndex >= 0)
|
||
{
|
||
dragEndRow = sourceTab.Rows[dragEndRowIndex];
|
||
if (selectRows.Contains(dragEndRow))
|
||
{
|
||
bool iscontain = false;
|
||
returnIndex = GetDragEndRowIndex(sourceTab, dragEndRowIndex, selectRows, out iscontain);
|
||
}
|
||
else
|
||
{
|
||
returnIndex = dragEndRowIndex;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
returnIndex = -1;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
returnIndex = dragEndRowIndex;
|
||
}
|
||
return returnIndex;
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 新建汇总
|
||
/// </summary>
|
||
/// <param name="dataRow"></param>
|
||
public void AddHeadquarters(DataRow dataRow = null)
|
||
{
|
||
try
|
||
{
|
||
this.gridControl.BeginUpdate();
|
||
this.gridView.CellValueChanged -= onCellValueChanged;//生成计划颜色判断事件
|
||
foreach (GridColumn gridColumn in this.gridView.Columns)
|
||
{
|
||
|
||
if (gridColumn.Summary.ActiveCount > 0)
|
||
{
|
||
if (gridColumn.Summary.ActiveCount == 1 && dataRow == null)
|
||
{
|
||
jhrowitem = null;
|
||
continue;
|
||
}
|
||
GridColumnSummaryItem sumItem = new GridColumnSummaryItem();
|
||
if (gridColumn.Summary.ActiveCount == 1)
|
||
{
|
||
sumItem = gridColumn.Summary[0];
|
||
}
|
||
else
|
||
{
|
||
sumItem = gridColumn.Summary[1];
|
||
}
|
||
//清空所有汇总
|
||
gridColumn.Summary.Clear();
|
||
//新建汇总
|
||
if (dataRow != null)
|
||
{
|
||
GridColumnSummaryItem sumItemNew = new GridColumnSummaryItem();
|
||
sumItemNew.SummaryType = DevExpress.Data.SummaryItemType.Max;
|
||
//传进来的行有值就以插入的为准,否则为空
|
||
sumItemNew.DisplayFormat = dataRow.Table.Columns.Contains(gridColumn.FieldName) ? dataRow[gridColumn.FieldName] + "" : " ";
|
||
//按顺序添加汇总
|
||
gridColumn.Summary.Add(sumItemNew);
|
||
}
|
||
gridColumn.Summary.Add(sumItem);
|
||
}
|
||
}
|
||
jhrowitem = dataRow;
|
||
if (jhrowitem != null)
|
||
{
|
||
this.gridView.CellValueChanged += onCellValueChanged;//生成计划颜色判断事件
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
this.gridControl.EndUpdate();
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// 值改变事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void onCellValueChanged(object sender, CellValueChangedEventArgs e)
|
||
{
|
||
// 只关心日期列;否则就直接 return
|
||
if (!DateTime.TryParse(e.Column.FieldName, out _))
|
||
return;
|
||
|
||
// 更新标题颜色(只花几毫秒)
|
||
RefreshHeaderColor();
|
||
// ---------- ① 重新计算本行合计 ----------
|
||
decimal rowSum = 0m;
|
||
foreach (GridColumn col in gridView.Columns)
|
||
{
|
||
// 只累加日期列
|
||
if (!DateTime.TryParse(col.FieldName, out _)) continue;
|
||
|
||
object valObj = gridView.GetRowCellValue(e.RowHandle, col);
|
||
if (valObj != DBNull.Value &&
|
||
decimal.TryParse(Convert.ToString(valObj), out decimal amt))
|
||
{
|
||
rowSum += amt;
|
||
}
|
||
}
|
||
|
||
// 把合计写入 “heji” 列(如不存在则自动忽略)
|
||
if (gridView.Columns.ColumnByFieldName("workingsum") != null)
|
||
{
|
||
gridView.SetRowCellValue(e.RowHandle, "workingsum", rowSum);
|
||
}
|
||
|
||
// ---------- ② 更新列标题颜色 ----------
|
||
RefreshHeaderColor(); // 若你需要参数,按之前定义调整即可
|
||
}
|
||
|
||
/// <summary>
|
||
/// 计划颜色变更操作:
|
||
/// 只要【列合计 Sum】与计划值不相等,即把整列背景改为浅黄
|
||
/// </summary>
|
||
/// <summary>根据“列 Sum 与计划值是否相等”刷新列标题字体颜色</summary>
|
||
public void RefreshHeaderColor()
|
||
{
|
||
if (jhrowitem == null) return;
|
||
|
||
// 更新 Summary,确保拿到最新合计
|
||
gridView.UpdateSummary();
|
||
|
||
foreach (GridColumn col in gridView.Columns)
|
||
{
|
||
// 只处理列名可解析成日期的列
|
||
if (!DateTime.TryParse(col.FieldName, out _))
|
||
continue;
|
||
|
||
// 取 “Sum” 合计
|
||
var sumItem = col.Summary
|
||
.OfType<GridColumnSummaryItem>()
|
||
.FirstOrDefault(s => s.SummaryType == SummaryItemType.Sum);
|
||
|
||
bool needRed = false;
|
||
|
||
if (sumItem?.SummaryValue != null &&
|
||
decimal.TryParse(sumItem.SummaryValue.ToString(), out var colSum) &&
|
||
jhrowitem.Table.Columns.Contains(col.FieldName) &&
|
||
decimal.TryParse(jhrowitem[col.FieldName].ToString(), out var planVal))
|
||
{
|
||
needRed = (colSum != planVal);
|
||
}
|
||
|
||
// 只改表头文字颜色
|
||
col.AppearanceHeader.ForeColor = needRed ? Color.Red : Color.Black;
|
||
col.AppearanceHeader.Options.UseForeColor = true;
|
||
}
|
||
// 立刻刷新表头
|
||
gridView.Invalidate();
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 分组后根据汇总排序
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void GridView_EndGrouping(object sender, EventArgs e)
|
||
{
|
||
int currentGroupCount = gridView.GroupedColumns.Count;
|
||
|
||
// 仅在分组状态变化(新增分组)时执行
|
||
if (SystemInfo.Instance.GroupSpecialMode && +currentGroupCount != _lastGroupCount && currentGroupCount > 0 && Completed)
|
||
{
|
||
Completed = false;
|
||
try
|
||
{
|
||
// 清除现有排序规则
|
||
gridView.GroupSummarySortInfo.Clear();
|
||
// 遍历多目标汇总列,按优先级添加排序
|
||
foreach (GridColumn gridColumn in gridView.Columns)
|
||
{
|
||
string summaryName = gridColumn.FieldName;
|
||
// 查找当前目标列的汇总项(假设汇总类型为Sum,可根据实际修改)
|
||
GridGroupSummaryItem summaryItem = gridView.GroupSummary
|
||
.FirstOrDefault(item => item.FieldName.Equals(summaryName)
|
||
&& item.SummaryType == SummaryItemType.Sum) as GridGroupSummaryItem;
|
||
|
||
if (summaryItem != null)
|
||
{
|
||
//根据汇总降序排序
|
||
gridView.GroupSummarySortInfo.Add(summaryItem, ColumnSortOrder.Descending);
|
||
break;
|
||
}
|
||
|
||
}
|
||
}
|
||
finally
|
||
{
|
||
Completed = true;
|
||
}
|
||
|
||
|
||
}
|
||
_lastGroupCount = currentGroupCount;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 设置数值的编辑格式
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void GridView_ShowingEditor(object sender, CancelEventArgs e)
|
||
{
|
||
GridColumn gridColumn = gridView.FocusedColumn;
|
||
if (gridColumn != null && gridColumn.Tag != null && gridColumn.Tag is GridColumnModel)
|
||
{
|
||
GridColumnModel model = (GridColumnModel)gridColumn.Tag;
|
||
EnsureSearchAdditionValueInDataSource(gridColumn, model);
|
||
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;
|
||
// }
|
||
//}
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// SearchBoxAddition保存文本值时,编辑器显示前把当前单元格值补进下拉数据源。
|
||
/// 避免已保存文本不在下拉SQL结果中时,点击单元格进入编辑态显示为空。
|
||
/// </summary>
|
||
private void EnsureSearchAdditionValueInDataSource(GridColumn gridColumn, GridColumnModel model)
|
||
{
|
||
if (gridColumn == null || model == null || !model.SearchBoxAddition) return;
|
||
if (!(ControlType.LabAutoCompleteText == model.FieldType || ControlType.LabAutoCompleteTextParam == model.FieldType ||
|
||
ControlType.LabAutoGridText == model.FieldType || ControlType.LabAutoGridTextParam == model.FieldType)) return;
|
||
|
||
RepositoryItemGridLookUpEdit searchEdit = gridColumn.ColumnEdit as RepositoryItemGridLookUpEdit;
|
||
if (searchEdit == null) return;
|
||
|
||
DataTable dt = searchEdit.DataSource as DataTable;
|
||
if (dt == null) return;
|
||
|
||
string valueName = searchEdit.ValueMember;
|
||
string textName = !string.IsNullOrWhiteSpace(searchEdit.DisplayMember) ? searchEdit.DisplayMember : model.TextMember;
|
||
if (string.IsNullOrWhiteSpace(valueName) || !dt.Columns.Contains(valueName)) return;
|
||
|
||
Type dataType = dt.Columns[valueName].DataType;
|
||
if (dataType != typeof(string)) return;
|
||
|
||
string value = gridView.GetFocusedRowCellValue(gridColumn) + "";
|
||
if (string.IsNullOrWhiteSpace(value)) return;
|
||
|
||
bool exists = dt.Rows.Cast<DataRow>().Any(x =>
|
||
(x[valueName] + "").Equals(value) ||
|
||
(!string.IsNullOrWhiteSpace(textName) && dt.Columns.Contains(textName) && (x[textName] + "").Equals(value)));
|
||
if (exists) return;
|
||
|
||
DataRow newRow = dt.NewRow();
|
||
newRow[valueName] = value;
|
||
if (!string.IsNullOrWhiteSpace(textName) && dt.Columns.Contains(textName))
|
||
{
|
||
newRow[textName] = value;
|
||
}
|
||
dt.Rows.Add(newRow.ItemArray);
|
||
}
|
||
|
||
|
||
/// 计算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;
|
||
|
||
// 转换为网格控件内的坐标(关键修正)
|
||
Point cellLocation = view.GridControl.PointToClient(
|
||
viewInfo.GridControl.PointToScreen(cellInfo.Bounds.Location)
|
||
);
|
||
|
||
return new Rectangle(
|
||
cellLocation.X,
|
||
cellLocation.Y,
|
||
cellInfo.Bounds.Width,
|
||
cellInfo.Bounds.Height
|
||
);
|
||
}
|
||
catch
|
||
{
|
||
return Rectangle.Empty;
|
||
}
|
||
}
|
||
|
||
// 计算按钮起始X坐标(支持左右对齐)
|
||
private int GetButtonStartX(int cellWidth, int totalButtonsWidth, bool isLeftAligned)
|
||
{
|
||
if (isLeftAligned)
|
||
{
|
||
// 靠左对齐:从单元格左侧开始
|
||
return 0;
|
||
}
|
||
else
|
||
{
|
||
// 靠右对齐:从右侧减去总宽度
|
||
return cellWidth - totalButtonsWidth;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 滚轮滚动事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void GridView_MouseWheel(object sender, MouseEventArgs e)
|
||
{
|
||
HandledMouseEventArgs handledArgs = e as HandledMouseEventArgs;
|
||
if (handledArgs != null)
|
||
{
|
||
handledArgs.Handled = false; // 放行事件,允许系统处理Shift+滚轮
|
||
}
|
||
if ((ModifierKeys & Keys.Shift) == Keys.Shift)
|
||
{
|
||
// 滚轮方向判断
|
||
int scrollStep = e.Delta > 0 ? -20 : 20; // 滚动步长,可调整(建议10-30)
|
||
// 计算滚动条位置
|
||
int newLeftCoord = gridView.LeftCoord + scrollStep;
|
||
newLeftCoord = Math.Max(0, newLeftCoord);//Math.Min(newLeftCoord, maxLeftCoord)
|
||
// 移动滚动条位置
|
||
gridView.LeftCoord = newLeftCoord;
|
||
|
||
if (handledArgs != null)
|
||
{
|
||
handledArgs.Handled = true;// 阻止默认垂直滚动
|
||
}
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
}
|