1508 lines
62 KiB
C#
1508 lines
62 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using DevExpress.XtraEditors;
|
|
using System.Drawing;
|
|
using DevExpress.XtraGrid.Views.Grid;
|
|
using System.Windows.Forms;
|
|
using System.Data;
|
|
using DevExpress.XtraGrid.Columns;
|
|
using Lskj.Business.Impl;
|
|
using Lskj.Control.Model;
|
|
using System.Threading;
|
|
using Lskj.Util;
|
|
using System.Text.RegularExpressions;
|
|
using Lskj.Data;
|
|
using DevExpress.XtraGrid.Menu;
|
|
using DevExpress.Utils.Menu;
|
|
using System.Data.SqlClient;
|
|
using Lskj.Business;
|
|
using Lskj.Model;
|
|
using Lskj.Core;
|
|
|
|
namespace Lskj.Control
|
|
{
|
|
public partial class AutoGridRevLookUp : TextEdit
|
|
{
|
|
/// <summary>
|
|
/// 是否能直接弹出框
|
|
/// </summary>
|
|
private bool PopShowFlag = true;
|
|
/// <summary>
|
|
/// 是否处理过计算
|
|
/// </summary>
|
|
private bool _Handed;
|
|
/// <summary>
|
|
/// 弹出框最大宽度
|
|
/// </summary>
|
|
private int _maxPopupWidth = 800;
|
|
private string _value;
|
|
private bool _hasRemark = false;
|
|
/// <summary>
|
|
/// 后台线程是否在执行中
|
|
/// </summary>
|
|
private bool _working = false;
|
|
private List<string> _queryQueue = new List<string>();
|
|
private LatestValueWorker<PopupQueryRequest> _queryWorker;
|
|
|
|
private sealed class PopupQueryRequest
|
|
{
|
|
public string SqlValue;
|
|
public bool IsNewPopup;
|
|
}
|
|
/// <summary>
|
|
/// The _popup
|
|
/// </summary>
|
|
public AutoGridRevPopup _popup = null;
|
|
/// <summary>
|
|
/// 新增模糊查询条件
|
|
/// </summary>
|
|
private string AddConditions = string.Empty;
|
|
/// <summary>
|
|
/// 弹出框是否显示
|
|
/// </summary>
|
|
/// <value><c>true</c> if this instance is show popup; otherwise, <c>false</c>.</value>
|
|
public bool IsShowPopup;
|
|
/// <summary>
|
|
/// 弹出框是否自动弹出
|
|
/// </summary>
|
|
/// <value><c>true</c> if this instance is show popup; otherwise, <c>false</c>.</value>
|
|
public bool AutoShowPopup = true;
|
|
/// <summary>
|
|
/// 是否需要自动匹配列宽度
|
|
/// </summary>
|
|
[Description("是否需要自动匹配列宽度")]
|
|
public bool IsBestFitColumns = true;
|
|
/// <summary>
|
|
/// The minimum popup width
|
|
/// </summary>
|
|
[Description("弹出框最小宽度")]
|
|
public int MinPopupWidth;
|
|
/// <summary>
|
|
/// The minimum popup height
|
|
/// </summary>
|
|
[Description("弹出框最小高度")]
|
|
public int MinPopupHeight;
|
|
/// <summary>
|
|
/// The value field
|
|
/// </summary>
|
|
public string ValueField = string.Empty;
|
|
/// <summary>
|
|
/// The value member
|
|
/// </summary>
|
|
[Description("设置ValueMember")]
|
|
public string ValueMember = string.Empty;
|
|
/// <summary>
|
|
/// The text field
|
|
/// </summary>
|
|
[Description("设置TextMember")]
|
|
public string TextMember = string.Empty;
|
|
public string FormKey = string.Empty;
|
|
/// <summary>
|
|
/// The remark text
|
|
/// </summary>
|
|
[Description("设置备注")]
|
|
public string RemarkField = "remark";
|
|
/// <summary>
|
|
/// 数据源
|
|
/// </summary>
|
|
public string SourceSQL = string.Empty;
|
|
/// <summary>
|
|
/// The contro object
|
|
/// </summary>
|
|
public MyControl ControlObj;
|
|
/// <summary>
|
|
/// 控件对象
|
|
/// </summary>
|
|
public ControlModel Model;
|
|
/// <summary>
|
|
/// 隐藏值改变时触发
|
|
/// </summary>
|
|
public event EventHandler HiddenValueChange;
|
|
/// <summary>
|
|
/// 是否为回车或下键显示弹出框
|
|
/// </summary>
|
|
private bool IsKeyDownFocusd = false;
|
|
/// <summary>
|
|
/// 是否已经赋予数据源
|
|
/// </summary>
|
|
public bool IsSetDataSource = false;
|
|
/// <summary>
|
|
/// 搜索回调
|
|
/// </summary>
|
|
public event EventHandler OnSearchCallBack;
|
|
/// <summary>
|
|
/// 隐藏值
|
|
/// </summary>
|
|
/// <value>The value.</value>
|
|
public new string EditValue
|
|
{
|
|
get
|
|
{
|
|
return _value;
|
|
}
|
|
set
|
|
{
|
|
bool TriggerCorrelation = (this._value != value);
|
|
if (this.Model != null && (this.Model.FieldType == ControlType.LabAutoCompleteText || this.Model.FieldType == ControlType.LabAutoCompleteTextParam))
|
|
{
|
|
// 自动搜索框显示名称、自动搜索框显示名称带参数时,直接显示与保存值,此时值可以任意输入,无需匹配数据源.
|
|
this.Text = this._value = value;
|
|
}
|
|
else
|
|
{
|
|
if (this.DataSource != null && this.DataSource is DataTable)
|
|
{
|
|
DataTable table = this.DataSourceTable != null && this.DataSourceTable.Rows.Count > 0 && !SourceSQL.ToLower().StartsWith("exec") ? this.DataSourceTable : this.DataSource as DataTable;
|
|
DataRow rowItem = table.Select("1=1").FirstOrDefault(x => value == x[ValueMember] + "");
|
|
if (rowItem != null)
|
|
{
|
|
this._value = rowItem[ValueMember] + "";
|
|
this.Text = rowItem[TextMember] + "";
|
|
this.SelectionStart = this.Text.Length;
|
|
}
|
|
else
|
|
{
|
|
rowItem = (this.DataSource as DataTable).Select("1=1").FirstOrDefault(x => value == x[TextMember] + "");
|
|
if (rowItem != null)
|
|
{
|
|
this._value = rowItem[ValueMember] + "";
|
|
this.Text = rowItem[TextMember] + "";
|
|
this.SelectionStart = this.Text.Length;
|
|
}
|
|
else
|
|
{
|
|
DataTable refTable = BaseImpl.GetDataTableResult(SourceSQL);
|
|
this.DataSource = refTable;
|
|
this.DataSourceTable = refTable.Copy();
|
|
DataTable newTable = this.DataSourceTable != null && this.DataSourceTable.Rows.Count > 0 && !SourceSQL.ToLower().StartsWith("exec") ? this.DataSourceTable : this.DataSource as DataTable;
|
|
DataRow newRowItem = newTable.Select("1=1").FirstOrDefault(x => value == x[ValueMember] + "");
|
|
if (newRowItem != null)
|
|
{
|
|
this._value = newRowItem[ValueMember] + "";
|
|
this.Text = newRowItem[TextMember] + "";
|
|
this.SelectionStart = this.Text.Length;
|
|
}
|
|
else
|
|
{
|
|
newRowItem = (this.DataSource as DataTable).Select("1=1").FirstOrDefault(x => value == x[TextMember] + "");
|
|
if (newRowItem != null)
|
|
{
|
|
this._value = newRowItem[ValueMember] + "";
|
|
this.Text = newRowItem[TextMember] + "";
|
|
this.SelectionStart = this.Text.Length;
|
|
}
|
|
else
|
|
{
|
|
this._value = string.Empty;
|
|
this.Text = string.Empty;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this._value = string.Empty;
|
|
this.Text = string.Empty;
|
|
}
|
|
}
|
|
if (TriggerCorrelation && this.Model != null && (this.Model.FieldType == ControlType.LabAutoCompleteValue || this.Model.FieldType == ControlType.LabAutoCompleteValueParam || this.Model.FieldType == ControlType.LabAutoCompleteText || this.Model.FieldType == ControlType.LabAutoCompleteTextParam))
|
|
{
|
|
//隐藏值改变后触发关联
|
|
if (HiddenValueChange != null) HiddenValueChange(this, null);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 设置数据源
|
|
/// </summary>
|
|
/// <value>The data source.</value>
|
|
public object DataSource
|
|
{
|
|
get
|
|
{
|
|
return this._popup != null ? this._popup.GridControlObj.DataSource : null;
|
|
}
|
|
set
|
|
{
|
|
if (value != null)
|
|
{
|
|
this._popup.GridControlObj.DataSource = value;
|
|
this._popup.GridViewObj.PopupMenuShowing += new PopupMenuShowingEventHandler(this.OnGridViewPopupMenuShowing);
|
|
this._popup.Model = Model;
|
|
this.SetGridViewColumns(value as DataTable);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 数据源(用于匹配数据)
|
|
/// </summary>
|
|
public DataTable DataSourceTable;
|
|
public string SpeciesValue;
|
|
/// <summary>
|
|
/// <para>说明:隐藏弹出框</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-16 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
public void HidePopup()
|
|
{
|
|
if (this._popup != null)//this.IsShowPopup && this._popup != null
|
|
{
|
|
this.IsShowPopup = false;
|
|
this._popup.Hide();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:显示弹出框</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-16 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
public void ShowPopup()
|
|
{
|
|
try
|
|
{
|
|
if (this.InvokeRequired)
|
|
{
|
|
this.Invoke(new Action(() =>
|
|
{
|
|
if (!this.Properties.ReadOnly && this.Enabled)//!this.Properties.ReadOnly && this.Enabled && !this.IsShowPopup
|
|
{
|
|
if (AutoShowPopup && this._popup != null)
|
|
{
|
|
CalcPopupLocation();
|
|
this.IsShowPopup = true;
|
|
this._popup.Show();
|
|
}
|
|
}
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
if (!this.Properties.ReadOnly && this.Enabled)//!this.Properties.ReadOnly && this.Enabled && !this.IsShowPopup
|
|
{
|
|
if (AutoShowPopup && this._popup != null)
|
|
{
|
|
CalcPopupLocation();
|
|
this.IsShowPopup = true;
|
|
this._popup.Show();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 弹出框
|
|
/// </summary>
|
|
/// <value>The popup.</value>
|
|
[Description("自动搜索弹出框")]
|
|
public AutoGridRevPopup Popup
|
|
{
|
|
get { return this._popup; }
|
|
private set
|
|
{
|
|
_popup = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 界面关闭时
|
|
/// </summary>
|
|
public event EventHandler OnPopupClosed;
|
|
public AutoGridRevLookUp()
|
|
{
|
|
InitializePopup();
|
|
_queryWorker = new LatestValueWorker<PopupQueryRequest>(ExecuteLatestPopupQuery);
|
|
InitializeEvent();
|
|
this.Disposed += OnDisposed;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:初始化事件</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-16 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void InitializeEvent()
|
|
{
|
|
this.GotFocus += new EventHandler(OnAutoGridLookUpGotFocus);
|
|
this.Click += new EventHandler(OnAutoGridRevLookUpMouseClick);
|
|
this.LostFocus += new EventHandler(OnAutoGridLookUpLostFocus);
|
|
this.KeyUp += new KeyEventHandler(OnAutoGridLookUpKeyUp);
|
|
this.TextChanged += AutoGridLookUp_TextChanged;
|
|
//this.Leave += new EventHandler(OnAutoGridLookUpLostFocus);
|
|
this._popup.GridControlObj.LostFocus += new EventHandler(OnAutoGridLookUpLostFocus);
|
|
this._popup.OnGridViewMouseClick += new EventHandler(OnPopupGridViewMouseClick);
|
|
this._popup.OnGridViewEnter += new KeyEventHandler(OnPopupGridViewEnter);
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>说明:初始化弹出框</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-15 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void InitializePopup()
|
|
{
|
|
this._popup = new AutoGridRevPopup();
|
|
this._popup.LookUp = this;
|
|
this._popup.Hide();
|
|
}
|
|
private void CalcFormAndGrid()
|
|
{
|
|
ThreadPool.QueueUserWorkItem(CalcPopupSize, Popup);
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:计算弹出控件位置</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-16 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void CalcPopupLocation()
|
|
{
|
|
this._popup.Parent = this.GetParent(this.Parent);
|
|
Form form = this._popup.Parent as Form;
|
|
if (form != null)
|
|
{
|
|
int iTop = this.Top + this.Height;
|
|
int iLeft = this.Left;
|
|
System.Windows.Forms.Control ctr = this.Parent;
|
|
while (ctr != form)
|
|
{
|
|
iTop += ctr.Top;
|
|
iLeft += ctr.Left;
|
|
ctr = ctr.Parent;
|
|
}
|
|
if (iTop + this.Height + this._popup.Height > ctr.Height)
|
|
{
|
|
if (iTop - this.Height > ctr.Height - iTop)
|
|
{
|
|
if (this._popup.Height > iTop - this.Height)
|
|
{
|
|
this._popup.Height = iTop - this.Height;
|
|
iTop = 0;
|
|
}
|
|
else
|
|
{
|
|
iTop = iTop - this.Height - this._popup.Height;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this._popup.Height = ctr.Height - iTop - 30;
|
|
}
|
|
}
|
|
if (iLeft + this._popup.Width > ctr.Width)
|
|
{
|
|
if (iLeft + this.Width > ctr.Width - iLeft)
|
|
{
|
|
if (this._popup.Width > iLeft + this.Width)
|
|
{
|
|
this._popup.Width = iLeft + this.Width;
|
|
iLeft = 0;
|
|
}
|
|
else
|
|
iLeft = iLeft + this.Width - this._popup.Width;
|
|
}
|
|
else
|
|
this._popup.Width = ctr.Width - iLeft - 30;
|
|
}
|
|
this._popup.Left = iLeft;
|
|
this._popup.Top = iTop;
|
|
}
|
|
this._popup.BringToFront();
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-21 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void HandPopupSqlValue(object searchText)
|
|
{
|
|
if (!string.IsNullOrEmpty(SourceSQL))
|
|
{
|
|
string sqlValue = string.Empty;
|
|
if (SourceSQL.ToLower().StartsWith("exec"))
|
|
{
|
|
// 存储过程处理
|
|
sqlValue = SourceSQL;
|
|
if (sqlValue.Contains("{" + ValueField + "}"))
|
|
sqlValue = sqlValue.Replace("{" + ValueField + "}", searchText + "");
|
|
if (sqlValue.Contains("{" + TextMember + "}"))
|
|
sqlValue = sqlValue.Replace("{" + TextMember + "}", searchText + "");
|
|
if (sqlValue.Contains("{" + RemarkField + "}"))
|
|
sqlValue = sqlValue.Replace("{" + RemarkField + "}", searchText + "");
|
|
if (this.ControlObj != null)
|
|
sqlValue = this.ControlObj.ReplaceControlValue(sqlValue);
|
|
sqlValue = ProcessingSql(sqlValue);
|
|
sqlValue = MainImpl.GetDefaultValue(SourceSQL);
|
|
sqlValue = ReplaceHelper.ReplaceParam(SourceSQL);
|
|
}
|
|
else
|
|
{
|
|
// SQL处理
|
|
string remarkCond = string.Empty;
|
|
bool nonEnglish = false;//是否全是英文
|
|
if (IsChina(searchText + "") || IsNumberic(searchText + ""))
|
|
{
|
|
nonEnglish = true;
|
|
}
|
|
if (this._hasRemark)
|
|
{
|
|
if (nonEnglish)
|
|
{
|
|
remarkCond = string.Format(" or {0} like '%{1}%' ", RemarkField, (searchText + "").Replace("[", "[[]"));
|
|
}
|
|
else
|
|
{
|
|
remarkCond = string.Format(" or {0} like '%{1}%' or dbo.P_getpy({0}) like '%{1}%'", RemarkField, (searchText + "").Replace("[", "[[]"));
|
|
}
|
|
}
|
|
//SourceSQL = ProcessingSql(SourceSQL);
|
|
//SourceSQL = MainImpl.GetDefaultValue(SourceSQL);
|
|
//SourceSQL = ReplaceHelper.ReplaceParam(SourceSQL);//同类似方法
|
|
if (nonEnglish)
|
|
{
|
|
string sql = "select top 500 * from ({0}) temp where {1} like '%{3}%' or {2} like '%{3}%' ";
|
|
sqlValue = string.Format(sql + remarkCond + AddConditions, SourceSQL, ValueField, TextMember, (searchText + "").Replace("[", "[[]"));
|
|
}
|
|
else
|
|
{
|
|
string sql = "select top 500 * from ({0}) temp where {1} like '%{3}%' or {2} like '%{3}%' or dbo.P_getpy({2}) like '%{3}%' ";
|
|
sqlValue = string.Format(sql + remarkCond + AddConditions, SourceSQL, ValueField, TextMember, (searchText + "").Replace("[", "[[]"));
|
|
}
|
|
if (Model != null && !string.IsNullOrEmpty(Model.AddOrderByCond))
|
|
{
|
|
sqlValue = string.Format("{0} {1}", sqlValue, Model.AddOrderByCond);
|
|
}
|
|
sqlValue = MainImpl.GetDefaultValue(sqlValue);
|
|
}
|
|
//带参数sql,处理
|
|
if (this.ControlObj != null && Regex.IsMatch(SourceSQL, ReplaceHelper.ReplaceParamKey))
|
|
{
|
|
string sourceSql = sqlValue;
|
|
// Step 1:替换SpeciesNo
|
|
List<string> condition = ReplaceHelper.GetParamFields(sourceSql);
|
|
if (!string.IsNullOrEmpty(SpeciesValue))
|
|
{
|
|
foreach (string item in condition)
|
|
{
|
|
string field = item.Replace("{", "").Replace("}", "");
|
|
if ("speciesno".Equals(field, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
sourceSql = sourceSql.Replace(item, SpeciesValue);
|
|
}
|
|
}
|
|
}
|
|
// Step 2:替换SpeciesNo
|
|
if (this.ControlObj.CurrentData != null && this.ControlObj.CurrentData.Table.Columns.Contains("SpeciesNo"))
|
|
{
|
|
foreach (string item in condition)
|
|
{
|
|
string field = item.Replace("{", "").Replace("}", "");
|
|
if ("speciesno".Equals(field, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
sourceSql = sourceSql.Replace(item, this.ControlObj.CurrentData["SpeciesNo"] + "");
|
|
}
|
|
}
|
|
}
|
|
sqlValue = ControlObj.ReplaceControlValue(sourceSql.Replace("#", ""));
|
|
}
|
|
QueuePopupQuery(sqlValue, false);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理sql
|
|
/// </summary>
|
|
/// <param name="sqlValue"></param>
|
|
/// <returns></returns>
|
|
private string ProcessingSql(string sqlValue)
|
|
{
|
|
// 带参数sql,处理
|
|
if (this.ControlObj != null && Regex.IsMatch(SourceSQL, ReplaceHelper.ReplaceParamKey))
|
|
{
|
|
string sourceSql = sqlValue;
|
|
// Step 1:替换SpeciesNo
|
|
List<string> condition = ReplaceHelper.GetParamFields(sourceSql);
|
|
if (!string.IsNullOrEmpty(SpeciesValue))
|
|
{
|
|
foreach (string item in condition)
|
|
{
|
|
string field = item.Replace("{", "").Replace("}", "");
|
|
if ("speciesno".Equals(field, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
sourceSql = sourceSql.Replace(item, SpeciesValue);
|
|
}
|
|
}
|
|
}
|
|
// Step 2:替换SpeciesNo
|
|
if (this.ControlObj.CurrentData != null && this.ControlObj.CurrentData.Table.Columns.Contains("SpeciesNo"))
|
|
{
|
|
foreach (string item in condition)
|
|
{
|
|
string field = item.Replace("{", "").Replace("}", "");
|
|
if ("speciesno".Equals(field, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
sourceSql = sourceSql.Replace(item, this.ControlObj.CurrentData["SpeciesNo"] + "");
|
|
}
|
|
}
|
|
}
|
|
|
|
sqlValue = ControlObj.ReplaceControlValue(sourceSql.Replace("#", ""));
|
|
}
|
|
return sqlValue;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <para>说明:刷新弹出框数据</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-05-02 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sqlValue">The SQL value.</param>
|
|
private void RefreshPopupDataSource(object sqlValue)
|
|
{
|
|
try
|
|
{
|
|
if (this.InvokeRequired)
|
|
{
|
|
this.Invoke(new EventHandler(delegate
|
|
{
|
|
this._working = true;
|
|
this.Popup.LabelObj.Text = "正在筛选数据,请稍后...";
|
|
this.Popup.BottomPanelObj.Visible = true;
|
|
this.Popup.GridControlObj.DataSourceTable().Clear();
|
|
}));
|
|
}
|
|
DateTime beginTime = DateTime.Now;
|
|
//DataTable table = MainImpl.GetDataTableResult(sqlValue + "");
|
|
DataTable table = new DataTable();
|
|
if (!string.IsNullOrWhiteSpace(sqlValue + ""))
|
|
{
|
|
try
|
|
{
|
|
table = SqlHelper.ExecuteDataTable(sqlValue + "");
|
|
}
|
|
catch (Exception)
|
|
{
|
|
table = new DataTable();
|
|
}
|
|
}
|
|
DateTime endTime = DateTime.Now;
|
|
if (this._queryQueue.Count > 0)
|
|
{
|
|
string sql = MainImpl.GetDefaultValue(this._queryQueue.Last());
|
|
sql = ReplaceHelper.ReplaceParam(sql);
|
|
// 在检索过程中还存在输入数据,则拿最后一次数据在进行匹配一次
|
|
ThreadPool.QueueUserWorkItem(
|
|
RefreshPopupDataSource,
|
|
sql);
|
|
this._queryQueue.Clear();
|
|
}
|
|
else
|
|
{
|
|
if (this.InvokeRequired)
|
|
{
|
|
this.Invoke(new EventHandler(delegate
|
|
{
|
|
int second = Convert.ToInt32((endTime - beginTime).TotalSeconds);
|
|
string tipMsg = "数据筛选完成.";
|
|
this.Popup.LabelObj.Text = second > 0 ? string.Format(tipMsg + "(耗时{0}秒)", second) : tipMsg;
|
|
this.Popup.GridControlObj.DataSource = table;
|
|
this._working = false;
|
|
this.CalcFormAndGrid();
|
|
}));
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:获取顶层窗口</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-16 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <returns>Control.</returns>
|
|
private Form GetParent(System.Windows.Forms.Control ctr)
|
|
{
|
|
if (ctr == null) return null;
|
|
|
|
return ctr is Form ? ctr as Form : GetParent(ctr.Parent);
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置值</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-16 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void SetValue()
|
|
{
|
|
DataRow rowItem = this._popup.GridViewObj.GetFocusedDataRow();
|
|
if (rowItem != null)
|
|
{
|
|
this.EditValue = rowItem[ValueMember] + "";
|
|
//this.Focus();
|
|
}
|
|
if (this.OnPopupClosed != null)
|
|
this.OnPopupClosed(this, null);
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:根据输入值判断下拉框中是否存在value值</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2020-05-14 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
public string getValueItem(string ItemText)
|
|
{
|
|
string obj = string.Empty;
|
|
DataTable table = this.DataSourceTable;
|
|
DataTable currtable = this.DataSource as DataTable;
|
|
if (table != null)
|
|
{
|
|
DataRow rowItemValue = table.Rows.Cast<DataRow>().FirstOrDefault(x => x[Model.TextMember] + "" == ItemText);
|
|
obj = rowItemValue != null ? rowItemValue[Model.ValueMember] + "" : string.Empty;
|
|
|
|
}
|
|
if (string.IsNullOrEmpty(obj) && currtable != null)
|
|
{
|
|
DataRow rowItemValue = currtable.Rows.Cast<DataRow>().FirstOrDefault(x => x[Model.TextMember] + "" == ItemText);
|
|
obj = rowItemValue != null ? rowItemValue[Model.ValueMember] + "" : string.Empty;
|
|
}
|
|
return obj;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置自定义列</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2019-09-17 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
public virtual void SetCustomColumns()
|
|
{
|
|
if (string.IsNullOrEmpty(this.FormKey) || !BaseImpl.HasExistsTable(ResourceKeys.SettingTableName)) return;
|
|
DataTable customTable = this._popup.GridViewObj.GetCustomColumnByDatabase(this.FormKey);
|
|
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._popup.GridViewObj.Columns.ColumnByName(fieldName);
|
|
if (gridColumn != null && gridColumn.Visible && gridColumn.Width > 0)
|
|
{
|
|
GridColumn colObj = this._popup.GridViewObj.Columns[fieldName];
|
|
colObj.VisibleIndex = index;
|
|
colObj.Width = fieldWidth;
|
|
colObj.Visible = visible;
|
|
colObj.Fixed = isFix ? FixedStyle.Left : FixedStyle.None;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:重置表格属性</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2019-09-17 </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._popup.GridViewObj.ResetCustomColumnToDatabase(FormKey);
|
|
SetGridViewColumns(DataSource as DataTable);
|
|
_Handed = false;
|
|
|
|
this.CalcFormAndGrid();
|
|
|
|
MessageUtil.Show(success ? ResourceKeys.ResetSuccess : ResourceKeys.ResetFault);
|
|
this.ShowPopup();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:保存表格属性</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2019-09-17 </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)
|
|
{
|
|
if (string.IsNullOrEmpty(this.FormKey))
|
|
{
|
|
MessageUtil.Show(ResourceKeys.NotSettingResetColumn);
|
|
return;
|
|
}
|
|
|
|
DataRow rowItem = null;
|
|
bool success = BaseImpl.HasExistsDataRow(ResourceKeys.SettingTableName, "formKey", FormKey, 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._popup.GridViewObj.SaveCustomColumnToDatabase(this.FormKey);
|
|
}
|
|
else
|
|
{
|
|
success = this._popup.GridViewObj.UpdateCustomColumnToDatabase(this.FormKey);
|
|
}
|
|
|
|
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>创建日期:2019-09-11 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></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>
|
|
/// <para>说明:</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-16 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
public void SetGridViewColumns(DataTable table)
|
|
{
|
|
AddConditions = string.Empty;
|
|
this._popup.GridViewObj.Columns.Clear();
|
|
if (table != null && this._popup.GridViewObj.Columns.Count == 0)
|
|
{
|
|
int popWidth = 200;
|
|
GridColumn valueColumn = new GridColumn();
|
|
valueColumn.Name = valueColumn.FieldName = ValueField;
|
|
valueColumn.Caption = "编码";
|
|
valueColumn.Visible = true;
|
|
valueColumn.Width = 60;
|
|
//字段第一个字符为下划线代表不显示
|
|
if (string.IsNullOrEmpty(ValueField) || ValueField.Substring(0, 1) == "_")
|
|
valueColumn.Visible = false;
|
|
|
|
|
|
GridColumn textColumn = new GridColumn();
|
|
textColumn.Name = textColumn.FieldName = TextMember;
|
|
textColumn.Caption = "名称";
|
|
textColumn.Visible = true;
|
|
textColumn.Width = 120;
|
|
//字段第一个字符为下划线代表不显示
|
|
if (string.IsNullOrEmpty(TextMember) || TextMember.Substring(0, 1) == "_")
|
|
textColumn.Visible = false;
|
|
|
|
|
|
this._popup.GridViewObj.Columns.AddRange(new GridColumn[] { valueColumn, textColumn });
|
|
if (table.Columns.IndexOf("remark") != -1)
|
|
{
|
|
DataColumn column = table.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 = "备注";
|
|
remarkColumn.Visible = true;
|
|
remarkColumn.Width = 120;
|
|
//字段第一个字符为下划线代表不显示
|
|
if (RemarkField.Substring(0, 1) == "_")
|
|
remarkColumn.Visible = false;
|
|
this._popup.GridViewObj.Columns.Add(remarkColumn);
|
|
_hasRemark = true;
|
|
}
|
|
|
|
foreach (DataColumn dcol in table.Columns)
|
|
{
|
|
if ((dcol.ColumnName.Substring(0, 1) != "_") && (dcol.ColumnName.ToLower() != ValueField.ToLower()) && (dcol.ColumnName.ToLower() != TextMember.ToLower()) && (dcol.ColumnName.ToLower() != RemarkField.ToLower()) && ((int)dcol.ColumnName[0] > 127))
|
|
{
|
|
GridColumn otherColumn = new GridColumn();
|
|
otherColumn.Name = otherColumn.FieldName = otherColumn.Caption = dcol.ColumnName;
|
|
otherColumn.Visible = true;
|
|
otherColumn.Width = 80;
|
|
this._popup.GridViewObj.Columns.Add(otherColumn);
|
|
AddConditions += "or " + otherColumn.Name + " like '%{3}%'";
|
|
}
|
|
}
|
|
this.SetCustomColumns();
|
|
this._popup.Width = popWidth;
|
|
}
|
|
}
|
|
/// <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>
|
|
protected virtual void CalcPopupSize(object obj)
|
|
{
|
|
if (this._Handed) return;
|
|
this._Handed = true;
|
|
try
|
|
{
|
|
AutoGridRevPopup popupObj = obj as AutoGridRevPopup;
|
|
if (popupObj != null && IsBestFitColumns)
|
|
{
|
|
if (this.InvokeRequired)
|
|
{
|
|
this.Invoke((EventHandler)delegate
|
|
{
|
|
int calcLen = this.Popup.GridViewObj.DataRowCount > 20 ? 20 : this.Popup.GridViewObj.DataRowCount;
|
|
DataTable table = this.Popup.GridControlObj.DataSourceTable();
|
|
bool hasReamrkField = table.Columns.Contains(RemarkField);
|
|
int iValueWidth = 0, iTextWidth = 0, iRemarkWidth = 0, iOtherWidth = 0;
|
|
int iIndexWidth = popupObj.GridViewObj.IndicatorWidth;
|
|
for (int i = 0; i < calcLen; i++)
|
|
{
|
|
string valueValue = ValueMember.Substring(0, 1) != "_" ? table.Rows[i][ValueMember] + "" : "";
|
|
string textValue = TextMember.Substring(0, 1) != "_" ? table.Rows[i][TextMember] + "" : "";
|
|
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.Popup.GridViewObj.Columns)
|
|
{
|
|
if (col.FieldName.Substring(0, 1) != "_" &&
|
|
col.FieldName.ToLower() != ValueField.ToLower() &&
|
|
col.FieldName.ToLower() != TextMember.ToLower() &&
|
|
col.FieldName.ToLower() != RemarkField.ToLower())
|
|
{
|
|
col.Width = col.GetBestWidth();
|
|
iOtherWidth += col.Width;
|
|
}
|
|
}
|
|
// 由于计算有误差,所以计算列结果都加10px
|
|
iValueWidth = iValueWidth < 50 ? 50 : iValueWidth + 10;
|
|
iTextWidth = iTextWidth + 10;
|
|
popupObj.GridViewObj.Columns[ValueMember].Width = iValueWidth;
|
|
popupObj.GridViewObj.Columns[TextMember].Width = iTextWidth;
|
|
if (hasReamrkField)
|
|
{
|
|
popupObj.GridViewObj.Columns[RemarkField].Width = iRemarkWidth;
|
|
iRemarkWidth = iRemarkWidth + 10;
|
|
}
|
|
|
|
int popupWidth = iIndexWidth + iValueWidth + iTextWidth + iRemarkWidth + iOtherWidth + 20;
|
|
if (popupWidth > popupObj.Width)
|
|
popupObj.Width = popupWidth > this._maxPopupWidth ? this._maxPopupWidth : popupWidth;
|
|
//this.CalcPopupLocation();
|
|
this._Handed = false;
|
|
});
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:值为空时弹出搜索界面</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-16 </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 OnAutoGridLookUpGotFocus(object sender, EventArgs e)
|
|
{
|
|
ThreadPool.QueueUserWorkItem(delegate
|
|
{
|
|
while (!this.IsSetDataSource)
|
|
{
|
|
if (IsDisposed || Disposing)
|
|
{
|
|
return;
|
|
}
|
|
Thread.Sleep(10);
|
|
}
|
|
if (IsDisposed || Disposing)
|
|
{
|
|
return;
|
|
}
|
|
this.HandPopupSqlValue(this.Text);
|
|
ShowPopup();
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 鼠标单击控件时
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void OnAutoGridRevLookUpMouseClick(object sender, EventArgs e)
|
|
{
|
|
if (this._popup.Visible == false)
|
|
{
|
|
ThreadPool.QueueUserWorkItem(delegate
|
|
{
|
|
while (!this.IsSetDataSource)
|
|
{
|
|
if (IsDisposed || Disposing)
|
|
{
|
|
return;
|
|
}
|
|
Thread.Sleep(10);
|
|
}
|
|
if (IsDisposed || Disposing)
|
|
{
|
|
return;
|
|
}
|
|
this.HandPopupSqlValue(this.Text);
|
|
ShowPopup();
|
|
});
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-15 </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 OnPopupGridViewEnter(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Enter)
|
|
{
|
|
this.GotFocus -= new EventHandler(OnAutoGridLookUpGotFocus);
|
|
this.HidePopup();
|
|
this.SetValue();
|
|
if (this.OnSearchCallBack != null)
|
|
{
|
|
OnSearchCallBack(this, null);
|
|
}
|
|
this.GotFocus += new EventHandler(OnAutoGridLookUpGotFocus);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:鼠标回调</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-15 </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 OnPopupGridViewMouseClick(object sender, EventArgs e)
|
|
{
|
|
this.GotFocus -= new EventHandler(OnAutoGridLookUpGotFocus);
|
|
this.HidePopup();
|
|
this.SetValue();
|
|
if (this.OnSearchCallBack != null)
|
|
{
|
|
OnSearchCallBack(this, null);
|
|
}
|
|
this.GotFocus += new EventHandler(OnAutoGridLookUpGotFocus);
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:搜索框离开焦点时</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2020-09-16 </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 OnAutoGridLookUpleave(object sender, EventArgs e)
|
|
{
|
|
if (this.Model != null && !string.IsNullOrEmpty(this.Text) && string.IsNullOrEmpty(getValueItem(this.Text)) && (ControlType.LabAutoCompleteValue == Model.FieldType || ControlType.LabAutoCompleteValueParam == Model.FieldType) && !this.IsKeyDownFocusd)
|
|
{
|
|
this.Text = string.Empty;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:失去焦点关闭界面</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-16 </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 OnAutoGridLookUpLostFocus(object sender, EventArgs e)
|
|
{
|
|
if (!this._popup.Focused && !this._popup.GridControlObj.Focused && !this.Focused && !this.IsKeyDownFocusd)
|
|
{
|
|
this.HidePopup();
|
|
}
|
|
if (this.Model != null && !string.IsNullOrEmpty(this.Text) && string.IsNullOrEmpty(getValueItem(this.Text)) && (ControlType.LabAutoCompleteValue == Model.FieldType || ControlType.LabAutoCompleteValueParam == Model.FieldType) && !this.IsKeyDownFocusd)
|
|
{
|
|
this._value = string.Empty;
|
|
this.Text = string.Empty;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:鼠标弹起时刷新数据</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-16 </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="KeyEventArgs"/> instance containing the event data.</param>
|
|
protected void OnAutoGridLookUpKeyUp(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Down)
|
|
{
|
|
this.IsKeyDownFocusd = true;
|
|
this._popup.Focus();
|
|
this.IsKeyDownFocusd = false;
|
|
}
|
|
//this.ShowPopup();
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:判断输入的是否是中文</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-15 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
public bool IsChina(string CString)
|
|
{
|
|
Console.WriteLine("{0}", CString.Length);
|
|
|
|
bool BoolValue = false;
|
|
for (int i = 0; i < CString.Length; i++)
|
|
{
|
|
if (Convert.ToInt32(Convert.ToChar(CString.Substring(i, 1))) > 128)
|
|
{
|
|
BoolValue = true;
|
|
return BoolValue;
|
|
}
|
|
}
|
|
return BoolValue;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断输入的字符串是否存在数字
|
|
/// </summary>
|
|
/// <param name="str"></param>
|
|
/// <returns></returns>
|
|
public static bool IsNumberic(string str)
|
|
{
|
|
try
|
|
{
|
|
bool BoolValue = false;
|
|
for (int i = 0; i < str.Length; i++)
|
|
{
|
|
if (Char.IsNumber(str, i))
|
|
{
|
|
BoolValue = true;
|
|
break;
|
|
}
|
|
|
|
}
|
|
return BoolValue;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 值改变时刷新
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void AutoGridLookUp_TextChanged(object sender, EventArgs e)
|
|
{
|
|
if (PopShowFlag)
|
|
{
|
|
if (SystemInfo.Instance.TrimWhiteSpace)
|
|
this.HandPopupSqlValueNew(this.Text.Trim());//使用原来的方法
|
|
else
|
|
this.HandPopupSqlValueNew(this.Text);
|
|
this.ShowPopup();
|
|
}
|
|
this.PopShowFlag = true;
|
|
}
|
|
|
|
private void HandPopupSqlValueNew(object searchText)
|
|
{
|
|
if (!string.IsNullOrEmpty(SourceSQL))
|
|
{
|
|
// 数据库搜索
|
|
string sqlValue = string.Empty;
|
|
if (SourceSQL.ToLower().StartsWith("exec"))
|
|
{
|
|
// 存储过程处理
|
|
sqlValue = SourceSQL;
|
|
if (sqlValue.Contains("{" + ValueField + "}"))
|
|
sqlValue = sqlValue.Replace("{" + ValueField + "}", searchText + "");
|
|
if (sqlValue.Contains("{" + TextMember + "}"))
|
|
sqlValue = sqlValue.Replace("{" + TextMember + "}", searchText + "");
|
|
if (sqlValue.Contains("{" + RemarkField + "}"))
|
|
sqlValue = sqlValue.Replace("{" + RemarkField + "}", searchText + "");
|
|
if (this.ControlObj != null)
|
|
sqlValue = this.ControlObj.ReplaceControlValue(sqlValue);
|
|
sqlValue = ProcessingSql(sqlValue);
|
|
sqlValue = MainImpl.GetDefaultValue(SourceSQL);
|
|
sqlValue = ReplaceHelper.ReplaceParam(SourceSQL);
|
|
}
|
|
else
|
|
{
|
|
// SQL处理
|
|
string remarkCond = string.Empty;
|
|
bool nonEnglish = false;//是否全是英文
|
|
if (IsChina(searchText + "") || IsNumberic(searchText + ""))
|
|
{
|
|
nonEnglish = true;
|
|
}
|
|
if (this._hasRemark)
|
|
{
|
|
if (nonEnglish)
|
|
{
|
|
remarkCond = string.Format(" or {0} like '%{1}%' ", RemarkField, (searchText + "").Replace("[", "[[]"));
|
|
}
|
|
else
|
|
{
|
|
remarkCond = string.Format(" or {0} like '%{1}%' or dbo.P_getpy({0}) like '%{1}%'", RemarkField, (searchText + "").Replace("[", "[[]"));
|
|
}
|
|
}
|
|
//SourceSQL = ProcessingSql(SourceSQL);
|
|
//SourceSQL = MainImpl.GetDefaultValue(SourceSQL);
|
|
//SourceSQL = ReplaceHelper.ReplaceParam(SourceSQL);//同类似方法
|
|
if (nonEnglish)
|
|
{
|
|
string sql = "select top 500 * from ({0}) temp where {1} like '%{3}%' or {2} like '%{3}%' ";
|
|
sqlValue = string.Format(sql + remarkCond + AddConditions, SourceSQL, ValueField, TextMember, (searchText + "").Replace("[", "[[]"));
|
|
}
|
|
else
|
|
{
|
|
string sql = "select top 500 * from ({0}) temp where {1} like '%{3}%' or {2} like '%{3}%' or dbo.P_getpy({2}) like '%{3}%' ";
|
|
sqlValue = string.Format(sql + remarkCond + AddConditions, SourceSQL, ValueField, TextMember, (searchText + "").Replace("[", "[[]"));
|
|
|
|
}
|
|
if (Model != null && !string.IsNullOrEmpty(Model.AddOrderByCond))
|
|
{
|
|
sqlValue = string.Format("{0} {1}", sqlValue, Model.AddOrderByCond);
|
|
}
|
|
sqlValue = MainImpl.GetDefaultValue(sqlValue);
|
|
}
|
|
//带参数sql,处理
|
|
if (this.ControlObj != null && Regex.IsMatch(SourceSQL, ReplaceHelper.ReplaceParamKey))
|
|
{
|
|
string sourceSql = sqlValue;
|
|
// Step 1:替换SpeciesNo
|
|
List<string> condition = ReplaceHelper.GetParamFields(sourceSql);
|
|
if (!string.IsNullOrEmpty(SpeciesValue))
|
|
{
|
|
foreach (string item in condition)
|
|
{
|
|
string field = item.Replace("{", "").Replace("}", "");
|
|
if ("speciesno".Equals(field, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
sourceSql = sourceSql.Replace(item, SpeciesValue);
|
|
}
|
|
}
|
|
}
|
|
// Step 2:替换SpeciesNo
|
|
if (this.ControlObj.CurrentData != null && this.ControlObj.CurrentData.Table.Columns.Contains("SpeciesNo"))
|
|
{
|
|
foreach (string item in condition)
|
|
{
|
|
string field = item.Replace("{", "").Replace("}", "");
|
|
if ("speciesno".Equals(field, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
sourceSql = sourceSql.Replace(item, this.ControlObj.CurrentData["SpeciesNo"] + "");
|
|
}
|
|
}
|
|
}
|
|
sqlValue = ControlObj.ReplaceControlValue(sourceSql.Replace("#", ""));
|
|
}
|
|
QueuePopupQuery(sqlValue, true);
|
|
}
|
|
}
|
|
|
|
private void QueuePopupQuery(string sqlValue, bool isNewPopup)
|
|
{
|
|
if (_queryWorker == null || IsDisposed || Disposing)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_working = true;
|
|
if (Popup != null)
|
|
{
|
|
Popup.LabelObj.Text = "正在筛选数据,请稍后...";
|
|
Popup.BottomPanelObj.Visible = true;
|
|
Popup.GridControlObj.DataSourceTable().Clear();
|
|
}
|
|
|
|
_queryWorker.Queue(new PopupQueryRequest
|
|
{
|
|
SqlValue = sqlValue,
|
|
IsNewPopup = isNewPopup
|
|
});
|
|
}
|
|
|
|
private void ExecuteLatestPopupQuery(PopupQueryRequest request, int version)
|
|
{
|
|
DateTime beginTime = DateTime.Now;
|
|
DataTable table = new DataTable();
|
|
|
|
if (request != null && !string.IsNullOrWhiteSpace(request.SqlValue))
|
|
{
|
|
try
|
|
{
|
|
table = SqlHelper.ExecuteDataTable(request.SqlValue);
|
|
}
|
|
catch
|
|
{
|
|
table = new DataTable();
|
|
}
|
|
}
|
|
|
|
DateTime endTime = DateTime.Now;
|
|
if (_queryWorker == null || !_queryWorker.IsCurrent(version) || IsDisposed || Disposing || !IsHandleCreated)
|
|
{
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
BeginInvoke(new MethodInvoker(delegate
|
|
{
|
|
if (_queryWorker == null || !_queryWorker.IsCurrent(version) || IsDisposed || Disposing || Popup == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
int second = Convert.ToInt32((endTime - beginTime).TotalSeconds);
|
|
string tipMsg = "数据筛选完成.";
|
|
Popup.LabelObj.Text = second > 0 ? string.Format(tipMsg + "(耗时{0}秒)", second) : tipMsg;
|
|
Popup.GridControlObj.DataSource = table;
|
|
_working = false;
|
|
if (request != null && !request.IsNewPopup)
|
|
{
|
|
CalcFormAndGrid();
|
|
}
|
|
}));
|
|
}
|
|
catch (InvalidOperationException)
|
|
{
|
|
}
|
|
}
|
|
private void RefreshPopupDataSourceNew(object sqlValue)
|
|
{
|
|
try
|
|
{
|
|
if (this.InvokeRequired)
|
|
{
|
|
this.Invoke(new EventHandler(delegate
|
|
{
|
|
this._working = true;
|
|
this.Popup.LabelObj.Text = "正在筛选数据,请稍后...";
|
|
this.Popup.BottomPanelObj.Visible = true;
|
|
this.Popup.GridControlObj.DataSourceTable().Clear();
|
|
}));
|
|
}
|
|
DateTime beginTime = DateTime.Now;
|
|
//DataTable table = MainImpl.GetDataTableResult(sqlValue + "");
|
|
DataTable table = new DataTable();
|
|
if (!string.IsNullOrWhiteSpace(sqlValue + ""))
|
|
{
|
|
try
|
|
{
|
|
table = SqlHelper.ExecuteDataTable(sqlValue + "");
|
|
}
|
|
catch (Exception)
|
|
{
|
|
table = new DataTable();
|
|
}
|
|
}
|
|
DateTime endTime = DateTime.Now;
|
|
|
|
if (this._queryQueue.Count > 0)
|
|
{
|
|
// 在检索过程中还存在输入数据,则拿最后一次数据在进行匹配一次
|
|
ThreadPool.QueueUserWorkItem(
|
|
RefreshPopupDataSourceNew,
|
|
this._queryQueue.Last());
|
|
|
|
this._queryQueue.Clear();
|
|
}
|
|
else
|
|
{
|
|
if (this.InvokeRequired)
|
|
{
|
|
this.Invoke(new EventHandler(delegate
|
|
{
|
|
int second = Convert.ToInt32((endTime - beginTime).TotalSeconds);
|
|
string tipMsg = "数据筛选完成.";
|
|
this.Popup.LabelObj.Text = second > 0 ? string.Format(tipMsg + "(耗时{0}秒)", second) : tipMsg;
|
|
this.Popup.GridControlObj.DataSource = table;
|
|
this._working = false;
|
|
//this.CalcFormAndGrid();
|
|
}));
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 搜索回调
|
|
/// </summary>
|
|
public void SearchCallBack()
|
|
{
|
|
this.HidePopup();
|
|
if (this.OnSearchCallBack != null)
|
|
{
|
|
OnSearchCallBack(this, null);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 注销时
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnDisposed(object sender, EventArgs e)
|
|
{
|
|
if (_queryWorker != null)
|
|
{
|
|
_queryWorker.Dispose();
|
|
_queryWorker = null;
|
|
}
|
|
_working = false;
|
|
_queryQueue.Clear();
|
|
this._popup?.Dispose();
|
|
this._popup = null;
|
|
}
|
|
}
|
|
}
|