/******************************
* 说明:带左侧树、表格操作右侧表格的自定义控件
* 创建人:龚宇超
* 创建日期:2017-09-01
* 修改人:
* 修改日期:
* 修改备注:
* 版本: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.Business.Impl;
using Lskj.Util;
using Lskj.Model;
using Lskj.Control.Model;
using Lskj.Data;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using System.IO;
using DevExpress.XtraGrid;
using DevExpress.XtraBars;
using DevExpress.XtraTab;
using DevExpress.XtraGrid.Columns;
using FastReport;
using DevExpress.XtraGrid.Views.BandedGrid;
using System.Diagnostics;
using Lskj.Core;
using Lskj.Business;
using DevExpress.XtraTreeList.Nodes;
using DevExpress.XtraTreeList;
using System.Collections;
using System.Threading.Tasks;
using DevExpress.XtraRichEdit;
using System.Data.SqlClient;
namespace Lskj.Control
{
///
/// 带左侧树、表格操作右侧表格的自定义控件
///
public partial class ModuleEx : UserControl
{
///
/// 当前富文本框是否改变
///
private bool _richTextDirty;
///
/// BMP字段
///
private string _labPicName;
///
/// 当前行
///
private DataRow _currentRow;
///
/// 左侧表格查询条件
///
private MyControl _leftGridSearchObj;
private GridDragTree _gridDragTree;
private bool mModuleResourcesReleased;
private GridDragGrid _gridDragGrid;
private BandedGridDragGrid _bandedGridDragGrid;
public bool IsExcel { get { return Model is DynamicExcelModel; } }
///
/// 是否为拖拽明细模式
///
public bool IsDragDetail;
///
/// 左侧条件
///
public string LeftCond;
///
/// 左侧树数据
///
public DataRow LeftRowObj;
///
/// 系统模块实体对象
///
/// The system model.
public ModuleModel SysModel { get; private set; }
///
/// 调用动态链接库默认传递参数对象
///
public DynamicModel Model { get; private set; }
///
/// 底部表格数据
///
public List Details;
///
/// 查询条件
///
/// The search object.
public MyControl SearchObj { get { return this.moduleGridDetailEx1.SearchObj; } }
///
/// 常用操作对象,用于加载时暂时获取焦点
///
/// The title label object.
public DevExpress.XtraEditors.DropDownButton ddbOperObj { get { return ModuleGridObj.ddbOperObj; } }
///
/// 带操作表格的自定义控件对象
///
public ModuleGridEx ModuleGridObj { get { return this.MainBodyTab.Visible ? (this.MainBodyTab.SelectedTabPage.Tag as ModuleGridDetailEx).ModuleGridObj : this.moduleGridDetailEx1.ModuleGridObj; } }
///
/// Gets the module grid detail object.
///
/// The module grid detail object.
public ModuleGridDetailEx ModuleGridDetailObj { get { return this.MainBodyTab.Visible ? this.MainBodyTab.SelectedTabPage.Tag as ModuleGridDetailEx : this.moduleGridDetailEx1; } }
///
/// 左侧树结构对象
///
/// The TreeView object.
public TreeViewEx LeftTreeViewObj { get { return this.treeLeft; } }
///
/// 左侧表格对象
///
/// The left grid view object.
public GridControlEx LeftGridViewObj { get { return this.gridLeft; } }
///
/// Excel控件
///
public ExcelControlEx ExcelControlObj;
///
/// 左侧表格行点击事件回调
///
public event EventHandler OnLeftGridViewRowClickCallBack;
///
/// 左侧树结构选中节后点回调
///
public event EventHandler OnLeftTreeViewRowClickCallBack;
///
/// 禁止刷新主表(树表格节点展开时禁止刷新主表)
///
public bool RefreshDisable = false;
///
/// 上一次选中的树表格节点
///
public TreeListNode treeListNode;
///
/// 动态列名表
///
public DataTable ColumnNameTable;
public ModuleEx()
{
InitializeComponent();
this.Disposed += OnModuleExDisposed;
}
public void ReleaseResourcesForDispose()
{
if (mModuleResourcesReleased)
{
return;
}
mModuleResourcesReleased = true;
HashSet details =
new HashSet();
HashSet grids = new HashSet();
foreach (System.Windows.Forms.Control control in
EnumerateModuleControls(this))
{
ModuleGridDetailEx detail = control as ModuleGridDetailEx;
if (detail != null)
{
details.Add(detail);
}
ModuleGridEx grid = control as ModuleGridEx;
if (grid != null)
{
grids.Add(grid);
}
}
foreach (ModuleGridDetailEx detail in details)
{
detail.ReleaseResourcesForDispose();
}
foreach (ModuleGridEx grid in grids)
{
grid.SaveEvent -= SetDetailGridView;
grid.OnExportCallBack -= SetExportGridView;
grid.ReleaseResourcesForDispose();
}
MyControl leftSearch = _leftGridSearchObj;
_leftGridSearchObj = null;
if (leftSearch != null)
{
leftSearch.OnDataSourceBindCallBack -= OnLeftControlObjDataSourceBindCallBack;
leftSearch.Dispose();
}
GridDragTree dragTree = _gridDragTree;
_gridDragTree = null;
if (dragTree != null)
{
dragTree.OnDragComplete -= OnDragTreeCompleted;
dragTree.Dispose();
}
GridDragGrid dragGrid = _gridDragGrid;
_gridDragGrid = null;
if (dragGrid != null)
{
dragGrid.OnDragComplete -= OnDragGridCompleted;
dragGrid.Dispose();
}
BandedGridDragGrid bandedDragGrid = _bandedGridDragGrid;
_bandedGridDragGrid = null;
if (bandedDragGrid != null)
{
bandedDragGrid.OnDragComplete -= OnDragBandedGridCompleted;
bandedDragGrid.Dispose();
}
try
{
if (treeLeft != null)
{
treeLeft.TreeNodeSelectAfter -= OnTreeLeftTreeNodeSelected;
treeLeft.OnTreeNodeMouseDoubleClick -= TreeLeft_OnTreeNodeMouseDoubleClick;
}
if (gridLeft != null && gridLeft.GridView != null)
{
gridLeft.GridView.RowClick -= OnGridViewRowClick;
}
if (treeGridLeft != null && treeGridLeft.TreeListObj != null)
{
treeGridLeft.TreeListObj.Click -= TreeListObj_Click;
treeGridLeft.TreeListObj.BeforeExpand -= TreeListObj_BeforeExpand;
treeGridLeft.TreeListObj.BeforeCollapse -= TreeListObj_BeforeCollapse;
}
if (MainBodyTab != null)
{
MainBodyTab.SelectedPageChanged -= MainBodyTab_SelectedPageChanged;
}
if (excelControlEx1 != null)
{
excelControlEx1.SaveCallBack -= OnExcelSaveClick;
}
}
catch
{
// A partially disposed child control must not stop cleanup.
}
try
{
if (Model != null && Model.DataCaches != null)
{
Model.DataCaches.Remove(this);
}
}
catch
{
// Cache cleanup must not interrupt module disposal.
}
OnLeftGridViewRowClickCallBack = null;
OnLeftTreeViewRowClickCallBack = null;
if (Details != null)
{
Details.Clear();
}
LeftRowObj = null;
ColumnNameTable = null;
_currentRow = null;
ExcelControlObj = null;
Model = null;
SysModel = null;
}
private static IEnumerable
EnumerateModuleControls(System.Windows.Forms.Control parent)
{
if (parent == null)
{
yield break;
}
foreach (System.Windows.Forms.Control child in parent.Controls)
{
yield return child;
foreach (System.Windows.Forms.Control nested in
EnumerateModuleControls(child))
{
yield return nested;
}
}
}
///
/// Excel 控件包含 SpreadsheetControl、BarManager 和命令注册项,
/// 普通表格模块不应在设计器初始化阶段创建这些重型资源。
///
private ExcelControlEx EnsureExcelControl()
{
if (this.excelControlEx1 != null && !this.excelControlEx1.IsDisposed)
{
return this.excelControlEx1;
}
this.excelControlEx1 = new ExcelControlEx
{
AddEnabled = true,
DeleteEnabled = true,
Dock = DockStyle.Fill,
Margin = new Padding(6),
Name = "excelControlEx1",
PrintEnabled = true,
SaveEnabled = true,
TabIndex = 1,
Visible = false
};
this.pl_right.Controls.Add(this.excelControlEx1);
this.ExcelControlObj = this.excelControlEx1;
return this.excelControlEx1;
}
///
/// 说明:创建界面
/// 创建人:龚宇超
/// 创建日期:2017-09-12
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The menu code.
public void InitControls(DynamicModel model)
{
try
{
if (model != null)
{
this.Model = model;
Dictionary