SVN-Revision: r258
This commit is contained in:
cyf
2025-02-08 06:34:46 +00:00
parent e910b8b55b
commit e776f3bd62
21 changed files with 2607 additions and 393 deletions
@@ -1,5 +1,7 @@
using DevExpress.XtraEditors;
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;
@@ -9,10 +11,12 @@ 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.RegularExpressions;
using System.Text;
using System.Windows.Forms;
namespace Lskj.Control.MultiModelLookUp
@@ -20,7 +24,14 @@ namespace Lskj.Control.MultiModelLookUp
public partial class FrmModelLookUp : BaseForm
{
#region
/// <summary>
/// 复选框字段名称
/// </summary>
private string _checkFieldName = "_check";
/// <summary>
/// The _id
/// </summary>
private string _id = "_id";
#endregion
#region
/// <summary>
@@ -60,7 +71,7 @@ namespace Lskj.Control.MultiModelLookUp
/// </summary>
public string RemarkField = "remark";
/// <summary>
/// 数据源(初始)
/// 数据源
/// </summary>
/// <value>The source SQL.</value>
public string SourceSQL { get; set; }
@@ -138,19 +149,7 @@ namespace Lskj.Control.MultiModelLookUp
/// 左侧树结构、表格主键
/// </summary>
public string ParentKeyField;
/// <summary>
/// 数据源(替换参数后)
/// </summary>
/// <value>The source SQL.</value>
public string NewSourceSQL;
/// <summary>
/// 关联返回参数的字段组合
/// </summary>
public string AddModuleResult;
/// <summary>
/// 返回关联的字典
/// </summary>
public Dictionary<string, string> ModuleResultDic = new Dictionary<string, string>();
#endregion
public FrmModelLookUp(string ModuleCodel)
{
@@ -189,23 +188,29 @@ namespace Lskj.Control.MultiModelLookUp
//设置关联模块
bool result = SetAssociatedModules();
//单选模式,不显示明细表,主表双击选中后退出选择界面
if (SingleChoiceMode)
{
this.splitMain_Right.PanelVisibility = SplitPanelVisibility.Panel1;
this.gcMain.GridView.DoubleClick += new EventHandler(OnRowCellClickRadio);
//设置上方条件
DataTable queryTable = BaseModuleImpl.GetCustomQueryFields(this.SysModel.CondKey);//加载自定义配置字段
this.SearchObj = new MyControl(this.SysModel.MenuSql, this.gcMain, LeftTreeViewEx, LeftGridEx);
this.SearchObj.ParentUnionField = this.ParentUnionField;
this.pl_top.Height = this.SearchObj.InitSearchControl(queryTable, this.pl_top);
this.SearchObj.OnSearchAfterCallBack += SearchObj_OnSearchAfterCallBack;
this.SourceSQL = this.SysModel.MenuSql;
}
else
{
this.gcMain.GridView.DoubleClick += new EventHandler(OnRowCellClick);
this.gcDetail.GridView.DoubleClick += new EventHandler(OnDoubleClick);
this.pl_top.Height = 0;
this.Resize += new System.EventHandler(maximization);
this.splitMain_Right.SplitterMoved += new EventHandler(PositionChange);
}
this.SourceSQL = this.SysModel.MenuSql;
this.gcDetail.GridView.OptionsSelection.EnableAppearanceFocusedCell = false;
this.gcDetail.GridView.OptionsView.ColumnAutoWidth = true;
@@ -279,7 +284,7 @@ namespace Lskj.Control.MultiModelLookUp
{
success = this.gcMain.GridView.UpdateCustomColumnToDatabase(this.CurrentOperColumnKey);
}
//this.SetDetailDataSource();
this.SetDetailDataSource();
MessageUtil.Show(success ? ResourceKeys.SaveSuccess : ResourceKeys.SaveFault);
}
catch (SqlException sex)
@@ -312,17 +317,16 @@ namespace Lskj.Control.MultiModelLookUp
/// </summary>
private void SetDetailDataSource()
{
//return;
//DataTable table = this.DataSource.Copy();
//DataRow[] rows = table.Select(_checkFieldName + "=True");
DataTable table = this.DataSource.Copy();
DataRow[] rows = table.Select(_checkFieldName + "=True");
//if (rows != null && rows.Length > 0)
// this.gcDetail.GridControl.DataSource = rows.CopyToDataTable();
//else
//{
// this.gcDetail.GridControl.DataSource = table;
// this.gcDetail.GridControl.DataSourceTable().Clear();
//}
if (rows != null && rows.Length > 0)
this.gcDetail.GridControl.DataSource = rows.CopyToDataTable();
else
{
this.gcDetail.GridControl.DataSource = table;
this.gcDetail.GridControl.DataSourceTable().Clear();
}
}
#endregion
@@ -364,17 +368,22 @@ namespace Lskj.Control.MultiModelLookUp
/// </summary>
private void SetReadOnlyColumns()
{
if (this.ConfigureColumnMode)//&& SingleChoiceMode
if (this.ConfigureColumnMode && SingleChoiceMode)
{
DataTable _gridColumns = BaseModuleImpl.GetBaseGridColumns(this.UnionModuleCodel);
this.gcMain.SetReadOnlyColumns(_gridColumns, GridCustomColumnStruct.BaseMainGridView + this.SysModel.FormKey);
this.gcDetail.SetReadOnlyColumns(_gridColumns, GridCustomColumnStruct.BaseMainGridView + this.SysModel.FormKey);
}
else
{
this.gcMain.GridView.Columns.Clear();
this.gcDetail.GridView.Columns.Clear();
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;
@@ -394,8 +403,8 @@ namespace Lskj.Control.MultiModelLookUp
this.gcMain.GridView.Columns.AddRange(new GridColumn[] { valueColumn, textColumn });
this.gcDetail.GridView.Columns.AddRange(new GridColumn[] { valueColumn, textColumn });
this.gcMain.GridView.Columns.AddRange(new GridColumn[] { checkColumn, valueColumn, textColumn });
this.gcDetail.GridView.Columns.AddRange(new GridColumn[] { checkColumn, valueColumn, textColumn });
if (DataSource.Columns.IndexOf("remark") != -1)
{
@@ -622,17 +631,11 @@ namespace Lskj.Control.MultiModelLookUp
/// <param name="menuCode">The menu code.</param>
public void InitControls(string UnionModuleCodel)
{
this.SysModel.MenuSql = this.NewSourceSQL;
//设置上方条件
this.pl_top.Controls.Clear();
DataTable queryTable = BaseModuleImpl.GetCustomQueryFields(this.SysModel.CondKey);//加载自定义配置字段
this.SearchObj = new MyControl(this.SysModel.MenuSql, this.gcMain, LeftTreeViewEx, LeftGridEx);
this.SearchObj.ParentUnionField = this.ParentUnionField;
this.pl_top.Height = 0;
this.pl_top.Height = this.SearchObj.InitSearchControl(queryTable, this.pl_top);
this.SearchObj.OnSearchAfterCallBack += SearchObj_OnSearchAfterCallBack;
//单选模式以模块sql为为准
if (SingleChoiceMode)
{
this.SourceSQL = this.SysModel.MenuSql;
}
if (LeftTreeViewEx != null && LeftTreeViewEx.TreeView.Nodes.Count > 0)
{
LeftTreeViewEx.TreeView.SelectedNode = LeftTreeViewEx.TreeView.Nodes[0];//重新打开时默认选中第一条
@@ -643,7 +646,7 @@ namespace Lskj.Control.MultiModelLookUp
LeftGridEx.GridView.SelectRow(0);
}
this.DataSource = BaseImpl.GetDataTableResult(this.NewSourceSQL);
this.DataSource = BaseImpl.GetDataTableResult(this.SourceSQL);
this.SetSelectionBox();
//创建表格列
if (isFirst)
@@ -661,7 +664,7 @@ namespace Lskj.Control.MultiModelLookUp
private void SearchObj_OnSearchAfterCallBack(object sender, EventArgs e)
{
//this.SetSelectionBox();
this.SetSelectionBox();
//this.SetReadOnlyColumns();
}
@@ -715,7 +718,8 @@ namespace Lskj.Control.MultiModelLookUp
DataRow rowItem = rowItem = this.DataSource.Rows.Cast<DataRow>().FirstOrDefault(x => x[isValue ? ValueMember : TextField] + "" == spilts[i].Trim());
if (rowItem != null)
{
(this.gcDetail.GridControl.DataSource as DataTable).Rows.Add(rowItem.ItemArray);
rowItem[_checkFieldName] = check;
rowItem.AcceptChanges();
}
}
this.SetDetailDataSource();
@@ -798,10 +802,11 @@ namespace Lskj.Control.MultiModelLookUp
DataRow rowItem = this.gcMain.GridView.GetFocusedDataRow();
if (rowItem != null)
{
(this.gcDetail.GridControl.DataSource as DataTable).Rows.Add(rowItem.ItemArray);
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.SetDetailDataSource();
}
/// <summary>
@@ -819,6 +824,8 @@ namespace Lskj.Control.MultiModelLookUp
{
DataRow dr = this.gcMain.GridView.GetFocusedDataRow();
//DataRow[] rowItems = this.DataSource.Select(_checkFieldName + "=True");
if (dr != null)
{
this.EditValue = dr[ValueMember] + "";
@@ -848,7 +855,13 @@ namespace Lskj.Control.MultiModelLookUp
{
if (this.gcDetail.GridView.RowCount == 0) return;
DataRow rowItem = this.gcDetail.GridView.GetFocusedDataRow();
(this.gcDetail.GridControl.DataSource as DataTable).Rows.Remove(rowItem);
DataRow[] sourceRowItems = this.DataSource.Select(_id + "=" + rowItem[_id] + "");
if (rowItem != null && sourceRowItems != null && sourceRowItems.Length > 0)
{
sourceRowItems[0][_checkFieldName] = 0;
sourceRowItems[0].AcceptChanges();
}
this.SetDetailDataSource();
}
#endregion
#region
@@ -884,49 +897,20 @@ namespace Lskj.Control.MultiModelLookUp
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private void btnOk_Click(object sender, EventArgs e)
{
EditValue = string.Empty;
EditText = string.Empty;
ModuleResultDic.Clear();
DataTable sourceTable = this.gcDetail.GridControl.DataSource as DataTable;
foreach (DataRow item in sourceTable.Rows)
this.EditValue = string.Empty;
this.EditText = string.Empty;
DataRow[] rowItems = this.DataSource.Select(_checkFieldName + "=True");
foreach (DataRow item in rowItems)
{
this.EditValue += item[ValueMember] + ",";
this.EditText += item[TextField] + ",";
}
if (!string.IsNullOrEmpty(AddModuleResult))
{
string[] resultFields = AddModuleResult.Split(',');
foreach (string resultField in resultFields)
{
Match match = Regex.Match(resultField, @"^\s*([^\s]+)\s+AS\s+([^\s]+)\s*$", RegexOptions.IgnoreCase);
if (match.Success)
{
string beforeAs = match.Groups[1].Value.Trim();
string afterAs = match.Groups[2].Value.Trim();
string value = "";
foreach (DataRow item in sourceTable.Rows)
{
if (item.Table.Columns.Contains(beforeAs))
{
value += item[beforeAs] + ",";
}
}
ModuleResultDic.Add(afterAs, value);
}
else
{
string value = "";
foreach (DataRow item in sourceTable.Rows)
{
if (item.Table.Columns.Contains(resultField))
{
value += item[resultField] + ",";
}
}
ModuleResultDic.Add(resultField, value);
}
}
}
//this.EditValue = this.EditValue.Trim(',');
//this.EditText = this.EditText.Trim(',');
this.DialogResult = DialogResult.OK;
this.Close();
}
@@ -961,8 +945,9 @@ namespace Lskj.Control.MultiModelLookUp
DataTable DataSource = this.gcMain.GridView.GetGridViewFilteredAndSortedDataToDataTable();
foreach (DataRow item in DataSource.Rows)
{
//DataRow rowItem = this.DataSource.Select("1=1").FirstOrDefault(x => (item[_id] + "").Equals(x[_id] + ""));
(this.gcDetail.GridControl.DataSource as DataTable).Rows.Add(item.ItemArray);
DataRow rowItem = this.DataSource.Select("1=1").FirstOrDefault(x => (item[_id] + "").Equals(x[_id] + ""));
rowItem[_checkFieldName] = 1;
rowItem.AcceptChanges();
}
this.SetDetailDataSource();
}
@@ -977,7 +962,16 @@ namespace Lskj.Control.MultiModelLookUp
private void btn_cancelAll_Click(object sender, EventArgs e)
{
(this.gcDetail.GridControl.DataSource as DataTable).Clear();
DataTable dt = this.DataSource.Clone();
foreach (DataRow item in this.DataSource.Rows)
{
if ("True".Equals(item[_checkFieldName] + ""))
{
item[_checkFieldName] = 0;
}
}
this.SetDetailDataSource();
}
#endregion
@@ -1038,4 +1032,17 @@ namespace Lskj.Control.MultiModelLookUp
case 2: // 左侧为表格
this.gridLeft.Visible = true;
this.treeLeft.Visible = false;
this.InitlizeSpiltL
this.InitlizeSpiltLocation();
this.SetLeftGridView();
//this.ModuleGridObj.SaveEvent += new Lskj.Control.ModuleGridEx.SaveEventHander(SetDetailGridView);
this.LeftGridEx = this.gridLeft;
break;
case 3: // 左侧为空
default:
this.splitMain.PanelVisibility = SplitPanelVisibility.Panel2;
break;
}
}
else