1026 lines
42 KiB
C#
1026 lines
42 KiB
C#
/******************************
|
|
* 说明:多选界面
|
|
* 创建人:龚宇超
|
|
* 创建日期:2018-03-20
|
|
* 修改人:
|
|
* 修改日期:
|
|
* 修改备注:
|
|
* 版本:1.0.0.0
|
|
******************************/
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using Lskj.Control.Model;
|
|
using DevExpress.XtraGrid.Columns;
|
|
using DevExpress.XtraEditors.Repository;
|
|
using DevExpress.Data;
|
|
using DevExpress.XtraGrid.Views.Grid;
|
|
using DevExpress.XtraGrid.Menu;
|
|
using DevExpress.Utils.Menu;
|
|
using Lskj.Business.Impl;
|
|
using Lskj.Data;
|
|
using System.Data.SqlClient;
|
|
using Lskj.Util;
|
|
using Lskj.Business;
|
|
using Lskj.Model;
|
|
using System.Text.RegularExpressions;
|
|
using System.Reflection;
|
|
using DevExpress.Data.Filtering;
|
|
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
|
|
|
|
namespace Lskj.Control.MultiGridLookUp
|
|
{
|
|
public partial class FrmLookUp : BaseForm
|
|
{
|
|
/// <summary>
|
|
/// 复选框字段名称
|
|
/// </summary>
|
|
private string _checkFieldName = "_check";
|
|
/// <summary>
|
|
/// The _id
|
|
/// </summary>
|
|
private string _id = "_id";
|
|
/// <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>
|
|
/// <value>The edit text.</value>
|
|
public string EditText { 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>
|
|
/// 数据源
|
|
/// </summary>
|
|
/// <value>The data source.</value>
|
|
///
|
|
public DataTable DataSource
|
|
{
|
|
get
|
|
{
|
|
return this.gcMain.GridControl.DataSourceTable();
|
|
}
|
|
set
|
|
{
|
|
//this.gcMain.HideFindPanel();
|
|
this.gcMain.GridControl.DataSource = value;
|
|
//this.gcMain.ShowFindPanel();
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// CurrentOperModel值
|
|
/// </summary>
|
|
/// <value>The data source.</value>
|
|
public List<DataRow> selectRow = null;
|
|
|
|
public FrmLookUp()
|
|
{
|
|
InitializeComponent();
|
|
this.Disposed += new EventHandler(OnFrmLookUp_Disposed);
|
|
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmLookUp_FormClosing);
|
|
this.gcMain.GridControl.ContextMenuStrip = contextMenuStrip1;
|
|
this.gcMain.PopupMenuShowing += new DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventHandler(this.OnGridViewPopupMenuShowing);
|
|
this.gcMain.DoubleClick += new EventHandler(GridView_RowCellClick);
|
|
this.gcDetail.DoubleClick += new EventHandler(GridView_DoubleClick);
|
|
GridDragGrid dragGrid = new GridDragGrid(this.gcMain, this.gcDetail);
|
|
GridDragGrid backdragGrid = new GridDragGrid(this.gcDetail, this.gcMain);
|
|
dragGrid.OnDragComplete += new GridFragGridCompleteEventHandler(OnDragGridCompleted);
|
|
backdragGrid.OnDragComplete += new GridFragGridCompleteEventHandler(OnDragGridBackCompleted);
|
|
//GridDragGrid.GridAddCheckBox(this.gcMain);
|
|
//GridDragGrid.GridAddCheckBox(this.gcDetail);
|
|
if (Business.Impl.LanguageTranslation.Translatable)
|
|
{
|
|
this.Text = Business.Impl.LanguageTranslation.GetTranslatedText(this.Text);
|
|
}
|
|
Lskj.Control.Model.ReplaceTranslation.TranslationFixedButton(this);
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>说明:清空选中状态</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-08-24 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
public void ClearSelect()
|
|
{
|
|
if (this.DataSource != null && this.DataSource.Columns.Contains(_checkFieldName))
|
|
{
|
|
foreach (DataRow item in this.DataSource.Rows)
|
|
{
|
|
item[_checkFieldName] = 0;
|
|
}
|
|
}
|
|
this.gcDetail.SelectAll();
|
|
this.gcDetail.DeleteSelectedRows();
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:窗口加载</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-20 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
selectRow = new List<DataRow>();
|
|
base.OnLoad(e);
|
|
this.SetReadOnlyColumns();
|
|
this.SetDefaultValue();
|
|
//this.gcMain.BestFitColumns();
|
|
//列超过5列则变为上下结构加载数据
|
|
if (this.DataSource.Columns.Count >= 5)
|
|
{
|
|
this.splitContainerControl1.Horizontal = false;
|
|
this.splitContainerControl1.SplitterPosition = 227;
|
|
CalcPopupSize();
|
|
this.Location = new Point((SystemInformation.PrimaryMonitorSize.Width - this.Width) / 2,
|
|
(SystemInformation.PrimaryMonitorSize.Height - this.Height) / 2);
|
|
}
|
|
// 自动列宽和弹窗尺寸计算完成后,最后应用个性化列配置,避免配置被覆盖。
|
|
this.SetCustomColumns();
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:计算控件Size,只计算一次</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-04-10 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="obj">The object.</param>
|
|
public void CalcPopupSize()
|
|
{
|
|
int calcLen = this.gridControl1.DataSourceTable().Rows.Count > 20 ? 20 : this.gridControl1.DataSourceTable().Rows.Count;
|
|
DataTable table = this.gridControl1.DataSourceTable();
|
|
|
|
bool hasReamrkField = table.Columns.Contains(RemarkField);
|
|
int iValueWidth = 0, iTextWidth = 0, iRemarkWidth = 0, iOtherWidth = 0;
|
|
int iIndexWidth = this.gcMain.IndicatorWidth;
|
|
|
|
for (int i = 0; i < calcLen; i++)
|
|
{
|
|
string valueValue = table.Rows[i][ValueMember] + "";
|
|
string textValue = table.Rows[i][TextField] + "";
|
|
string remarkValue = hasReamrkField ? table.Rows[i][RemarkField] + "" : "";
|
|
|
|
int valueWidth = GraphicsText.GetTextWidth(valueValue);
|
|
int textWidth = GraphicsText.GetTextWidth(textValue);
|
|
int remarkWidth = GraphicsText.GetTextWidth(remarkValue);
|
|
|
|
if (iValueWidth < valueWidth) iValueWidth = valueWidth;
|
|
if (iTextWidth < textWidth) iTextWidth = textWidth;
|
|
if (iRemarkWidth < remarkWidth) iRemarkWidth = remarkWidth;
|
|
}
|
|
|
|
foreach (GridColumn col in this.gcMain.Columns)
|
|
{
|
|
if (col.Name.Substring(0, 1) != "_" &&
|
|
col.Name.ToLower() != ValueField.ToLower() &&
|
|
col.Name.ToLower() != TextField.ToLower() &&
|
|
col.Name.ToLower() != RemarkField.ToLower())
|
|
{
|
|
col.Width = col.GetBestWidth();
|
|
iOtherWidth += col.Width;
|
|
}
|
|
}
|
|
|
|
// 由于计算有误差,所以计算列结果都加10px
|
|
iValueWidth = iValueWidth < 50 ? 50 : iValueWidth + 10;
|
|
iTextWidth = iTextWidth + 10;
|
|
|
|
gcMain.Columns[ValueMember].Width = iValueWidth;
|
|
gcMain.Columns[TextField].Width = iTextWidth;
|
|
if (hasReamrkField)
|
|
{
|
|
gcMain.Columns[RemarkField].Width = iRemarkWidth;
|
|
iRemarkWidth = iRemarkWidth + 10;
|
|
}
|
|
|
|
int popupWidth = iIndexWidth + iValueWidth + iTextWidth + iRemarkWidth + iOtherWidth + 20;
|
|
if (popupWidth > gridControl1.Width)
|
|
this.Width = popupWidth;
|
|
|
|
foreach (GridColumn item in gcMain.Columns)
|
|
{
|
|
var column = this.gcDetail.Columns.Where(n => n.Caption.Equals(item.Caption)).FirstOrDefault();
|
|
if (column != null)
|
|
{
|
|
column.Width = item.Width;
|
|
}
|
|
}
|
|
//this._Handed = false;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置只读列</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-20 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void SetReadOnlyColumns()
|
|
{
|
|
this.gcMain.Columns.Clear();
|
|
this.gcDetail.Columns.Clear();
|
|
if (this.DataSource != null)
|
|
{
|
|
if (!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;
|
|
}
|
|
}
|
|
for (int i = 0; i < 2; i++)
|
|
{
|
|
GridColumn checkColumn = new GridColumn();
|
|
checkColumn.Name = checkColumn.FieldName = this._checkFieldName;
|
|
checkColumn.Caption = Business.Impl.LanguageTranslation.Translatable ? Business.Impl.LanguageTranslation.GetTranslatedText("选") : "选";
|
|
checkColumn.Width = 30;
|
|
checkColumn.Visible = true;
|
|
checkColumn.OptionsColumn.AllowEdit = false;
|
|
checkColumn.OptionsFilter.FilterPopupMode = FilterPopupMode.CheckedList;
|
|
|
|
GridColumn valueColumn = new GridColumn();
|
|
valueColumn.FieldName = valueColumn.Name = ValueField;
|
|
valueColumn.Caption = Business.Impl.LanguageTranslation.Translatable ? Business.Impl.LanguageTranslation.GetTranslatedText("编码") : "编码";
|
|
valueColumn.Width = 200;
|
|
//valueColumn.Visible = true;
|
|
valueColumn.Visible = ValueMember.Substring(0, 1) != "_";
|
|
valueColumn.OptionsColumn.AllowEdit = false;
|
|
valueColumn.OptionsFilter.FilterPopupMode = FilterPopupMode.CheckedList;
|
|
|
|
GridColumn textColumn = new GridColumn();
|
|
textColumn.FieldName = textColumn.Name = TextField;
|
|
textColumn.Caption = Business.Impl.LanguageTranslation.Translatable ? Business.Impl.LanguageTranslation.GetTranslatedText("名称") : "名称";
|
|
textColumn.Width = 350;
|
|
//textColumn.Visible = true;
|
|
textColumn.Visible = TextField.Substring(0, 1) != "_";
|
|
textColumn.OptionsColumn.AllowEdit = false;
|
|
textColumn.OptionsFilter.FilterPopupMode = FilterPopupMode.CheckedList;
|
|
|
|
if (i == 0)
|
|
{
|
|
this.gcMain.Columns.AddRange(new GridColumn[] { checkColumn, valueColumn, textColumn });
|
|
}
|
|
else if (i == 1)
|
|
{
|
|
this.gcDetail.Columns.AddRange(new GridColumn[] { checkColumn, valueColumn, textColumn });
|
|
}
|
|
}
|
|
|
|
if (DataSource.Columns.IndexOf("remark") != -1)
|
|
{
|
|
for (int i = 0; i < 2; i++)
|
|
{
|
|
DataColumn column = DataSource.Columns.Cast<DataColumn>().FirstOrDefault(x => x.ColumnName.ToLower() == RemarkField);
|
|
if (column != null) RemarkField = column.ColumnName;
|
|
|
|
GridColumn remarkColumn = new GridColumn();
|
|
remarkColumn.Name = remarkColumn.FieldName = RemarkField;
|
|
remarkColumn.Caption = Business.Impl.LanguageTranslation.Translatable ? Business.Impl.LanguageTranslation.GetTranslatedText("备注") : "备注";
|
|
remarkColumn.Visible = true;
|
|
remarkColumn.Width = 120;
|
|
//字段第一个字符为下划线代表不显示
|
|
if (RemarkField.Substring(0, 1) == "_")
|
|
remarkColumn.Visible = false;
|
|
remarkColumn.OptionsFilter.FilterPopupMode = FilterPopupMode.CheckedList;
|
|
if (i == 0)
|
|
{
|
|
this.gcMain.Columns.Add(remarkColumn);
|
|
}
|
|
else if (i == 1)
|
|
{
|
|
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))
|
|
{
|
|
for (int i = 0; i < 2; i++)
|
|
{
|
|
GridColumn otherColumn = new GridColumn();
|
|
otherColumn.Name = otherColumn.FieldName = otherColumn.Caption = dcol.ColumnName;
|
|
otherColumn.Caption=Business.Impl.LanguageTranslation.Translatable? Business.Impl.LanguageTranslation.GetTranslatedText(otherColumn.Caption) : otherColumn.Caption;
|
|
otherColumn.Visible = true;
|
|
otherColumn.Width = 150;
|
|
otherColumn.OptionsFilter.FilterPopupMode = FilterPopupMode.CheckedList;
|
|
if (i == 0)
|
|
{
|
|
this.gcMain.Columns.Add(otherColumn);
|
|
}
|
|
else if (i == 1)
|
|
{
|
|
this.gcDetail.Columns.Add(otherColumn);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this.gcDetail.GridControl.DataSource = this.gridControl1.DataSourceTable().Clone();
|
|
this.gcMain.BestFitColumns();
|
|
//this.gcDetail.SelectAll();
|
|
//this.gcDetail.DeleteSelectedRows();
|
|
}
|
|
}
|
|
/// <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.GetCustomColumnByDatabase(this.CurrentOperColumnKey);
|
|
if (customTable != null && customTable.Rows.Count > 0)
|
|
{
|
|
this.gcMain.BeginUpdate();
|
|
this.gcDetail.BeginUpdate();
|
|
try
|
|
{
|
|
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);
|
|
|
|
SetCustomColumn(this.gcMain.Columns.ColumnByName(fieldName), fieldWidth, index, visible, isFix);
|
|
SetCustomColumn(this.gcDetail.Columns.ColumnByName(fieldName), fieldWidth, index, visible, isFix);
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
this.gcDetail.EndUpdate();
|
|
this.gcMain.EndUpdate();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 应用单列的个性化布局。
|
|
/// </summary>
|
|
private static void SetCustomColumn(GridColumn column, int width, int visibleIndex, bool visible, bool isFix)
|
|
{
|
|
if (column == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
column.Visible = visible;
|
|
if (visible)
|
|
{
|
|
column.VisibleIndex = visibleIndex;
|
|
}
|
|
if (width > 0)
|
|
{
|
|
column.Width = width;
|
|
}
|
|
column.Fixed = isFix ? FixedStyle.Left : FixedStyle.None;
|
|
column.OptionsFilter.FilterPopupMode = FilterPopupMode.CheckedList;
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>说明:设置默认选中</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-20 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void SetDefaultValue()
|
|
{
|
|
this.gridControl2.DataSourceTable().Clear();
|
|
if (!string.IsNullOrEmpty(EditValue) && (this.IsType == ControlType.LabMultiSelectValue || this.IsType == ControlType.LabMultiSelectValueNew || this.IsType == ControlType.LabMultiSelectValueParam))
|
|
{
|
|
this.UpdateChecked(EditValue.Trim().Replace(", ", ",").TrimEnd(',').Split(','), ValueMember, true);
|
|
}
|
|
else
|
|
{
|
|
if (!string.IsNullOrEmpty(EditText))
|
|
{
|
|
this.UpdateChecked(EditText.Trim().Replace(", ", ",").TrimEnd(',').Split(','), TextField, false);
|
|
}
|
|
}
|
|
}
|
|
/// <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[isValue ? ValueMember : TextField] + "" == spilts[i].Trim());
|
|
if (rowItem != null)
|
|
{
|
|
rowItem[_checkFieldName] = check;
|
|
rowItem.AcceptChanges();
|
|
selectRow.Add(rowItem);
|
|
}
|
|
}
|
|
this.SetDetailDataSource();
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置明细数据源</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-04-23 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void SetDetailDataSource()
|
|
{
|
|
DataTable table = this.DataSource.Copy();
|
|
DataRow[] rows = table.Select(_checkFieldName + "=True");
|
|
|
|
if (rows != null && rows.Length > 0)
|
|
{
|
|
DataTable table2 = this.DataSource.Clone();
|
|
if (selectRow != null && selectRow.Count > 0)
|
|
{
|
|
foreach (DataRow item in selectRow)
|
|
{
|
|
table2.Rows.Add(item.ItemArray);
|
|
}
|
|
}
|
|
//selectRow
|
|
//this.gcDetail.GridControl.DataSource = rows.CopyToDataTable();
|
|
this.gcDetail.GridControl.DataSource = table2;//根据点击顺序显示
|
|
}
|
|
else
|
|
{
|
|
this.gcDetail.GridControl.DataSource = table;
|
|
this.gcDetail.GridControl.DataSourceTable().Clear();
|
|
}
|
|
}
|
|
/// <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 btnAdd_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
/// <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)
|
|
{
|
|
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] + ",";
|
|
//}
|
|
//根据选中的顺序显示
|
|
for (int i = 0; i < selectRow.Count; i++)
|
|
{
|
|
this.EditValue += selectRow[i][ValueMember] + ",";
|
|
this.EditText += selectRow[i][TextField] + ",";
|
|
}
|
|
|
|
if (!SystemInfo.Instance.MutilTrailingComma)
|
|
{
|
|
this.EditValue = this.EditValue.Trim(',');
|
|
this.EditText = this.EditText.Trim(',');
|
|
}
|
|
|
|
|
|
this.DialogResult = DialogResult.OK;
|
|
this.Close();
|
|
}
|
|
/// <summary>
|
|
/// 全选所有数据
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void btn_selectAll_Click(object sender, EventArgs e)
|
|
{
|
|
DataTable DataSource = this.gcMain.GetGridViewFilteredAndSortedDataToDataTable();
|
|
//selectRow.Clear();
|
|
foreach (DataRow item in DataSource.Rows)
|
|
{
|
|
if (Convert.ToInt32(item[_checkFieldName]) == 0)
|
|
{
|
|
DataRow rowItem = this.DataSource.Select("1=1").FirstOrDefault(x => (item[_id] + "").Equals(x[_id] + ""));
|
|
rowItem[_checkFieldName] = 1;
|
|
rowItem.AcceptChanges();
|
|
selectRow.Add(rowItem);
|
|
}
|
|
}
|
|
this.SetDetailDataSource();
|
|
}
|
|
/// <summary>
|
|
/// 取消全选
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void btn_cancelAll_Click(object sender, EventArgs e)
|
|
{
|
|
DataTable DataSource = this.gcMain.GetGridViewFilteredAndSortedDataToDataTable();
|
|
foreach (DataRow item in DataSource.Rows)
|
|
{
|
|
if (Convert.ToInt32(item[_checkFieldName]) == 1)
|
|
{
|
|
DataRow rowItem = this.DataSource.Select("1=1").FirstOrDefault(x => (item[_id] + "").Equals(x[_id] + ""));
|
|
rowItem[_checkFieldName] = 0;
|
|
rowItem.AcceptChanges();
|
|
//selectRow.Remove(rowItem);
|
|
}
|
|
}
|
|
selectRow.Clear();
|
|
this.SetDetailDataSource();
|
|
}
|
|
/// <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 btnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
this.DialogResult = DialogResult.Cancel;
|
|
}
|
|
/// <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 tsmi_all_Click(object sender, EventArgs e)
|
|
{
|
|
DataTable DataSource = this.gcMain.GetGridViewFilteredAndSortedDataToDataTable();
|
|
foreach (DataRow item in DataSource.Rows)
|
|
{
|
|
DataRow rowItem = this.DataSource.Select("1=1").FirstOrDefault(x => (item[_id] + "").Equals(x[_id] + ""));
|
|
rowItem[_checkFieldName] = 1;
|
|
rowItem.AcceptChanges();
|
|
selectRow.Add(rowItem);
|
|
}
|
|
this.SetDetailDataSource();
|
|
}
|
|
/// <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 tsmi_reserve_Click(object sender, EventArgs e)
|
|
{
|
|
DataTable dt = this.DataSource.Clone();
|
|
DataTable FilterDt = this.gcMain.GetGridViewFilteredAndSortedDataToDataTable();//筛选后的表
|
|
foreach (DataRow item in this.DataSource.Rows)
|
|
{
|
|
if (FilterDt.Rows.Cast<DataRow>().FirstOrDefault(x => (x[ValueMember] + "").Equals(item[ValueMember] + "")) != null)
|
|
{
|
|
item[_checkFieldName] = "True".Equals(item[_checkFieldName] + "") ? 0 : 1;
|
|
}
|
|
|
|
if (Convert.ToInt32(item[_checkFieldName]) == 1)
|
|
{
|
|
dt.ImportRow(item);
|
|
}
|
|
}
|
|
this.gridControl2.DataSource = dt;
|
|
}
|
|
/// <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 tsmi_cancel_Click(object sender, EventArgs e)
|
|
{
|
|
//清空
|
|
ClearSelect();
|
|
}
|
|
|
|
/// <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="DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs"/> instance containing the event data.</param>
|
|
private void GridView_RowCellClick(object sender, EventArgs e)
|
|
{
|
|
|
|
Point pt = this.gcMain.GridControl.PointToClient(System.Windows.Forms.Control.MousePosition);
|
|
GridHitInfo hitInfo = this.gcMain.CalcHitInfo(pt);
|
|
// 判断是否点击在列头(如果是,则不执行双击逻辑)
|
|
if (hitInfo.InColumnPanel) return;
|
|
|
|
DataRow rowItem = this.gcMain.GetFocusedDataRow();
|
|
bool isSelect = true;
|
|
if (rowItem != null)
|
|
{
|
|
isSelect = "True".Equals(rowItem[_checkFieldName] + "") ? true : false;
|
|
rowItem[_checkFieldName] = isSelect ? 0 : 1;
|
|
rowItem.AcceptChanges();
|
|
if (isSelect)
|
|
{
|
|
selectRow.Remove(rowItem);
|
|
}
|
|
else
|
|
{
|
|
selectRow.Add(rowItem);
|
|
}
|
|
}
|
|
this.SetDetailDataSource();
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:获取选中行数据</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2019-10-18 </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;
|
|
}
|
|
/// <summary>
|
|
/// 添加选择项
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnDragGridCompleted(object sender, GridDragGridArgs e)
|
|
{
|
|
DataRow[] rowArray = GetViewFocusedDataRows(gcMain);
|
|
for (int i = 0; i < rowArray.Length; i++)
|
|
{
|
|
if (rowArray[i] != null && "False".Equals(rowArray[i][_checkFieldName] + ""))
|
|
{
|
|
rowArray[i][_checkFieldName] = 1;
|
|
rowArray[i].AcceptChanges();
|
|
selectRow.Add(rowArray[i]);
|
|
}
|
|
}
|
|
this.SetDetailDataSource();
|
|
DataTable table = this.gridControl2.DataSource as DataTable;
|
|
this.gcMain.ClearSelection();
|
|
this.gcDetail.SelectRowHandler(table.Rows.Count - 1);
|
|
this.gcDetail.UpdateCurrentRow();
|
|
this.gcDetail.ShowEditor();
|
|
|
|
}
|
|
/// <summary>
|
|
/// 反退选择项
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnDragGridBackCompleted(object sender, GridDragGridArgs e)
|
|
{
|
|
DataRow[] rowArray = GetViewFocusedDataRows(gcDetail);
|
|
|
|
for (int i = 0; i < rowArray.Length; i++)
|
|
{
|
|
DataRow[] sourceRowItems = this.DataSource.Select(_id + "=" + rowArray[i][_id] + "");
|
|
if (rowArray[i] != null && sourceRowItems != null && sourceRowItems.Length > 0)
|
|
{
|
|
for (int j = 0; j < selectRow.Count; j++)
|
|
{
|
|
DataRow dr = selectRow[j];
|
|
IEqualityComparer<DataRow> comparer = DataRowComparer.Default;
|
|
if (comparer.Equals(dr, rowArray[i]))
|
|
{
|
|
selectRow.RemoveAt(j);
|
|
}
|
|
}
|
|
sourceRowItems[0][_checkFieldName] = 0;
|
|
sourceRowItems[0].AcceptChanges();
|
|
}
|
|
}
|
|
this.SetDetailDataSource();
|
|
this.gcDetail.ClearSelection();
|
|
DataTable table = this.gridControl1.DataSource as DataTable;
|
|
this.gcMain.SelectRowHandler(table.Rows.Count - 1);
|
|
this.gcMain.UpdateCurrentRow();
|
|
this.gcMain.ShowEditor();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>说明:取消选择</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-04-23 </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 GridView_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
if (this.gcDetail.RowCount == 0) return;
|
|
|
|
|
|
Point pt = this.gcDetail.GridControl.PointToClient(System.Windows.Forms.Control.MousePosition);
|
|
GridHitInfo hitInfo = this.gcDetail.CalcHitInfo(pt);
|
|
// 判断是否点击在列头(如果是,则不执行双击逻辑)
|
|
if (hitInfo.InColumnPanel) return;
|
|
|
|
DataRow rowItem = this.gcDetail.GetFocusedDataRow();
|
|
DataRow[] sourceRowItems = this.DataSource.Select(_id + "=" + rowItem[_id] + "");
|
|
if (rowItem != null && sourceRowItems != null && sourceRowItems.Length > 0)
|
|
{
|
|
for (int i = 0; i < selectRow.Count; i++)
|
|
{
|
|
DataRow dr = selectRow[i];
|
|
IEqualityComparer<DataRow> comparer = DataRowComparer.Default;
|
|
if (comparer.Equals(dr, rowItem))
|
|
{
|
|
selectRow.RemoveAt(i);
|
|
}
|
|
}
|
|
sourceRowItems[0][_checkFieldName] = 0;
|
|
sourceRowItems[0].AcceptChanges();
|
|
}
|
|
this.SetDetailDataSource();
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:保存表格属性</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-02-01 </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.SaveCustomColumnToDatabase(this.CurrentOperColumnKey);
|
|
}
|
|
else
|
|
{
|
|
success = this.gcMain.UpdateCustomColumnToDatabase(this.CurrentOperColumnKey);
|
|
}
|
|
this.SetDetailDataSource();
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:重置表格属性</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-02-01 </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 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.ResetCustomColumnToDatabase(CurrentOperColumnKey);
|
|
this.SetReadOnlyColumns();
|
|
this.SetDetailDataSource();
|
|
MessageUtil.Show(success ? ResourceKeys.ResetSuccess : ResourceKeys.ResetFault);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:列右键菜单扩展</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-02-01 </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>
|
|
protected void OnGridViewPopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
|
|
{
|
|
if (e.MenuType == GridMenuType.Column)
|
|
{
|
|
GridViewColumnMenu columnMenu = e.Menu as GridViewColumnMenu;
|
|
DXMenuItem itemSaveColumn = new DXMenuItem("保存表格属性", SaveItemClick);
|
|
DXMenuItem itemResetColumn = new DXMenuItem("重置表格属性", ResetItemClick);
|
|
itemSaveColumn.BeginGroup = true;
|
|
itemSaveColumn.Tag = e.HitInfo.Column;
|
|
columnMenu.Items.AddRange(new DXMenuItem[] { itemSaveColumn, itemResetColumn });
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 关闭时清空唯一键
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void FrmLookUp_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
CurrentOperColumnKey = "";
|
|
CurrentOperModel = null;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:释放时清理数据源</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-16 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
private void OnFrmLookUp_Disposed(object sender, EventArgs e)
|
|
{
|
|
if (this.DataSource != null)
|
|
{
|
|
this.DataSource = null;
|
|
}
|
|
GC.Collect();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 每次弹出时查询设置搜索值
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void FrmLookUp_Shown(object sender, EventArgs e)
|
|
{
|
|
string MainText = this.gcMain.FindFilterText;
|
|
string DatailText = this.gcDetail.FindFilterText;
|
|
if (!string.IsNullOrWhiteSpace(MainText))
|
|
{
|
|
this.gcMain.FindFilterText = "";
|
|
this.gcMain.FindFilterText = MainText;
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(DatailText))
|
|
{
|
|
this.gcDetail.FindFilterText = "";
|
|
this.gcDetail.FindFilterText = DatailText;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|