using DevExpress.XtraBars;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Layout;
using DevExpress.XtraTab;
using Kdbndp;
using Lskj.Business;
using Lskj.Business.Impl;
using Lskj.Core;
using Lskj.Data;
using Lskj.Model;
using Lskj.Util;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using System.Windows.Forms;
namespace Lskj.Control.Model
{
///
/// 查询控件、添加修改界面控件管理类
///
public class MyControl
{
private string _searchSql;
private DataTable _controls;
private DataTable _schemes;
private System.Windows.Forms.ComboBox _fixField;
private System.Windows.Forms.TextBox _fixKey;
private XtraScrollableControl _parentPanel;
private SimpleButton _button, _fixButton, _refreshButton;
private GridControl _gridControl;
private GridControlEx _mainGridEx;
private GridControlEx _gridLeft;
private TreeViewEx _tvLeft;
private MyControl _leftSearch;
private DropDownButton _dropDown = new DropDownButton();
private PopupMenu _popupMenu = new PopupMenu();
///
/// 计算字段
///
private List _calcControls = new List();
public List _models = new List();
///
/// 缓存本次数据源
///
protected Dictionary mCacheDictionary = new Dictionary();
///
/// 菜单ID
///
public int ModuleId;
///
/// 表格数据行
///
public int GridRowCount;
///
/// 记住上一次选中行
///
public bool RememberRow = true;
///
/// 是否允许控件关联值、计算值
///
public bool CanExecControl = true;
///
/// 左侧树结构、表格主键
///
public string ParentKeyField;
///
/// 主表查询时,左侧树表格是否为精确查询(like改成=)
///
public bool TreeExactQuery = false;
///
/// 左侧树结构、表格主键关联右侧数据字段
///
public string ParentUnionField;
///
/// 树结构隐藏值
///
public string ParentKey;
///
/// 树结构显示值
///
public string ParentValue;
///
/// 主键值
///
public string PrimaryValue;
///
/// 特殊查询条件
///
public string WhereCond;
///
/// 需要关联的刷新控件名称
///
public string RefreshControl;
protected bool mLoading = false;
protected Timer mTimer = new Timer();
///
/// 查询按钮
///
/// The button object.
public SimpleButton ButtonObj { get { return _button; } }
///
/// 条件数据源刷新按钮
///
/// The button object.
public SimpleButton RefreshButtonObj { get { return _refreshButton; } }
///
/// 是否为特殊搜索框
///
public bool isRevTextEdit = false;
///
/// 查询主表公共模块
///
/// The button object.
public GridControlEx MainGridEx { get { return _mainGridEx; } }
///
/// 条件参数
///
public string[] OtherParams;
public DataRow CurrentData;
public ModuleModel SystemModel;
///
/// 下拉框、搜索框控件对象
///
public List mControlList = new List();
private readonly List mExtendedReturnSearchControls =
new List();
private readonly List> mExtendedReturnPendingChanges =
new List>();
private readonly ExtendedReturnModuleSourceResolver mExtendedReturnModuleSourceResolver =
new ExtendedReturnModuleSourceResolver();
private int mExtendedReturnBatchDepth;
///
/// 数据源任务对象
///
public Dictionary> mControlSourceDic = new Dictionary>();
///
/// 获取控件model数据
///
/// The control models.
public List ControlModels { get { return this._models; } }
///
/// 明细里复选框选中的数据(主表和明细都是复选模式才记录) <页签名, <主表选中行,明细选中行主键(,拼接)>>
/// 如果主表刷新后还要选中之前的明细,就要存主表主键值(目前没用传进来)
///
public Dictionary> DetailSelection = new Dictionary>();
///
/// 是否为审核界面主表
///
public bool isAuditMain = false;
///
///单据特殊模块id(单据来源控件)
///
public string BillSourceControlId = string.Empty;
///
/// 保存验证条件表
///
public DataTable SaveCondTab = new DataTable();
///
/// 执行查询之前验证
///
public event PreSearchVerification preSearchVerification;
///
/// 执行查询之前
///
public event SearchEventHandler OnSearchBeforeCallBack;
///
/// 执行查询之后
///
public event EventHandler OnSearchAfterCallBack;
///
/// 执行新增控件框之后
///
public event EventHandler OnAddCallBack;
///
///改变的智能搜索框
///
private Dictionary changeLabelAutoGridLooks = new Dictionary();
///
/// 主表点击搜索按钮,查询内容为0行时,清空明细
///
public event EventHandler ClearDetails;
///
/// 执行最后次查询后触发
///
public event EventHandler OnLastQueryTriggered;
///
/// 说明:键盘按下时触发
/// 创建人:龚宇超
/// 创建日期:2017-12-21
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
public event KeyEventHandler OnSourceRefrshCallBack;
///
/// 数据源绑定完成触发
///
public event EventHandler OnDataSourceBindCallBack;
///
/// mrp固定传输接口
///
public DynamicModel mrpDyncModel;
//public event RefreshThePage refreshThePage;
//public delegate void RefreshThePage(string text);
///
/// mrp按钮对象
///
public Dictionary mrpBtnDic = new Dictionary();
///
/// 重新设置控件值时是否刷新下拉框数据源
///
public bool refGridLookUpData;
///
/// 条件搜索按钮
///
public SimpleButton btnCondSearch;
///
/// 默认传递参数
///
public DynamicModel Model;
///
/// 弹出框默认传递参数
///
public DynamicModel popUpDyncModel;
///
/// 弹出框右键
///
public BarItemLinkCollection rightItemLinks;
///
/// 模块选择框 选中后返回关联的字典
///
public Dictionary ModuleResultDic = new Dictionary();
///
/// 带参数控件修改数据源字典
///
public Dictionary> ParaContrlsDic = new Dictionary>();
///
/// 控件值改变动态刷新表格列
///
public event KeyEventHandler OnDataFileRefrshCallBack;
///
/// 打开来源模块
///
public event EventHandler OpenDocumentSource;
///
///特殊左侧表
///
public GridControlEx SpecialLeftTable;
///
/// 控件Panel对象
///
public XtraScrollableControl ParentPanel
{
get
{
return this._parentPanel;
}
set
{
this._parentPanel = value;
}
}
///
/// Initializes a new instance of the class.
///
public MyControl()
{
}
///
/// Initializes a new instance of the class.
///
/// 查询条件sql
/// 查询条件
/// The grid control.
/// The tree view.
public MyControl(string searchSql, GridControlEx mainGridEx, TreeViewEx treeView = null, GridControlEx gridLeft = null, MyControl leftSearch = null)
{
this._searchSql = searchSql;
this._mainGridEx = mainGridEx;
if (this._mainGridEx != null) this._gridControl = _mainGridEx.GridControl;
this._tvLeft = treeView;
this._gridLeft = gridLeft;
this._leftSearch = leftSearch;
}
///
/// 说明:设置GridControlEx
/// 创建人:龚宇超
/// 创建日期:2019-05-21
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The main grid ex.
public void SetGridControlEx(GridControlEx mainGridEx)
{
this._mainGridEx = mainGridEx;
if (this._mainGridEx != null) this._gridControl = _mainGridEx.GridControl;
}
///
/// 说明:设置GridLeft
/// 创建人:龚宇超
/// 创建日期:2019-05-21
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The main grid ex.
public void SetGridLeft(GridControlEx gridLeft)
{
this._gridLeft = gridLeft;
}
///
/// 说明:创建添加修改界面控件
/// 创建人:龚宇超
/// 创建日期:2017-09-01
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The table.
/// The parent.
public int InitControl(DataTable controls, XtraScrollableControl parent, bool isSweepCode = true)
{
return this.InitControl(controls, parent, null, isSweepCode);
}
///
/// 说明:创建分页控件
/// 创建人:王一帆
/// 创建日期:2021-04-23
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The table.
/// The parent.
public int InitPageControl(DataTable controls, DataTable groups, int PageCount)
{
List startLocktion = new List();
List OverLocktion = new List();
Dictionary pageKey = new Dictionary();
int width = 0, height = 0, x = 0, y = 0;
XtraTabControl tabpage = new XtraTabControl();
tabpage.Dock = DockStyle.Fill;
tabpage.Parent = _parentPanel;
this._parentPanel.Controls.Add(tabpage);
for (int i = 1; i <= PageCount; i++)
{
DataTable SelectGroups = groups.Select("PageOrder=" + i).CopyToDataTable();
DataRow rtGroup = SelectGroups.Rows[SelectGroups.Rows.Count - 1];
if (SelectGroups == null) continue;
XtraTabPage page = new XtraTabPage();
page.Text = rtGroup["pageName"] + "";
startLocktion.Add(Convert.ToInt32(SelectGroups.Rows[0]["controlTop"]));
OverLocktion.Add(Convert.ToInt32(rtGroup["controlTop"]) + Convert.ToInt32(rtGroup["controlHeight"]));
pageKey.Add(i, page);
foreach (DataRow groupdr in SelectGroups.Rows)
{
GroupBox group = new GroupBox();
group.Text = groupdr["groupName"] + "";
group.Width = Convert.ToInt32(groupdr["controlWidth"]);
group.Left = Convert.ToInt32(groupdr["controlLeft"]);
group.Top = i > 1 ? Convert.ToInt32(groupdr["controlTop"]) - OverLocktion[i - 2] : Convert.ToInt32(groupdr["controlTop"]);
group.Height = Convert.ToInt32(groupdr["controlHeight"]);
page.Controls.Add(group);
}
//if (xtr != null)
//{
// if (i == 1)
// {
// xtr.TabPages[0].Text = page.Text;
// }
// else
// {
// dummyPage.Text = page.Text;
// xtr.TabPages.Add(dummyPage);
// dummyPage.Tag = i;
// }
//}
tabpage.TabPages.Add(page);
}
foreach (DataRow item in controls.Rows)
{
ControlModel model = GetControlModel(item);
model.IsSearchControl = false;
System.Windows.Forms.Control control = InitControl(model);
if (control != null)
{
BaseUserControl baseControl = control as BaseUserControl;
baseControl.Location = model.Location;
System.Threading.SynchronizationContext.Current.Post(SetProperty, null);
void SetProperty(object state)
{
//放到外面避免线程问题
baseControl.Model = model;
baseControl.FontSize = model.FontSize;
baseControl.Name = "txt_" + model.FieldName;
baseControl.LabelText = model.LabelText;
baseControl.NullText = model.NullText;
//baseControl.EditText = model.DefaultValue;
//baseControl.Location = model.Location;
baseControl.Size = model.Size;
if (!model.ReadOnly && !string.IsNullOrWhiteSpace(model.ControlTitleColor))
{
baseControl.ModifyDefaultColors(ColorTranslator.FromHtml(model.ControlTitleColor));
}
baseControl.ReadOnly = model.ReadOnly;
baseControl.Required = model.IsEmpty;
baseControl.Tag = model;
baseControl.TabIndex = model.TabOrder;
}
for (int i = 0; i < startLocktion.Count; i++)
{
if (startLocktion[i] < control.Top && control.Top < OverLocktion[i])
{
if (i > 0) control.Top -= OverLocktion[i - 1];
XtraTabPage page = pageKey[i + 1];
control.Parent = page;
int hgt = control.Top + control.Height;
if (hgt > height) height = hgt;
if (y == 0 || model.Location.Y < y) y = model.Location.Y;
if (model.Location.X >= x && model.Location.Y == y)
{
x = model.Location.X;
width = model.Location.X + model.Size.Width;
}
// 树结构类型直接隐藏,不根据配置显示.
if (model.FieldType == ControlType.LabTreeType)
control.Visible = false;
control.BringToFront();
}
}
}
this._models.Add(model);
}
this._parentPanel.Tag = tabpage;
return height;
}
///
/// 说明:构造控件
/// 创建人:龚宇超
/// 创建日期:2018-03-20
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The controls.
/// The parent.
/// The groups.
public int InitControl(DataTable controls, XtraScrollableControl parent, DataTable groups, bool isSweepCode = true)
{
if (controls == null) return 0;
this._parentPanel = parent;
this._controls = controls;
parent.SuspendLayout();
bool isExecute = true;
int width = 0, height = 0, x = 0, y = 0;
Console.WriteLine("构造控件:" + DateTime.Now);
if (groups != null && groups.Rows.Count > 0 && groups.Columns.Contains("pageOrder"))
{
string maxOrder = groups.Compute("max(pageOrder)", "") + "";
if (!string.IsNullOrEmpty(maxOrder))
{
isExecute = false;
height = InitPageControl(controls, groups, Convert.ToInt32(maxOrder));
}
}
if (isExecute)
{
Dictionary