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 { /// /// 控件数据源 /// private DataTable _controlTable; /// /// 系统模块实体对象 /// /// The system model. public ModuleModel SysModel { get; private set; } /// /// 调用动态链接库默认传递参数 /// public DynamicModel Model { get; private set; } /// /// 父控件查询对象 /// public MyControl ParentControlObj { get; private set; } /// /// 控件对象 /// public MyControl ControlObj { get; private set; } /// /// 控件高度 /// /// The height of the control. public int ControlHeight { get; private set; } /// /// 控件赋值sql /// public string ControlSql; /// /// 当前获得的条件sql /// public string CondSql { get; private set; } public ModuleConditionsPanelEx() { InitializeComponent(); this.Load += new EventHandler(OnLoad); } /// /// 窗体初始化 /// /// /// private void OnLoad(object sender, EventArgs e) { InitEvent(); } /// /// 初始化事件 /// private void InitEvent() { this.BtnSave.Click += new EventHandler(OnBtnSave_Click); this.BtnClose.Click += new EventHandler(OnBtnClose_Click); } /// /// 说明:初始化模块 /// 创建人:龚宇超 /// 创建日期:2017-11-03 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The menu row. 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); } } /// /// 说明:点击空白处获取焦点 /// 创建人:王一帆 /// 创建日期: /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. 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); } } /// /// 说明:数据绑定完成后加载数据 /// 创建人:龚宇超 /// 创建日期: /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void OnControlObjOnDataSourceBindCallBack(object sender, EventArgs e) { try { this.SetUpdateData(); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:设置修改数据 /// 创建人:龚宇超 /// 创建日期:2017-11-09 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// 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; } /// /// 设置查询条件 /// public string SetSearchSqlValue(string searchSql) { if (this.ControlObj == null) return searchSql; string sqlValue = searchSql; List 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 事件 /// /// 关闭按钮事件 /// /// /// private void OnBtnClose_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; } /// /// 保存按钮事件 /// /// /// 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 } }