/****************************** * 说明:顶部为表格、底部为多标签内容模版(适用于基础档案上下模版、报表上下模版、单据审批模版) * 创建人:龚宇超 * 创建日期:2017-11-21 * 修改人: * 修改日期: * 修改备注: * 版本: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 DevExpress.XtraTab; using Lskj.Model; using Lskj.Data; using Lskj.Control.Model; using DevExpress.XtraEditors; using Lskj.Business.Impl; using Lskj.Util; using DevExpress.XtraGrid.Views.Grid; using Lskj.Business; using Lskj.Core; using System.Diagnostics; using System.Text.RegularExpressions; using System.Collections; using System.Threading.Tasks; namespace Lskj.Control { /// /// 顶部为表格、底部为多标签内容模版 /// public partial class ReplacementDetailEx : UserControl { /// /// 系统模块实体对象 /// /// The system model. public ModuleModel SysModel { get; private set; } /// /// 调用动态链接库默认传递参数对象 /// public DynamicModel Model { get; private set; } /// /// Gets or sets a value indicating whether [visible detail panel]. /// /// true if [visible detail panel]; otherwise, false. public bool VisibleDetailPanel { get { return this.scc_container.PanelVisibility == SplitPanelVisibility.Both; } set { this.scc_container.PanelVisibility = value ? SplitPanelVisibility.Both : SplitPanelVisibility.Panel1; } } /// /// 是否为拖拽明细模式 /// public bool IsDragDetail; /// /// 底部多标签表格数据 /// public List GridDetailList; /// /// 左边查询条件 /// public MyControl _leftGridSearchObj; /// /// 查询条件 /// /// The search object. public MyControl SearchObj { get { return this.mg_control.SearchObj; } } /// /// 顶部表格控件 /// public ModuleGridEx ModuleGridObj { get { return this.mg_control; } } /// /// 底部多标签控件 /// public XtraTabControl TabObj { get { return this.tcButtom.TabControlObj; } } /// /// 底部容器 /// /// The container object. public PanelControl BottomPanel { get { return this.pl_bottom; } } /// /// 是否只刷新当前选中明细 /// /// The container object. public bool RefreshDetail = false; public ReplacementDetailEx() { InitializeComponent(); } /// /// 说明:初始化控件 /// 创建人:龚宇超 /// 创建日期:2017-11-21 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The menu row. public void InitializeControl(ModuleModel sysModel, DynamicModel dyncModel) { try { if (sysModel != null && dyncModel != null) { this.SysModel = sysModel;//系统模块实体对象 this.Model = dyncModel;//调用动态链接库默认传递参数对象 Console.WriteLine(DateTime.Now); if (SysModel.isLeftRightMode) this.scc_container.Horizontal = true; // 初始化顶部GridView this.ModuleGridObj._leftGridSearchObj = _leftGridSearchObj;// 顶部表格控件 this.ModuleGridObj.TabObj = TabObj;// 底部多标签控件 this.ModuleGridObj.InitializeControl(sysModel, dyncModel); RefreshDetail = this.SysModel.RefreshDetail == "0"; Console.WriteLine(DateTime.Now); // 初始化底部多标签 this.InitializePages(); Console.WriteLine(DateTime.Now); TabControlEx newtcButtom = tcButtom; ModuleGridEx newModuleGridEx = mg_control; this.scc_container.Panel1.Controls.Clear(); this.scc_container.Panel2.Controls.Clear(); this.scc_container.Panel1.Controls.Add(newtcButtom); this.scc_container.Panel2.Controls.Add(newModuleGridEx); } else { MessageUtil.Show(ResourceKeys.MenuCodeIsNotNull); } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message,ex.Message); } } /// /// 获取数据源缓存 /// /// /// /// public void GetDataCaches(Dictionary cachesDic) { //获取通用数据 Task sysModelTask = cachesDic.GetTask(this, "SysModel"); Task dynamicModelTask = cachesDic.GetTask(this, "DynamicModel"); Task> detailsTask = cachesDic.GetTask>(this, "Details"); cachesDic.AddTask(ModuleGridObj, "DynamicModel", dynamicModelTask); cachesDic.AddTask(ModuleGridObj, "SysModel", sysModelTask); cachesDic.AddTask(ModuleGridObj, "Details", detailsTask); cachesDic.AddTask(tcButtom, "DynamicModel", dynamicModelTask); cachesDic.AddTask(tcButtom, "Details", detailsTask); //初始化顶部表格 ModuleGridObj.GetDataCaches(cachesDic); // 初始化底部多标签 tcButtom.GetDataCaches(cachesDic); } /// /// 说明:初始化底部多标签数据 /// 创建人:龚宇超 /// 创建日期:2017-11-21 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// protected void InitializePages() { if (this.GridDetailList == null || this.GridDetailList.Count == 0) { this.scc_container.PanelVisibility = SplitPanelVisibility.Panel1; } else { this.InitlizeSpiltLocation(); this.InitilizeGridViewEvent(); this.tcButtom.Model = this.Model; this.tcButtom.DrgaParentPrimaryKey = this.SysModel.ParmaryKey; this.tcButtom.IsDragDetail = false; this.tcButtom.ParentGridEx = this.ModuleGridObj.GridControlObj; this.tcButtom.InitTabPages(this.GridDetailList); this.tcButtom.OnRightCallback += new EventHandler(OnGridViewRightCallBack); } } /// /// 说明:设置分割条位置 /// 创建人:龚宇超 /// 创建日期:2018-02-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// protected void InitlizeSpiltLocation() { try { string htight = IniHelper.Read(string.Format("base_height_{0}", this.Model.ModuleCode)); if (!string.IsNullOrEmpty(htight)) { this.scc_container.SplitterPosition = Convert.ToInt32(htight); } } catch (Exception ex) { LogHelper.Instance.WriteError(ex); string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message,ex.Message); } } /// /// 说明:绑定事件 /// 创建人:龚宇超 /// 创建日期:2017-11-22 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// protected void InitilizeGridViewEvent() { if (this.IsDragDetail) { // 拖拽模式 } else { // 非拖拽模式 if (Model.IsBaseModule) { if (this.ModuleGridObj.GridControlObj is TreeGridControlEx) { (this.ModuleGridObj.GridControlObj as TreeGridControlEx).TreeListObj.FocusedNodeChanged += OnFocusedNodeChanged; } this.ModuleGridObj.GridControlObj.GridView.FocusedRowObjectChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventHandler(OnGridViewFocusedRowObjectChanged); this.ModuleGridObj.GridControlObj.GridView.RowCellClick += new RowCellClickEventHandler(GridView_RowCellClick); //this.ModuleGridObj.GridControlObj.GridView.FocusedRowChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventHandler(OnGridViewFocusedRowChanged); } else { if (this.ModuleGridObj.GridControlObj is TreeGridControlEx) { (this.ModuleGridObj.GridControlObj as TreeGridControlEx).TreeListObj.FocusedNodeChanged += OnFocusedNodeChanged; } this.ModuleGridObj.GridControlObj.GridView.DoubleClick += new EventHandler(OnGridViewDoubleClick); } } } /// /// 说明:获取底部多标签数据 /// 创建人:龚宇超 /// 创建日期:2017-12-19 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// public void SetDetailGridDataSource(XtraTabPage tabPage = null) { if (tabPage != null) { this.SetTabPageDataSource(tabPage); } else { DataRow rowItem = this.ModuleGridObj.GridControlObj.GetViewFocusedDataRow(); if (RefreshDetail) { XtraTabPage RefreshPage = this.TabObj.SelectedTabPage; if (rowItem != null && RefreshPage != null) { this.SetTabPageDataSource(RefreshPage); } else { SetTabPageDataSource(RefreshPage, true); } } else { foreach (XtraTabPage page in this.TabObj.TabPages) { if (rowItem != null && page != null) { this.SetTabPageDataSource(page); } else { SetTabPageDataSource(page, true); } } } } } /// /// 说明:拖拽模式获取底部多标签数据 /// 创建人:龚宇超 /// 创建日期:2017-12-19 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// public void SetDetailGridDataSource(string where, bool isTree, TreeViewEx treeViewEx, GridControlEx gridControlEx) { foreach (XtraTabPage tabPage in this.TabObj.TabPages) { GridDetailModel model = this.tcButtom.GetGridDetailModel(tabPage); string sqlValue = model.IsReadOnly || model.IsChart ? model.DetailSql : model.SystemModel.MenuSql; if (isTree) { // 左侧为树,查询数据则追加条件 if (tabPage.Tag is GridControlEx) { sqlValue = ReplaceHelper.IsProcedure(sqlValue) ? ReplaceHelper.ReplaceTreeViewParentKeyCond(sqlValue, treeViewEx.GetSelectNodeValue()) : sqlValue + where; (tabPage.Tag as GridControlEx).LastSearchSql = sqlValue; } this.tcButtom.SetGridDataSource(tabPage, MainImpl.GetDataTableResult(sqlValue)); } else { // 左侧为表格,查询数据则替换选中行数据 DataRow rowItem = gridControlEx.GridView.GetFocusedDataRow(); string searchSql = this.GetSearchSql(model, rowItem); if (tabPage.Tag is GridControlEx) { (tabPage.Tag as GridControlEx).LastSearchSql = searchSql; } this.tcButtom.SetGridDataSource(tabPage, MainImpl.GetDataTableResult(searchSql)); } } } /// /// 说明:设置表格数据 /// 创建人:龚宇超 /// 创建日期:2018-01-29 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The tab page. /// The grid control. protected void SetTabPageDataSource(XtraTabPage tabPage, bool isNull = false) { if (isNull) { this.tcButtom.SetGridDataSource(tabPage, new DataTable()); return; } GridDetailModel model = this.tcButtom.GetGridDetailModel(tabPage); DataRow rowItem = this.ModuleGridObj.GridControlObj.GetViewFocusedDataRow(); if (rowItem != null && model != null) { if (tabPage.Tag is ModuleWebView) { // 加载网页 string url = model.DetailSql.StartsWith("http") ? model.DetailSql : SystemInfo.Instance.OAUrl + model.DetailSql; ModuleWebView webView = tabPage.Tag as ModuleWebView; webView.Dock = DockStyle.Fill; webView.Tag = model; webView.Navigate(ReplaceHelper.ReplaceRowParam(rowItem, ReplaceHelper.ReplaceUserInfo(url))); } else { string searchSql = this.GetSearchSql(model, rowItem); if (tabPage.Tag is GridControlEx) { (tabPage.Tag as GridControlEx).LastSearchSql = searchSql; } this.tcButtom.SetGridDataSource(tabPage, MainImpl.GetDataTableResult(searchSql)); //配置明细直接根据条件加载 if (model.SystemModel != null && 1 == model.SystemModel.isFirstLoad) { (tabPage.Tag as GridControlEx).ParentControl.SearchGrid(); tabPage.Text = model.DetailName + "(" + (tabPage.Tag as GridControlEx).ParentControl.GridRowCount + "条)"; } else { if (tabPage.Tag is GridControlEx && (tabPage.Tag as GridControlEx).ParentControl != null) (tabPage.Tag as GridControlEx).ParentControl.SetAllControlValue(rowItem); } } } else if (rowItem != null && tabPage.Tag is TabMultipledetails) { TabMultipledetails tabMultipledetails = tabPage.Tag as TabMultipledetails; GridControlEx grdExMain = (tabMultipledetails.SplitMain.Panel1.Tag as GridControlEx); GridControlEx grdExAdditional = (tabMultipledetails.SplitMain.Panel2.Tag as GridControlEx); GridDetailModel MainModel = grdExMain.Tag as GridDetailModel; GridDetailModel AdditionalModel = grdExAdditional.Tag as GridDetailModel; string searchMainSql = this.GetSearchSql(MainModel, rowItem); string searchAddSql = this.GetSearchSql(AdditionalModel, rowItem); DataTable firstTable = MainImpl.GetDataTableResult(searchMainSql); grdExMain.LastSearchSql = searchMainSql; grdExAdditional.LastSearchSql = searchAddSql; grdExMain.SetGridViewDataSource(firstTable); tabPage.Text = MainModel.DetailName + "(" + firstTable.Rows.Count + "条)"; grdExAdditional.SetGridViewDataSource(MainImpl.GetDataTableResult(searchAddSql)); } } /// /// 说明:获取查询条件 /// 创建人:龚宇超 /// 创建日期:2017-11-22 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The model. /// The row item. /// System.String. protected string GetSearchSql(GridDetailModel model, DataRow rowItem) { string fieldName = !string.IsNullOrEmpty(model.UnionParentField) && rowItem.Table.Columns.Contains(model.UnionParentField) ? model.UnionParentField : ModuleGridObj.ParmaryKey; string sqlValue = model.IsReadOnly || model.IsChart ? model.DetailSql : model.SystemModel.MenuSql; sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, sqlValue); if (ReplaceHelper.IsSelect(sqlValue) && !string.IsNullOrEmpty(model.UnionValue)) { sqlValue = ReplaceHelper.ReplaceWhereCond(sqlValue) + string.Format(" and {0}='{1}'", model.UnionValue, rowItem[fieldName] + ""); } return sqlValue; } /// /// 说明:右键菜单执行后刷新数据,刷新规则按照上一次查询条件刷新 /// 创建人:龚宇超 /// 创建日期:2017-11-02 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. protected void OnGridViewRightCallBack(object sender, EventArgs e) { try { this.SetDetailGridDataSource(this.TabObj.SelectedTabPage); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message,ex.Message); } } /// /// 说明:双击加载明细 /// 创建人:龚宇超 /// 创建日期:2017-11-22 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnGridViewDoubleClick(object sender, EventArgs e) { try { WaitForm.ShowForm(); this.SetDetailGridDataSource(); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message,ex.Message); LogHelper.Instance.WriteError(ex); } finally { WaitForm.HideForm(); } } /// /// 说明:双击加载树表格明细 /// 创建人:王一帆 /// 创建日期:2020-02-12 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void OnFocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e) { try { WaitForm.ShowForm(); this.SetDetailGridDataSource(); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message,ex.Message); LogHelper.Instance.WriteError(ex); } finally { WaitForm.HideForm(); } } /// /// 说明:加载明细数据 /// 创建人:龚宇超 /// 创建日期:2018-09-28 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void GridView_RowCellClick(object sender, RowCellClickEventArgs e) { try { WaitForm.ShowForm(); this.SetDetailGridDataSource(); } catch (Exception ex) { LogHelper.Instance.WriteError(ex); string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message,ex.Message); } finally { WaitForm.HideForm(); } } /// /// 说明:数据行发生改变加载明细 /// 创建人:龚宇超 /// 创建日期: /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. protected void OnGridViewFocusedRowObjectChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventArgs e) { try { WaitForm.ShowForm(); this.SetDetailGridDataSource(); } catch (Exception ex) { LogHelper.Instance.WriteError(ex); string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message,ex.Message); } finally { WaitForm.HideForm(); } } /// /// 说明:加载明细数据 /// 创建人:龚宇超 /// 创建日期:2017-11-22 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnGridViewFocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) { try { WaitForm.ShowForm(); this.SetDetailGridDataSource(); } catch (Exception ex) { LogHelper.Instance.WriteError(ex); string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message,ex.Message); } finally { WaitForm.HideForm(); } } /// /// 说明:设置分割条位置 /// 创建人:龚宇超 /// 创建日期:2018-02-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnSplitterMoved(object sender, EventArgs e) { try { if (this.Model != null) { IniHelper.Write(string.Format("base_height_{0}", this.Model.ModuleCode), this.scc_container.SplitterPosition + ""); } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message,ex.Message); } } } }