using DevExpress.Utils.Menu; using DevExpress.XtraEditors; using DevExpress.XtraGrid.Columns; using DevExpress.XtraGrid.Menu; using DevExpress.XtraGrid.Views.Grid; using Lskj.Business; using Lskj.Business.Impl; using Lskj.Control.Model; using Lskj.Core; using Lskj.Data; using Lskj.Model; using Lskj.Util; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Lskj.Control.MultiModelLookUp { public partial class FrmRowsModelLookUp : BaseForm { #region 私有字段 /// /// 复选框字段名称 /// private string _checkFieldName = "frmRowsModelcheck"; /// /// The _id /// private string _id = "frmRowsModelid"; /// /// 左侧表格查询条件 /// private MyControl _leftGridSearchObj; /// /// 主表自定义查询条件 /// public MyControl SearchObj { get; private set; } /// /// 查询条件 /// private DataTable _queryTable = new DataTable(); #endregion #region 公有字段 /// /// 数据源 /// /// The data source. public DataTable DataSource { get { return this.gcMain.gridControl.DataSourceTable(); } set { DataTable sourceTab = value; if (sourceTab != null && !sourceTab.Columns.Contains(_checkFieldName)) { sourceTab.Columns.Add(_checkFieldName, typeof(bool)); sourceTab.Columns.Add(_id, typeof(int)); for (int i = 0; i < sourceTab.Rows.Count; i++) { sourceTab.Rows[i][_checkFieldName] = 0; sourceTab.Rows[i][_id] = i; } } this.gcMain.gridControl.DataSource = sourceTab; } } /// /// 控件类型 /// /// The type. public int IsType { get; set; } /// /// 绑定ValueMember /// public string ValueMember { get; set; } /// /// 隐藏值字段 /// public string ValueField { get; set; } /// /// 显示值字段 /// public string TextField { get; set; } /// /// 备注字段 /// public string RemarkField = "remark"; /// /// 数据源 /// /// The source SQL. public string SourceSQL { get; set; } /// /// 隐藏值 /// /// The edit value. public string EditValue { get; set; } /// /// 筛选列 /// public string selectField { get; set; } /// /// 显示值 /// /// The edit text. public string EditText { get; set; } /// /// 选中行值 /// public DataRow selectRowsEditValue { get; set; } /// /// CurrentOperColumnKey值 /// /// The data source. public string CurrentOperColumnKey = string.Empty; /// /// CurrentOperModel值 /// /// The data source. public GridColumnModel CurrentOperModel = null; /// /// 配置的关联ModuleCodel值 /// /// The Union ModuleCodel. public string UnionModuleCodel; /// /// 配置的关联列model类型 /// /// The Union ModuleCodel. public GridColumnModel gridColumnModel; /// /// 左侧树数据 /// public DataRow LeftRowObj; /// /// 系统模块实体对象 /// /// The system model. public ModuleModel SysModel { get; private set; } /// /// 分割条位置 /// public int PositionSplitter; /// /// 分割条位置 /// public int WindowHeight; #endregion public FrmRowsModelLookUp() { InitializeComponent(); this.Disposed += new EventHandler(OnFrmModelLookUp_Disposed); this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.OnFormClosing); this.gcMain.GridControl.ContextMenuStrip = contextMenuStrip1; this.gcMain.GridView.OptionsBehavior.EditorShowMode = DevExpress.Utils.EditorShowMode.MouseDown; //this.ModuleGridObj.GridControlObj.GridView.PopupMenuShowing += new DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventHandler(this.OnGridViewPopupMenuShowing); this.gcMain.GridView.RowCellClick += new RowCellClickEventHandler(OnRowCellClick); //this.gcMain.gridControl.DataSourceChanged += new EventHandler(OnGridControl_DataSourceChanged); this.btnFixSearch.Click += new EventHandler(OnFixButtonClick); InitControls(); } #region 方法 #region 设置分割条位置 /// /// 说明:设置分割条位置 /// 创建人:王一帆 /// 创建日期:2021-07-21 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// protected void InitlizeSpiltLocation() { try { string width = IniHelper.Read(string.Format("base_width_{0}", this.UnionModuleCodel));//通过Key获取Value值 if (!string.IsNullOrEmpty(width)) { this.splitMain.SplitterPosition = Convert.ToInt32(width); } } catch (Exception ex) { LogHelper.Instance.WriteError(ex); MessageUtil.Show(ex); } } #endregion #region 保存表格属性 /// /// 说明:保存表格属性 /// 创建人:王一帆 /// 创建日期:2021-07-20 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. protected virtual void SaveItemClick(object sender, EventArgs e) { DataRow rowItem = null; bool success = BaseImpl.HasExistsDataRow(ResourceKeys.SettingTableName, "formKey", CurrentOperColumnKey, string.Format(" and OperatorId='{0}' ", ERPInfo.Instance.UserId), out rowItem); if (!success) { MessageUtil.Show(ResourceKeys.NotFoundSettingColumnTable); return; } if (MessageUtil.Show(ResourceKeys.IsSaveColumn, MessageBoxButtons.YesNo) == DialogResult.Yes) { try { if (rowItem == null) { success = this.gcMain.GridView.SaveCustomColumnToDatabase(this.CurrentOperColumnKey); } else { success = this.gcMain.GridView.UpdateCustomColumnToDatabase(this.CurrentOperColumnKey); } MessageUtil.Show(success ? ResourceKeys.SaveSuccess : ResourceKeys.SaveFault); } catch (SqlException sex) { if (sex.Message.Contains(ResourceKeys.FieldLenIsShort) && MessageUtil.Show(ResourceKeys.SaveFault + "\r\n" + ResourceKeys.CanUpgradeTable, MessageBoxButtons.YesNo) == DialogResult.Yes && BaseImpl.UpdateTableField(ResourceKeys.SettingTableName, "formKey", "varchar(200)")) { MessageUtil.Show(ResourceKeys.UpdateSuccess); } } catch (Exception ex) { LogHelper.Instance.WriteError(ex); LogUtil.WriteError("保存表格属性出错", ex); MessageUtil.Show(ex); } } } #endregion #region 重置表格属性 /// /// 说明:重置表格属性 /// 创建人:王一帆 /// 创建日期:2021-07-20 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. protected virtual void ResetItemClick(object sender, EventArgs e) { if (!BaseImpl.HasExistsTable(ResourceKeys.SettingTableName)) { MessageUtil.Show(ResourceKeys.NotFoundSettingColumnTable); return; } if (MessageUtil.Show(ResourceKeys.IsResetColumn, MessageBoxButtons.YesNo) == DialogResult.Yes) { bool success = this.gcMain.GridView.ResetCustomColumnToDatabase(CurrentOperColumnKey); this.SetReadOnlyColumns(); MessageUtil.Show(success ? ResourceKeys.ResetSuccess : ResourceKeys.ResetFault); } } #endregion #region 设置默认选中 /// /// 说明:设置默认选中 /// 创建人:龚宇超 /// 创建日期:2018-03-20 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void SetDefaultValue() { if (!string.IsNullOrEmpty(EditValue) && this.IsType == ControlType.LabSelectReturnId) { //this.UpdateChecked(EditValue.Trim().Replace(", ", ",").TrimEnd(',').Split(','), ValueMember, true); this.UpdateChecked(EditValue.Trim().Replace(", ", ",").TrimEnd(',').Split(','), selectField, true); } else { if (!string.IsNullOrEmpty(EditText)) { //this.UpdateChecked(EditText.Trim().Replace(", ", ",").TrimEnd(',').Split(','), TextField, false); this.UpdateChecked(EditText.Trim().Replace(", ", ",").TrimEnd(',').Split(','), selectField, false); } } } #endregion #region 设置只读列 /// /// 说明:设置只读列 /// 创建人:王一帆 /// 创建日期:2021-07-20 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void SetReadOnlyColumns() { this.gcMain.GridView.Columns.Clear(); //if (this.DataSource != null && !this.DataSource.Columns.Contains(_checkFieldName)) //{ // this.DataSource.Columns.Add(_checkFieldName, typeof(bool)); // this.DataSource.Columns.Add(_id, typeof(int)); // for (int i = 0; i < DataSource.Rows.Count; i++) // { // DataSource.Rows[i][_checkFieldName] = 0; // DataSource.Rows[i][_id] = i; // } //} GridColumn checkColumn = new GridColumn(); checkColumn.Name = checkColumn.FieldName = this._checkFieldName; checkColumn.Caption = "选"; checkColumn.Width = 30; checkColumn.Visible = true; checkColumn.OptionsColumn.AllowEdit = false; //GridColumn valueColumn = new GridColumn(); //valueColumn.FieldName = valueColumn.Name = ValueField; //valueColumn.Caption = "编码"; //valueColumn.Width = 200; ////valueColumn.Visible = true; //valueColumn.Visible = ValueMember.Substring(0, 1) != "_"; //valueColumn.OptionsColumn.AllowEdit = false; //GridColumn textColumn = new GridColumn(); //textColumn.FieldName = textColumn.Name = TextField; //textColumn.Caption = "名称"; //textColumn.Width = 350; ////textColumn.Visible = true; //textColumn.Visible = TextField.Substring(0, 1) != "_"; //textColumn.OptionsColumn.AllowEdit = false; //this.gcMain.Columns.AddRange(new GridColumn[] { checkColumn, valueColumn, textColumn }); //this.gcDetail.Columns.AddRange(new GridColumn[] { checkColumn, valueColumn, textColumn }); this.gcMain.GridView.Columns.AddRange(new GridColumn[] { checkColumn }); //if (DataSource.Columns.IndexOf("remark") != -1) //{ // DataColumn column = DataSource.Columns.Cast().FirstOrDefault(x => x.ColumnName.ToLower() == RemarkField); // if (column != null) RemarkField = column.ColumnName; // GridColumn remarkColumn = new GridColumn(); // remarkColumn.Name = remarkColumn.FieldName = RemarkField; // remarkColumn.Caption = "备注"; // remarkColumn.Visible = true; // remarkColumn.Width = 120; // //字段第一个字符为下划线代表不显示 // if (RemarkField.Substring(0, 1) == "_") // remarkColumn.Visible = false; // this.gcMain.Columns.Add(remarkColumn); // this.gcDetail.Columns.Add(remarkColumn); //} //DataTable DT = gridControl1.DataSource == null ? new DataTable() : gridControl1.DataSource as DataTable; //foreach (DataColumn dcol in DT.Columns) //{ // if ((dcol.ColumnName.Substring(0, 1) != "_") && (dcol.ColumnName.ToLower() != ValueField.ToLower()) && (dcol.ColumnName.ToLower() != TextField.ToLower()) && ((int)dcol.ColumnName[0] > 127)) // { // GridColumn otherColumn = new GridColumn(); // otherColumn.Name = otherColumn.FieldName = otherColumn.Caption = dcol.ColumnName; // otherColumn.Visible = true; // otherColumn.Width = 150; // this.gcMain.Columns.Add(otherColumn); // this.gcDetail.Columns.Add(otherColumn); // } //} if (gridColumnModel != null && !string.IsNullOrEmpty(gridColumnModel.SqlSource)) { DataTable dataTable = SqlHelper.ExecuteDataTable(this.SourceSQL); if (dataTable != null) { foreach (DataColumn col in dataTable.Columns) { GridColumn otherColumn = new GridColumn(); otherColumn.Name = otherColumn.FieldName = col.ColumnName; otherColumn.Caption = col.ColumnName; otherColumn.Visible = true; otherColumn.Width = 150; otherColumn.OptionsColumn.AllowEdit = false; this.gcMain.GridView.Columns.Add(otherColumn); } } } else if (!string.IsNullOrEmpty(UnionModuleCodel)) { DataTable colunmsTab = BaseModuleImpl.GetBaseGridColumns(UnionModuleCodel); if (colunmsTab != null && colunmsTab.Rows.Count > 0) { foreach (DataRow row in colunmsTab.Rows) { GridColumnModel gridColumnModel = new GridColumnModel(row); GridColumn otherColumn = new GridColumn(); otherColumn.Name = otherColumn.FieldName = gridColumnModel.FieldName; otherColumn.Caption = gridColumnModel.FieldText; otherColumn.Visible = true; otherColumn.Width = 150; otherColumn.OptionsColumn.AllowEdit = false; this.gcMain.GridView.Columns.Add(otherColumn); } } } SetCustomColumns(); //this.gcDetail.SelectAll(); //this.gcDetail.DeleteSelectedRows(); } #endregion #region 加载自定义列 /// /// 说明:加载自定义列 /// 创建人:王一帆 /// 创建日期:2019-9-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void SetCustomColumns() { if (string.IsNullOrEmpty(this.CurrentOperColumnKey) || !BaseImpl.HasExistsTable(ResourceKeys.SettingTableName)) return; DataTable customTable = this.gcMain.GridView.GetCustomColumnByDatabase(this.CurrentOperColumnKey); if (customTable != null && customTable.Rows.Count > 0) { foreach (DataRow rowItem in customTable.Rows) { string fieldName = rowItem["fieldName"] + ""; int fieldWidth = Convert.ToInt32(rowItem["fieldWidth"]); int index = Convert.ToInt32(rowItem["orderid"]); bool visible = "1".Equals(rowItem["isVisible"] + "") && fieldWidth > 0; bool isFix = "True".Equals(rowItem["IfFixColumn"] + "", StringComparison.OrdinalIgnoreCase); GridColumn gridColumn = this.gcMain.GridView.Columns.ColumnByName(fieldName); if (gridColumn != null && gridColumn.Visible && gridColumn.Width > 0) { GridColumn colObj = this.gcMain.GridView.Columns[fieldName]; colObj.VisibleIndex = index; colObj.Width = fieldWidth; colObj.Visible = visible; colObj.Fixed = isFix ? FixedStyle.Left : FixedStyle.None; } } } } #endregion #region 获取选中行数据 /// /// 说明:获取选中行数据 /// 创建人:王一帆 /// 创建日期:2021-07-20 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// DataRow[]. public DataRow[] GetViewFocusedDataRows(GridView gridView) { int[] rows = gridView.GetSelectedRows(); DataRow[] dataRows = new DataRow[rows.Length]; for (int i = 0; i < rows.Length; i++) { dataRows[i] = gridView.GetDataRow(rows[i]); } return dataRows; } #endregion #region 刷新左侧树数据 /// /// 说明:设置左侧树数据 /// 创建人:王一帆 /// 创建日期:2021-07-21 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// protected void SetLeftTreeView() { this.LeftRowObj = BaseModuleImpl.GetBaseLeftTreeField(this.UnionModuleCodel);//获取表格左侧树字段 if (this.LeftRowObj != null) { //this.ModuleGridObj.ParentUnionField = this.LeftRowObj["fieldname"] + ""; this.treeLeft.TreeNodeKeyField = this.LeftRowObj["fieldsqlid"] + ""; this.treeLeft.TreeNodeTextField = this.LeftRowObj["fieldsqlname"] + ""; this.treeLeft.TreeNodeSelectAfter += new TreeViewEventHandler(OnTreeLeftTreeNodeSelected); this.treeLeft.BindTreeView(BaseImpl.GetDataTableResult(this.LeftRowObj["fieldsql"] + "")); } else { // 根据模块上配置的sql加载树 if (this.SysModel != null && !string.IsNullOrEmpty(this.SysModel.TreeSQL)) { this.treeLeft.TreeNodeKeyField = "SpeciesNo"; this.treeLeft.TreeNodeTextField = "SpeciesName"; this.treeLeft.TreeNodeSelectAfter += new TreeViewEventHandler(OnTreeLeftTreeNodeSelected); this.treeLeft.BindTreeView(BaseImpl.GetDataTableResult(this.SysModel.TreeSQL)); } } } /// /// 说明:树节点点击后刷新数据 /// 创建人:龚宇超 /// 创建日期:2017-10-26 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnTreeLeftTreeNodeSelected(object sender, TreeViewEventArgs e) { string where = string.Format(" and {0} like '{1}%' ", this.treeLeft.TreeNodeKeyField, e.Node.Name); this.SetMainGridView(where); //if (this.IsDragDetail) // this.SetDetailGridView(where); //if (this.OnLeftTreeViewRowClickCallBack != null) // this.OnLeftTreeViewRowClickCallBack(treeLeft, e); string sqlValue = ReplaceHelper.IsProcedure(SourceSQL) ? ReplaceHelper.ReplaceTreeViewParentKeyCond(SourceSQL, treeLeft.GetSelectNodeValue()) : SourceSQL + where; this.DataSource = MainImpl.GetDataTableResult(sqlValue); this.SetReadOnlyColumns(); this.SetDefaultValue(); } /// /// 说明:加载主表格数据 /// 创建人:龚宇超 /// 创建日期:2018-01-31 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The where key. protected void SetMainGridView(string where = "") { //string sqlValue = ReplaceHelper.ReplaceWhereCond(this.SysModel.MenuSql); //sqlValue = this.SysModel.MenuSql.StartsWith("select", StringComparison.OrdinalIgnoreCase) ? sqlValue + where : sqlValue; //if (IsExcel && !string.IsNullOrEmpty(this._labPicName)) //{ // string sql = MainImpl.GetDefaultValue(sqlValue, this.ModuleGridObj.ParentKeyField, Model.OtherParams()); // DataTable dt = MainImpl.GetDataTableResult(ReplaceLeftOrGridValue(sql)); // if (dt.Rows.Count > 0) // { // this._currentRow = dt.Rows[0]; // Byte[] file = (byte[])this._currentRow[this._labPicName]; // if (file.Length <= 0) // { // this.excelControlEx1.SpreadSheetBarObj.Control.CreateNewDocument(); // } // else // { // if (!string.IsNullOrEmpty(this.excelControlEx1.CurrentPath) && File.Exists(this.excelControlEx1.CurrentPath)) // { // File.Delete(this.excelControlEx1.CurrentPath); // } // this.excelControlEx1.LoadFileSteam(file); // } // } // else // { // this.excelControlEx1.SpreadSheetBarObj.Control.CreateNewDocument(); // MessageUtil.Show(ResourceKeys.NotConfigExcel); // } //} //else //{ // // 左侧gridView时,需要替换sql参数(包含查询条件、表格选中行). // if (this.gridLeft.Visible) // { // sqlValue = this._leftGridSearchObj != null ? this._leftGridSearchObj.ReplaceParentControlValue(sqlValue) : sqlValue; // sqlValue = ReplaceHelper.ReplaceRowParam(this.gridLeft.GridView.GetFocusedDataRow(), sqlValue); // } // this.ModuleGridObj.SearchObj.SearchGrid(sqlValue); // if (!this.IsDragDetail) // this.ModuleGridDetailObj.SetDetailGridDataSource(); //} } #endregion #region 创建界面 /// /// 说明:初始化查询条件(查询条件不自动查询) /// 创建人:龚宇超 /// 创建日期:2017-09-05 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void InitializeQueryCondition() { if (this.SysModel != null) { bool fixedQuery = _queryTable == null || _queryTable.Rows.Count == 0; //替换sql语句中的bmp字段 this.SearchObj = new MyControl(this.SysModel.MenuSql, gcMain, treeLeft.Visible ? treeLeft : null, gridLeft, _leftGridSearchObj); //if (this._leftGridField != null) //{ // this.SearchObj.ParentKey = this._parentKey = this._leftGridField["fieldname"] + ""; //} //this.SearchObj.ModuleId = SysModel.ModuleId; //this.SearchObj.ParentKeyField = this.ParentKeyField; //this.SearchObj.ParentUnionField = this.ParentUnionField; //this.SearchObj.OnSearchBeforeCallBack += new SearchEventHandler(OnSearchBeforeCallBack); // 查询条件执行前 this.SearchObj.OnSearchAfterCallBack += new EventHandler(OnSearchAfterCallBack); // 明细表格默认不查询 //this.SearchObj.OnDataSourceBindCallBack += new EventHandler(OnMainSearchDataSourceBindCallBack); // 数据源绑定完成触发 //if (!string.IsNullOrEmpty(ParentKeyValue) && !string.IsNullOrEmpty(DetailKeyField)) // this.SearchObj.WhereCond = string.Format(" and {0}='{1}'", DetailKeyField, ParentKeyValue); } if (gridColumnModel != null) { bool isFixlayout = string.IsNullOrEmpty(gridColumnModel.TextMember) ? string.IsNullOrEmpty(gridColumnModel.ValueMember) : true; if (isFixlayout && !string.IsNullOrEmpty(gridColumnModel.SqlSource))//点击判断dm或mc存在 { int left = 10; this.pl_top_fix_search.Visible = true; if (!string.IsNullOrEmpty(gridColumnModel.ValueMember)) { this.labDm.Left = left; string[] condSplit = gridColumnModel.ValueMember.Split('^'); if (condSplit.Count() > 1) { this.labDm.Tag = condSplit[0]; this.labDm.LabelText = condSplit[1]; this.labDm.EditText = ""; this.labDm.Visible = true; left = this.labDm.Right + 10; } if (condSplit.Count() == 1) { this.labDm.Tag = condSplit[0]; this.labDm.LabelText = "编码"; this.labDm.EditText = ""; this.labDm.Visible = true; left = this.labDm.Right + 10; } } if (!string.IsNullOrEmpty(gridColumnModel.TextMember)) { this.labMc.Left = left; string[] condSplit = gridColumnModel.TextMember.Split('^'); if (condSplit.Count() > 1) { this.labMc.Tag = condSplit[0]; this.labMc.LabelText = condSplit[1]; this.labMc.EditText = ""; this.labMc.Visible = true; left = this.labMc.Right + 10; } if (condSplit.Count() == 1) { this.labMc.Tag = condSplit[0]; this.labMc.LabelText = "名称"; this.labMc.EditText = ""; this.labMc.Visible = true; left = this.labMc.Right + 10; } } this.btnFixSearch.Left = left; } else { // 加载配置查询条件 this.pl_top_fix_search.Visible = false; //this.SearchObj.OtherParams = Model.OtherParams(); this.pl_main_top.Height = this.SearchObj.InitSearchControl(_queryTable, this.pl_main_top); if (!string.IsNullOrEmpty(gridColumnModel.SqlSource)) { this.DataSource = BaseImpl.GetDataTableResult(SourceSQL); } else { this.SearchObj.OnDataSourceBindCallBack -= new EventHandler(OnMainSearchDataSourceBindCallBack); this.SearchObj.OnDataSourceBindCallBack += new EventHandler(OnMainSearchDataSourceBindCallBack);// 数据源绑定完成触发 } } } } /// /// 说明:查询条件绑定完成查询数据 /// 创建人:龚宇超 /// 创建日期: /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. protected void OnMainSearchDataSourceBindCallBack(object sender, EventArgs e) { try { if (!string.IsNullOrEmpty(this.SysModel.CustomColumnSQL)) { BaseImpl.ExecSqlValue(this.SearchObj.ReplaceControlValue(this.SysModel.CustomColumnSQL)); } this.SearchObj.SyncLocalModel(); this.SearchObj.SearchGrid(); DataTable sourceTab = this.gcMain.gridControl.DataSourceTable(); if (sourceTab != null && !sourceTab.Columns.Contains(_checkFieldName)) { sourceTab.Columns.Add(_checkFieldName, typeof(bool)); sourceTab.Columns.Add(_id, typeof(int)); for (int i = 0; i < sourceTab.Rows.Count; i++) { sourceTab.Rows[i][_checkFieldName] = 0; sourceTab.Rows[i][_id] = i; } } this.gcMain.gridControl.DataSource = sourceTab; //if (!IsDetail) //{ // DynamicReportModel reportModel = this.Model as DynamicReportModel; // if (this.SysModel.CsHasDefultSearch || (reportModel != null && reportModel.AutoQuery)) // { // this.SearchObj.SearchGrid(); // } //} } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:默认按照dm mc 加载数据 /// 创建人:王一帆 /// 创建日期:2022-10-05 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnFixButtonClick(object sender, EventArgs e) { StringBuilder strWhere = new StringBuilder(); if (this.labDm.Visible) { string field = this.labDm.Tag + ""; string fieldText = this.labDm.EditText; strWhere.Append(string.Format(" and (dbo.P_getpy('{0}') like '%{1}%' or {0} like '%{1}%')", field, fieldText)); } if (this.labMc.Visible) { string field = this.labMc.Tag + ""; string fieldText = this.labMc.EditText; strWhere.Append(string.Format(" and (dbo.P_getpy('{0}') like '%{1}%' or {0} like '%{1}%')", field, fieldText)); } string sqlValue = ReplaceHelper.ReplaceWhereCond(this.SourceSQL) + strWhere.ToString(); //this.gcMain.SetGridViewDataSource(MainImpl.GetAdapterResult(sqlValue)); this.DataSource = BaseImpl.GetDataTableResult(sqlValue); } /// /// 说明:搜索之后 /// 创建人:龚宇超 /// 创建日期:2019-05-21 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The e. protected void OnSearchAfterCallBack(object sender, EventArgs e) { WaitForm.ShowForm(); try { DataTable sourceTab = this.gcMain.gridControl.DataSourceTable(); if (sourceTab != null && !sourceTab.Columns.Contains(_checkFieldName)) { sourceTab.Columns.Add(_checkFieldName, typeof(bool)); sourceTab.Columns.Add(_id, typeof(int)); for (int i = 0; i < sourceTab.Rows.Count; i++) { sourceTab.Rows[i][_checkFieldName] = 0; sourceTab.Rows[i][_id] = i; } } this.gcMain.GridView.BeginUpdate(); this.gcMain.gridControl.DataSource = sourceTab; this.gcMain.GridView.EndUpdate(); } catch (Exception) { } finally { WaitForm.HideForm(); } } /// /// 说明:创建界面 /// 创建人:王一帆 /// 创建日期:2021-07-21 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The menu code. public void InitControls() { this.SetReadOnlyColumns(); //this.SetDefaultValue(); //this.gcDetail.Columns["_check"].Visible = false; //设置列为不显示 //this.gcMain.Columns["_check"].Visible = false; //设置列为不显示 this.gcMain.GridView.OptionsView.ColumnAutoWidth = true; WindowHeight = this.Height; if (gridColumnModel != null && !string.IsNullOrEmpty(gridColumnModel.SqlSource)) { this.splitMain.PanelVisibility = SplitPanelVisibility.Panel2; } else if (!string.IsNullOrEmpty(UnionModuleCodel)) { DataRow modelRow = MainImpl.GetSystemdllTab(UnionModuleCodel);//获取单个模块信息 if (modelRow == null) { MessageUtil.Show("模块编号[" + UnionModuleCodel + "],配置错误!\r\n该模块信息未找到!"); return; } this.SysModel = new ModuleModel(modelRow);// 系统模块实体对象 this._queryTable = BaseModuleImpl.GetCustomQueryFields(this.SysModel.CondKey);//加载自定义配置字段 switch (this.SysModel.MenuType) { case 1: // 左侧为树节点 this.pl_left_top.Visible = false; this.gridLeft.Visible = false; this.treeLeft.Visible = true; this.InitlizeSpiltLocation();//设置分割条位置 this.SetLeftTreeView();//设置左侧树数据 break; case 2: // 左侧为表格 this.gridLeft.Visible = true; this.treeLeft.Visible = false; this.InitlizeSpiltLocation(); this.SetLeftGridView(); //this.ModuleGridObj.SaveEvent += new Lskj.Control.ModuleGridEx.SaveEventHander(SetDetailGridView); break; case 3: // 左侧为空 default: this.splitMain.PanelVisibility = SplitPanelVisibility.Panel2; break; } DataTable _gridColumns = BaseModuleImpl.GetBaseGridColumns(UnionModuleCodel); this.gcMain.SetReadOnlyColumns(_gridColumns, GridCustomColumnStruct.BaseMainGridView + this.SysModel.FormKey); GridColumn checkColumn = new GridColumn(); checkColumn.Name = checkColumn.FieldName = _checkFieldName; checkColumn.Caption = "选"; checkColumn.Width = 30; checkColumn.Visible = true; checkColumn.VisibleIndex = 0; checkColumn.OptionsColumn.AllowEdit = false; gcMain.GridView.Columns.Insert(0, checkColumn); } InitializeQueryCondition(); } #endregion #region 设置左侧表格数据 /// /// 说明:设置左侧表格数据 /// 创建人:龚宇超 /// 创建日期:2017-10-25 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// protected void SetLeftGridView() { this.LeftRowObj = BaseModuleImpl.GetBaseLeftTreeField(UnionModuleCodel);//获取表格左侧树字段 if (this.LeftRowObj != null) { //this.ModuleGridObj.ParentKeyField = this.LeftRowObj["fieldsqlid"] + ""; //this.ModuleGridObj.ParentUnionField = this.LeftRowObj["fieldname"] + ""; //this.ModuleGridObj.LeftGridEx = this.gridLeft; //this.ModuleGridObj.ParentGridEx = this.gridLeft; // 方便右侧添加数据自动带出相同字段值 DataTable dtTable = BaseModuleImpl.GetBaseLeftGridField(UnionModuleCodel); DataTable dtColorTable = BaseModuleImpl.GetBaseGridRowColors(this.LeftRowObj["fieldKey"] + ""); this.gridLeft.GridView.RowClick += new DevExpress.XtraGrid.Views.Grid.RowClickEventHandler(OnGridViewRowClick); this.gridLeft.SetGridRowColors(dtColorTable); this.gridLeft.SetReadOnlyColumns(dtTable, GridCustomColumnStruct.BaseLeftGridView + UnionModuleCodel); DataTable table = BaseModuleImpl.GetCustomQueryFields(LeftRowObj["fieldKey"] + ""); string searchSql = LeftRowObj["fieldsql"] + ""; if (table != null && table.Rows.Count > 0) { // 自定义查询条件 this._leftGridSearchObj = new MyControl(searchSql, this.gridLeft); this.pl_left_top.Height = this._leftGridSearchObj.InitSearchControl(table, this.pl_left_top); this._leftGridSearchObj.OnDataSourceBindCallBack += new EventHandler(OnLeftControlObjDataSourceBindCallBack); } } } /// /// 说明:数据绑定完成后加载数据 /// 创建人:王一帆 /// 创建日期: /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnLeftControlObjDataSourceBindCallBack(object sender, EventArgs e) { try { this._leftGridSearchObj.SearchGrid(); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } #endregion #region 更新选中状态 /// /// 说明:更新选中状态 /// 创建人:龚宇超 /// 创建日期:2018-03-20 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The spilts. /// Name of the field. /// if set to true [check]. private void UpdateChecked(string[] spilts, string fieldName, bool isValue, bool check = true) { if (spilts == null || spilts.Length == 0 || string.IsNullOrEmpty(fieldName) || this.DataSource == null || this.DataSource.Rows.Count == 0) return; for (int i = 0; i < spilts.Length; i++) { //DataRow rowItem = rowItem = this.DataSource.Rows.Cast().FirstOrDefault(x => x[isValue ? ValueMember : TextField] + "" == spilts[i].Trim DataRow rowItem = rowItem = this.DataSource.Rows.Cast().FirstOrDefault(x => x[fieldName] + "" == spilts[i].Trim()); if (rowItem != null) { rowItem[_checkFieldName] = check; rowItem.AcceptChanges(); } } } #endregion #region 刷新右侧表格数据 /// /// 说明:刷新右侧表格数据 /// 创建人:龚宇超 /// 创建日期:2018-03-19 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnGridViewRowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e) { try { this.SetMainGridView(); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } #endregion #endregion #region 事件 #region 选中行 /// /// 说明:选中行 /// 创建人:王一帆 /// 创建日期:2021-07-20 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void OnRowCellClick(object sender, RowCellClickEventArgs e) { DataRow rowItem = this.gcMain.GetViewFocusedDataRow(); if (rowItem != null && e.Column.FieldName == _checkFieldName) { rowItem[_checkFieldName] = "True".Equals(rowItem[_checkFieldName] + "") ? 0 : 1; //rowItem[_checkFieldName] = rowItem.Table.Columns.Contains(_checkFieldName) : "True".Equals(rowItem[_checkFieldName] + "") ? 0 : 1 ? 0; rowItem.AcceptChanges(); this.btnOk_Click(sender, e); } } #endregion #region 关闭时清空唯一键 /// /// 说明:关闭时清空唯一键 /// 创建人:王一帆 /// 创建日期:2021-07-20 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void OnFormClosing(object sender, FormClosingEventArgs e) { CurrentOperColumnKey = ""; CurrentOperModel = null; } #endregion #region 确定 /// /// 说明:确定 /// 创建人:龚宇超 /// 创建日期:2018-03-20 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void btnOk_Click(object sender, EventArgs e) { //this.EditValue = string.Empty; //this.EditText = string.Empty; DataRow[] rowItems = this.DataSource.Select(_checkFieldName + "=True"); this.selectRowsEditValue = this.DataSource.NewRow(); foreach (DataRow item in rowItems) { //this.EditValue += item[ValueMember] + ","; //this.EditText += item[TextField] + ","; foreach (DataColumn col in item.Table.Columns) { if (col.ColumnName.Equals(_checkFieldName) || col.ColumnName.Equals(_id)) continue; if (!string.IsNullOrEmpty(this.selectRowsEditValue[col.ColumnName] + "")) { this.selectRowsEditValue[col.ColumnName] = this.selectRowsEditValue[col.ColumnName] + "" + item[col.ColumnName] + "" + ","; } else { this.selectRowsEditValue[col.ColumnName] = item[col.ColumnName] + "" + ","; } } } foreach (DataColumn col in this.selectRowsEditValue.Table.Columns) { if (col.ColumnName.Equals(_checkFieldName) || col.ColumnName.Equals(_id)) continue; this.selectRowsEditValue[col] = (this.selectRowsEditValue[col] + "").Trim(','); } //this.EditValue = this.EditValue.Trim(','); //this.EditText = this.EditText.Trim(','); this.DialogResult = DialogResult.OK; this.Close(); } #endregion #region 取消 /// /// 说明:取消 /// 创建人:龚宇超 /// 创建日期:2018-03-20 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void btnCancel_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; } #endregion #region 取消全选 /// /// 取消全选 /// /// /// private void btn_cancelAll_Click(object sender, EventArgs e) { DataTabl