c8fbb3eca9
SVN-Revision: r325
4052 lines
180 KiB
C#
4052 lines
180 KiB
C#
/******************************
|
|
* 说明:表格树
|
|
* 创建人:龚宇超
|
|
* 创建日期:2017-12-26
|
|
* 修改人:
|
|
* 修改日期:
|
|
* 修改备注:
|
|
* 版本: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 Lskj.Control.Model;
|
|
using Lskj.Model;
|
|
using DevExpress.XtraTreeList;
|
|
using DevExpress.XtraTreeList.Columns;
|
|
using DevExpress.Utils;
|
|
using DevExpress.XtraGrid;
|
|
using DevExpress.XtraTreeList.Menu;
|
|
using DevExpress.Utils.Menu;
|
|
using Lskj.Data;
|
|
using Lskj.Business.Impl;
|
|
using System.Data.SqlClient;
|
|
using Lskj.Util;
|
|
using Lskj.Business;
|
|
using DevExpress.XtraTreeList.Nodes;
|
|
using DevExpress.XtraEditors.Repository;
|
|
using DevExpress.XtraEditors.Controls;
|
|
using DevExpress.XtraEditors;
|
|
using System.Reflection;
|
|
using DevExpress.Data.Filtering;
|
|
using DevExpress.XtraGrid.Drawing;
|
|
using Lskj.Control.MultiGridLookUp;
|
|
using Lskj.Control.MultiModelLookUp;
|
|
using System.Text.RegularExpressions;
|
|
using Lskj.Core;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Collections;
|
|
|
|
namespace Lskj.Control
|
|
{
|
|
/// <summary>
|
|
/// 表格树
|
|
/// </summary>
|
|
public partial class TreeGridControlEx : GridControlEx
|
|
{
|
|
public TreeList TreeListObj { get { return gcMain; } }
|
|
|
|
/// <summary>
|
|
/// 树表格固定菜单
|
|
/// </summary>
|
|
public ContextMenuStrip MenuStrip { get { return contextMenuStrip; } }
|
|
/// <summary>
|
|
/// 默认全部展开
|
|
/// </summary>
|
|
public string Expansion = "1";
|
|
|
|
//treeList树展开的节点块
|
|
public List<TreeListNode> treeListNodes = new List<TreeListNode>();
|
|
|
|
/// <summary>
|
|
/// 排序字段
|
|
/// </summary>
|
|
public string SortField;
|
|
|
|
/// <summary>
|
|
/// 上次选中行
|
|
/// </summary>
|
|
private int lastNodeIndex;
|
|
|
|
|
|
/// <summary>
|
|
/// 下拉框数据源绑定完成后执行
|
|
/// </summary>
|
|
public new event EventHandler OnDataSourceBindCallBack;
|
|
|
|
public TreeGridControlEx()
|
|
{
|
|
InitializeComponent();
|
|
this.gcMain.KeyDown += new KeyEventHandler(OnTreeGridViewKeyDown);
|
|
this.gcMain.SelectionChanged += new EventHandler(gcMain_SelectionChanged);
|
|
this.gcMain.CustomDrawNodeCell += new CustomDrawNodeCellEventHandler(OnCustomDrawNodeCell);
|
|
this.TreeListObj.CustomDrawNodeIndicator += TreeListObj_CustomDrawNodeIndicator;//显示行号
|
|
this.gcMain.CellValueChanged += GcMain_CellValueChanged;
|
|
this.gcMain.NodesReloaded += OnNodesReloaded;
|
|
this.SetGridRowHeightAndFont();
|
|
if (SystemInfo.Instance.ExpandButtonType.Equals("1"))
|
|
{
|
|
this.gcMain.CustomDrawNodeButton += OnCustomDrawNodeButton;//绘制按钮
|
|
}
|
|
//InitializeTreeMethod();
|
|
//this.gcMain.OptionsBehavior.EnableFiltering = true;
|
|
//this.gcMain.OptionsFind.AlwaysVisible = true;
|
|
}
|
|
void gcMain_SelectionChanged(object sender, EventArgs e)
|
|
{
|
|
//try
|
|
//{
|
|
//List<TreeListCell> cells = this.gcMain.GetSelectedCells();
|
|
//DataRow[] rows = GetViewFocusedDataRows();
|
|
|
|
//this.pl_buttom.Visible = cells.Count > 1 && rows.Length > 1;
|
|
//if (this.pl_buttom.Visible)
|
|
//{
|
|
|
|
// // 分别计算求和、平均值、最大值、最小值、计数
|
|
// double sum = 0, avg = 0, max = 0, min = 0;
|
|
// int count = 0;
|
|
|
|
// foreach (DataRow row in rows)
|
|
// {
|
|
// foreach (TreeListCell cell in cells)
|
|
// {
|
|
// double cellNumber = 0;
|
|
// string cellValue = row[cell.Column.Name] + "";
|
|
// 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;
|
|
// 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)
|
|
//{
|
|
//}
|
|
}
|
|
/// <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 override 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.gcMain.CustomDrawNodeCell += new CustomDrawNodeCellEventHandler(OnGridViewRowCellStyle);
|
|
else
|
|
this.gcMain.NodeCellStyle += new GetCustomNodeCellStyleEventHandler(OnGridViewRowStyle);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置树表格行颜色</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2019-11-15 </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, GetCustomNodeCellStyleEventArgs e)
|
|
{
|
|
if (this.GridRowColorsTable != null && this.GridRowColorsTable.Rows.Count > 0)
|
|
{
|
|
// 渲染界面数据量过多界面刷新会很慢
|
|
DataRowView dataRowView = this.gcMain.GetDataRecordByNode(e.Node) as DataRowView;
|
|
DataRow gridRow = dataRowView != null ? dataRowView.Row : null;
|
|
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>创建日期:2019-11-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.Grid.RowCellStyleEventArgs"/> instance containing the event data.</param>
|
|
/// <exception cref="System.NotImplementedException"></exception>
|
|
protected void OnGridViewRowCellStyle(object sender, CustomDrawNodeCellEventArgs e)
|
|
{
|
|
if (this.GridRowColorsTable != null && this.GridRowColorsTable.Rows.Count > 0 && !string.IsNullOrEmpty(e.CellValue + ""))
|
|
{
|
|
// 渲染界面数据量过多界面刷新会很慢
|
|
DataRowView dataRowView = this.gcMain.GetDataRecordByNode(e.Node) as DataRowView;
|
|
DataRow gridRow = dataRowView != null ? dataRowView.Row : null;
|
|
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>
|
|
/// 绘制按钮
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnCustomDrawNodeButton(object sender, CustomDrawNodeButtonEventArgs e)
|
|
{
|
|
Rectangle rect = Rectangle.Inflate(e.Bounds, 0, 0);
|
|
Image img = e.Expanded ? global::Lskj.Control.Properties.Resources.UnExpand : global::Lskj.Control.Properties.Resources.Expand;
|
|
float scaleX = (float)rect.Width / img.Width;
|
|
float scaleY = (float)rect.Height / img.Height;
|
|
float scale = Math.Min(scaleX, scaleY);
|
|
int newWidth = (int)(img.Width * scale);
|
|
int newHeight = (int)(img.Height * scale);
|
|
int offsetX = (rect.Width - newWidth) / 2;
|
|
int offsetY = (rect.Height - newHeight) / 2;
|
|
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
|
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
|
e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
|
e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
|
|
e.Graphics.DrawImage(img, rect.X + offsetX, rect.Y + offsetY, newWidth, newHeight);
|
|
e.Handled = true;
|
|
}
|
|
/// <summary>
|
|
/// 节点加载完成后
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnNodesReloaded(object sender, EventArgs e)
|
|
{
|
|
//根据记录展开对应节点
|
|
foreach (TreeListNode treeListNode in treeListNodes)
|
|
{
|
|
TreeListNode treeListNode1 = this.gcMain.Nodes.TreeList.FindNodeByID(treeListNode.Id);
|
|
if (treeListNode1 != null) treeListNode1.Expanded = true;
|
|
}
|
|
|
|
if ((Expansion + "").Equals("1"))
|
|
{
|
|
this.gcMain.ExpandAll();
|
|
}
|
|
else if ((Expansion + "").Equals("2"))
|
|
{
|
|
this.gcMain.ExpandToLevel(0);
|
|
}
|
|
this.TreeListObj.FocusedNode = this.TreeListObj.GetNodeByVisibleIndex(lastNodeIndex);
|
|
//if (selectRowHandler)
|
|
//{
|
|
// this.TreeListObj.FocusedNode = this.TreeListObj.GetNodeByVisibleIndex(lastNodeIndex);
|
|
//}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置只读列</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-30 </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>
|
|
public override void SetReadOnlyColumns(DataTable table, string customColumKey = "")
|
|
{
|
|
if (table == null) return;
|
|
Dictionary<object, Hashtable> dataCaches = Model != null ? Model.DataCaches : null;
|
|
this.CustomColumKey = customColumKey;
|
|
this.gcMain.PopupMenuShowing += new PopupMenuShowingEventHandler(OnPopupMenuShowing);
|
|
for (int i = 0; i < table.Rows.Count; i++)
|
|
{
|
|
DataRow item = table.Rows[i];
|
|
|
|
GridColumnModel model = new GridColumnModel(item, false);
|
|
TreeListColumn gridColumn = new TreeListColumn();
|
|
|
|
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;
|
|
gridColumn.OptionsColumn.AllowEdit = false;
|
|
gridColumn.OptionsColumn.ReadOnly = false;
|
|
gridColumn.OptionsFilter.FilterPopupMode = DevExpress.XtraTreeList.FilterPopupMode.CheckedList;
|
|
gridColumn.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
|
|
|
|
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;
|
|
}
|
|
|
|
// 设置列格式化、汇总
|
|
this.SetColumnFormat(gridColumn, model);
|
|
this.SetColumnSumming(gridColumn, model);
|
|
// 创建列
|
|
this.InitEditColumns(gridColumn, model);
|
|
this.gcMain.Columns.AddRange(new TreeListColumn[] { gridColumn });
|
|
this.ColumnList.Add(model);
|
|
}
|
|
if (!dataCaches.GetValue(this, "CustomColumnByDatabase", out DataTable customTable))
|
|
{
|
|
customTable = this.gcMain.GetCustomColumnByDatabase(this.CustomColumKey);
|
|
}
|
|
this.SetCustomColumns(customTable);
|
|
|
|
// 延迟加载数据源
|
|
this.mLoading = false;
|
|
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="item">The dr row.</param>
|
|
protected void InitEditColumns(TreeListColumn column, GridColumnModel model)
|
|
{
|
|
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.LabMultiSelectValueParam:
|
|
case ControlType.LabMultiSelectText:
|
|
case ControlType.LabMultiSelectTextParam:
|
|
InitMutilEdit(column, model);
|
|
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);
|
|
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.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.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>创建日期: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(TreeListColumn 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(TreeListColumn 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(TreeListColumn 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;
|
|
|
|
comboxEdit.DataSource = BaseImpl.GetDataTableResult(model.SqlSource);//加载数据源
|
|
|
|
this.mControlList.Add(model);
|
|
}
|
|
|
|
|
|
/// <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(TreeListColumn gridColumn)
|
|
{
|
|
RepositoryItemProgressBar progressEdit = new RepositoryItemProgressBar();
|
|
progressEdit.ShowTitle = true;
|
|
|
|
gridControl.RepositoryItems.Add(progressEdit);
|
|
gridColumn.ColumnEdit = progressEdit;
|
|
}
|
|
|
|
|
|
/// <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(TreeListColumn 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 += OnAutoSearchEditPopupMenuShowing;
|
|
searchEdit.KeyDown += OnsearchEditKeyDown;
|
|
searchEdit.QueryPopUp += new CancelEventHandler(OnSearchEditQueryPopUp);
|
|
DataTable cusTable = new DataTable();
|
|
|
|
DevExpress.XtraGrid.Columns.GridColumn valueColumn = new DevExpress.XtraGrid.Columns.GridColumn();
|
|
valueColumn.Name = valueColumn.FieldName = model.ValueMember;
|
|
valueColumn.Caption = "编码";
|
|
valueColumn.Visible = model.ValueMember.Substring(0, 1) != "_";
|
|
|
|
DevExpress.XtraGrid.Columns.GridColumn textColumn = new DevExpress.XtraGrid.Columns.GridColumn();
|
|
textColumn.Name = textColumn.FieldName = model.TextMember;
|
|
textColumn.Caption = "名称";
|
|
textColumn.Visible = model.TextMember.Substring(0, 1) != "_";
|
|
|
|
searchEdit.View.Columns.AddRange(new DevExpress.XtraGrid.Columns.GridColumn[] { valueColumn, textColumn });
|
|
|
|
searchEdit.PopupFormSize = new System.Drawing.Size(popWidth, searchEdit.PopupFormSize.Height);
|
|
gridControl.RepositoryItems.Add(searchEdit);
|
|
gridColumn.ColumnEdit = searchEdit;
|
|
searchEdit.View.Tag = searchEdit;
|
|
searchEdit.EditValueChanging += gridLookUpEdit1_EditValueChanging;
|
|
searchEdit.View.CustomDrawFilterPanel += OnCustomDrawFilterPanel;
|
|
searchEdit.View.Click += new EventHandler(View_Click);
|
|
|
|
//加载数据源
|
|
DataTable table = BaseImpl.GetDataTableResult(model.SqlSource);
|
|
searchEdit.DataSource = table;
|
|
if (table.Columns.Contains("remark"))
|
|
{
|
|
DevExpress.XtraGrid.Columns.GridColumn remarkColumn = new DevExpress.XtraGrid.Columns.GridColumn();
|
|
remarkColumn.Caption = "备注";
|
|
remarkColumn.Name = remarkColumn.FieldName = "remark";
|
|
remarkColumn.Visible = true;
|
|
|
|
searchEdit.View.Columns.Add(remarkColumn);
|
|
}
|
|
|
|
foreach (DataColumn dcol in table.Columns)
|
|
{
|
|
if ((dcol.ColumnName.Substring(0, 1) != "_"))
|
|
{
|
|
if ((dcol.ColumnName.ToLower() != model.ValueMember.ToLower()) && (dcol.ColumnName.ToLower() != model.TextMember.ToLower()) && (dcol.ColumnName.ToLower() != "remark") && ((int)dcol.ColumnName[0] > 127))
|
|
{
|
|
DevExpress.XtraGrid.Columns.GridColumn otherColumn = new DevExpress.XtraGrid.Columns.GridColumn();
|
|
otherColumn.Name = otherColumn.FieldName = otherColumn.Caption = dcol.ColumnName;
|
|
otherColumn.Visible = true;
|
|
searchEdit.View.Columns.Add(otherColumn);
|
|
}
|
|
if (searchEdit.View.Columns.FirstOrDefault(x => x.FieldName == dcol.ColumnName) != null)
|
|
{
|
|
DevExpress.XtraGrid.Columns.GridColumn gCol = searchEdit.View.Columns[dcol.ColumnName];
|
|
gCol.Width = CalcMaxColumnWidth(table, gCol.Name);
|
|
popWidth += gCol.Width;
|
|
}
|
|
}
|
|
}
|
|
searchEdit.PopupFormSize = new System.Drawing.Size(popWidth, searchEdit.PopupFormSize.Height);
|
|
|
|
this.mControlList.Add(model);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <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(TreeListColumn 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(TreeListColumn 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(TreeListColumn 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(TreeListColumn 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(TreeListColumn gridColumn)
|
|
{
|
|
RepositoryItemMemoEdit memo = new RepositoryItemMemoEdit();
|
|
memo.Appearance.TextOptions.WordWrap = WordWrap.Wrap;//自动换行
|
|
gridControl.RepositoryItems.Add(memo);
|
|
gridColumn.ColumnEdit = memo;
|
|
}
|
|
|
|
|
|
/// <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(TreeListColumn 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.LabMultiSelectValueParam ? model.ValueMember : model.TextMember;
|
|
mutilLookUp.Tag = model;
|
|
|
|
RepositoryItemCheckedComboBoxEdit btnEdit = new RepositoryItemCheckedComboBoxEdit();
|
|
btnEdit.NullText = "";
|
|
btnEdit.PopupBorderStyle = PopupBorderStyles.Flat;
|
|
btnEdit.AllowNullInput = DefaultBoolean.False;
|
|
btnEdit.DisplayMember = model.TextMember;
|
|
btnEdit.SeparatorChar = ',';
|
|
btnEdit.ValueMember = model.FieldType == ControlType.LabMultiSelectValue ||
|
|
model.FieldType == ControlType.LabMultiSelectValueParam ? model.ValueMember : model.TextMember;
|
|
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>说明:创建树节点自动搜索框</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(TreeListColumn 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.ValueField = model.ValueMember;
|
|
_popup.TextMember = model.TextMember;
|
|
_popup.SourceSQL = model.SqlSource;
|
|
_popup.TreeViewObj.CheckBoxes = isMulitClick;
|
|
DataTable table = MainImpl.GetDataTableResult(model.SqlSource);
|
|
_popup.SetDataSource(table);
|
|
_popup.Dock = DockStyle.Fill;
|
|
_popup.model = model;
|
|
_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 (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>创建日期: </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(TreeListColumn 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-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(TreeListColumn gridColumn)
|
|
{
|
|
RepositoryItemRichTextEdit richEdit = new RepositoryItemRichTextEdit();
|
|
richEdit.Encoding = Encoding.UTF8;//乱码问题
|
|
gridControl.RepositoryItems.Add(richEdit);
|
|
gridColumn.ColumnEdit = richEdit;
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>说明:表格图片</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-08-02 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
public void InitPicEdit(TreeListColumn gridColumn)
|
|
{
|
|
RepositoryItemPictureEdit picEdit = new RepositoryItemPictureEdit();
|
|
picEdit.AutoHeight = true;
|
|
picEdit.SizeMode = PictureSizeMode.Zoom;
|
|
picEdit.BestFitWidth = 16;
|
|
picEdit.CustomHeight = 16;
|
|
gridColumn.ColumnEdit = picEdit;
|
|
}
|
|
|
|
|
|
/// <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(TreeListColumn gridColumn, GridColumnModel model)
|
|
{
|
|
FrmModelLookUp modelLookUp = new FrmModelLookUp(model.addModuleld, model.IsRadio);
|
|
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;
|
|
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 = modelLookUp;
|
|
btnEdit.ButtonClick += new ButtonPressedEventHandler(OnModuleChoice);
|
|
|
|
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(TreeListColumn gridColumn, GridColumnModel model)
|
|
{
|
|
FrmModelLookUp2 modelLookUp = new FrmModelLookUp2(model.addModuleld, model.IsRadio);
|
|
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;
|
|
//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 = modelLookUp;
|
|
btnEdit.ButtonClick += new ButtonPressedEventHandler(OnModuleChoiceNew);
|
|
|
|
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(TreeListColumn 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;
|
|
//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;
|
|
//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 = modelLookUp;
|
|
btnEdit.ButtonClick += new ButtonPressedEventHandler(OnModuleRowsChoice);
|
|
|
|
gridControl.RepositoryItems.Add(btnEdit);
|
|
gridColumn.OptionsColumn.ReadOnly = true;
|
|
gridColumn.ColumnEdit = btnEdit;
|
|
|
|
this.mControlList.Add(model);
|
|
}
|
|
|
|
|
|
|
|
/// <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(TreeListColumn gridColumn)
|
|
{
|
|
RepositoryItemCheckEdit checkEdit = new RepositoryItemCheckEdit();
|
|
checkEdit.ValueChecked = 1;
|
|
checkEdit.ValueUnchecked = 0;
|
|
|
|
gridControl.RepositoryItems.Add(checkEdit);
|
|
gridColumn.ColumnEdit = checkEdit;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:列菜单配置</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-08-09 </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 OnPopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (e.Menu.MenuType == TreeListMenuType.Column)
|
|
{
|
|
TreeList treeList = sender as TreeList;
|
|
TreeListHitInfo hitInfo = treeList.CalcHitInfo(e.Point);
|
|
TreeListMenu columnMenu = e.Menu as TreeListMenu;
|
|
|
|
DXMenuItem itemFixLeft = new DXMenuItem("冻结列", FixLeftItemClick);
|
|
DXMenuItem itemFixLeftAll = new DXMenuItem("冻结列(所有列)", FixLeftAllItemClick);
|
|
DXMenuItem itemUnFix = new DXMenuItem("清除冻结", UnFixItemClick);
|
|
|
|
DXMenuItem itemSaveColumn = new DXMenuItem("保存表格属性", SaveItemClick);
|
|
DXMenuItem itemResetColumn = new DXMenuItem("重置表格属性", ResetItemClick);
|
|
DXMenuItem itemExportColumn = new DXMenuItem("导出表格数据", ExportItemClick);
|
|
DXMenuItem itemPrintColumn = new DXMenuItem("打印表格数据", PrintItemClick);
|
|
DXMenuItem itemSortColumn = new DXMenuItem("清除全部列排序", ClearSortItemClick);
|
|
|
|
itemSaveColumn.BeginGroup = itemFixLeft.BeginGroup = true;
|
|
|
|
itemFixLeft.Tag = itemFixLeftAll.Tag = itemUnFix.Tag = hitInfo.Column;
|
|
itemSaveColumn.Tag = itemResetColumn.Tag = itemExportColumn.Tag = itemPrintColumn.Tag = itemSortColumn.Tag = hitInfo.Column;
|
|
|
|
columnMenu.Items.AddRange(new DXMenuItem[] { itemFixLeft, itemFixLeftAll, itemUnFix });
|
|
if (!string.IsNullOrEmpty(CustomColumKey)) columnMenu.Items.AddRange(new DXMenuItem[] { itemSaveColumn, itemResetColumn });
|
|
columnMenu.Items.AddRange(new DXMenuItem[] { itemExportColumn, itemPrintColumn, itemSortColumn });
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:冻结列点击</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-08-09 </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 override void FixLeftItemClick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
DXMenuItem item = sender as DXMenuItem;
|
|
TreeListColumn column = item.Tag as TreeListColumn;
|
|
column.Fixed = FixedStyle.Left;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:冻结所有列</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-08-09 </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 override void FixLeftAllItemClick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
DXMenuItem item = sender as DXMenuItem;
|
|
TreeListColumn column = item.Tag as TreeListColumn;
|
|
TreeList treeList = sender as TreeList;
|
|
foreach (TreeListColumn col in treeList.Columns)
|
|
{
|
|
if (col.AbsoluteIndex <= column.AbsoluteIndex)
|
|
{
|
|
col.Fixed = FixedStyle.Left;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
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 override void UnFixItemClick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
DXMenuItem item = sender as DXMenuItem;
|
|
TreeListColumn column = item.Tag as TreeListColumn;
|
|
column.Fixed = FixedStyle.None;
|
|
column.VisibleIndex = column.AbsoluteIndex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置编辑列</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-08-09 </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>
|
|
public override void SetEditColumns(DataTable table, string customColumKey = "")
|
|
{
|
|
if (table == null) return;
|
|
this.CustomColumKey = customColumKey;
|
|
for (int i = 0; i < table.Rows.Count; i++)
|
|
{
|
|
GridColumnModel model = new GridColumnModel(table.Rows[i]);
|
|
TreeListColumn gridColumn = new TreeListColumn();
|
|
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;
|
|
gridColumn.OptionsColumn.AllowEdit = model.Edit;
|
|
|
|
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;
|
|
}
|
|
|
|
gridColumn.OptionsFilter.FilterPopupMode = FilterPopupMode.CheckedList;
|
|
gridColumn.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
|
|
|
|
|
|
if (!string.IsNullOrEmpty(model.AutoPadDataReleColName))
|
|
{
|
|
AutoPadDataReleColList.Add(model);
|
|
}
|
|
|
|
|
|
// 设置列格式化、汇总
|
|
this.SetColumnFormat(gridColumn, model);
|
|
this.SetColumnSumming(gridColumn, model);
|
|
// 创建列
|
|
this.InitEditColumns(gridColumn, model);
|
|
this.gcMain.Columns.AddRange(new TreeListColumn[] { gridColumn });
|
|
this.ColumnList.Add(model);
|
|
}
|
|
DataTable customTable = this.gcMain.GetCustomColumnByDatabase(this.CustomColumKey);
|
|
this.SetCustomColumns(customTable);
|
|
|
|
// 延迟加载数据源
|
|
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
|
|
{
|
|
foreach (GridColumnModel item in mControlList)
|
|
{
|
|
if (ControlType.IsNotLoadData(item.FieldType)) continue;
|
|
DataTable 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 = this.gcMain.Columns[item.FieldName].ColumnEdit as RepositoryItemLookUpEdit;
|
|
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 = this.gcMain.Columns[item.FieldName].ColumnEdit as RepositoryItemGridLookUpEdit;
|
|
DataTable table = dataTable;
|
|
lookGridUp.DataSource = table;
|
|
|
|
if (table.Columns.Contains("remark") && lookGridUp.View.Columns.FirstOrDefault(x => x.FieldName == "remark") == null)
|
|
{
|
|
DevExpress.XtraGrid.Columns.GridColumn remarkColumn = new DevExpress.XtraGrid.Columns.GridColumn();
|
|
remarkColumn.Caption = "备注";
|
|
remarkColumn.Name = remarkColumn.FieldName = "remark";
|
|
remarkColumn.Visible = true;
|
|
lookGridUp.View.Columns.Add(remarkColumn);
|
|
}
|
|
|
|
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))
|
|
{
|
|
DevExpress.XtraGrid.Columns.GridColumn otherColumn = new DevExpress.XtraGrid.Columns.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)
|
|
{
|
|
DevExpress.XtraGrid.Columns.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;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
finally
|
|
{
|
|
if (this.OnDataSourceBindCallBack != null) this.OnDataSourceBindCallBack(null, null);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.mTimer.Stop();
|
|
this.mTimer.Dispose();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <para>说明:设置编辑列</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-08-09 </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>
|
|
public void InitializeTreeMethod()
|
|
{
|
|
this.TreeListObj.CellValueChanging += new DevExpress.XtraTreeList.CellValueChangedEventHandler(OnCellValueChaning);
|
|
}
|
|
|
|
|
|
protected void OnCellValueChaning(object sender, CellValueChangedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
TreeListColumn gridColumn = e.Column;
|
|
SetCheckedChildNodes(e.Node, e.Value, gridColumn);
|
|
SetCheckedParentNodes(e.Node, e.Value, gridColumn);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置子节点的状态</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2020-05-12 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="node">The node.</param>
|
|
/// <param name="check">The check.</param>
|
|
/// <param name="gridColumn">The grid column.</param>
|
|
protected void SetCheckedChildNodes(DevExpress.XtraTreeList.Nodes.TreeListNode node, Object check, TreeListColumn gridColumn)
|
|
{
|
|
for (int i = 0; i < node.Nodes.Count; i++)
|
|
{
|
|
node.Nodes[i].SetValue(gridColumn, check);
|
|
SetCheckedChildNodes(node.Nodes[i], check, gridColumn);
|
|
}
|
|
node.SetValue(gridColumn, check);
|
|
SetCheckedParentNodes(node, check, gridColumn);
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置父节点的状态</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2020-05-12 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="node">The node.</param>
|
|
/// <param name="check">The check.</param>
|
|
/// <param name="gridColumn">The grid column.</param>
|
|
protected void SetCheckedParentNodes(DevExpress.XtraTreeList.Nodes.TreeListNode node, Object check, TreeListColumn gridColumn)
|
|
{
|
|
if (node.ParentNode != null)
|
|
{
|
|
bool b = false;
|
|
int state;
|
|
for (int i = 0; i < node.ParentNode.Nodes.Count; i++)
|
|
{
|
|
state = (int)(node.ParentNode.Nodes[i].GetValue(gridColumn));
|
|
if ((int)check != state)
|
|
{
|
|
b = !b;
|
|
break;
|
|
}
|
|
}
|
|
node.ParentNode.SetValue(gridColumn, b ? CheckState.Indeterminate : check);
|
|
SetCheckedParentNodes(node.ParentNode, check, gridColumn);
|
|
}
|
|
}
|
|
/// <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.gcMain.Appearance.Row.Font = new Font("微软雅黑", SystemInfo.Instance.GridRowFontSize);
|
|
if (SystemInfo.Instance.GridRowHeight > 0)
|
|
{
|
|
this.gcMain.ColumnPanelRowHeight = this.gcMain.RowHeight = SystemInfo.Instance.GridRowHeight;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:保存树表格表格属性</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2019-11-14 </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 override void SaveItemClick(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(this.CustomColumKey))
|
|
{
|
|
MessageUtil.Show(ResourceKeys.NotSettingResetColumn);
|
|
return;
|
|
}
|
|
|
|
DataRow rowItem = null;
|
|
bool success = BaseImpl.HasExistsDataRow(ResourceKeys.SettingTableName, "formKey", CustomColumKey.ToString(), string.Format(" and OperatorName='{0}' ", ERPInfo.Instance.UserName), out rowItem);
|
|
if (!success)
|
|
{
|
|
MessageUtil.Show(ResourceKeys.NotFoundSettingColumnTable);
|
|
return;
|
|
}
|
|
|
|
if (MessageUtil.Show(ResourceKeys.IsSaveColumn, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
|
{
|
|
try
|
|
{
|
|
if (rowItem == null)
|
|
{
|
|
success = this.gcMain.SaveCustomColumnToDatabase(this.CustomColumKey);
|
|
}
|
|
else
|
|
{
|
|
success = this.gcMain.UpdateCustomColumnToDatabase(this.CustomColumKey);
|
|
}
|
|
|
|
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)
|
|
{
|
|
|
|
LogUtil.WriteError("保存表格属性出错", ex);
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:重置树表格属性</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2019-11-14 </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 override 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.gcMain.ResetCustomColumnToDatabase(this.CustomColumKey);
|
|
|
|
DataTable customTable = this.gcMain.GetCustomColumnByDatabase(this.CustomColumKey);
|
|
this.SetCustomColumns(customTable, false);
|
|
MessageUtil.Show(success ? ResourceKeys.ResetSuccess : ResourceKeys.ResetFault);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
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>
|
|
/// <param name="gridColumn">The grid column.</param>
|
|
/// <param name="model">The model.</param>
|
|
private void SetColumnFormat(TreeListColumn gridColumn, GridColumnModel model)
|
|
{
|
|
if (gridColumn == null || model == null) return;
|
|
|
|
// 格式化数字
|
|
if (!string.IsNullOrEmpty(model.DataFormat))
|
|
{
|
|
if (model.FieldType == ControlType.LabTextInt || model.FieldType == ControlType.LabCalcText)
|
|
{
|
|
gridColumn.Format.FormatType = FormatType.Numeric;
|
|
gridColumn.Format.FormatString = model.DataFormat;
|
|
}
|
|
else
|
|
{
|
|
gridColumn.Format.FormatType = FormatType.Custom;
|
|
gridColumn.Format.FormatString = model.DataFormat;
|
|
}
|
|
}
|
|
// 特殊字段格式化
|
|
if (model.CanAccuracy)
|
|
{
|
|
gridColumn.Format.FormatType = FormatType.Numeric;
|
|
gridColumn.Format.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>
|
|
private void SetColumnSumming(TreeListColumn gridColumn, GridColumnModel model)
|
|
{
|
|
// 设置底部合计
|
|
if (gridColumn.VisibleIndex == 0)
|
|
{
|
|
gcMain.OptionsView.ShowSummaryFooter = true;
|
|
gridColumn.AllNodesSummary = true;
|
|
gridColumn.SummaryFooter = SummaryItemType.Count;
|
|
gridColumn.SummaryFooterStrFormat = "合计:{0:#,###}行";
|
|
}
|
|
else
|
|
{
|
|
if (model.CanSum)
|
|
{
|
|
gcMain.OptionsView.ShowSummaryFooter = true;
|
|
gridColumn.AllNodesSummary = true;
|
|
gridColumn.SummaryFooter = DevExpress.XtraTreeList.SummaryItemType.Sum;
|
|
gridColumn.SummaryFooterStrFormat = "{0:" + model.DataFormat + "}";
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置树表格自定义列</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2019-11-14 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
protected override 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)
|
|
{
|
|
foreach (DataRow rowItem in customTable.Rows)
|
|
{
|
|
string fieldName = rowItem["fieldName"] + "";
|
|
int fieldWidth = Convert.ToInt32(rowItem["fieldWidth"]);
|
|
int index = Convert.ToInt32(rowItem["orderid"]);
|
|
bool visible = "1".Equals(rowItem["isVisible"] + "") && fieldWidth > 0;
|
|
bool isFix = "True".Equals(rowItem["IfFixColumn"] + "", StringComparison.OrdinalIgnoreCase);
|
|
|
|
GridColumnModel column = this.ColumnList.Find(x => x.FieldName == fieldName);
|
|
TreeListColumn gridColumn = this.gcMain.Columns.ColumnByName(fieldName);
|
|
if (column != null && gridColumn != null && gridColumn.Visible && gridColumn.Width > 0)
|
|
{
|
|
TreeListColumn colObj = this.gcMain.Columns[fieldName];
|
|
colObj.VisibleIndex = index;
|
|
colObj.Width = fieldWidth;
|
|
colObj.Visible = visible;
|
|
colObj.Fixed = isFix ? FixedStyle.Left : FixedStyle.None;
|
|
}
|
|
}
|
|
}
|
|
if (!isInit)
|
|
{
|
|
// 非初始化,假如未配置则初始化到系统配置
|
|
for (int i = 0; i < this.ColumnList.Count; i++)
|
|
{
|
|
GridColumnModel column = this.ColumnList[i];
|
|
if (this.gcMain.Columns.ColumnByName(column.FieldName) != null)
|
|
{
|
|
TreeListColumn colObj = this.gcMain.Columns[column.FieldName];
|
|
colObj.VisibleIndex = i;
|
|
colObj.Width = column.Width;
|
|
colObj.Visible = column.Visible;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>说明:监听树表格键盘事件</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2019-11-04 </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 OnTreeGridViewKeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
|
|
// 替换本列下所有数据为当前单元格数据
|
|
if (e.KeyCode == Keys.F6 || e.KeyCode == Keys.F7)
|
|
{
|
|
TreeListColumn column = this.gcMain.FocusedColumn;
|
|
GridColumnModel model = column.Tag as GridColumnModel;
|
|
if (column != null &&
|
|
column.OptionsColumn.AllowEdit &&
|
|
this.gcMain.Nodes.Count > 0 &&
|
|
this.gcMain.OptionsBehavior.Editable)
|
|
{
|
|
// 允许操作
|
|
//焦点行节点
|
|
TreeListNode focusedNode = gcMain.FocusedNode;
|
|
//获取当前界面上排序的节点
|
|
List<TreeListNode> dataSourceInTreeListOrder = GetDataSourceInTreeListOrder();
|
|
//选中行
|
|
DataRow FocusedRow = GetViewSpecifyDataRow(focusedNode);
|
|
//当前选中行,在界面上的行数
|
|
int focusedRowHandle = dataSourceInTreeListOrder.IndexOf(focusedNode);
|
|
//界面上的全部数据条数
|
|
int totalRowCount = dataSourceInTreeListOrder.Count;
|
|
//操作的单元格
|
|
List<TreeListCell> cells = this.gcMain.GetSelectedCells();
|
|
|
|
if (cells.Count == 1 && focusedRowHandle + 1 < totalRowCount)
|
|
{
|
|
if (MessageUtil.Show(e.KeyCode == Keys.F6 ? ResourceKeys.IsReplaceAllEmptyColumn : ResourceKeys.IsReplaceAllColumn, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
|
{
|
|
WaitForm.ShowForm("数据填充中");
|
|
object obj = focusedNode.GetValue(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++)
|
|
{
|
|
//选中节点下方的节点,和对应的行
|
|
TreeListNode node = dataSourceInTreeListOrder[i];
|
|
DataRow dr = GetViewSpecifyDataRow(node);
|
|
//如果有修改提交就验证,不合的就不会改变值
|
|
if (!string.IsNullOrWhiteSpace(ModifyCond))
|
|
{
|
|
// 检查条件
|
|
if (!ValidateCond(ModifyCond, dr)) continue;
|
|
}
|
|
|
|
if (e.KeyCode == Keys.F6)
|
|
{
|
|
object obj2 = dr[column.FieldName];
|
|
// F6 覆盖当前列下所有为空的列
|
|
if (string.IsNullOrEmpty(obj2 + ""))
|
|
{
|
|
dr[column.FieldName] = obj;
|
|
if (!string.IsNullOrEmpty(model.UnionFields))
|
|
{
|
|
this.SetUnionValue(model, obj + "", node);
|
|
}
|
|
//计算规则配置在结果字段上,所以无需验证当前操作控件
|
|
this.SetCalcValue(model, obj + "", node);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// F7 覆盖当前列下所有列
|
|
dr[column.FieldName] = obj;
|
|
if (!string.IsNullOrEmpty(model.UnionFields))
|
|
{
|
|
this.SetUnionValue(model, obj + "", node);
|
|
}
|
|
//计算规则配置在结果字段上,所以无需验证当前操作控件
|
|
this.SetCalcValue(model, obj + "", node);
|
|
}
|
|
|
|
}
|
|
|
|
gcMain.PostEditor();
|
|
//if (isFilterContain)
|
|
//{
|
|
// gridView.FocusedRowHandle = gridView.FocusedRowHandle - 1;
|
|
//}
|
|
e.Handled = true;
|
|
}
|
|
WaitForm.HideForm();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 已当前列为基准,按顺序生成本列数据
|
|
if (e.KeyCode == Keys.F8)
|
|
{
|
|
TreeListColumn column = this.gcMain.FocusedColumn;
|
|
if (column != null &&
|
|
column.OptionsColumn.AllowEdit &&
|
|
this.gcMain.Nodes.Count > 0 &&
|
|
this.gcMain.OptionsBehavior.Editable)
|
|
{
|
|
// 允许操作
|
|
TreeListNode focusedNode = gcMain.FocusedNode;
|
|
//获取当前界面上排序的节点
|
|
List<TreeListNode> dataSourceInTreeListOrder = GetDataSourceInTreeListOrder();
|
|
//选中行
|
|
DataRow FocusedRow = GetViewSpecifyDataRow(focusedNode);
|
|
//当前选中行,在界面上的行数
|
|
int focusedRowHandle = dataSourceInTreeListOrder.IndexOf(focusedNode);
|
|
//界面上的全部数据条数
|
|
int totalRowCount = dataSourceInTreeListOrder.Count;
|
|
//操作的单元格
|
|
List<TreeListCell> cells = this.gcMain.GetSelectedCells();
|
|
|
|
if (cells.Count == 1 && focusedRowHandle + 1 < totalRowCount)
|
|
{
|
|
if (MessageUtil.Show(ResourceKeys.IsGenerateAllColumn, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
|
{
|
|
bool isExec = false;
|
|
int value = 0;
|
|
int valueNum = 0;
|
|
object obj = focusedNode.GetValue(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.ToInt32(rightString);
|
|
for (int i = focusedRowHandle; i < totalRowCount; i++)
|
|
{
|
|
//选中节点下方的节点,和对应的行
|
|
TreeListNode node = dataSourceInTreeListOrder[i];
|
|
gcMain.SetFocusedNode(node);
|
|
node.SetValue(column, leftString + value.ToString().PadLeft(valueNum, '0'));
|
|
gcMain.PostEditor();
|
|
value++;
|
|
}
|
|
e.Handled = true;
|
|
}
|
|
else
|
|
{
|
|
if (MessageUtil.Show(ResourceKeys.SelectColumnValueTypeNotNumber, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
|
{
|
|
value = 1;
|
|
for (int i = focusedRowHandle; i <= totalRowCount; i++)
|
|
{
|
|
TreeListNode node = dataSourceInTreeListOrder[i];
|
|
gcMain.SetFocusedNode(node);
|
|
node.SetValue(column, value);
|
|
gcMain.PostEditor();
|
|
value++;
|
|
}
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// 复制单元格
|
|
if (e.Control && e.KeyCode == Keys.C)
|
|
{
|
|
var selectNodes = this.gcMain.Selection;
|
|
if (selectNodes != null && selectNodes.Count == 1)
|
|
{
|
|
//object obj = gridView.GetFocusedRowCellValue(gridView.FocusedColumn);
|
|
object obj = this.gcMain.FocusedNode.GetDisplayText(this.gcMain.FocusedColumn);
|
|
if (obj != null)
|
|
{
|
|
Clipboard.SetDataObject(obj + "");
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
else if (selectNodes != null && selectNodes.Count > 1)
|
|
{
|
|
DataRow[] dataRows = new DataRow[selectNodes.Count];
|
|
string copySummary = string.Empty;
|
|
for (int i = 0; i < selectNodes.Count; i++)
|
|
{
|
|
TreeListNode treeNode = selectNodes[i];
|
|
List<TreeListColumn> cells = gcMain.GetSelectedCells(treeNode);
|
|
DataRowView dataRowView = this.gcMain.GetDataRecordByNode(treeNode) as DataRowView;
|
|
dataRows[i] = dataRowView != null ? dataRowView.Row : null;
|
|
foreach (TreeListColumn cell in cells)
|
|
{
|
|
copySummary += dataRows[i][cell.Name] + "\t";
|
|
}
|
|
copySummary += "\n";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(copySummary))
|
|
{
|
|
copySummary = copySummary.TrimEnd('\n');
|
|
Clipboard.SetDataObject(copySummary);
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
gcMain.CopyToClipboard();
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
else if (e.Modifiers.CompareTo(Keys.Control) == 0 && e.KeyCode == Keys.V)
|
|
{
|
|
//if (this.gridView.IsFindPanelVisible)
|
|
//{
|
|
// MessageUtil.Show("搜索模式下无法粘贴行.");
|
|
// return;
|
|
//}
|
|
TreeListColumn column = this.gcMain.FocusedColumn;
|
|
GridColumnModel model = column.Tag as GridColumnModel;
|
|
if (column != null &&
|
|
column.OptionsColumn.AllowEdit &&
|
|
this.gcMain.Nodes.Count > 0 &&
|
|
this.gcMain.OptionsBehavior.Editable)
|
|
{
|
|
object _objData = null;
|
|
IDataObject dataObj = Clipboard.GetDataObject();
|
|
|
|
if (dataObj.GetDataPresent(DataFormats.Text))
|
|
_objData = dataObj.GetData(DataFormats.Text);
|
|
NewPasteMethod(e, _objData);
|
|
}
|
|
|
|
}
|
|
else if (e.Control && e.KeyCode == Keys.F)
|
|
{
|
|
this.gcMain.ShowFindPanel();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
/// <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 override DataRow GetViewFocusedDataRow()
|
|
{
|
|
TreeListNode treeNode = this.gcMain.FocusedNode as TreeListNode;
|
|
|
|
if (treeNode != null)
|
|
{
|
|
DataRowView dataRowView = this.gcMain.GetDataRecordByNode(treeNode) as DataRowView;
|
|
return dataRowView != null ? dataRowView.Row : null;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/// <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 DataRow GetViewSpecifyDataRow(TreeListNode treeNode)
|
|
{
|
|
if (treeNode != null)
|
|
{
|
|
DataRowView dataRowView = this.gcMain.GetDataRecordByNode(treeNode) as DataRowView;
|
|
return dataRowView != null ? dataRowView.Row : null;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
|
|
/// <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 override DataRow[] GetViewFocusedDataRows()
|
|
{
|
|
var selectNodes = this.gcMain.Selection;
|
|
DataRow[] dataRows = new DataRow[selectNodes.Count];
|
|
|
|
for (int i = 0; i < selectNodes.Count; i++)
|
|
{
|
|
TreeListNode treeNode = selectNodes[i];
|
|
DataRowView dataRowView = this.gcMain.GetDataRecordByNode(treeNode) as DataRowView;
|
|
dataRows[i] = dataRowView != null ? dataRowView.Row : null;
|
|
}
|
|
return dataRows;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:获取数据源</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-30 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="table">The table.</param>
|
|
/// <param name="selectRowHandler">if set to <c>true</c> [select row handler].</param>
|
|
public DataTable GetGridViewDataSource()
|
|
{
|
|
return this.gcMain.DataSource as DataTable;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置数据源</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-30 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="table">The table.</param>
|
|
/// <param name="selectRowHandler">if set to <c>true</c> [select row handler].</param>
|
|
public override void SetGridViewDataSource(DataTable table, bool selectRowHandler = true)
|
|
{
|
|
lastNodeIndex = 0;
|
|
if (selectRowHandler) lastNodeIndex = this.TreeListObj.GetVisibleIndexByNode(this.TreeListObj.FocusedNode);
|
|
GetTreeExpanded();
|
|
this.gcMain.ClearNodes();
|
|
this.gcMain.DataSource = table;
|
|
}
|
|
public override int SetGridViewDataSource(SqlDataAdapter adapter, bool selectRowHandler = true)
|
|
{
|
|
if (adapter == null) return 0;
|
|
lastNodeIndex = 0;
|
|
if (selectRowHandler) lastNodeIndex = this.TreeListObj.GetVisibleIndexByNode(this.TreeListObj.FocusedNode);
|
|
this.AdapterObj = adapter;
|
|
DataSet dataSet = new DataSet();
|
|
adapter.Fill(dataSet, "SetGridViewDataSource");
|
|
|
|
SqlCommandBuilder cb = new SqlCommandBuilder(this.AdapterObj);
|
|
|
|
GetTreeExpanded();
|
|
this.gcMain.DataSource = dataSet.Tables[0];
|
|
|
|
|
|
return dataSet.Tables[0] != null ? dataSet.Tables[0].Rows.Count : 0;
|
|
}
|
|
/// <summary>
|
|
/// 记录展开的节点
|
|
/// </summary>
|
|
public void GetTreeExpanded()
|
|
{
|
|
|
|
treeListNodes.Clear();
|
|
foreach (TreeListNode n in this.gcMain.Nodes)
|
|
{
|
|
setRecursive(n);
|
|
}
|
|
}
|
|
|
|
|
|
public void setRecursive(TreeListNode treeNode)
|
|
{
|
|
if (treeNode.Expanded) treeListNodes.Add(treeNode);
|
|
// Visit each node recursively.
|
|
foreach (TreeListNode tn in treeNode.Nodes)
|
|
{
|
|
setRecursive(tn);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <para>说明:全部展开</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-08-13 </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>
|
|
private void OnAllExpandClick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
this.gcMain.ExpandAll();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:全部合并</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-08-13 </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>
|
|
private void OnAllMergeClick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
this.gcMain.CollapseAll();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
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 OnAutoSearchEditPopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (e.MenuType == DevExpress.XtraGrid.Views.Grid.GridMenuType.Column)
|
|
{
|
|
CurrentOperGridView = e.HitInfo.View;
|
|
|
|
DevExpress.XtraGrid.Menu.GridViewColumnMenu columnMenu = e.Menu as DevExpress.XtraGrid.Menu.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);
|
|
}
|
|
|
|
}
|
|
|
|
private void gridLookUpEdit1_EditValueChanging(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 (string.IsNullOrWhiteSpace(edit.AutoSearchText) && e.NewValue == "")
|
|
{
|
|
DataRow newRow = dt.NewRow();
|
|
if (dt.Rows.Cast<DataRow>().FirstOrDefault(x => x == newRow) == null)
|
|
{
|
|
dt.Rows.Add(newRow.ItemArray);
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
private void FilterLookup(object sender, string NewValue)
|
|
{
|
|
try
|
|
{
|
|
GridLookUpEdit edit = sender as GridLookUpEdit;
|
|
DevExpress.XtraGrid.Views.Grid.GridView gridView = edit.Properties.View as DevExpress.XtraGrid.Views.Grid.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 (DevExpress.XtraGrid.Columns.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);
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 隐藏自动搜索框的过滤面板
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnCustomDrawFilterPanel(object sender, DevExpress.XtraGrid.Views.Base.CustomDrawObjectEventArgs e)
|
|
{
|
|
GridFilterPanelInfoArgs info = e.Info as DevExpress.XtraGrid.Drawing.GridFilterPanelInfoArgs;
|
|
info.ShowCloseButton = false;
|
|
info.ShowCustomizeButton = false;
|
|
info.ShowActiveButton = false;
|
|
e.Handled = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 数据源中点击将数据源更新
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void View_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
DevExpress.XtraGrid.Views.Grid.GridView gridView = sender as DevExpress.XtraGrid.Views.Grid.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);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <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-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;
|
|
popupedit.Properties.PopupControl.Width = popupedit.Width;
|
|
|
|
popupedit.Properties.PopupControl.Height = (int)(popupedit.Width * 1.1);
|
|
}
|
|
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.TreeViewExObj.DataSource.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>说明:表格打开模块返回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.SourceSQL = model.SqlSource.Replace("#", "");
|
|
//单据头关联取值
|
|
if (this.ParentControl != null)
|
|
{
|
|
modelLookUp.SourceSQL = this.ParentControl.ReplaceControlValue(modelLookUp.SourceSQL);
|
|
}
|
|
|
|
modelLookUp.SourceSQL = ReplaceHelper.ReplaceRowParam(this.GetViewFocusedDataRow(), modelLookUp.SourceSQL);
|
|
//modelLookUp.DataSource = BaseImpl.GetDataTableResult(modelLookUp.SourceSQL);
|
|
modelLookUp.InitControls(modelLookUp.UnionModuleCodel);
|
|
DialogResult result = modelLookUp.ShowDialog();
|
|
if (result == DialogResult.OK)
|
|
{
|
|
TreeListObj.ShowEditor();
|
|
btnEdit.EditValue = modelLookUp.EditValue;
|
|
TreeListObj.PostEditor();
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:表格打开模块返回id</para>
|
|
/// <para>创建人:曹屹峰</para>
|
|
/// <para>创建日期:2021-08-23 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
protected void OnModuleChoiceNew(object sender, ButtonPressedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
CheckedComboBoxEdit btnEdit = (CheckedComboBoxEdit)sender;
|
|
FrmModelLookUp2 modelLookUp = e.Button.Tag as FrmModelLookUp2;
|
|
|
|
GridColumnModel model = modelLookUp.Tag as GridColumnModel;
|
|
modelLookUp.EditText = btnEdit.Text;
|
|
modelLookUp.CurrentOperColumnKey = Model.ModuleCode + "_" + model.FieldName;
|
|
modelLookUp.EditText = btnEdit.Text;
|
|
modelLookUp.EditValue = btnEdit.EditValue + "";
|
|
//多选关联单据头
|
|
string SourceSQL = modelLookUp.SysModel.MenuSql.Replace("#", "") + model.SplicingConditions;
|
|
//单据头关联取值
|
|
if (this.ParentControl != null)
|
|
{
|
|
SourceSQL = this.ParentControl.ReplaceControlValue(SourceSQL);
|
|
}
|
|
|
|
modelLookUp.NewSourceSQL = ReplaceHelper.ReplaceRowParam(this.GetViewFocusedDataRow(), SourceSQL);
|
|
modelLookUp.AddModuleResult = model.addModuleResult;
|
|
modelLookUp.InitControls(modelLookUp.UnionModuleCodel);
|
|
DialogResult result = modelLookUp.ShowDialog();
|
|
if (result == DialogResult.OK)
|
|
{
|
|
TreeListObj.ShowEditor();
|
|
btnEdit.EditValue = modelLookUp.EditValue;
|
|
TreeListObj.PostEditor();
|
|
string[] resultFields = model.addModuleResult.Trim().Split(',');
|
|
DataRow focusedRow = this.GetViewFocusedDataRow();
|
|
if (focusedRow != null)
|
|
{
|
|
foreach (string resultKey in modelLookUp.ModuleResultDic.Keys)
|
|
{
|
|
string resultValue = modelLookUp.ModuleResultDic[resultKey];
|
|
if (focusedRow.Table.Columns.Contains(resultKey))
|
|
{
|
|
focusedRow[resultKey] = resultValue;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>说明:表格打开模块返回数据源行</para>
|
|
/// <para>创建人:唐德馨</para>
|
|
/// <para>创建日期: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.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.GetViewFocusedDataRow(), 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.GetViewFocusedDataRow();
|
|
if (!string.IsNullOrEmpty(model.SqlSource))
|
|
{
|
|
foreach (DevExpress.XtraGrid.Columns.GridColumn gridColumn in this.gcMain.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>创建日期:2020-10-30 </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>
|
|
private void OnCustomDrawNodeCell(object sender, CustomDrawNodeCellEventArgs e)
|
|
{
|
|
if (e.Node == this.gcMain.FocusedNode)
|
|
e.Appearance.BackColor = ColorTranslator.FromHtml("#9feb6a");
|
|
}
|
|
/// <summary>
|
|
/// 粘贴功能
|
|
/// </summary>
|
|
/// <param name="e"></param>
|
|
/// <param name="_objData"></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;
|
|
TreeListColumn focColumn = this.gcMain.FocusedColumn;
|
|
focColumn = focColumn == null ? this.gcMain.Columns[0] : focColumn;
|
|
if (focColumn != null)
|
|
{
|
|
DataTable table = this.GetGridViewDataSource();
|
|
int beforeNumber = table.Rows.Count;
|
|
_rowNumber = this.gcMain.GetVisibleIndexByNode(this.gcMain.FocusedNode);
|
|
if (_rowNumber < 0)
|
|
{
|
|
_rowNumber = 0;
|
|
}
|
|
if (_arrayRowStr.Length != this.gcMain.Selection.Count)
|
|
{
|
|
//选择区域与粘贴行数不匹配
|
|
}
|
|
_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);
|
|
TreeListColumnCollection gridColumns = this.gcMain.Columns;
|
|
this.gcMain.FocusedNode = this.gcMain.GetNodeByVisibleIndex(_rowNumber);
|
|
foreach (TreeListColumn 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.gcMain.FocusedNode = this.gcMain.GetNodeByVisibleIndex(_rowNumber);
|
|
if (_arrayStr2.Length == 0)
|
|
_arrayStr2[0] = _arrayRowStr[i];
|
|
int _colNumber = beforeNumber == 0 ? 0 : focColumn.VisibleIndex;
|
|
|
|
for (int j = 0; j < _arrayStr2.Length; j++)//j = _colNumber
|
|
{
|
|
TreeListColumn col = this.gcMain.VisibleColumns[_colNumber];
|
|
|
|
GridColumnModel model = col.Tag as GridColumnModel;
|
|
if (model != null && (model.CanCopy || ((this.gcMain.OptionsBehavior.Editable) && (this.gcMain.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;
|
|
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)
|
|
{
|
|
DataRow dataRow = this.GetViewFocusedDataRow();
|
|
dataRow[this.gcMain.FocusedColumn.FieldName] = 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 < this.gcMain.Columns.Count; j++)
|
|
{
|
|
if (this.gcMain.Columns[j].Tag == null) continue;
|
|
if ((this.gcMain.Columns[j].Tag as GridColumnModel).LimitLength > 0)
|
|
{
|
|
int MaxInputLength = System.Text.Encoding.Default.GetBytes(newRow[this.gcMain.Columns[j].FieldName].ToString()).Length;
|
|
if (MaxInputLength > (this.gcMain.Columns[j].Tag as GridColumnModel).LimitLength)
|
|
{
|
|
newRow.SetColumnError(newRow.Table.Columns[this.gcMain.Columns[j].FieldName], "当前输入文本超过设定长度!");//不满足条件设置错误信息
|
|
}
|
|
}
|
|
}
|
|
table.Rows.Add(newRow);
|
|
//this.gridView.FocusedRowHandle = _rowNumber - 1;
|
|
}
|
|
else
|
|
{
|
|
//this.gcMain.UpdateCurrentRow();
|
|
}
|
|
}
|
|
this.gcMain.ShowEditor();
|
|
e.Handled = true;
|
|
//SendKeys.Send("{Esc}");
|
|
}
|
|
}
|
|
}
|
|
/// <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>说明:绑定数据源并重新生成节点id</para>
|
|
/// <para>创建人:曹屹峰</para>
|
|
/// <para>创建日期:2024-03-05 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="table">传入的数据源</param>
|
|
public void SetGridViewDataSourceGenerateID(DataTable table)
|
|
{
|
|
DataRow[] dataRows = table.Rows.Cast<DataRow>().Where(x => string.IsNullOrWhiteSpace(x[TreeListObj.KeyFieldName] + "")).ToArray();
|
|
|
|
//传入的表格全部没有节点id,生成id后设置为数据源
|
|
if (table.Rows.Count == dataRows.Length)
|
|
{
|
|
int i = 1;
|
|
foreach (DataRow item in table.Rows)
|
|
{
|
|
item[TreeListObj.KeyFieldName] = i;
|
|
i++;
|
|
}
|
|
this.SetGridViewDataSource(table);
|
|
}
|
|
else
|
|
{
|
|
//没有节点id的行赋值当前最大id
|
|
foreach (DataRow item in dataRows)
|
|
{
|
|
int maxid = int.Parse(table.Rows.Cast<DataRow>().Max(n => n[TreeListObj.KeyFieldName]) + "") + 1;
|
|
item[TreeListObj.KeyFieldName] = maxid + "";
|
|
}
|
|
this.SetGridViewDataSource(table);
|
|
}
|
|
|
|
if ((Expansion + "").Equals("1"))
|
|
{
|
|
this.gcMain.ExpandAll();
|
|
}
|
|
else if ((Expansion + "").Equals("2"))
|
|
{
|
|
this.gcMain.CollapseAll();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取新增节点id
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string GetNewNodesId()
|
|
{
|
|
int id = 1;
|
|
DataTable gridTable = (this.gcMain.DataSource as DataTable).TrimDeleteRows();
|
|
//获取表里最大的节点id
|
|
if (gridTable != null && gridTable.Rows.Count > 0)
|
|
{
|
|
string maxid = gridTable.Rows.Cast<DataRow>().Max(n => n[TreeListObj.KeyFieldName]) + "";
|
|
if (!string.IsNullOrWhiteSpace(maxid) && int.Parse(maxid) > 0)
|
|
{
|
|
id = int.Parse(maxid) + 1;
|
|
}
|
|
}
|
|
|
|
return id + "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>说明:数据源重新生成节点id</para>
|
|
/// <para>创建人:曹屹峰</para>
|
|
/// <para>创建日期:2024-03-05 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
public void GenerateNodeID()
|
|
{
|
|
//树表格当前数据源重新生成id
|
|
DataTable dt = this.gcMain.DataSource as DataTable;
|
|
int i = 1;
|
|
foreach (DataRow item in dt.Rows)
|
|
{
|
|
item[TreeListObj.KeyFieldName] = i;
|
|
i++;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <para>说明:删除选中行</para>
|
|
/// <para>创建人:曹屹峰</para>
|
|
/// <para>创建日期:2024-03-05 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="deleteCond">删除条件</param>
|
|
public void DeleteSelectedRows(string deleteCond = null)
|
|
{
|
|
DataRow[] rows = this.GetViewFocusedDataRows();
|
|
if (rows.Length < 1) return;
|
|
DialogResult result = MessageUtil.Show(string.Format("确定要删除选中的{0}个节点和其对应的子节点?", rows.Length), MessageBoxButtons.YesNo);
|
|
if (result == DialogResult.Yes)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(deleteCond))
|
|
{
|
|
|
|
//没有条件,直接删除选中的数据
|
|
this.TreeListObj.DeleteSelectedNodes();
|
|
}
|
|
else
|
|
{
|
|
//判断选中行是否满足条件,满足就删除
|
|
DataRow[] dataRows = this.GetViewFocusedDataRows();
|
|
List<DataRow> deleteRows = new List<DataRow>();//可以删除的行
|
|
List<string> DeleteFailedRows = new List<string>();//不满足条件,删除失败的行的行号
|
|
//选中行判断条件
|
|
foreach (DataRow rowItem in dataRows)
|
|
{
|
|
string deleteCond2 = ReplaceHelper.ReplaceRowParam(rowItem, deleteCond);
|
|
if (ReplaceHelper.EvalCond(deleteCond2))
|
|
{
|
|
deleteRows.Add(rowItem);
|
|
}
|
|
else
|
|
{
|
|
//int index = dt.Rows.IndexOf(rowItem);
|
|
DeleteFailedRows.Add(rowItem[TreeListObj.KeyFieldName] + "");
|
|
}
|
|
}
|
|
DataTable table = this.gcMain.DataSource as DataTable;
|
|
foreach (DataRow item in deleteRows)
|
|
{
|
|
table.Rows.Remove(item);
|
|
}
|
|
if (DeleteFailedRows != null && DeleteFailedRows.Count > 0)
|
|
{
|
|
MessageUtil.Show("发现如下:" + string.Join(",", DeleteFailedRows.ToArray()) + "节点号的行不满足条件无法删除!");
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("删除成功!");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <para>说明:添加行数据</para>
|
|
/// <para>创建人:曹屹峰</para>
|
|
/// <para>创建日期:2024-03-05 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="dataRow">需要添加的数据行</param>
|
|
/// <param name="node">添加到的节点,如果没有就在最外层添加</param>
|
|
public void AddRowData(DataRow dataRow, TreeListNode node = null)
|
|
{
|
|
string Pid = "0";
|
|
if (node != null)
|
|
{
|
|
Pid = node.Id + "";
|
|
}
|
|
|
|
DataTable gridTable = (this.gcMain.DataSource as DataTable).TrimDeleteRows();
|
|
if (!gridTable.Columns.Contains(ERPInfo.Instance.isAddRows))
|
|
{
|
|
gridTable.Columns.Add(ERPInfo.Instance.isAddRows, typeof(String));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 添加新增空行右键
|
|
/// </summary>
|
|
public void AddRightButton()
|
|
{
|
|
ToolStripMenuItem menuItem1 = new ToolStripMenuItem("新增");
|
|
menuItem1.ImageIndex = 0;
|
|
menuItem1.Click += MenuItem1_Click;
|
|
contextMenuStrip.Items.Add(menuItem1);
|
|
}
|
|
|
|
//新增空行
|
|
private void MenuItem1_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
DataTable gridTable = (this.gcMain.DataSource as DataTable).TrimDeleteRows();
|
|
DataRow tmpRow = gridTable.NewRow();
|
|
int position = gridTable.Rows.Count - 1;
|
|
foreach (GridColumnModel model in this.ColumnList)
|
|
{
|
|
string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue);
|
|
|
|
if (!string.IsNullOrEmpty(model.DefaultValue))
|
|
{
|
|
if (model.DefaultValue.Contains("{ROW"))
|
|
{
|
|
if (position > 0)
|
|
{
|
|
|
|
fieldValue = ReplaceHelper.GetParamFields(model.DefaultValue)[0];
|
|
fieldValue = fieldValue.Replace("}", "").Replace("{", "");
|
|
fieldValue = fieldValue.Substring(fieldValue.IndexOf('_') + 1);
|
|
string topFieldValue = gridTable.Rows[position - 1][fieldValue] + "";
|
|
if (gridTable.Columns[model.FieldName].DataType == typeof(DateTime))
|
|
{
|
|
if (!string.IsNullOrEmpty(topFieldValue)) tmpRow[model.FieldName] = Convert.ToDateTime(topFieldValue);
|
|
}
|
|
else
|
|
{
|
|
tmpRow[model.FieldName] = topFieldValue;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
tmpRow[model.FieldName] = fieldValue;
|
|
}
|
|
}
|
|
}
|
|
tmpRow[this.gcMain.KeyFieldName] = GetNewNodesId();//节点id
|
|
gridTable.Rows.Add(tmpRow);
|
|
this.gcMain.ShowEditor();
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#region 拖拽相关
|
|
/// <summary>
|
|
/// 是否按下alt键
|
|
/// </summary>
|
|
private bool PressAlt = false;
|
|
|
|
/// <summary>
|
|
/// <para>说明:判断是否需要绑定拖拽</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2020-05-22 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
public void InitializedragState()
|
|
{
|
|
try
|
|
{
|
|
this.TreeListObj.AllowDrop = true;
|
|
// 可编辑
|
|
this.TreeListObj.OptionsBehavior.Editable = true;
|
|
//拖动节点
|
|
this.TreeListObj.OptionsBehavior.DragNodes = true;
|
|
//拖拽后执行
|
|
this.TreeListObj.AfterDragNode += TreeListObj_AfterDragNode;
|
|
|
|
|
|
this.TreeListObj.DragDrop += TreeListObj_DragDrop;
|
|
//this.TreeListObj.KeyDown += TreeGridControlEx_KeyDown;
|
|
//this.TreeListObj.KeyUp += TreeGridControlEx_KeyUp;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void TreeGridControlEx_KeyUp(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Menu || e.KeyCode == Keys.Alt)
|
|
{
|
|
PressAlt = false;
|
|
}
|
|
|
|
}
|
|
|
|
private void TreeGridControlEx_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Menu || e.KeyCode == Keys.Alt)
|
|
{
|
|
PressAlt = true;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 拖拽完成时特殊处理
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void TreeListObj_DragDrop(object sender, DragEventArgs e)
|
|
{
|
|
// Alt键被按下,只能在同层级拖拽,拖拽行移动到目标行下方
|
|
if (e.KeyState == 32)
|
|
{
|
|
e.Effect = DragDropEffects.None;
|
|
DataTable dataTable = GetGridViewDataSource();
|
|
|
|
//如果有排序列,所有序号大于目标行的序号的值都+1,拖拽行最后为目标行序号+1
|
|
if (!string.IsNullOrWhiteSpace(this.SortField) && dataTable.Columns.Contains(this.SortField))
|
|
{
|
|
//目标节点
|
|
TreeListHitInfo hitInfo = TreeListObj.CalcHitInfo(TreeListObj.PointToClient(new System.Drawing.Point(e.X, e.Y)));
|
|
TreeListNode TreeListNode = hitInfo.Node;//当前目标节点
|
|
TreeListNode parentNode = TreeListNode.ParentNode; // 获取目标节点的父节点
|
|
int nodeIndex = parentNode == null ? TreeListObj.Nodes.IndexOf(TreeListNode) : parentNode.Nodes.IndexOf(TreeListNode);//当前目标节点的索引
|
|
//拖拽节点
|
|
TreeListNode SelectedNode = this.TreeListObj.FocusedNode;
|
|
TreeListNode SelectedParentNode = TreeListNode.ParentNode; // 获取拖拽节点的父节点
|
|
int SelectedNodeIndex = SelectedParentNode == null ? TreeListObj.Nodes.IndexOf(SelectedNode) : SelectedParentNode.Nodes.IndexOf(SelectedNode);//拖拽节点的索引
|
|
//如果目标节点和拖拽节点的父节点不一样,就证明不在同一层级,直接结束
|
|
if (SelectedNode.ParentNode != parentNode)
|
|
{
|
|
e.Effect = DragDropEffects.None;
|
|
return;
|
|
}
|
|
|
|
DataRow DragRow = (this.gcMain.GetDataRecordByNode(SelectedNode) as DataRowView).Row;//拖拽行
|
|
DataRow TargetRow = (this.gcMain.GetDataRecordByNode(TreeListNode) as DataRowView).Row; //目标行
|
|
int SerialNumber = int.Parse(TargetRow[this.SortField] + "") + 1;//目标行序号+1
|
|
|
|
foreach (DataRow item in dataTable.Rows)
|
|
{
|
|
if (int.Parse(item[this.SortField] + "") >= SerialNumber) item[this.SortField] = int.Parse(item[this.SortField] + "") + 1;
|
|
|
|
}
|
|
DragRow[this.SortField] = int.Parse(TargetRow[this.SortField] + "") + 1;
|
|
|
|
DataView dataView = dataTable.AsDataView();
|
|
dataView.Sort = this.SortField;
|
|
dataTable = dataView.ToTable();
|
|
int NodeIndex = this.TreeListObj.GetVisibleIndexByNode(TreeListNode);
|
|
if (SelectedNodeIndex > nodeIndex) NodeIndex = NodeIndex + 1;//向上方拖,选中行为目标行索引+1
|
|
this.SetGridViewDataSourceGenerateID(dataTable);
|
|
this.TreeListObj.FocusedNode = this.TreeListObj.GetNodeByVisibleIndex(NodeIndex);
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 拖拽后执行
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void TreeListObj_AfterDragNode(object sender, AfterDragNodeEventArgs e)
|
|
{
|
|
DataSourceSorting();
|
|
//强制重新加载数据
|
|
// this.TreeListObj.RefreshDataSource();
|
|
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
#region 排序
|
|
public int NumberValue;
|
|
/// <summary>
|
|
/// 数据源排序(根据界面上显示的效果,重新排序,只改变排序字段)
|
|
/// </summary>
|
|
public void DataSourceSorting()
|
|
{
|
|
DataTable dataTable = GetGridViewDataSource();
|
|
if (!string.IsNullOrWhiteSpace(this.SortField) && dataTable.Columns.Contains(this.SortField))
|
|
{
|
|
this.NumberValue = 1;
|
|
// 遍历TreeList的所有节点
|
|
foreach (TreeListNode node in TreeListObj.Nodes)
|
|
{
|
|
SortAllNodes(node);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private void SortAllNodes(TreeListNode node)
|
|
{
|
|
|
|
DataRow rowItem = (this.gcMain.GetDataRecordByNode(node) as DataRowView).Row;
|
|
rowItem[this.SortField] = NumberValue;
|
|
NumberValue++;
|
|
|
|
// 递归遍历子节点
|
|
foreach (TreeListNode childNode in node.Nodes)
|
|
{
|
|
SortAllNodes(childNode);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
#region 显示行号
|
|
/// <summary>
|
|
/// 显示行号
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void TreeListObj_CustomDrawNodeIndicator(object sender, CustomDrawNodeIndicatorEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
TreeList tree = sender as DevExpress.XtraTreeList.TreeList;
|
|
tree.IndicatorWidth = 30;
|
|
DevExpress.Utils.Drawing.IndicatorObjectInfoArgs args = e.ObjectArgs as DevExpress.Utils.Drawing.IndicatorObjectInfoArgs;
|
|
args.DisplayText = (tree.GetVisibleIndexByNode(e.Node) + 1).ToString();
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 单元格值改变时触发计算和关联
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
public void GcMain_CellValueChanged(object sender, CellValueChangedEventArgs e)
|
|
{
|
|
//TreeListNode aaa = this.gcMain.Nodes[e.Node.Id+1];//获取当前改变行下一行的节点
|
|
//DataRow a = (this.gcMain.GetDataRecordByNode(aaa) as DataRowView).Row;//根据节点获取行数据
|
|
//treeListNode.SetValue(e.Column, "新值"); // 赋值
|
|
|
|
|
|
//当前值改变的节点
|
|
TreeListNode treeListNode = e.Node;
|
|
if (e.Column.Tag == null) return;
|
|
GridColumnModel model = e.Column.Tag as GridColumnModel;
|
|
|
|
//计算列
|
|
if (model.FieldType == 158)
|
|
{
|
|
string result = EvalHelper.Eval2(ReplaceHelper.ReplaceEvalCond(e.Value + "")) + "";
|
|
treeListNode.SetValue(e.Column, result);
|
|
}
|
|
|
|
DataTable dataTable = this.gcMain.DataSource as DataTable;
|
|
int rowHandle = treeListNode.Id;
|
|
|
|
//根据某一列的值自动填充对应值
|
|
if (this.AutoPadDataReleColList.Count > 0)
|
|
{
|
|
foreach (GridColumnModel selectColumnModel in AutoPadDataReleColList)
|
|
{
|
|
if (!string.IsNullOrEmpty(selectColumnModel.AutoPadDataReleColName))
|
|
{
|
|
DataRow FocusedRow = GetViewSpecifyDataRow(treeListNode);
|
|
string value = FocusedRow[selectColumnModel.FieldName] + "";
|
|
//string value = dataTable.Rows[rowHandle][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);
|
|
TreeListNode node = this.gcMain.Nodes[dataSourceIndex];
|
|
selectRow[e.Column.FieldName] = e.Value;
|
|
//关联
|
|
if (!string.IsNullOrEmpty(model.UnionFields))
|
|
{
|
|
this.SetUnionValue(model, e.Value + "", node);
|
|
}
|
|
//计算规则配置在结果字段上,所以无需验证当前操作控件
|
|
this.SetCalcValue(model, e.Value + "", node);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//关联
|
|
if (!string.IsNullOrEmpty(model.UnionFields))
|
|
{
|
|
this.SetUnionValue(model, e.Value + "", treeListNode);
|
|
}
|
|
//计算规则配置在结果字段上,所以无需验证当前操作控件
|
|
this.SetCalcValue(model, e.Value + "", treeListNode);
|
|
this.SetUpperValue(model, treeListNode, e.Value + "");
|
|
this.SetDisableColumn(model, treeListNode, e.Value + "");
|
|
|
|
//验证数据长度
|
|
if (model.LimitLength > 0 && e.Value != null)
|
|
{
|
|
DataRow HandleRow = (this.gcMain.GetDataRecordByNode(treeListNode) as DataRowView).Row;
|
|
int MaxInputLength = System.Text.Encoding.Default.GetBytes(e.Value.ToString()).Length;
|
|
if (model.LimitLength < MaxInputLength)
|
|
HandleRow.SetColumnError(HandleRow.Table.Columns[e.Column.ColumnHandle], "当前输入文本超过设定长度!");//满足条件设置错误信息
|
|
else
|
|
HandleRow.ClearErrors();//清除错误信息
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <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, TreeListNode node)
|
|
{
|
|
DataTable table = this.gcMain.DataSource as DataTable;
|
|
DataRow rowItem = table.Rows.Count == 0 || this.gcMain.FocusedNode != null ? this.GetViewFocusedDataRow() : this.gcMain.FocusedNode == node || node == null ? this.GetViewFocusedDataRow() : (this.gcMain.GetDataRecordByNode(node) as DataRowView).Row;
|
|
|
|
|
|
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, TreeListNode node)
|
|
{
|
|
if (this.GridSumming) return;
|
|
this.GridSumming = true;
|
|
try
|
|
{
|
|
DataTable table = this.gcMain.DataSource as DataTable;
|
|
DataRow rowItem = table.Rows.Count == 0 || this.gcMain.FocusedNode != null ? this.GetViewFocusedDataRow() : this.gcMain.FocusedNode == node || node == null ? this.GetViewFocusedDataRow() : (this.gcMain.GetDataRecordByNode(node) as DataRowView).Row;
|
|
|
|
if (rowItem != null && model != null)
|
|
{
|
|
foreach (TreeListColumn col in this.gcMain.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);
|
|
|
|
result = EvalHelper.Eval2(ReplaceHelper.ReplaceEvalCond(calcExpr)) + "";
|
|
|
|
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);
|
|
}
|
|
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] + "", node);
|
|
}
|
|
}
|
|
}
|
|
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>创建日期: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, TreeListNode node, 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, node);
|
|
}
|
|
}
|
|
}
|
|
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, TreeListNode node)
|
|
{
|
|
DataTable Table = this.gcMain.DataSource as DataTable;
|
|
DataRow rowItem = (this.gcMain.GetDataRecordByNode(node) as DataRowView).Row;
|
|
string UpperFieldName = ReplaceHelper.GetParamFields(gridModel.DefaultValue)[0];
|
|
UpperFieldName = UpperFieldName.Replace("}", "").Replace("{", "");
|
|
UpperFieldName = UpperFieldName.Substring(UpperFieldName.IndexOf('_') + 1);
|
|
if (string.IsNullOrWhiteSpace(rowItem[gridModel.FieldName] + "") || this.gcMain.FocusedNode != node)
|
|
{
|
|
if (node.Id != 0 && Table.Columns.Contains(ERPInfo.Instance.isAddRows))
|
|
{
|
|
if (rowItem[ERPInfo.Instance.isAddRows] + "" != "1")
|
|
{
|
|
rowItem[gridModel.FieldName] = gridModel.DefaultValue.StartsWith("@") ? BaseImpl.GetDefaultValue(ReplaceHelper.ReplaceParamToValue(gridModel.DefaultValue, Table.Rows[node.Id - 1][UpperFieldName] + "")) : rowItem[gridModel.FieldName] = Table.Rows[node.Id - 1][UpperFieldName] + "";
|
|
}
|
|
rowItem[ERPInfo.Instance.isAddRows] = "1";
|
|
}
|
|
if (!string.IsNullOrEmpty(gridModel.UnionFields))
|
|
{
|
|
this.SetUnionValue(gridModel, rowItem[gridModel.FieldName] + "", node);
|
|
}
|
|
|
|
// 计算规则配置在结果字段上,所以无需验证当前操作控件
|
|
this.SetCalcValue(model, rowItem[gridModel.FieldName] + "", node);
|
|
}
|
|
string[] fields = !string.IsNullOrEmpty(gridModel.UnionFields) ? gridModel.UnionFields.Trim(',').Split(',') : new string[] { };
|
|
if (node.Id < Table.Rows.Count - 1 && ((fields.Contains(model.FieldName)) || model.FieldName == UpperFieldName || model.FieldName == gridModel.FieldName))
|
|
{
|
|
if (Table.Columns.Contains(ERPInfo.Instance.isAddRows))
|
|
{
|
|
Table.Rows[node.Id + 1][ERPInfo.Instance.isAddRows] = 0;
|
|
}
|
|
this.OnGridViewtUpperValueChanged(this.gcMain.Columns[gridModel.FieldName], Table.Rows[node.Id + 1][gridModel.FieldName] + "", node.Id + 1, gridModel);
|
|
}
|
|
}
|
|
|
|
/// <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(TreeListColumn Newcolumn, string value, int rowhandle, GridColumnModel gridModel)
|
|
{
|
|
if (Newcolumn == null) return;
|
|
GridColumnModel model = Newcolumn.Tag as GridColumnModel;
|
|
TreeListNode node = this.gcMain.Nodes[rowhandle];
|
|
if (!string.IsNullOrEmpty(model.UnionFields))
|
|
{
|
|
this.SetUnionValue(model, value, node);
|
|
}
|
|
|
|
// 计算规则配置在结果字段上,所以无需验证当前操作控件
|
|
this.SetCalcValue(model, value, node);
|
|
this.UpperChange(model, gridModel, node);
|
|
this.SetDisableColumn(model, node, value);
|
|
}
|
|
|
|
|
|
|
|
/// <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, TreeListNode node, string fieldValue)
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(model.EnableCond))
|
|
{
|
|
GridColumnModel[] columns = this.ColumnList.Where(x => x.EnableCond.Contains("{" + model.FieldName + "}")).ToArray();
|
|
DataRow rowItem = (this.gcMain.GetDataRecordByNode(node) as DataRowView).Row;
|
|
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.gcMain.Columns.ColumnByFieldName(model.FieldName).Visible = ("true".Equals(ValidateCond(disableCond, null) + "", StringComparison.OrdinalIgnoreCase));
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <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>创建日期: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>
|
|
/// 判断树表格是否处于排序状态
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool IsColumnSorted()
|
|
{
|
|
foreach (TreeListColumn column in this.gcMain.Columns)
|
|
{
|
|
if (column.SortIndex > 0)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 清除排序
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public void ClearAllSort()
|
|
{
|
|
this.gcMain.ClearSorting();
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 按节点顺序获取所有节点的集合
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<TreeListNode> GetDataSourceInTreeListOrder()
|
|
{
|
|
List<TreeListNode> orderedList = new List<TreeListNode>();
|
|
|
|
// 遍历所有的TreeList节点
|
|
foreach (TreeListNode node in TreeListObj.Nodes)
|
|
{
|
|
// 递归地添加节点
|
|
AddNodeAndChildren(node, orderedList);
|
|
}
|
|
|
|
return orderedList;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 记录当前节点和对应子节点
|
|
/// </summary>
|
|
/// <param name="node"></param>
|
|
/// <param name="list"></param>
|
|
public void AddNodeAndChildren(TreeListNode node, List<TreeListNode> list)
|
|
{
|
|
// 添加当前节点的数据
|
|
list.Add(node);
|
|
|
|
// 递归添加子节点
|
|
foreach (TreeListNode childNode in node.Nodes)
|
|
{
|
|
AddNodeAndChildren(childNode, list);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <para>说明:获取Grid列,判断是否是必填列</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2020-12-17 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="columns">The columns.</param>
|
|
public bool isRequiredFields(string requiredFields)
|
|
{
|
|
if (!string.IsNullOrEmpty(requiredFields))
|
|
{
|
|
string[] Fields = requiredFields.TrimEnd(',').Split(',');
|
|
foreach (string requiredField in Fields)
|
|
{
|
|
DataTable dt = GetGridViewDataSource();
|
|
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(dt.Rows[i][requiredField] + ""))
|
|
{
|
|
MessageUtil.Show(string.Format("明细列:{0}不能为空!", TreeListObj.Columns[requiredField].Caption));
|
|
return false;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 重新设置表格的字段属性
|
|
/// </summary>
|
|
/// <param name="ModifyFields">修改字段</param>
|
|
/// <param name="RequiredFields">必填字段</param>
|
|
public override void SetFieldStatus(string ModifyFields, string RequiredFields)
|
|
{
|
|
|
|
TreeListColumnCollection gc = this.gcMain.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 + ",";
|
|
}
|
|
|
|
foreach (TreeListColumn 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;
|