ab56a9bcf7
SVN-Revision: r240
898 lines
37 KiB
C#
898 lines
37 KiB
C#
using DevExpress.XtraEditors;
|
|
using DevExpress.XtraGrid.Columns;
|
|
using DevExpress.XtraGrid.Views.Grid;
|
|
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
|
|
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.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 FrmRowsModelLookUpNew : BaseForm
|
|
{
|
|
#region 私有字段
|
|
/// <summary>
|
|
/// The _id
|
|
/// </summary>
|
|
private string _id = "frmRowsModelid";
|
|
/// <summary>
|
|
/// 左侧表格查询条件
|
|
/// </summary>
|
|
private MyControl _leftGridSearchObj;
|
|
/// <summary>
|
|
/// 主表自定义查询条件
|
|
/// </summary>
|
|
public MyControl SearchObj { get; private set; }
|
|
/// <summary>
|
|
/// 查询条件
|
|
/// </summary>
|
|
private DataTable _queryTable = new DataTable();
|
|
#endregion
|
|
#region 公有字段
|
|
/// <summary>
|
|
/// 数据源
|
|
/// </summary>
|
|
/// <value>The data source.</value>
|
|
public DataTable DataSource
|
|
{
|
|
get
|
|
{
|
|
return this.gcMain.gridControl.DataSourceTable();
|
|
}
|
|
set
|
|
{
|
|
DataTable sourceTab = value;
|
|
if (sourceTab != null && !sourceTab.Columns.Contains(_id))
|
|
{
|
|
sourceTab.Columns.Add(_id, typeof(int));
|
|
for (int i = 0; i < sourceTab.Rows.Count; i++)
|
|
{
|
|
sourceTab.Rows[i][_id] = i;
|
|
}
|
|
}
|
|
this.gcMain.gridControl.DataSource = sourceTab;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 控件类型
|
|
/// </summary>
|
|
/// <value>The type.</value>
|
|
public int IsType { get; set; }
|
|
/// <summary>
|
|
/// 绑定ValueMember
|
|
/// </summary>
|
|
public string ValueMember { get; set; }
|
|
/// <summary>
|
|
/// 隐藏值字段
|
|
/// </summary>
|
|
public string ValueField { get; set; }
|
|
/// <summary>
|
|
/// 显示值字段
|
|
/// </summary>
|
|
public string TextField { get; set; }
|
|
/// <summary>
|
|
/// 备注字段
|
|
/// </summary>
|
|
public string RemarkField = "remark";
|
|
/// <summary>
|
|
/// 数据源
|
|
/// </summary>
|
|
/// <value>The source SQL.</value>
|
|
public string SourceSQL { get; set; }
|
|
/// <summary>
|
|
/// 隐藏值
|
|
/// </summary>
|
|
/// <value>The edit value.</value>
|
|
public string EditValue { get; set; }
|
|
/// <summary>
|
|
/// 筛选列
|
|
/// </summary>
|
|
public string selectField { get; set; }
|
|
/// <summary>
|
|
/// 显示值
|
|
/// </summary>
|
|
/// <value>The edit text.</value>
|
|
public string EditText { get; set; }
|
|
/// <summary>
|
|
/// 选中行值
|
|
/// </summary>
|
|
public DataRow selectRowsEditValue { get; set; }
|
|
/// <summary>
|
|
/// CurrentOperColumnKey值
|
|
/// </summary>
|
|
/// <value>The data source.</value>
|
|
public string CurrentOperColumnKey = string.Empty;
|
|
/// <summary>
|
|
/// CurrentOperModel值
|
|
/// </summary>
|
|
/// <value>The data source.</value>
|
|
public GridColumnModel CurrentOperModel = null;
|
|
/// <summary>
|
|
/// 配置的关联ModuleCodel值
|
|
/// </summary>
|
|
/// <value>The Union ModuleCodel.</value>
|
|
public string UnionModuleCodel;
|
|
/// <summary>
|
|
/// 配置的关联列model类型
|
|
/// </summary>
|
|
/// <value>The Union ModuleCodel.</value>
|
|
public GridColumnModel gridColumnModel;
|
|
/// <summary>
|
|
/// 左侧树数据
|
|
/// </summary>
|
|
public DataRow LeftRowObj;
|
|
/// <summary>
|
|
/// 系统模块实体对象
|
|
/// </summary>
|
|
/// <value>The system model.</value>
|
|
public ModuleModel SysModel { get; private set; }
|
|
/// <summary>
|
|
/// 分割条位置
|
|
/// </summary>
|
|
public int PositionSplitter;
|
|
/// <summary>
|
|
/// 分割条位置
|
|
/// </summary>
|
|
public int WindowHeight;
|
|
/// <summary>
|
|
/// 单选模式
|
|
/// </summary>
|
|
public bool SingleChoiceMode;
|
|
#endregion
|
|
public FrmRowsModelLookUpNew()
|
|
{
|
|
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.btnFixSearch.Click += new EventHandler(OnFixButtonClick);
|
|
this.gcMain.GridView.OptionsSelection.MultiSelect = true;
|
|
this.gcMain.GridView.OptionsSelection.MultiSelectMode = GridMultiSelectMode.CheckBoxRowSelect;
|
|
this.gcMain.GridView.OptionsSelection.EnableAppearanceFocusedCell = false;
|
|
this.gcMain.GridView.SelectionChanged += OnGridViewSelectionChanged;
|
|
this.gcMain.GridView.DoubleClick += OnGridViewDoubleClick;
|
|
InitControls();
|
|
}
|
|
#region 方法
|
|
#region 设置分割条位置
|
|
/// <summary>
|
|
/// <para>说明:设置分割条位置</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2021-07-21 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
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 保存表格属性
|
|
/// <summary>
|
|
/// <para>说明:保存表格属性</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2021-07-20 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
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 设置默认选中
|
|
/// <summary>
|
|
/// <para>说明:设置默认选中</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-20 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void SetDefaultValue()
|
|
{
|
|
if (DataSource.Columns.Contains(selectField))
|
|
{
|
|
if (!string.IsNullOrEmpty(EditValue) && this.IsType == ControlType.LabSelectReturnId)
|
|
{
|
|
this.UpdateChecked(EditValue.Trim().Replace(", ", ",").TrimEnd(',').Split(','), selectField, true);
|
|
}
|
|
else
|
|
{
|
|
if (!string.IsNullOrEmpty(EditText))
|
|
{
|
|
this.UpdateChecked(EditText.Trim().Replace(", ", ",").TrimEnd(',').Split(','), selectField, false);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
#endregion
|
|
#region 加载自定义列
|
|
/// <summary>
|
|
/// <para>说明:加载自定义列</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2019-9-16 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
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 获取选中行数据
|
|
/// <summary>
|
|
/// <para>说明:获取选中行数据</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2021-07-20 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <returns>DataRow[].</returns>
|
|
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 刷新左侧树数据
|
|
/// <summary>
|
|
/// <para>说明:设置左侧树数据</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2021-07-21 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
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));
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:树节点点击后刷新数据</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-10-26 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="TreeViewEventArgs"/> instance containing the event data.</param>
|
|
protected void OnTreeLeftTreeNodeSelected(object sender, TreeViewEventArgs e)
|
|
{
|
|
string where = string.Format(" and {0} like '{1}%' ", this.treeLeft.TreeNodeKeyField, e.Node.Name);
|
|
string sqlValue = ReplaceHelper.IsProcedure(SourceSQL) ?
|
|
ReplaceHelper.ReplaceTreeViewParentKeyCond(SourceSQL, treeLeft.GetSelectNodeValue()) :
|
|
SourceSQL + where;
|
|
this.DataSource = BaseImpl.GetDataTableResult(sqlValue);
|
|
this.SetDefaultValue();
|
|
}
|
|
#endregion
|
|
#region 创建界面
|
|
/// <summary>
|
|
/// <para>说明:初始化查询条件(查询条件不自动查询)</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-09-05 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
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);
|
|
this.SearchObj.OnSearchAfterCallBack += new EventHandler(OnSearchAfterCallBack);
|
|
}
|
|
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);// 数据源绑定完成触发
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:查询条件绑定完成查询数据</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期: </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
protected void OnMainSearchDataSourceBindCallBack(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (this.SysModel.CsHasDefultSearch)
|
|
{
|
|
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(_id))
|
|
{
|
|
sourceTab.Columns.Add(_id, typeof(int));
|
|
for (int i = 0; i < sourceTab.Rows.Count; i++)
|
|
{
|
|
sourceTab.Rows[i][_id] = i;
|
|
}
|
|
}
|
|
this.gcMain.gridControl.DataSource = sourceTab;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:默认按照dm mc 加载数据</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2022-10-05 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
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.DataSource = BaseImpl.GetDataTableResult(sqlValue);
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>说明:搜索之后</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2019-05-21 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The e.</param>
|
|
protected void OnSearchAfterCallBack(object sender, EventArgs e)
|
|
{
|
|
WaitForm.ShowForm();
|
|
try
|
|
{
|
|
DataTable sourceTab = this.gcMain.gridControl.DataSourceTable();
|
|
if (sourceTab != null && !sourceTab.Columns.Contains(_id))
|
|
{
|
|
sourceTab.Columns.Add(_id, typeof(int));
|
|
for (int i = 0; i < sourceTab.Rows.Count; i++)
|
|
{
|
|
sourceTab.Rows[i][_id] = i;
|
|
}
|
|
}
|
|
this.gcMain.GridView.BeginUpdate();
|
|
this.gcMain.gridControl.DataSource = sourceTab;
|
|
this.gcMain.GridView.EndUpdate();
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
finally
|
|
{
|
|
WaitForm.HideForm();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:创建界面</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2021-07-21 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="menuCode">The menu code.</param>
|
|
public void InitControls()
|
|
{
|
|
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);
|
|
}
|
|
InitializeQueryCondition();
|
|
}
|
|
#endregion
|
|
#region 设置左侧表格数据
|
|
/// <summary>
|
|
/// <para>说明:设置左侧表格数据</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-10-25 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
protected void SetLeftGridView()
|
|
{
|
|
this.LeftRowObj = BaseModuleImpl.GetBaseLeftTreeField(UnionModuleCodel);//获取表格左侧树字段
|
|
if (this.LeftRowObj != null)
|
|
{
|
|
DataTable dtTable = BaseModuleImpl.GetBaseLeftGridField(UnionModuleCodel);
|
|
DataTable dtColorTable = BaseModuleImpl.GetBaseGridRowColors(this.LeftRowObj["fieldKey"] + "");
|
|
this.gridLeft.GridView.RowClick += new 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);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:数据绑定完成后加载数据</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期: </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
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 更新选中状态
|
|
/// <summary>
|
|
/// <para>说明:更新选中状态</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-20 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="spilts">The spilts.</param>
|
|
/// <param name="fieldName">Name of the field.</param>
|
|
/// <param name="check">if set to <c>true</c> [check].</param>
|
|
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<DataRow>().FirstOrDefault(x => x[fieldName] + "" == spilts[i].Trim());
|
|
if (rowItem != null)
|
|
{
|
|
this.gcMain.GridView.SelectRow(DataSource.Rows.IndexOf(rowItem));
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
#region 刷新右侧表格数据
|
|
/// <summary>
|
|
/// <para>说明:刷新右侧表格数据</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-19 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="DevExpress.Data.SelectionChangedEventArgs"/> instance containing the event data.</param>
|
|
protected void OnGridViewRowClick(object sender, RowClickEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
string sqlValue = ReplaceHelper.ReplaceWhereCond(SourceSQL);
|
|
// 左侧gridView时,需要替换sql参数(包含查询条件、表格选中行).
|
|
if (this.gridLeft.Visible)
|
|
{
|
|
sqlValue = this._leftGridSearchObj != null ? this._leftGridSearchObj.ReplaceParentControlValue(sqlValue) : sqlValue;
|
|
sqlValue = ReplaceHelper.ReplaceRowParam(this.gridLeft.GridView.GetFocusedDataRow(), sqlValue);
|
|
}
|
|
this.DataSource = BaseImpl.GetDataTableResult(sqlValue);
|
|
this.SetDefaultValue();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
}
|
|
#endregion
|
|
#region 事件
|
|
#region 关闭时清空唯一键
|
|
/// <summary>
|
|
/// <para>说明:关闭时清空唯一键</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2021-07-20 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="PopupMenuShowingEventArgs"/> instance containing the event data.</param>
|
|
private void OnFormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
CurrentOperColumnKey = "";
|
|
CurrentOperModel = null;
|
|
}
|
|
#endregion
|
|
#region 确定
|
|
/// <summary>
|
|
/// <para>说明:确定</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-20 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
private void btnOk_Click(object sender, EventArgs e)
|
|
{
|
|
int[] rowIndexs = this.gcMain.GridView.GetSelectedRows();
|
|
this.selectRowsEditValue = this.DataSource.NewRow();
|
|
foreach (DataColumn col in this.selectRowsEditValue.Table.Columns)
|
|
{
|
|
if (col.ColumnName.Equals(_id)) continue;
|
|
string value = "";
|
|
foreach (int index in rowIndexs)
|
|
{
|
|
DataRow item = this.gcMain.GridView.GetDataRow(index);
|
|
value += $"{item[col.ColumnName]},";
|
|
}
|
|
if (!string.IsNullOrEmpty(value.Trim(',')))
|
|
{
|
|
this.selectRowsEditValue[col] = value.Trim(',');
|
|
}
|
|
}
|
|
this.DialogResult = DialogResult.OK;
|
|
this.Close();
|
|
}
|
|
#endregion
|
|
#region 取消全选
|
|
/// <summary>
|
|
/// 取消全选
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void btn_cancelAll_Click(object sender, EventArgs e)
|
|
{
|
|
this.gcMain.GridView.ClearSelection();
|
|
}
|
|
/// <summary>
|
|
/// 表格双击选中
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnGridViewDoubleClick(object sender, EventArgs e)
|
|
{
|
|
Point point = this.gcMain.GridControl.PointToClient(MousePosition);
|
|
GridHitInfo hitInfo = this.gcMain.GridView.CalcHitInfo(point);
|
|
if (hitInfo.InRow)
|
|
{
|
|
if (hitInfo.RowHandle >= 0)
|
|
{
|
|
if (this.gcMain.GridView.IsRowSelected(hitInfo.RowHandle))
|
|
{
|
|
this.gcMain.GridView.UnselectRow(hitInfo.RowHandle);
|
|
}
|
|
else
|
|
{
|
|
if (SingleChoiceMode)
|
|
{
|
|
this.gcMain.GridView.ClearSelection();
|
|
}
|
|
this.gcMain.GridView.SelectRow(hitInfo.RowHandle);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 选中行改变时
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnGridViewSelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
|
|
{
|
|
DataRow focusedRow = this.gcMain.GridView.GetFocusedDataRow();
|
|
this.gcMain.GridView.SelectionChanged -= OnGridViewSelectionChanged;
|
|
if (SingleChoiceMode)
|
|
{
|
|
//清除所有选择
|
|
this.gcMain.GridView.ClearSelection();
|
|
}
|
|
if (e.Action == CollectionChangeAction.Add)//选中
|
|
{
|
|
this.gcMain.GridView.SelectRow(e.ControllerRow);
|
|
}
|
|
this.gcMain.GridView.SelectionChanged += OnGridViewSelectionChanged;
|
|
}
|
|
#endregion
|
|
#region 释放时清理数据源
|
|
/// <summary>
|
|
/// <para>说明:释放时清理数据源</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-16 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
private void OnFrmModelLookUp_Disposed(object sender, EventArgs e)
|
|
{
|
|
if (this.DataSource != null)
|
|
{
|
|
this.DataSource = null;
|
|
}
|
|
GC.Collect();
|
|
}
|
|
#endregion
|
|
#endregion
|
|
}
|
|
}
|