ab56a9bcf7
SVN-Revision: r240
301 lines
13 KiB
C#
301 lines
13 KiB
C#
using Lskj.Business;
|
|
using Lskj.Business.Impl;
|
|
using Lskj.Control.Model;
|
|
using Lskj.Model;
|
|
using Lskj.Util;
|
|
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;
|
|
|
|
namespace Lskj.Control
|
|
{
|
|
public partial class ModuleConditionsPanelEx : BaseForm
|
|
{
|
|
/// <summary>
|
|
/// 控件数据源
|
|
/// </summary>
|
|
private DataTable _controlTable;
|
|
/// <summary>
|
|
/// 系统模块实体对象
|
|
/// </summary>
|
|
/// <value>The system model.</value>
|
|
public ModuleModel SysModel { get; private set; }
|
|
/// <summary>
|
|
/// 调用动态链接库默认传递参数
|
|
/// </summary>
|
|
public DynamicModel Model { get; private set; }
|
|
/// <summary>
|
|
/// 父控件查询对象
|
|
/// </summary>
|
|
public MyControl ParentControlObj { get; private set; }
|
|
/// <summary>
|
|
/// 控件对象
|
|
/// </summary>
|
|
public MyControl ControlObj { get; private set; }
|
|
/// <summary>
|
|
/// 控件高度
|
|
/// </summary>
|
|
/// <value>The height of the control.</value>
|
|
public int ControlHeight { get; private set; }
|
|
/// <summary>
|
|
/// 控件赋值sql
|
|
/// </summary>
|
|
public string ControlSql;
|
|
/// <summary>
|
|
/// 当前获得的条件sql
|
|
/// </summary>
|
|
public string CondSql { get; private set; }
|
|
public ModuleConditionsPanelEx()
|
|
{
|
|
InitializeComponent();
|
|
this.Load += new EventHandler(OnLoad);
|
|
}
|
|
/// <summary>
|
|
/// 窗体初始化
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnLoad(object sender, EventArgs e)
|
|
{
|
|
InitEvent();
|
|
}
|
|
/// <summary>
|
|
/// 初始化事件
|
|
/// </summary>
|
|
private void InitEvent()
|
|
{
|
|
this.BtnSave.Click += new EventHandler(OnBtnSave_Click);
|
|
this.BtnClose.Click += new EventHandler(OnBtnClose_Click);
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:初始化模块</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-11-03 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="menuRow">The menu row.</param>
|
|
public void InitializeControl(ModuleModel sysModel, DynamicModel dyncModel, MyControl myControl, bool IsAutoScroll = false)
|
|
{
|
|
try
|
|
{
|
|
if (sysModel != null)
|
|
{
|
|
this.SysModel = sysModel;
|
|
this.Model = dyncModel;
|
|
this.ParentControlObj = myControl;
|
|
this._controlTable = BaseModuleImpl.GetCustomQueryFields(this.SysModel.CondKey);//加载自定义配置字段
|
|
//this._controlTable = BaseModuleImpl.GetControlLocation(this.SysModel.FormKey, this.Model.ModuleCode);
|
|
this.pl_main.Click += new EventHandler(OnMainClick);
|
|
this.ControlObj = new MyControl()
|
|
{
|
|
SystemModel = sysModel,
|
|
};
|
|
int parentWidth;
|
|
int parentHeight;
|
|
this.ControlObj.InitControl(this._controlTable, this.pl_main, BaseModuleImpl.GetAddGroupData(this.SysModel.FormKey), out parentHeight, out parentWidth, true);//divider
|
|
this.Height = parentHeight + 90;
|
|
this.Width = parentWidth + 20;
|
|
this.pl_main.AutoScroll = IsAutoScroll;
|
|
this.pl_main.HorizontalScroll.Visible = false;//设置禁止水平滚动条
|
|
//this.ControlObj.OnDataSourceBindCallBack += new EventHandler(OnControlObjOnDataSourceBindCallBack);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
}
|
|
/// <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>
|
|
private void OnMainClick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
this.pl_main.Focus();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
}
|
|
/// <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>
|
|
private void OnControlObjOnDataSourceBindCallBack(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
this.SetUpdateData();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置修改数据</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-11-09 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void SetUpdateData()
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(this.ControlSql))
|
|
{
|
|
DataRow rowItem = BaseImpl.GetDataRowResult(this.ControlSql);
|
|
this.ControlObj.SetAllControlValue(rowItem);
|
|
this.ControlObj.SyncLocalModel();
|
|
}
|
|
this.ControlObj.CanExecControl = true;
|
|
}
|
|
/// <summary>
|
|
/// 设置查询条件
|
|
/// </summary>
|
|
public string SetSearchSqlValue(string searchSql)
|
|
{
|
|
if (this.ControlObj == null) return searchSql;
|
|
string sqlValue = searchSql;
|
|
List<string> paramList = ReplaceHelper.GetParamFields(sqlValue);
|
|
if (ReplaceHelper.IsProcedure(sqlValue))
|
|
{
|
|
foreach (string item in paramList)
|
|
{
|
|
string fileName = item.Replace("{", "").Replace("}", "");
|
|
sqlValue = sqlValue.Replace(item, this.ControlObj.GetControlValue(fileName));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
StringBuilder strWhere = new StringBuilder();
|
|
// 自定义查询条件处理
|
|
foreach (DataRow dr in this._controlTable.Rows)
|
|
{
|
|
int fieldTypeId = Convert.ToInt32(dr["fieldTypeId"] + "");
|
|
string cond = dr["checkCond"] + "";
|
|
string fieldName = dr["fieldName"].ToString().Replace("{", "").Replace("}", "");
|
|
string fieldValue = this.ControlObj.GetControlValue(fieldName);
|
|
// 处理sql中的配置参数
|
|
foreach (string item in paramList)
|
|
{
|
|
if (item.Contains("{#") && fieldName.Equals(item.Replace("{#", "").Replace("}", ""), StringComparison.OrdinalIgnoreCase))
|
|
sqlValue = sqlValue.Replace(item, fieldValue);
|
|
if (item.Contains("{") && fieldName.Equals(item.Replace("{", "").Replace("}", ""), StringComparison.OrdinalIgnoreCase))
|
|
sqlValue = sqlValue.Replace(item, fieldValue);
|
|
}
|
|
}
|
|
// 自定义查询条件处理
|
|
foreach (DataRow dr in this._controlTable.Rows)
|
|
{
|
|
int fieldTypeId = Convert.ToInt32(dr["fieldTypeId"] + "");
|
|
string cond = dr["checkCond"] + "";
|
|
string fieldName = dr["fieldName"].ToString().Replace("{", "").Replace("}", "");
|
|
string fieldValue = this.ControlObj.GetControlValue(fieldName, true);
|
|
if (string.IsNullOrWhiteSpace(fieldValue)) continue;
|
|
if (SystemInfo.Instance.TrimWhiteSpace)
|
|
cond = ReplaceHelper.ReplaceSearchControlCond(cond, fieldValue.Trim());
|
|
else
|
|
cond = ReplaceHelper.ReplaceSearchControlCond(cond, fieldValue);
|
|
// 带复选框控件构造sql语句时,假如没有值,则不构造查询条件
|
|
if ((fieldTypeId == ControlType.LabCheckAutoSeacherText ||
|
|
fieldTypeId == ControlType.LabCheckAutoSeacherValue ||
|
|
fieldTypeId == ControlType.LabCheckBox ||
|
|
fieldTypeId == ControlType.LabCheckComboxText ||
|
|
fieldTypeId == ControlType.LabCheckComboxValue ||
|
|
fieldTypeId == ControlType.LabCheckDateEx ||
|
|
fieldTypeId == ControlType.LabCheckDateTimeEx ||
|
|
fieldTypeId == ControlType.LabCheckDateTimeShort ||
|
|
fieldTypeId == ControlType.LabCheckShortTime ||
|
|
fieldTypeId == ControlType.LabCheckTime ||
|
|
fieldTypeId == ControlType.LabCheckMultiSelectValue ||
|
|
fieldTypeId == ControlType.LabCheckText ||
|
|
fieldTypeId == ControlType.LabCheckMultiSelectText) && string.IsNullOrWhiteSpace(fieldValue))
|
|
{
|
|
cond = "";
|
|
}
|
|
// 处理sql中的配置参数
|
|
foreach (string item in paramList)
|
|
{
|
|
if (item.Contains("{&") && fieldName.Equals(item.Replace("{&", "").Replace("}", ""), StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
sqlValue = sqlValue.Replace(item, cond);
|
|
cond = "";
|
|
}
|
|
if (item.Contains("{") && fieldName.Equals(item.Replace("{", "").Replace("}", ""), StringComparison.OrdinalIgnoreCase))
|
|
sqlValue = sqlValue.Replace(item, fieldValue);
|
|
}
|
|
strWhere.Append(" " + cond);
|
|
}
|
|
sqlValue = ReplaceHelper.ReplaceWhereCond(sqlValue) + strWhere.ToString();
|
|
}
|
|
return sqlValue;
|
|
}
|
|
#region 事件
|
|
/// <summary>
|
|
/// 关闭按钮事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnBtnClose_Click(object sender, EventArgs e)
|
|
{
|
|
this.DialogResult = DialogResult.Cancel;
|
|
}
|
|
/// <summary>
|
|
/// 保存按钮事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnBtnSave_Click(object sender, EventArgs e)
|
|
{
|
|
string sqlValue = this.SysModel.MenuSql;
|
|
sqlValue = ReplaceHelper.ReplaceUserInfo(sqlValue);
|
|
sqlValue = ReplaceHelper.ReplaceWhereCond(sqlValue);
|
|
sqlValue = SetSearchSqlValue(sqlValue);
|
|
this.CondSql = sqlValue;
|
|
this.DialogResult = DialogResult.OK;
|
|
}
|
|
public void ReplaceParentControlObj(MyControl parentControlObj)
|
|
{
|
|
foreach (ControlModel controlModel in this.ControlObj.ControlModels)
|
|
{
|
|
BaseUserControl baseControl = parentControlObj.FindControl(controlModel.FieldName);
|
|
if (baseControl != null)
|
|
{
|
|
parentControlObj.SetControlValue(controlModel.FieldName, this.ControlObj.GetControlValue(controlModel.FieldName));
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|