using DevExpress.Data; using DevExpress.Utils; using DevExpress.XtraBars; using DevExpress.XtraEditors; using DevExpress.XtraGrid.Columns; using DevExpress.XtraGrid.Views.Base; using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraTab; using DevExpress.XtraTreeList.Columns; using DevExpress.XtraTreeList.Nodes; using Lskj.Business; using Lskj.Business.Impl; using Lskj.Control; using Lskj.Control.BrowserSetting; using Lskj.Control.Model; using Lskj.Core; using Lskj.Data; using Lskj.Model; using Lskj.PubBillManagement.Model; using Lskj.Util; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.IO; using System.Linq; using System.Net; using System.Reflection; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; namespace Lskj.PubBillManagement { public partial class BillModule : UserControl { /// /// 是否为初始化创建 /// private bool _isInitFinish; /// /// 是否加载右侧控件数据 /// private bool _isLoadRightControlValue = true; /// /// 是否手动选择了模版 /// private bool _isSelectedTemplete; /// /// 是否直接打印 /// private bool _isExcPrint; /// /// 是否选择关联下发 /// private bool _isCheck; /// /// 主打印Sql /// private string _mainPrintSql; private string guidField = "xxxxx_guid"; /// /// 主键字段 /// private string mRecordPrimaryField; /// /// 单据水印 /// private WaterMark _waterMark; /// /// 导入单据明细数据、导入单据明细并更新 /// private BarButtonItem _itemImport, _itemImportUpdate; /// /// 打印主sql中关联打印次数返回条件 /// private string _printModeCond; /// /// 打印完成后添加数据用到的参数: 表名,列前缀,主键字段,主键值,模块编号,主打印Sql /// private List _printSaveParams; /// /// 单据明细列 /// private DataTable _detailColumns; private bool IsCopying = false; protected DataRow BillRowItem; /// /// 主表控件 /// public MyControl ControlObj; /// /// 入口参数 /// protected DynamicBillModel SysModel; /// /// 是否为Brp模版 /// /// true if this instance is BRP templete; otherwise, false. protected bool IsBrpTemplete { get { return SysModel is DynamicBillBrpModel; } } /// /// /// public BillModel BillModel; /// /// 数量名称 /// public string NumberMc; /// /// 红字单据的分配管理模块 /// public string rdRedUnionCode; /// /// 蓝字单据的分配管理模块 /// public string rdBlueUnionCode; /// /// 蓝字单据的分配管理模块 /// Dictionary pageNumKey = new Dictionary(); /// /// 是否拖拽换行展示 /// public bool isDragWrap = true; /// /// 触发主表改变刷新来源限制 /// private bool IsBillMaster = true; /// /// 是否执行了加载储存过程 /// //public bool ProcessExists = false; /// /// 保存或修改时报错信息 /// public string SaveErrorMessage = string.Empty; /// /// 单据明细删除的行 /// // private Dictionary ToWithdrawRows = new Dictionary(); private List> ToWithdrawRows = new List>(); /// ///改变颜色行 /// private List ChangeColorRow = new List(); /// /// /// public string AssociatedField = string.Empty; /// /// 注册设置公共事件私有类 /// private static PubEvenImpl _eventHandler; /// /// 注册设置公共事件类 /// private static PubEvenImpl eventHandler; /// /// 当前人员是否有导出权限 /// public bool ExportPermission; /// /// 是否显示单据管理条数 /// public bool IsBillShowCount = false; /// /// 来源明细的页面名字后缀(设置成全局变量,更好的处理语言翻译的情况) /// public string DetailedSuffix = Business.Impl.LanguageTranslation.Translatable ? "-" + Business.Impl.LanguageTranslation.GetTranslatedText("明细") : "-明细"; /// /// 数量后缀 /// public string QuantitySuffix = Business.Impl.LanguageTranslation.Translatable ? Business.Impl.LanguageTranslation.GetTranslatedText("条") + ")" : "条)"; /// /// 新增 /// public string addText = Business.Impl.LanguageTranslation.Translatable ? "(" + Business.Impl.LanguageTranslation.GetTranslatedText("新增") + ")" : "(新增)"; /// /// 修改 /// public string updateText = Business.Impl.LanguageTranslation.Translatable ? "(" + Business.Impl.LanguageTranslation.GetTranslatedText("修改") + ")" : "(修改)"; /// /// 单据来源控件集合 /// public Dictionary BillModuleModelDic = new Dictionary(); /// /// 主表动态生成的日期列 /// public List DateColumnList = new List(); /// /// 主表动态生成的合计列 /// public GridColumn SumGridColumn = new GridColumn(); /// /// 附加右键菜单集合 /// public List itemCommonList = new List(); /// /// 是否已经添加了多行汇总 /// public bool MultiLineSummary; /// /// 扫码框 /// public TextEdit ScanCodeTextEdit = null; /// /// 初始化时选中的页签 /// public XtraTabPage InitialSelectionTab = null; /// /// 当前操作的ImageEdit /// private LabelImageEdit _imageEdit; /// /// 当前来源明细中变色行 /// private HashSet ColorHandles = new HashSet(); /// /// 保存验证条件表 /// public DataTable SaveCondTab = new DataTable(); public BillModule() { InitializeComponent(); } #region 初始化操作 /// /// 说明:窗口加载 /// 创建人:龚宇超 /// 创建日期:2017-11-23 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The instance containing the event data. public void OnLoad(DynamicBillModel Model) { try { this.SysModel = Model;// 单据动态链接库参数,入口参数 this._isInitFinish = false;// 是否为初始化创建 this.ssc_main.Visible = false; //获取或设置一个值,该值指示是否显示该控件及其所有子控件。 //this.ProcessExists = (Lskj.Data.Caches.CacheSYSConfig.Instance().JudgeProcessExists() && SystemInfo.Instance.isExecload); Dictionary dataCaches = Model != null ? Model.DataCaches : null; dataCaches.GetValue(this, "DataCaches", out bool _);//等待缓存数据加载完成 this.InitializeSetting();//初始化系统配置 this.InitializeControl();//初始化控件 this.InitlizeSpiltLocation(); } catch (Exception ex) { LogHelper.Instance.WriteError(ex); LogUtil.WriteError("单据初始化窗体失败!", ex); MessageUtil.Show(ex.StackTrace); } finally { this._isInitFinish = true; this.ssc_main.Visible = true; } } /// /// 获取数据源缓存 /// /// public void GetDataCaches(Dictionary cachesDic) { //获取通用数据 Task sysModelTask = cachesDic.GetTask(this, "SysModel"); Task systemDllRowTask = cachesDic.GetTask(this, "SystemDllRow"); Task dynamicModelTask = cachesDic.GetTask(this, "DynamicModel"); Task getDataCachesTask = cachesDic.AddTask(this, "DataCaches", new Task(() => { DynamicBillModel dynamicModel = (DynamicBillModel)dynamicModelTask.Result; #region InitializeSetting初始化系统配置 Task billInfoRowTask = cachesDic.AddTask(this, "BillInfo", new Task(() => { return BillImpl.GetBillInfo(dynamicModel.ModuleCode);//获取单个模块信息 })); Task billModelTask = cachesDic.AddTask(this, "BillModel", new Task(() => { BillModel model = null; if (billInfoRowTask.Result != null) { model = new BillModel(billInfoRowTask.Result); } return model; })); BillModel billModel = billModelTask.Result; if (billModel != null) { Task masterPreFixTask = cachesDic.AddTask(this, "MasterPreFix", new Task(() => { return BaseImpl.GetColumnPrefix(billModel.MasterTable);// 主表列前缀 })); Task detailPreFixTask = cachesDic.AddTask(this, "DetailPreFix", new Task(() => { return BaseImpl.GetColumnPrefix(billModel.DetailTable);// 明细表列前缀 })); } Task menuConfigTabTask = cachesDic.AddTask(this, "MenuConfigTab", new Task(() => { DataRow dataRow = BaseImpl.GetMenuConfigTab(dynamicModel.ModuleId); if (dataRow != null) { billModel.BillSourceIds = dataRow.Table.Columns.Contains("BillSourceIds") ? (dataRow["BillSourceIds"] + "").Trim(',') : string.Empty; billModel.BillFlag = dataRow.Table.Columns.Contains("BillFlag") && !string.IsNullOrEmpty(dataRow["BillFlag"] + "") ? Convert.ToInt32(dataRow["BillFlag"] + "") : -1; //billModel } return dataRow;//获取菜单其他配置 })); #region GetPrintOtherParam获取打印其他参数 if (string.IsNullOrEmpty(billModel.PrintSql) && billModel.PrintSql.Contains("<<")) { string[] strs = billModel.PrintSql.Split(new[] { ">>" }, 2, StringSplitOptions.None); _mainPrintSql = strs[1]; _printModeCond = strs[0].Replace("<<", ""); } if (!string.IsNullOrEmpty(_printModeCond) && _printModeCond.IndexOf(';') > 0) { string[] str = _printModeCond.Split(';'); Task printOtherSystemRowTask = cachesDic.AddTask(this, "PrintOtherSystemRow", new Task(() => { return AttachImpl.GetSystemModule(str[0]); })); Task printOtherColumnPrefixTask = cachesDic.AddTask(this, "PrintOtherColumnPrefix", new Task(() => { string tableName = printOtherSystemRowTask.Result["TableName"] + ""; return BaseImpl.GetColumnPrefix(tableName); })); Task printOtherPrimaryKeyTask = cachesDic.AddTask(this, "PrintOtherPrimaryKey", new Task(() => { string modetype = printOtherSystemRowTask.Result["modType"] + ""; return modetype == "1" ? BaseImpl.GetBasePrimaryKey(str[0]) : printOtherColumnPrefixTask.Result + "billdocument_id"; })); Task printOtherIsExcPrintTask = cachesDic.AddTask(this, "PrintOtherIsExcPrint", new Task(() => { string modetype = printOtherSystemRowTask.Result["modType"] + ""; switch (modetype) { case "1": ModuleModel mode = new ModuleModel(MainImpl.GetSystemdllTab(str[0])); if (mode != null) { return mode.PrintType == 3; } break; case "2": BaseAccraditationModel model = new BaseAccraditationModel(BillAuditImpl.GetPubAuditProperty(str[0])); if (model != null) { return model.BillPrintType == 3; } break; } return false; })); } #endregion Task billSettingTask = cachesDic.AddTask(this, "BillSetting", new Task(() => { BillImpl.InitBillSetting(billModel); return true; })); #endregion if (billModel.PanelWidth > 0) { #region InitializeBillSource初始化单据来源 Task> detailTask = cachesDic.AddTask(this, "Details", new Task>(() => { List details = new List(); DataTable table = BaseAuditImpl.GetAttachTabs(dynamicModel.ModuleCode, "100", " and orderid < 0 "); foreach (DataRow item in table.Rows) { GridDetailModel gridDetailModel = new GridDetailModel(item, null, GridCustomColumnStruct.BillSourceDetailAttachGridView); details.Add(gridDetailModel); Task addGridColumnsTask = cachesDic.AddTask(gridDetailModel, "GridColumns", new Task(() => { DataTable gridColumns = BaseAuditImpl.GetBottomBasicInformation(item["formKey"] + ""); gridDetailModel.GridColumns = gridColumns; return gridColumns; })); } return details; })); Task sourcesTask = cachesDic.AddTask(this, "Sources", new Task(() => { DataRow menuConfigRow = menuConfigTabTask.Result; string SourceIds = (billModel.BillSourceIds + "").Trim(','); if (!string.IsNullOrWhiteSpace(dynamicModel.SourceDetailsID)) { SourceIds = (SourceIds + "," + dynamicModel.SourceDetailsID).Trim(','); } return BillImpl.GetSources(dynamicModel.ModuleCode, SourceIds);//获取单据来源 })); cachesDic.AddTask(tb_buttom, "DynamicModel", dynamicModelTask); cachesDic.AddTask(tb_buttom, "Details", detailTask); tb_buttom.GetDataCaches(cachesDic); Task initSourcesTask = cachesDic.AddTask(this, "InitSourcesTask", new Task(() => { Hashtable htTable = sourcesTask.Result; DataTable masterTable = htTable["master"] as DataTable; DataTable detailTable = htTable["detail"] as DataTable; for (int i = 0; i < masterTable.Rows.Count; i++) { DataRow sourceModelRow = masterTable.Rows[i]; BillModuleModel billModuleModel = new BillModuleModel(); BillSourceModel model = new BillSourceModel(sourceModelRow); billModuleModel.SourceModel = model; Task customQueryFieldsTask = cachesDic.AddTask(model, "CustomQueryFields", new Task(() => { return BaseModuleImpl.GetCustomQueryFields(model.FormKey); })); #region 加载来源表头 GridControlEx gridControl = null; TreeViewEx treeView = null; if (model.SourceType == 1) { // 来源为树类型 treeView = new TreeViewEx(); billModuleModel.SourceControl = treeView; Task bindTreeTableTask = cachesDic.AddTask(treeView, "BindTreeTable", new Task(() => { return BaseImpl.GetDataTableResult(model.SourceSql); })); } else if (model.SourceType == 5) { model.ChangeSourceType(2);//单据来源显示条数 } else if (model.SourceType == 3 || model.SourceType == 4) { gridControl = new TreeGridControlEx(); billModuleModel.SourceControl = gridControl; Task sourceColumnsTask = cachesDic.AddTask(gridControl, "SourceColumns", new Task(() => { return BillImpl.GetSourceColumns(model.Id); })); Task sourceGridRowColorsTask = cachesDic.AddTask(gridControl, "BaseGridRowColors", new Task(() => { return BaseModuleImpl.GetBaseGridRowColors("BILLSOURCE_" + model.FormKey); })); Task sourceGridRightMenusTask = cachesDic.AddTask(gridControl, "BaseGridRightMenus", new Task(() => { return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCE_" + model.FormKey); })); } else { // 来源为表格类型 gridControl = new GridControlEx(); billModuleModel.SourceControl = gridControl; Task sourceColumnsTask = cachesDic.AddTask(gridControl, "SourceColumns", new Task(() => { return BillImpl.GetSourceColumns(model.Id); })); //创建表格列 cachesDic.AddTask(gridControl, "DynamicModel", dynamicModelTask); gridControl.GetDataCaches(cachesDic, GridCustomColumnStruct.BillSourceGridView + model.FormKey); Task sourceGridRowColorsTask = cachesDic.AddTask(gridControl, "BaseGridRowColors", new Task(() => { return BaseModuleImpl.GetBaseGridRowColors("BILLSOURCE_" + model.FormKey); })); Task sourceGridRightMenusTask = cachesDic.AddTask(gridControl, "BaseGridRightMenus", new Task(() => { return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCE_" + model.FormKey); })); } #endregion #region 加载来源明细 GridControlEx gridDetail = new GridControlEx(); if (model.sourceDetailType.Equals("1")) { //明细为树表格 gridDetail = new TreeGridControlEx(); billModuleModel.SourceDetailControl = gridDetail; //创建表格列 cachesDic.AddTask(gridDetail, "DynamicModel", dynamicModelTask); gridDetail.GetDataCaches(cachesDic, GridCustomColumnStruct.BillSourceDetailGridView + model.FormKey); Task detailGridRowColorsTask = cachesDic.AddTask(gridDetail, "BaseGridRowColors", new Task(() => { return BaseModuleImpl.GetBaseGridRowColors("SOURCEDETAIL_" + model.FormKey); })); Task detailGridRightMenusTask = cachesDic.AddTask(gridDetail, "BaseGridRightMenus", new Task(() => { return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDT_" + model.FormKey); })); } else { gridDetail = new GridControlEx(); billModuleModel.SourceDetailControl = gridDetail; //创建表格列 cachesDic.AddTask(gridDetail, "DynamicModel", dynamicModelTask); gridDetail.GetDataCaches(cachesDic, GridCustomColumnStruct.BillSourceDetailGridView + model.FormKey); Task detailGridRowColorsTask = cachesDic.AddTask(gridDetail, "BaseGridRowColors", new Task(() => { return BaseModuleImpl.GetBaseGridRowColors("SOURCEDETAIL_" + model.FormKey); })); Task detailGridRightMenusTask = cachesDic.AddTask(gridDetail, "BaseGridRightMenus", new Task(() => { return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDT_" + model.FormKey); })); //明细的明细(明细分成左右2个) if (!string.IsNullOrEmpty(model.SourceDetailsDetailsSql)) { GridControlEx gridDetail_Details = new GridControlEx(); billModuleModel.SourceDetailDetailControl = gridDetail_Details; //创建只读列 Task detailDetailsTask = cachesDic.AddTask(gridDetail_Details, "DetailDetails", new Task(() => { return BaseModuleImpl.getDetail_Details(model.FormKey); })); //创建表格列 cachesDic.AddTask(gridDetail_Details, "DynamicModel", dynamicModelTask); gridDetail_Details.GetDataCaches(cachesDic); Task detailDetailsGridRightMenusTask = cachesDic.AddTask(gridDetail_Details, "BaseGridRightMenus", new Task(() => { return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDTX_" + model.FormKey); })); } } #endregion BillModuleModelDic.Add(sourceModelRow, billModuleModel); #region 加载来源条件 Task searchControlTask = cachesDic.AddTask(sourceModelRow, "SearchControl", new Task(() => { DataTable controls = customQueryFieldsTask.Result; MyControl searchControl = null; if (model.SourceType != 1 || (controls != null && controls.Rows.Count > 0)) { // 创建自定义条件 string searchSql = model.SourceType == 1 ? Regex.Replace(model.DetailSql, "{speciesno}", "", RegexOptions.IgnoreCase) : model.SourceSql; searchControl = new MyControl(searchSql, gridControl == null ? gridDetail : gridControl, treeView); searchControl.Model = dynamicModel; searchControl.OtherParams = dynamicModel.OtherParams(); cachesDic.AddTask(searchControl, "DynamicModel", dynamicModelTask); cachesDic.AddTask(searchControl, "ControlsTable", customQueryFieldsTask); searchControl.GetSearchDataCaches(cachesDic); } return searchControl; })); #endregion } return true; })); #endregion } return true; })); #endregion } /// /// 说明:初始化分割条位置 /// 创建人:龚宇超 /// 创建日期:2018-03-06 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void InitlizeSpiltLocation() { try { // 设置单据来源底部高度 if (this.BillModel.PanelHeight == 0) { // 隐藏来源明细 this.ssc_main.PanelVisibility = SplitPanelVisibility.Panel1; } else { string height = IniHelper.Read(string.Format("bill_height_{0}", this.SysModel.ModuleCode)); if (!string.IsNullOrEmpty(height)) this.ssc_main.SplitterPosition = Convert.ToInt32(height); } } catch (Exception ex) { LogHelper.Instance.WriteError(ex); } } /// /// 说明:初始化系统配置 /// 创建人:龚宇超 /// 创建日期:2017-11-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void InitializeSetting() { Dictionary dataCaches = SysModel != null ? SysModel.DataCaches : null; if (!dataCaches.GetValue(this, "BillInfo", out DataRow modelRow)) { modelRow = BillImpl.GetBillInfo(this.SysModel.ModuleCode);//获取单个模块信息 } if (modelRow == null) { throw new Exception("模块编号[" + this.SysModel.ModuleCode + "],配置错误!\r\n该模块信息未找到!"); } if (!dataCaches.GetValue(this, "BillModel", out BillModel)) { this.BillModel = new BillModel(modelRow);//初始化类的新实例。 } if (this.BillModel != null) { this.BillModel.TypeName = string.IsNullOrEmpty(SysModel.BillMasterSql) ? this.SysModel.FormText : this.BillModel.TypeName;// 模块名称 if (!string.IsNullOrWhiteSpace(this.SysModel.DocumentName)) this.BillModel.TypeName = this.SysModel.DocumentName; if (!dataCaches.GetValue(this, "MasterPreFix", out string masterPreFix)) { masterPreFix = BaseImpl.GetColumnPrefix(this.BillModel.MasterTable);// 主表列前缀 } this.BillModel.MasterPreFix = masterPreFix; if (!dataCaches.GetValue(this, "DetailPreFix", out string detailPreFix)) { detailPreFix = BaseImpl.GetColumnPrefix(this.BillModel.DetailTable);// 明细表列前缀 } this.BillModel.DetailPreFix = detailPreFix; this.BillModel.DetailOrderField = this.BillModel.DetailPreFix + "lsidx_id";// 单据来源id if (SystemInfo.Instance.IsNotBillDetailOrder)//禁用排序 this.BillModel.DetailOrderField = string.Empty; } if (!dataCaches.GetValue(this, "MenuConfigTab", out DataRow menuRow)) { menuRow = BaseImpl.GetMenuConfigTab(this.SysModel.ModuleId);//获取菜单其他配置 } if (menuRow != null) { this.BillModel.BillSourceIds = menuRow.Table.Columns.Contains("BillSourceIds") ? (menuRow["BillSourceIds"] + "").Trim(',') : string.Empty; this.BillModel.BillFlag = menuRow.Table.Columns.Contains("BillFlag") && !string.IsNullOrEmpty(menuRow["BillFlag"] + "") ? Convert.ToInt32(menuRow["BillFlag"] + "") : -1; } if (this.SysModel.HideSource) { this.BillModel.PanelWidth = 0; this.BillModel.PanelHeight = 0; } if (!dataCaches.GetValue(this, "BillSetting", out bool _)) { BillImpl.InitBillSetting(this.BillModel); } } /// /// 说明:初始化控件 /// 创建人:龚宇超 /// 创建日期:2017-11-23 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void InitializeControl() { this.InitializeBillSource();//初始化单据来源 } /// /// 点击第一个默认新增行新增默认数据 /// /// /// private void GridView_MouseDown(object sender, MouseEventArgs e) { } /// /// 说明:初始化单据来源 /// 创建人:龚宇超 /// 创建日期:2017-11-28 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void InitializeBillSource() { this.xtc_main_container.TabPages.Clear(); Dictionary dataCaches = SysModel != null ? SysModel.DataCaches : null; if (!dataCaches.GetValue(this, "Details", out List attachModels)) { attachModels = GetAttachTabs(); } if (!dataCaches.GetValue(this, "Sources", out Hashtable htTable)) { string SourceIds = (this.BillModel.BillSourceIds + "").Trim(','); if (!string.IsNullOrWhiteSpace(this.SysModel.SourceDetailsID)) { SourceIds = (SourceIds + "," + this.SysModel.SourceDetailsID).Trim(','); } htTable = BillImpl.GetSources(this.SysModel.ModuleCode, SourceIds);//获取单据来源 } DataTable masterTable = htTable["master"] as DataTable; DataTable detailTable = htTable["detail"] as DataTable; /* 构造原理 * 1. 假如存在附加信息,则底部显示来源明细(来源明细摆放在标签第一个位置)+多标签,假如标签只有一个则隐藏标签头. * 2. 假如不存在附加信息,则底部只显示来源明细. **/ if (attachModels.Count > 0) { this.tb_buttom.Model = this.SysModel; this.tb_buttom.ParentControlEx = this.ControlObj; //this.tb_buttom.ParentGridEx = this.gcMain; if (this.BillModel.RefreshSelectedDetail) { //配置了只刷新当前页签后,切换页签时刷新 this.tb_buttom.TabControlObj.SelectedPageChanged += TabControlObj_SelectedPageChanged; } this.tb_buttom.InitTabPages(attachModels); } else { this.tb_buttom.TabControlObj.ShowTabHeader = DevExpress.Utils.DefaultBoolean.False; } dataCaches.GetValue(this, "InitSourcesTask", out bool _); int SerialNumber = 0; for (int i = 0; i < masterTable.Rows.Count; i++) { DataRow sourceModelRow = masterTable.Rows[i]; BillModuleModel billModuleModel = BillModuleModelDic.ContainsKey(sourceModelRow) ? BillModuleModelDic[sourceModelRow] : new BillModuleModel(); BillSourceModel model = billModuleModel.SourceModel != null ? billModuleModel.SourceModel : new BillSourceModel(sourceModelRow); object sourceControl = billModuleModel.SourceControl != null ? billModuleModel.SourceControl : null; object sourceDetailControl = billModuleModel.SourceDetailControl != null ? billModuleModel.SourceDetailControl : null; object sourceDetailDetailControl = billModuleModel.SourceDetailDetailControl != null ? billModuleModel.SourceDetailDetailControl : null; BillSourceUnionModel unionModel = new BillSourceUnionModel(); if (!dataCaches.GetValue(model, "CustomQueryFields", out DataTable controls)) { controls = BaseModuleImpl.GetCustomQueryFields(model.FormKey); } XtraTabPage tabPage = new XtraTabPage(); tabPage.Text = model.UserName; //只加载单据管理类型 if (!(model.SourceType == 2 || model.SourceType == 4)) continue; #region 加载来源表头 GridControlEx gridControl = null; TreeViewEx treeView = null; if (model.SourceType == 1) { // 来源为树类型 treeView = sourceControl != null ? (TreeViewEx)sourceControl : new TreeViewEx(); treeView.BorderStyle = BorderStyle.None; treeView.Dock = DockStyle.Fill; treeView.TreeNodeKeyField = model.SourceKeyField; treeView.TreeNodeTextField = model.SourceResult; if (!dataCaches.GetValue(treeView, "BindTreeTable", out DataTable bindTreeTable)) { bindTreeTable = BaseImpl.GetDataTableResult(model.SourceSql); } treeView.TreeInhibitSort = model.TreeInhibitSort; treeView.BindTreeView(bindTreeTable); treeView.TreeNodeSelectAfter += new TreeViewEventHandler(OnTreeNodeSelectAfter); tabPage.Controls.Add(treeView); } else if (model.SourceType == 5) { model.ChangeSourceType(2);//单据来源显示条数 this.IsBillShowCount = true; } else if (model.SourceType == 3 || model.SourceType == 4) { //类型为3,是树表格类型的单据管理。 //类型为4,是树表格类型的数据来源 gridControl = sourceControl != null ? (TreeGridControlEx)sourceControl : new TreeGridControlEx(); gridControl.Dock = DockStyle.Fill; gridControl.BorderStyle = System.Windows.Forms.BorderStyle.None; gridControl.Model = this.SysModel; if (!dataCaches.GetValue(gridControl, "SourceColumns", out DataTable dtSourceColumns)) { dtSourceColumns = BillImpl.GetSourceColumns(model.Id); } if (!dataCaches.GetValue(gridControl, "BaseGridRowColors", out DataTable dtBaseGridRowColors)) { dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("BILLSOURCE_" + model.FormKey); } if (!dataCaches.GetValue(gridControl, "BaseGridRightMenus", out DataTable dtBaseGridRightMenus)) { dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCE_" + model.FormKey); } //节点编号 if (!string.IsNullOrWhiteSpace(model.SourceKeyFieldName)) (gridControl as TreeGridControlEx).TreeListObj.KeyFieldName = model.SourceKeyFieldName; //父节点编号 if (!string.IsNullOrWhiteSpace(model.SourceParentFieldName)) (gridControl as TreeGridControlEx).TreeListObj.ParentFieldName = model.SourceParentFieldName; gridControl.SetReadOnlyColumns(dtSourceColumns, GridCustomColumnStruct.BillSourceGridView + model.FormKey); gridControl.SetGridRowColors(dtBaseGridRowColors); //gridControl.SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridControlRightCallback); (gridControl as TreeGridControlEx).SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridControlRightCallback); unionModel.TreeGridControlObj = gridControl as TreeGridControlEx; unionModel.TreeGridControlObj.TreeListObj.FocusedNodeChanged += new DevExpress.XtraTreeList.FocusedNodeChangedEventHandler(OnTreeListObjFocusedNodeChanged); if (BillModel.IsBillSourceCheck == 1) { GridDragGrid.TreeListAddCheckBox((gridControl as TreeGridControlEx).TreeListObj); } tabPage.Controls.Add(gridControl); } else { // 来源为表格类型 gridControl = sourceControl != null ? (GridControlEx)sourceControl : new GridControlEx(); gridControl.BorderStyle = BorderStyle.None; gridControl.Model = this.SysModel; gridControl.Dock = DockStyle.Fill; gridControl.ExportPermission = this.BillModel.ExportPermission; if (model.LoadFilter) { gridControl.GridView.OptionsView.ShowAutoFilterRow = true; } if (!dataCaches.GetValue(gridControl, "SourceColumns", out DataTable dtSourceColumns)) { dtSourceColumns = BillImpl.GetSourceColumns(model.Id); } if (!dataCaches.GetValue(gridControl, "BaseGridRowColors", out DataTable dtBaseGridRowColors)) { dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("BILLSOURCE_" + model.FormKey); } if (!dataCaches.GetValue(gridControl, "BaseGridRightMenus", out DataTable dtBaseGridRightMenus)) { dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCE_" + model.FormKey); } gridControl.SetReadOnlyColumns(dtSourceColumns, GridCustomColumnStruct.BillSourceGridView + model.FormKey); gridControl.SetGridRowColors(dtBaseGridRowColors); gridControl.SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridControlRightCallback); //gridControl.GridView.SelectionChanged += new SelectionChangedEventHandler(OnGridControlSelectionChanged); //gridControl.GridView.FocusedRowObjectChanged += OnFocusedRowObjectChanged; //if (model.DetailsDoubleClick) //{ // gridControl.GridView.DoubleClick += OnSourceGridViewDoubleClick; // 2023-3-11 增加双击配置 //} //else //{ // gridControl.GridView.RowCellClick += OnGridViewRowCellClick; // 2019-11-12 cmd提出改为行点击事件,否则会出现保存提交后,单据管理无法查询出数据 //} gridControl.GridView.RowCellClick += OnGridViewRowCellClick; // 2019-11-12 cmd提出改为行点击事件,否则会出现保存提交后,单据管理无法查询出数据 gridControl.GridView.DoubleClick += OnSourceGridViewDoubleClick;//双击事件改成打开单据主消息控件 if (BillModel.IsBillSourceCheck == 1) { GridDragGrid.GridAddCheckBox(gridControl.GridView); } tabPage.Controls.Add(gridControl); } #endregion #region 加载来源明细 XtraTabPage tabDetail = new XtraTabPage(); if (SystemInfo.Instance.GridRowFontSize > 0) { //页签大小 FontFamily fontFamily = tabDetail.Appearance.Header.Font.FontFamily; tabDetail.Appearance.Header.Font = new System.Drawing.Font(fontFamily, SystemInfo.Instance.GridRowFontSize); } DataRow[] detailColumns = detailTable.Select("sourceId=" + model.Id); //明细为表格 GridControlEx gridDetail = new GridControlEx(); if (!string.IsNullOrWhiteSpace(model.DetailMenuCode)) { //来源明细配置了模块号,根据模块号创建对应的ModuleGridEx //ModuleGridEx主要是用保存的功能,数据源sql还是根据配置的为准 DataRow modelRow = MainImpl.GetSystemdllTab(model.DetailMenuCode);//获取模块信息 if (modelRow == null) { MessageUtil.Show($"没有找到编号为 {model.DetailMenuCode} 的模块信息"); gridDetail.Parent = gridDetail; continue; } ModuleModel sysModel = new ModuleModel(modelRow); //设置主表sql //model.SourceSql = sysModel.MenuSql; DynamicModuleModel dyncModel = new DynamicModuleModel(new[] { sysModel.MenuName, ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, this.SysModel.Privilege, sysModel.ModeCode, "0" }); ModuleGridEx gridEx = new ModuleGridEx(); gridEx.Dock = DockStyle.Fill; if (model.SourceType == 1) { gridEx.LeftTreeViewEx = treeView; } else { gridEx.LeftGridEx = gridControl; gridEx.ParentGridEx = gridControl; } gridEx.ParentKeyField = model.SourceKeyField; gridEx.ParentUnionField = model.SourceKeyField; gridEx.VisibleSearchPanel = false;//禁止上方搜索 gridEx.InitializeControl(sysModel, dyncModel); gridDetail = gridEx.GridControlObj; gridEx.Parent = tabDetail; unionModel.GridDetailModuleGridEx = gridEx; if (sysModel.TreeAutoMultiHeader == 1) model.ChangeSourceDetailType("1"); if (SerialNumber == 0) { this.tb_buttom.TabControlObj.TabPages.Insert(0, tabDetail); this.tb_buttom.TabControlObj.SelectedTabPageIndex = 0; if (attachModels.Count > 0) this.tb_buttom.TabControlObj.TabPages[0].Text = model.UserName + DetailedSuffix; } } else { if (model.sourceDetailType.Equals("1")) { //明细为树表格 gridDetail = sourceDetailControl != null ? (TreeGridControlEx)sourceDetailControl : new TreeGridControlEx(); gridDetail.Model = this.SysModel; gridDetail.Dock = DockStyle.Fill; gridDetail.SetReadOnlyColumns(detailColumns == null || detailColumns.Length == 0 ? new DataTable() : detailColumns.CopyToDataTable(), GridCustomColumnStruct.BillSourceDetailGridView + model.FormKey); if (!dataCaches.GetValue(gridDetail, "BaseGridRowColors", out DataTable dtBaseGridRowColors)) { dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("SOURCEDETAIL_" + model.FormKey); } if (!dataCaches.GetValue(gridDetail, "BaseGridRightMenus", out DataTable dtBaseGridRightMenus)) { dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDT_" + model.FormKey); } gridDetail.SetGridRowColors(dtBaseGridRowColors); gridDetail.SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridDetailRightMenuCallback); gridDetail.Parent = tabDetail; gridDetail.BorderStyle = System.Windows.Forms.BorderStyle.None; if (SerialNumber == 0) { this.tb_buttom.TabControlObj.TabPages.Insert(0, tabDetail); this.tb_buttom.TabControlObj.SelectedTabPageIndex = 0; if (attachModels.Count > 0) this.tb_buttom.TabControlObj.TabPages[0].Text = model.UserName + DetailedSuffix; } if (BillModel.IsBillDetailCheck == 1)//加载复选框 { GridDragGrid.TreeListAddCheckBox((gridDetail as TreeGridControlEx).TreeListObj); } } else { gridDetail = sourceDetailControl != null ? (GridControlEx)sourceDetailControl : new GridControlEx(); gridDetail.Model = this.SysModel; gridDetail.Dock = DockStyle.Fill; gridDetail.SetReadOnlyColumns(detailColumns == null || detailColumns.Length == 0 ? new DataTable() : detailColumns.CopyToDataTable(), GridCustomColumnStruct.BillSourceDetailGridView + model.FormKey); if (model.DetailedLoadFilter) { gridDetail.GridView.OptionsView.ShowAutoFilterRow = true; } if (!dataCaches.GetValue(gridDetail, "BaseGridRowColors", out DataTable dtBaseGridRowColors)) { dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("SOURCEDETAIL_" + model.FormKey); } if (!dataCaches.GetValue(gridDetail, "BaseGridRightMenus", out DataTable dtBaseGridRightMenus)) { dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDT_" + model.FormKey); } gridDetail.SetGridRowColors(dtBaseGridRowColors); gridDetail.SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridDetailRightMenuCallback); //明细的明细(明细分成左右2个) if (!string.IsNullOrEmpty(model.SourceDetailsDetailsSql)) { GridControlEx gridDetail_Details = sourceDetailDetailControl != null ? (GridControlEx)sourceDetailDetailControl : new GridControlEx(); gridDetail_Details.Model = this.SysModel; gridDetail_Details.Dock = DockStyle.Fill; //创建只读列 if (!dataCaches.GetValue(gridDetail_Details, "Detail_Details", out DataTable dataTable)) { dataTable = BaseModuleImpl.getDetail_Details(model.FormKey); } gridDetail_Details.SetReadOnlyColumns(dataTable); //设置右键 if (!dataCaches.GetValue(gridDetail_Details, "BaseGridRightMenus", out DataTable dttBaseGridRightMenus)) { dttBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDTX_" + model.FormKey); } gridDetail_Details.SetGridRightMenus(dttBaseGridRightMenus, this.SysModel, OnGridDetailRightMenuCallback); //明细点击 更新 明细的明细 gridDetail.GridView.FocusedRowObjectChanged += GridView_FocusedRowObjectChanged; gridDetail.GridView.Tag = model.SourceDetailsDetailsSql; //创建SplitContainerControl控件,让下方可以左右拖动 SplitContainerControl splitContainerControl = new DevExpress.XtraEditors.SplitContainerControl(); splitContainerControl.Dock = DockStyle.Fill; splitContainerControl.Panel1.Controls.Add(gridDetail); gridDetail.BorderStyle = System.Windows.Forms.BorderStyle.None; splitContainerControl.Panel2.Controls.Add(gridDetail_Details); gridDetail_Details.BorderStyle = System.Windows.Forms.BorderStyle.None; splitContainerControl.SplitterMoved += new System.EventHandler(this.OnDetailsSplitterMoved); string newwidth = IniHelper.Read(string.Format("bill_Details_Width_{0}", this.SysModel.ModuleCode));//通过Key获取Value值 if (!string.IsNullOrEmpty(newwidth)) { splitContainerControl.SplitterPosition = Convert.ToInt32(newwidth); } else { int width = this.tb_buttom.Width;//获取控件宽度 splitContainerControl.SplitterPosition = width / 2;//然后将分割位置设置在宽度一半位置 } splitContainerControl.Parent = tabDetail; unionModel.GridDetailDetailControlObj = gridDetail_Details; } else { gridDetail.Parent = tabDetail; gridDetail.BorderStyle = System.Windows.Forms.BorderStyle.None; } if (SerialNumber == 0) { this.tb_buttom.TabControlObj.TabPages.Insert(0, tabDetail); this.tb_buttom.TabControlObj.SelectedTabPageIndex = 0; if (attachModels.Count > 0) this.tb_buttom.TabControlObj.TabPages[0].Text = model.UserName + DetailedSuffix; } if (BillModel.IsBillDetailCheck == 1)//加载复选框 { GridDragGrid.GridAddCheckBox(gridDetail.GridView); } } } #endregion #region 加载来源条件 if (model.SourceType == 1 && (controls == null || controls.Rows.Count == 0)) { //// 设置默认下拉列表框 //DataTable columnTable = detailTable.Select("sourceId=" + model.Id + " and isnull(isVisible,0)=0").CopyToDataTable(); //this.lceCombobox.ValueMember = this.lceCombobox.ValueField = "fieldName"; //this.lceCombobox.TextField = "userName"; //this.lceCombobox.SetDataSource(columnTable); //this.lceCombobox.TextEdit.SelectedIndex = 0; //this.pl_treeview_detault_search.Dock = DockStyle.Bottom; //this.pl_treeview_detault_search.Visible = true; //tabPage.Controls.Add(pl_treeview_detault_search); } else { // 创建自定义条件 string searchSql = model.SourceType == 1 ? Regex.Replace(model.DetailSql, "{speciesno}", "", RegexOptions.IgnoreCase) : model.SourceSql; PanelControl searchPanel = new PanelControl(); if (!dataCaches.GetValue(sourceModelRow, "SearchControl", out MyControl searchControl)) { searchControl = new MyControl(searchSql, gridControl == null ? gridDetail : gridControl, treeView); } searchControl.OnSearchBeforeCallBack += new SearchEventHandler(OnSearchBefore); searchControl.OnSearchAfterCallBack += new EventHandler(OnSearchAfterd); if (SerialNumber == 0 && !SystemInfo.Instance.IsBillSourceRefushTag.Equals("1") && string.IsNullOrWhiteSpace(this.BillModel.InitialRefreshId)) { // 第一个页面要刷新数据,所以绑定事件用于初始化完成后在查询数据 searchControl.OnDataSourceBindCallBack += new EventHandler(OnFirstPageDataSourceBindCallBack); } if (!string.IsNullOrWhiteSpace(this.BillModel.InitialRefreshId) && this.BillModel.InitialRefreshId.Equals(model.Id + "")) { searchControl.OnDataSourceBindCallBack += SearchControl_OnDataSourceBindCallBack; InitialSelectionTab = tabPage; } searchControl.ParentUnionField = model.SourceKeyField; searchPanel.Dock = DockStyle.Top; searchPanel.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder; searchPanel.BackColor = Color.Transparent; searchPanel.Parent = tabPage; searchControl.OtherParams = this.SysModel.OtherParams(); searchPanel.Height = searchControl.InitSearchControl(controls, searchPanel); unionModel.SearchObj = searchControl; } #endregion unionModel.GridControlObj = gridControl; if (model.sourceDetailType.Equals("1")) { unionModel.TreeGridDetailControlObj = (gridDetail as TreeGridControlEx); } else { unionModel.GridDetailControlObj = gridDetail; } unionModel.ModelObj = model; unionModel.TreeViewObj = treeView; if (SerialNumber == 0) unionModel.IsChange = true; tabPage.Tag = unionModel; if (model.SourceType == 0 && !model.DisableShowSourceCount) { // 模块要查看具体条数 unionModel.SearchObj.OnDataSourceBindCallBack += new EventHandler(OnPageDataSourceBindCallBack); pageNumKey.Add(unionModel.SearchObj, tabPage); } this.xtc_main_container.TabPages.Add(tabPage); SerialNumber++; } } /// /// 点击来源明细,加载明细的明细 /// /// /// private void GridView_FocusedRowObjectChanged(object sender, FocusedRowObjectChangedEventArgs e) { try { GridView gridView = sender as GridView; DataRow rowItem = gridView.GetFocusedDataRow(); string sql = gridView.Tag + ""; BillSourceUnionModel unionModel = this.xtc_main_container.SelectedTabPage.Tag as BillSourceUnionModel; if (unionModel.GridDetailDetailControlObj != null) { unionModel.GridDetailDetailControlObj.gridControl.DataSource = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, sql)); } } catch (Exception ex) { MessageUtil.Show(ex); } } #region 单据来源相关 /// /// 说明:刷新当前选中的TabPage /// 创建人:龚宇超 /// 创建日期:2018-06-29 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// private void RefreshSelectedSource() { if (this.xtc_main_container.SelectedTabPage == null) return;//来源选择为null(不显示左侧来源)。不执行下方刷新 XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; BillSourceUnionModel model = tabPage.Tag as BillSourceUnionModel; if (model.GridControlObj != null) this.RefreshSource(model); if (BillModel.drgFinishHide == "1") { if (model.ModelObj.SourceType == 1) { string sqlValue = ReplaceHelper.ReplaceUserInfo(ReplaceHelper.ReplaceWhereCond(model.ModelObj.DetailSql)); sqlValue = sqlValue.Replace("#", ""); sqlValue = this.ControlObj.ReplaceControlValue(sqlValue); sqlValue = ReplaceHelper.ReplaceParamToValue(sqlValue, model.TreeViewObj.GetSelectValue()); model.GridDetailControlObj.GridControl.DataSource = BillImpl.GetDataTableResult(sqlValue); } else { this.RefreshSourceDetail(model); } } if (model.ModelObj.SourceType == 0 && model.SearchObj.GridRowCount > 0) tabPage.Text = model.ModelObj.UserName + "(" + model.SearchObj.GridRowCount + QuantitySuffix; } /// /// 说明:刷新单据来源主表,未传递时,默认刷新 /// 创建人:龚宇超 /// 创建日期:2017-12-13 /// 修改人: /// 修改日期: /// 修改备注:gcMain /// 版本:1.0 /// /// The union model. /// XtraTabPage. private void RefreshSource(BillSourceUnionModel unionModel = null) { if (unionModel == null || unionModel.SearchObj == null) return; unionModel.SearchObj.SearchLastGrid(); } /// /// 说明:刷新单据来源明细 /// 创建人:龚宇超 /// 创建日期:2017-11-30 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The union model. private void RefreshSourceDetail(BillSourceUnionModel unionModel) { if (unionModel == null) return; XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; if (unionModel.ModelObj.SourceType == 1) { // 树加载明细 //string fieldName = this.lceCombobox.EditValue; //string fieldValue = this.textEdit1.Text.Trim(); string fieldName = string.Empty; string fieldValue = string.Empty; string checkStrs = unionModel.TreeViewObj.GetCheckValues(); string sqlValue = ReplaceHelper.ReplaceParamToValue(ReplaceHelper.ReplaceUserInfo(unionModel.ModelObj.DetailSql), unionModel.TreeViewObj.GetSelectNodeValue()); if (!string.IsNullOrEmpty(checkStrs)) checkStrs = " and SpeciesNo in (" + checkStrs.TrimEnd(',') + ")"; sqlValue = string.Format("select * from ({0}) temp where 1=1 ", ReplaceHelper.ReplaceWhereCond(sqlValue) + checkStrs) + string.Format(" and ({0} like '%{1}%' or dbo.P_getpy({0}) like '%{1}%')", fieldName, fieldValue); try { WaitForm.ShowForm(); unionModel.GridDetailControlObj.GridControl.DataSource = BillImpl.GetDataTableResult(sqlValue); } catch (Exception ex) { MessageUtil.Show(ex); LogHelper.Instance.WriteError(ex); LogUtil.WriteError(BillModel.TypeName + "模块刷新树加载明细出错!", ex); } finally { WaitForm.HideForm(); } } else { // 加载明细 try { WaitForm.ShowForm(); DataRow rowItem = unionModel.GridControlObj.GridView.GetFocusedDataRow(); //unionModel.GridDetailControlObj.GridControl.DataSource = rowItem == null // ? new DataTable() : BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, unionModel.ModelObj.DetailSql)); if (unionModel.ModelObj.SourceType == 3 || unionModel.ModelObj.SourceType == 4) { rowItem = unionModel.TreeGridControlObj.GetViewFocusedDataRow(); } string DetailSql = unionModel.ModelObj.DetailSql; DetailSql = ReplaceHelper.ReplaceUserInfo(DetailSql); DetailSql = ReplaceHelper.ReplaceWhereCond(DetailSql); DetailSql = ReplaceHelper.ReplaceRowParam(rowItem, DetailSql); if (unionModel.SearchObj != null) DetailSql = unionModel.SearchObj.ReplaceParentControlValue(DetailSql); if (unionModel.ModelObj.sourceDetailType == "1") { unionModel.TreeGridDetailControlObj.SetGridViewDataSource(rowItem == null ? new DataTable() : BillImpl.GetDataTableResult(DetailSql)); } else { //有复选框的页签在刷新前清空选中行,否则合计在刷新数据源后不会自带改变 if (unionModel.GridDetailControlObj.GridView.OptionsSelection.MultiSelectMode == GridMultiSelectMode.CheckBoxRowSelect && unionModel.GridDetailControlObj.GridView.OptionsSelection.MultiSelect == true) { //int[] selectIndexs = unionModel.GridDetailControlObj.GridView.GetSelectedRows(); unionModel.GridDetailControlObj.GridView.ClearSelection(); } unionModel.GridDetailControlObj.GridControl.DataSource = rowItem == null ? new DataTable() : BillImpl.GetDataTableResult(DetailSql); } if (unionModel.GridDetailModuleGridEx != null) { unionModel.GridDetailModuleGridEx.GridControlObj.LastSearchSql = DetailSql; } DataTable table = null; if (unionModel.ModelObj.sourceDetailType == "1") { table = unionModel.TreeGridDetailControlObj.TreeListObj.DataSource as DataTable; } else { table = unionModel.GridDetailControlObj.GridControl.DataSource as DataTable; } if (table != null && !table.Columns.Contains("_check")) { table.Columns.Add("_check", typeof(bool)); foreach (DataRow row in table.Rows) { row["_check"] = 0; } } if (tb_buttom.TabControlObj.TabPages.Count > 0) { for (int i = 0; i < this.tb_buttom.TabControlObj.TabPages.Count; i++) { XtraTabPage page = this.tb_buttom.TabControlObj.TabPages[i]; if (i == 0) continue; if (rowItem != null && page != null) { this.SetTabPageDataSource(page, rowItem); } } //foreach (XtraTabPage AttachPage in this.tb_buttom.TabControlObj.TabPages) //{ // GridDetailModel model = tb_buttom.GetGridDetailModel(AttachPage); // if (model == null) continue; // string sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, model.DetailSql); // this.tb_buttom.SetGridDataSource(AttachPage, sqlValue); //} } } catch (Exception ex) { MessageUtil.Show(ex); LogHelper.Instance.WriteError(ex); LogUtil.WriteError(BillModel.TypeName + "模块加载明细出错!", ex); } finally { WaitForm.HideForm(); } } } /// /// 说明:刷新单据来源 /// 创建人:龚宇超 /// 创建日期:2019-12-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void SaveRefreshSource() { foreach (XtraTabPage tabPage in this.xtc_main_container.TabPages) { BillSourceUnionModel model = tabPage.Tag as BillSourceUnionModel; if (model != null && model.GridControlObj != null && model.ModelObj.SaveRefreshFlag) { this.RefreshSource(model); this.RefreshSourceDetail(model); } } } /// /// 说明: /// 创建人:龚宇超 /// 创建日期:2017-11-30 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// true if XXXX, false otherwise. private bool ValidateDetailCond(DataRow rowItem, BillSourceUnionModel unionModel) { bool validate = false; try { string detailCond = ReplaceHelper.ReplaceRowParam(rowItem, unionModel.ModelObj.DetailEnableCond); detailCond = detailCond.ToLower();//2025-09-08 赵坤表示条件全部转成小写判断。 来源明细中不能配置单元格类型(不能配置 复选框条件 {xxx}=0 ),只能写{xxx}='Ture'。这种bit类型容易忘记大小的情况 if (detailCond.Contains("#")) { List condition = ReplaceHelper.GetParamFields(detailCond); foreach (string item in condition) { string fieldValue = this.ControlObj.GetControlValue(item.Replace("{#", "").Replace("}", "")); detailCond = detailCond.Replace(item, fieldValue); } } if (detailCond.StartsWith("@") || detailCond.StartsWith("!")) { validate = "1".Equals(BaseImpl.GetDefaultValue(detailCond)); } else { validate = ReplaceHelper.EvalCond(detailCond); } } catch (Exception ex) { LogHelper.Instance.WriteLog(ex.StackTrace); LogUtil.WriteError("验证多条添加条件出错!", ex); //MessageUtil.Show(ResourceKeys.CondtionError + "\r\n" + unionModel.ModelObj.DetailEnableCond); } return validate; } /// /// 说明:单据来源右键菜单执行完后刷新 /// 创建人:龚宇超 /// 创建日期:2017-12-11 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void OnGridControlRightCallback(object sender, EventArgs e) { this.RefreshSelectedSource(); // 执行右键菜单后刷新单据状态2020-03-23 XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; BillSourceUnionModel model = tabPage.Tag as BillSourceUnionModel; } /// /// 说明:获取单据管理的单据来源标签 /// 创建人:龚宇超 /// 创建日期:2017-12-13 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private BillSourceUnionModel GetBillSourceManager() { foreach (XtraTabPage item in this.xtc_main_container.TabPages) { BillSourceUnionModel model = item.Tag as BillSourceUnionModel; if (model.ModelObj.SourceType == 2) return model; } return null; } /// /// 说明:初始化附加信息 /// 创建人:龚宇超 /// 创建日期:2018-04-26 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private List GetAttachTabs() { List details = new List(); DataTable table = BaseAuditImpl.GetAttachTabs(this.SysModel.ModuleCode, "100", " and orderid < 0 "); foreach (DataRow item in table.Rows) { DataTable gridColumns = BaseAuditImpl.GetBottomBasicInformation(item["formKey"] + ""); details.Add(new GridDetailModel(item, gridColumns, GridCustomColumnStruct.BillSourceDetailAttachGridView)); } return details; } #endregion #region 事件相关 /// /// 说明:打印完成后回调 /// 创建人:龚宇超 /// 创建日期:2018-07-05 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The e. private void OnReportPrintAfter(object sender, EventArgs e) { //打印完成后添加数据库 if (_printSaveParams != null && _printSaveParams.Count > 0) { int result = BaseModuleImpl.SavePrintRecord(_printSaveParams[0], _printSaveParams[1], _printSaveParams[2], _printSaveParams[3], _printSaveParams[4]); } } /// /// 说明: /// 创建人:龚宇超 /// 创建日期:2017-11-28 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void OnFrmMainKeyDown(object sender, KeyEventArgs e) { // 窗口获取按键则表格按键中断.有时间处理 if (e.Modifiers.CompareTo(Keys.Control) == 0) { if (e.KeyCode == Keys.Down) this.ssc_main.Collapsed = true; if (e.KeyCode == Keys.Up) this.ssc_main.Collapsed = false; } } /// /// 说明:树节点选中刷新明细 /// 创建人:龚宇超 /// 创建日期:2017-12-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void OnTreeNodeSelectAfter(object sender, TreeViewEventArgs e) { TreeView tree = (TreeView)sender; XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel; if (unionModel != null) { WaitForm.ShowForm(); try { string sqlValue = ReplaceHelper.ReplaceUserInfo(ReplaceHelper.ReplaceWhereCond(unionModel.ModelObj.DetailSql)); sqlValue = sqlValue.Replace("#", ""); sqlValue = this.ControlObj.ReplaceControlValue(sqlValue); if (unionModel.SearchObj != null) sqlValue = unionModel.SearchObj.ReplaceControlValue(sqlValue); sqlValue = ReplaceHelper.ReplaceParamToValue(sqlValue, e.Node.Name); if (unionModel.GridDetailModuleGridEx != null) { unionModel.GridDetailModuleGridEx.GridControlObj.LastSearchSql = sqlValue; } if (unionModel.ModelObj.sourceDetailType == "1" && unionModel.TreeGridDetailControlObj.TreeListObj != null) { unionModel.TreeGridDetailControlObj.TreeListObj.DataSource = BillImpl.GetDataTableResult(sqlValue); } else { unionModel.GridDetailControlObj.GridControl.DataSource = BillImpl.GetDataTableResult(sqlValue); } } catch (Exception ex) { LogHelper.Instance.WriteError(ex); LogUtil.WriteError(BillModel.TypeName + "模块选中树节点" + tree.SelectedNode.Text + "刷新明细失败!", ex); } finally { WaitForm.HideForm(); } } } /// /// 说明:单据来源切换Tab标签 /// 创建人:龚宇超 /// 创建日期:2017-11-28 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void OnTabSelectedPageChanged(object sender, TabPageChangedEventArgs e) { try { if (_isInitFinish && !SystemInfo.Instance.IsBillSourceRefushTag.Equals("1")) { BillSourceUnionModel unionModel = e.Page.Tag as BillSourceUnionModel; if (unionModel != null) { this.RefreshSelectedSource(); this.tb_buttom.TabControlObj.TabPages[0].Controls.Clear(); if (unionModel.GridDetailModuleGridEx != null) { this.tb_buttom.TabControlObj.TabPages[0].Controls.Add(unionModel.GridDetailModuleGridEx); } else if (unionModel.GridDetailDetailControlObj == null) { this.tb_buttom.TabControlObj.TabPages[0].Controls.Add(unionModel.GridDetailControlObj != null ? unionModel.GridDetailControlObj : unionModel.TreeGridDetailControlObj); } else { //this.tb_buttom.TabControlObj.TabPages[0].Controls.Add(unionModel.GridDetailDetailControlObj); //创建SplitContainerControl控件,让下方可以左右拖动 SplitContainerControl splitContainerControl = new DevExpress.XtraEditors.SplitContainerControl(); splitContainerControl.Dock = DockStyle.Fill; splitContainerControl.Panel1.Controls.Add(unionModel.GridDetailControlObj); splitContainerControl.Panel2.Controls.Add(unionModel.GridDetailDetailControlObj); int width = this.tb_buttom.Width;//获取控件宽度 splitContainerControl.SplitterPosition = width / 2;//然后将分割位置设置在宽度一半位置 this.tb_buttom.TabControlObj.TabPages[0].Controls.Add(splitContainerControl); } this.tb_buttom.TabControlObj.TabPages[0].Text = unionModel.ModelObj.UserName + DetailedSuffix; if (unionModel.IsChange == false) { AutoSizeChange.ControllInitializeSize(this.tb_buttom.TabControlObj.TabPages[0]); unionModel.IsChange = true; } } } } catch (Exception ex) { LogHelper.Instance.WriteError(ex); LogUtil.WriteError("单据切换标签失败!", ex); } } /// /// 说明:单据来源树结构默认查询条件 /// 创建人:龚宇超 /// 创建日期:2017-11-28 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void OnTreeSearchClick(object sender, EventArgs e) { XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel); } /// /// 单据来源树 条件框回车查询 /// /// /// private void OnTreeConditionKeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { this.OnTreeSearchClick(null, null); } } /// /// 说明:第一个页签初始化完成刷新数据 /// 创建人:龚宇超 /// 创建日期: /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. private void OnFirstPageDataSourceBindCallBack(object sender, EventArgs e) { try { if (IsBillMaster) { this.RefreshSelectedSource(); } } catch (Exception ex) { LogHelper.Instance.WriteError(ex); LogUtil.WriteError("单据切换标查询失败!", ex); } } /// /// 说明:第一个页签初始化完成刷新数据 /// 创建人:龚宇超 /// 创建日期: /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. private void OnPageDataSourceBindCallBack(object sender, EventArgs e) { try { MyControl searchControl = sender as MyControl; XtraTabPage tabPage = pageNumKey[searchControl]; if (tabPage.TabIndex == 0) return; BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel; string searchSql = unionModel.ModelObj.SourceSql; searchSql = ReplaceHelper.ReplaceUserInfo(searchSql); searchSql = ReplaceHelper.ReplaceWhereCond(searchSql); searchSql = unionModel.SearchObj.SetSearchSqlValue(searchSql, true, true); // 查找FROM子句的位置 int fromIndex = searchSql.IndexOf("FROM", StringComparison.OrdinalIgnoreCase); if (fromIndex != -1) { // 生成优化后的SQL查询 string optimizedSql = "SELECT COUNT(*) " + searchSql.Substring(fromIndex); searchSql = optimizedSql; } DataTable dt = MainImpl.GetDataTableResult(searchSql); if (dt.Rows.Count > 0) tabPage.Text += "(" + dt.Rows[0][0] + QuantitySuffix; } catch (Exception ex) { LogHelper.Instance.WriteError(ex); LogUtil.WriteError("单据条件绑定失败失败!", ex); } } /// /// 跳转到指定页签,并执行配置条件的搜索 /// /// /// private void SearchControl_OnDataSourceBindCallBack(object sender, EventArgs e) { if (InitialSelectionTab != null) { this.xtc_main_container.SelectedTabPage = InitialSelectionTab; BillSourceUnionModel model = InitialSelectionTab.Tag as BillSourceUnionModel; if (model.SearchObj != null) model.SearchObj.SearchGrid(); } } /// /// 说明:单据来源选中行,加载明细 /// 创建人:龚宇超 /// 创建日期:2017-11-30 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void OnGridControlSelectionChanged(object sender, SelectionChangedEventArgs e) { XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel); } /// /// 说明:单据来源选中行,加载明细 /// 创建人:龚宇超 /// 创建日期:2017-11-30 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void OnGridViewRowCellClick(object sender, RowCellClickEventArgs e) { XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel; this.RefreshSourceDetail(unionModel); } private void OnSourceGridViewDoubleClick(object sender, EventArgs e) { XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel; //this.RefreshSourceDetail(unionModel); DataRow rowItem = unionModel.GridControlObj.GridView.GetFocusedDataRow(); if (rowItem == null) return; //单据号 string billno = rowItem[BillModel.PrimaryKey] + ""; DynamicBillModel model = CloneDynamicBillModel(this.SysModel); model.BillOrderNo = billno; FrmBill frmBill = new FrmBill(model); frmBill.Text = string.Format("{0}-详情[单据编号:{1}]", this.BillModel.TypeName, billno); frmBill.ShowDialog(); //刷新界面 unionModel.SearchObj.SearchLastGrid(); } // /// 复制单据动态参数,保留原对象的运行时配置和缓存。 /// private static DynamicBillModel CloneDynamicBillModel(DynamicBillModel source) { if (source == null) return null; MethodInfo method = typeof(object).GetMethod( "MemberwiseClone", BindingFlags.Instance | BindingFlags.NonPublic); return method.Invoke(source, null) as DynamicBillModel; } /// /// 说明:单据明细选中刷新附件明细 /// 创建人:王一帆 /// 创建日期:2021-06-30 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void OngcMainRowCellClick(object sender, RowCellClickEventArgs e) { if (this.tb_buttom.TabControlObj.TabPages.Count > 1) { SetDetailGridDataSource(); } } /// /// 切换下方附加模块页签时,刷新当前页签 /// /// /// private void TabControlObj_SelectedPageChanged(object sender, TabPageChangedEventArgs e) { if (this.tb_buttom.TabControlObj.TabPages.Count > 1) { SetDetailGridDataSource(); } } /// /// 说明:获取底部多标签数据 /// 创建人:龚宇超 /// 创建日期:2017-12-19 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// public void SetDetailGridDataSource() { DataRow rowItem = null; //DataRow rowItem = this.gcMain.GridView.GetFocusedDataRow(); //if (this.BillModel.DetailTreeTable) //{ // rowItem = (this.gcMain as TreeGridControlEx).GetViewFocusedDataRow(); //} int i = 0; foreach (XtraTabPage page in this.tb_buttom.TabControlObj.TabPages) { if (i == 0) { i++; continue; } if (this.BillModel.RefreshSelectedDetail && page != tb_buttom.TabControlObj.SelectedTabPage) { continue; } if (rowItem != null && page != null) { this.SetTabPageDataSource(page, rowItem); } } } /// /// 说明:设置表格数据 /// 创建人:龚宇超 /// 创建日期:2018-01-29 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The tab page. /// The grid control. public void SetTabPageDataSource(XtraTabPage tabPage, DataRow rowItem) { GridDetailModel model = this.tb_buttom.GetGridDetailModel(tabPage); if (rowItem != null && model != null) { if (tabPage.Tag is ModuleWebView) { // 加载网页 string url = ReplaceHelper.ReplaceRowParam(rowItem, ReplaceHelper.ReplaceUserInfo(model.DetailSql)); url = url.StartsWith("http") ? url : SystemInfo.Instance.OAUrl + url; ModuleWebView webView = tabPage.Tag as ModuleWebView; webView.Dock = DockStyle.Fill; webView.Tag = model; webView.Navigate(url); } else if (tabPage.Tag is FrmWebBrowser) { // 加载网页 string url = ReplaceHelper.ReplaceRowParam(rowItem, ReplaceHelper.ReplaceUserInfo(model.DetailSql)); url = url.StartsWith("http") ? url : SystemInfo.Instance.OAUrl + url; FrmWebBrowser webView = tabPage.Tag as FrmWebBrowser; webView.Dock = DockStyle.Fill; webView.Tag = model; webView.LoadUrl(url); } else if (tabPage.Tag is FrmMiniBlink) { // 加载网页 string url = ReplaceHelper.ReplaceRowParam(rowItem, ReplaceHelper.ReplaceUserInfo(model.DetailSql)); url = url.StartsWith("http") ? url : SystemInfo.Instance.OAUrl + url; FrmMiniBlink webView = tabPage.Tag as FrmMiniBlink; webView.Dock = DockStyle.Fill; webView.Tag = model; webView.LoadUrl(url); } else if (tabPage.Tag is TabMultipledetails) { TabMultipledetails tabMultipledetails = tabPage.Tag as TabMultipledetails; tabMultipledetails.SetConditionValues(rowItem); GridControlEx grdExMain = (tabMultipledetails.SplitMain.Panel1.Tag as GridControlEx); GridDetailModel MainModel = grdExMain.Tag as GridDetailModel; string searchMainSql = this.GetSearchSql(MainModel, rowItem); DataTable firstTable = MainImpl.GetDataTableResult(searchMainSql); grdExMain.LastSearchSql = searchMainSql; grdExMain.SetGridViewDataSource(firstTable); if (tabMultipledetails.SplitMain.Panel2.Tag is GridControlEx) { GridControlEx grdExAdditional = (tabMultipledetails.SplitMain.Panel2.Tag as GridControlEx); GridDetailModel AdditionalModel = grdExAdditional.Tag as GridDetailModel; string searchAddSql = this.GetSearchSql(AdditionalModel, rowItem); if (!MainModel.IsUnioDetail) { grdExAdditional.LastSearchSql = searchAddSql; grdExAdditional.SetGridViewDataSource(MainImpl.GetDataTableResult(searchAddSql)); } //右侧是左侧的明细,左侧没有数据时。右侧赋空值(因为无法触发左侧行改变事件) if (MainModel.IsUnioDetail && firstTable.Rows.Count == 0) { grdExAdditional.LastSearchSql = ""; grdExAdditional.SetGridViewDataSource(new DataTable()); } } else if (tabMultipledetails.SplitMain.Panel2.Tag is ChartControlEx) { ChartControlEx grdExAdditional = (tabMultipledetails.SplitMain.Panel2.Tag as ChartControlEx); GridDetailModel AdditionalModel = grdExAdditional.Tag as GridDetailModel; string searchAddSql = this.GetSearchSql(AdditionalModel, rowItem); DataTable table = MainImpl.GetDataTableResult(searchAddSql); grdExAdditional.CreateChart(table); } tabPage.Text = MainModel.DetailName + "(" + firstTable.Rows.Count + QuantitySuffix; //tabPage.Text = MainModel.DetailName + "(" + firstTable.Rows.Count + "条)"; //tabPage.Appearance.Header.ForeColor = firstTable.Rows.Count > 0 ? Color.Red : Color.FromArgb(0, 0, 0); } else { string searchSql = this.GetSearchSql(model, rowItem); if (tabPage.Tag is GridControlEx) { (tabPage.Tag as GridControlEx).LastSearchSql = searchSql; } this.tb_buttom.SetGridDataSource(tabPage, MainImpl.GetDataTableResult(searchSql)); if (tabPage.Tag is GridControlEx && (tabPage.Tag as GridControlEx).ParentControl != null) (tabPage.Tag as GridControlEx).ParentControl.SetAllControlValue(rowItem); //配置明细直接根据条件加载 if (model.SystemModel != null && 1 == model.SystemModel.isFirstLoad) { (tabPage.Tag as GridControlEx).ParentControl.SearchGrid(); GridControlEx gridControlEx = tabPage.Tag as GridControlEx; if (gridControlEx.CustomGroupBandEx != null) { tabPage.Text = model.DetailName + "(" + gridControlEx.CustomGroupBandEx.DataRowCount() + QuantitySuffix; } else if (gridControlEx.CustomGroupTreeBandEx != null) { tabPage.Text = model.DetailName + "(" + gridControlEx.CustomGroupTreeBandEx.DataRowCount() + QuantitySuffix; } else { tabPage.Text = model.DetailName + "(" + (tabPage.Tag as GridControlEx).ParentControl.GridRowCount + QuantitySuffix; } //tabPage.Text = gridControlEx.CustomGroupBandEx != null ? model.DetailName + "(" + gridControlEx.CustomGroupBandEx.DataRowCount() + "条)" : model.DetailName + "(" + (tabPage.Tag as GridControlEx).ParentControl.GridRowCount + "条)"; //tabPage.Text = model.DetailName + "(" + (tabPage.Tag as GridControlEx).ParentControl.GridRowCount + "条)"; } //附加信息根据主表明细选中行,判断配置的按钮条件 Object moduleObject = tabPage.Controls.Cast().FirstOrDefault(); ModuleGridEx moduleGridEx = null; if (moduleObject is ModuleGridEx) { moduleGridEx = moduleObject as ModuleGridEx; moduleGridEx.ParentButtonState(rowItem); } } } } /// /// 说明:获取查询条件 /// 创建人:龚宇超 /// 创建日期: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 : BillModel.PrimaryKey; string sqlValue = model.IsReadOnly || model.IsChart ? model.DetailSql : model.SystemModel.MenuSql; string unioValue = string.Empty; unioValue = rowItem.Table.Columns.Contains(fieldName) ? rowItem[fieldName] + "" : string.Empty; if (this.ControlObj != null && string.IsNullOrEmpty(unioValue)) { unioValue = !string.IsNullOrEmpty(model.UnionParentField) && this.ControlObj.FindControl(model.UnionParentField) != null ? this.ControlObj.GetControlValue(model.UnionParentField) : unioValue; } sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, sqlValue); sqlValue = this.ControlObj.ReplaceControlValue(sqlValue);//后替换主表内容 if (ReplaceHelper.IsSelect(sqlValue) && !string.IsNullOrEmpty(model.UnionValue)) { sqlValue = ReplaceHelper.ReplaceWhereCond(sqlValue) + string.Format(" and {0}='{1}'", model.UnionValue, unioValue); } if (!string.IsNullOrEmpty(model.UnionCond)) { string UnionCond = ReplaceHelper.ReplaceRowParam(rowItem, model.UnionCond); sqlValue += UnionCond; } return sqlValue; } /// /// 说明:单据来源选中行,加载明细 /// 创建人:龚宇超 /// 创建日期:2019-07-25 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. private void OnTreeListObjFocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e) { XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel); } /// /// 说明:单据来源明细右键菜单执行后刷新数据 /// 创建人:龚宇超 /// 创建日期:2017-12-19 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void OnGridDetailRightMenuCallback(object sender, EventArgs e) { XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel); } /// /// 说明:分割条移动保存位置 /// 创建人:龚宇超 /// 创建日期:2018-03-06 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void OnMainSplitterMoved(object sender, EventArgs e) { if (this._isInitFinish) { IniHelper.Write(string.Format("bill_height_{0}", this.SysModel.ModuleCode), this.ssc_main.SplitterPosition + ""); } } /// /// 说明:明细分割条移动保存位置 /// 创建人:龚宇超 /// 创建日期:2018-03-06 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void OnDetailsSplitterMoved(object sender, EventArgs e) { if (this._isInitFinish) { SplitContainerControl splitContainerControl = sender as SplitContainerControl; IniHelper.Write(string.Format("bill_Details_Width_{0}", this.SysModel.ModuleCode), splitContainerControl.SplitterPosition + ""); } } /// /// 说明:单据来源查询之前处理 /// 创建人:龚宇超 /// 创建日期:2018-03-06 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The e. private void OnSearchBefore(object sender, SearchArgs e) { // 用户搜索时不加载右侧控件值,只有点击、人为选中行在加载右侧控件值. this._isLoadRightControlValue = false; XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel; if (!unionModel.SearchObj.VerifyNull()) { e.Continue = false; } } /// /// 说明:单据来源查询完成 /// 创建人:龚宇超 /// 创建日期:2018-03-06 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. /// private void OnSearchAfterd(object sender, EventArgs e) { this._isLoadRightControlValue = true; XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel; if (unionModel.ModelObj.SourceType == 1) { if (unionModel.TreeViewObj != null && unionModel.SearchObj.MainGridEx != null) { string sql = ReplaceHelper.ReplaceUserInfo(unionModel.SearchObj.MainGridEx.LastSearchSql); //和上一次查询sql相同就不再次查询了 if (!unionModel.SearchObj.MainGridEx.LastSearchSql.Equals(sql)) { unionModel.SearchObj.MainGridEx.SetGridViewDataSource(BaseImpl.GetDataTableResult(sql)); } } } else { if (unionModel.GridControlObj != null) { string sql = ReplaceHelper.ReplaceUserInfo(unionModel.GridControlObj.LastSearchSql); if (SubstringCount(sql, "#") > 1) { string fixedSql = sql.Substring(sql.IndexOf('#'), sql.LastIndexOf('#') + 1 - sql.IndexOf('#')); string billMainCode = sql.Substring(sql.IndexOf('#'), sql.LastIndexOf('#') + 1 - sql.IndexOf('#')).Replace("#", ""); var paramList = ReplaceHelper.GetParamFields(billMainCode); bool isCondReplace = true; foreach (string item in paramList) { string field = item.Replace("{", "").Replace("}", ""); if (ControlObj.FindControl(field) != null) { string value = ControlObj.GetControlValue(field); if (string.IsNullOrEmpty(value)) isCondReplace = false; billMainCode = billMainCode.Replace(item, value); } } if (!isCondReplace) { sql = sql.Replace(fixedSql, "1=1"); } else { sql = sql.Replace(fixedSql, billMainCode); } } int oldRowHandle = 0; if (unionModel.GridControlObj.GridView != null) { oldRowHandle = unionModel.GridControlObj.GridView.FocusedRowHandle; } //和上一次查询sql相同就不再次查询了 if (!unionModel.GridControlObj.LastSearchSql.Equals(sql)) { unionModel.GridControlObj.gridControl.DataSource = BaseImpl.GetDataTableResult(sql); unionModel.GridControlObj.GridView.SelectRowHandler(oldRowHandle); } //如果没有数据,显示 (0条) //(unionModel.ModelObj.SourceType == 0 || this.IsBillShowCount) && unionModel.SearchObj.GridRowCount > 0 if (unionModel.ModelObj.SourceType == 0 || this.IsBillShowCount) tabPage.Text = unionModel.ModelObj.UserName + "(" + unionModel.SearchObj.GridRowCount + QuantitySuffix; RefreshSourceDetail(unionModel); } } } /// /// 说明:判断字符串出现次数 /// 创建人:龚宇超 /// 创建日期: /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The string. /// The substring. /// System.Int32. private static int SubstringCount(string str, string substring) { if (str.Contains(substring)) { string strReplaced = str.Replace(substring, ""); return (str.Length - strReplaced.Length) / substring.Length; } return 0; } #endregion #region private void tb_buttom_Load(object sender, EventArgs e) { } #endregion /// /// 说明:检查可用条件 /// 创建人:龚宇超 /// 创建日期:2017-11-09 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The cond. /// The data row. /// true if XXXX, false otherwise. private bool ValidateCond(string cond, DataRow dataRow) { bool result = false; string condition = cond; try { if (string.IsNullOrWhiteSpace(cond)) return true;//如果值是空格或者空行,默认正确 cond = ReplaceHelper.ReplaceRowParam(dataRow, cond); if (cond.StartsWith("@") || cond.StartsWith("!")) { result = "1".Equals(BaseImpl.GetDefaultValue(cond)); } else if (dataRow == null) { result = ReplaceHelper.EvalCond(cond); } else { result = ReplaceHelper.ReplaceRowParamCond(dataRow, cond); } return result; } catch (Exception ex) { } return result; } /// /// 设置打印按钮条件 /// /// public bool SetPrintButton(DataRow rowItem) { try { bool result = false; //判断打印按钮条件 if (!string.IsNullOrWhiteSpace(this.BillModel.PrintingConditions)) { if (rowItem == null) return result; string cond = ReplaceHelper.ReplaceRowParam(rowItem, this.BillModel.PrintingConditions); if (cond.StartsWith("@") || cond.StartsWith("!")) { result = "1".Equals(BaseImpl.GetDefaultValue(cond)); } else { result = ReplaceHelper.ReplaceRowParamCond(rowItem, cond); } return result; } else { return true; } } catch (Exception ex) { return false; } } } }