2260 lines
106 KiB
C#
2260 lines
106 KiB
C#
using DevExpress.Utils;
|
|
using DevExpress.XtraEditors;
|
|
using DevExpress.XtraGrid.Columns;
|
|
using DevExpress.XtraGrid.Views.Grid;
|
|
using DevExpress.XtraTab;
|
|
using Lskj.Business;
|
|
using Lskj.Business.Impl;
|
|
using Lskj.Control;
|
|
using Lskj.Control.Model;
|
|
using Lskj.Core;
|
|
using Lskj.Data;
|
|
using Lskj.Model;
|
|
using Lskj.PubProductSmart.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.Text.RegularExpressions;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Lskj.PubProductSmart
|
|
{
|
|
public partial class FrmMain : BaseForm
|
|
{
|
|
#region 私有变量
|
|
/// <summary>
|
|
/// 左侧树数据
|
|
/// </summary>
|
|
private DataRow LeftTreeRow;
|
|
/// <summary>
|
|
/// 左侧树主键关联右侧数据字段
|
|
/// </summary>
|
|
private string ParentUnionField;
|
|
/// <summary>
|
|
/// 左侧树字段
|
|
/// </summary>
|
|
private string _leftField;
|
|
/// <summary>
|
|
/// 表格列
|
|
/// </summary>
|
|
private DataTable _gridColumns = new DataTable();
|
|
/// <summary>
|
|
/// The _grid all columns
|
|
/// </summary>
|
|
private DataTable _gridAllColumns = new DataTable();
|
|
/// <summary>
|
|
/// 必须录入字段
|
|
/// </summary>
|
|
private DataRow[] _nullFields = new DataRow[] { };
|
|
/// <summary>
|
|
/// 左侧表格列字段
|
|
/// </summary>
|
|
private DataRow _leftGridField;
|
|
/// <summary>
|
|
/// 方案id
|
|
/// </summary>
|
|
private string projectId;
|
|
/// <summary>
|
|
/// 动态控件对象集合
|
|
/// </summary>
|
|
private List<SysSetModel> ControlList = new List<SysSetModel>();
|
|
#endregion
|
|
#region 公有变量
|
|
/// <summary>
|
|
/// 共有入口参数
|
|
/// </summary>
|
|
public DynamicProductSmartModel Model;
|
|
/// <summary>
|
|
/// 主表数据类
|
|
/// </summary>
|
|
public ModuleModel MainModuleObj;
|
|
/// <summary>
|
|
/// 主模块控件对象
|
|
/// </summary>
|
|
public MyControl MainControlObj;
|
|
/// <summary>
|
|
/// 主表条件类
|
|
/// </summary>
|
|
public MyControl SearchMainObj;
|
|
/// <summary>
|
|
/// 底部多标签表格数据
|
|
/// </summary>
|
|
public List<GridDetailModel> GridDetailList;
|
|
/// <summary>
|
|
/// 主键
|
|
/// </summary>
|
|
public string ParmaryKey;
|
|
/// <summary>
|
|
/// 动态模块对象
|
|
/// </summary>
|
|
private MyControl TopControlObj;
|
|
/// <summary>
|
|
/// 控件表
|
|
/// </summary>
|
|
private DataTable ControlTable = new DataTable();
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private List<SimpleButton> rightBtn = new List<SimpleButton>();
|
|
protected bool mLoading = false;
|
|
protected System.Windows.Forms.Timer mTimer = new System.Windows.Forms.Timer();
|
|
/// <summary>
|
|
/// 禁止控件值改变反写事件(执行 行选中改变控件)
|
|
/// </summary>
|
|
private bool CloseReverseWriting=false;
|
|
|
|
#endregion
|
|
public FrmMain(DynamicProductSmartModel model = null)
|
|
{
|
|
InitializeComponent();
|
|
this.Model = model != null ? model : null;
|
|
}
|
|
#region 方法
|
|
/// <summary>
|
|
/// 初始化事件绑定
|
|
/// </summary>
|
|
private void InitEvent()
|
|
{
|
|
this.splitMainContainer.SplitterPositionChanged += OnSplitMainContainerPositionChanged;
|
|
this.splitRightContainer.SplitterPositionChanged += OnSplitMainContainerPositionChanged;
|
|
this.splitDynamicContainer.SplitterPositionChanged += OnSplitMainContainerPositionChanged;
|
|
this.splitRightUpAndDownContainer.SplitterPositionChanged += OnSplitMainContainerPositionChanged;
|
|
this.pl_Top.Click += OnScrollableControlClick;
|
|
this.btnSave.Click += OnBtnSaveClick;
|
|
this.btnUpdate.Click += OnBtnUpdateClick;
|
|
this.gcMain.GridView.RowClick += GridView_FocusedRowObjectChanged;
|
|
//this.gcMain.GridView.OptionsBehavior.EditorShowMode = DevExpress.Utils.EditorShowMode.MouseDown;
|
|
//this.gcMain.GridView.RowCellClick += GridView_RowClick;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 初始化左侧控件
|
|
/// </summary>
|
|
private void InitLeftControl()
|
|
{
|
|
this.InitlizeSpiltLocation();//设置分割条位置
|
|
WaitForm.ShowForm();
|
|
try
|
|
{
|
|
this.Model.Privilege = this.Model.Privilege.Equals("3") ? "1" : Model.ModuleId > 0 ? BaseImpl.GetUserPurviewsByMenuId(Model.ModuleId + "") + "" : BaseImpl.GetUserPurviewsByMenuCode(Model.ModuleCode) + "";// 权限(1.有操作权限.0.无权限.2.只读权限.3.右键配置权限全部开放)
|
|
DataRow modelRow = MainImpl.GetSystemdllTab(this.Model.ModuleCode);//获取单个模块信息
|
|
if (modelRow == null)
|
|
{
|
|
MessageUtil.Show("模块编号[" + this.Model.ModuleCode + "],配置错误!\r\n该模块信息未找到!");
|
|
return;
|
|
}
|
|
this.MainModuleObj = new ModuleModel(modelRow);//系统模块实体对象
|
|
switch (this.MainModuleObj.MenuType)
|
|
{
|
|
case 1:
|
|
case 4://左侧为树节点
|
|
this.SetLeftTreeView();//设置左侧树数据
|
|
if (this.MainModuleObj.IsHideTreeViewBoxs)
|
|
{
|
|
this.treeLeftViewEx.TreeView.CheckBoxes = false;
|
|
}
|
|
break;
|
|
case 3://左侧为空
|
|
default:
|
|
this.splitMainContainer.PanelVisibility = SplitPanelVisibility.Panel2;
|
|
break;
|
|
}
|
|
//隐藏中间下方浏览器
|
|
this.splitDynamicContainer.PanelVisibility = SplitPanelVisibility.Panel1;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
WaitForm.HideForm();
|
|
}
|
|
/// <summary>
|
|
/// 初始化主模块控件
|
|
/// </summary>
|
|
private void InitMainControl()
|
|
{
|
|
this.TopControlObj = new MyControl()
|
|
{
|
|
ParentPanel = this.pl_Top
|
|
};
|
|
|
|
|
|
this.GridDetailList = GetDetails();
|
|
this._leftField = BaseModuleImpl.GetBaseLeftField(this.Model.ModuleCode);
|
|
this.ParmaryKey = BaseImpl.GetBasePrimaryKey(this.Model.ModuleCode);//获取主键
|
|
this._gridColumns = BaseModuleImpl.GetBaseGridColumns(this.Model.ModuleCode);//获取主表列数据
|
|
this._gridAllColumns = BaseModuleImpl.GetBaseGridAllColumns(this.Model.ModuleCode);//获取所有列数据
|
|
if (this._gridColumns != null && this._gridColumns.Rows.Count > 0)
|
|
{
|
|
this._nullFields = this._gridColumns.Select("nullable=1");
|
|
this._leftGridField = this._gridColumns.Select("fieldsqlTag=3").FirstOrDefault();
|
|
}
|
|
this.frmWebBrowser.FrmLoad("");//初始化浏览器
|
|
this.InitializeGridView();
|
|
this.InitializePages();
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:初始化表格操作</para>
|
|
/// <para>创建人:唐德馨</para>
|
|
/// <para>创建日期:2023-10-13 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void InitializeGridView(bool ProcessExists = false)
|
|
{
|
|
this.gcMain.Model = this.Model;
|
|
if (MainModuleObj.CanEdit)
|
|
{
|
|
this.gcMain.SetEditColumns(this._gridColumns, GridCustomColumnStruct.BaseMainGridView + this.MainModuleObj.FormKey);
|
|
}
|
|
else
|
|
{
|
|
this.gcMain.SetReadOnlyColumns(this._gridColumns, GridCustomColumnStruct.BaseMainGridView + this.MainModuleObj.FormKey);
|
|
}
|
|
this.gcMain.SetGridRowColors(BaseModuleImpl.GetBaseGridRowColors(this.Model.ModuleCode));//设置表格颜色
|
|
this.gcMain.SetGridRightMenus(BaseModuleImpl.GetBaseGridRightMenus(this.Model.ModuleCode), Model, null, null);//设置表格菜单
|
|
if (this.MainModuleObj.MenuType == 1 || this.MainModuleObj.MenuType == 4)
|
|
{
|
|
this.SearchMainObj = new MyControl(this.MainModuleObj.MenuSql, gcMain, this.treeLeftViewEx, null, null);
|
|
}
|
|
else
|
|
{
|
|
this.SearchMainObj = new MyControl(this.MainModuleObj.MenuSql, gcMain, null, null, null);
|
|
}
|
|
this.SearchMainObj.OtherParams = Model.OtherParams();
|
|
this.SearchMainObj.OnSearchAfterCallBack += OnSearchAfterCallBack;
|
|
this.SearchMainObj.OnDataSourceBindCallBack += SearchMainObj_OnDataSourceBindCallBack;
|
|
this.SearchMainObj.ParentUnionField = this.ParentUnionField;
|
|
DataTable queryTable = BaseModuleImpl.GetCustomQueryFields(this.MainModuleObj.CondKey);//获取主模块构建的条件
|
|
if (queryTable != null && queryTable.Rows.Count > 0)
|
|
{
|
|
// 加载自定义查询条件
|
|
this.plm_top_cond.Visible = true;
|
|
this.plm_top_cond.Controls.Clear();
|
|
int height = this.SearchMainObj.InitSearchControl(queryTable, this.plm_top_cond, null, null, false);
|
|
this.plm_top_cond.Height = height;
|
|
this.SearchMainObj.ButtonObj.Visible = true;
|
|
System.Windows.Forms.Control control = this.plm_top_cond.Controls.Find("btnCondSearch", true).FirstOrDefault();
|
|
this.plm_top_cond.Width = control.Location.X;
|
|
}
|
|
|
|
//右键
|
|
DataTable RightDt = BaseModuleImpl.GetBaseGridRightMenus(this.Model.ModuleCode);
|
|
int x = this.btnSave.Location.X;
|
|
foreach (DataRow item in RightDt.Rows)
|
|
{
|
|
SimpleButton itemCommon = new SimpleButton();
|
|
//itemCommon.AutoSize = true;
|
|
itemCommon.Text = item["menuname"] + "";
|
|
itemCommon.Tag = item;
|
|
itemCommon.Size = new System.Drawing.Size(110, 26);
|
|
itemCommon.Click += new EventHandler(itemCommon_Click);
|
|
itemCommon.Location = new Point(x - 6 - 110, 6);
|
|
itemCommon.Anchor= ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
|
x = x - itemCommon.Width - 6;
|
|
plm_bot_btn.Controls.Add(itemCommon);
|
|
rightBtn.Add(itemCommon);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <para>说明:获取查询条件</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-11-22 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="model">The model.</param>
|
|
/// <param name="rowItem">The row item.</param>
|
|
/// <returns>System.String.</returns>
|
|
protected string GetSearchSql(GridDetailModel model, DataRow rowItem, bool isLeft = false)
|
|
{
|
|
string fieldName = !string.IsNullOrEmpty(model.UnionParentField) && rowItem.Table.Columns.Contains(model.UnionParentField) ? model.UnionParentField : this.ParmaryKey;
|
|
|
|
string sqlValue = model.IsReadOnly || model.IsChart ? model.DetailSql : model.SystemModel.MenuSql;
|
|
|
|
|
|
sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, sqlValue);
|
|
DataRow row = this.gcMain.GetViewFocusedDataRow();
|
|
if (row != null && isLeft)
|
|
{
|
|
//先替换左侧选中行,在替换主表
|
|
sqlValue = ReplaceHelper.ReplaceRowParam(row, sqlValue);
|
|
}
|
|
|
|
if (ReplaceHelper.IsSelect(sqlValue) && !string.IsNullOrEmpty(model.UnionValue))
|
|
{
|
|
string Conditions = string.Empty;
|
|
//是左侧选中行,并且没有替换字段,则使用主表选中行
|
|
Conditions = isLeft ? rowItem.Table.Columns.Contains(fieldName) ? rowItem[fieldName] + "" : row[fieldName] + "" : rowItem[fieldName] + "";
|
|
|
|
sqlValue = ReplaceHelper.ReplaceWhereCond(sqlValue) + string.Format(" and {0}='{1}'", model.UnionValue, Conditions);
|
|
|
|
}
|
|
if (!string.IsNullOrEmpty(model.UnionCond))
|
|
{
|
|
string UnionCond = ReplaceHelper.ReplaceRowParam(rowItem, model.UnionCond);
|
|
sqlValue += UnionCond;
|
|
}
|
|
return sqlValue;
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 设置选中行控件值
|
|
/// </summary>
|
|
private void SetRowControlValues()
|
|
{
|
|
try
|
|
{
|
|
//根据主表选中行给左侧控件赋值
|
|
DataRow dr = this.gcMain.GetViewFocusedDataRow();
|
|
if (dr != null)
|
|
{
|
|
//this.CloseReverseWriting = true;
|
|
List<BaseUserControl> modelControls = this.pl_Top.Controls.Cast<BaseUserControl>().Where(n => !string.IsNullOrEmpty((n.Tag as SysSetModel).DbName)).OrderBy(n => (n.Tag as SysSetModel).OrderId).ToList();
|
|
foreach (BaseUserControl item in modelControls)
|
|
{
|
|
SysSetModel sysSetModel = item.Tag as SysSetModel;
|
|
string controlName = !string.IsNullOrWhiteSpace(sysSetModel.DbName) ? sysSetModel.DbName : sysSetModel.SysName;
|
|
if (dr.Table.Columns.Contains(controlName))
|
|
{
|
|
this.SetControlValue(controlName, dr[sysSetModel.DbName]);
|
|
}
|
|
else
|
|
{
|
|
this.SetControlValue(controlName, "");
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
finally
|
|
{
|
|
//this.CloseReverseWriting = false;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>说明:初始化多标签数据</para>
|
|
/// <para>创建人:唐德馨</para>
|
|
/// <para>创建日期:2024-1-5 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void InitializePages()
|
|
{
|
|
if (this.GridDetailList != null || this.GridDetailList.Count > 0)
|
|
this.tabMain.Model = this.Model;
|
|
this.tabMain.DrgaParentPrimaryKey = this.MainModuleObj.ParmaryKey;
|
|
this.tabMain.ParentGridEx = this.gcMain;
|
|
this.tabMain.InitTabPages(this.GridDetailList);
|
|
//明细只有一个选项卡时是否隐藏
|
|
if (SystemInfo.Instance.HidingIndividualDetails)
|
|
{
|
|
this.tabMain.TabControlObj.ShowTabHeader = this.tabMain.TabControlObj.TabPages.Count == 1 ? DefaultBoolean.False : DefaultBoolean.Default;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 初始化数据
|
|
/// </summary>
|
|
private void InitlizeData()
|
|
{
|
|
if (Model.IsAddOrUpdate.Equals("1"))//修改
|
|
{
|
|
this.btnSave.Enabled = false;
|
|
}
|
|
|
|
|
|
//SelectDatatable();
|
|
//if (Model.IsAddOrUpdate.Equals("1"))//修改
|
|
//{
|
|
// string primaryKey = BaseImpl.GetBasePrimaryKey(this.Model.ModuleCode);
|
|
// string primaryVlaue = Model.PrimaryValue;
|
|
// DataRow selectSource = MainImpl.GetDataRowResult(string.Format("select * from {0} where {1} = '{2}'", MainModuleObj.MenuTable, primaryKey, primaryVlaue));
|
|
// List<BaseUserControl> modelControls = this.pl_Top.Controls.Cast<BaseUserControl>().Where(n => !string.IsNullOrEmpty((n.Tag as SysSetModel).DbName)).OrderBy(n => (n.Tag as SysSetModel).OrderId).ToList();
|
|
// foreach (BaseUserControl item in modelControls)
|
|
// {
|
|
// SysSetModel sysSetModel = item.Tag as SysSetModel;
|
|
// string value = selectSource.Table.Columns.Contains(sysSetModel.DbName) ? selectSource[sysSetModel.DbName] + "" : "";
|
|
// double doubleValue;
|
|
// if (double.TryParse(value, out doubleValue))
|
|
// {
|
|
// item.EditText = doubleValue + "";
|
|
// }
|
|
// else
|
|
// {
|
|
// item.EditText = value;
|
|
// }
|
|
// }
|
|
//}
|
|
}
|
|
/// <summary>
|
|
/// 数据源添加空行
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private void SelectDatatable()
|
|
{
|
|
DataTable dataTable = this.gcMain.GridControl.DataSourceTable();
|
|
DataTable newSourceTab = dataTable.Clone();
|
|
DataRow dataRow = newSourceTab.NewRow();
|
|
//处理默认值(目前只替换全局参数和条件值)
|
|
foreach (GridColumn col in this.gcMain.GridView.Columns)
|
|
{
|
|
// 未包含字段,则使用控件默认值.
|
|
GridColumnModel model = col.Tag as GridColumnModel;
|
|
string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue);
|
|
if (model.DefaultValue != null && model.DefaultValue.Contains("{#"))
|
|
{
|
|
fieldValue = this.SearchMainObj.ReplaceParentControlValue(model.DefaultValue);
|
|
|
|
}
|
|
if (model.DefaultValue != null && !string.IsNullOrEmpty(fieldValue))
|
|
{
|
|
dataRow[col.FieldName] = fieldValue;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
newSourceTab.Rows.Add(dataRow);
|
|
this.gcMain.SetGridViewDataSource(newSourceTab);
|
|
}
|
|
/// <summary>
|
|
/// 设置分割条位置
|
|
/// </summary>
|
|
private void InitlizeSpiltLocation()
|
|
{
|
|
try
|
|
{
|
|
string splitMainWidth = IniHelper.Read(string.Format("PubProductSmart_SplitMain_{0}", this.Model.ModuleCode));//通过Key获取Value值
|
|
if (!string.IsNullOrEmpty(splitMainWidth))
|
|
{
|
|
this.splitMainContainer.SplitterPosition = Convert.ToInt32(splitMainWidth);
|
|
}
|
|
string splitRightWidth = IniHelper.Read(string.Format("PubProductSmart_SplitRight_{0}", this.Model.ModuleCode));//通过Key获取Value值
|
|
if (!string.IsNullOrEmpty(splitRightWidth))
|
|
{
|
|
this.splitRightContainer.SplitterPosition = Convert.ToInt32(splitRightWidth);
|
|
}
|
|
string splitControlWidth = IniHelper.Read(string.Format("PubProductSmart_SplitDynamic_{0}", this.Model.ModuleCode));//通过Key获取Value值
|
|
if (!string.IsNullOrEmpty(splitMainWidth))
|
|
{
|
|
this.splitDynamicContainer.SplitterPosition = Convert.ToInt32(splitControlWidth);
|
|
}
|
|
string SplitRightUpAndDownWidth = IniHelper.Read(string.Format("PubProductSmart_SplitRightUpAndDown_{0}", this.Model.ModuleCode));//通过Key获取Value值
|
|
if (!string.IsNullOrEmpty(SplitRightUpAndDownWidth))
|
|
{
|
|
this.splitRightUpAndDownContainer.SplitterPosition = Convert.ToInt32(SplitRightUpAndDownWidth);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageUtil.Show(ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 设置左侧树数据
|
|
/// </summary>
|
|
private void SetLeftTreeView()
|
|
{
|
|
this.LeftTreeRow = BaseModuleImpl.GetBaseLeftTreeField(this.Model.ModuleCode);//获取表格左侧树字段
|
|
if (this.LeftTreeRow != null)
|
|
{
|
|
this.ParentUnionField = this.LeftTreeRow["fieldname"] + "";
|
|
string parentKeyField = this.LeftTreeRow["fieldsqlid"] + "";
|
|
this.treeLeftViewEx.TreeNodeKeyField = parentKeyField;
|
|
this.treeLeftViewEx.TreeNodeTextField = this.LeftTreeRow["fieldsqlname"] + "";
|
|
this.treeLeftViewEx.OnTreeNodeMouseClick += new TreeNodeMouseClickEventHandler(OnTreeLeftTreeNodeSelected);
|
|
this.treeLeftViewEx.TreeNodeLength = this.LeftTreeRow.Table.Columns.Contains("TreeNodeLength") ? this.LeftTreeRow["TreeNodeLength"] + "" : "";
|
|
this.treeLeftViewEx.BindTreeView(BaseImpl.GetDataTableResult(this.LeftTreeRow["fieldsql"] + ""));
|
|
if (this.LeftTreeRow.Table.Columns.Contains("TreeNodeSearch") && "1".Equals(this.LeftTreeRow["TreeNodeSearch"] + "")) this.treeLeftViewEx.pl_top.Visible = true;
|
|
}
|
|
else
|
|
{
|
|
// 根据模块上配置的sql加载树
|
|
if (this.MainModuleObj != null && !string.IsNullOrEmpty(this.MainModuleObj.TreeSQL))
|
|
{
|
|
this.ParentUnionField = "SpeciesNo";
|
|
string parentKeyField = "SpeciesNo";
|
|
this.treeLeftViewEx.TreeNodeKeyField = parentKeyField;
|
|
this.treeLeftViewEx.TreeNodeTextField = "SpeciesName";
|
|
this.treeLeftViewEx.OnTreeNodeMouseClick += new TreeNodeMouseClickEventHandler(OnTreeLeftTreeNodeSelected);
|
|
this.treeLeftViewEx.BindTreeView(BaseImpl.GetDataTableResult(this.MainModuleObj.TreeSQL));
|
|
}
|
|
else if (this.MainModuleObj.DefaultTreeSql)
|
|
{
|
|
this.ParentUnionField = "SpeciesNo";
|
|
string parentKeyField = "SpeciesNo";
|
|
this.treeLeftViewEx.TreeNodeKeyField = parentKeyField;
|
|
this.treeLeftViewEx.TreeNodeTextField = "SpeciesName";
|
|
this.treeLeftViewEx.OnTreeNodeMouseClick += new TreeNodeMouseClickEventHandler(OnTreeLeftTreeNodeSelected);
|
|
this.treeLeftViewEx.BindTreeView(BaseImpl.GetDataTableResult("select a.SpeciesNo,a.SpeciesName from p_productspeciestab a where a.ban=0"));
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 判断是否是selete开头(可以处理sql前方有注释和空格的情况)
|
|
/// </summary>
|
|
/// <param name="sqlText"></param>
|
|
/// <returns></returns>
|
|
public static bool IsSelectAtStart(string sqlText)
|
|
{
|
|
string cleanedText = Regex.Replace(sqlText, @"^(\s*--.*?(\r\n|\n)|\s*)*", "");
|
|
return cleanedText.StartsWith("select", StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置动态控件显示刷新</para>
|
|
/// <para>创建人:唐德馨</para>
|
|
/// <para>创建日期:2023-10-24 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="where">The where key.</param>
|
|
private void SetDynamicControl(string groupId)
|
|
{
|
|
this.pl_Top.Controls.Clear();
|
|
this.ControlList.Clear();
|
|
if (string.IsNullOrEmpty(groupId)) return;
|
|
try
|
|
{
|
|
|
|
|
|
DataTable dataTable = new DataTable();
|
|
string dataSourceSql = string.Format("select * from p_productsyssettab where groupid = '{0}' and ban = 0 order by orderid", groupId);
|
|
ControlTable = dataTable = MainImpl.GetDataTableResult(dataSourceSql);
|
|
int x = 10;
|
|
int y = 10;
|
|
int z = 1;
|
|
|
|
|
|
|
|
foreach (DataRow controlRow in dataTable.Rows)
|
|
{
|
|
BaseUserControl baseControl = new BaseUserControl();
|
|
SysSetModel setModel = new SysSetModel(controlRow);
|
|
|
|
switch (setModel.Item)//控件类型
|
|
{
|
|
//下拉框控件
|
|
case "1":
|
|
LabelAutoTextEdit labelAutoTextEdit = new LabelAutoTextEdit();
|
|
setModel.FieldType = 5;
|
|
setModel.ValueMember = "id";
|
|
setModel.TextMember = "sysnamelist";
|
|
labelAutoTextEdit.Model = setModel;
|
|
labelAutoTextEdit.clickAfterEmpty = false;
|
|
labelAutoTextEdit.ValueField = "id";
|
|
labelAutoTextEdit.TextField = "sysnamelist";
|
|
labelAutoTextEdit.ValueMember = labelAutoTextEdit.ValueField;
|
|
labelAutoTextEdit.TextEdit.ControlObj = TopControlObj;
|
|
labelAutoTextEdit.TextEdit.OnlyQueryName = setModel.OnlyQueryName;
|
|
|
|
if (!string.IsNullOrEmpty(setModel.DataSourceSql))
|
|
{
|
|
labelAutoTextEdit.TextEdit.SourceSQL = setModel.DataSourceSql;
|
|
}
|
|
else
|
|
{
|
|
labelAutoTextEdit.TextEdit.SourceSQL = string.Format("select b.midno as id,b.sysnamelist as sysnamelist,b.bak as bak from p_productsyssettab a join p_productsyslisttab b on a.id = b.mid where mid = '{0}'", setModel.Id);
|
|
//labelAutoTextEdit.TextEdit.SourceSQL = " select b.midno as id,b.sysnamelist as sysnamelist,b.bak as bak from p_productsyssettab a join p_productsyslisttab b on a.id = b.mid where mid = '15' and # str1='{str1}'#";
|
|
}
|
|
labelAutoTextEdit.TextEdit.KeyDown += new KeyEventHandler(OnTextEditKeyDown);
|
|
labelAutoTextEdit.TextEdit.TextChanged += new EventHandler(OnTextEditTextChanged);
|
|
baseControl = labelAutoTextEdit;
|
|
break;
|
|
//多选框控件
|
|
case "3":
|
|
LabelMultiAutoTextEdit labelMultiAutoTextEdit = new LabelMultiAutoTextEdit();
|
|
setModel.FieldType = 14;
|
|
setModel.ValueMember = "id";
|
|
setModel.TextMember = "sysnamelist";
|
|
labelMultiAutoTextEdit.Model = setModel;
|
|
labelMultiAutoTextEdit.ValueField = "id";
|
|
labelMultiAutoTextEdit.TextField = "sysnamelist";
|
|
labelMultiAutoTextEdit.ValueMember = labelMultiAutoTextEdit.ValueField;
|
|
labelMultiAutoTextEdit.TextEdit.KeyDown += new KeyEventHandler(OnTextEditKeyDown);
|
|
labelMultiAutoTextEdit.TextEdit.TextChanged += new EventHandler(OnTextEditTextChanged);
|
|
baseControl = labelMultiAutoTextEdit;
|
|
break;
|
|
//备注框A
|
|
case "4":
|
|
LabelMemoEdit labelMemoEdit = new LabelMemoEdit();
|
|
labelMemoEdit.TextEdit.KeyDown += new KeyEventHandler(OnTextEditKeyDown);
|
|
labelMemoEdit.TextEdit.TextChanged += new EventHandler(OnTextEditTextChanged);
|
|
baseControl = labelMemoEdit;
|
|
break;
|
|
//下拉备注框
|
|
case "5":
|
|
LabelAutoMemoEdit labelAutoMemoEdit = new LabelAutoMemoEdit();
|
|
setModel.FieldType = 5;
|
|
setModel.ValueMember = "id";
|
|
setModel.TextMember = "sysnamelist";
|
|
labelAutoMemoEdit.Model = setModel;
|
|
labelAutoMemoEdit.clickAfterEmpty = false;
|
|
labelAutoMemoEdit.ValueField = "id";
|
|
labelAutoMemoEdit.TextField = "sysnamelist";
|
|
labelAutoMemoEdit.ValueMember = labelAutoMemoEdit.ValueField;
|
|
labelAutoMemoEdit.TextEdit.ControlObj = TopControlObj;
|
|
if (!string.IsNullOrEmpty(setModel.DataSourceSql))
|
|
{
|
|
labelAutoMemoEdit.TextEdit.SourceSQL = setModel.DataSourceSql;
|
|
}
|
|
else
|
|
{
|
|
labelAutoMemoEdit.TextEdit.SourceSQL = string.Format("select b.midno as id,b.sysnamelist as sysnamelist,b.bak as bak from p_productsyssettab a join p_productsyslisttab b on a.id = b.mid where mid = '{0}'", setModel.Id);
|
|
//labelAutoTextEdit.TextEdit.SourceSQL = " select b.midno as id,b.sysnamelist as sysnamelist,b.bak as bak from p_productsyssettab a join p_productsyslisttab b on a.id = b.mid where mid = '15' and # str1='{str1}'#";
|
|
}
|
|
labelAutoMemoEdit.TextEdit.KeyDown += new KeyEventHandler(OnTextEditKeyDown);
|
|
labelAutoMemoEdit.TextEdit.TextChanged += new EventHandler(OnTextEditTextChanged);
|
|
baseControl = labelAutoMemoEdit;
|
|
break;
|
|
//文本(标签)
|
|
case "6":
|
|
LabelTitle labelTitle = new LabelTitle();
|
|
baseControl = labelTitle;
|
|
break;
|
|
//复选框
|
|
case "7":
|
|
LabelCheckEdit checkEdit = new LabelCheckEdit();
|
|
baseControl = checkEdit;
|
|
break;
|
|
//日期框
|
|
case "9":
|
|
LabelDateEdit dateEdit = new LabelDateEdit();
|
|
dateEdit.TextEdit.KeyDown += new KeyEventHandler(OnTextEditKeyDown);
|
|
dateEdit.TextEdit.TextChanged += new EventHandler(OnTextEditTextChanged);
|
|
//有格式化配置,按配置格式化显示.否则按照控件类型格式化.
|
|
|
|
dateEdit.DateFormat(setModel.DataFormat);
|
|
baseControl = dateEdit;
|
|
break;
|
|
//文本框控件
|
|
case "2":
|
|
default:
|
|
LabelTextEdit labelTextEdit = new LabelTextEdit();
|
|
if (setModel.Item =="8")
|
|
{
|
|
labelTextEdit.TextEdit.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.OnIntKeyPress);
|
|
labelTextEdit.TextEdit.EditValueChanging += new DevExpress.XtraEditors.Controls.ChangingEventHandler(this.OnIntEditValueChanging);
|
|
}
|
|
labelTextEdit.TextEdit.KeyDown += new KeyEventHandler(OnTextEditKeyDown);
|
|
labelTextEdit.TextEdit.TextChanged += new EventHandler(OnTextEditTextChanged);
|
|
baseControl = labelTextEdit;
|
|
break;
|
|
}
|
|
string controlName = !string.IsNullOrWhiteSpace(setModel.DbName) ? "txt_" + setModel.DbName : "txt_" + setModel.SysName;
|
|
baseControl.Name = controlName;
|
|
baseControl.LabelText = setModel.SysName;
|
|
baseControl.Size = new Size(300, 21);
|
|
baseControl.Required = setModel.MustTig == 1;
|
|
baseControl.Tag = setModel;
|
|
baseControl.Model = setModel;
|
|
baseControl.TabIndex = dataTable.Rows.IndexOf(controlRow);
|
|
baseControl.Location = new Point(x, y);
|
|
if (setModel.LineNumber > 0 && setModel.ColumnNumber > 0)
|
|
{
|
|
baseControl.Location = new Point(10+(setModel.ColumnNumber-1)*315, 10+(setModel.LineNumber-1)*30);
|
|
}
|
|
else
|
|
{
|
|
baseControl.Location = new Point(x, y);
|
|
}
|
|
baseControl.ReadOnly = setModel.ProhibitEdited;
|
|
this.pl_Top.Controls.Add(baseControl);
|
|
this.ControlList.Add(setModel);
|
|
//if (x + baseControl.Width + 15 + baseControl.Width > this.splitDynamicContainer.Panel1.Width)
|
|
//只要2列
|
|
if (z > 1)
|
|
{
|
|
x = 10;
|
|
y += baseControl.Height + 9;
|
|
z = 1;
|
|
}
|
|
else
|
|
{
|
|
x += baseControl.Width + 15;
|
|
z++;
|
|
}
|
|
|
|
|
|
}
|
|
//Thread thread = new Thread(SetControlDataSource);
|
|
//thread.Start();
|
|
//线程方式无法在赋数据源后赋主表选中行的值
|
|
mLoading = false;
|
|
this.mTimer.Tick += new EventHandler(SetControlDataSource);
|
|
this.mTimer.Start();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置关联值</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-12-06 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="model">The model.</param>
|
|
private void SetUnionControl(SysSetModel model)
|
|
{
|
|
string unionFields = model.UnionFields;
|
|
string unionValues = ReplaceControlValue(model.UnionValues);
|
|
try
|
|
{
|
|
DataTable table = BaseImpl.GetDataTableResult(unionValues);
|
|
foreach (string field in unionFields.Trim(',').Split(','))
|
|
{
|
|
if (table.Rows.Count > 0 && table.Columns.Contains(field))
|
|
{
|
|
SetControlValue(field, table.Rows[0][field] + "");
|
|
}
|
|
else
|
|
{
|
|
SetControlValue(field, "");
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Instance.WriteError(ex);
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 设置控件值
|
|
/// </summary>
|
|
/// <param name="controlName"></param>
|
|
/// <param name="controlValue"></param>
|
|
public void SetControlValue(string controlName, object controlValue)
|
|
{
|
|
try
|
|
{
|
|
BaseUserControl baseControl = FindControl(controlName);
|
|
if (baseControl == null) return;
|
|
baseControl.EditText = controlValue + "";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:从当前面板查找控件替换{xxx}值</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-12-06 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="defaultValue">The default value.</param>
|
|
public string ReplaceControlValue(string defaultValue)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(defaultValue))
|
|
{
|
|
defaultValue = ReplaceHelper.ReplaceUserInfo(defaultValue);
|
|
if (this.treeLeftViewEx.TreeView.SelectedNode!=null)
|
|
{
|
|
string parentValue = this.treeLeftViewEx.TreeView.SelectedNode.Name;
|
|
defaultValue = ReplaceHelper.ReplaceTreeViewParentKeyCond(defaultValue, parentValue);
|
|
}
|
|
|
|
|
|
var paramList = ReplaceHelper.GetParamFields(defaultValue);
|
|
foreach (string item in paramList)
|
|
{
|
|
string field = item.Replace("{", "").Replace("}", "");
|
|
if (FindControl(field) != null)
|
|
{
|
|
string value = GetControlValue(field);
|
|
defaultValue = defaultValue.Replace(item, value);
|
|
}
|
|
}
|
|
}
|
|
return defaultValue;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:查找控件(无需要传入txt_)</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-11-08 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="controlName">Name of the control.</param>
|
|
/// <returns>BaseUserControl.</returns>
|
|
public BaseUserControl FindControl(string controlName)
|
|
{
|
|
System.Windows.Forms.Control controlObj = new System.Windows.Forms.Control();
|
|
|
|
controlObj = this.pl_Top.Controls
|
|
.Cast<System.Windows.Forms.Control>()
|
|
.FirstOrDefault(x => x.Name.Equals("txt_" + controlName, StringComparison.OrdinalIgnoreCase));
|
|
if (controlObj != null && controlObj is BaseUserControl)
|
|
{
|
|
return controlObj as BaseUserControl;
|
|
}
|
|
|
|
if (controlObj != null && controlObj is BaseUserControl)
|
|
{
|
|
return controlObj as BaseUserControl;
|
|
}
|
|
return null;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:获取控件值</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-09-04 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="controlName">Name of the control.</param>
|
|
/// <returns>System.String.</returns>
|
|
public string GetControlValue(string controlName)
|
|
{
|
|
string value = string.Empty;
|
|
var ctrs = pl_Top.Controls.Find("txt_" + controlName, true);
|
|
if (ctrs != null && ctrs.Length > 0)
|
|
{
|
|
var ctr = ctrs[0];
|
|
BaseUserControl uControl = ctr as BaseUserControl;
|
|
SysSetModel setModel = uControl.Tag as SysSetModel;
|
|
switch (setModel.Item)//控件类型
|
|
{
|
|
//下拉框控件
|
|
case "1":
|
|
LabelAutoTextEdit labelAutoTextEdit = ctr as LabelAutoTextEdit;
|
|
if (setModel.FxTypeDB.Equals("编码"))
|
|
{
|
|
value = labelAutoTextEdit.EditValue;
|
|
}
|
|
else if (setModel.FxTypeDB.Equals("名称"))
|
|
{
|
|
value = labelAutoTextEdit.EditText;
|
|
}
|
|
break;
|
|
//多选框控件
|
|
case "3":
|
|
LabelMultiAutoTextEdit labelMultiAutoTextEdit = ctr as LabelMultiAutoTextEdit;
|
|
if (setModel.FxType.Equals("名称"))
|
|
{
|
|
value = labelMultiAutoTextEdit.EditText;
|
|
}
|
|
else if (setModel.FxType.Equals("编码"))
|
|
{
|
|
value = labelMultiAutoTextEdit.EditValue;
|
|
}
|
|
break;
|
|
//备注框A
|
|
case "4":
|
|
LabelMemoEdit labelMemoEdit = ctr as LabelMemoEdit;
|
|
value = labelMemoEdit.EditText;
|
|
break;
|
|
//下拉备注框
|
|
case "5":
|
|
LabelAutoMemoEdit labelAutoMemoEdit = ctr as LabelAutoMemoEdit;
|
|
if (setModel.FxTypeDB.Equals("编码"))
|
|
{
|
|
value = labelAutoMemoEdit.EditValue;
|
|
}
|
|
else if (setModel.FxTypeDB.Equals("名称"))
|
|
{
|
|
value = labelAutoMemoEdit.EditText;
|
|
}
|
|
break;
|
|
//标签
|
|
case "6":
|
|
value = "";
|
|
break;
|
|
//复选框
|
|
case "7":
|
|
LabelCheckEdit checkEdit = ctr as LabelCheckEdit;
|
|
value = checkEdit.EditText;
|
|
break;
|
|
//日期框
|
|
case "9":
|
|
LabelDateEdit dateEdit = ctr as LabelDateEdit;
|
|
value = dateEdit.TextEdit.EditValue == null ? dateEdit.EditText : dateEdit.TextEdit.EditValue.ToString();
|
|
break;
|
|
//文本框控件
|
|
case "2":
|
|
default:
|
|
LabelTextEdit labelTextEdit = ctr as LabelTextEdit;
|
|
value = labelTextEdit.EditText;
|
|
break;
|
|
}
|
|
}
|
|
return value;
|
|
}
|
|
/// <summary>
|
|
/// 延迟加载数据源
|
|
/// </summary>
|
|
private void SetControlDataSource(object sender, EventArgs e)
|
|
{
|
|
if (!mLoading)
|
|
{
|
|
mLoading = true;
|
|
bool ClickMain = true;//点击主表
|
|
try
|
|
{
|
|
List< SysSetModel > sysSetModels= this.ControlList.Where(p => p.Item.Equals("1")|| p.Item.Equals("3")|| p.Item.Equals("5")).ToList();
|
|
|
|
foreach (SysSetModel setModel in sysSetModels)
|
|
{
|
|
string controlName = !string.IsNullOrWhiteSpace(setModel.DbName) ? "txt_" + setModel.DbName : "txt_" + setModel.SysName;
|
|
System.Windows.Forms.Control ctr = this.pl_Top.Controls.Find(controlName, false).FirstOrDefault();
|
|
if (ctr != null && setModel.Item.Equals("1"))
|
|
{
|
|
DataTable dataSource = new DataTable();
|
|
if (setModel.DataSourceType.Equals("来源SQL"))
|
|
{
|
|
dataSource = MainImpl.GetDataTableResult(setModel.DataSourceSql);
|
|
}
|
|
else
|
|
{
|
|
string selectSql = "select b.midno as id,b.sysnamelist as sysnamelist,b.bak as bak from p_productsyssettab a join p_productsyslisttab b on a.id = b.mid where mid = '{0}' order by b.{1}";
|
|
if (!string.IsNullOrEmpty(setModel.OrderField))
|
|
{
|
|
selectSql = string.Format(selectSql, setModel.Id, setModel.OrderField);
|
|
}
|
|
else
|
|
{
|
|
selectSql = string.Format(selectSql, setModel.Id, "orderid");
|
|
}
|
|
dataSource = MainImpl.GetDataTableResult(selectSql);
|
|
|
|
}
|
|
LabelAutoTextEdit labelAutoTextEdit = ctr as LabelAutoTextEdit;
|
|
if (dataSource.Columns.Count >= 2)
|
|
{
|
|
string keyField = dataSource.Columns[0].ColumnName;
|
|
string valueField = dataSource.Columns[1].ColumnName;
|
|
setModel.ValueMember = keyField;
|
|
setModel.TextMember = valueField;
|
|
labelAutoTextEdit.ValueField = keyField;
|
|
labelAutoTextEdit.TextField = valueField;
|
|
labelAutoTextEdit.ValueMember = keyField;
|
|
}
|
|
labelAutoTextEdit.SetDataSource(dataSource);
|
|
}
|
|
else if (ctr != null && setModel.Item.Equals("3"))
|
|
{
|
|
DataTable dataSource = new DataTable();
|
|
if (setModel.DataSourceType.Equals("来源SQL"))
|
|
{
|
|
dataSource = MainImpl.GetDataTableResult(setModel.DataSourceSql);
|
|
}
|
|
else
|
|
{
|
|
string selectSql = "select b.midno as id,b.sysnamelist as sysnamelist,b.bak as bak from p_productsyssettab a join p_productsyslisttab b on a.id = b.mid where mid = '{0}' order by b.{1}";
|
|
if (!string.IsNullOrEmpty(setModel.OrderField))
|
|
{
|
|
selectSql = string.Format(selectSql, setModel.Id, setModel.OrderField);
|
|
}
|
|
else
|
|
{
|
|
selectSql = string.Format(selectSql, setModel.Id, "orderid");
|
|
}
|
|
dataSource = MainImpl.GetDataTableResult(selectSql);
|
|
|
|
}
|
|
LabelMultiAutoTextEdit labelMultiAutoTextEdit = ctr as LabelMultiAutoTextEdit;
|
|
if (dataSource.Columns.Count >= 2)
|
|
{
|
|
string keyField = dataSource.Columns[0].ColumnName;
|
|
string valueField = dataSource.Columns[1].ColumnName;
|
|
setModel.ValueMember = keyField;
|
|
setModel.TextMember = valueField;
|
|
labelMultiAutoTextEdit.ValueField = keyField;
|
|
labelMultiAutoTextEdit.TextField = valueField;
|
|
labelMultiAutoTextEdit.ValueMember = keyField;
|
|
}
|
|
labelMultiAutoTextEdit.SetDataSource(dataSource);
|
|
}
|
|
else if (ctr != null && setModel.Item.Equals("5"))
|
|
{
|
|
DataTable dataSource = new DataTable();
|
|
if (setModel.DataSourceType.Equals("来源SQL"))
|
|
{
|
|
dataSource = MainImpl.GetDataTableResult(setModel.DataSourceSql);
|
|
}
|
|
else
|
|
{
|
|
string selectSql = "select b.midno as id,b.sysnamelist as sysnamelist,b.bak as bak from p_productsyssettab a join p_productsyslisttab b on a.id = b.mid where mid = '{0}' order by b.{1}";
|
|
if (!string.IsNullOrEmpty(setModel.OrderField))
|
|
{
|
|
selectSql = string.Format(selectSql, setModel.Id, setModel.OrderField);
|
|
}
|
|
else
|
|
{
|
|
selectSql = string.Format(selectSql, setModel.Id, "orderid");
|
|
}
|
|
dataSource = MainImpl.GetDataTableResult(selectSql);
|
|
|
|
}
|
|
LabelAutoMemoEdit labelAutoMemoEdit = ctr as LabelAutoMemoEdit;
|
|
if (dataSource.Columns.Count >= 2)
|
|
{
|
|
string keyField = dataSource.Columns[0].ColumnName;
|
|
string valueField = dataSource.Columns[1].ColumnName;
|
|
setModel.ValueMember = keyField;
|
|
setModel.TextMember = valueField;
|
|
labelAutoMemoEdit.ValueField = keyField;
|
|
labelAutoMemoEdit.TextField = valueField;
|
|
labelAutoMemoEdit.ValueMember = keyField;
|
|
}
|
|
labelAutoMemoEdit.SetDataSource(dataSource);
|
|
}
|
|
}
|
|
|
|
DataTable dataTable = this.gcMain.GridControl.DataSourceTable();
|
|
if (dataTable != null && dataTable.Rows.Count == 0)
|
|
{
|
|
ClickMain = false;
|
|
SelectDatatable();
|
|
foreach (SysSetModel setModel in this.ControlList)
|
|
{
|
|
string defaultValue = "";
|
|
if (!string.IsNullOrEmpty(setModel.DefaultID))
|
|
{
|
|
defaultValue = setModel.DefaultID;
|
|
}
|
|
if (!string.IsNullOrEmpty(setModel.DefaultName))
|
|
{
|
|
defaultValue = setModel.DefaultName;
|
|
}
|
|
if (!string.IsNullOrEmpty(defaultValue))
|
|
{
|
|
string controlName = !string.IsNullOrWhiteSpace(setModel.DbName) ? "txt_" + setModel.DbName : "txt_" + setModel.SysName;
|
|
System.Windows.Forms.Control ctr = this.pl_Top.Controls.Find(controlName, false).FirstOrDefault();
|
|
BaseUserControl baseUserControl = ctr as BaseUserControl;
|
|
baseUserControl.Invoke(new Action(() =>
|
|
{
|
|
baseUserControl.EditText = defaultValue;
|
|
}));
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
finally
|
|
{
|
|
//this.SetRowControlValues();
|
|
if(ClickMain) this.GridView_FocusedRowObjectChanged(null,null);
|
|
//CloseReverseWriting = true;
|
|
}
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 反写规格型号时获取BaseUserControl的值
|
|
/// </summary>
|
|
/// <param name="baseUserControl"></param>
|
|
/// <param name="setModel"></param>
|
|
/// <returns></returns>
|
|
private string GetBaseControlValue(BaseUserControl baseUserControl,string type="")
|
|
{
|
|
string rtnValue = "";
|
|
try
|
|
{
|
|
SysSetModel setModel = baseUserControl.Tag as SysSetModel;
|
|
if (string.IsNullOrWhiteSpace(type)) type = setModel.FxType;
|
|
|
|
switch (setModel.Item)//控件类型
|
|
{
|
|
case "1":
|
|
LabelAutoTextEdit labelAutoTextEdit = baseUserControl as LabelAutoTextEdit;
|
|
if (type.Equals("名称"))
|
|
{
|
|
rtnValue = labelAutoTextEdit.EditText;
|
|
}
|
|
else if (type.Equals("编码"))
|
|
{
|
|
rtnValue = labelAutoTextEdit.EditValue;
|
|
}
|
|
break;
|
|
case "3":
|
|
LabelMultiAutoTextEdit labelMultiAutoTextEdit = baseUserControl as LabelMultiAutoTextEdit;
|
|
if (type.Equals("名称"))
|
|
{
|
|
rtnValue = labelMultiAutoTextEdit.EditText;
|
|
}
|
|
else if (type.Equals("编码"))
|
|
{
|
|
rtnValue = labelMultiAutoTextEdit.EditValue;
|
|
}
|
|
break;
|
|
//备注框A
|
|
case "4":
|
|
LabelMemoEdit labelMemoEdit = baseUserControl as LabelMemoEdit;
|
|
rtnValue = labelMemoEdit.EditText;
|
|
break;
|
|
//下拉备注框
|
|
case "5":
|
|
LabelAutoMemoEdit labelAutoMemoEdit = baseUserControl as LabelAutoMemoEdit;
|
|
if (type.Equals("名称"))
|
|
{
|
|
rtnValue = labelAutoMemoEdit.EditText;
|
|
}
|
|
else if (type.Equals("编码"))
|
|
{
|
|
rtnValue = labelAutoMemoEdit.EditValue;
|
|
}
|
|
break;
|
|
//标签
|
|
case "6":
|
|
rtnValue = "";
|
|
break;
|
|
//复选框
|
|
case "7":
|
|
LabelCheckEdit checkEdit = baseUserControl as LabelCheckEdit;
|
|
rtnValue = checkEdit.EditText;
|
|
break;
|
|
//日期框
|
|
case "9":
|
|
LabelDateEdit dateEdit = baseUserControl as LabelDateEdit;
|
|
rtnValue = dateEdit.TextEdit.EditValue == null ? dateEdit.EditText : dateEdit.TextEdit.EditValue.ToString();
|
|
break;
|
|
case "2":
|
|
default:
|
|
LabelTextEdit labelTextEdit = baseUserControl as LabelTextEdit;
|
|
rtnValue = labelTextEdit.EditText;
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
if (rtnValue.Equals("(无)"))
|
|
{
|
|
rtnValue = "";
|
|
}
|
|
return rtnValue;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:加载主表格数据</para>
|
|
/// <para>创建人:唐德馨</para>
|
|
/// <para>创建日期:2023-10-24 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="where">The where key.</param>
|
|
private void SetMainGridView(string where = "", bool selectHandler = false, bool initColumns = true)
|
|
{
|
|
string sqlValue = ReplaceHelper.ReplaceWhereCond(this.MainModuleObj.MenuSql);
|
|
sqlValue = IsSelectAtStart(sqlValue) ? sqlValue + where : sqlValue;
|
|
this.SearchMainObj.SearchGrid(sqlValue);
|
|
this.GridView_FocusedRowObjectChanged(null, null);
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:拿到底部表格数据</para>
|
|
// <para>创建人:唐德馨</para>
|
|
/// <para>创建日期:2024-1-8 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <returns>List<GridDetailModel>.</returns>
|
|
private List<GridDetailModel> GetDetails()
|
|
{
|
|
List<GridDetailModel> details = new List<GridDetailModel>();//表格明细对象的集合
|
|
DataTable table = BaseModuleImpl.GetBaseDetailPages(Model.ModuleCode);// 根据传入的模块编号获得基础档案底部标签的数据
|
|
foreach (DataRow item in table.Rows)
|
|
{
|
|
DataTable gridColumns = new DataTable();
|
|
gridColumns = ReportImpl.GetReportDetailColumns(Model.ModuleCode, item["id"] + "");//获取报表明细列
|
|
details.Add(new GridDetailModel(item, gridColumns, GridCustomColumnStruct.BaseDetailGridView));
|
|
}
|
|
return details;
|
|
}
|
|
#endregion
|
|
#region 事件
|
|
/// <summary>
|
|
/// 窗体加载时
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
InitLeftControl();
|
|
InitMainControl();//构建主模块控件
|
|
InitEvent();
|
|
InitlizeData();
|
|
}
|
|
/// <summary>
|
|
/// 分隔条位置改变时
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnSplitMainContainerPositionChanged(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (this.Model != null)
|
|
{
|
|
IniHelper.Write(string.Format("PubProductSmart_SplitMain_{0}", this.Model.ModuleCode), this.splitMainContainer.SplitterPosition + "");
|
|
IniHelper.Write(string.Format("PubProductSmart_SplitRight_{0}", this.Model.ModuleCode), this.splitRightContainer.SplitterPosition + "");
|
|
IniHelper.Write(string.Format("PubProductSmart_SplitDynamic_{0}", this.Model.ModuleCode), this.splitDynamicContainer.SplitterPosition + "");
|
|
IniHelper.Write(string.Format("PubProductSmart_SplitRightUpAndDown_{0}", this.Model.ModuleCode), this.splitRightUpAndDownContainer.SplitterPosition + "");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageUtil.Show(ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 控件面板点击时切换焦点,实现隐藏弹出框
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnScrollableControlClick(object sender, EventArgs e)
|
|
{
|
|
ScrollableControl scrollableControl = (ScrollableControl)sender;
|
|
scrollableControl.Focus();
|
|
}
|
|
/// <summary>
|
|
/// 动态控件按钮点击时
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnTextEditKeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
//BaseUserControl baseControl = (sender as System.Windows.Forms.Control).ToBaseUserControl();
|
|
//baseControl.EditText = baseControl.EditText;
|
|
}
|
|
/// <summary>
|
|
/// 动态控件值改变时
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnTextEditTextChanged(object sender, EventArgs e)
|
|
{
|
|
//if (CloseReverseWriting) return;
|
|
DataTable dataTable = this.gcMain.GridControl.DataSourceTable();
|
|
|
|
BaseUserControl baseControl = (sender as System.Windows.Forms.Control).ToBaseUserControl();
|
|
SysSetModel model = baseControl.Tag as SysSetModel;
|
|
if (dataTable != null && dataTable.Rows.Count == 0)
|
|
{
|
|
string value = baseControl.EditText;
|
|
SelectDatatable();
|
|
dataTable = this.gcMain.GridControl.DataSourceTable();
|
|
//新增行后会刷新控件数据,把新增前的值记录后重新赋值
|
|
baseControl.EditText = value;
|
|
}
|
|
|
|
|
|
int index = this.gcMain.GridView.FocusedRowHandle;
|
|
DataRow dataRow = dataTable.Rows[index];
|
|
|
|
|
|
// 是否存在关联值
|
|
if (!string.IsNullOrWhiteSpace(model.UnionValues) && !string.IsNullOrWhiteSpace(model.UnionFields))
|
|
{
|
|
this.SetUnionControl(model);//关联计算
|
|
}
|
|
|
|
this.SetDisableControl(model);
|
|
|
|
//反写相同名字的列
|
|
if (dataRow.Table.Columns.Contains(model.DbName))
|
|
{
|
|
string Value = this.GetControlValue(model.DbName);
|
|
dataRow[model.DbName] = Value;
|
|
|
|
}
|
|
|
|
|
|
if (model.OrderId.Equals(1) && dataRow.Table.Columns.Contains("appellation"))//反写名称
|
|
{
|
|
this.gcMain.GridView.SetRowCellValue(index, "appellation", baseControl.EditText);
|
|
//dataRow["appellation"] = baseControl.EditText;
|
|
}
|
|
if (model.SpecDbName.Equals(1) && dataRow.Table.Columns.Contains("spec"))//反写规格
|
|
{
|
|
List<BaseUserControl> specControls = this.pl_Top.Controls.Cast<BaseUserControl>().Where(n => (n.Tag as SysSetModel).SpecDbName.Equals(1) && !string.IsNullOrWhiteSpace(n.EditText)).OrderBy(n => (n.Tag as SysSetModel).SpecSort).ToList();
|
|
StringBuilder specText = new StringBuilder();
|
|
for (int i = 0; i < specControls.Count; i++)
|
|
{
|
|
BaseUserControl item = specControls[i];
|
|
if (string.IsNullOrWhiteSpace(item.EditText)) continue;
|
|
SysSetModel sysSetModel = item.Tag as SysSetModel;
|
|
|
|
string editText = GetBaseControlValue(item, sysSetModel.FxTypeGg);
|
|
if (!string.IsNullOrWhiteSpace(editText))
|
|
{
|
|
if (i == 0)
|
|
{
|
|
specText.Append(string.Format("{0}{1}{2}", sysSetModel.ConnectorStrGg,editText, sysSetModel.EndConnectorStrGg));
|
|
}
|
|
else
|
|
{
|
|
specText.Append(string.Format("{0}{1}{2}{3}", sysSetModel.ConnectorStr, sysSetModel.ConnectorStrGg, editText, sysSetModel.EndConnectorStrGg));
|
|
}
|
|
}
|
|
}
|
|
this.gcMain.GridView.SetRowCellValue(index, "spec", specText.ToString());
|
|
}
|
|
if (model.ModelDbName.Equals(1) && dataRow.Table.Columns.Contains("model"))//反写型号
|
|
{
|
|
List<BaseUserControl> modelControls = this.pl_Top.Controls.Cast<BaseUserControl>().Where(n => (n.Tag as SysSetModel).ModelDbName.Equals(1) && !string.IsNullOrWhiteSpace(n.EditText)).OrderBy(n => (n.Tag as SysSetModel).ModelSort).ToList();
|
|
StringBuilder modelText = new StringBuilder();
|
|
for (int i = 0; i < modelControls.Count; i++)
|
|
{
|
|
BaseUserControl item = modelControls[i];
|
|
if (string.IsNullOrWhiteSpace(item.EditText)) continue;
|
|
SysSetModel sysSetModel = item.Tag as SysSetModel;
|
|
string editText = GetBaseControlValue(item, sysSetModel.FxTypeXh);
|
|
if (!string.IsNullOrWhiteSpace(editText))
|
|
{
|
|
if (i == 0)
|
|
{
|
|
modelText.Append(string.Format("{0}{1}{2}", sysSetModel.ConnectorStrXh, editText, sysSetModel.EndConnectorStrXh));
|
|
}
|
|
else
|
|
{
|
|
modelText.Append(string.Format("{0}{1}{2}{3}", sysSetModel.ConnectorStr, sysSetModel.ConnectorStrXh, editText, sysSetModel.EndConnectorStrXh));
|
|
}
|
|
}
|
|
}
|
|
this.gcMain.GridView.SetRowCellValue(index, "model", modelText.ToString());
|
|
}
|
|
if (model.ZhSxdbName.Equals(1) && dataRow.Table.Columns.Contains("productDe"))//反写综合属性
|
|
{
|
|
List<BaseUserControl> zhsxControls = this.pl_Top.Controls.Cast<BaseUserControl>().Where(n => (n.Tag as SysSetModel).ZhSxdbName.Equals(1) && !string.IsNullOrWhiteSpace(n.EditText)).OrderBy(n => (n.Tag as SysSetModel).ProDeSort).ToList();
|
|
StringBuilder zhsxText = new StringBuilder();
|
|
for (int i = 0; i < zhsxControls.Count; i++)
|
|
{
|
|
BaseUserControl item = zhsxControls[i];
|
|
if (string.IsNullOrWhiteSpace(item.EditText)) continue;
|
|
SysSetModel sysSetModel = item.Tag as SysSetModel;
|
|
string editText = GetBaseControlValue(item, sysSetModel.FxTypeZhsx);
|
|
if (editText.Equals("无"))
|
|
{
|
|
editText = "";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(editText))
|
|
{
|
|
if (i == 0)
|
|
{
|
|
zhsxText.Append(string.Format("{0}{1}{2}", sysSetModel.ConnectorStrZhsx, editText, sysSetModel.EndConnectorStrZhsx));
|
|
}
|
|
else
|
|
{
|
|
zhsxText.Append(string.Format("{0}{1}{2}{3}", sysSetModel.ConnectorStr, sysSetModel.ConnectorStrZhsx, editText, sysSetModel.EndConnectorStrZhsx));
|
|
}
|
|
}
|
|
}
|
|
this.gcMain.GridView.SetRowCellValue(index, "productDe", zhsxText.ToString());
|
|
}
|
|
if (model.CzdbName.Equals(1) && dataRow.Table.Columns.Contains("grade"))//反写材质属性
|
|
{
|
|
List<BaseUserControl> czControls = this.pl_Top.Controls.Cast<BaseUserControl>().Where(n => (n.Tag as SysSetModel).CzdbName.Equals(1) && !string.IsNullOrWhiteSpace(n.EditText)).OrderBy(n => (n.Tag as SysSetModel).GradeSort).ToList();
|
|
StringBuilder czText = new StringBuilder();
|
|
for (int i = 0; i < czControls.Count; i++)
|
|
{
|
|
BaseUserControl item = czControls[i];
|
|
if (string.IsNullOrWhiteSpace(item.EditText)) continue;
|
|
SysSetModel sysSetModel = item.Tag as SysSetModel;
|
|
|
|
string editText = GetBaseControlValue(item, sysSetModel.FxTypeCz);
|
|
if (editText.Equals("无"))
|
|
{
|
|
editText = "";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(editText))
|
|
{
|
|
if (i == 0)
|
|
{
|
|
czText.Append(string.Format("{0}{1}{2}", sysSetModel.ConnectorStrCz, editText, sysSetModel.EndConnectorStrCz));
|
|
}
|
|
else
|
|
{
|
|
czText.Append(string.Format("{0}{1}{2}{3}", sysSetModel.ConnectorStr, sysSetModel.ConnectorStrCz, editText, sysSetModel.EndConnectorStrCz));
|
|
}
|
|
}
|
|
}
|
|
this.gcMain.GridView.SetRowCellValue(index, "grade", czText.ToString());
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <para>说明:</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2019-01-22 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="model">The model.</param>
|
|
/// <param name="fieldValue">The field value.</param>
|
|
private void SetDisableControl(SysSetModel model)
|
|
{
|
|
SysSetModel[] controls = this.ControlList.Where(x => x.DisableCond.Contains("{" + model.DbName + "}") || x.RequiredCond.Contains("{" + model.DbName + "}")).ToArray();
|
|
if (controls == null || controls.Length == 0) return;
|
|
|
|
string fieldValue = GetControlValue(model.DbName);
|
|
foreach (SysSetModel item in controls)
|
|
{
|
|
try
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(item.DisableCond))
|
|
{
|
|
string disableCond = this.ReplaceControlValue(item.DisableCond.Replace("{" + model.DbName + "}", fieldValue));
|
|
BaseUserControl control = FindControl(item.DbName);
|
|
control.Enabled = ("true".Equals(ValidateCond(disableCond, null) + "", StringComparison.OrdinalIgnoreCase));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(item.RequiredCond))
|
|
{
|
|
string requiredCond = this.ReplaceControlValue(item.RequiredCond.Replace("{" + model.DbName + "}", fieldValue));
|
|
BaseUserControl control = FindControl(item.DbName);
|
|
control.Required = ("true".Equals(ValidateCond(requiredCond, null) + "", StringComparison.OrdinalIgnoreCase));
|
|
item.MustTig = control.Required ? 1 : 0;
|
|
control.ReadOnly = control.Model.ReadOnly;//重新设置编辑状态可以改变必填颜色
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//MessageUtil.Show(ex);
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 树节点点击后刷新数据
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnTreeLeftTreeNodeSelected(object sender, TreeNodeMouseClickEventArgs e)
|
|
{
|
|
WaitForm.ShowForm();
|
|
try
|
|
{
|
|
string where = null;
|
|
if (string.IsNullOrWhiteSpace(this.ParentUnionField))
|
|
{
|
|
where = string.Format(" and {0} = N'{1}' ", this.treeLeftViewEx.TreeNodeKeyField, e.Node.Name);
|
|
}
|
|
else
|
|
{
|
|
where = string.Format(" and {0} = N'{1}' ", this.ParentUnionField, e.Node.Name);
|
|
}
|
|
this.SetMainGridView(where);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageUtil.Show(ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 查询后执行
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnSearchAfterCallBack(object sender, EventArgs e)
|
|
{
|
|
string where = null;
|
|
TreeNode treeNode = null;
|
|
if (this.LeftTreeRow != null && this.treeLeftViewEx.Visible == true)
|
|
{
|
|
treeNode = this.treeLeftViewEx.TreeView.SelectedNode;
|
|
if (string.IsNullOrWhiteSpace(this.ParentUnionField))
|
|
{
|
|
where = string.Format(" and {0} = N'{1}' ", this.treeLeftViewEx.TreeNodeKeyField, treeNode.Name);
|
|
}
|
|
else
|
|
{
|
|
where = string.Format(" and {0} = N'{1}' ", this.ParentUnionField, treeNode.Name);
|
|
}
|
|
}
|
|
string sqlValue = "select BmFaID from P_ProductSpeciesTab where 1=1 ";
|
|
sqlValue = ReplaceHelper.ReplaceWhereCond(sqlValue);
|
|
if (!string.IsNullOrEmpty(Model.ProjectName))
|
|
{
|
|
//string projectName = Model.ProjectName;
|
|
//projectId = MainImpl.GetResult(string.Format("select id from p_productsyssetGrouptab where itemName = '{0}'", projectName)) + "";
|
|
projectId = Model.ProjectName;
|
|
}
|
|
else
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(where))
|
|
{
|
|
sqlValue = IsSelectAtStart(sqlValue) ? sqlValue + where : sqlValue;
|
|
sqlValue = MainImpl.GetDefaultValue(sqlValue);
|
|
projectId = MainImpl.GetResult(sqlValue) + "";
|
|
}
|
|
else
|
|
{
|
|
sqlValue = ReplaceHelper.ReplaceUserInfo(sqlValue);
|
|
sqlValue = ReplaceHelper.ReplaceWhereCond(sqlValue);
|
|
sqlValue = SearchMainObj.SetSearchSqlValue(sqlValue);
|
|
sqlValue = MainImpl.GetDefaultValue(sqlValue);
|
|
projectId = MainImpl.GetResult(sqlValue) + "";
|
|
}
|
|
}
|
|
SetDynamicControl(projectId);
|
|
DataRow dataRow = this.gcMain.GetViewFocusedDataRow();
|
|
if (dataRow != null)
|
|
{
|
|
string url = dataRow.Table.Columns.Contains("url") ? dataRow["url"] + "" : "";
|
|
if (!string.IsNullOrEmpty(url))
|
|
{
|
|
this.splitDynamicContainer.PanelVisibility = SplitPanelVisibility.Both;
|
|
this.tipsLabel.Visible = false;
|
|
this.frmWebBrowser.Visible = true;
|
|
this.frmWebBrowser.LoadUrl(url);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.tipsLabel.Visible = true;
|
|
this.frmWebBrowser.Visible = false;
|
|
}
|
|
//SelectDatatable();
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
/// 修改编码事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnBtnUpdateClick(object sender, EventArgs e)
|
|
{
|
|
WaitForm.ShowForm("正在修改数据");
|
|
try
|
|
{
|
|
if (this.VerifyNull(this.pl_Top))
|
|
{
|
|
DataRow focusRow = this.gcMain.GridView.GetFocusedDataRow();
|
|
if (focusRow == null)
|
|
{
|
|
MessageUtil.Show("请选择一行数据");
|
|
return;
|
|
}
|
|
//string Autogrowcolumn = BaseImpl.GetResult(string.Format("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='{0}' AND COLUMNPROPERTY(OBJECT_ID('{0}'),COLUMN_NAME,'IsIdentity')=1", this.MainModuleObj.MenuTable)) + "";
|
|
//DataTable tableColumns = BaseImpl.GetTableColumns(this.MainModuleObj.MenuTable);
|
|
//string newBillNo = focusRow["productid"] + "";
|
|
|
|
//主键和主键值
|
|
string primaryKey = BaseImpl.GetBasePrimaryKey(this.Model.ModuleCode);
|
|
string primaryValue = focusRow[primaryKey] + "";
|
|
if (string.IsNullOrWhiteSpace(primaryValue))
|
|
{
|
|
MessageUtil.Show("主键值不能为空");
|
|
return;
|
|
}
|
|
string parentValue = string.Empty;
|
|
if (this.treeLeftViewEx.TreeView.SelectedNode != null) parentValue = this.treeLeftViewEx.TreeView.SelectedNode.Name;
|
|
|
|
//string newBillNo = BaseImpl.GetDefaultValue(model.Default, parentValue);
|
|
List<string> keyList = new List<string>() { "speciesno", "operatorname", "operatedate", "smartbmfa" };
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
List<BaseUserControl> modelControls = this.pl_Top.Controls.Cast<BaseUserControl>().Where(n => !string.IsNullOrEmpty((n.Tag as SysSetModel).DbName)).OrderBy(n => (n.Tag as SysSetModel).OrderId).ToList();
|
|
foreach (BaseUserControl item in modelControls)
|
|
{
|
|
SysSetModel sysSetModel = item.Tag as SysSetModel;
|
|
string fxValue = "";
|
|
try
|
|
{
|
|
string controlName = !string.IsNullOrWhiteSpace(sysSetModel.DbName) ? sysSetModel.DbName : sysSetModel.SysName;
|
|
fxValue = this.GetControlValue(controlName);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
if (!sysSetModel.DbName.Equals(primaryKey, StringComparison.OrdinalIgnoreCase) && !sysSetModel.DbName.Equals("productid", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
keyList.Add(sysSetModel.DbName.ToLower());
|
|
sqlBuilder.Append(string.Format("{0} = N'{1}',", sysSetModel.DbName, fxValue.Replace("'", "''")));
|
|
}
|
|
|
|
//拼接主表反写数据
|
|
if (sysSetModel.OrderId.Equals(1) && focusRow.Table.Columns.Contains("appellation") && !keyList.Contains("appellation"))//反写名称
|
|
{
|
|
keyList.Add("appellation");
|
|
sqlBuilder.Append(string.Format("{0} = N'{1}',", "appellation", focusRow["appellation"] + ""));
|
|
}
|
|
if (sysSetModel.SpecDbName.Equals(1) && focusRow.Table.Columns.Contains("spec") && !keyList.Contains("spec"))//反写规格
|
|
{
|
|
keyList.Add("spec");
|
|
sqlBuilder.Append(string.Format("{0} = N'{1}',", "spec", focusRow["spec"] + ""));
|
|
}
|
|
if (sysSetModel.ModelDbName.Equals(1) && focusRow.Table.Columns.Contains("model") && !keyList.Contains("model"))//反写型号
|
|
{
|
|
keyList.Add("model");
|
|
sqlBuilder.Append(string.Format("{0} = N'{1}',", "model", focusRow["model"] + ""));
|
|
}
|
|
if (sysSetModel.ZhSxdbName.Equals(1) && focusRow.Table.Columns.Contains("productde") && !keyList.Contains("productde"))//反写综合属性
|
|
{
|
|
keyList.Add("productde");
|
|
sqlBuilder.Append(string.Format("{0} = N'{1}',", "productde", focusRow["productde"] + ""));
|
|
}
|
|
if (sysSetModel.CzdbName.Equals(1) && focusRow.Table.Columns.Contains("grade") && !keyList.Contains("grade"))//反写综合属性
|
|
{
|
|
keyList.Add("grade");
|
|
sqlBuilder.Append(string.Format("{0} = N'{1}',", "grade", focusRow["grade"] + ""));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//foreach (ControlModel item in this.MainControlObj.ControlModels)
|
|
//{
|
|
// if (!item.IsSave ||
|
|
// _leftField.Equals(item.FieldName) ||
|
|
// "ID".Equals(item.FieldName, StringComparison.CurrentCultureIgnoreCase) ||
|
|
// item.FieldName.Equals(primaryKey, StringComparison.CurrentCultureIgnoreCase) ||
|
|
// item.FieldName.Equals("productid", StringComparison.CurrentCultureIgnoreCase) ||
|
|
// item.FieldType == ControlType.LabPic ||
|
|
// item.FieldType == ControlType.LabPicEx || !tableColumns.Columns.Contains(item.FieldName) ||
|
|
// Autogrowcolumn.ToLower() == item.FieldName.ToLower())
|
|
// continue;
|
|
// BaseUserControl userControl = this.MainControlObj.FindControl(item);
|
|
// // userControl.IsUpdate() 保存所有数据
|
|
// if (userControl != null)
|
|
// {
|
|
// string fieldValue = this.MainControlObj.GetControlValue(item);
|
|
// if (fieldValue == "****") continue;
|
|
// if (item.FieldType == 7)
|
|
// {
|
|
// if (fieldValue.Contains('%')) fieldValue = (double.Parse(fieldValue.Replace("%", "")) * 0.01).ToString();
|
|
// if (fieldValue.Contains(',')) fieldValue = fieldValue.Replace(",", "");
|
|
// }
|
|
// if (string.IsNullOrEmpty(fieldValue) && item.Isintordecimal) fieldValue = "0";//数值保存时为空的话默认保存为0;
|
|
// if (!keyList.Contains(item.FieldName.ToLower()))
|
|
// {
|
|
// sqlBuilder.Append(string.IsNullOrEmpty(fieldValue) ? string.Format("{0} = {1}", item.FieldName, this.MainControlObj.GetNullValue(item)) : string.Format("{0}='{1}',", item.FieldName, fieldValue));
|
|
// }
|
|
// }
|
|
//}
|
|
string execSql = "";
|
|
if (!string.IsNullOrWhiteSpace(sqlBuilder.ToString()))
|
|
{
|
|
execSql = string.Format("update {0} set {1},speciesno = '{2}', operatedate = '{3}',OperatorId = '{4}' where {5} = '{6}'", this.MainModuleObj.MenuTable, sqlBuilder.ToString().TrimEnd(','), parentValue, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ERPInfo.Instance.UserId, primaryKey, primaryValue);
|
|
}
|
|
BaseSaveModel saveModel = new BaseSaveModel
|
|
{
|
|
BaseSaveType = SaveType.Update,
|
|
BaseSql = execSql,
|
|
KeyField = primaryKey,
|
|
FieldValue = primaryValue,
|
|
MenuCode = MainModuleObj.ModeCode,
|
|
TableName = MainModuleObj.MenuTable,
|
|
ComfirmFlag = 0,
|
|
NewVer = MainModuleObj.NewVer
|
|
};
|
|
int result = BaseModuleImpl.SaveBasePanelData(saveModel);
|
|
if (result == 1)
|
|
{
|
|
if (ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.AfterModuleDataChange, saveModel.MenuCode, 0))
|
|
{
|
|
ApiHelper apiHelper = new ApiHelper(saveModel.MenuCode, saveModel.FieldValue, saveModel.KeyField, saveModel.TableName, 0);
|
|
switch (saveModel.BaseSaveType)
|
|
{
|
|
case SaveType.Add:
|
|
apiHelper.OnEvent(Interface.Api.OperateEvent.AfterModuleDataChange, Interface.Api.ActionType.Add);//添加
|
|
break;
|
|
case SaveType.Update:
|
|
apiHelper.OnEvent(Interface.Api.OperateEvent.AfterModuleDataChange, Interface.Api.ActionType.Update);//更新
|
|
break;
|
|
}
|
|
if (!string.IsNullOrEmpty(apiHelper.apiResutMsg))
|
|
MessageUtil.Show(apiHelper.apiResutMsg);
|
|
}
|
|
MessageUtil.Show(ResourceKeys.SaveSuccess);
|
|
|
|
|
|
string where = null;
|
|
if (this.splitMainContainer.PanelVisibility == SplitPanelVisibility.Both)
|
|
{
|
|
string nodeName = string.Empty;
|
|
if (this.treeLeftViewEx.TreeView.SelectedNode != null) nodeName = this.treeLeftViewEx.TreeView.SelectedNode.Name;
|
|
if (string.IsNullOrWhiteSpace(this.ParentUnionField))
|
|
{
|
|
where = string.Format(" and {0} = N'{1}'", this.treeLeftViewEx.TreeNodeKeyField, nodeName);
|
|
}
|
|
else
|
|
{
|
|
where = string.Format(" and {0} = N'{1}'", this.ParentUnionField, nodeName);
|
|
}
|
|
}
|
|
|
|
this.SetMainGridView(where, true, false);
|
|
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show(ResourceKeys.SaveFault + "\r\n" + saveModel.FaultMsg);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageUtil.Show(ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
WaitForm.HideForm();
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 保存按钮点击
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnBtnSaveClick(object sender, EventArgs e)
|
|
{
|
|
WaitForm.ShowForm("正在保存数据");
|
|
try
|
|
{
|
|
if (this.VerifyNull(this.pl_Top))
|
|
{
|
|
DataRow focusRow = this.gcMain.GridView.GetFocusedDataRow();
|
|
|
|
//string Autogrowcolumn = BaseImpl.GetResult(string.Format("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='{0}' AND COLUMNPROPERTY(OBJECT_ID('{0}'),COLUMN_NAME,'IsIdentity')=1", this.MainModuleObj.MenuTable)) + "";
|
|
string primaryKey = BaseImpl.GetBasePrimaryKey(this.Model.ModuleCode);
|
|
string primaryValue = this.GetControlValue(primaryKey);
|
|
DataTable tableColumns = BaseImpl.GetTableColumns(this.MainModuleObj.MenuTable);
|
|
//ControlModel model = this.MainControlObj._models.FirstOrDefault(x => x.FieldName == primaryKey);
|
|
string parentValue = string.Empty;
|
|
if (this.treeLeftViewEx.TreeView.SelectedNode != null) parentValue = this.treeLeftViewEx.TreeView.SelectedNode.Name;
|
|
StringBuilder keyBuilder = new StringBuilder();
|
|
StringBuilder valueBuilder = new StringBuilder();
|
|
List<string> keyList = new List<string>() { "speciesno", "operatorname", "operatedate", "smartbmfa" };
|
|
List<BaseUserControl> modelControls = this.pl_Top.Controls.Cast<BaseUserControl>().Where(n => !string.IsNullOrEmpty((n.Tag as SysSetModel).DbName)).OrderBy(n => (n.Tag as SysSetModel).OrderId).ToList();
|
|
foreach (BaseUserControl item in modelControls)
|
|
{
|
|
SysSetModel sysSetModel = item.Tag as SysSetModel;
|
|
string fxValue = "";
|
|
try
|
|
{
|
|
string controlName = !string.IsNullOrWhiteSpace(sysSetModel.DbName) ? sysSetModel.DbName : sysSetModel.SysName;
|
|
fxValue = this.GetControlValue(controlName);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
if (!keyList.Contains(sysSetModel.DbName.ToLower()))
|
|
{
|
|
keyList.Add(sysSetModel.DbName.ToLower());
|
|
keyBuilder.Append(string.Format("{0},", sysSetModel.DbName));
|
|
valueBuilder.Append(string.Format("N'{0}',", fxValue.Replace("'", "''")));
|
|
}
|
|
|
|
//拼接主表反写数据
|
|
if (sysSetModel.OrderId.Equals(1) && focusRow.Table.Columns.Contains("appellation") && !keyList.Contains("appellation"))//反写名称
|
|
{
|
|
keyList.Add("appellation");
|
|
keyBuilder.Append(string.Format("{0},", "appellation"));
|
|
valueBuilder.Append(string.Format("N'{0}',", focusRow["appellation"] + ""));
|
|
}
|
|
if (sysSetModel.SpecDbName.Equals(1) && focusRow.Table.Columns.Contains("spec") && !keyList.Contains("spec"))//反写规格
|
|
{
|
|
keyList.Add("spec");
|
|
keyBuilder.Append(string.Format("{0},", "spec"));
|
|
valueBuilder.Append(string.Format("N'{0}',", focusRow["spec"] + ""));
|
|
}
|
|
if (sysSetModel.ModelDbName.Equals(1) && focusRow.Table.Columns.Contains("model") && !keyList.Contains("model"))//反写型号
|
|
{
|
|
keyList.Add("model");
|
|
keyBuilder.Append(string.Format("{0},", "model"));
|
|
valueBuilder.Append(string.Format("N'{0}',", focusRow["model"] + ""));
|
|
}
|
|
if (sysSetModel.ZhSxdbName.Equals(1) && focusRow.Table.Columns.Contains("productde") && !keyList.Contains("productde"))//反写综合属性
|
|
{
|
|
keyList.Add("productde");
|
|
keyBuilder.Append(string.Format("{0},", "productde"));
|
|
valueBuilder.Append(string.Format("N'{0}',", focusRow["productde"] + ""));
|
|
}
|
|
if (sysSetModel.CzdbName.Equals(1) && focusRow.Table.Columns.Contains("grade") && !keyList.Contains("grade"))//反写综合属性
|
|
{
|
|
keyList.Add("grade");
|
|
keyBuilder.Append(string.Format("{0},", "grade"));
|
|
valueBuilder.Append(string.Format("N'{0}',", focusRow["grade"] + ""));
|
|
}
|
|
|
|
|
|
|
|
}
|
|
//foreach (ControlModel item in MainControlObj.ControlModels)
|
|
//{
|
|
// if (!item.IsSave ||
|
|
// _leftField.Equals(item.FieldName) ||
|
|
// "ID".Equals(item.FieldName, StringComparison.CurrentCultureIgnoreCase) ||
|
|
// item.FieldType == ControlType.LabPic ||
|
|
// item.FieldType == ControlType.LabPicEx || !tableColumns.Columns.Contains(item.FieldName) ||
|
|
// Autogrowcolumn.ToLower() == item.FieldName.ToLower())
|
|
// continue;
|
|
// string fieldValue = MainControlObj.GetControlValue(item);
|
|
// if (fieldValue == "****") continue;
|
|
// if (item.FieldType == 7)
|
|
// {
|
|
// if (fieldValue.Contains('%')) fieldValue = (double.Parse(fieldValue.Replace("%", "")) * 0.01).ToString();
|
|
// if (fieldValue.Contains(',')) fieldValue = fieldValue.Replace(",", "");
|
|
// }
|
|
// if (!keyList.Contains(item.FieldName.ToLower()))
|
|
// {
|
|
// keyList.Add(item.FieldName.ToLower());
|
|
// keyBuilder.Append(item.FieldName + ",");
|
|
// if (string.IsNullOrEmpty(fieldValue) && item.Isintordecimal) fieldValue = "0";//数值保存时为空的话默认保存为0;
|
|
// valueBuilder.Append(string.IsNullOrEmpty(fieldValue) ? MainControlObj.GetNullValue(item) : string.Format("'{0}',", fieldValue));
|
|
// }
|
|
//}
|
|
//拼接条件
|
|
foreach (ControlModel item in this.SearchMainObj.ControlModels)
|
|
{
|
|
if (item.Montage && !keyList.Contains(item.FieldName.ToLower()))
|
|
{
|
|
string fieldValue = this.SearchMainObj.GetControlValue(item);
|
|
keyList.Add(item.FieldName.ToLower());
|
|
keyBuilder.Append(string.Format("{0},", item.FieldName));
|
|
valueBuilder.Append(string.Format("N'{0}',", fieldValue.Replace("'", "''")));
|
|
}
|
|
|
|
}
|
|
|
|
string insertSql = string.Format("insert into {0} ({1},speciesno,Operatedate,OperatorId) values ({2},'{3}','{4}','{5}')\r\n", this.MainModuleObj.MenuTable, keyBuilder.ToString().TrimEnd(','), valueBuilder.ToString().TrimEnd(','), parentValue, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ERPInfo.Instance.UserId);
|
|
BaseSaveModel saveModel = new BaseSaveModel
|
|
{
|
|
BaseSaveType = SaveType.Add,
|
|
BaseSql = insertSql,
|
|
KeyField = primaryKey,
|
|
FieldValue = primaryValue,
|
|
MenuCode = MainModuleObj.ModeCode,
|
|
TableName = MainModuleObj.MenuTable,
|
|
ComfirmFlag = 0,
|
|
NewVer = MainModuleObj.NewVer
|
|
};
|
|
int result = BaseModuleImpl.SaveBasePanelData(saveModel);
|
|
//int result = BaseImpl.ExecSqlValue(insertSql);
|
|
if (result == 1)// result >0
|
|
{
|
|
if (saveModel.NewVer == 1 && saveModel.BaseSaveType == SaveType.Add)
|
|
saveModel.FieldValue = primaryValue = saveModel.FaultMsg;
|
|
if (ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.AfterModuleDataChange, saveModel.MenuCode, 0))
|
|
{
|
|
ApiHelper apiHelper = new ApiHelper(saveModel.MenuCode, saveModel.FieldValue, saveModel.KeyField, saveModel.TableName, 0);
|
|
switch (saveModel.BaseSaveType)
|
|
{
|
|
case SaveType.Add:
|
|
apiHelper.OnEvent(Interface.Api.OperateEvent.AfterModuleDataChange, Interface.Api.ActionType.Add);//添加
|
|
break;
|
|
case SaveType.Update:
|
|
apiHelper.OnEvent(Interface.Api.OperateEvent.AfterModuleDataChange, Interface.Api.ActionType.Update);//更新
|
|
break;
|
|
}
|
|
if (!string.IsNullOrEmpty(apiHelper.apiResutMsg))
|
|
MessageUtil.Show(apiHelper.apiResutMsg);
|
|
}
|
|
MessageUtil.Show(ResourceKeys.SaveSuccess);
|
|
//this.MainControlObj.ResetControlValue();
|
|
//SetDynamicControl(projectId);
|
|
//刷新主表
|
|
string where = null;
|
|
if (this.splitMainContainer.PanelVisibility == SplitPanelVisibility.Both)
|
|
{
|
|
string nodeName = string.Empty;
|
|
if (this.treeLeftViewEx.TreeView.SelectedNode != null) nodeName = this.treeLeftViewEx.TreeView.SelectedNode.Name;
|
|
if (string.IsNullOrWhiteSpace(this.ParentUnionField))
|
|
{
|
|
where = string.Format(" and {0} = N'{1}'", this.treeLeftViewEx.TreeNodeKeyField, nodeName);
|
|
}
|
|
else
|
|
{
|
|
where = string.Format(" and {0} = N'{1}'", this.ParentUnionField, nodeName);
|
|
}
|
|
}
|
|
|
|
this.SetMainGridView(where, false, false);
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show(ResourceKeys.SaveFault + "\r\n" + saveModel.FaultMsg);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageUtil.Show(ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
WaitForm.HideForm();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <para>说明:验证数据合法性</para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
|
public bool VerifyNull(System.Windows.Forms.Control parentPanel)
|
|
{
|
|
foreach (System.Windows.Forms.Control item in parentPanel.Controls)
|
|
{
|
|
if (item is BaseUserControl)
|
|
{
|
|
var baseControl = item as BaseUserControl;
|
|
SysSetModel setModel = baseControl.Tag as SysSetModel;
|
|
if (string.IsNullOrWhiteSpace(baseControl.EditText) && setModel != null && setModel.MustTig == 1)
|
|
{
|
|
baseControl.Focus();
|
|
MessageUtil.Show(string.Format("{0}未填写数据", baseControl.LabelText));
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 右键点击
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void itemCommon_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
SimpleButton btn = sender as SimpleButton;
|
|
DataRow rowItem = btn.Tag as DataRow;
|
|
GridRightMenuModel model = new GridRightMenuModel(rowItem);
|
|
|
|
DataRow focusedRow = this.gcMain.GridView.GetFocusedDataRow();
|
|
//把左侧控件的值替换到主表选中行中
|
|
//List<BaseUserControl> modelControls = this.pl_Top.Controls.Cast<BaseUserControl>().Where(n => !string.IsNullOrEmpty((n.Tag as SysSetModel).DbName)).OrderBy(n => (n.Tag as SysSetModel).OrderId).ToList();
|
|
//foreach (BaseUserControl item in modelControls)
|
|
//{
|
|
// SysSetModel sysSetModel = item.Tag as SysSetModel;
|
|
// string fxValue = "";
|
|
// try
|
|
// {
|
|
// string controlName = !string.IsNullOrWhiteSpace(sysSetModel.DbName) ? sysSetModel.DbName : sysSetModel.SysName;
|
|
// fxValue = this.GetControlValue(controlName);
|
|
// }
|
|
// catch (Exception)
|
|
// {
|
|
// }
|
|
// if (focusedRow.Table.Columns.Contains(sysSetModel.DbName))
|
|
// {
|
|
// focusedRow[sysSetModel.DbName] = fxValue;
|
|
// }
|
|
//}
|
|
|
|
BaseRightMenu menu = new BaseRightMenu();
|
|
menu.Model = this.Model;
|
|
|
|
if (menu.ExecRightMenu(model, new DataRow[] { focusedRow }) && model.Refresh)
|
|
{
|
|
//this.SearchLastGrid();
|
|
SearchMainObj_OnDataSourceBindCallBack(null, null);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 数据源绑定后刷新
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void SearchMainObj_OnDataSourceBindCallBack(object sender, EventArgs e)
|
|
{
|
|
//刷新主表
|
|
this.SearchMainObj.SearchGrid();
|
|
OnSearchAfterCallBack(null, null);
|
|
OperationCondition();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 主表行切换刷新界面
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void GridView_FocusedRowObjectChanged(object sender, RowClickEventArgs e)
|
|
{
|
|
|
|
SetRowControlValues();
|
|
RefreshDetails();
|
|
RightClickForJudgment();
|
|
OperationCondition();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断右键按钮
|
|
/// </summary>
|
|
private void RightClickForJudgment()
|
|
{
|
|
DataRow rowItem = this.gcMain.GridView.GetFocusedDataRow();
|
|
//int i = 0;
|
|
// 判断右键菜单是否可用
|
|
foreach (SimpleButton toolButton in rightBtn)
|
|
{
|
|
DataRow dr = toolButton.Tag as DataRow;
|
|
GridRightMenuModel model = new GridRightMenuModel(dr);
|
|
|
|
if (model == null) continue;
|
|
toolButton.Enabled = true;
|
|
if (model.PrivilegeOper.Length > 1 && !model.PrivilegeOper.Contains(ERPInfo.Instance.UserName + ","))
|
|
{
|
|
toolButton.Enabled = false;
|
|
}
|
|
else
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(model.MenuCond))
|
|
{
|
|
try
|
|
{
|
|
string cond = ReplaceHelper.ReplaceRowParam(rowItem, model.MenuCond);
|
|
toolButton.Enabled = ReplaceHelper.EvalCond(cond);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
//i++;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///修改和操作条件
|
|
/// </summary>
|
|
private void OperationCondition()
|
|
{
|
|
try
|
|
{
|
|
DataRow rowItem = this.gcMain.GridView.GetFocusedDataRow();
|
|
this.btnSave.Enabled = this.ValidateCond(this.MainModuleObj.AddCond, rowItem); // 判断新增权限
|
|
this.btnUpdate.Enabled = this.ValidateCond(this.MainModuleObj.ModifyCond, rowItem); // 判断修改权限
|
|
//没有选中行时隐藏其余右键
|
|
if (rowItem == null)
|
|
{
|
|
foreach (SimpleButton toolButton in rightBtn)
|
|
{
|
|
toolButton.Enabled = false;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 刷新子页签数据
|
|
/// </summary>
|
|
|
|
private void RefreshDetails()
|
|
{
|
|
foreach (XtraTabPage tabPage in this.tabMain.TabControlObj.TabPages)
|
|
{
|
|
GridDetailModel model = this.tabMain.GetGridDetailModel(tabPage);
|
|
DataRow rowItem = this.gcMain.GetViewFocusedDataRow();
|
|
|
|
if (rowItem != null && model != null)
|
|
{
|
|
if (!string.IsNullOrEmpty(model.UnionModule) && (string.IsNullOrEmpty(model.UnionValue) && string.IsNullOrEmpty(model.UnionCond))) return;
|
|
string searchSql = this.GetSearchSql(model, rowItem);
|
|
|
|
|
|
|
|
if (tabPage.Tag is GridControlEx)
|
|
{
|
|
(tabPage.Tag as GridControlEx).LastSearchSql = searchSql;
|
|
}
|
|
GridView view = this.gcMain.GridView;
|
|
//DataTable dataTable = MainImpl.GetDataTableResult(searchSql);//明细数据源
|
|
this.tabMain.SetGridDataSource(tabPage, MainImpl.GetDataTableResult(searchSql), view);
|
|
if (tabPage.Tag is GridControlEx && (tabPage.Tag as GridControlEx).ParentControl != null)
|
|
(tabPage.Tag as GridControlEx).ParentControl.SetAllControlValue(rowItem);
|
|
//配置明细直接根据条件加载
|
|
if (model.SystemModel != null && 1 == model.SystemModel.isFirstLoad)
|
|
{
|
|
(tabPage.Tag as GridControlEx).ParentControl.SearchGrid();
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <para>说明:检查可用条件</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-11-09 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="cond">The cond.</param>
|
|
/// <param name="dataRow">The data row.</param>
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
|
private bool ValidateCond(string cond, DataRow dataRow, string TableName = null, string ColumnName = null)
|
|
{
|
|
bool result = false;
|
|
string condition = cond;
|
|
try
|
|
{
|
|
if (string.IsNullOrWhiteSpace(cond)) return true;//如果值是空格或者空行,默认正确
|
|
cond = ReplaceHelper.ReplaceRowParam(dataRow, cond);
|
|
if (cond.StartsWith("@") || cond.StartsWith("!"))
|
|
{
|
|
result = "1".Equals(BaseImpl.GetDefaultValue(cond));
|
|
}
|
|
else if (dataRow == null)
|
|
{
|
|
result = ReplaceHelper.EvalCond(cond);
|
|
}
|
|
else
|
|
{
|
|
result = ReplaceHelper.ReplaceRowParamCond(dataRow, cond);
|
|
}
|
|
return result;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 限制數值框不能輸入中文
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnIntKeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
// 检查输入的是否是数字或控制字符(例如退格键)
|
|
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) &&
|
|
(e.KeyChar != '.') && (e.KeyChar != '-') && (e.KeyChar != '%'))
|
|
{
|
|
e.Handled = true; // 不处理这个字符,即不会显示在控件中
|
|
}
|
|
|
|
// 只允许输入一个小数点
|
|
if ((e.KeyChar == '.') && ((sender as TextEdit).Text.IndexOf('.') > -1))
|
|
{
|
|
e.Handled = true;
|
|
}
|
|
|
|
// 只允许输入一个负号
|
|
if ((e.KeyChar == '-') && ((sender as TextEdit).Text.IndexOf('-') > -1))
|
|
{
|
|
e.Handled = true;
|
|
}
|
|
// 只允许输入一个百分号
|
|
if ((e.KeyChar == '%') && ((sender as TextEdit).Text.IndexOf('%') > -1))
|
|
{
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 限制數值框粘貼不能粘貼中文
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnIntEditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
|
|
{
|
|
string newText = e.NewValue as string;
|
|
|
|
|
|
// 第一个输入负号不会取消,出现了千位分隔符不会取消更改,末尾为百分号不会取消
|
|
if (!newText.Equals("-") && !string.IsNullOrEmpty(newText) && !Regex.IsMatch(newText, @"^(?:-(?:[0-9]+(?:,[0-9]{3})*(?:\.[0-9]*)?)|[0-9]+(?:,[0-9]{3})*(?:\.[0-9]*)?)(?:%)?$"))
|
|
{
|
|
e.Cancel = true; // 取消这次更改
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|