eea88e0b2b
SVN-Revision: r485
8290 lines
395 KiB
C#
8290 lines
395 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 System.Diagnostics;
|
|
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;
|
|
|
|
namespace Lskj.Control
|
|
{
|
|
/// <summary>
|
|
/// 自定义表格控件
|
|
/// </summary>
|
|
public partial class GridControlEx : UserControl
|
|
{
|
|
/// <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>
|
|
public SumPanelControl sumPanel;
|
|
/// <summary>
|
|
/// 单据主表控件、基础档案查询条件控件等等
|
|
/// </summary>
|
|
public MyControl ParentControl;
|
|
/// <summary>
|
|
/// Gets or sets the adapter object.
|
|
/// </summary>
|
|
/// <value>The adapter object.</value>
|
|
public SqlDataAdapter 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>
|
|
/// 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 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>
|
|
private List<int> SelectedDataSource = new List<int>();
|
|
/// <summary>
|
|
/// 禁显列不加载数据源
|
|
/// </summary>
|
|
public bool DisableFieldSources;
|
|
/// <summary>
|
|
/// 表格重新赋值数据源时,更新的列
|
|
/// </summary>
|
|
public string UpdateColumns;
|
|
/// <summary>
|
|
/// 聚合多表头控件
|
|
/// </summary>
|
|
public BandedGridControlEx CustomGroupBandEx;
|
|
|
|
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.CellMerge += new CellMergeEventHandler(OnGridViewCellMerge);
|
|
this.gridView.CustomSummaryCalculate += new CustomSummaryEventHandler(OnGridViewSummaryCalculate);
|
|
this.gridView.OptionsNavigation.EnterMoveNextColumn = true;
|
|
this.gridView.OptionsBehavior.EditorShowMode = DevExpress.Utils.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; ;
|
|
#endregion
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 保存前反写多表头数据源
|
|
/// </summary>
|
|
public void callbackUpdData()
|
|
{
|
|
try
|
|
{
|
|
// 获取动态多表头的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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
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;//默认合并
|
|
for (int i = 0; i < fields.Length; i++)
|
|
{
|
|
int row1 = e.RowHandle1;
|
|
int row2 = e.RowHandle2;
|
|
string McColumn = fields[i] + "";//关联条件列
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
/// <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))
|
|
{
|
|
bool isMergrGroup = !string.IsNullOrEmpty(model.MergeGroup) && gridRow.Table.Columns.Contains(model.MergeGroup) && e.RowHandle != 0 ? (gridRow[model.MergeGroup] + "").Equals(BeforeGroupName) : false;
|
|
if (model.CanMerge && BeforeClass == Convert.ToDecimal(e.FieldValue) && isMergrGroup)
|
|
{
|
|
BeforeClass = Convert.ToDecimal(e.FieldValue);
|
|
BeforeGroupName = !string.IsNullOrEmpty(model.MergeGroup) && gridRow.Table.Columns.Contains(model.MergeGroup) ? gridRow[model.MergeGroup] + "" : "";
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
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(2), 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 (SqlConnection sqlConnection = new SqlConnection(SqlHelper._connection.ConnectionString))
|
|
{
|
|
using (SqlCommand cmd = new SqlCommand())
|
|
{
|
|
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;
|
|
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
|
|
adapter.Fill(dataTable);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
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.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, true);
|
|
break;
|
|
case ControlType.LabTreeLookValue:
|
|
case ControlType.LabTreeLookText:
|
|
case ControlType.LabCheckTreeLookValue:
|
|
case ControlType.LabCheckTreeLookText:
|
|
case ControlType.LabTreeLastlevelValue:
|
|
case ControlType.LabTreeLastlevelText:
|
|
case ControlType.LabCheckTreeLastlevelValue:
|
|
case ControlType.LabCheckTreeLastlevelText:
|
|
InitAutoTreeSearchEdit(column, model, false, false);
|
|
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);
|
|
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;
|
|
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, "合计: {0:#,###}行") });
|
|
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, "合计: {0:#,###}行") });
|
|
}
|
|
|
|
|
|
|
|
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>
|
|
/// <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;
|
|
//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 (!dataCaches.GetValue(this, "RightMenuBtn", out DataTable rightMentTab))
|
|
{
|
|
if (this.Model != null)
|
|
{
|
|
rightMentTab = BaseModuleImpl.GetBaseGridRightMenus(this.Model.ModuleCode);
|
|
}
|
|
}
|
|
if (this.Model != null && BaseModuleImpl.IsGridViewRightMenuBtnEdit(rightMentTab))
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
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 (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;
|
|
//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 (Model != null)
|
|
{
|
|
if (!Model.DataCaches.GetValue(this, "RightMenuBtn", out DataTable rightMentTab))
|
|
{
|
|
if (this.Model != null)
|
|
{
|
|
rightMentTab = BaseModuleImpl.GetBaseGridRightMenus(this.Model.ModuleCode);
|
|
}
|
|
}
|
|
if (this.Model != null && BaseModuleImpl.IsGridViewRightMenuBtnEdit(rightMentTab))
|
|
{
|
|
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(SqlDataAdapter adapter, bool selectRowHandler = true)
|
|
{
|
|
if (adapter == null) return 0;
|
|
|
|
try
|
|
{
|
|
this.AdapterObj = adapter;
|
|
DataSet dataSet = new DataSet();
|
|
adapter.Fill(dataSet, "SetGridViewDataSource");
|
|
|
|
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();
|
|
}
|
|
}
|
|
SqlCommandBuilder cb = new SqlCommandBuilder(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>
|
|
/// <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();
|
|
}
|
|
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));
|
|
}
|
|
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) || !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;
|
|
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, "合计: {0:#,###}行") });
|
|
|
|
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, "合计: {0:#,###}行") });
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (visible)
|
|
{
|
|
isShowFooter = true;
|
|
col.Summary.AddRange(new GridSummaryItem[] { new GridColumnSummaryItem(SummaryItemType.Sum, col.FieldName, "{0:}") });
|
|
|
|
if (SystemInfo.Instance.GroupSpecialMode)
|
|
{
|
|
gridView.GroupSummary.Add(new GridGroupSummaryItem(DevExpress.Data.SummaryItemType.Sum, col.FieldName, col, "{0:}"));
|
|
gridView.OptionsView.GroupFooterShowMode = GroupFooterShowMode.VisibleAlways;
|
|
}
|
|
else
|
|
{
|
|
gridView.GroupSummary.AddRange(new GridSummaryItem[] { new GridGroupSummaryItem(SummaryItemType.Sum, col.FieldName, null, "{0:}") });
|
|
}
|
|
}
|
|
}
|
|
if (colSplit.Length > 3)
|
|
{
|
|
string dataFormat = colSplit[3];
|
|
|
|
if (!string.IsNullOrWhiteSpace(dataFormat))
|
|
{
|
|
col.DisplayFormat.FormatType = FormatType.Custom;
|
|
col.DisplayFormat.FormatString = dataFormat;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
col.Width = 150;
|
|
}
|
|
gridView.OptionsView.ShowFooter = isShowFooter;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <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("微软雅黑", SystemInfo.Instance.GridRowFontSize);
|
|
this.gridView.Appearance.HeaderPanel.Font = new Font("微软雅黑", SystemInfo.Instance.GridRowFontSize);
|
|
}
|
|
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>
|
|
/// <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();
|
|
|
|
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;
|
|
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))
|
|
{
|
|
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>
|
|
/// <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;
|
|
|
|
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.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);
|
|
|
|
|
|
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.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.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)
|
|
{
|
|
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.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>
|
|
/// 数据源中点击将数据源更新
|
|
/// </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);
|
|
}
|
|
}
|
|
|
|
|
|
//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);
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
private void InitRightMenuBtnEdit()
|
|
{
|
|
GridColumn gridColumn = new GridColumn();
|
|
gridColumn.FieldName = "RightMenuBtnEdit";
|
|
gridColumn.Name = "RightMenuBtnEdit";
|
|
gridColumn.Caption = "操作列";
|
|
//gridColumn.OptionsColumn.ShowCaption = false;
|
|
gridColumn.Visible = 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);
|
|
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);
|
|
}
|
|
}
|
|
gridColumn.ColumnEdit = ItemButtonEdit;
|
|
this.gridView.Columns.Add(gridColumn);
|
|
this.gridView.OptionsBehavior.EditorShowMode = EditorShowMode.MouseDown;
|
|
gridColumn.MaxWidth = rightMenuBtns.Length * picWidth;
|
|
gridColumn.MinWidth = rightMenuBtns.Length * picWidth;
|
|
gridColumn.Width = rightMenuBtns.Length * picWidth;
|
|
}
|
|
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;
|
|
|
|
|
|
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;
|
|
//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(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>创建日期: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;
|
|
|
|
// 计算数字部分宽度
|
|
int numberWidth = (int)(rowCount.ToString().Length * 7.5) + 16;
|
|
|
|
// 设置最终宽度(取较大值,并在40-80px之间)
|
|
this.gridView.IndicatorWidth = Math.Max(40, Math.Min(80, numberWidth));
|
|
}
|
|
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();
|
|
|
|
if (dataObj.GetDataPresent(DataFormats.Text))
|
|
_objData = dataObj.GetData(DataFormats.Text);
|
|
if (SystemInfo.Instance.IsOldPost || (this.Tag != null && this.Tag.ToString() == "IsOldPost"))
|
|
{
|
|
OldPasteMethod(e, _objData);
|
|
}
|
|
else
|
|
{
|
|
//OldPasteMethod(e, _objData);
|
|
NewPasteMethod(e, _objData);
|
|
}
|
|
}
|
|
// 向下复制整行
|
|
if (e.Control && e.Shift && e.KeyCode == Keys.C)
|
|
{
|
|
DataRow rt = this.gridView.GetDataRow(gridView.FocusedRowHandle);
|
|
DataTable dt = (DataTable)this.GridControl.DataSource;
|
|
dt.Rows.Add(rt.ItemArray);
|
|
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 ((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 (model != null && (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)
|
|
{
|
|
RepositoryItemCheckedComboBoxEdit rccbe = col.ColumnEdit as RepositoryItemCheckedComboBoxEdit;
|
|
FrmModelLookUp modelLookUp = rccbe.Buttons[1].Tag as FrmModelLookUp;
|
|
if (modelLookUp.SingleChoiceMode)
|
|
{
|
|
value = GetValueByCaption(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 ((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 (model != null && (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;
|
|
}
|
|
}
|
|
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 + ""))
|
|
{
|
|
// 渲染界面数据量过多界面刷新会很慢
|
|
//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 + "");
|
|
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 = new FontStyle();
|
|
if (model.IsBold) fontStyle = fontStyle | FontStyle.Bold;
|
|
if (model.IsItalic) fontStyle = fontStyle | FontStyle.Italic;
|
|
if (model.IsStrickOut) fontStyle = fontStyle | FontStyle.Strikeout;
|
|
if (model.IsUnderLine) fontStyle = fontStyle | FontStyle.Underline;
|
|
|
|
e.Appearance.Font = new Font(e.Appearance.Font, 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"] + "");
|
|
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 = new FontStyle();
|
|
if (model.IsBold) fontStyle = fontStyle | FontStyle.Bold;
|
|
if (model.IsItalic) fontStyle = fontStyle | FontStyle.Italic;
|
|
if (model.IsStrickOut) fontStyle = fontStyle | FontStyle.Strikeout;
|
|
if (model.IsUnderLine) fontStyle = fontStyle | FontStyle.Underline;
|
|
|
|
e.Appearance.Font = new Font(e.Appearance.Font, 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 (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 = new FontStyle();
|
|
if (model.IsBold) fontStyle = fontStyle | FontStyle.Bold;
|
|
if (model.IsItalic) fontStyle = fontStyle | FontStyle.Italic;
|
|
if (model.IsStrickOut) fontStyle = fontStyle | FontStyle.Strikeout;
|
|
if (model.IsUnderLine) fontStyle = fontStyle | FontStyle.Underline;
|
|
|
|
e.Appearance.Font = new Font(e.Appearance.Font, 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);
|
|
}
|
|
}
|
|
}
|
|
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))
|
|
{
|
|
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)));
|
|
}
|
|
|
|
}
|
|
}
|
|
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 && gridView.OptionsSelection.MultiSelect == true && gridView.OptionsSelection.MultiSelectMode == GridMultiSelectMode.CheckBoxRowSelect && gridView.OptionsSelection.EnableAppearanceFocusedCell == false)
|
|
{
|
|
SelectedDataSource.Clear();
|
|
// 遍历勾选的行索引,并获取它们在数据源中的索引
|
|
foreach (int rowHandle in SelectedRows)
|
|
{
|
|
// 获取行在数据源中的索引
|
|
int dataSourceRowIndex = gridView.GetDataSourceRowIndex(rowHandle);
|
|
SelectedDataSource.Add(dataSourceRowIndex);
|
|
}
|
|
}
|
|
}
|
|
/// <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));
|
|
}
|
|
}
|
|
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
|
|
{
|
|
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 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 });
|
|
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 });
|
|
}
|
|
}
|
|
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)
|
|
{
|
|
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;
|
|
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>
|
|
/// <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;
|
|
//SourceSQL = modelLookUp.SysModel.MenuSql.Replace("#", "");
|
|
//单据头关联取值
|
|
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>
|
|
/// 模块返回框清空
|
|
/// </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>
|
|
/// <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)
|
|
{
|
|
DataTable currentDataSource = gridView.GridControl.DataSource as DataTable;
|
|
if (currentDataSource != null)
|
|
{
|
|
BuildDynamicGroupedColumns(CustomGroupBandEx, 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;
|
|
|
|
// 获取你的定义的主键、分组列、聚合数据列
|
|
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; // 数据不足直接退出
|
|
|
|
// 清理现有结构
|
|
bandedGridControlEx.BandedView.Bands.Clear();
|
|
bandedGridControlEx.BandedView.Columns.Clear();
|
|
|
|
// 保留其他非聚合列
|
|
List<GridColumnModel> normalColumns = ColumnList.Where(o => o.IsCustomGroupField == 0).ToList();
|
|
|
|
// 创建正常列的Band
|
|
GridBand normalBand = new GridBand() { Caption = "基本信息" };
|
|
bandedGridControlEx.BandedView.Bands.Add(normalBand);
|
|
|
|
// 添加正常列到Band中
|
|
foreach (var normalCol in normalColumns)
|
|
{
|
|
if (originalDataSource.Columns.Contains(normalCol.FieldName))
|
|
{
|
|
BandedGridColumn col = new BandedGridColumn()
|
|
{
|
|
FieldName = normalCol.FieldName,
|
|
Caption = normalCol.FieldText,
|
|
Width = normalCol.Width,
|
|
Visible = normalCol.Visible,
|
|
Tag = normalCol,
|
|
//MinWidth = normalCol.Width,
|
|
//MaxWidth = normalCol.Width,
|
|
OptionsColumn = { AllowEdit = normalCol.Edit, FixedWidth = true }
|
|
};
|
|
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);
|
|
normalBand.Columns.Add(col);
|
|
bandedGridControlEx.BandedView.Columns.Add(col);
|
|
}
|
|
}
|
|
|
|
// 动态获取需要聚合的列
|
|
var dynamicHeaders = originalDataSource.AsEnumerable()
|
|
.Select(r => r.Field<string>(GroupFieldprimary.FieldName))
|
|
.Distinct().Where(x => !string.IsNullOrEmpty(x)).ToList();
|
|
|
|
// 为每个动态表头生成GridBand,并添加子列
|
|
foreach (string headerName in dynamicHeaders)
|
|
{
|
|
GridBand dynamicBand = new GridBand() { Caption = headerName };
|
|
bandedGridControlEx.BandedView.Bands.Add(dynamicBand);
|
|
|
|
foreach (var subField in GroupField)
|
|
{
|
|
string dynamicFieldName = $"{headerName}_{subField.FieldName}";
|
|
|
|
BandedGridColumn subColumn = new BandedGridColumn()
|
|
{
|
|
FieldName = dynamicFieldName,
|
|
Caption = subField.FieldText,
|
|
Width = subField.Width,
|
|
Visible = subField.Visible,
|
|
Tag = subField,
|
|
MinWidth = subField.Width,
|
|
MaxWidth = subField.Width,
|
|
OptionsColumn = { AllowEdit = subField.Edit, FixedWidth = true }
|
|
};
|
|
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);
|
|
dynamicBand.Columns.Add(subColumn);
|
|
bandedGridControlEx.BandedView.Columns.Add(subColumn);
|
|
}
|
|
}
|
|
bandedGridControlEx.BandedView.EndUpdate();
|
|
// 构建最终动态数据源
|
|
DataTable dynamicDataTable = BuildDynamicDataSource(originalDataSource, GroupPrimary, GroupFieldprimary, GroupField, normalColumns, dynamicHeaders);
|
|
bandedGridControlEx.gridControl.DataSource = dynamicDataTable;
|
|
}
|
|
|
|
/// <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>
|
|
private DataTable BuildDynamicDataSource(DataTable originalDataSource,
|
|
GridColumnModel GroupPrimary,
|
|
GridColumnModel GroupFieldprimary,
|
|
List<GridColumnModel> GroupField,
|
|
List<GridColumnModel> normalColumns,
|
|
List<string> dynamicHeaders)
|
|
{
|
|
try
|
|
{
|
|
DataTable dtResult = new DataTable();
|
|
|
|
// 添加主键列
|
|
if (!dtResult.Columns.Contains(GroupPrimary.FieldName))
|
|
{
|
|
Type dataType = originalDataSource.Columns[GroupPrimary.FieldName].DataType;
|
|
dtResult.Columns.Add(GroupPrimary.FieldName, dataType);
|
|
}
|
|
|
|
|
|
// 添加普通列,仅当原数据源存在时才添加
|
|
foreach (var col in normalColumns)
|
|
{
|
|
if (originalDataSource.Columns.Contains(col.FieldName) && col.FieldName != GroupPrimary.FieldName)
|
|
{
|
|
Type dataType = originalDataSource.Columns[col.FieldName].DataType;
|
|
dtResult.Columns.Add(col.FieldName, dataType);
|
|
}
|
|
}
|
|
|
|
// 添加动态列 (改为string类型避免异常)
|
|
foreach (string header in dynamicHeaders)
|
|
{
|
|
foreach (var subField in GroupField)
|
|
{
|
|
string dynamicFieldName = $"{header}_{subField.FieldName}";
|
|
if (!dtResult.Columns.Contains(dynamicFieldName))
|
|
{
|
|
Type dataType = originalDataSource.Columns[subField.FieldName].DataType;
|
|
dtResult.Columns.Add(dynamicFieldName, dataType); // <-- 此处已修改为string
|
|
}
|
|
}
|
|
}
|
|
|
|
// 根据主键聚合数据
|
|
var groupedData = originalDataSource.AsEnumerable()
|
|
.GroupBy(row => row.Field<string>(GroupPrimary.FieldName));
|
|
|
|
foreach (var group in groupedData)
|
|
{
|
|
DataRow newRow = dtResult.NewRow();
|
|
|
|
// 主键列赋值
|
|
DataRow firstRow = group.First();
|
|
newRow[GroupPrimary.FieldName] = firstRow[GroupPrimary.FieldName];
|
|
|
|
// 普通列赋值(需判断原数据源中存在)
|
|
foreach (var col in normalColumns)
|
|
{
|
|
if (originalDataSource.Columns.Contains(col.FieldName))
|
|
newRow[col.FieldName] = firstRow[col.FieldName];
|
|
}
|
|
|
|
// 动态聚合列赋值
|
|
foreach (var header in dynamicHeaders)
|
|
{
|
|
var matchedRow = group.FirstOrDefault(r => r.Field<string>(GroupFieldprimary.FieldName) == header);
|
|
foreach (var subField in GroupField)
|
|
{
|
|
string dynamicFieldName = $"{header}_{subField.FieldName}";
|
|
|
|
object value = DBNull.Value;
|
|
|
|
if (matchedRow != null && originalDataSource.Columns.Contains(subField.FieldName))
|
|
{
|
|
value = matchedRow[subField.FieldName];
|
|
}
|
|
|
|
newRow[dynamicFieldName] = value;
|
|
}
|
|
}
|
|
|
|
dtResult.Rows.Add(newRow);
|
|
}
|
|
|
|
return dtResult;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// 最好将异常记录下来
|
|
Console.WriteLine(ex.Message);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
#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();
|
|
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();
|
|
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;
|
|
|
|
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)
|
|
{
|
|
|
|
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;
|
|
}
|
|
if (!string.IsNullOrEmpty(RequiredFields) && RequiredFields != "-1")
|
|
{
|
|
Required = true;
|
|
RequiredFields = RequiredFields + ",";
|
|
}
|
|
this.gridView.BeginUpdate();
|
|
foreach (GridColumn item in gc)
|
|
{
|
|
GridColumnModel model = item.Tag as GridColumnModel;
|
|
//修改
|
|
if (Modify)
|
|
{
|
|
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.IndexOf(item.FieldName + ",", StringComparison.OrdinalIgnoreCase) != -1)
|
|
{
|
|
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();
|
|
|
|
//if (ColumnsList.Count == 0) ColumnsList = this.gridView.Columns.ToList();
|
|
//if (ColumnsList.Count == 0) return;
|
|
//this.gridView.Columns.Clear();
|
|
//if (string.IsNullOrWhiteSpace(ColumnName))
|
|
//{
|
|
// this.gridView.Columns.Add(ColumnsList[0]);
|
|
// return;
|
|
//}
|
|
//string[] ColumnNames = ColumnName.Split(',');
|
|
|
|
//foreach (GridColumn item in ColumnsList)
|
|
//{
|
|
// GridColumnModel model = item.Tag as GridColumnModel;
|
|
// bool isContain = ColumnNames.Contains(model.FieldName) ? true : false;
|
|
// if (isContain)
|
|
// {
|
|
// item.Visible = true;
|
|
// this.gridView.Columns.Add(item);
|
|
// }
|
|
//}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 表格有复选框的情况下,勾选的行在筛选后默认显示
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void GridView_CustomRowFilter(object sender, RowFilterEventArgs e)
|
|
{
|
|
if (SystemInfo.Instance.DisplayCheckboxSelection && gridView.OptionsSelection.MultiSelect == true && gridView.OptionsSelection.MultiSelectMode == GridMultiSelectMode.CheckBoxRowSelect && gridView.OptionsSelection.EnableAppearanceFocusedCell == false)
|
|
{
|
|
if (SelectedDataSource.Contains(e.ListSourceRow))
|
|
{
|
|
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
|
|
|
|
}
|
|
} |