5604 lines
246 KiB
C#
5604 lines
246 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;
|
||
using System.Data.Common;
|
||
|
||
namespace Lskj.Control
|
||
{
|
||
/// <summary>
|
||
/// 表格树
|
||
/// </summary>
|
||
public partial class TreeGridControlEx : GridControlEx
|
||
{
|
||
public virtual TreeList TreeListObj { get { return gcMain; } }
|
||
|
||
/// <summary>
|
||
/// 树表格固定菜单
|
||
/// </summary>
|
||
public virtual ContextMenuStrip MenuStrip { get { return contextMenuStrip; } }
|
||
/// <summary>
|
||
/// 默认全部展开
|
||
/// </summary>
|
||
private string _expansion = "1";
|
||
public virtual string Expansion
|
||
{
|
||
get { return _expansion; }
|
||
set { _expansion = value; }
|
||
}
|
||
|
||
//treeList树展开的节点块
|
||
private List<TreeListNode> _treeListNodes = new List<TreeListNode>();
|
||
public virtual List<TreeListNode> treeListNodes
|
||
{
|
||
get { return _treeListNodes; }
|
||
set { _treeListNodes = value; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 排序字段
|
||
/// </summary>
|
||
public string SortField;
|
||
|
||
/// <summary>
|
||
/// 是否使用按层级分段的新版节点编号;默认false,保持老版整数节点号规则。
|
||
/// </summary>
|
||
public bool UseSegmentedNodeId { get; set; }
|
||
|
||
/// <summary>
|
||
/// 是否启用单据树表格粘贴;启用后粘贴内容作为新节点添加,不覆盖已有行。
|
||
/// </summary>
|
||
public bool BillPaste { get; set; }
|
||
|
||
// 记录单据粘贴是否应从一级节点开始,避免通过清空TreeList选择状态来表达粘贴位置。
|
||
private bool _billPasteAsRoot;
|
||
|
||
private int _treeNumberNodes = 2;
|
||
/// <summary>
|
||
/// 每级节点编号占用的位数,最小为2位。
|
||
/// </summary>
|
||
public int TreeNumberNodes
|
||
{
|
||
get { return _treeNumberNodes; }
|
||
set { _treeNumberNodes = value < 2 ? 2 : value; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 上次选中行
|
||
/// </summary>
|
||
private int lastNodeIndex;
|
||
|
||
/// <summary>
|
||
/// 日期类型控件名称
|
||
/// </summary>
|
||
private List<string> DateColumnNames = new List<string>();
|
||
/// <summary>
|
||
/// 聚合多表头控件
|
||
/// </summary>
|
||
//public TreeBandedGridControlEx CustomGroupTreeBandEx;
|
||
|
||
/// <summary>
|
||
///单据明细拖拽条件(为树表格时推拽改变父节点和来源明细中推拽内容上去)
|
||
/// </summary>
|
||
public string TreeTableDragCondition;
|
||
|
||
/// <summary>
|
||
/// 下拉框数据源绑定完成后执行
|
||
/// </summary>
|
||
public new event EventHandler OnDataSourceBindCallBack;
|
||
// 全局标记:是否正在编辑
|
||
private bool isEditing = false;
|
||
|
||
|
||
public TreeGridControlEx()
|
||
{
|
||
InitializeComponent();
|
||
this.gcMain.KeyDown += new KeyEventHandler(OnTreeGridViewKeyDown);
|
||
this.gcMain.SelectionChanged += new EventHandler(gcMain_SelectionChanged);
|
||
this.gcMain.CustomDrawNodeCell += new CustomDrawNodeCellEventHandler(OnCustomDrawNodeCell);
|
||
this.gcMain.CustomDrawNodeIndicator += TreeListObj_CustomDrawNodeIndicator;//显示行号
|
||
this.gcMain.CellValueChanged += GcMain_CellValueChanged;
|
||
this.gcMain.NodesReloaded += OnNodesReloaded;
|
||
this.gcMain.ColumnFilterChanged += TreeList1_ColumnFilterChanged;
|
||
|
||
this.gcMain.CustomDrawFooterCell += GcMain_CustomDrawFooterCell;
|
||
|
||
// 双击编辑单元格时禁用“双击节点折叠/展开”
|
||
this.gcMain.OptionsBehavior.AllowExpandOnDblClick = false;
|
||
this.gcMain.MouseDown += GcMain_MouseDown;
|
||
this.gcMain.ShownEditor += GcMain_ShownEditor;
|
||
this.gcMain.HiddenEditor += GcMain_HiddenEditor;
|
||
|
||
if (LicenseManager.UsageMode != LicenseUsageMode.Designtime)
|
||
{
|
||
SetGridRowHeightAndFont(this.gcMain);
|
||
if (SystemInfo.Instance.ExpandButtonType.Equals("1"))
|
||
{
|
||
this.gcMain.CustomDrawNodeButton += OnCustomDrawNodeButton;//绘制按钮
|
||
}
|
||
}
|
||
|
||
this.gcMain.PopupMenuShowing += new PopupMenuShowingEventHandler(OnPopupMenuShowing);
|
||
#region LabPicUrl控件实现事件
|
||
LabPicUrlPreview_TreeList.Attach(this.gcMain); // 必须
|
||
LabPicUrlPreview_TreeList.AttachPreview(this.gcMain); // 新增(双击预览)
|
||
#endregion
|
||
//InitializeTreeMethod();
|
||
//this.gcMain.OptionsBehavior.EnableFiltering = true;
|
||
//this.gcMain.OptionsFind.AlwaysVisible = true;
|
||
}
|
||
|
||
private void GcMain_HiddenEditor(object sender, EventArgs e)
|
||
{
|
||
isEditing = false;
|
||
}
|
||
|
||
private void GcMain_ShownEditor(object sender, EventArgs e)
|
||
{
|
||
isEditing = true;
|
||
}
|
||
|
||
private void GcMain_MouseDown(object sender, MouseEventArgs e)
|
||
{
|
||
TreeList treeList = sender as TreeList;
|
||
if (treeList == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (e.Button == MouseButtons.Left)
|
||
{
|
||
TreeListHitInfo mouseHitInfo = treeList.CalcHitInfo(e.Location);
|
||
|
||
if (BillPaste)
|
||
{
|
||
// 点击空白区域时后续粘贴为一级节点,不改动TreeList内部的选中集合。
|
||
_billPasteAsRoot = mouseHitInfo.HitInfoType == HitInfoType.Empty;
|
||
}
|
||
|
||
if (treeList.OptionsSelection.MultiSelect &&
|
||
treeList.OptionsSelection.MultiSelectMode == TreeListMultiSelectMode.CellSelect &&
|
||
(mouseHitInfo.HitInfoType == HitInfoType.RowIndicator || mouseHitInfo.HitInfoType == HitInfoType.RowIndicatorEdge) &&
|
||
treeList.FocusedColumn == null && treeList.VisibleColumns.Count > 0)
|
||
{
|
||
// DevExpress 15.2在单元格多选模式下重复点击行序号时会清空FocusedColumn,
|
||
// 后续点击会将null列传给IsCellSelected并触发“参数名:key”异常。
|
||
treeList.FocusedColumn = treeList.VisibleColumns[0];
|
||
}
|
||
}
|
||
|
||
if (isEditing) return; // 编辑中不处理折叠
|
||
|
||
if (e.Clicks != 2 || e.Button != MouseButtons.Left)
|
||
return;
|
||
|
||
TreeListHitInfo hitInfo = treeList.CalcHitInfo(e.Location);
|
||
if (hitInfo.Node == null) return;
|
||
|
||
// 双击可编辑单元格 → 仅编辑,不折叠
|
||
if (hitInfo.HitInfoType == HitInfoType.Cell
|
||
&& hitInfo.Column != null
|
||
&& hitInfo.Column.OptionsColumn.AllowEdit)
|
||
{
|
||
treeList.ShowEditor();
|
||
}
|
||
//单击行,或者节点前的按钮,或者不可编辑单元格 就改变折叠状态
|
||
else if (hitInfo.HitInfoType == HitInfoType.Row || hitInfo.HitInfoType == HitInfoType.Button||(hitInfo.HitInfoType == HitInfoType.Cell&& !hitInfo.Column.OptionsColumn.AllowEdit))
|
||
{
|
||
// 15.2切换节点展开状态(原生API)
|
||
hitInfo.Node.Expanded = !hitInfo.Node.Expanded;
|
||
}
|
||
}
|
||
|
||
private void GcMain_CustomDrawFooterCell(object sender, CustomDrawFooterCellEventArgs e)
|
||
{
|
||
TreeListColumn listColumn = e.Column;
|
||
GridColumnModel columnModel = listColumn.Tag as GridColumnModel;
|
||
if (!string.IsNullOrWhiteSpace(columnModel.SumCond))
|
||
{
|
||
decimal sum = CalculateConditionalSum(columnModel);
|
||
|
||
e.Text = sum + "";
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 计算符合条件的合计值
|
||
/// </summary>
|
||
private decimal CalculateConditionalSum(GridColumnModel columnModel)
|
||
{
|
||
decimal total = 0;
|
||
List<TreeListNode> listNodes = this.GetAllNodesOnTheInterface();
|
||
// 遍历所有节点(包含子节点)
|
||
foreach (TreeListNode node in listNodes)
|
||
{
|
||
// 跳过空节点
|
||
if (node == null) continue;
|
||
DataRowView dataRowView = this.TreeListObj.GetDataRecordByNode(node) as DataRowView;
|
||
DataRow gridRow = dataRowView != null ? dataRowView.Row : null;
|
||
|
||
if ("true".Equals(EvalHelper.Eval(ReplaceHelper.ReplaceEvalCond(ReplaceHelper.ReplaceRowParam(gridRow, columnModel.SumCond))) + "", StringComparison.OrdinalIgnoreCase))
|
||
{
|
||
if (decimal.TryParse(node.GetDisplayText(columnModel.FieldName), out decimal value))
|
||
{
|
||
total += value;
|
||
}
|
||
}
|
||
}
|
||
return total;
|
||
}
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 修改筛选框筛选日期类型列的条件(日期=xxx 替换wei 日期>=xxx && 日期<xxx+1)
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void TreeList1_ColumnFilterChanged(object sender, EventArgs e)
|
||
{
|
||
TreeList treeList = sender as TreeList;
|
||
string filter = treeList.ActiveFilterString;
|
||
|
||
if (string.IsNullOrEmpty(filter))
|
||
return;
|
||
|
||
// 配置需要处理的日期列列表(不含方括号)
|
||
//string[] dateColumns = new[] { "mrp_hb_operatedate", "wms_lout_tagiddate", "wms_lout_takedate" };
|
||
string[] dateColumns = DateColumnNames.ToArray();
|
||
string newFilter = filter;
|
||
|
||
// 遍历所有日期列,替换精确匹配为范围匹配
|
||
foreach (string column in dateColumns)
|
||
{
|
||
string columnPattern = $@"\[{column}\] = #(\d{{4}}-\d{{2}}-\d{{2}})#";
|
||
newFilter = Regex.Replace(newFilter, columnPattern, match =>
|
||
{
|
||
if (DateTime.TryParse(match.Groups[1].Value, out DateTime date))
|
||
{
|
||
return $"([{column}] >= #{date:yyyy-MM-dd}# And [{column}] < #{date.AddDays(1):yyyy-MM-dd}#)";
|
||
}
|
||
return match.Value; // 解析失败则保持原样
|
||
});
|
||
}
|
||
|
||
// 应用修改后的筛选表达式
|
||
if (newFilter != filter)
|
||
{
|
||
treeList.ActiveFilterString = newFilter;
|
||
}
|
||
}
|
||
|
||
|
||
void gcMain_SelectionChanged(object sender, EventArgs e)
|
||
{
|
||
//try
|
||
//{
|
||
//List<TreeListCell> cells = this.TreeListObj.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.TreeListObj.CustomDrawNodeCell += new CustomDrawNodeCellEventHandler(OnGridViewRowCellStyle);
|
||
else
|
||
this.TreeListObj.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 virtual void OnGridViewRowStyle(object sender, GetCustomNodeCellStyleEventArgs e)
|
||
{
|
||
if (this.GridRowColorsTable != null && this.GridRowColorsTable.Rows.Count > 0)
|
||
{
|
||
// 渲染界面数据量过多界面刷新会很慢
|
||
DataRowView dataRowView = this.TreeListObj.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"] + "");
|
||
string cond = ReplaceHelper.ReplaceRowParamEmptyWrapQuote(gridRow, item["condition"] + "");
|
||
try
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(cond) && ReplaceHelper.EvalCond(cond))
|
||
{
|
||
GridRowColorModel model = new GridRowColorModel(item);
|
||
if (!string.IsNullOrWhiteSpace(model.BackColor))
|
||
{
|
||
e.Appearance.BackColor = ColorTranslator.FromHtml(model.BackColor);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(model.ForceColor))
|
||
{
|
||
e.Appearance.ForeColor = ColorTranslator.FromHtml(model.ForceColor);
|
||
}
|
||
|
||
FontStyle fontStyle = 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 virtual void OnGridViewRowCellStyle(object sender, CustomDrawNodeCellEventArgs e)
|
||
{
|
||
if (this.GridRowColorsTable != null && this.GridRowColorsTable.Rows.Count > 0 && !string.IsNullOrEmpty(e.CellValue + ""))
|
||
{
|
||
// 渲染界面数据量过多界面刷新会很慢
|
||
DataRowView dataRowView = this.TreeListObj.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 + "");
|
||
string cond = ReplaceHelper.ReplaceRowParamEmptyWrapQuote(gridRow, item["condition"] + "").ReplaceColumnParam(e.Column.Name, e.Column.Caption, e.CellValue + "");
|
||
try
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(cond) && ReplaceHelper.EvalCond(cond))
|
||
{
|
||
GridRowColorModel model = new GridRowColorModel(item);
|
||
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.TreeListObj.Nodes.TreeList.FindNodeByID(treeListNode.Id);
|
||
if (treeListNode1 != null) treeListNode1.Expanded = true;
|
||
}
|
||
this.TreeListObj.FocusedNode = this.TreeListObj.GetNodeByVisibleIndex(lastNodeIndex);
|
||
if ((Expansion + "").Equals("1"))
|
||
{
|
||
this.TreeListObj.ExpandAll();
|
||
}
|
||
else if ((Expansion + "").Equals("2"))
|
||
{
|
||
this.TreeListObj.ExpandToLevel(0);
|
||
}
|
||
else if ((Expansion + "").Equals("3"))
|
||
{
|
||
this.TreeListObj.CollapseAll();
|
||
}
|
||
|
||
//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;
|
||
|
||
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;
|
||
}
|
||
if (model.DataAlignment > 0)
|
||
{
|
||
gridColumn.AppearanceCell.Options.UseTextOptions = true;
|
||
gridColumn.AppearanceCell.TextOptions.HAlignment = model.DataAlignment == 1 ? DevExpress.Utils.HorzAlignment.Center : DevExpress.Utils.HorzAlignment.Far;
|
||
}
|
||
// 设置列格式化、汇总
|
||
this.SetColumnFormat(gridColumn, model);
|
||
this.SetColumnSumming(gridColumn, model);
|
||
// 创建列
|
||
this.InitEditColumns(gridColumn, model);
|
||
this.TreeListObj.Columns.AddRange(new TreeListColumn[] { gridColumn });
|
||
//TreeListObj.Bands[0].Columns.Add(gridColumn);
|
||
|
||
this.ColumnList.Add(model);
|
||
}
|
||
if (!dataCaches.GetValue(this, "CustomColumnByDatabase", out DataTable customTable))
|
||
{
|
||
customTable = this.TreeListObj.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 virtual 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:
|
||
DateColumnNames.Add(model.FieldName);
|
||
InitDateTimeEdit(column, model.FieldType);
|
||
break;
|
||
case ControlType.LabTime:
|
||
case ControlType.LabShortTime:
|
||
InitTimeEdit(column, model.FieldType);
|
||
break;
|
||
case ControlType.LabCalcText:
|
||
InitCalcEdit(column);
|
||
break;
|
||
case ControlType.LabMemoEdit:
|
||
InitMemoEdit(column);
|
||
break;
|
||
case ControlType.LabRemark:
|
||
InitRemarkEdit(column);
|
||
break;
|
||
//case ControlType.LabAccount:
|
||
// this.cellHelper.AddAmountColumn(column, 11);
|
||
// break;
|
||
case ControlType.LabMultiSelectValue:
|
||
case ControlType.LabMultiSelectValueNew:
|
||
case ControlType.LabMultiSelectValueParam:
|
||
case ControlType.LabMultiSelectText:
|
||
case ControlType.LabMultiSelectTextNew:
|
||
case ControlType.LabMultiSelectTextParam:
|
||
InitMutilEdit(column, model);
|
||
break;
|
||
case ControlType.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.LabPicUrl:
|
||
// 用工具类创建图片列(绑定 Tag、Repository、UnboundType)
|
||
LabPicUrlPreview_TreeList.InitPicColumn(this.TreeListObj, column, model);
|
||
break;
|
||
case ControlType.LabSelectReturnId:
|
||
case ControlType.LabSelectReturnText:
|
||
InitSelectReturnId(column, model);
|
||
break;
|
||
case ControlType.LabSelectReturnIdNew:
|
||
case ControlType.LabSelectReturnTextNew:
|
||
InitSelectReturnIdNew(column, model);
|
||
break;
|
||
case ControlType.LabSelectReturnRows:
|
||
InitSelectReturnRows(column, model);
|
||
break;
|
||
//case ControlType.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 virtual 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 virtual 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 virtual 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 virtual 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 virtual 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 virtual 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 virtual 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 virtual 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 virtual 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 virtual 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 virtual 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.LabMultiSelectValueNew ||
|
||
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.LabMultiSelectValueNew ||
|
||
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 virtual 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 virtual 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 virtual 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 virtual 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);
|
||
if (model.ModuleFrameDisplayText)
|
||
{
|
||
DataTable dataTable = MainImpl.GetDataTableResult(modelLookUp.SysModel.MenuSql);
|
||
btnEdit.DataSource = dataTable;
|
||
}
|
||
|
||
btnEdit.Buttons[0].Visible = false; // 不能移除,移除后事件不起作用.
|
||
btnEdit.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] { new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Ellipsis) });
|
||
|
||
btnEdit.Tag = model;
|
||
btnEdit.Buttons[1].Tag = modelLookUp;
|
||
btnEdit.ButtonClick += new ButtonPressedEventHandler(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 virtual 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);
|
||
|
||
DXMenuItem itemBsChartShowClick = new DXMenuItem("一键所有列属性设置", InstAllColumn);
|
||
|
||
itemSaveColumn.BeginGroup = itemFixLeft.BeginGroup = true;
|
||
itemBsChartShowClick.Visible = ERPInfo.Instance.UserName == "管理员" && Model != null;
|
||
|
||
itemFixLeft.Tag = itemFixLeftAll.Tag = itemUnFix.Tag = hitInfo.Column;
|
||
itemSaveColumn.Tag = itemResetColumn.Tag = itemExportColumn.Tag = itemPrintColumn.Tag = itemSortColumn.Tag = itemBsChartShowClick.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, itemBsChartShowClick });
|
||
}
|
||
}
|
||
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-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 ExportItemClick(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
this.TreeListObj.ToExcelTreeList(this.Model.FormText);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:清除全部列排序</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-02-01 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected override void ClearSortItemClick(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
this.TreeListObj.ClearSorting();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
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.TreeListObj.Columns.AddRange(new TreeListColumn[] { gridColumn });
|
||
this.ColumnList.Add(model);
|
||
}
|
||
DataTable customTable = this.TreeListObj.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
|
||
{
|
||
SetColumnsSource();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
}
|
||
finally
|
||
{
|
||
if (this.OnDataSourceBindCallBack != null) this.OnDataSourceBindCallBack(null, null);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
this.mTimer.Stop();
|
||
this.mTimer.Dispose();
|
||
}
|
||
}
|
||
|
||
|
||
|
||
private void SetColumnsSource()
|
||
{
|
||
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.TreeListObj.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.TreeListObj.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;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/// <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 virtual void InitializeTreeMethod()
|
||
{
|
||
this.TreeListObj.CellValueChanging += new DevExpress.XtraTreeList.CellValueChangedEventHandler(OnCellValueChaning);
|
||
}
|
||
|
||
|
||
protected virtual 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 virtual 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 virtual 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 virtual void SetGridRowHeightAndFont()
|
||
{
|
||
SetGridRowHeightAndFont(this.TreeListObj);
|
||
}
|
||
|
||
private void SetGridRowHeightAndFont(TreeList treeList)
|
||
{
|
||
if (treeList == null) return;
|
||
if (SystemInfo.Instance.GridRowFontSize > 0)
|
||
{
|
||
treeList.Appearance.Row.Font = new Font("微软雅黑", SystemInfo.Instance.GridRowFontSize);
|
||
treeList.Appearance.HeaderPanel.Font = new Font("微软雅黑", SystemInfo.Instance.GridRowFontSize);
|
||
}
|
||
if (SystemInfo.Instance.GridRowHeight > 0)
|
||
{
|
||
treeList.ColumnPanelRowHeight = treeList.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.TreeListObj.SaveCustomColumnToDatabase(this.CustomColumKey);
|
||
}
|
||
else
|
||
{
|
||
success = this.TreeListObj.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.TreeListObj.ResetCustomColumnToDatabase(this.CustomColumKey);
|
||
|
||
DataTable customTable = this.TreeListObj.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>
|
||
public virtual 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)
|
||
{
|
||
TreeListObj.OptionsView.ShowSummaryFooter = true;
|
||
gridColumn.AllNodesSummary = true;
|
||
gridColumn.SummaryFooter = SummaryItemType.Count;
|
||
gridColumn.SummaryFooterStrFormat = "合计:{0:#,###}行";
|
||
}
|
||
else
|
||
{
|
||
if (model.CanSum)
|
||
{
|
||
TreeListObj.OptionsView.ShowSummaryFooter = true;
|
||
gridColumn.AllNodesSummary = true;
|
||
gridColumn.SummaryFooter = !string.IsNullOrEmpty(model.SumCond) ? DevExpress.XtraTreeList.SummaryItemType.Custom : 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);
|
||
//}
|
||
// !hasExistsSettingTable
|
||
if (string.IsNullOrEmpty(this.CustomColumKey) || customTable.Columns.Count == 0) 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.TreeListObj.Columns.ColumnByName(fieldName);
|
||
if (column != null && gridColumn != null && gridColumn.Visible && gridColumn.Width > 0)
|
||
{
|
||
TreeListColumn colObj = this.TreeListObj.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.TreeListObj.Columns.ColumnByName(column.FieldName) != null)
|
||
{
|
||
TreeListColumn colObj = this.TreeListObj.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.TreeListObj.FocusedColumn;
|
||
GridColumnModel model = column.Tag as GridColumnModel;
|
||
if (column != null &&
|
||
column.OptionsColumn.AllowEdit &&
|
||
this.TreeListObj.Nodes.Count > 0 &&
|
||
this.TreeListObj.OptionsBehavior.Editable)
|
||
{
|
||
// 允许操作
|
||
//焦点行节点
|
||
TreeListNode focusedNode = TreeListObj.FocusedNode;
|
||
//获取当前界面上排序的节点
|
||
List<TreeListNode> dataSourceInTreeListOrder = GetDataSourceInTreeListOrder();
|
||
//选中行
|
||
DataRow FocusedRow = GetViewSpecifyDataRow(focusedNode);
|
||
//当前选中行,在界面上的行数
|
||
int focusedRowHandle = dataSourceInTreeListOrder.IndexOf(focusedNode);
|
||
//界面上的全部数据条数
|
||
int totalRowCount = dataSourceInTreeListOrder.Count;
|
||
//操作的单元格
|
||
List<TreeListCell> cells = this.TreeListObj.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);
|
||
}
|
||
|
||
}
|
||
|
||
TreeListObj.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.TreeListObj.FocusedColumn;
|
||
if (column != null &&
|
||
column.OptionsColumn.AllowEdit &&
|
||
this.TreeListObj.Nodes.Count > 0 &&
|
||
this.TreeListObj.OptionsBehavior.Editable)
|
||
{
|
||
// 允许操作
|
||
TreeListNode focusedNode = TreeListObj.FocusedNode;
|
||
//获取当前界面上排序的节点
|
||
List<TreeListNode> dataSourceInTreeListOrder = GetDataSourceInTreeListOrder();
|
||
//选中行
|
||
DataRow FocusedRow = GetViewSpecifyDataRow(focusedNode);
|
||
//当前选中行,在界面上的行数
|
||
int focusedRowHandle = dataSourceInTreeListOrder.IndexOf(focusedNode);
|
||
//界面上的全部数据条数
|
||
int totalRowCount = dataSourceInTreeListOrder.Count;
|
||
//操作的单元格
|
||
List<TreeListCell> cells = this.TreeListObj.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];
|
||
TreeListObj.SetFocusedNode(node);
|
||
node.SetValue(column, leftString + value.ToString().PadLeft(valueNum, '0'));
|
||
TreeListObj.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];
|
||
TreeListObj.SetFocusedNode(node);
|
||
node.SetValue(column, value);
|
||
TreeListObj.PostEditor();
|
||
value++;
|
||
}
|
||
e.Handled = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
e.Handled = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
// 复制单元格
|
||
if (e.Control && e.KeyCode == Keys.C)
|
||
{
|
||
//List<TreeListCell> cells=new List<TreeListCell>();
|
||
////复选框状态
|
||
//if (TreeListObj.OptionsSelection.MultiSelect == true && TreeListObj.OptionsSelection.MultiSelectMode == TreeListMultiSelectMode.RowSelect && TreeListObj.OptionsSelection.EnableAppearanceFocusedCell == false && this.GetViewFocusedDataRows().Length == 0)
|
||
//{
|
||
// //GridViewInfo info = gridView.GetViewInfo() as GridViewInfo;
|
||
// //GridCellInfo cellInfo = info.GetGridCellInfo(gridView.FocusedRowHandle, gridView.FocusedColumn);
|
||
// TreeListCell cell = new TreeListCell(TreeListObj.FocusedNode, TreeListObj.FocusedColumn);
|
||
// cells.Add(cell);
|
||
//}
|
||
//else
|
||
//{
|
||
// cells = this.TreeListObj.GetSelectedCells();
|
||
//}
|
||
|
||
|
||
|
||
var selectNodes = this.TreeListObj.Selection;
|
||
if (selectNodes != null && selectNodes.Count == 1)
|
||
{
|
||
//object obj = gridView.GetFocusedRowCellValue(gridView.FocusedColumn);
|
||
object obj = this.TreeListObj.FocusedNode.GetDisplayText(this.TreeListObj.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 = TreeListObj.GetSelectedCells(treeNode);
|
||
DataRowView dataRowView = this.TreeListObj.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
|
||
{
|
||
TreeListObj.CopyToClipboard();
|
||
e.Handled = true;
|
||
}
|
||
}
|
||
else if (e.Modifiers.CompareTo(Keys.Control) == 0 && e.KeyCode == Keys.V)
|
||
{
|
||
if (this.BillPaste)
|
||
{
|
||
// 单据树表格粘贴始终新增节点,不进入下方按可见行覆盖数据的通用粘贴逻辑。
|
||
if (!SystemInfo.Instance.CancelPasteClearSort)
|
||
{
|
||
this.TreeListObj.ClearSorting();
|
||
}
|
||
|
||
object billPasteData = null;
|
||
IDataObject billDataObj = Clipboard.GetDataObject();
|
||
if (billDataObj != null && billDataObj.GetDataPresent(DataFormats.Text))
|
||
{
|
||
billPasteData = billDataObj.GetData(DataFormats.Text);
|
||
}
|
||
BillPasteMethod(e, billPasteData);
|
||
return;
|
||
}
|
||
|
||
//if (this.gridView.IsFindPanelVisible)
|
||
//{
|
||
// MessageUtil.Show("搜索模式下无法粘贴行.");
|
||
// return;
|
||
//}
|
||
TreeListColumn column = this.TreeListObj.FocusedColumn;
|
||
GridColumnModel model = column.Tag as GridColumnModel;
|
||
if (column != null &&
|
||
column.OptionsColumn.AllowEdit &&
|
||
this.TreeListObj.Nodes.Count > 0 &&
|
||
this.TreeListObj.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.TreeListObj.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.TreeListObj.FocusedNode as TreeListNode;
|
||
|
||
if (treeNode != null)
|
||
{
|
||
DataRowView dataRowView = this.TreeListObj.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.TreeListObj.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.TreeListObj.Selection;
|
||
DataRow[] dataRows = new DataRow[selectNodes.Count];
|
||
|
||
for (int i = 0; i < selectNodes.Count; i++)
|
||
{
|
||
TreeListNode treeNode = selectNodes[i];
|
||
DataRowView dataRowView = this.TreeListObj.GetDataRecordByNode(treeNode) as DataRowView;
|
||
dataRows[i] = dataRowView != null ? dataRowView.Row : null;
|
||
}
|
||
|
||
//设置了复选框这个获取所有选中的节点行
|
||
if (this.TreeListObj.OptionsView.ShowCheckBoxes == true && this.TreeListObj.OptionsSelection.MultiSelect == true && this.TreeListObj.OptionsSelection.MultiSelectMode == TreeListMultiSelectMode.RowSelect)
|
||
{
|
||
List<TreeListNode> TreeListNodeList = this.TreeListObj.GetAllCheckedNodes();
|
||
dataRows = new DataRow[TreeListNodeList.Count];
|
||
for (int i = 0; i < TreeListNodeList.Count; i++)
|
||
{
|
||
TreeListNode treeNode = TreeListNodeList[i];
|
||
DataRowView dataRowView = this.TreeListObj.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 virtual DataTable GetGridViewDataSource()
|
||
{
|
||
return this.TreeListObj.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)
|
||
{
|
||
if (this.ColumnList == null || this.ColumnList.Count == 0)
|
||
{
|
||
this.TreeListObj.Columns.Clear();
|
||
}
|
||
lastNodeIndex = 0;
|
||
if (selectRowHandler) lastNodeIndex = this.TreeListObj.GetVisibleIndexByNode(this.TreeListObj.FocusedNode);
|
||
GetTreeExpanded();
|
||
this.TreeListObj.ClearNodes();
|
||
this.TreeListObj.DataSource = table;
|
||
this.AdjustIndicatorWidthSmart();
|
||
this.SetAutoColumns();
|
||
}
|
||
public override int SetGridViewDataSource(DbDataAdapter adapter, bool selectRowHandler = true)
|
||
{
|
||
if (adapter == null) return 0;
|
||
if (this.ColumnList == null || this.ColumnList.Count == 0)
|
||
{
|
||
this.TreeListObj.Columns.Clear();
|
||
}
|
||
lastNodeIndex = 0;
|
||
if (selectRowHandler) lastNodeIndex = this.TreeListObj.GetVisibleIndexByNode(this.TreeListObj.FocusedNode);
|
||
this.AdapterObj = adapter;
|
||
DataSet dataSet = new DataSet();
|
||
//adapter.Fill(dataSet, "SetGridViewDataSource");
|
||
|
||
// 重连配置
|
||
int maxRetryCount = 2; // 次数
|
||
int retryDelay = 1000; // 等待时间
|
||
for (int i = 0; i < maxRetryCount; i++)
|
||
{
|
||
try
|
||
{
|
||
adapter.Fill(dataSet, "SetGridViewDataSource");
|
||
break;//连接成功
|
||
}
|
||
catch (SqlException ex)
|
||
{
|
||
// 判断是否是连接相关错误
|
||
if (IsConnectionError(ex.Number) ||
|
||
ex.Message.Contains("物理连接不可用") ||
|
||
ex.Message.Contains("传输级错误"))
|
||
{
|
||
if (i < maxRetryCount - 1)
|
||
{
|
||
SqlConnection.ClearAllPools();
|
||
System.Threading.Thread.Sleep(retryDelay);
|
||
continue; // 重试
|
||
}
|
||
else
|
||
{
|
||
// 最后一次重试失败,抛出错误
|
||
throw new Exception($"经过 {maxRetryCount} 次重试后仍无法连接到数据库: {ex.Message}", ex);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// 其他SQL错误直接抛出
|
||
throw;
|
||
}
|
||
}
|
||
}
|
||
DbCommandBuilder cb = SqlHelper.dbFactory.CreateCommandBuilder();
|
||
cb.DataAdapter = this.AdapterObj;
|
||
//SqlCommandBuilder cb = new SqlCommandBuilder(this.AdapterObj);
|
||
|
||
|
||
GetTreeExpanded();
|
||
|
||
this.TreeListObj.DataSource = dataSet.Tables[0];
|
||
this.AdjustIndicatorWidthSmart();
|
||
this.SetAutoColumns();
|
||
|
||
if ((Expansion + "").Equals("1"))
|
||
{
|
||
this.TreeListObj.ExpandAll();
|
||
}
|
||
else if ((Expansion + "").Equals("2"))
|
||
{
|
||
this.TreeListObj.ExpandToLevel(0);
|
||
}
|
||
else if ((Expansion + "").Equals("3"))
|
||
{
|
||
this.TreeListObj.CollapseAll();
|
||
}
|
||
return dataSet.Tables[0] != null ? dataSet.Tables[0].Rows.Count : 0;
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:设置动态列</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-06-03 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
protected virtual void SetAutoColumns()
|
||
{
|
||
if (this.ColumnList == null || this.ColumnList.Count == 0)
|
||
{
|
||
bool isShowFooter = false;
|
||
for (int i = 0; i < TreeListObj.Columns.Count; i++)
|
||
{
|
||
try
|
||
{
|
||
TreeListColumn col = TreeListObj.Columns[i];
|
||
col.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
|
||
col.OptionsFilter.FilterPopupMode = FilterPopupMode.CheckedList;
|
||
|
||
if (col.FieldName.Contains("_"))
|
||
{
|
||
string[] colSplit = col.FieldName.Split('_');
|
||
if (colSplit.Length >= 2)
|
||
{
|
||
col.Caption = colSplit[0];
|
||
col.Width = Convert.ToInt32(colSplit[1]);
|
||
if (Convert.ToInt32(colSplit[1]) == 0)
|
||
col.Visible = false;
|
||
if (colSplit.Length > 2)
|
||
{
|
||
bool visible = "1".Equals(colSplit[2]);
|
||
// 设置底部合计
|
||
if (col.VisibleIndex == 0)
|
||
{
|
||
isShowFooter = true;
|
||
|
||
TreeListObj.OptionsView.ShowSummaryFooter = true;
|
||
col.AllNodesSummary = true;
|
||
col.SummaryFooter = SummaryItemType.Count;
|
||
col.SummaryFooterStrFormat = "合计:{0:#,###}行";
|
||
|
||
|
||
}
|
||
else
|
||
{
|
||
if (visible)
|
||
{
|
||
isShowFooter = true;
|
||
|
||
TreeListObj.OptionsView.ShowSummaryFooter = true;
|
||
col.AllNodesSummary = true;
|
||
col.SummaryFooter = DevExpress.XtraTreeList.SummaryItemType.Sum;
|
||
col.SummaryFooterStrFormat = "{0:}";
|
||
|
||
}
|
||
}
|
||
if (colSplit.Length > 3)
|
||
{
|
||
string dataFormat = colSplit[3];
|
||
|
||
if (!string.IsNullOrWhiteSpace(dataFormat))
|
||
{
|
||
col.Format.FormatType = FormatType.Custom;
|
||
col.Format.FormatString = dataFormat;
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
col.Width = 150;
|
||
}
|
||
//cMain.OptionsView.ShowFooter = isShowFooter;
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 记录展开的节点
|
||
/// </summary>
|
||
public virtual void GetTreeExpanded()
|
||
{
|
||
|
||
treeListNodes.Clear();
|
||
foreach (TreeListNode n in this.TreeListObj.Nodes)
|
||
{
|
||
setRecursive(n);
|
||
}
|
||
}
|
||
|
||
|
||
public virtual 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.TreeListObj.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.TreeListObj.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 virtual 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 virtual 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 virtual 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.LabMultiSelectValueNew || model.FieldType == ControlType.LabMultiSelectValueParam)
|
||
{
|
||
modelLookUp.EditValue = btnEdit.EditValue + "";
|
||
modelLookUp.EditText = string.Empty;
|
||
}
|
||
else
|
||
{
|
||
modelLookUp.EditText = btnEdit.Text;
|
||
modelLookUp.EditValue = string.Empty;
|
||
}
|
||
//多选关联单据头
|
||
modelLookUp.SourceSQL = model.SqlSource.Replace("#", "");
|
||
//单据头关联取值
|
||
if (this.ParentControl != null)
|
||
{
|
||
modelLookUp.SourceSQL = this.ParentControl.ReplaceControlValue(modelLookUp.SourceSQL);
|
||
}
|
||
|
||
modelLookUp.SourceSQL = ReplaceHelper.ReplaceRowParam(this.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 virtual void OnModuleRowsChoice(object sender, ButtonPressedEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
ButtonEdit btnEdit = (ButtonEdit)sender;
|
||
FrmRowsModelLookUp modelLookUp = e.Button.Tag as FrmRowsModelLookUp;
|
||
|
||
GridColumnModel model = modelLookUp.Tag as GridColumnModel;
|
||
modelLookUp.EditText = btnEdit.Text;
|
||
modelLookUp.CurrentOperColumnKey = Model.ModuleCode + "_" + model.FieldName;
|
||
if (model.FieldType == ControlType.LabMultiSelectValue || model.FieldType == ControlType.LabMultiSelectValueNew || model.FieldType == ControlType.LabMultiSelectValueParam)
|
||
{
|
||
modelLookUp.EditValue = btnEdit.EditValue + "";
|
||
modelLookUp.EditText = string.Empty;
|
||
}
|
||
else
|
||
{
|
||
modelLookUp.EditText = btnEdit.Text;
|
||
modelLookUp.EditValue = string.Empty;
|
||
}
|
||
////多选关联单据头
|
||
//modelLookUp.SourceSQL = model.SqlSource.Replace("#", "");
|
||
////单据头关联取值
|
||
//if (this.ParentControl != null)
|
||
//{
|
||
// modelLookUp.SourceSQL = this.ParentControl.ReplaceControlValue(modelLookUp.SourceSQL);
|
||
//}
|
||
|
||
//modelLookUp.SourceSQL = ReplaceHelper.ReplaceRowParam(this.gridView.GetFocusedDataRow(), modelLookUp.SourceSQL);
|
||
//modelLookUp.DataSource = BaseImpl.GetDataTableResult(modelLookUp.SourceSQL);
|
||
string sourceSql = string.Empty;
|
||
if (!string.IsNullOrEmpty(model.SqlSource))
|
||
{
|
||
sourceSql = model.SqlSource;
|
||
}
|
||
else
|
||
{
|
||
DataRow modelRow = MainImpl.GetSystemdllTab(model.addModuleld);//获取单个模块信息
|
||
if (modelRow == null)
|
||
{
|
||
MessageUtil.Show("模块编号[" + model.addModuleld + "],配置错误!\r\n该模块信息未找到!");
|
||
return;
|
||
}
|
||
ModuleModel moduleModel = new ModuleModel(modelRow);// 系统模块实体对象
|
||
sourceSql = moduleModel.MenuSql;
|
||
}
|
||
|
||
//多选关联单据头
|
||
modelLookUp.SourceSQL = sourceSql.Replace("#", "");
|
||
//单据头关联取值
|
||
if (this.ParentControl != null)
|
||
{
|
||
modelLookUp.SourceSQL = this.ParentControl.ReplaceControlValue(modelLookUp.SourceSQL);
|
||
}
|
||
|
||
modelLookUp.SourceSQL = ReplaceHelper.ReplaceRowParam(this.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.TreeListObj.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.TreeListObj.FocusedNode)
|
||
e.Appearance.BackColor = ColorTranslator.FromHtml("#9feb6a");
|
||
|
||
|
||
|
||
}
|
||
/// <summary>
|
||
/// 单据树表格粘贴。先将剪贴板内容转换为临时表,再统一设置父节点和节点号并追加到数据源。
|
||
/// </summary>
|
||
/// <param name="e">键盘事件,用于阻止系统继续处理本次粘贴。</param>
|
||
/// <param name="clipboardData">剪贴板中的制表符分隔文本。</param>
|
||
private void BillPasteMethod(KeyEventArgs e, object clipboardData)
|
||
{
|
||
if (clipboardData == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
DataTable sourceTable = this.GetGridViewDataSource();
|
||
if (sourceTable == null || this.TreeListObj.VisibleColumns.Count == 0 ||
|
||
!sourceTable.Columns.Contains(this.TreeListObj.KeyFieldName) ||
|
||
!sourceTable.Columns.Contains(this.TreeListObj.ParentFieldName))
|
||
{
|
||
return;
|
||
}
|
||
|
||
TreeListColumn focusedColumn = this.TreeListObj.FocusedColumn;
|
||
if (focusedColumn == null || focusedColumn.VisibleIndex < 0)
|
||
{
|
||
focusedColumn = this.TreeListObj.VisibleColumns[0];
|
||
}
|
||
|
||
string pasteText = clipboardData.ToString();
|
||
pasteText = Regex.Replace(pasteText, "\"[^\"]*(?:\"\"[^\"]*)*\"", m => m.Value.Replace("\r\n", "{lskj}").Replace("\"", ""));
|
||
string[] pasteRows = pasteText.Split(new string[] { "\r\n" }, StringSplitOptions.None);
|
||
DataTable pasteTable = sourceTable.Clone();
|
||
int startColumnIndex = sourceTable.Rows.Count == 0 ? 0 : focusedColumn.VisibleIndex;
|
||
|
||
for (int i = 0; i < pasteRows.Length; i++)
|
||
{
|
||
if (i == pasteRows.Length - 1 && pasteRows[i].Trim().Length == 0)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
string[] pasteCells = IgnoreTab ? new string[] { pasteRows[i] } : pasteRows[i].Split('\t');
|
||
DataRow pasteRow = pasteTable.NewRow();
|
||
SetBillPasteDefaultValues(pasteRow);
|
||
|
||
int columnIndex = startColumnIndex;
|
||
for (int j = 0; j < pasteCells.Length && columnIndex < this.TreeListObj.VisibleColumns.Count; j++, columnIndex++)
|
||
{
|
||
TreeListColumn column = this.TreeListObj.VisibleColumns[columnIndex];
|
||
GridColumnModel model = column.Tag as GridColumnModel;
|
||
if (model == null || model.ProhibitPaste ||
|
||
(!model.CanCopy && (!this.TreeListObj.OptionsBehavior.Editable || !column.OptionsColumn.AllowEdit)))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (!string.IsNullOrWhiteSpace(model.DisableCond))
|
||
{
|
||
string updateCond = model.DisableCond;
|
||
if (this.ParentControl != null)
|
||
{
|
||
updateCond = this.ParentControl.ReplaceParentControlValue(updateCond);
|
||
}
|
||
updateCond = ReplaceHelper.ReplaceRowParam(pasteRow, updateCond);
|
||
if (!ReplaceHelper.EvalCond(updateCond))
|
||
{
|
||
continue;
|
||
}
|
||
}
|
||
|
||
SetBillPasteCellValue(pasteRow, column, model, pasteCells[j]);
|
||
}
|
||
|
||
SetBillPasteLengthErrors(pasteRow);
|
||
pasteTable.Rows.Add(pasteRow);
|
||
}
|
||
|
||
if (pasteTable.Rows.Count == 0)
|
||
{
|
||
e.Handled = true;
|
||
return;
|
||
}
|
||
|
||
TreeListNode parentNode = _billPasteAsRoot ? null : this.TreeListObj.FocusedNode;
|
||
DataRow parentRow = this.GetViewSpecifyDataRow(parentNode);
|
||
string parentNodeId = parentRow == null ? "0" : parentRow[this.TreeListObj.KeyFieldName] + "";
|
||
if (string.IsNullOrWhiteSpace(parentNodeId))
|
||
{
|
||
parentNodeId = "0";
|
||
}
|
||
|
||
if (UseSegmentedNodeId)
|
||
{
|
||
// 保留剪贴板中的节点号和父节点号,按原父子关系整体映射到当前选中节点下。
|
||
pasteTable = PrepareNodeIdsForInsert(pasteTable, parentNodeId);
|
||
}
|
||
else
|
||
{
|
||
PrepareOldNodeIdsForInsert(pasteTable, parentNodeId);
|
||
}
|
||
|
||
object lastNodeId = null;
|
||
foreach (DataRow pasteRow in pasteTable.Rows)
|
||
{
|
||
DataRow newRow = sourceTable.NewRow();
|
||
foreach (DataColumn column in sourceTable.Columns)
|
||
{
|
||
if (column.AutoIncrement || column.ReadOnly || !string.IsNullOrEmpty(column.Expression))
|
||
{
|
||
continue;
|
||
}
|
||
newRow[column.ColumnName] = pasteRow[column.ColumnName];
|
||
}
|
||
sourceTable.Rows.Add(newRow);
|
||
lastNodeId = newRow[this.TreeListObj.KeyFieldName];
|
||
}
|
||
|
||
this.TreeListObj.RefreshDataSource();
|
||
if (parentNode != null)
|
||
{
|
||
parentNode.Expanded = true;
|
||
}
|
||
DataSourceSorting();
|
||
if (UseSegmentedNodeId)
|
||
{
|
||
// 新版节点号必须与最终界面顺序一致,追加完成后再统一整理一次。
|
||
RenumberNodeIds();
|
||
}
|
||
|
||
if (lastNodeId != null)
|
||
{
|
||
TreeListNode lastNode = this.TreeListObj.FindNodeByKeyID(lastNodeId);
|
||
if (lastNode != null)
|
||
{
|
||
this.TreeListObj.FocusedNode = lastNode;
|
||
}
|
||
}
|
||
this.TreeListObj.ShowEditor();
|
||
e.Handled = true;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 按普通表格粘贴规则,为新增粘贴行设置列默认值和父控件参数默认值。
|
||
/// </summary>
|
||
/// <param name="row">待填充的临时粘贴行。</param>
|
||
private void SetBillPasteDefaultValues(DataRow row)
|
||
{
|
||
foreach (TreeListColumn column in this.TreeListObj.Columns)
|
||
{
|
||
GridColumnModel model = column.Tag as GridColumnModel;
|
||
if (model == null || !row.Table.Columns.Contains(column.FieldName))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue);
|
||
if (!string.IsNullOrEmpty(model.DefaultValue) && model.DefaultValue.Contains("{#") && this.ParentControl != null)
|
||
{
|
||
fieldValue = this.ParentControl.ReplaceParentControlValue(model.DefaultValue);
|
||
if (!string.IsNullOrEmpty(fieldValue))
|
||
{
|
||
row[column.FieldName] = fieldValue;
|
||
}
|
||
}
|
||
else if (!string.IsNullOrEmpty(model.DefaultValue) && !model.DefaultValue.Contains("{ROW_"))
|
||
{
|
||
row[column.FieldName] = fieldValue;
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 将单个剪贴板文本转换为列的实际保存值,并处理下拉框、模块返回框、日期和数值类型校验。
|
||
/// </summary>
|
||
/// <param name="row">待赋值的临时粘贴行。</param>
|
||
/// <param name="column">目标树表格列。</param>
|
||
/// <param name="model">目标列配置。</param>
|
||
/// <param name="pasteValue">剪贴板中的显示文本。</param>
|
||
private void SetBillPasteCellValue(DataRow row, TreeListColumn column, GridColumnModel model, string pasteValue)
|
||
{
|
||
string cellValue = string.IsNullOrEmpty(pasteValue) ? pasteValue : pasteValue.Replace("{lskj}", "\n");
|
||
bool isTextEqualValue = false;
|
||
object value = ControlType.IsValue(model.FieldType) ? GetValueByCaption(model, column.ColumnEdit, cellValue, out isTextEqualValue) : cellValue;
|
||
value = model.FieldType == 14 ? ReplaceMultiSpace(value) : value;
|
||
|
||
if (model.FieldType == 17)
|
||
{
|
||
value = value.Equals("非校验") ? 0 : value.Equals("校验") ? 1 : value;
|
||
if (value.Equals("不确定"))
|
||
{
|
||
return;
|
||
}
|
||
}
|
||
|
||
if (model.FieldType == 116 || model.FieldType == 117 || model.FieldType == 160 || model.FieldType == 161)
|
||
{
|
||
value = ModuleReturnVerify(model, column.ColumnEdit, cellValue, out isTextEqualValue);
|
||
if (!isTextEqualValue && cellValue == value + "")
|
||
{
|
||
return;
|
||
}
|
||
}
|
||
|
||
DateTime dateValue;
|
||
if (!isTextEqualValue && ((ControlType.IsValue(model.FieldType) && cellValue == value + "") ||
|
||
(ControlType.LabTextInt == model.FieldType && (value + "").IsChinese()) ||
|
||
(ControlType.IsDate(model.FieldType) && !DateTime.TryParse(value + "", out dateValue))))
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(value + ""))
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(row[column.FieldName] + ""))
|
||
{
|
||
return;
|
||
}
|
||
|
||
string columnType = column.ColumnType.Name.ToLower();
|
||
if (columnType == "string" || columnType.IndexOf("char") >= 0)
|
||
row[column.FieldName] = "";
|
||
else if (columnType.IndexOf("int") >= 0 || columnType == "decimal")
|
||
row[column.FieldName] = 0;
|
||
}
|
||
else
|
||
{
|
||
row[column.FieldName] = value;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 检查粘贴行的文本字节长度,超出列配置限制时在DataRow上记录列错误。
|
||
/// </summary>
|
||
/// <param name="row">已完成字段转换的临时粘贴行。</param>
|
||
private void SetBillPasteLengthErrors(DataRow row)
|
||
{
|
||
foreach (TreeListColumn column in this.TreeListObj.Columns)
|
||
{
|
||
GridColumnModel model = column.Tag as GridColumnModel;
|
||
if (model == null || model.LimitLength <= 0 || !row.Table.Columns.Contains(column.FieldName))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
int inputLength = Encoding.Default.GetBytes(row[column.FieldName] + "").Length;
|
||
if (inputLength > model.LimitLength)
|
||
{
|
||
row.SetColumnError(row.Table.Columns[column.FieldName], "当前输入文本超过设定长度!");
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 按老版整数节点号规则迁移一批粘贴数据,同时保留这批数据内部的父子关系。
|
||
/// 数值型来源节点号沿用原来的整体偏移方式;非数值或空节点号从当前最大节点号继续生成。
|
||
/// </summary>
|
||
/// <param name="pasteTable">已从剪贴板转换完成、尚未加入主数据源的临时表。</param>
|
||
/// <param name="targetParentNodeId">整批粘贴数据要插入到的目标父节点号。</param>
|
||
private void PrepareOldNodeIdsForInsert(DataTable pasteTable, string targetParentNodeId)
|
||
{
|
||
string keyFieldName = this.TreeListObj.KeyFieldName;
|
||
string parentFieldName = this.TreeListObj.ParentFieldName;
|
||
int nextNodeId = int.Parse(GetNewNodesId());
|
||
int nodeOffset = nextNodeId - 1;
|
||
Dictionary<string, int> nodeIdMap = new Dictionary<string, int>(StringComparer.Ordinal);
|
||
HashSet<int> usedNodeIds = new HashSet<int>();
|
||
|
||
// 第一遍只生成新节点号,并记录来源节点号到新节点号的映射,父节点在第二遍统一处理。
|
||
foreach (DataRow row in pasteTable.Rows)
|
||
{
|
||
string sourceNodeId = (row[keyFieldName] + "").Trim();
|
||
|
||
int sourceNumber;
|
||
int mappedNodeId;
|
||
if (!string.IsNullOrEmpty(sourceNodeId) && !nodeIdMap.ContainsKey(sourceNodeId) &&
|
||
int.TryParse(sourceNodeId, out sourceNumber) && sourceNumber > 0)
|
||
{
|
||
mappedNodeId = sourceNumber + nodeOffset;
|
||
}
|
||
else
|
||
{
|
||
mappedNodeId = nextNodeId;
|
||
}
|
||
|
||
while (usedNodeIds.Contains(mappedNodeId))
|
||
{
|
||
mappedNodeId++;
|
||
}
|
||
|
||
usedNodeIds.Add(mappedNodeId);
|
||
nextNodeId = Math.Max(nextNodeId, mappedNodeId + 1);
|
||
row[keyFieldName] = mappedNodeId;
|
||
if (!string.IsNullOrEmpty(sourceNodeId) && !nodeIdMap.ContainsKey(sourceNodeId))
|
||
{
|
||
nodeIdMap.Add(sourceNodeId, mappedNodeId);
|
||
}
|
||
}
|
||
|
||
// 只有父节点也包含在本次粘贴数据中时才保留层级,否则该行直接挂到目标父节点下。
|
||
foreach (DataRow row in pasteTable.Rows)
|
||
{
|
||
string sourceParentNodeId = (row[parentFieldName] + "").Trim();
|
||
int mappedParentNodeId;
|
||
row[parentFieldName] = !string.IsNullOrEmpty(sourceParentNodeId) && sourceParentNodeId != "0" &&
|
||
nodeIdMap.TryGetValue(sourceParentNodeId, out mappedParentNodeId)
|
||
? mappedParentNodeId + ""
|
||
: targetParentNodeId;
|
||
}
|
||
}
|
||
|
||
/// <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.TreeListObj.FocusedColumn;
|
||
focColumn = focColumn == null ? this.TreeListObj.Columns[0] : focColumn;
|
||
if (focColumn != null)
|
||
{
|
||
DataTable table = this.GetGridViewDataSource();
|
||
int beforeNumber = table.Rows.Count;
|
||
_rowNumber = this.TreeListObj.GetVisibleIndexByNode(this.TreeListObj.FocusedNode);
|
||
if (_rowNumber < 0)
|
||
{
|
||
_rowNumber = 0;
|
||
}
|
||
if (_arrayRowStr.Length != this.TreeListObj.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.TreeListObj.Columns;
|
||
this.TreeListObj.FocusedNode = this.TreeListObj.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.TreeListObj.FocusedNode = this.TreeListObj.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.TreeListObj.VisibleColumns[_colNumber];
|
||
|
||
GridColumnModel model = col.Tag as GridColumnModel;
|
||
if (model != null && (model.CanCopy || ((this.TreeListObj.OptionsBehavior.Editable) && (this.TreeListObj.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.TreeListObj.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.TreeListObj.Columns.Count; j++)
|
||
{
|
||
if (this.TreeListObj.Columns[j].Tag == null) continue;
|
||
if ((this.TreeListObj.Columns[j].Tag as GridColumnModel).LimitLength > 0)
|
||
{
|
||
int MaxInputLength = System.Text.Encoding.Default.GetBytes(newRow[this.TreeListObj.Columns[j].FieldName].ToString()).Length;
|
||
if (MaxInputLength > (this.TreeListObj.Columns[j].Tag as GridColumnModel).LimitLength)
|
||
{
|
||
newRow.SetColumnError(newRow.Table.Columns[this.TreeListObj.Columns[j].FieldName], "当前输入文本超过设定长度!");//不满足条件设置错误信息
|
||
}
|
||
}
|
||
}
|
||
table.Rows.Add(newRow);
|
||
//this.gridView.FocusedRowHandle = _rowNumber - 1;
|
||
}
|
||
else
|
||
{
|
||
//this.TreeListObj.UpdateCurrentRow();
|
||
}
|
||
}
|
||
this.TreeListObj.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)
|
||
{
|
||
if (UseSegmentedNodeId)
|
||
{
|
||
table = EnsureSegmentedNodeColumnTypes(table);
|
||
AssignMissingSegmentedNodeIds(table);
|
||
this.SetGridViewDataSource(table);
|
||
RenumberNodeIds();
|
||
}
|
||
else
|
||
{
|
||
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
|
||
{
|
||
DataRow[] AlreadyExistsRow = table.Rows.Cast<DataRow>().Where(x => !string.IsNullOrWhiteSpace(x[TreeListObj.KeyFieldName] + "")).ToArray();
|
||
int maxid = int.Parse(AlreadyExistsRow.Cast<DataRow>().Max(n => n[TreeListObj.KeyFieldName]) + "") + 1;
|
||
//没有节点id的行赋值当前最大id
|
||
foreach (DataRow item in dataRows)
|
||
{
|
||
item[TreeListObj.KeyFieldName] = maxid + "";
|
||
maxid++;
|
||
}
|
||
this.SetGridViewDataSource(table);
|
||
}
|
||
}
|
||
|
||
SetTreeExpansion();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 数据源重新绑定后,根据Expansion配置恢复树节点的展开状态。
|
||
/// </summary>
|
||
private void SetTreeExpansion()
|
||
{
|
||
if ((Expansion + "").Equals("1"))
|
||
{
|
||
this.TreeListObj.ExpandAll();
|
||
}
|
||
else if ((Expansion + "").Equals("2"))
|
||
{
|
||
this.TreeListObj.ExpandToLevel(0);
|
||
}
|
||
else if ((Expansion + "").Equals("3"))
|
||
{
|
||
this.TreeListObj.CollapseAll();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取新增一级节点号;新版从一级节点分段继续编号,老版取最大整数节点号加一。
|
||
/// </summary>
|
||
/// <returns>可用于新增一级节点的节点号。</returns>
|
||
public string GetNewNodesId()
|
||
{
|
||
if (UseSegmentedNodeId)
|
||
{
|
||
return GetNewNodesId("0");
|
||
}
|
||
|
||
return GetOldNewNodesId();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据父节点获取新增节点号;老版模式忽略父节点并继续使用最大整数节点号。
|
||
/// </summary>
|
||
/// <param name="parentNodeId">目标父节点号,0或空字符串表示一级节点。</param>
|
||
/// <returns>目标层级中下一个可用节点号。</returns>
|
||
public string GetNewNodesId(string parentNodeId)
|
||
{
|
||
if (!UseSegmentedNodeId)
|
||
{
|
||
return GetOldNewNodesId();
|
||
}
|
||
|
||
DataTable gridTable = this.TreeListObj.DataSource as DataTable;
|
||
return GetNewNodesId(parentNodeId, gridTable);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据指定数据源和父节点获取新增节点号,用于尚未绑定到TreeList的批量新增数据。
|
||
/// </summary>
|
||
/// <param name="parentNodeId">目标父节点号,0或空字符串表示一级节点。</param>
|
||
/// <param name="dataTable">参与计算现有节点号的数据源。</param>
|
||
/// <returns>目标层级中下一个可用节点号。</returns>
|
||
public string GetNewNodesId(string parentNodeId, DataTable dataTable)
|
||
{
|
||
if (!UseSegmentedNodeId)
|
||
{
|
||
return GetOldNewNodesId();
|
||
}
|
||
|
||
int sequence = GetNextNodeSequence(dataTable, parentNodeId);
|
||
return BuildSegmentedNodeId(parentNodeId, sequence);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取指定父节点下最后一个节点号,供新增主节点后继续追加关联子数据使用。
|
||
/// </summary>
|
||
/// <param name="parentNodeId">目标父节点号。</param>
|
||
/// <returns>最后一个同级节点号;该层级没有节点时返回空字符串。</returns>
|
||
public string GetLastNodesId(string parentNodeId)
|
||
{
|
||
if (!UseSegmentedNodeId)
|
||
{
|
||
int nodeId;
|
||
return int.TryParse(GetOldNewNodesId(), out nodeId) ? (nodeId - 1) + "" : "";
|
||
}
|
||
|
||
DataTable gridTable = this.TreeListObj.DataSource as DataTable;
|
||
int sequence = GetNextNodeSequence(gridTable, parentNodeId) - 1;
|
||
return sequence > 0 ? BuildSegmentedNodeId(parentNodeId, sequence) : "";
|
||
}
|
||
|
||
/// <summary>
|
||
/// 按老版规则获取全表最大整数节点号加一。
|
||
/// </summary>
|
||
/// <returns>下一个可用的老版整数节点号。</returns>
|
||
private string GetOldNewNodesId()
|
||
{
|
||
int id = 1;
|
||
DataTable dataSource = this.TreeListObj.DataSource as DataTable;
|
||
DataTable gridTable = dataSource == null ? null : dataSource.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>
|
||
/// 获取指定父节点下的下一个分段序号,只统计符合当前分段位数的直接子节点。
|
||
/// </summary>
|
||
/// <param name="dataTable">节点数据源。</param>
|
||
/// <param name="parentNodeId">目标父节点号。</param>
|
||
/// <returns>从1开始的下一个同级序号。</returns>
|
||
private int GetNextNodeSequence(DataTable dataTable, string parentNodeId)
|
||
{
|
||
if (dataTable == null || !dataTable.Columns.Contains(TreeListObj.KeyFieldName) || !dataTable.Columns.Contains(TreeListObj.ParentFieldName))
|
||
{
|
||
return 1;
|
||
}
|
||
|
||
string parentId = NormalizeParentNodeId(parentNodeId);
|
||
int maxSequence = 0;
|
||
foreach (DataRow row in dataTable.Rows)
|
||
{
|
||
if (row.RowState == DataRowState.Deleted || !IsSameParentNode(row[TreeListObj.ParentFieldName] + "", parentId))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
string nodeId = row[TreeListObj.KeyFieldName] + "";
|
||
if (!nodeId.StartsWith(parentId, StringComparison.Ordinal) || nodeId.Length != parentId.Length + TreeNumberNodes)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
int sequence;
|
||
if (int.TryParse(nodeId.Substring(parentId.Length, TreeNumberNodes), out sequence) && sequence > maxSequence)
|
||
{
|
||
maxSequence = sequence;
|
||
}
|
||
}
|
||
|
||
return maxSequence + 1;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 将父节点号和同级序号组合成新版分段节点号,例如01 + 02生成0102。
|
||
/// </summary>
|
||
/// <param name="parentNodeId">父节点号。</param>
|
||
/// <param name="sequence">当前父节点下的同级序号。</param>
|
||
/// <returns>按TreeNumberNodes补零后的完整节点号。</returns>
|
||
private string BuildSegmentedNodeId(string parentNodeId, int sequence)
|
||
{
|
||
string segment = sequence.ToString();
|
||
if (segment.Length > TreeNumberNodes)
|
||
{
|
||
throw new InvalidOperationException("当前层级的节点数量已超过" + new string('9', TreeNumberNodes) + "个,无法继续新增节点。");
|
||
}
|
||
|
||
return NormalizeParentNodeId(parentNodeId) + segment.PadLeft(TreeNumberNodes, '0');
|
||
}
|
||
|
||
/// <summary>
|
||
/// 统一根节点表示方式,空字符串和0都转换为空前缀。
|
||
/// </summary>
|
||
/// <param name="parentNodeId">待规范化的父节点号。</param>
|
||
/// <returns>用于拼接新版节点号的父节点前缀。</returns>
|
||
private string NormalizeParentNodeId(string parentNodeId)
|
||
{
|
||
string value = (parentNodeId + "").Trim();
|
||
return string.IsNullOrEmpty(value) || value == "0" ? "" : value;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 比较两个父节点号,根节点的空字符串和0视为相同。
|
||
/// </summary>
|
||
/// <param name="rowParentNodeId">数据行中的父节点号。</param>
|
||
/// <param name="parentNodeId">目标父节点号。</param>
|
||
/// <returns>规范化后是否为同一个父节点。</returns>
|
||
private bool IsSameParentNode(string rowParentNodeId, string parentNodeId)
|
||
{
|
||
return string.Equals(NormalizeParentNodeId(rowParentNodeId), NormalizeParentNodeId(parentNodeId), StringComparison.Ordinal);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 导入数据的临时树节点,保留来源节点关系以便整体重映射节点号。
|
||
/// </summary>
|
||
private class ImportedTreeNode
|
||
{
|
||
public DataRow Row;
|
||
public string SourceNodeId;
|
||
public string SourceParentNodeId;
|
||
public List<ImportedTreeNode> Children = new List<ImportedTreeNode>();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 将待插入树数据的来源父子关系整体映射到目标父节点下,并生成不重复的新版分段节点号。
|
||
/// </summary>
|
||
/// <param name="dataTable">待插入的数据,KeyFieldName和ParentFieldName保存来源节点关系。</param>
|
||
/// <param name="parentNodeId">整批数据要插入到的目标父节点号。</param>
|
||
/// <returns>已重新生成节点号和父节点号的数据源。</returns>
|
||
public DataTable PrepareNodeIdsForInsert(DataTable dataTable, string parentNodeId)
|
||
{
|
||
if (!UseSegmentedNodeId || dataTable == null || dataTable.Rows.Count == 0 ||
|
||
!dataTable.Columns.Contains(TreeListObj.KeyFieldName) || !dataTable.Columns.Contains(TreeListObj.ParentFieldName))
|
||
{
|
||
return dataTable;
|
||
}
|
||
|
||
dataTable = EnsureSegmentedNodeColumnTypes(dataTable);
|
||
|
||
List<ImportedTreeNode> importNodes = new List<ImportedTreeNode>();
|
||
Dictionary<string, ImportedTreeNode> nodeMap = new Dictionary<string, ImportedTreeNode>(StringComparer.Ordinal);
|
||
foreach (DataRow row in dataTable.Rows)
|
||
{
|
||
ImportedTreeNode node = new ImportedTreeNode
|
||
{
|
||
Row = row,
|
||
SourceNodeId = (row[TreeListObj.KeyFieldName] + "").Trim(),
|
||
SourceParentNodeId = (row[TreeListObj.ParentFieldName] + "").Trim()
|
||
};
|
||
importNodes.Add(node);
|
||
if (!string.IsNullOrEmpty(node.SourceNodeId) && !nodeMap.ContainsKey(node.SourceNodeId))
|
||
{
|
||
nodeMap.Add(node.SourceNodeId, node);
|
||
}
|
||
}
|
||
|
||
List<ImportedTreeNode> rootNodes = new List<ImportedTreeNode>();
|
||
foreach (ImportedTreeNode node in importNodes)
|
||
{
|
||
ImportedTreeNode parentNode;
|
||
if (!string.IsNullOrEmpty(node.SourceParentNodeId) && node.SourceParentNodeId != "0" &&
|
||
nodeMap.TryGetValue(node.SourceParentNodeId, out parentNode) && parentNode != node)
|
||
{
|
||
parentNode.Children.Add(node);
|
||
}
|
||
else
|
||
{
|
||
rootNodes.Add(node);
|
||
}
|
||
}
|
||
|
||
HashSet<ImportedTreeNode> handledNodes = new HashSet<ImportedTreeNode>();
|
||
int sequence = GetNextNodeSequence(this.TreeListObj.DataSource as DataTable, parentNodeId);
|
||
foreach (ImportedTreeNode node in rootNodes)
|
||
{
|
||
AssignImportedNodeId(node, parentNodeId, ref sequence, handledNodes);
|
||
}
|
||
|
||
// 异常的循环父子关系没有根节点,将未处理行按根节点继续添加,避免导入死循环。
|
||
foreach (ImportedTreeNode node in importNodes)
|
||
{
|
||
if (!handledNodes.Contains(node))
|
||
{
|
||
AssignImportedNodeId(node, parentNodeId, ref sequence, handledNodes);
|
||
}
|
||
}
|
||
|
||
return dataTable;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 递归为导入节点及其子节点生成目标树中的分段节点号。
|
||
/// </summary>
|
||
/// <param name="node">当前待编号的导入节点。</param>
|
||
/// <param name="parentNodeId">当前节点在目标树中的父节点号。</param>
|
||
/// <param name="sequence">当前层级下一个可用序号,处理后自动递增。</param>
|
||
/// <param name="handledNodes">已处理节点集合,用于避免异常循环父子关系导致无限递归。</param>
|
||
private void AssignImportedNodeId(ImportedTreeNode node, string parentNodeId, ref int sequence, HashSet<ImportedTreeNode> handledNodes)
|
||
{
|
||
if (!handledNodes.Add(node))
|
||
{
|
||
return;
|
||
}
|
||
|
||
string nodeId = BuildSegmentedNodeId(parentNodeId, sequence);
|
||
sequence++;
|
||
node.Row[TreeListObj.KeyFieldName] = nodeId;
|
||
node.Row[TreeListObj.ParentFieldName] = string.IsNullOrEmpty(NormalizeParentNodeId(parentNodeId)) ? "0" : parentNodeId;
|
||
|
||
int childSequence = 1;
|
||
foreach (ImportedTreeNode childNode in node.Children)
|
||
{
|
||
AssignImportedNodeId(childNode, nodeId, ref childSequence, handledNodes);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 记录界面节点顺序对应的新节点号,避免遍历过程中直接修改KeyFieldName破坏父子关系。
|
||
/// </summary>
|
||
private class NodeNumberAssignment
|
||
{
|
||
public DataRow Row;
|
||
public string NodeId;
|
||
public string ParentNodeId;
|
||
}
|
||
|
||
private bool _renumberingNodeIds;
|
||
|
||
/// <summary>
|
||
/// 按当前树节点显示顺序重新生成全部分段节点号和父节点号,然后一次性重新绑定数据源。
|
||
/// </summary>
|
||
public void RenumberNodeIds()
|
||
{
|
||
if (!UseSegmentedNodeId || this.TreeListObj.DataSource == null || _renumberingNodeIds)
|
||
{
|
||
return;
|
||
}
|
||
|
||
_renumberingNodeIds = true;
|
||
try
|
||
{
|
||
List<NodeNumberAssignment> assignments = new List<NodeNumberAssignment>();
|
||
CollectNodeNumberAssignments(this.TreeListObj.Nodes, "", assignments);
|
||
if (assignments.Count == 0)
|
||
{
|
||
return;
|
||
}
|
||
|
||
DataTable sourceTable = this.TreeListObj.DataSource as DataTable;
|
||
if (sourceTable == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
DataTable numberedTable = sourceTable.Copy();
|
||
foreach (NodeNumberAssignment assignment in assignments)
|
||
{
|
||
int rowIndex = sourceTable.Rows.IndexOf(assignment.Row);
|
||
if (rowIndex >= 0 && rowIndex < numberedTable.Rows.Count)
|
||
{
|
||
DataRow numberedRow = numberedTable.Rows[rowIndex];
|
||
numberedRow[TreeListObj.ParentFieldName] = string.IsNullOrEmpty(assignment.ParentNodeId) ? "0" : assignment.ParentNodeId;
|
||
numberedRow[TreeListObj.KeyFieldName] = assignment.NodeId;
|
||
}
|
||
}
|
||
|
||
this.SetGridViewDataSource(numberedTable);
|
||
}
|
||
finally
|
||
{
|
||
_renumberingNodeIds = false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 按TreeList当前同级顺序递归收集节点号分配结果,不在遍历过程中修改原数据。
|
||
/// </summary>
|
||
/// <param name="nodes">当前层级的节点集合。</param>
|
||
/// <param name="parentNodeId">当前层级对应的父节点号。</param>
|
||
/// <param name="assignments">用于汇总全部节点分配结果的集合。</param>
|
||
private void CollectNodeNumberAssignments(TreeListNodes nodes, string parentNodeId, List<NodeNumberAssignment> assignments)
|
||
{
|
||
for (int i = 0; i < nodes.Count; i++)
|
||
{
|
||
TreeListNode node = nodes[i];
|
||
DataRowView rowView = this.TreeListObj.GetDataRecordByNode(node) as DataRowView;
|
||
if (rowView == null)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
string nodeId = BuildSegmentedNodeId(parentNodeId, i + 1);
|
||
assignments.Add(new NodeNumberAssignment
|
||
{
|
||
Row = rowView.Row,
|
||
NodeId = nodeId,
|
||
ParentNodeId = parentNodeId
|
||
});
|
||
CollectNodeNumberAssignments(node.Nodes, nodeId, assignments);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 为数据源中节点号为空的行补充分段节点号,已有节点号保持不变。
|
||
/// </summary>
|
||
/// <param name="dataTable">需要补充节点号的数据源。</param>
|
||
private void AssignMissingSegmentedNodeIds(DataTable dataTable)
|
||
{
|
||
if (dataTable == null || !dataTable.Columns.Contains(TreeListObj.KeyFieldName) || !dataTable.Columns.Contains(TreeListObj.ParentFieldName))
|
||
{
|
||
return;
|
||
}
|
||
|
||
foreach (DataRow row in dataTable.Rows)
|
||
{
|
||
if (row.RowState == DataRowState.Deleted || !string.IsNullOrWhiteSpace(row[TreeListObj.KeyFieldName] + ""))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
string parentNodeId = row[TreeListObj.ParentFieldName] + "";
|
||
row[TreeListObj.KeyFieldName] = GetNewNodesId(parentNodeId, dataTable);
|
||
if (string.IsNullOrEmpty(NormalizeParentNodeId(parentNodeId)))
|
||
{
|
||
row[TreeListObj.ParentFieldName] = "0";
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 确保新版节点号和父节点号使用可写字符串列,避免01等前导零被数值列丢失。
|
||
/// </summary>
|
||
/// <param name="dataTable">待检查或转换的数据源。</param>
|
||
/// <returns>列类型已满足新版编号要求的数据源;无需转换时返回原表。</returns>
|
||
private DataTable EnsureSegmentedNodeColumnTypes(DataTable dataTable)
|
||
{
|
||
if (dataTable == null || !dataTable.Columns.Contains(TreeListObj.KeyFieldName) || !dataTable.Columns.Contains(TreeListObj.ParentFieldName))
|
||
{
|
||
return dataTable;
|
||
}
|
||
|
||
DataColumn keyColumn = dataTable.Columns[TreeListObj.KeyFieldName];
|
||
DataColumn parentColumn = dataTable.Columns[TreeListObj.ParentFieldName];
|
||
bool keyIsString = (keyColumn.DataType == typeof(string) || keyColumn.DataType == typeof(object)) && !keyColumn.ReadOnly;
|
||
bool parentIsString = (parentColumn.DataType == typeof(string) || parentColumn.DataType == typeof(object)) && !parentColumn.ReadOnly;
|
||
if (keyIsString && parentIsString)
|
||
{
|
||
return dataTable;
|
||
}
|
||
|
||
DataTable stringTable = new DataTable(dataTable.TableName);
|
||
foreach (DataColumn column in dataTable.Columns)
|
||
{
|
||
bool isNodeColumn = column.ColumnName.Equals(TreeListObj.KeyFieldName, StringComparison.OrdinalIgnoreCase) ||
|
||
column.ColumnName.Equals(TreeListObj.ParentFieldName, StringComparison.OrdinalIgnoreCase);
|
||
DataColumn newColumn = new DataColumn(column.ColumnName, isNodeColumn ? typeof(string) : column.DataType)
|
||
{
|
||
Caption = column.Caption,
|
||
AllowDBNull = column.AllowDBNull,
|
||
DefaultValue = isNodeColumn ? "" : column.DefaultValue,
|
||
ColumnMapping = column.ColumnMapping
|
||
};
|
||
if (!isNodeColumn && column.DataType == typeof(string))
|
||
{
|
||
newColumn.MaxLength = column.MaxLength;
|
||
}
|
||
foreach (object key in column.ExtendedProperties.Keys)
|
||
{
|
||
newColumn.ExtendedProperties[key] = column.ExtendedProperties[key];
|
||
}
|
||
stringTable.Columns.Add(newColumn);
|
||
}
|
||
|
||
foreach (DataRow sourceRow in dataTable.Rows)
|
||
{
|
||
if (sourceRow.RowState == DataRowState.Deleted)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
DataRow newRow = stringTable.NewRow();
|
||
foreach (DataColumn column in dataTable.Columns)
|
||
{
|
||
object value = sourceRow[column];
|
||
if (column.ColumnName.Equals(TreeListObj.KeyFieldName, StringComparison.OrdinalIgnoreCase) ||
|
||
column.ColumnName.Equals(TreeListObj.ParentFieldName, StringComparison.OrdinalIgnoreCase))
|
||
{
|
||
newRow[column.ColumnName] = value == DBNull.Value ? "" : value + "";
|
||
}
|
||
else
|
||
{
|
||
newRow[column.ColumnName] = value;
|
||
}
|
||
}
|
||
stringTable.Rows.Add(newRow);
|
||
|
||
if (sourceRow.RowState == DataRowState.Unchanged)
|
||
{
|
||
newRow.AcceptChanges();
|
||
}
|
||
else if (sourceRow.RowState == DataRowState.Modified)
|
||
{
|
||
newRow.AcceptChanges();
|
||
newRow.SetModified();
|
||
}
|
||
}
|
||
|
||
foreach (DataColumn sourceColumn in dataTable.Columns)
|
||
{
|
||
DataColumn targetColumn = stringTable.Columns[sourceColumn.ColumnName];
|
||
bool isNodeColumn = sourceColumn.ColumnName.Equals(TreeListObj.KeyFieldName, StringComparison.OrdinalIgnoreCase) ||
|
||
sourceColumn.ColumnName.Equals(TreeListObj.ParentFieldName, StringComparison.OrdinalIgnoreCase);
|
||
if (!isNodeColumn && !string.IsNullOrEmpty(sourceColumn.Expression))
|
||
{
|
||
targetColumn.Expression = sourceColumn.Expression;
|
||
}
|
||
targetColumn.ReadOnly = isNodeColumn ? false : sourceColumn.ReadOnly;
|
||
}
|
||
|
||
return stringTable;
|
||
}
|
||
|
||
/// <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()
|
||
{
|
||
if (UseSegmentedNodeId)
|
||
{
|
||
RenumberNodeIds();
|
||
return;
|
||
}
|
||
|
||
//树表格当前数据源重新生成id
|
||
DataTable dt = this.TreeListObj.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();
|
||
DataTable dataSource = this.GetGridViewDataSource();
|
||
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);
|
||
// 递归添加所有子节点
|
||
this.AddAllChildRows(rowItem, dataSource, deleteRows);
|
||
}
|
||
else
|
||
{
|
||
//int index = dt.Rows.IndexOf(rowItem);
|
||
DeleteFailedRows.Add(rowItem[TreeListObj.KeyFieldName] + "");
|
||
}
|
||
}
|
||
DataTable table = this.TreeListObj.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("删除成功!");
|
||
}
|
||
}
|
||
|
||
if (UseSegmentedNodeId)
|
||
{
|
||
RenumberNodeIds();
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// <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.TreeListObj.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.TreeListObj.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.TreeListObj.KeyFieldName] = GetNewNodesId("0");//节点id
|
||
if (UseSegmentedNodeId && gridTable.Columns.Contains(this.TreeListObj.ParentFieldName))
|
||
{
|
||
tmpRow[this.TreeListObj.ParentFieldName] = "0";
|
||
}
|
||
gridTable.Rows.Add(tmpRow);
|
||
this.TreeListObj.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;
|
||
//this.TreeListObj.BeforeDragNode += TreeListObj_BeforeDragNode;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 当尝试拖动节点时触发
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
//private void TreeListObj_BeforeDragNode(object sender, BeforeDragNodeEventArgs e)
|
||
//{
|
||
//}
|
||
|
||
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>
|
||
/// 拖拽释放时处理限制条件和Alt同层排序。新版模式会先移动界面节点,再同步排序字段和分段节点号。
|
||
/// </summary>
|
||
/// <param name="sender">触发拖拽的TreeList。</param>
|
||
/// <param name="e">拖拽目标位置和按键状态。</param>
|
||
private void TreeListObj_DragDrop(object sender, DragEventArgs e)
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(TreeTableDragCondition))
|
||
{
|
||
//目标节点
|
||
TreeListHitInfo hitInfo = TreeListObj.CalcHitInfo(TreeListObj.PointToClient(new System.Drawing.Point(e.X, e.Y)));
|
||
TreeListNode TargetNode = hitInfo.Node;//当前目标节点
|
||
DataRow TargetRow = GetViewSpecifyDataRow(TargetNode);
|
||
//拖拽节点
|
||
TreeListNode SelectedNode = this.TreeListObj.FocusedNode;
|
||
DataRow SelectedRow = GetViewSpecifyDataRow(SelectedNode);
|
||
|
||
if (!ReplaceHelper.EvalCond(ReplaceHelper.ReplaceRowParam(TargetRow, this.TreeTableDragCondition))&& !ReplaceHelper.EvalCond(ReplaceHelper.ReplaceRowParam(SelectedRow, this.TreeTableDragCondition)))
|
||
{
|
||
e.Effect = DragDropEffects.None;
|
||
}
|
||
}
|
||
|
||
// Alt键被按下,只能在同层级拖拽,拖拽行移动到目标行下方
|
||
if (e.KeyState == 32)
|
||
{
|
||
e.Effect = DragDropEffects.None;
|
||
DataTable dataTable = GetGridViewDataSource();
|
||
|
||
//如果有排序列,所有序号大于目标行的序号的值都+1,拖拽行最后为目标行序号+1
|
||
if (!string.IsNullOrWhiteSpace(this.SortField) && dataTable.Columns.Contains(this.SortField))
|
||
{
|
||
//目标节点
|
||
DXDragEventArgs dragEventArgs = DXDragEventArgs.GetEventArgs(TreeListObj, e);
|
||
TreeListHitInfo hitInfo = TreeListObj.CalcHitInfo(TreeListObj.PointToClient(new System.Drawing.Point(e.X, e.Y)));
|
||
TreeListNode TreeListNode = dragEventArgs == null || dragEventArgs.TargetNode == null ? hitInfo.Node : dragEventArgs.TargetNode;//当前目标节点
|
||
if (TreeListNode == null)
|
||
{
|
||
return;
|
||
}
|
||
TreeListNode parentNode = TreeListNode.ParentNode; // 获取目标节点的父节点
|
||
int nodeIndex = parentNode == null ? TreeListObj.Nodes.IndexOf(TreeListNode) : parentNode.Nodes.IndexOf(TreeListNode);//当前目标节点的索引
|
||
//拖拽节点
|
||
TreeListNode SelectedNode = dragEventArgs == null || dragEventArgs.Node == null ? this.TreeListObj.FocusedNode : dragEventArgs.Node;
|
||
if (SelectedNode == null || SelectedNode == TreeListNode)
|
||
{
|
||
return;
|
||
}
|
||
TreeListNode SelectedParentNode = SelectedNode.ParentNode; // 获取拖拽节点的父节点
|
||
int SelectedNodeIndex = SelectedParentNode == null ? TreeListObj.Nodes.IndexOf(SelectedNode) : SelectedParentNode.Nodes.IndexOf(SelectedNode);//拖拽节点的索引
|
||
//如果目标节点和拖拽节点的父节点不一样,就证明不在同一层级,直接结束
|
||
if (SelectedNode.ParentNode != parentNode)
|
||
{
|
||
e.Effect = DragDropEffects.None;
|
||
return;
|
||
}
|
||
|
||
if (UseSegmentedNodeId)
|
||
{
|
||
// 新版编号必须以界面中的同层节点顺序为准,先移动节点,再重写排序字段和节点号。
|
||
int newNodeIndex = SelectedNodeIndex < nodeIndex ? nodeIndex : nodeIndex + 1;
|
||
this.TreeListObj.SetNodeIndex(SelectedNode, newNodeIndex);
|
||
int focusedNodeIndex = this.TreeListObj.GetVisibleIndexByNode(SelectedNode);
|
||
DataSourceSorting();
|
||
RebindSegmentedNodesBySortField(focusedNodeIndex);
|
||
return;
|
||
}
|
||
|
||
DataRow DragRow = (this.TreeListObj.GetDataRecordByNode(SelectedNode) as DataRowView).Row;//拖拽行
|
||
DataRow TargetRow = (this.TreeListObj.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>
|
||
/// TreeList完成普通节点拖拽后,同步数据源排序;新版模式再按最终界面顺序重新生成节点号。
|
||
/// </summary>
|
||
/// <param name="sender">完成拖拽的TreeList。</param>
|
||
/// <param name="e">拖拽完成后的节点信息。</param>
|
||
private void TreeListObj_AfterDragNode(object sender, AfterDragNodeEventArgs e)
|
||
{
|
||
DataSourceSorting();
|
||
if (UseSegmentedNodeId)
|
||
{
|
||
int focusedNodeIndex = this.TreeListObj.GetVisibleIndexByNode(e.Node ?? this.TreeListObj.FocusedNode);
|
||
RebindSegmentedNodesBySortField(focusedNodeIndex);
|
||
}
|
||
//强制重新加载数据
|
||
// this.TreeListObj.RefreshDataSource();
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 按排序字段重新绑定新版树节点,再按绑定后的界面顺序生成节点号并恢复焦点位置。
|
||
/// </summary>
|
||
/// <param name="focusedNodeIndex">重新绑定前焦点节点的可见索引。</param>
|
||
private void RebindSegmentedNodesBySortField(int focusedNodeIndex)
|
||
{
|
||
DataTable dataTable = GetGridViewDataSource();
|
||
if (dataTable == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (!string.IsNullOrWhiteSpace(this.SortField) && dataTable.Columns.Contains(this.SortField))
|
||
{
|
||
DataView dataView = dataTable.AsDataView();
|
||
dataView.Sort = "[" + this.SortField.Replace("]", "]]") + "] ASC";
|
||
dataTable = dataView.ToTable();
|
||
}
|
||
|
||
this.SetGridViewDataSourceGenerateID(dataTable);
|
||
if (focusedNodeIndex >= 0)
|
||
{
|
||
this.TreeListObj.FocusedNode = this.TreeListObj.GetNodeByVisibleIndex(focusedNodeIndex);
|
||
}
|
||
}
|
||
#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.TreeListObj.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;
|
||
if(tree.IndicatorWidth<30) 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.TreeListObj.Nodes[e.Node.Id+1];//获取当前改变行下一行的节点
|
||
//DataRow a = (this.TreeListObj.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.TreeListObj.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.TreeListObj.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.TreeListObj.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.TreeListObj.DataSource as DataTable;
|
||
DataRow rowItem = table.Rows.Count == 0 || this.TreeListObj.FocusedNode != null ? this.GetViewFocusedDataRow() : this.TreeListObj.FocusedNode == node || node == null ? this.GetViewFocusedDataRow() : (this.TreeListObj.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.TreeListObj.DataSource as DataTable;
|
||
DataRow rowItem = table.Rows.Count == 0 || this.TreeListObj.FocusedNode != null ? this.GetViewFocusedDataRow() : this.TreeListObj.FocusedNode == node || node == null ? this.GetViewFocusedDataRow() : (this.TreeListObj.GetDataRecordByNode(node) as DataRowView).Row;
|
||
|
||
if (rowItem != null && model != null)
|
||
{
|
||
foreach (TreeListColumn col in this.TreeListObj.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.TreeListObj.DataSource as DataTable;
|
||
DataRow rowItem = (this.TreeListObj.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.TreeListObj.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.TreeListObj.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.TreeListObj.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.TreeListObj.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.TreeListObj.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.TreeListObj.Columns)
|
||
{
|
||
if (column.SortIndex > 0)
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 清除排序
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public void ClearAllSort()
|
||
{
|
||
this.TreeListObj.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>
|
||
/// 获取界面上所有的节点(获取ctrl+f后的数据,包含折叠的子节点)
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<TreeListNode> GetAllNodesOnTheInterface()
|
||
{
|
||
List<TreeListNode> orderedList = new List<TreeListNode>();
|
||
|
||
// 遍历所有的TreeList节点
|
||
foreach (TreeListNode node in TreeListObj.Nodes)
|
||
{
|
||
// 递归地添加节点
|
||
if (node.Visible)
|
||
{
|
||
AddNodeAndChildrenInterface(node, orderedList);
|
||
}
|
||
|
||
}
|
||
|
||
return orderedList;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 记录当前节点和对应子节点
|
||
/// </summary>
|
||
/// <param name="node"></param>
|
||
/// <param name="list"></param>
|
||
public void AddNodeAndChildrenInterface(TreeListNode node, List<TreeListNode> list)
|
||
{
|
||
// 添加当前节点的数据
|
||
list.Add(node);
|
||
|
||
// 递归添加子节点
|
||
foreach (TreeListNode childNode in node.Nodes)
|
||
{
|
||
if (childNode.Visible)
|
||
{
|
||
AddNodeAndChildrenInterface(childNode, list);
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 递归获取所有子节点并添加到删除集合中(删除选中节点数据和对应的子节点数据)
|
||
/// </summary>
|
||
/// <param name="parentRow">选中节点的数据</param>
|
||
/// <param name="table">表格数据</param>
|
||
/// <param name="deleteRows">删除数据集合</param>
|
||
private void AddAllChildRows(DataRow parentRow, DataTable table, List<DataRow> deleteRows)
|
||
{
|
||
if (parentRow == null || table == null) return;
|
||
|
||
// 获取TreeList的父子关系字段
|
||
string keyField = this.TreeListObj.KeyFieldName;
|
||
string parentField = this.TreeListObj.ParentFieldName;
|
||
|
||
// 获取当前父节点的键值
|
||
object parentKeyValue = parentRow[keyField];
|
||
if (parentKeyValue == DBNull.Value) return;
|
||
|
||
// 查找所有直接子节点
|
||
DataRow[] childRows = table.Select($"{parentField} = '{parentKeyValue}'");
|
||
|
||
foreach (DataRow childRow in childRows)
|
||
{
|
||
if (!deleteRows.Contains(childRow))
|
||
{
|
||
deleteRows.Add(childRow);
|
||
// 递归查找子节点的子节点
|
||
AddAllChildRows(childRow, table, deleteRows);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/// <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, DataTable AuthorityTable = null)
|
||
{
|
||
|
||
TreeListColumnCollection gc = this.TreeListObj.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;
|
||
|
||
if (!item.OptionsColumn.AllowEdit)
|
||
{
|
||
item.AppearanceHeader.Options.UseForeColor = true;
|
||
item.AppearanceHeader.ForeColor = ColorTranslator.FromHtml(HeaderColor);
|
||
}
|
||
else
|
||
{
|
||
item.AppearanceHeader.Options.UseForeColor = true;
|
||
item.AppearanceHeader.ForeColor = ColorTranslator.FromHtml("#00000");
|
||
}
|
||
if (model.FieldType == ControlType.LabMemoEdit) item.OptionsColumn.AllowEdit = true;
|
||
|
||
}
|
||
//必填
|
||
if (Required && RequiredFields.IndexOf(item.FieldName + ",", StringComparison.OrdinalIgnoreCase) != -1)
|
||
{
|
||
item.AppearanceHeader.Options.UseForeColor = true;
|
||
item.AppearanceHeader.ForeColor = RequiredForceColor;
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:刷新数据源</para>
|
||
/// <para>创建人:曹屹峰</para>
|
||
/// <para>创建日期:2023-9-30 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="UpdateColumnRefresh">判断是否只刷新UpdateColumn中配置的列的数据源</param>
|
||
public void RefreshDataSource(bool UpdateColumnRefresh = false)
|
||
{
|
||
//this.mLoading = false;
|
||
SetColumnsSource();
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 设置序号列宽度
|
||
/// </summary>
|
||
public void AdjustIndicatorWidthSmart()
|
||
{
|
||
try
|
||
{
|
||
int nodeCount = this.TreeListObj.AllNodesCount;// 获取节点总数
|
||
if (nodeCount == 0) return;
|
||
// 计算数字宽度(TreeList可能有层级,适当增加系数)
|
||
int numberWidth = (int)(nodeCount.ToString().Length * 7.5) + 16; // 系数和偏移量略大于GridView
|
||
|
||
// 设置宽度(范围可适当放宽,如50-100px,适应层级缩进)
|
||
this.TreeListObj.IndicatorWidth = Math.Max(40, Math.Min(80, numberWidth));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
}
|
||
}
|