3140 lines
138 KiB
C#
3140 lines
138 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 DevExpress.XtraGrid.Views.BandedGrid;
|
||
using System.Collections;
|
||
using System.Data.Common;
|
||
using Lskj.Core;
|
||
|
||
namespace Lskj.Control
|
||
{
|
||
/// <summary>
|
||
/// 表格树
|
||
/// </summary>
|
||
public partial class TreeBandedGridControlEx : TreeGridControlEx
|
||
{
|
||
/// <summary>
|
||
/// 获取模块配置
|
||
/// </summary>
|
||
public ModuleModel moduleModel;
|
||
public override TreeList TreeListObj { get { return gcMain; } }
|
||
|
||
/// <summary>
|
||
/// 树表格固定菜单
|
||
/// </summary>
|
||
public override ContextMenuStrip MenuStrip { get { return contextMenuStrip; } }
|
||
/// <summary>
|
||
/// 默认全部展开
|
||
/// </summary>
|
||
private string _expansion = "1";
|
||
public override string Expansion
|
||
{
|
||
get { return _expansion; }
|
||
set { _expansion = value; }
|
||
}
|
||
|
||
//treeList树展开的节点块
|
||
private List<TreeListNode> _treeListNodes = new List<TreeListNode>();
|
||
public override List<TreeListNode> treeListNodes
|
||
{
|
||
get { return _treeListNodes; }
|
||
set { _treeListNodes = value; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 按初始顺序保存全部gridBand
|
||
/// </summary>
|
||
public List<TreeListBand> saveGridBands = new List<TreeListBand>();
|
||
/// <summary>
|
||
/// 按初始顺序保存全部gridBand对应的二级列名
|
||
/// </summary>
|
||
public Dictionary<TreeListBand, string> saveGridBandColumn = new Dictionary<TreeListBand, string>();
|
||
/// <summary>
|
||
/// 日期类型控件名称
|
||
/// </summary>
|
||
private List<string> DateColumnNames = new List<string>();
|
||
|
||
/// <summary>
|
||
/// 上次选中行
|
||
/// </summary>
|
||
private int lastNodeIndex;
|
||
|
||
public TreeBandedGridControlEx()
|
||
{
|
||
InitializeComponent();
|
||
this.gcMain.IndicatorWidth = 40;
|
||
this.gcMain.KeyDown += new KeyEventHandler(OnTreeGridViewKeyDown);
|
||
this.gcMain.CustomDrawNodeIndicator += TreeListObj_CustomDrawNodeIndicator;//显示行号
|
||
this.gcMain.SelectionChanged += new EventHandler(gcMain_SelectionChanged);
|
||
this.gcMain.CustomDrawNodeCell += new CustomDrawNodeCellEventHandler(OnCustomDrawNodeCell);
|
||
this.gcMain.ColumnFilterChanged += TreeList1_ColumnFilterChanged;
|
||
if (LicenseManager.UsageMode != LicenseUsageMode.Designtime)
|
||
{
|
||
this.SetGridRowHeightAndFont();
|
||
}
|
||
this.gcMain.PopupMenuShowing += new PopupMenuShowingEventHandler(OnPopupMenuShowing);
|
||
|
||
this.gcMain.NodesReloaded += OnNodesReloaded;
|
||
//InitializeTreeMethod();
|
||
//this.gcMain.OptionsBehavior.EnableFiltering = true;
|
||
//this.gcMain.OptionsFind.AlwaysVisible = true;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 节点加载完成后
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnNodesReloaded(object sender, EventArgs e)
|
||
{
|
||
//根据记录展开对应节点
|
||
foreach (TreeListNode treeListNode in treeListNodes)
|
||
{
|
||
TreeListNode treeListNode1 = this.gcMain.Nodes.TreeList.FindNodeByID(treeListNode.Id);
|
||
if (treeListNode1 != null) treeListNode1.Expanded = true;
|
||
}
|
||
this.TreeListObj.FocusedNode = this.TreeListObj.GetNodeByVisibleIndex(lastNodeIndex);
|
||
if ((Expansion + "").Equals("1"))
|
||
{
|
||
this.gcMain.ExpandAll();
|
||
}
|
||
else if ((Expansion + "").Equals("2"))
|
||
{
|
||
this.gcMain.ExpandToLevel(0);
|
||
}
|
||
else if ((Expansion + "").Equals("3"))
|
||
{
|
||
this.gcMain.CollapseAll();
|
||
}
|
||
|
||
//if (selectRowHandler)
|
||
//{
|
||
// this.TreeListObj.FocusedNode = this.TreeListObj.GetNodeByVisibleIndex(lastNodeIndex);
|
||
//}
|
||
}
|
||
|
||
/// <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;
|
||
}
|
||
}
|
||
|
||
private void TreeListObj_CustomDrawNodeIndicator(object sender, CustomDrawNodeIndicatorEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
TreeList tree = sender as DevExpress.XtraTreeList.TreeList;
|
||
DevExpress.Utils.Drawing.IndicatorObjectInfoArgs args = e.ObjectArgs as DevExpress.Utils.Drawing.IndicatorObjectInfoArgs;
|
||
args.DisplayText = (tree.GetVisibleIndexByNode(e.Node) + 1).ToString();
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
void gcMain_SelectionChanged(object sender, EventArgs e)
|
||
{
|
||
//try
|
||
//{
|
||
//List<TreeListCell> cells = this.gcMain.GetSelectedCells();
|
||
//DataRow[] rows = GetViewFocusedDataRows();
|
||
|
||
//this.pl_buttom.Visible = cells.Count > 1 && rows.Length > 1;
|
||
//if (this.pl_buttom.Visible)
|
||
//{
|
||
|
||
// // 分别计算求和、平均值、最大值、最小值、计数
|
||
// double sum = 0, avg = 0, max = 0, min = 0;
|
||
// int count = 0;
|
||
|
||
// foreach (DataRow row in rows)
|
||
// {
|
||
// foreach (TreeListCell cell in cells)
|
||
// {
|
||
// double cellNumber = 0;
|
||
// string cellValue = row[cell.Column.Name] + "";
|
||
// if (double.TryParse(cellValue, out cellNumber))
|
||
// {
|
||
// cellNumber = Convert.ToDouble(cellValue);
|
||
|
||
// if (max < cellNumber)
|
||
// max = cellNumber;
|
||
// if (min == 0 || min > cellNumber)
|
||
// min = cellNumber;
|
||
|
||
// count++;
|
||
// sum += cellNumber;
|
||
// }
|
||
// }
|
||
// }
|
||
|
||
// avg = count == 0 || count == 0 ? 0 : sum / count;
|
||
// lblTotal.Text = string.Format(ResourceKeys.GridTotalDisplayText, count, Math.Round(sum, 2), Math.Round(avg, 2), Math.Round(max, 2), Math.Round(min, 2));
|
||
//}
|
||
//}
|
||
//catch (Exception)
|
||
//{
|
||
//}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:设置表格颜色</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-12 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="table">The table.</param>
|
||
public override void SetGridRowColors(DataTable table)
|
||
{
|
||
this.GridRowColorsTable = table;
|
||
if (table != null && table.Rows.Count > 0)
|
||
{
|
||
DataRow rowItem = table.Select("1=1").FirstOrDefault(x => (x["condition"] + "").Contains("COLUMN_"));
|
||
if (rowItem != null)
|
||
this.gcMain.CustomDrawNodeCell += new CustomDrawNodeCellEventHandler(OnGridViewRowCellStyle);
|
||
else
|
||
this.gcMain.NodeCellStyle += new GetCustomNodeCellStyleEventHandler(OnGridViewRowStyle);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:设置树表格行颜色</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2019-11-15 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="RowStyleEventArgs"/> instance containing the event data.</param>
|
||
protected override void OnGridViewRowStyle(object sender, GetCustomNodeCellStyleEventArgs e)
|
||
{
|
||
if (this.GridRowColorsTable != null && this.GridRowColorsTable.Rows.Count > 0)
|
||
{
|
||
// 渲染界面数据量过多界面刷新会很慢
|
||
DataRowView dataRowView = this.gcMain.GetDataRecordByNode(e.Node) as DataRowView;
|
||
DataRow gridRow = dataRowView != null ? dataRowView.Row : null;
|
||
foreach (DataRow item in this.GridRowColorsTable.Rows)
|
||
{
|
||
string cond = ReplaceHelper.ReplaceRowParam(gridRow, item["condition"] + "");
|
||
try
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(cond) && ReplaceHelper.EvalCond(cond))
|
||
{
|
||
GridRowColorModel model = new GridRowColorModel(item);
|
||
if (!string.IsNullOrWhiteSpace(model.BackColor))
|
||
{
|
||
e.Appearance.BackColor = ColorTranslator.FromHtml(model.BackColor);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(model.ForceColor))
|
||
{
|
||
e.Appearance.ForeColor = ColorTranslator.FromHtml(model.ForceColor);
|
||
}
|
||
|
||
FontStyle fontStyle = new FontStyle();
|
||
if (model.IsBold) fontStyle = fontStyle | FontStyle.Bold;
|
||
if (model.IsItalic) fontStyle = fontStyle | FontStyle.Italic;
|
||
if (model.IsStrickOut) fontStyle = fontStyle | FontStyle.Strikeout;
|
||
if (model.IsUnderLine) fontStyle = fontStyle | FontStyle.Underline;
|
||
|
||
e.Appearance.Font = new Font(e.Appearance.Font, fontStyle);
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
//LogHelper.Instance.WriteLog("GridView RowCellStyle Error. Condition:" + model.Condition + ";EvalCondtion:" + cond);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:设置树表格单元格颜色</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2019-11-15 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs"/> instance containing the event data.</param>
|
||
/// <exception cref="System.NotImplementedException"></exception>
|
||
protected override void OnGridViewRowCellStyle(object sender, CustomDrawNodeCellEventArgs e)
|
||
{
|
||
if (this.GridRowColorsTable != null && this.GridRowColorsTable.Rows.Count > 0 && !string.IsNullOrEmpty(e.CellValue + ""))
|
||
{
|
||
// 渲染界面数据量过多界面刷新会很慢
|
||
DataRowView dataRowView = this.gcMain.GetDataRecordByNode(e.Node) as DataRowView;
|
||
DataRow gridRow = dataRowView != null ? dataRowView.Row : null;
|
||
foreach (DataRow item in this.GridRowColorsTable.Rows)
|
||
{
|
||
string cond = ReplaceHelper.ReplaceRowParam(gridRow, item["condition"] + "").ReplaceColumnParam(e.Column.Name, e.Column.Caption, e.CellValue + "");
|
||
try
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(cond) && ReplaceHelper.EvalCond(cond))
|
||
{
|
||
GridRowColorModel model = new GridRowColorModel(item);
|
||
if (!string.IsNullOrWhiteSpace(model.BackColor))
|
||
{
|
||
e.Appearance.BackColor = ColorTranslator.FromHtml(model.BackColor);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(model.ForceColor))
|
||
{
|
||
e.Appearance.ForeColor = ColorTranslator.FromHtml(model.ForceColor);
|
||
}
|
||
|
||
FontStyle fontStyle = new FontStyle();
|
||
if (model.IsBold) fontStyle = fontStyle | FontStyle.Bold;
|
||
if (model.IsItalic) fontStyle = fontStyle | FontStyle.Italic;
|
||
if (model.IsStrickOut) fontStyle = fontStyle | FontStyle.Strikeout;
|
||
if (model.IsUnderLine) fontStyle = fontStyle | FontStyle.Underline;
|
||
|
||
e.Appearance.Font = new Font(e.Appearance.Font, fontStyle);
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
//LogHelper.Instance.WriteLog("GridView RowCellStyle Error. Condition:" + model.Condition + ";EvalCondtion:" + cond);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <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;
|
||
this.CustomColumKey = customColumKey;
|
||
|
||
|
||
//设置列头自动高度
|
||
this.gcMain.OptionsView.ColumnHeaderAutoHeight = DefaultBoolean.True;
|
||
base.ColumnList.Clear();
|
||
this.gcMain.Bands.Clear();
|
||
this.gcMain.Columns.Clear();
|
||
this.AddBandColumns(table);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:添加多表头列</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-04-11 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="table">The table.</param>
|
||
/// <param name="readOnly">if set to <c>true</c> [read only].</param>
|
||
protected void AddBandColumns(DataTable table, bool readOnly = true)
|
||
{
|
||
if (table == null) return;
|
||
this.InitGridColumsTab = table;
|
||
this.mControlList.Clear();
|
||
List<String> bandFieldstr = new List<String>();
|
||
string bandFields = string.Empty;
|
||
foreach (DataRow item in table.Rows)
|
||
{
|
||
GridColumnModel model = new GridColumnModel(item);
|
||
this.ColumnList.Add(model);
|
||
}
|
||
|
||
Dictionary<int, TreeListBand> gridBandEmptyDic = new Dictionary<int, TreeListBand>();
|
||
TreeListBand gridBandEmpty = new TreeListBand();
|
||
|
||
GridColumnModel[] bandRows = this.ColumnList.Where(x => !string.IsNullOrEmpty(x.BandFields)).ToArray();
|
||
GridColumnModel[] AutobandRows = this.ColumnList.Where(x => x.FieldText.Contains("|")).ToArray();
|
||
GridColumnModel[] bandEmptyRows = null;
|
||
|
||
if (this.moduleModel != null && this.moduleModel.TreeAutoMultiHeader == 1)
|
||
{
|
||
bandEmptyRows = AutobandRows.Length > 0
|
||
? this.ColumnList.Where(x => !x.FieldText.Contains("|") && x.Width > 0).ToArray()
|
||
: this.ColumnList.Where(x => bandRows.Select(n => n.BandFields.Equals(x.FieldName)).Count() == 0 && x.Width > 0).ToArray();
|
||
|
||
foreach (GridColumnModel columnModel in this.ColumnList)
|
||
{
|
||
string bandTitle = !string.IsNullOrEmpty(columnModel.BandFields)
|
||
? columnModel.BandTitle
|
||
: columnModel.FieldText.Contains("|")
|
||
? columnModel.FieldText.Substring(0, columnModel.FieldText.LastIndexOf("|"))
|
||
: string.Empty;
|
||
|
||
TreeListBand gridBand = null;
|
||
|
||
if (!string.IsNullOrEmpty(bandTitle))
|
||
{
|
||
if (bandFieldstr.Contains(bandTitle)) continue;
|
||
bandFieldstr.Add(bandTitle);
|
||
|
||
gridBand = new TreeListBand();
|
||
gridBand.Caption = bandTitle.Replace("\\r\\n", " ");
|
||
gridBand.AppearanceHeader.Options.UseFont = true;
|
||
gridBand.AppearanceHeader.Font = new Font("宋体", 9, FontStyle.Bold);
|
||
gridBand.AppearanceHeader.Options.UseTextOptions = true;
|
||
gridBand.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
|
||
|
||
if (bandTitle.Contains("\\r\\n"))
|
||
{
|
||
gridBand.AppearanceHeader.TextOptions.WordWrap = WordWrap.Wrap;
|
||
gridBand.RowCount = 2;
|
||
}
|
||
|
||
saveGridBands.Add(gridBand);
|
||
this.gcMain.Bands.Add(gridBand);
|
||
gridBandEmpty = new TreeListBand();
|
||
}
|
||
else if ((AutobandRows.Length > 0 && !columnModel.FieldText.Contains("|") && columnModel.Width > 0)
|
||
|| (AutobandRows.Length <= 0 && bandRows.Select(n => n.BandFields.Equals(columnModel.FieldName)).Count() == 0 && columnModel.Width > 0))
|
||
{
|
||
gridBandEmpty.Caption = "";
|
||
gridBandEmpty.AppearanceHeader.Options.UseFont = true;
|
||
gridBandEmpty.AppearanceHeader.Font = new Font("宋体", 9, FontStyle.Bold);
|
||
gridBandEmpty.AppearanceHeader.Options.UseTextOptions = true;
|
||
gridBandEmpty.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
|
||
|
||
if (this.moduleModel.BandSequentialMode)
|
||
{
|
||
if (!gcMain.Bands.Contains(gridBandEmpty))
|
||
{
|
||
gcMain.Bands.Add(gridBandEmpty);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
TreeListBand treeListBand = gcMain.Bands.Cast<TreeListBand>().FirstOrDefault(x => string.IsNullOrEmpty(x.Caption));
|
||
if (treeListBand == null)
|
||
{
|
||
gcMain.Bands.Add(gridBandEmpty);
|
||
}
|
||
}
|
||
|
||
gridBandEmptyDic.Add(this.ColumnList.IndexOf(columnModel), gridBandEmpty);
|
||
}
|
||
}
|
||
}
|
||
|
||
// 创建列
|
||
for (int i = 0; i < this.ColumnList.Count; i++)
|
||
{
|
||
GridColumnModel model = this.ColumnList[i];
|
||
int startIndex = model.FieldText.Contains("|") ? model.FieldText.LastIndexOf("|") : 0;
|
||
string FieldText = startIndex > 0 ? model.FieldText.Substring(startIndex + 1) : model.FieldText;
|
||
|
||
TreeListColumn gridColumn = new TreeListColumn();
|
||
gridColumn.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
|
||
|
||
string bandTitle = startIndex > 0 ? model.FieldText.Substring(0, startIndex) : HasBand(model.FieldName, bandRows);
|
||
|
||
TreeListBand gridBand = gcMain.Bands.Cast<TreeListBand>().FirstOrDefault(x => x.Caption == bandTitle);
|
||
|
||
if (gridBand != null && !string.IsNullOrEmpty(gridBand.Caption))
|
||
{
|
||
gridBand.Columns.Add(gridColumn);
|
||
if (saveGridBandColumn.ContainsKey(gridBand))
|
||
saveGridBandColumn[gridBand] += model.FieldName + "^";
|
||
else
|
||
saveGridBandColumn.Add(gridBand, model.FieldName + "^");
|
||
}
|
||
else if (bandEmptyRows != null && bandEmptyRows.Contains(model))
|
||
{
|
||
if (this.moduleModel != null && this.moduleModel.BandSequentialMode)
|
||
gridBandEmptyDic[this.ColumnList.IndexOf(model)].Columns.Add(gridColumn);
|
||
else
|
||
gridBandEmpty.Columns.Add(gridColumn);
|
||
}
|
||
|
||
gcMain.Columns.Add(gridColumn);
|
||
|
||
gridColumn.FieldName = model.FieldName;
|
||
gridColumn.Caption = FieldText;
|
||
gridColumn.Width = model.Width;
|
||
gridColumn.Visible = model.Visible;
|
||
gridColumn.OptionsColumn.AllowEdit = !readOnly && model.Edit;
|
||
gridColumn.Tag = model;
|
||
gridColumn.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
|
||
|
||
if (model.DataAlignment > 0)
|
||
{
|
||
gridColumn.AppearanceCell.Options.UseTextOptions = true;
|
||
gridColumn.AppearanceCell.TextOptions.HAlignment = model.DataAlignment == 1
|
||
? HorzAlignment.Center
|
||
: HorzAlignment.Far;
|
||
}
|
||
|
||
SetColumnFormat(gridColumn, model);
|
||
SetColumnSumming(gridColumn, model);
|
||
InitEditColumns(gridColumn, model);
|
||
|
||
if (model.RepeatedVerification)
|
||
this.RepeatedVerificationNames.Add(model.FieldName);
|
||
}
|
||
SetCustomColumns();
|
||
this.mLoading = false;
|
||
this.mTimer.Tick += mTimerTick;
|
||
this.mTimer.Start();
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:是否为多表头</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-25 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="fieldName">Name of the field.</param>
|
||
/// <param name="bands">The bands.</param>
|
||
protected string HasBand(string fieldName, GridColumnModel[] bands)
|
||
{
|
||
foreach (GridColumnModel model in bands)
|
||
{
|
||
if (("|" + model.BandFields + "|").Contains("|" + fieldName + "|"))
|
||
{
|
||
return model.BandTitle;
|
||
}
|
||
}
|
||
return string.Empty;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/// <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 override 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.LabSelectReturnIdNew:
|
||
case ControlType.LabSelectReturnTextNew:
|
||
InitSelectReturnId(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 override 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 override 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 override 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 override 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 override 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 override 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 override 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 override 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 override 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 override 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 override 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.Disposed += (s, e) =>
|
||
{
|
||
mutilLookUp?.Dispose();
|
||
mutilLookUp = null;
|
||
};
|
||
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 override 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 override 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 override 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 override 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)
|
||
{
|
||
FrmModelLookUp2 modelLookUp = new FrmModelLookUp2(model.addModuleld);
|
||
modelLookUp.ValueField = model.ValueMember;
|
||
modelLookUp.TextField = model.TextMember;
|
||
modelLookUp.SourceSQL = model.SqlSource;
|
||
modelLookUp.IsType = model.FieldType;
|
||
modelLookUp.ValueMember = model.FieldType == ControlType.LabSelectReturnIdNew ? model.ValueMember : model.TextMember;
|
||
modelLookUp.Tag = model;
|
||
|
||
RepositoryItemCheckedComboBoxEdit btnEdit = new RepositoryItemCheckedComboBoxEdit();
|
||
btnEdit.NullText = "";
|
||
btnEdit.PopupBorderStyle = PopupBorderStyles.Flat;
|
||
btnEdit.AllowNullInput = DefaultBoolean.False;
|
||
btnEdit.DisplayMember = model.TextMember;
|
||
btnEdit.SeparatorChar = ',';
|
||
btnEdit.ValueMember = model.FieldType == ControlType.LabSelectReturnIdNew ? model.ValueMember : model.TextMember;
|
||
if (model.ModuleFrameDisplayText)
|
||
{
|
||
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(OnModuleChoice);
|
||
|
||
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.LabSelectReturnIdNew ? 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 override 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-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;
|
||
//设置列头自动高度
|
||
this.gcMain.OptionsView.ColumnHeaderAutoHeight = DefaultBoolean.True;
|
||
base.ColumnList.Clear();
|
||
this.gcMain.Bands.Clear();
|
||
this.gcMain.Columns.Clear();
|
||
this.AddBandColumns(table, false);
|
||
}
|
||
/// <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 InitializeTreeMethod()
|
||
{
|
||
this.TreeListObj.CellValueChanging += new DevExpress.XtraTreeList.CellValueChangedEventHandler(OnCellValueChaning);
|
||
}
|
||
|
||
|
||
protected override 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 override 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 override 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 override void SetGridRowHeightAndFont()
|
||
{
|
||
if (SystemInfo.Instance.GridRowFontSize > 0)
|
||
this.TreeListObj.Appearance.Row.Font = new Font("微软雅黑", SystemInfo.Instance.GridRowFontSize);
|
||
if (SystemInfo.Instance.GridRowHeight > 0)
|
||
{
|
||
this.TreeListObj.ColumnPanelRowHeight = this.TreeListObj.RowHeight = SystemInfo.Instance.GridRowHeight;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:保存树表格表格属性</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2019-11-14 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected override void SaveItemClick(object sender, EventArgs e)
|
||
{
|
||
if (string.IsNullOrEmpty(this.CustomColumKey))
|
||
{
|
||
MessageUtil.Show(ResourceKeys.NotSettingResetColumn);
|
||
return;
|
||
}
|
||
|
||
DataRow rowItem = null;
|
||
bool success = BaseImpl.HasExistsDataRow(ResourceKeys.SettingTableName, "formKey", CustomColumKey.ToString(), string.Format(" and OperatorName='{0}' ", ERPInfo.Instance.UserName), out rowItem);
|
||
if (!success)
|
||
{
|
||
MessageUtil.Show(ResourceKeys.NotFoundSettingColumnTable);
|
||
return;
|
||
}
|
||
|
||
if (MessageUtil.Show(ResourceKeys.IsSaveColumn, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
{
|
||
try
|
||
{
|
||
if (rowItem == null)
|
||
{
|
||
success = this.gcMain.SaveCustomColumnToDatabase(this.CustomColumKey);
|
||
}
|
||
else
|
||
{
|
||
success = this.gcMain.UpdateCustomColumnToDatabase(this.CustomColumKey);
|
||
}
|
||
|
||
MessageUtil.Show(success ? ResourceKeys.SaveSuccess : ResourceKeys.SaveFault);
|
||
}
|
||
catch (SqlException sex)
|
||
{
|
||
if (sex.Message.Contains(ResourceKeys.FieldLenIsShort) &&
|
||
MessageUtil.Show(ResourceKeys.SaveFault + "\r\n" + ResourceKeys.CanUpgradeTable, MessageBoxButtons.YesNo) == DialogResult.Yes &&
|
||
|
||
|
||
|
||
|
||
BaseImpl.UpdateTableField(ResourceKeys.SettingTableName, "formKey", "varchar(200)"))
|
||
{
|
||
MessageUtil.Show(ResourceKeys.UpdateSuccess);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
LogUtil.WriteError("保存表格属性出错", ex);
|
||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:重置树表格属性</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2019-11-14 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected override void ResetItemClick(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (string.IsNullOrEmpty(this.CustomColumKey))
|
||
{
|
||
MessageUtil.Show(ResourceKeys.NotSettingResetColumn);
|
||
return;
|
||
}
|
||
if (!BaseImpl.HasExistsTable(ResourceKeys.SettingTableName))
|
||
{
|
||
MessageUtil.Show(ResourceKeys.NotFoundSettingColumnTable);
|
||
return;
|
||
}
|
||
if (MessageUtil.Show(ResourceKeys.IsResetColumn, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
{
|
||
bool success = this.gcMain.ResetCustomColumnToDatabase(this.CustomColumKey);
|
||
|
||
DataTable customTable = this.gcMain.GetCustomColumnByDatabase(this.CustomColumKey);
|
||
this.SetCustomColumns(customTable, false);
|
||
MessageUtil.Show(success ? ResourceKeys.ResetSuccess : ResourceKeys.ResetFault);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:导出表格数据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-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-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 override void SetColumnFormat(TreeListColumn gridColumn, GridColumnModel model)
|
||
{
|
||
if (gridColumn == null || model == null) return;
|
||
|
||
// 格式化数字
|
||
if (!string.IsNullOrEmpty(model.DataFormat))
|
||
{
|
||
if (model.FieldType == ControlType.LabTextInt || model.FieldType == ControlType.LabCalcText)
|
||
{
|
||
gridColumn.Format.FormatType = FormatType.Numeric;
|
||
gridColumn.Format.FormatString = model.DataFormat;
|
||
}
|
||
else
|
||
{
|
||
gridColumn.Format.FormatType = FormatType.Custom;
|
||
gridColumn.Format.FormatString = model.DataFormat;
|
||
}
|
||
}
|
||
// 特殊字段格式化
|
||
if (model.CanAccuracy)
|
||
{
|
||
gridColumn.Format.FormatType = FormatType.Numeric;
|
||
gridColumn.Format.FormatString = "F2";
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:设置列汇总</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-03-21 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="gridColumn">The grid column.</param>
|
||
/// <param name="model">The model.</param>
|
||
private void SetColumnSumming(TreeListColumn gridColumn, GridColumnModel model)
|
||
{
|
||
// 设置底部合计
|
||
if (gridColumn.VisibleIndex == 0)
|
||
{
|
||
gcMain.OptionsView.ShowSummaryFooter = true;
|
||
gridColumn.AllNodesSummary = true;
|
||
gridColumn.SummaryFooter = SummaryItemType.Count;
|
||
gridColumn.RowFooterSummaryStrFormat = "合计:{0:#,###}行";
|
||
}
|
||
else
|
||
{
|
||
if (model.CanSum)
|
||
{
|
||
gcMain.OptionsView.ShowSummaryFooter = true;
|
||
gridColumn.AllNodesSummary = true;
|
||
gridColumn.SummaryFooter = DevExpress.XtraTreeList.SummaryItemType.Sum;
|
||
gridColumn.RowFooterSummaryStrFormat = "{0:" + model.DataFormat + "}";
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:设置自定义列(适配TreeList)</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-02-01 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <summary>
|
||
/// 设置自定义列(适配TreeList,精准修正OwnerBand不存在的问题)
|
||
/// </summary>
|
||
/// <summary>
|
||
/// <para>说明:设置自定义列(适配TreeList)</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-02-01 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
protected virtual void SetCustomColumns(bool isInit = true)
|
||
{
|
||
if (string.IsNullOrEmpty(this.CustomColumKey) || !BaseImpl.HasExistsTable(ResourceKeys.SettingTableName)) return;
|
||
if (!BaseImpl.HasExistsColumn(ResourceKeys.SettingTableName, "FieldText"))
|
||
{
|
||
BaseImpl.ExecSqlValue("alter table " + ResourceKeys.SettingTableName + " add FieldText varchar(100)");
|
||
}
|
||
|
||
DataTable customTable = this.gcMain.GetCustomColumnByDatabase(this.CustomColumKey);
|
||
if (customTable != null && customTable.Rows.Count > 0)
|
||
{
|
||
int MaxIndex = customTable.Columns.Count;
|
||
foreach (DataRow rowItem in customTable.Rows)
|
||
{
|
||
string fieldName = rowItem["fieldName"] + "";
|
||
string FieldText = rowItem["FieldText"] + "";
|
||
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 treeColumn = this.gcMain.Columns[fieldName];
|
||
|
||
if (column != null && !string.IsNullOrEmpty(fieldName) && treeColumn != null && treeColumn.Visible && treeColumn.Width > 0)
|
||
{
|
||
TreeListBand treeBand = gcMain.Bands.Cast<TreeListBand>().FirstOrDefault(b => b.Columns.Contains(treeColumn));
|
||
|
||
if (index >= 0 && index <= this.gcMain.Columns.Count - 1)
|
||
{
|
||
this.gcMain.Columns.Remove(treeColumn);
|
||
TreeListColumn newColumn = this.gcMain.Columns.Insert(index);
|
||
|
||
//重新设置列属性
|
||
newColumn.FieldName = fieldName;
|
||
newColumn.Caption = FieldText;
|
||
newColumn.Width = fieldWidth;
|
||
newColumn.VisibleIndex = index;
|
||
newColumn.Visible = visible;
|
||
newColumn.Tag = column;
|
||
newColumn.OptionsColumn.AllowEdit = treeColumn.OptionsColumn.AllowEdit;
|
||
|
||
if (treeBand != null)
|
||
{
|
||
treeBand.Columns.Add(newColumn);
|
||
treeBand.Fixed = isFix ? FixedStyle.Left : FixedStyle.None;
|
||
}
|
||
|
||
if (FieldText.Contains("|") && isFix)
|
||
{
|
||
FixLeftItemClick(newColumn, new EventArgs());
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
foreach (TreeListColumn col in this.gcMain.Columns)
|
||
{
|
||
DataRow a = customTable.Rows.Cast<DataRow>().FirstOrDefault(x => col.Name.Equals(x["fieldName"] + "", StringComparison.OrdinalIgnoreCase));
|
||
if (a == null)
|
||
{
|
||
bool visible = col.Visible;
|
||
col.VisibleIndex = MaxIndex;
|
||
MaxIndex += 1;
|
||
col.Visible = visible;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (!isInit)
|
||
{
|
||
for (int i = 0; i < this.ColumnList.Count; i++)
|
||
{
|
||
GridColumnModel column = this.ColumnList[i];
|
||
if (this.gcMain.Columns[column.FieldName] != null)
|
||
{
|
||
TreeListColumn colObj = this.gcMain.Columns[column.FieldName];
|
||
colObj.VisibleIndex = i;
|
||
colObj.Width = column.Width;
|
||
colObj.Visible = column.Visible;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:监听树表格键盘事件</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2019-11-04 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="KeyEventArgs"/> instance containing the event data.</param>
|
||
protected override void OnTreeGridViewKeyDown(object sender, KeyEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
// 复制单元格
|
||
if (e.Control && e.KeyCode == Keys.C)
|
||
{
|
||
var selectNodes = this.gcMain.Selection;
|
||
if (selectNodes != null && selectNodes.Count == 1)
|
||
{
|
||
//object obj = gridView.GetFocusedRowCellValue(gridView.FocusedColumn);
|
||
object obj = this.gcMain.FocusedNode.GetDisplayText(this.gcMain.FocusedColumn);
|
||
if (obj != null)
|
||
{
|
||
Clipboard.SetDataObject(obj + "");
|
||
e.Handled = true;
|
||
}
|
||
}
|
||
else if (selectNodes != null && selectNodes.Count > 1)
|
||
{
|
||
DataRow[] dataRows = new DataRow[selectNodes.Count];
|
||
string copySummary = string.Empty;
|
||
for (int i = 0; i < selectNodes.Count; i++)
|
||
{
|
||
TreeListNode treeNode = selectNodes[i];
|
||
List<TreeListColumn> cells = gcMain.GetSelectedCells(treeNode);
|
||
DataRowView dataRowView = this.gcMain.GetDataRecordByNode(treeNode) as DataRowView;
|
||
dataRows[i] = dataRowView != null ? dataRowView.Row : null;
|
||
foreach (TreeListColumn cell in cells)
|
||
{
|
||
copySummary += dataRows[i][cell.Name] + "\t";
|
||
}
|
||
copySummary += "\n";
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(copySummary))
|
||
{
|
||
copySummary = copySummary.TrimEnd('\n');
|
||
Clipboard.SetDataObject(copySummary);
|
||
e.Handled = true;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
gcMain.CopyToClipboard();
|
||
e.Handled = true;
|
||
}
|
||
}
|
||
else if (e.Modifiers.CompareTo(Keys.Control) == 0 && e.KeyCode == Keys.V)
|
||
{
|
||
//if (this.gridView.IsFindPanelVisible)
|
||
//{
|
||
// MessageUtil.Show("搜索模式下无法粘贴行.");
|
||
// return;
|
||
//}
|
||
object _objData = null;
|
||
IDataObject dataObj = Clipboard.GetDataObject();
|
||
|
||
if (dataObj.GetDataPresent(DataFormats.Text))
|
||
_objData = dataObj.GetData(DataFormats.Text);
|
||
NewPasteMethod(e, _objData);
|
||
}
|
||
else if (e.Control && e.KeyCode == Keys.F)
|
||
{
|
||
this.gcMain.ShowFindPanel();
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:获取选中行数据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-10-18 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <returns>DataRow.</returns>
|
||
public override DataRow GetViewFocusedDataRow()
|
||
{
|
||
TreeListNode treeNode = this.gcMain.FocusedNode as TreeListNode;
|
||
|
||
if (treeNode != null)
|
||
{
|
||
DataRowView dataRowView = this.gcMain.GetDataRecordByNode(treeNode) as DataRowView;
|
||
return dataRowView != null ? dataRowView.Row : null;
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:获取选中行数据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-10-18 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <returns>DataRow[].</returns>
|
||
public override DataRow[] GetViewFocusedDataRows()
|
||
{
|
||
var selectNodes = this.gcMain.Selection;
|
||
DataRow[] dataRows = new DataRow[selectNodes.Count];
|
||
|
||
for (int i = 0; i < selectNodes.Count; i++)
|
||
{
|
||
TreeListNode treeNode = selectNodes[i];
|
||
DataRowView dataRowView = this.gcMain.GetDataRecordByNode(treeNode) as DataRowView;
|
||
dataRows[i] = dataRowView != null ? dataRowView.Row : null;
|
||
}
|
||
return dataRows;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:设置数据源</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-03-30 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="table">The table.</param>
|
||
/// <param name="selectRowHandler">if set to <c>true</c> [select row handler].</param>
|
||
public override DataTable GetGridViewDataSource()
|
||
{
|
||
return this.gcMain.DataSource as DataTable;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:设置数据源</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-03-30 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="table">The table.</param>
|
||
/// <param name="selectRowHandler">if set to <c>true</c> [select row handler].</param>
|
||
public override void SetGridViewDataSource(DataTable table, bool selectRowHandler = true)
|
||
{
|
||
if (this.ColumnList == null || this.ColumnList.Count == 0)
|
||
{
|
||
this.gcMain.Bands.Clear();
|
||
this.gcMain.Columns.Clear();
|
||
}
|
||
TreeListNode lastNode = this.TreeListObj.FocusedNode;
|
||
|
||
lastNodeIndex = 0;
|
||
if (selectRowHandler) lastNodeIndex = this.TreeListObj.GetVisibleIndexByNode(this.TreeListObj.FocusedNode);
|
||
|
||
GetTreeExpanded();
|
||
this.gcMain.DataSource = table;
|
||
this.SetAutoColumns();
|
||
//根据记录展开对应节点
|
||
foreach (TreeListNode treeListNode in treeListNodes)
|
||
{
|
||
TreeListNode treeListNode1 = this.gcMain.Nodes.TreeList.FindNodeByID(treeListNode.Id);
|
||
if (treeListNode1 != null) treeListNode1.Expanded = true;
|
||
}
|
||
//if (selectRowHandler)
|
||
//{
|
||
// this.TreeListObj.FocusedNode = lastNode;
|
||
//}
|
||
}
|
||
public override int SetGridViewDataSource(DbDataAdapter adapter, bool selectRowHandler = true)
|
||
{
|
||
if (adapter == null) return 0;
|
||
DbDataAdapter previousAdapter = this.AdapterObj;
|
||
if (this.ColumnList == null || this.ColumnList.Count == 0)
|
||
{
|
||
this.gcMain.Bands.Clear();
|
||
this.gcMain.Columns.Clear();
|
||
}
|
||
TreeListNode lastNode = this.TreeListObj.FocusedNode;
|
||
|
||
lastNodeIndex = 0;
|
||
if (selectRowHandler) lastNodeIndex = this.TreeListObj.GetVisibleIndexByNode(this.TreeListObj.FocusedNode);
|
||
|
||
DataSet dataSet = new DataSet();
|
||
//adapter.Fill(dataSet, "SetGridViewDataSource");
|
||
// 重连配置
|
||
int maxRetryCount = 2; // 次数
|
||
int retryDelay = 1000; // 等待时间
|
||
try
|
||
{
|
||
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;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
dataSet.Dispose();
|
||
DisposeDataAdapter(adapter);
|
||
throw;
|
||
}
|
||
|
||
DataTable resultTable = dataSet.Tables.Count > 0 ? dataSet.Tables[0] : null;
|
||
int rowCount = resultTable == null ? 0 : resultTable.Rows.Count;
|
||
if (resultTable != null)
|
||
{
|
||
dataSet.Tables.Remove(resultTable);
|
||
}
|
||
dataSet.Dispose();
|
||
|
||
DisposeAdapterCommandBuilder();
|
||
if (previousAdapter != null && !ReferenceEquals(previousAdapter, adapter))
|
||
{
|
||
DisposeDataAdapter(previousAdapter);
|
||
}
|
||
this.AdapterObj = adapter;
|
||
|
||
SetAdapterCommandBuilder(this.AdapterObj);
|
||
//SqlCommandBuilder cb = new SqlCommandBuilder(this.AdapterObj);
|
||
|
||
GetTreeExpanded();
|
||
this.gcMain.DataSource = resultTable;
|
||
this.SetAutoColumns();
|
||
//根据记录展开对应节点
|
||
foreach (TreeListNode treeListNode in treeListNodes)
|
||
{
|
||
TreeListNode treeListNode1 = this.gcMain.Nodes.TreeList.FindNodeByID(treeListNode.Id);
|
||
if (treeListNode1 != null) treeListNode1.Expanded = true;
|
||
}
|
||
|
||
if ((Expansion + "").Equals("1"))
|
||
{
|
||
this.gcMain.ExpandAll();
|
||
}
|
||
else if ((Expansion + "").Equals("2"))
|
||
{
|
||
this.gcMain.ExpandToLevel(0);
|
||
}
|
||
else if ((Expansion + "").Equals("3"))
|
||
{
|
||
this.gcMain.CollapseAll();
|
||
}
|
||
if (selectRowHandler)
|
||
{
|
||
this.TreeListObj.FocusedNode = lastNode;
|
||
}
|
||
return rowCount;
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:设置动态列</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-06-03 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
protected override void SetAutoColumns()
|
||
{
|
||
try
|
||
{
|
||
bool isShowFooter = false;
|
||
if (this.ColumnList == null || this.ColumnList.Count == 0)
|
||
{
|
||
this.SuspendLayout();
|
||
this.ResumeLayout();
|
||
List<String> bandEmptyRows = new List<String>();
|
||
List<String> bandFields = new List<String>();
|
||
DataRow dr = MainImpl.GetSystemdllTab(this.Model.ModuleCode);
|
||
bool isEdit = false;//是否可操作
|
||
if (dr != null && !(this.Model is DynamicReportModel))
|
||
{
|
||
ModuleModel SysModel = new ModuleModel(dr);
|
||
isEdit = SysModel.CanEdit;
|
||
}
|
||
if (this is TreeBandedGridControlEx)
|
||
{
|
||
|
||
TreeListBand gridBandEmpty = new TreeListBand();
|
||
foreach (TreeListColumn item in gcMain.Columns)
|
||
{
|
||
//if (item.FieldName.StartsWith("|")) item.FieldName = item.FieldName.Replace("|","");
|
||
if (item.FieldName.Contains("|"))
|
||
{
|
||
int index = item.FieldName.LastIndexOf("|");
|
||
string bandField = item.FieldName.Substring(0, index);
|
||
if (!bandFields.Contains(bandField)) bandFields.Add(bandField);
|
||
}
|
||
else
|
||
{
|
||
bandEmptyRows.Add(item.FieldName);
|
||
}
|
||
}
|
||
foreach (string bandName in bandFields)
|
||
{
|
||
TreeListBand gridBand = new TreeListBand();
|
||
gridBand.Caption = bandName;
|
||
gridBand.AppearanceHeader.Options.UseFont = true;
|
||
gridBand.AppearanceHeader.Font = new Font("宋体", 9, FontStyle.Bold);
|
||
gridBand.AppearanceHeader.Options.UseTextOptions = true;
|
||
gridBand.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
|
||
gcMain.Bands.AddRange(new TreeListBand[] { gridBand });
|
||
//bandFields += "|" + item.BandFields;
|
||
}
|
||
if (bandEmptyRows != null && bandEmptyRows.Count() > 0)
|
||
{
|
||
// 空白列
|
||
gridBandEmpty.Caption = "";
|
||
gridBandEmpty.AppearanceHeader.Options.UseFont = true;
|
||
gridBandEmpty.AppearanceHeader.Font = new Font("宋体", 9, FontStyle.Bold);
|
||
gridBandEmpty.AppearanceHeader.Options.UseTextOptions = true;
|
||
gridBandEmpty.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
|
||
gcMain.Bands.Insert(0, gridBandEmpty);
|
||
}
|
||
gcMain.BeginUpdate();
|
||
// 创建列
|
||
for (int i = 0; i < gcMain.Columns.Count; i++)
|
||
{
|
||
TreeListColumn col = gcMain.Columns[i];
|
||
int vsNum = 0; bool isNum = false; string FieldName = col.FieldName; string bandTitle = string.Empty;
|
||
col.VisibleIndex = i;
|
||
if (col.FieldName.Contains("|"))
|
||
{
|
||
string[] colSplit = col.FieldName.Split('|');
|
||
if (colSplit.Length >= 2)
|
||
{
|
||
FieldName = colSplit[1];
|
||
bandTitle = colSplit[0];
|
||
}
|
||
}
|
||
if (col.VisibleIndex == 0)
|
||
{
|
||
isShowFooter = true;
|
||
|
||
gcMain.OptionsView.ShowSummaryFooter = true;
|
||
col.AllNodesSummary = true;
|
||
col.SummaryFooter = SummaryItemType.Count;
|
||
col.SummaryFooterStrFormat = "合计:{0:#,###}行";
|
||
|
||
}
|
||
if (FieldName.Contains("_"))
|
||
{
|
||
string[] colparame = FieldName.Split('_');
|
||
if (colparame.Length >= 2)
|
||
{
|
||
FieldName = colparame[0];
|
||
isNum = Int32.TryParse(colparame[1], out vsNum);
|
||
if (vsNum == 0)
|
||
col.Visible = false;
|
||
if (colparame.Length > 2)
|
||
{
|
||
bool visible = "1".Equals(colparame[2]);
|
||
// 设置底部合计
|
||
if (visible)
|
||
{
|
||
isShowFooter = true;
|
||
|
||
gcMain.OptionsView.ShowSummaryFooter = true;
|
||
col.AllNodesSummary = true;
|
||
col.SummaryFooter = DevExpress.XtraTreeList.SummaryItemType.Sum;
|
||
col.SummaryFooterStrFormat = "{0:}";
|
||
}
|
||
if (colparame.Length > 3)
|
||
{
|
||
string dataFormat = colparame[3];
|
||
if (!string.IsNullOrWhiteSpace(dataFormat))
|
||
{
|
||
col.Format.FormatType = FormatType.Custom;
|
||
col.Format.FormatString = dataFormat;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(bandTitle))
|
||
{
|
||
// 绑定了多表头显示
|
||
TreeListBand gridBand = gcMain.Bands.Cast<TreeListBand>().FirstOrDefault(x => x.Caption == bandTitle);
|
||
if (gridBand != null)
|
||
{
|
||
gridBand.Columns.Add(col);//
|
||
TreeListBandColumnCollection gcc = gridBand.Columns;
|
||
}
|
||
gcMain.Columns.Add(col);
|
||
}
|
||
else
|
||
{
|
||
// 未绑定多表头则直接显示
|
||
if (bandEmptyRows != null && bandEmptyRows.Contains(col.FieldName))
|
||
{
|
||
gridBandEmpty.Columns.Add(col);
|
||
}
|
||
gcMain.Columns.Add(col);
|
||
}
|
||
if (isNum) col.Width = vsNum;
|
||
|
||
col.OptionsColumn.AllowEdit = isEdit;
|
||
//col.FieldName = FieldName;
|
||
//col.Name = FieldName;
|
||
col.Caption = FieldName;
|
||
col.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
|
||
col.OptionsFilter.FilterPopupMode = FilterPopupMode.CheckedList;
|
||
col.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
|
||
//gcMain.OptionsView.ShowFooter = isShowFooter;
|
||
}
|
||
gcMain.EndUpdate();
|
||
//this.bandedGridView.DataSource = bandedGridView.DataSource as DataTable;
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 记录展开的节点
|
||
/// </summary>
|
||
public override void GetTreeExpanded()
|
||
{
|
||
|
||
treeListNodes.Clear();
|
||
foreach (TreeListNode n in this.gcMain.Nodes)
|
||
{
|
||
setRecursive(n);
|
||
}
|
||
}
|
||
|
||
|
||
public override void setRecursive(TreeListNode treeNode)
|
||
{
|
||
if (treeNode.Expanded) treeListNodes.Add(treeNode);
|
||
// Visit each node recursively.
|
||
foreach (TreeListNode tn in treeNode.Nodes)
|
||
{
|
||
setRecursive(tn);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:全部展开</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-08-13 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnAllExpandClick(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
this.gcMain.ExpandAll();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:全部合并</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-08-13 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnAllMergeClick(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
this.gcMain.CollapseAll();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:自动搜索框弹出时</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-06-10 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="PopupMenuShowingEventArgs"/> instance containing the event data.</param>
|
||
protected override 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 override 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 override void OnModuleChoice(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;
|
||
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)
|
||
{
|
||
btnEdit.EditValue = modelLookUp.EditValue;
|
||
}
|
||
|
||
}
|
||
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 override 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.gcMain.Columns)
|
||
{
|
||
GridColumnModel colModel = gridColumn.Tag as GridColumnModel;
|
||
if (!string.IsNullOrEmpty(colModel.unionCompare) && colModel.unionCompare.Trim().Split('^').Length == 2)
|
||
{
|
||
string[] fields = colModel.unionCompare.Trim().Split('^');
|
||
string inField = fields[0];
|
||
string outField = fields[1];
|
||
if (returnRow.Table.Columns.Contains(inField))
|
||
{
|
||
dataRow[outField] = returnRow[inField] + "";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//btnEdit.EditValue = modelLookUp.EditValue;
|
||
foreach (DataColumn col in returnRow.Table.Columns)
|
||
{
|
||
if (dataRow.Table.Columns.Contains(col.ColumnName))
|
||
{
|
||
dataRow[col.ColumnName] = returnRow[col.ColumnName] + "";
|
||
}
|
||
}
|
||
}
|
||
SendKeys.Send("{Esc}");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex, Model.ModuleCode);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:重写表格选中事件.</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2020-10-30 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs"/> instance containing the event data.</param>
|
||
private void OnCustomDrawNodeCell(object sender, CustomDrawNodeCellEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (e.Node == this.gcMain.FocusedNode)
|
||
e.Appearance.BackColor = ColorTranslator.FromHtml("#9feb6a");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// 粘贴功能
|
||
/// </summary>
|
||
/// <param name="e"></param>
|
||
/// <param name="_objData"></param>
|
||
private void NewPasteMethod(KeyEventArgs e, object _objData)
|
||
{
|
||
if (_objData != null)
|
||
{
|
||
string _tempStr = _objData.ToString();
|
||
_tempStr = Regex.Replace(_tempStr, "\"[^\"]*(?:\"\"[^\"]*)*\"", m => m.Value.Replace("\r\n", "{lskj}").Replace("\"", ""));
|
||
|
||
int _rowNumber = 1;
|
||
int _pasteRowCount = 1;
|
||
string[] _split = { "\r\n" };
|
||
string[] _arrayRowStr = _tempStr.Split(_split, StringSplitOptions.None);
|
||
if (_arrayRowStr.Length < 1)
|
||
return;
|
||
TreeListColumn focColumn = this.gcMain.FocusedColumn;
|
||
focColumn = focColumn == null ? this.gcMain.Columns[0] : focColumn;
|
||
if (focColumn != null)
|
||
{
|
||
DataTable table = this.GetGridViewDataSource();
|
||
int beforeNumber = table.Rows.Count;
|
||
_rowNumber = this.gcMain.GetVisibleIndexByNode(this.gcMain.FocusedNode);
|
||
if (_rowNumber < 0)
|
||
{
|
||
_rowNumber = 0;
|
||
}
|
||
if (_arrayRowStr.Length != this.gcMain.Selection.Count)
|
||
{
|
||
//选择区域与粘贴行数不匹配
|
||
}
|
||
_pasteRowCount = _arrayRowStr.Length;
|
||
for (int i = 0; i < _pasteRowCount; i++)
|
||
{
|
||
string[] _arrayStr2 = _arrayRowStr[i].Split('\t');
|
||
if ((i == _pasteRowCount - 1 && _arrayRowStr[_pasteRowCount - 1].Replace("\r\n", "").Trim() == ""))
|
||
continue;
|
||
DataRow newRow = null;
|
||
if (_rowNumber + 1 > table.Rows.Count)
|
||
{
|
||
newRow = table.NewRow();
|
||
//table.Rows.Add(newRow);
|
||
TreeListColumnCollection gridColumns = this.gcMain.Columns;
|
||
this.gcMain.FocusedNode = this.gcMain.GetNodeByVisibleIndex(_rowNumber);
|
||
foreach (TreeListColumn col in gridColumns)
|
||
{
|
||
GridColumnModel model = col.Tag as GridColumnModel;
|
||
string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue);
|
||
|
||
if (model.DefaultValue != null && model.DefaultValue.Contains("{#") && this.ParentControl != null)
|
||
{
|
||
fieldValue = this.ParentControl.ReplaceParentControlValue(model.DefaultValue);
|
||
if (!string.IsNullOrEmpty(fieldValue))
|
||
{
|
||
newRow[col.FieldName] = fieldValue;
|
||
}
|
||
}
|
||
else if (!string.IsNullOrEmpty(model.DefaultValue) && !model.DefaultValue.Contains("{ROW_"))
|
||
{
|
||
newRow[col.FieldName] = fieldValue;
|
||
}
|
||
}
|
||
}
|
||
this.gcMain.FocusedNode = this.gcMain.GetNodeByVisibleIndex(_rowNumber);
|
||
if (_arrayStr2.Length == 0)
|
||
_arrayStr2[0] = _arrayRowStr[i];
|
||
int _colNumber = beforeNumber == 0 ? 0 : focColumn.VisibleIndex;
|
||
|
||
for (int j = 0; j < _arrayStr2.Length; j++)//j = _colNumber
|
||
{
|
||
TreeListColumn col = this.gcMain.VisibleColumns[_colNumber];
|
||
|
||
GridColumnModel model = col.Tag as GridColumnModel;
|
||
if (model != null && (model.CanCopy || ((this.gcMain.OptionsBehavior.Editable) && (this.gcMain.VisibleColumns[_colNumber].OptionsColumn.AllowEdit))))
|
||
{
|
||
// 返回ID类型特殊处理
|
||
string cellValue = _arrayStr2[j];
|
||
if (!string.IsNullOrEmpty(cellValue)) cellValue = cellValue.Replace("{lskj}", "\n");
|
||
|
||
bool IsTextEqualValue = false;
|
||
object value = model != null && ControlType.IsValue(model.FieldType) ? GetValueByCaption(model, col.ColumnEdit, cellValue, out IsTextEqualValue) : cellValue;
|
||
value = model != null && model.FieldType == 14 ? ReplaceMultiSpace(value) : value;
|
||
DateTime dateValue = new DateTime();
|
||
|
||
// 避免下拉框值替换失败提示错误
|
||
if (model != null && !IsTextEqualValue && ((ControlType.IsValue(model.FieldType) && cellValue == value + "") ||
|
||
(ControlType.LabTextInt == model.FieldType && (value + "").IsChinese()) ||
|
||
(ControlType.IsDate(model.FieldType) && !DateTime.TryParse(value + "", out dateValue))))
|
||
{
|
||
_colNumber += 1;
|
||
continue;
|
||
}
|
||
|
||
if (newRow == null)
|
||
{
|
||
DataRow dataRow = this.GetViewFocusedDataRow();
|
||
dataRow[this.gcMain.FocusedColumn.FieldName] = value;
|
||
}
|
||
else
|
||
{
|
||
if (string.IsNullOrEmpty(value + ""))
|
||
{
|
||
if (string.IsNullOrWhiteSpace(newRow[col.FieldName] + ""))
|
||
{
|
||
if (col.ColumnType.Name.ToLower() == "string")
|
||
newRow[col.FieldName] = "";
|
||
if (col.ColumnType.Name.ToLower().IndexOf("char") >= 0)
|
||
newRow[col.FieldName] = "";
|
||
if (col.ColumnType.Name.ToLower().IndexOf("int") >= 0)
|
||
newRow[col.FieldName] = 0;
|
||
if (col.ColumnType.Name.ToLower() == "decimal")
|
||
newRow[col.FieldName] = 0;
|
||
//if (dc.DataType.Name.ToLower().IndexOf("date") >= 0)
|
||
// tmpRow[dc] = DateTime.Now;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
newRow[col.FieldName] = value;
|
||
}
|
||
|
||
}
|
||
//gridView.SetRowCellValue(_rowNumber, col, value);
|
||
}
|
||
_colNumber += 1;
|
||
}
|
||
_rowNumber += 1;
|
||
if (newRow != null)
|
||
{
|
||
// 其它处理(如绑定左侧树结构数据)
|
||
//if (OnParseGridDataCallBack != null) this.OnParseGridDataCallBack(newRow);
|
||
for (int j = 0; j < this.gcMain.Columns.Count; j++)
|
||
{
|
||
if (this.gcMain.Columns[j].Tag == null) continue;
|
||
if ((this.gcMain.Columns[j].Tag as GridColumnModel).LimitLength > 0)
|
||
{
|
||
int MaxInputLength = System.Text.Encoding.Default.GetBytes(newRow[this.gcMain.Columns[j].FieldName].ToString()).Length;
|
||
if (MaxInputLength > (this.gcMain.Columns[j].Tag as GridColumnModel).LimitLength)
|
||
{
|
||
newRow.SetColumnError(newRow.Table.Columns[this.gcMain.Columns[j].FieldName], "当前输入文本超过设定长度!");//不满足条件设置错误信息
|
||
}
|
||
}
|
||
}
|
||
table.Rows.Add(newRow);
|
||
//this.gridView.FocusedRowHandle = _rowNumber - 1;
|
||
}
|
||
else
|
||
{
|
||
//this.gcMain.UpdateCurrentRow();
|
||
}
|
||
}
|
||
this.gcMain.ShowEditor();
|
||
e.Handled = true;
|
||
//SendKeys.Send("{Esc}");
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 去除多选框中的空格
|
||
/// </summary>
|
||
private object ReplaceMultiSpace(object text)
|
||
{
|
||
if (string.IsNullOrEmpty(text + ""))
|
||
{
|
||
return text;
|
||
}
|
||
string[] keyValues = (text + "").Split(',');
|
||
string returnText = "";
|
||
foreach (string keyValue in keyValues)
|
||
{
|
||
string newKeyValue = keyValue.Trim();
|
||
returnText += string.Format("{0},", newKeyValue);
|
||
}
|
||
returnText = returnText.TrimEnd(',');
|
||
return returnText + ",";
|
||
}
|
||
}
|
||
}
|