ba650c5c63
SVN-Revision: r310
1981 lines
96 KiB
C#
1981 lines
96 KiB
C#
using DevExpress.XtraEditors;
|
|
using DevExpress.XtraGrid.Views.Grid;
|
|
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
|
|
using DevExpress.XtraTreeList;
|
|
using DevExpress.XtraTreeList.Nodes;
|
|
using Lskj.Business.Impl;
|
|
using Lskj.Control;
|
|
using Lskj.Control.Model;
|
|
using Lskj.Core;
|
|
using Lskj.Data;
|
|
using Lskj.Model;
|
|
using Lskj.PubBomAlter.Model;
|
|
using Lskj.Util;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Drawing;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Lskj.PubBomAlter
|
|
{
|
|
public partial class FrmMain : BaseForm
|
|
{
|
|
public DynamicBomAlterModel BomAlterModel;
|
|
public string[] ModelObj;
|
|
/// <summary>
|
|
/// 模块表
|
|
/// </summary>
|
|
public TreeGridControlEx TreeGridObj
|
|
{
|
|
get { return treeGridControlEx; }
|
|
}
|
|
/// <summary>
|
|
/// 查询对象
|
|
/// </summary>
|
|
public MyControl SearchObj;
|
|
/// <summary>
|
|
/// 数据源绑定完成后
|
|
/// </summary>
|
|
public event EventHandler OnAfterDataSourceCallback;
|
|
/// <summary>
|
|
/// 上方控件面板
|
|
/// </summary>
|
|
private XtraScrollableControl MainControlPanel = new XtraScrollableControl();
|
|
/// <summary>
|
|
/// 主表控件
|
|
/// </summary>
|
|
public MyControl TopControlObj;
|
|
/// <summary>
|
|
/// 模块行数据
|
|
/// </summary>
|
|
private DataRow modelRow;
|
|
/// <summary>
|
|
/// 系统模块对象
|
|
/// </summary>
|
|
private ModuleModel sysModel;
|
|
/// <summary>
|
|
/// 列数据源
|
|
/// </summary>
|
|
private DataTable _gridColumns;
|
|
/// <summary>
|
|
/// 无需更新的列
|
|
/// </summary>
|
|
private string[] _disUpdateColumns = { "id" };
|
|
/// <summary>
|
|
/// 明细表
|
|
/// </summary>
|
|
private DataTable detailsTab;
|
|
/// <summary>
|
|
/// 上方控件对象
|
|
/// </summary>
|
|
public DynamicModel TopDynamic;
|
|
/// <summary>
|
|
/// 上方控件对象
|
|
/// </summary>
|
|
public ModuleModel TopModuleObj;
|
|
/// <summary>
|
|
/// 中间表格对象
|
|
/// </summary>
|
|
public DynamicModel GcMainDynamic;
|
|
/// <summary>
|
|
/// 中间表格对象
|
|
/// </summary>
|
|
public ModuleModel GcMainModuleObj;
|
|
/// <summary>
|
|
/// 右边表格对象
|
|
/// </summary>
|
|
public DynamicModel GcDetailDynamic;
|
|
/// <summary>
|
|
/// 右边表格对象
|
|
/// </summary>
|
|
public ModuleModel GcDetailModuleObj;
|
|
/// <summary>
|
|
/// 动态控件对象集合
|
|
/// </summary>
|
|
private List<SysSetModel> ControlList = new List<SysSetModel>();
|
|
/// <summary>
|
|
/// 规格控件
|
|
/// </summary>
|
|
private BaseUserControl _SpecBaseControl;
|
|
/// <summary>
|
|
/// 型号控件
|
|
/// </summary>
|
|
private BaseUserControl _ModelBaseControl;
|
|
/// <summary>
|
|
/// 综合属性控件
|
|
/// </summary>
|
|
private BaseUserControl _ZhSxBaseControl;
|
|
/// <summary>
|
|
/// 名称控件
|
|
/// </summary>
|
|
private BaseUserControl _NameBaseControl;
|
|
/// <summary>
|
|
/// 名称控件
|
|
/// </summary>
|
|
private BaseUserControl _UnitBaseControl;
|
|
/// <summary>
|
|
/// 名称控件
|
|
/// </summary>
|
|
private BaseUserControl _CzBaseControl;
|
|
/// <summary>
|
|
/// 规格控件
|
|
/// </summary>
|
|
public BaseUserControl SpecBaseControl
|
|
{
|
|
get
|
|
{
|
|
if (_SpecBaseControl == null)
|
|
{
|
|
_SpecBaseControl = this.TopControlObj.FindControl("spec");
|
|
}
|
|
return _SpecBaseControl;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 型号控件
|
|
/// </summary>
|
|
public BaseUserControl ModelBaseControl
|
|
{
|
|
get
|
|
{
|
|
if (_ModelBaseControl == null)
|
|
{
|
|
_ModelBaseControl = this.TopControlObj.FindControl("model");
|
|
}
|
|
return _ModelBaseControl;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 综合属性控件
|
|
/// </summary>
|
|
public BaseUserControl ZhSxBaseControl
|
|
{
|
|
get
|
|
{
|
|
if (_ZhSxBaseControl == null)
|
|
{
|
|
_ZhSxBaseControl = this.TopControlObj.FindControl("ProductDescrip");
|
|
}
|
|
return _ZhSxBaseControl;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 材质属性控件
|
|
/// </summary>
|
|
public BaseUserControl CzBaseControl
|
|
{
|
|
get
|
|
{
|
|
if (_CzBaseControl == null)
|
|
{
|
|
_CzBaseControl = this.TopControlObj.FindControl("grade");
|
|
}
|
|
return _CzBaseControl;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 名称控件
|
|
/// </summary>
|
|
public BaseUserControl NameBaseControl
|
|
{
|
|
get
|
|
{
|
|
if (_NameBaseControl == null)
|
|
{
|
|
_NameBaseControl = this.TopControlObj.FindControl("appellation");
|
|
}
|
|
return _NameBaseControl;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 单位控件
|
|
/// </summary>
|
|
public BaseUserControl UnitBaseControl
|
|
{
|
|
get
|
|
{
|
|
if (_UnitBaseControl == null)
|
|
{
|
|
_UnitBaseControl = this.TopControlObj.FindControl("Productunitname");
|
|
}
|
|
return _UnitBaseControl;
|
|
}
|
|
}
|
|
public FrmMain()
|
|
{
|
|
InitializeComponent();
|
|
this.Load += OnFrmMainLoad;
|
|
}
|
|
/// <summary>
|
|
/// 窗体加载时
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnFrmMainLoad(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
WaitForm.ShowForm();
|
|
InitlizeSpiltLocation();
|
|
InitTreeGridControl();
|
|
CreateControlLocation();
|
|
InitGcMainControl();
|
|
InitGcDetailControl();
|
|
InitEvents();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageUtil.Show(ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
WaitForm.HideForm();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 右键完成后执行
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnGridViewRightCallBack(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
SearchObj.SearchGrid();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageUtil.Show(ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 右键完成后执行
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnGridDetailViewRightCallBack(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
DataRow dataRow = gcMainControlEx.GridView.GetFocusedDataRow();
|
|
if (dataRow != null)
|
|
{
|
|
SysSetModel setModel = new SysSetModel(dataRow);
|
|
if (setModel != null && (setModel.Item.Equals("1") || setModel.Item.Equals("5")))
|
|
{
|
|
string controlName = !string.IsNullOrWhiteSpace(setModel.DbName) ? setModel.DbName : setModel.SysName;
|
|
string selectSql = "select * from(select row_number() over (partition by mid order by orderid)hh,* from p_productsyslisttab)a where mid = '{0}' order by '{1}'";
|
|
if (!string.IsNullOrEmpty(setModel.OrderField))
|
|
{
|
|
selectSql = string.Format(selectSql, setModel.Id, setModel.OrderField);
|
|
}
|
|
else
|
|
{
|
|
selectSql = string.Format(selectSql, setModel.Id, "orderid");
|
|
}
|
|
DataTable dataSource = BaseImpl.GetDataTableResult(selectSql);
|
|
int index = this.gcDetailControlEx.GridView.FocusedRowHandle;
|
|
this.gcDetailControlEx.GridControl.DataSource = dataSource;
|
|
this.gcDetailControlEx.GridView.FocusedRowHandle = index;
|
|
}
|
|
else
|
|
{
|
|
this.gcDetailControlEx.GridControl.DataSource = null;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageUtil.Show(ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 设置分割条位置
|
|
/// </summary>
|
|
private void InitlizeSpiltLocation()
|
|
{
|
|
try
|
|
{
|
|
string splitRightWidth = IniHelper.Read(string.Format("PubBomAlter_SplitRight_{0}", this.BomAlterModel.ModuleCode));//通过Key获取Value值
|
|
if (!string.IsNullOrEmpty(splitRightWidth))
|
|
{
|
|
this.splitRightContainer.SplitterPosition = Convert.ToInt32(splitRightWidth);
|
|
}
|
|
string splitControlWidth = IniHelper.Read(string.Format("PubBomAlter_SplitControl_{0}", this.BomAlterModel.ModuleCode));//通过Key获取Value值
|
|
if (!string.IsNullOrEmpty(splitControlWidth))
|
|
{
|
|
this.splitControlContainer.SplitterPosition = Convert.ToInt32(splitControlWidth);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageUtil.Show(ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 构建控件
|
|
/// </summary>
|
|
private void InitTreeGridControl()
|
|
{
|
|
detailsTab = BaseModuleImpl.GetBaseDetailPages(this.BomAlterModel.ModuleCode);
|
|
modelRow = MainImpl.GetSystemdllTab(BomAlterModel.ModuleCode);//获取单个模块信息
|
|
sysModel = new ModuleModel(modelRow);// 系统模块实体对象
|
|
TreeGridObj.TreeListObj.OptionsBehavior.AllowExpandOnDblClick = false;
|
|
TreeGridObj.Model = BomAlterModel;
|
|
DataTable queryTable = BaseModuleImpl.GetCustomQueryFields(sysModel.CondKey);//加载自定义配置字段
|
|
sysModel.PrefixKey = BaseImpl.GetColumnPrefix(sysModel.MenuTable);//获取列前缀
|
|
SearchObj = new MyControl(sysModel.MenuSql, TreeGridObj);//替换sql语句中的bmp字段
|
|
SearchObj.OnDataSourceBindCallBack += OnSearchObjDataSourceBindCallBack;
|
|
SearchObj.OnSearchAfterCallBack += OnSearchObjSearchAfterCallBack;
|
|
bool fixedQuery = queryTable == null || queryTable.Rows.Count == 0;
|
|
if (fixedQuery)
|
|
{
|
|
pl_top_fix_search.Visible = true;
|
|
// 加载固定查询条件
|
|
DataTable table = BaseModuleImpl.GetFixedQueryFields(BomAlterModel.ModuleCode);//加载固定查询条件
|
|
cbField.DisplayMember = "fieldText";
|
|
cbField.ValueMember = "fieldName";
|
|
cbField.DataSource = table;
|
|
SearchObj.InitDefaultSearchControl(table, pl_top_fix_search);
|
|
}
|
|
else
|
|
{
|
|
// 加载配置查询条件
|
|
pl_top_fix_search.Visible = false;
|
|
SearchObj.OtherParams = BomAlterModel.OtherParams();
|
|
pl_top.Height = SearchObj.InitSearchControl(queryTable, pl_top_search);
|
|
}
|
|
_gridColumns = BaseModuleImpl.GetBaseGridColumns(BomAlterModel.ModuleCode);
|
|
TreeGridObj.SetEditColumns(_gridColumns, GridCustomColumnStruct.BaseMainGridView + sysModel.FormKey);
|
|
TreeGridObj.SetGridRowColors(BaseModuleImpl.GetBaseGridRowColors(BomAlterModel.ModuleCode));
|
|
TreeGridObj.TreeListObj.MouseClick += OnTreeListObjMouseClick;
|
|
DataTable rightMenusTable = BaseModuleImpl.GetBaseGridRightMenus(BomAlterModel.ModuleCode);
|
|
TreeGridObj.SetGridRightMenus(rightMenusTable, BomAlterModel, OnGridViewRightCallBack, SearchObj);
|
|
}
|
|
/// <summary>
|
|
/// 构建控件
|
|
/// </summary>
|
|
private void InitGcMainControl()
|
|
{
|
|
if (detailsTab != null && detailsTab.Rows.Count > 2)
|
|
{
|
|
string unionModule = detailsTab.Rows[2]["unionModule"] + "";
|
|
GcMainDynamic = new DynamicModel(new string[] { ModelObj[0], ModelObj[1], ModelObj[2], ModelObj[3], unionModule });
|
|
DataRow dllRow = MainImpl.GetSystemdllTab(GcMainDynamic.ModuleCode);//获取单个模块信息
|
|
if (dllRow == null)
|
|
{
|
|
MessageUtil.Show("模块编号[" + GcMainDynamic.ModuleCode + "],配置错误!\r\n该模块信息未找到!");
|
|
return;
|
|
}
|
|
GcMainModuleObj = new ModuleModel(dllRow);//系统模块实体对象
|
|
InitializeGcMainView();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 构建控件
|
|
/// </summary>
|
|
private void InitGcDetailControl()
|
|
{
|
|
WaitForm.ShowForm();
|
|
try
|
|
{
|
|
if (detailsTab != null && detailsTab.Rows.Count > 1)
|
|
{
|
|
string unionModule = detailsTab.Rows[1]["unionModule"] + "";
|
|
GcDetailDynamic = new DynamicModel(new string[] { ModelObj[0], ModelObj[1], ModelObj[2], ModelObj[3], unionModule });
|
|
DataRow dllRow = MainImpl.GetSystemdllTab(GcDetailDynamic.ModuleCode);//获取单个模块信息
|
|
if (dllRow == null)
|
|
{
|
|
MessageUtil.Show("模块编号[" + GcDetailDynamic.ModuleCode + "],配置错误!\r\n该模块信息未找到!");
|
|
return;
|
|
}
|
|
GcDetailModuleObj = new ModuleModel(dllRow);//系统模块实体对象
|
|
InitializeGcDetailView();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
WaitForm.HideForm();
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:初始化表格操作</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2023-10-13 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void InitializeGcDetailView()
|
|
{
|
|
this.gcDetailControlEx.GridView.OptionsSelection.MultiSelect = true;
|
|
this.gcDetailControlEx.GridView.OptionsSelection.MultiSelectMode = GridMultiSelectMode.CheckBoxRowSelect;
|
|
this.gcDetailControlEx.GridView.OptionsSelection.EnableAppearanceFocusedCell = true;
|
|
this.gcDetailControlEx.GridView.OptionsBehavior.EditorShowMode = DevExpress.Utils.EditorShowMode.MouseDown;
|
|
DataTable gridColumns = BaseModuleImpl.GetBaseGridColumns(GcDetailDynamic.ModuleCode);//获取主表列数据
|
|
this.gcDetailControlEx.Model = GcDetailDynamic;
|
|
this.gcDetailControlEx.SetReadOnlyColumns(gridColumns, GridCustomColumnStruct.BaseMainGridView + this.GcDetailModuleObj.FormKey);
|
|
this.gcDetailControlEx.SetGridRowColors(BaseModuleImpl.GetBaseGridRowColors(GcDetailDynamic.ModuleCode));//设置表格颜色
|
|
DataTable rightMenusTable = BaseModuleImpl.GetBaseGridRightMenus(GcDetailDynamic.ModuleCode);
|
|
this.gcDetailControlEx.SetGridRightMenus(rightMenusTable, GcDetailDynamic, OnGridDetailViewRightCallBack);
|
|
this.gcDetailControlEx.GridView.OptionsView.ShowFooter = false;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:初始化表格操作</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2023-10-13 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void InitializeGcMainView()
|
|
{
|
|
//this.gcMainControlEx.GridView.OptionsBehavior.EditorShowMode = DevExpress.Utils.EditorShowMode.MouseDown;
|
|
DataTable gridColumns = BaseModuleImpl.GetBaseGridColumns(GcMainDynamic.ModuleCode);//获取主表列数据
|
|
this.gcMainControlEx.Model = GcMainDynamic;
|
|
this.gcMainControlEx.SetEditColumns(gridColumns, GridCustomColumnStruct.BaseMainGridView + this.GcMainModuleObj.FormKey);
|
|
this.gcMainControlEx.SetGridRowColors(BaseModuleImpl.GetBaseGridRowColors(GcMainDynamic.ModuleCode));//设置表格颜色
|
|
this.gcMainControlEx.GridView.OptionsView.ShowFooter = false;
|
|
this.gcMainControlEx.GridView.FocusedRowChanged += OnGcGridViewFocusedRowChanged;
|
|
this.gcMainControlEx.GridView.CellValueChanged += OnGcMainGridCellValueChanged;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:初始化主模块控件</para>
|
|
/// <para>创建人:唐德馨</para>
|
|
/// <para>创建日期:2023-10-19 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void CreateControlLocation()
|
|
{
|
|
try
|
|
{
|
|
if (detailsTab != null && detailsTab.Rows.Count > 0)
|
|
{
|
|
string unionModule = detailsTab.Rows[0]["unionModule"] + "";
|
|
TopDynamic = new DynamicModel(new string[] { ModelObj[0], ModelObj[1], ModelObj[2], ModelObj[3], unionModule });
|
|
DataRow dllRow = MainImpl.GetSystemdllTab(this.TopDynamic.ModuleCode);//获取单个模块信息
|
|
if (dllRow == null)
|
|
{
|
|
MessageUtil.Show("模块编号[" + this.TopDynamic.ModuleCode + "],配置错误!\r\n该模块信息未找到!");
|
|
return;
|
|
}
|
|
this.TopModuleObj = new ModuleModel(dllRow);//系统模块实体对象
|
|
}
|
|
DataTable mainControlTable = BaseModuleImpl.GetControlLocation(TopModuleObj.FormKey, this.TopDynamic.ModuleCode);
|
|
this.TopControlObj = new MyControl()
|
|
{
|
|
ParentPanel = this.scrollableControl,
|
|
SystemModel = this.TopModuleObj,
|
|
OtherParams = this.BomAlterModel.OtherParams()
|
|
};
|
|
this.TopControlObj.InitControl(mainControlTable, this.scrollableControl, null, true);
|
|
this.scrollableControl.AutoScroll = true;
|
|
this.scrollableControl.HorizontalScroll.Visible = false;//设置禁止水平滚动条
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 添加事件
|
|
/// </summary>
|
|
private void InitEvents()
|
|
{
|
|
//TreeGridObj.TreeListObj.MouseDoubleClick += OnTreeListObjMouseDoubleClick;
|
|
TreeGridObj.TreeListObj.CustomDrawNodeButton += OnTreeListObjCustomDrawNodeButton;
|
|
this.splitRightContainer.SplitterPositionChanged += OnSplitMainContainerPositionChanged;
|
|
this.splitControlContainer.SplitterPositionChanged += OnSplitMainContainerPositionChanged;
|
|
//this.pl_Top.Click += OnScrollableControlClick;
|
|
//this.pl_scrollBottom.Click += OnScrollableControlClick;
|
|
this.btnPmsSave.Click += OnBtnPmsSaveClick;
|
|
this.btnSave.Click += OnBtnSaveClick;
|
|
this.btnApply.Click += OnBtnApplyClick;
|
|
this.gcDetailControlEx.GridView.DoubleClick += OnGcDetailGridViewDoubleClick;
|
|
this.gcDetailControlEx.GridView.SelectionChanged += OnGridViewSelectionChanged;
|
|
}
|
|
/// <summary>
|
|
/// 树表格行点击
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnTreeListObjMouseClick(object sender, MouseEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
this.OnAfterDataSourceCallback -= OnAfterDataSource;
|
|
gcMainControlEx.GridControl.DataSource = null;
|
|
TreeList treeListGrid = sender as TreeList;
|
|
Point gcPoint = treeListGrid.PointToScreen(treeListGrid.Location);
|
|
Point pt = new Point(MousePosition.X - gcPoint.X, MousePosition.Y - gcPoint.Y);
|
|
TreeListHitInfo _hitInfo = treeListGrid.CalcHitInfo(pt);
|
|
if (_hitInfo != null && _hitInfo.Node != null)
|
|
{
|
|
TreeListNode focusedNode = treeListGrid.FocusedNode;
|
|
DataRow dataRow = (treeListGrid.GetDataRecordByNode(focusedNode) as DataRowView).Row;
|
|
if (dataRow.Table.Columns.Contains("Plm_lmb_SmartBmFa"))
|
|
{
|
|
string projectId = dataRow["Plm_lmb_SmartBmFa"] + "";
|
|
this.OnAfterDataSourceCallback += OnAfterDataSource;
|
|
SetDynamicControl(projectId);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageUtil.Show(ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 数据源加载完成后事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnAfterDataSource(object sender, EventArgs e)
|
|
{
|
|
WaitForm.ShowForm();
|
|
this.Invoke(new Action(() =>
|
|
{
|
|
TreeListNode focusedNode = TreeGridObj.TreeListObj.FocusedNode;
|
|
DataRow dataRow = (TreeGridObj.TreeListObj.GetDataRecordByNode(focusedNode) as DataRowView).Row;
|
|
SetAllControlValue(dataRow);
|
|
}));
|
|
WaitForm.HideForm();
|
|
}
|
|
/// <summary>
|
|
/// 更改菜单点击
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnToolStripMenuItemClick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
TreeList treeListGrid = treeGridControlEx.TreeListObj;
|
|
TreeListNode focusedNode = treeListGrid.FocusedNode;
|
|
DataRow dataRow = (treeListGrid.GetDataRecordByNode(focusedNode) as DataRowView).Row;
|
|
if (focusedNode.ParentNode == null || (focusedNode.ParentNode != null && (focusedNode.ParentNode["Plm_lmb_updatetig"] + "").Equals("1")))
|
|
{
|
|
string sourceSql = GcMainModuleObj.MenuSql;
|
|
sourceSql = ReplaceHelper.ReplaceRowParam(dataRow, sourceSql);
|
|
DataTable sourceTable = BaseImpl.GetDataTableResult(sourceSql);
|
|
gcMainControlEx.GridControl.DataSource = sourceTable;
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("父节点未修改");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageUtil.Show(ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 参数表格点击时
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnGcGridViewFocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
|
|
{
|
|
DataRow dataRow = gcMainControlEx.GridView.GetFocusedDataRow();
|
|
if (dataRow != null)
|
|
{
|
|
SysSetModel setModel = new SysSetModel(dataRow);
|
|
if (setModel != null && (setModel.Item.Equals("1") || setModel.Item.Equals("5")))
|
|
{
|
|
string controlName = !string.IsNullOrWhiteSpace(setModel.DbName) ? setModel.DbName : setModel.SysName;
|
|
string selectSql = "select * from(select row_number() over (partition by mid order by orderid)hh,* from p_productsyslisttab)a where mid = '{0}' order by '{1}'";
|
|
if (!string.IsNullOrEmpty(setModel.OrderField))
|
|
{
|
|
selectSql = string.Format(selectSql, setModel.Id, setModel.OrderField);
|
|
}
|
|
else
|
|
{
|
|
selectSql = string.Format(selectSql, setModel.Id, "orderid");
|
|
}
|
|
DataTable dataSource = BaseImpl.GetDataTableResult(selectSql);
|
|
this.gcDetailControlEx.GridControl.DataSource = dataSource;
|
|
string editValue = this.GetControlValue(controlName, true);
|
|
if (!string.IsNullOrEmpty(editValue))
|
|
{
|
|
DataRow selectRow = dataSource.AsEnumerable().Where(n => (n["midno"] + "").Equals(editValue)).FirstOrDefault();
|
|
if (selectRow != null)
|
|
{
|
|
int index = dataSource.Rows.IndexOf(selectRow);
|
|
index = this.gcDetailControlEx.GridView.GetRowHandle(index);
|
|
this.gcDetailControlEx.GridView.SelectRow(index);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.gcDetailControlEx.GridControl.DataSource = null;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 表格值改变时
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnGcMainGridCellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
|
|
{
|
|
if (e.Column.FieldName.Equals("sysvalue"))
|
|
{
|
|
DataRow focusedRow = gcMainControlEx.GridView.GetDataRow(e.RowHandle);
|
|
string dbName = focusedRow["DbName"] + "";
|
|
string sysName = focusedRow["SysName"] + "";
|
|
string controlName = !string.IsNullOrWhiteSpace(dbName) ? dbName : sysName;
|
|
string value = focusedRow["sysvalue"] + "";
|
|
focusedRow["sysvalue"] = "";
|
|
SetControlValue(controlName, value);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 绘制树表格前图标
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnTreeListObjCustomDrawNodeButton(object sender, CustomDrawNodeButtonEventArgs e)
|
|
{
|
|
if ((e.Node["Plm_lmb_updatetig"] + "").Equals("1"))
|
|
{
|
|
Image image = Properties.Resources.update;
|
|
Rectangle nodeBounds = e.Bounds;
|
|
int x = nodeBounds.Left;
|
|
int y = nodeBounds.Top;
|
|
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
|
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
|
e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
|
e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
|
|
e.Graphics.DrawImage(image, x, y, nodeBounds.Width, nodeBounds.Height);
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 设置动态控件
|
|
/// </summary>
|
|
private void SetDynamicControl(string projectId)
|
|
{
|
|
this.MainControlPanel.Controls.Clear();
|
|
this.ControlList.Clear();
|
|
try
|
|
{
|
|
if (!string.IsNullOrEmpty(projectId))
|
|
{
|
|
TreeListNode focusedNode = treeGridControlEx.TreeListObj.FocusedNode;
|
|
DataRow dataRow = (treeGridControlEx.TreeListObj.GetDataRecordByNode(focusedNode) as DataRowView).Row;
|
|
DataTable dataTable = new DataTable();
|
|
//string dataSourceSql = string.Format("select * from p_productsyssettab where speciesid = '{0}' and groupname = '{1}' and ban = 0 order by orderid", speciesid, groupname);
|
|
//string dataSourceSql = string.Format("select '' as sysvalue,* from p_productsyssettab where groupid = '{0}' and ban = 0 order by orderid", projectId);
|
|
string sourceSql = GcMainModuleObj.MenuSql;
|
|
sourceSql = ReplaceHelper.ReplaceRowParam(dataRow, sourceSql);
|
|
dataTable = BaseImpl.GetDataTableResult(sourceSql);
|
|
gcMainControlEx.GridControl.DataSource = dataTable;
|
|
int x = 10;
|
|
int y = 10;
|
|
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.AutoShowPopup = false;
|
|
if (!string.IsNullOrEmpty(setModel.DataSourceSql))
|
|
{
|
|
labelAutoTextEdit.TextEdit.SourceSQL = setModel.DataSourceSql;
|
|
//labelAutoTextEdit.TextEdit.SourceSQL = "select id ,unit as sysnamelist from P_UnitTab where 1=1 and #OperatorId='{shape}'#";
|
|
}
|
|
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.TextChanged += new EventHandler(OnTextEditTextChanged);
|
|
//labelAutoTextEdit.ReadOnly = setModel.ProhibitEdited;
|
|
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.TextChanged += new EventHandler(OnTextEditTextChanged);
|
|
//labelMultiAutoTextEdit.ReadOnly = setModel.ProhibitEdited;
|
|
baseControl = labelMultiAutoTextEdit;
|
|
break;
|
|
//备注框A
|
|
case "4":
|
|
LabelMemoEdit labelMemoEdit = new LabelMemoEdit();
|
|
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;
|
|
labelAutoMemoEdit.TextEdit.AutoShowPopup = false;
|
|
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.TextChanged += new EventHandler(OnTextEditTextChanged);
|
|
baseControl = labelAutoMemoEdit;
|
|
break;
|
|
//文本框控件
|
|
case "2":
|
|
default:
|
|
LabelTextEdit labelTextEdit = new LabelTextEdit();
|
|
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);
|
|
baseControl.ReadOnly = setModel.ProhibitEdited;
|
|
this.MainControlPanel.Controls.Add(baseControl);
|
|
this.ControlList.Add(setModel);
|
|
if (x + baseControl.Width + 15 + baseControl.Width > this.splitRightContainer.Panel1.Width)
|
|
{
|
|
x = 10;
|
|
y += baseControl.Height + 9;
|
|
}
|
|
else
|
|
{
|
|
x += baseControl.Width + 15;
|
|
}
|
|
}
|
|
//SetControlDataSource();
|
|
Thread thread = new Thread(SetControlDataSource);
|
|
thread.Start();
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 延迟加载数据源
|
|
/// </summary>
|
|
private void SetControlDataSource()
|
|
{
|
|
try
|
|
{
|
|
foreach (SysSetModel setModel in this.ControlList)
|
|
{
|
|
string controlName = !string.IsNullOrWhiteSpace(setModel.DbName) ? "txt_" + setModel.DbName : "txt_" + setModel.SysName;
|
|
System.Windows.Forms.Control ctr = this.MainControlPanel.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 = BaseImpl.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);
|
|
}
|
|
}
|
|
foreach (SysSetModel setModel in this.ControlList)
|
|
{
|
|
string defaultValue = "";
|
|
if (!string.IsNullOrEmpty(setModel.DefaultID))
|
|
{
|
|
defaultValue = setModel.DefaultID;
|
|
}
|
|
if (!string.IsNullOrEmpty(setModel.DefaultName))
|
|
{
|
|
defaultValue = this.TopControlObj.ReplaceControlValue(setModel.DefaultName);
|
|
if (defaultValue.StartsWith("@") || defaultValue.StartsWith("!"))
|
|
{
|
|
defaultValue = BaseImpl.GetDefaultValue(defaultValue);
|
|
}
|
|
}
|
|
if (!string.IsNullOrEmpty(defaultValue))
|
|
{
|
|
string controlName = !string.IsNullOrWhiteSpace(setModel.DbName) ? "txt_" + setModel.DbName : "txt_" + setModel.SysName;
|
|
System.Windows.Forms.Control ctr = this.MainControlPanel.Controls.Find(controlName, false).FirstOrDefault();
|
|
BaseUserControl baseUserControl = ctr as BaseUserControl;
|
|
baseUserControl.Invoke(new Action(() =>
|
|
{
|
|
baseUserControl.EditText = defaultValue;
|
|
}));
|
|
}
|
|
}
|
|
if (OnAfterDataSourceCallback != null)
|
|
{
|
|
OnAfterDataSourceCallback(null, null);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 动态控件值改变时
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnTextEditTextChanged(object sender, EventArgs e)
|
|
{
|
|
BaseUserControl baseControl = (sender as System.Windows.Forms.Control).ToBaseUserControl();
|
|
SysSetModel model = baseControl.Tag as SysSetModel;
|
|
// 是否存在关联值
|
|
if (!string.IsNullOrWhiteSpace(model.UnionValues) && !string.IsNullOrWhiteSpace(model.UnionFields))
|
|
{
|
|
this.SetUnionControl(model);//关联计算
|
|
}
|
|
if (model.OrderId.Equals(1) && this.NameBaseControl != null)//反写名称
|
|
{
|
|
this.NameBaseControl.EditText = baseControl.EditText;
|
|
//string speciesid = this.treeLeftViewEx.TreeView.SelectedNode.Name;
|
|
//string whereSql = string.Format(" and speciesno = '{0}' ", speciesid);
|
|
//this.SetMainGridView(whereSql);
|
|
}
|
|
if (model.SpecDbName.Equals(1) && this.SpecBaseControl != null)//反写规格
|
|
{
|
|
List<BaseUserControl> specControls = this.MainControlPanel.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);
|
|
if (!string.IsNullOrWhiteSpace(editText))
|
|
{
|
|
if (i == 0)
|
|
{
|
|
specText.Append(string.Format("{0}", editText));
|
|
}
|
|
else
|
|
{
|
|
specText.Append(string.Format("{0}{1}", sysSetModel.ConnectorStr, editText));
|
|
}
|
|
}
|
|
}
|
|
this.SpecBaseControl.EditText = specText.ToString();
|
|
}
|
|
if (model.ModelDbName.Equals(1) && this.ModelBaseControl != null)//反写型号
|
|
{
|
|
List<BaseUserControl> modelControls = this.MainControlPanel.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);
|
|
if (!string.IsNullOrWhiteSpace(editText))
|
|
{
|
|
if (i == 0)
|
|
{
|
|
modelText.Append(string.Format("{0}", editText));
|
|
}
|
|
else
|
|
{
|
|
modelText.Append(string.Format("{0}{1}", sysSetModel.ConnectorStr, editText));
|
|
}
|
|
}
|
|
}
|
|
this.ModelBaseControl.EditText = modelText.ToString();
|
|
}
|
|
if (model.ZhSxdbName.Equals(1) && this.ZhSxBaseControl != null)//反写综合属性
|
|
{
|
|
List<BaseUserControl> zhsxControls = this.MainControlPanel.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 = item.EditText;
|
|
if (editText.Equals("无"))
|
|
{
|
|
editText = "";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(editText))
|
|
{
|
|
if (i == 0)
|
|
{
|
|
zhsxText.Append(string.Format("{0}", editText));
|
|
}
|
|
else
|
|
{
|
|
zhsxText.Append(string.Format("{0}{1}", sysSetModel.ConnectorStr, editText));
|
|
}
|
|
}
|
|
}
|
|
this.ZhSxBaseControl.EditText = zhsxText.ToString();
|
|
}
|
|
if (model.CzdbName.Equals(1) && this.CzBaseControl != null)//反写材质属性
|
|
{
|
|
List<BaseUserControl> czControls = this.MainControlPanel.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 = item.EditText;
|
|
if (editText.Equals("无"))
|
|
{
|
|
editText = "";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(editText))
|
|
{
|
|
if (i == 0)
|
|
{
|
|
czText.Append(string.Format("{0}", editText));
|
|
}
|
|
else
|
|
{
|
|
czText.Append(string.Format("{0}{1}", sysSetModel.ConnectorStr, editText));
|
|
}
|
|
}
|
|
}
|
|
this.CzBaseControl.EditText = czText.ToString();
|
|
}
|
|
model.SourceRow["sysvalue"] = baseControl.EditText;
|
|
}
|
|
/// <summary>
|
|
/// 反写规格型号时获取BaseUserControl的值
|
|
/// </summary>
|
|
/// <param name="baseUserControl"></param>
|
|
/// <param name="setModel"></param>
|
|
/// <returns></returns>
|
|
private string GetBaseControlValue(BaseUserControl baseUserControl)
|
|
{
|
|
string rtnValue = "";
|
|
try
|
|
{
|
|
SysSetModel setModel = baseUserControl.Tag as SysSetModel;
|
|
switch (setModel.Item)//控件类型
|
|
{
|
|
case "1":
|
|
LabelAutoTextEdit labelAutoTextEdit = baseUserControl as LabelAutoTextEdit;
|
|
if (setModel.FxType.Equals("名称"))
|
|
{
|
|
rtnValue = labelAutoTextEdit.EditText;
|
|
}
|
|
else if (setModel.FxType.Equals("编码"))
|
|
{
|
|
rtnValue = labelAutoTextEdit.EditValue;
|
|
}
|
|
break;
|
|
case "3":
|
|
LabelMultiAutoTextEdit labelMultiAutoTextEdit = baseUserControl as LabelMultiAutoTextEdit;
|
|
if (setModel.FxType.Equals("名称"))
|
|
{
|
|
rtnValue = labelMultiAutoTextEdit.EditText;
|
|
}
|
|
else if (setModel.FxType.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 (setModel.FxType.Equals("名称"))
|
|
{
|
|
rtnValue = labelAutoMemoEdit.EditText;
|
|
}
|
|
else if (setModel.FxType.Equals("编码"))
|
|
{
|
|
rtnValue = labelAutoMemoEdit.EditValue;
|
|
}
|
|
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>创建日期: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, this.MainControlPanel);
|
|
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>
|
|
/// <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, System.Windows.Forms.Control control)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(defaultValue))
|
|
{
|
|
defaultValue = ReplaceHelper.ReplaceUserInfo(defaultValue);
|
|
var paramList = ReplaceHelper.GetParamFields(defaultValue);
|
|
foreach (string item in paramList)
|
|
{
|
|
string field = item.Replace("{", "").Replace("}", "");
|
|
if (FindControl(field, control) != null)
|
|
{
|
|
string value = GetControlValue(field);
|
|
defaultValue = defaultValue.Replace(item, value);
|
|
}
|
|
}
|
|
}
|
|
return defaultValue;
|
|
}
|
|
/// <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, bool getId = false)
|
|
{
|
|
string value = string.Empty;
|
|
var ctrs = MainControlPanel.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 (getId)
|
|
{
|
|
value = labelAutoTextEdit.EditValue;
|
|
}
|
|
else
|
|
{
|
|
if (setModel.FxTypeDB.Equals("编码"))
|
|
{
|
|
value = labelAutoTextEdit.EditValue;
|
|
}
|
|
else if (setModel.FxTypeDB.Equals("名称"))
|
|
{
|
|
value = labelAutoTextEdit.EditText;
|
|
}
|
|
}
|
|
break;
|
|
//多选框控件
|
|
case "3":
|
|
LabelMultiAutoTextEdit labelMultiAutoTextEdit = ctr as LabelMultiAutoTextEdit;
|
|
if (getId)
|
|
{
|
|
value = labelMultiAutoTextEdit.EditValue;
|
|
}
|
|
else
|
|
{
|
|
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 (getId)
|
|
{
|
|
value = labelAutoMemoEdit.EditValue;
|
|
}
|
|
else
|
|
{
|
|
if (setModel.FxTypeDB.Equals("编码"))
|
|
{
|
|
value = labelAutoMemoEdit.EditValue;
|
|
}
|
|
else if (setModel.FxTypeDB.Equals("名称"))
|
|
{
|
|
value = labelAutoMemoEdit.EditText;
|
|
}
|
|
}
|
|
break;
|
|
//文本框控件
|
|
case "2":
|
|
default:
|
|
LabelTextEdit labelTextEdit = ctr as LabelTextEdit;
|
|
value = labelTextEdit.EditText;
|
|
break;
|
|
}
|
|
}
|
|
return value;
|
|
}
|
|
/// <summary>
|
|
/// 设置控件值
|
|
/// </summary>
|
|
/// <param name="controlName"></param>
|
|
/// <param name="controlValue"></param>
|
|
public void SetControlValue(string controlName, object controlValue)
|
|
{
|
|
BaseUserControl baseControl = FindControl(controlName, this.MainControlPanel);
|
|
if (baseControl == null) return;
|
|
baseControl.EditText = controlValue + "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置控件值
|
|
/// </summary>
|
|
/// <param name="dataRow"></param>
|
|
public void SetAllControlValue(DataRow dataRow)
|
|
{
|
|
string primaryVlaue = dataRow["productid"] + "";
|
|
DataRow selectSource = BaseImpl.GetDataRowResult(string.Format("select * from p_producttab where productid = '{0}'", primaryVlaue));
|
|
if (selectSource != null)
|
|
{
|
|
TopControlObj.SetAllControlValue(selectSource);
|
|
}
|
|
if (dataRow != null)
|
|
{
|
|
TopControlObj.SetAllControlValue(dataRow);
|
|
}
|
|
if (BomAlterModel != null && BomAlterModel.MaintabFocusedRow != null)
|
|
{
|
|
TopControlObj.SetAllControlValue(BomAlterModel.MaintabFocusedRow);
|
|
}
|
|
List<BaseUserControl> modelControls = this.MainControlPanel.Controls.Cast<BaseUserControl>().Where(n => !string.IsNullOrEmpty((n.Tag as SysSetModel).DbName)).OrderBy(n => (n.Tag as SysSetModel).OrderId).ToList();
|
|
if (selectSource == null)
|
|
{
|
|
primaryVlaue = dataRow["plm_lmb_id"] + "";
|
|
selectSource = BaseImpl.GetDataRowResult(string.Format("select * from Plm_MbomListTab where plm_lmb_id = '{0}'", primaryVlaue));
|
|
foreach (BaseUserControl item in modelControls)
|
|
{
|
|
SysSetModel sysSetModel = item.Tag as SysSetModel;
|
|
string value = "";
|
|
if (selectSource != null)
|
|
{
|
|
value = selectSource.Table.Columns.Contains(sysSetModel.DbName) ? selectSource[sysSetModel.DbName] + "" : "";
|
|
}
|
|
item.EditText = value;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (BaseUserControl item in modelControls)
|
|
{
|
|
SysSetModel sysSetModel = item.Tag as SysSetModel;
|
|
string value = "";
|
|
if (selectSource != null)
|
|
{
|
|
value = selectSource.Table.Columns.Contains(sysSetModel.DbName) ? selectSource[sysSetModel.DbName] + "" : "";
|
|
}
|
|
item.EditText = value;
|
|
}
|
|
}
|
|
//if (!string.IsNullOrEmpty(lastValues))
|
|
//{
|
|
// string[] lastValueArray = lastValues.Split('\\');
|
|
// for (int i = 0; i < modelControls.Count; i++)
|
|
// {
|
|
// if (i == 0)
|
|
// {
|
|
// continue;
|
|
// }
|
|
// int index = i - 1;
|
|
// string value = index >= 0 && lastValueArray.Length > index ? lastValueArray[index] : "";
|
|
// BaseUserControl item = modelControls[i];
|
|
// item.EditText = value;
|
|
// }
|
|
//}
|
|
}
|
|
/// <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 control)
|
|
{
|
|
System.Windows.Forms.Control controlObj = new System.Windows.Forms.Control();
|
|
controlObj = control.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>
|
|
/// 分隔条位置改变时
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnSplitMainContainerPositionChanged(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (this.BomAlterModel != null)
|
|
{
|
|
IniHelper.Write(string.Format("PubBomAlter_SplitRight_{0}", this.BomAlterModel.ModuleCode), this.splitRightContainer.SplitterPosition + "");
|
|
IniHelper.Write(string.Format("PubBomAlter_SplitControl_{0}", this.BomAlterModel.ModuleCode), this.splitControlContainer.SplitterPosition + "");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageUtil.Show(ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 表格双击选中
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnGcDetailGridViewDoubleClick(object sender, EventArgs e)
|
|
{
|
|
Point point = this.gcDetailControlEx.GridControl.PointToClient(MousePosition);
|
|
GridHitInfo hitInfo = this.gcDetailControlEx.GridView.CalcHitInfo(point);
|
|
if (hitInfo.InRow)
|
|
{
|
|
if (hitInfo.RowHandle >= 0)
|
|
{
|
|
if (this.gcDetailControlEx.GridView.IsRowSelected(hitInfo.RowHandle))
|
|
{
|
|
this.gcDetailControlEx.GridView.UnselectRow(hitInfo.RowHandle);
|
|
}
|
|
else
|
|
{
|
|
this.gcDetailControlEx.GridView.SelectRow(hitInfo.RowHandle);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 选中改变事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnGridViewSelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
|
|
{
|
|
DataRow focusedRow = this.gcMainControlEx.GridView.GetFocusedDataRow();
|
|
this.gcDetailControlEx.GridView.SelectionChanged -= OnGridViewSelectionChanged;
|
|
//清除所有选择
|
|
this.gcDetailControlEx.GridView.ClearSelection();
|
|
if (e.Action == CollectionChangeAction.Add)//选中
|
|
{
|
|
this.gcDetailControlEx.GridView.SelectRow(e.ControllerRow);
|
|
}
|
|
this.gcDetailControlEx.GridView.SelectionChanged += OnGridViewSelectionChanged;
|
|
int[] indexs = this.gcDetailControlEx.GridView.GetSelectedRows();
|
|
string dbName = focusedRow["DbName"] + "";
|
|
string sysName = focusedRow["SysName"] + "";
|
|
string controlName = !string.IsNullOrWhiteSpace(dbName) ? "txt_" + dbName : "txt_" + sysName;
|
|
System.Windows.Forms.Control ctr = this.MainControlPanel.Controls.Find(controlName, false).FirstOrDefault();
|
|
if (ctr != null)
|
|
{
|
|
BaseUserControl selectControl = ctr as BaseUserControl;
|
|
if (indexs.Length > 0 && focusedRow != null)
|
|
{
|
|
DataRow dataRow = this.gcDetailControlEx.GridView.GetDataRow(indexs[0]);
|
|
string value = dataRow["sysnamelist"] + "";
|
|
selectControl.EditText = value;
|
|
}
|
|
else
|
|
{
|
|
selectControl.EditText = "";
|
|
}
|
|
}
|
|
}
|
|
/// <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>
|
|
private void OnBtnPmsSaveClick(object sender, EventArgs e)
|
|
{
|
|
TreeListNode focusedNode = treeGridControlEx.TreeListObj.FocusedNode;
|
|
DataRow focusedRow = (treeGridControlEx.TreeListObj.GetDataRecordByNode(focusedNode) as DataRowView).Row;
|
|
if (focusedNode.ParentNode == null || (focusedNode.ParentNode != null && (focusedNode.ParentNode["Plm_lmb_updatetig"] + "").Equals("1")))
|
|
{
|
|
try
|
|
{
|
|
WaitForm.ShowForm("正在保存数据");
|
|
if (this.VerifyNull(this.MainControlPanel))
|
|
{
|
|
if (!string.IsNullOrEmpty(BomAlterModel.VerifySql))
|
|
{
|
|
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", sysModel.MenuTable)) + "";
|
|
DataTable tableColumns = BaseImpl.GetTableColumns(sysModel.MenuTable);
|
|
string primaryKey = BaseImpl.GetBasePrimaryKey(this.BomAlterModel.ModuleCode);
|
|
string newBillNo = focusedRow[primaryKey] + "";
|
|
ControlModel model = this.TopControlObj._models.FirstOrDefault(x => x.FieldName == primaryKey);
|
|
List<string> keyList = new List<string>() { "speciesno", "operatorname", "operatedate", "smartbmfa" };
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder alterTableSqlBuilder = new StringBuilder();
|
|
List<BaseUserControl> modelControls = this.MainControlPanel.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))
|
|
{
|
|
if (!tableColumns.Columns.Contains(sysSetModel.DbName))
|
|
{
|
|
alterTableSqlBuilder.AppendLine($"alter table {sysModel.MenuTable} add {sysSetModel.DbName} varchar(1000);");
|
|
}
|
|
keyList.Add(sysSetModel.DbName.ToLower());
|
|
sqlBuilder.Append(string.Format("{0} = '{1}',", sysSetModel.DbName, fxValue.Replace("'", "''")));
|
|
}
|
|
}
|
|
foreach (ControlModel item in this.TopControlObj.ControlModels)
|
|
{
|
|
if (!item.IsSave ||
|
|
"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 ||
|
|
Autogrowcolumn.ToLower() == item.FieldName.ToLower())
|
|
continue;
|
|
BaseUserControl userControl = this.TopControlObj.FindControl(item);
|
|
if (userControl != null)
|
|
{
|
|
string fieldValue = this.TopControlObj.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()))
|
|
{
|
|
if (!tableColumns.Columns.Contains(item.FieldName))
|
|
{
|
|
alterTableSqlBuilder.AppendLine($"alter table {sysModel.MenuTable} add {item.FieldName} varchar(1000);");
|
|
}
|
|
sqlBuilder.Append(string.IsNullOrEmpty(fieldValue) ? string.Format("{0} = {1}", item.FieldName, this.TopControlObj.GetNullValue(item)) : string.Format("{0}='{1}',", item.FieldName, fieldValue));
|
|
}
|
|
}
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(alterTableSqlBuilder.ToString()))
|
|
{
|
|
BaseImpl.ExecSqlValue(alterTableSqlBuilder.ToString());
|
|
}
|
|
string execSql = "";
|
|
if (!string.IsNullOrWhiteSpace(sqlBuilder.ToString()))
|
|
{
|
|
execSql = string.Format("update {0} set {1} where {2} = '{3}'", sysModel.MenuTable, sqlBuilder.ToString().TrimEnd(','), primaryKey, newBillNo);
|
|
}
|
|
BaseSaveModel saveModel = new BaseSaveModel
|
|
{
|
|
BaseSaveType = SaveType.Update,
|
|
BaseSql = execSql,
|
|
KeyField = primaryKey,
|
|
FieldValue = newBillNo,
|
|
MenuCode = sysModel.ModeCode,
|
|
TableName = sysModel.MenuTable,
|
|
ComfirmFlag = 0,
|
|
NewVer = sysModel.NewVer
|
|
};
|
|
int result = BaseModuleImpl.SaveBasePanelData(saveModel);
|
|
if (result == 1)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show(ResourceKeys.SaveFault + "\r\n" + saveModel.FaultMsg);
|
|
return;
|
|
}
|
|
string pattern = @"(\w+)\((.*?)\)";
|
|
Regex regex = new Regex(pattern);
|
|
Match match = regex.Match(BomAlterModel.VerifySql);
|
|
if (match.Success)
|
|
{
|
|
string functionName = match.Groups[1].Value;
|
|
string parameters = match.Groups[2].Value;
|
|
if (!string.IsNullOrEmpty(functionName))
|
|
{
|
|
DataTable sqlParametersTab = BaseImpl.GetDataTableResult($"SELECT PARAMETER_NAME,PARAMETER_MODE,CHARACTER_MAXIMUM_LENGTH,DATA_TYPE FROM INFORMATION_SCHEMA.PARAMETERS WHERE SPECIFIC_NAME = '{functionName}' ORDER BY ORDINAL_POSITION;");
|
|
using (SqlCommand command = new SqlCommand(functionName, SqlHelper._connection))
|
|
{
|
|
string[] parametersArray = parameters.Split(',');
|
|
foreach (DataRow parameterRow in sqlParametersTab.Rows)
|
|
{
|
|
string parameterName = parameterRow["PARAMETER_NAME"] + "";
|
|
string parameterMode = parameterRow["PARAMETER_MODE"] + "";
|
|
int.TryParse(parameterRow["CHARACTER_MAXIMUM_LENGTH"] + "", out int dataLength);
|
|
string dataType = parameterRow["DATA_TYPE"] + "";
|
|
SqlParameter sqlParameter = null;
|
|
if (parameterMode.Equals("int"))
|
|
{
|
|
sqlParameter = new SqlParameter(parameterName, SqlDbType.Int);
|
|
}
|
|
else
|
|
{
|
|
sqlParameter = new SqlParameter(parameterName, SqlDbType.VarChar, dataLength);
|
|
}
|
|
if (parameterMode.Equals("IN"))
|
|
{
|
|
sqlParameter.Direction = ParameterDirection.Input;
|
|
}
|
|
else
|
|
{
|
|
sqlParameter.Direction = ParameterDirection.Output;
|
|
}
|
|
command.Parameters.Add(sqlParameter);
|
|
}
|
|
for (int i = 0; i < command.Parameters.Count; i++)
|
|
{
|
|
SqlParameter sqlParameter = command.Parameters[i];
|
|
if (parametersArray.Length > i)
|
|
{
|
|
string commandParameter = parametersArray[i];
|
|
string field = commandParameter.Replace("@", "").Replace("{", "").Replace("}", "");
|
|
string value = focusedRow.Table.Columns.Contains(field) ? focusedRow[field] + "" : commandParameter.Replace("@", "");
|
|
value = SearchObj.ReplaceControlValue(value);
|
|
value = TopControlObj.ReplaceControlValue(value);
|
|
value = ReplaceControlValue(value, MainControlPanel);
|
|
value = value.Replace("@", "").Replace("{", "").Replace("}", "");
|
|
sqlParameter.Value = value;
|
|
}
|
|
}
|
|
SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4);
|
|
returnValue.Direction = ParameterDirection.ReturnValue;
|
|
command.Parameters.Add(returnValue);
|
|
command.CommandType = CommandType.StoredProcedure;
|
|
command.ExecuteNonQuery();
|
|
if ((returnValue.Value + "").Equals("1"))
|
|
{
|
|
SearchObj.SearchGrid();
|
|
}
|
|
SqlParameter outSqlParameter = command.Parameters.Cast<SqlParameter>().Where(n => n.Direction == ParameterDirection.Output).FirstOrDefault();
|
|
if (outSqlParameter != null)
|
|
{
|
|
string outMessage = outSqlParameter.Value + "";
|
|
if (!string.IsNullOrEmpty(outMessage))
|
|
{
|
|
MessageUtil.Show(outSqlParameter.Value + "");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("保存逻辑配置错误");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("保存逻辑配置错误");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("保存逻辑配置错误,不能为空");
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageUtil.Show(ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
WaitForm.HideForm();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("父节点未修改");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 保存按钮
|
|
/// </summary>
|
|
private void OnBtnSaveClick(object sender, EventArgs e)
|
|
{
|
|
TreeGridControlEx treeMain = TreeGridObj;
|
|
string tableName = this.sysModel.MenuTable;
|
|
if (string.IsNullOrEmpty(tableName))
|
|
{
|
|
MessageUtil.Show(ResourceKeys.MenuTableNameIsNull);
|
|
return;
|
|
}
|
|
List<BaseSaveModel> mList = new List<BaseSaveModel>();
|
|
DataRow[] modifiedRows = (treeMain.TreeListObj.DataSource as DataTable)
|
|
.Rows
|
|
.Cast<DataRow>()
|
|
.Where(x => x.RowState == DataRowState.Modified || x.RowState == DataRowState.Added)
|
|
.ToArray();
|
|
|
|
if (modifiedRows == null || modifiedRows.Length == 0)
|
|
{
|
|
MessageUtil.Show(ResourceKeys.UnUpdateData);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
string _parmaryKey = BaseImpl.GetBasePrimaryKey(this.BomAlterModel.ModuleCode);//获取主键
|
|
DataColumnCollection columns = BaseImpl.GetTableColumns(tableName).Columns;
|
|
foreach (DataRow row in modifiedRows)
|
|
{
|
|
string updateSql = "update {0} set {1} where {2}='{3}';";
|
|
string insertSql = "insert into {0}({1}) values({2});";
|
|
string updateFields = string.Empty;
|
|
string insertFields = string.Empty;
|
|
string insertValues = string.Empty;
|
|
BaseSaveModel model = new BaseSaveModel()
|
|
{
|
|
MenuCode = this.BomAlterModel.ModuleCode,
|
|
TableName = tableName,
|
|
KeyField = _parmaryKey,
|
|
NewVer = this.sysModel.NewVer
|
|
};
|
|
foreach (DataColumn col in columns)
|
|
{
|
|
// 区分大小写匹配列
|
|
DataRow hasContainRow = _gridColumns.Rows.Cast<DataRow>().FirstOrDefault(x => x["fieldname"] + "" == col.ColumnName);
|
|
if (hasContainRow != null && col.ColumnName != _parmaryKey && !_disUpdateColumns.Contains(col.ColumnName))
|
|
{
|
|
if (row.RowState == DataRowState.Modified && string.IsNullOrEmpty(sysModel.CustomColumnSQL))
|
|
{
|
|
if ((col.DataType == typeof(DateTime)) && (row[col.ColumnName] + "" == ""))
|
|
{
|
|
updateFields += string.Format("[{0}]=null,", col.ColumnName);
|
|
}
|
|
else
|
|
{
|
|
if (col.DataType == typeof(Decimal) && string.IsNullOrWhiteSpace((row[col.ColumnName] + "").Replace("'", "''")))
|
|
{
|
|
updateFields += string.Format("[{0}]='{1}',", col.ColumnName, 0);
|
|
}
|
|
else
|
|
{
|
|
updateFields += string.Format("[{0}]='{1}',", col.ColumnName, (row[col.ColumnName] + "").Replace("'", "''"));
|
|
}
|
|
|
|
}
|
|
}
|
|
else if (row.RowState == DataRowState.Added || (row.RowState == DataRowState.Modified && !string.IsNullOrEmpty(sysModel.CustomColumnSQL)))
|
|
{
|
|
// 动态生成列,保存时默认全部为新增
|
|
string fieldValue = (row[col.ColumnName] + "").Replace("'", "''");
|
|
insertFields += "[" + col.ColumnName + "],";
|
|
if (!string.IsNullOrWhiteSpace(fieldValue))
|
|
{
|
|
insertValues += col.DataType == typeof(DateTime) ? "'" + Convert.ToDateTime(fieldValue).ToString("yyyy-MM-dd HH:mm:ss") + "'," : "'" + fieldValue + "',";
|
|
}
|
|
else
|
|
{
|
|
if (col.DataType == typeof(Decimal) || col.DataType == typeof(Int32))
|
|
insertValues += "0,";
|
|
else if (col.DataType == typeof(DateTime))
|
|
insertValues += "NULL,";
|
|
else
|
|
insertValues += "'',";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
updateFields = updateFields.TrimEnd(',');
|
|
insertFields = insertFields.TrimEnd(',');
|
|
insertValues = insertValues.TrimEnd(',');
|
|
|
|
if (!string.IsNullOrEmpty(updateFields))
|
|
{
|
|
model.FieldValue = row[_parmaryKey] + "";
|
|
model.BaseSaveType = SaveType.Update;
|
|
model.BaseSql = string.Format(updateSql, tableName, updateFields, _parmaryKey, row[_parmaryKey]);
|
|
}
|
|
if (!string.IsNullOrEmpty(insertFields))
|
|
{
|
|
model.BaseSaveType = SaveType.Add;
|
|
model.FieldValue = row[_parmaryKey] + "";
|
|
model.BaseSql = string.Format(insertSql, tableName, insertFields, insertValues);
|
|
}
|
|
mList.Add(model);
|
|
}
|
|
try
|
|
{
|
|
// 批量保存数据
|
|
if (BaseModuleImpl.SaveBaseGridData(mList))
|
|
{
|
|
(treeMain.TreeListObj.DataSource as DataTable).AcceptChanges();
|
|
if (this.SearchObj != null)
|
|
{
|
|
this.SearchObj.SearchLastGrid();
|
|
}
|
|
MessageUtil.Show(ResourceKeys.SaveSuccess);
|
|
}
|
|
else
|
|
{
|
|
StringBuilder builder = new StringBuilder();
|
|
builder.Append("失败列表\r\n");
|
|
foreach (BaseSaveModel item in mList)
|
|
{
|
|
if (!string.IsNullOrEmpty(item.FaultMsg))
|
|
builder.Append("原因:" + item.FaultMsg + "\r\n"); ;
|
|
}
|
|
LogHelper.Instance.WriteLog(builder.ToString());
|
|
MessageUtil.Show(builder.ToString());
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 提交按钮
|
|
/// </summary>
|
|
private void OnBtnApplyClick(object sender, EventArgs e)
|
|
{
|
|
TreeListNode focusedNode = treeGridControlEx.TreeListObj.FocusedNode;
|
|
DataRow focusedRow = (treeGridControlEx.TreeListObj.GetDataRecordByNode(focusedNode) as DataRowView).Row;
|
|
if (!string.IsNullOrEmpty(BomAlterModel.SaveSql))
|
|
{
|
|
string pattern = @"(\w+)\((.*?)\)";
|
|
Regex regex = new Regex(pattern);
|
|
Match match = regex.Match(BomAlterModel.SaveSql);
|
|
if (match.Success)
|
|
{
|
|
string functionName = match.Groups[1].Value;
|
|
string parameters = match.Groups[2].Value;
|
|
if (!string.IsNullOrEmpty(functionName))
|
|
{
|
|
DataTable sqlParametersTab = BaseImpl.GetDataTableResult($"SELECT PARAMETER_NAME,PARAMETER_MODE,CHARACTER_MAXIMUM_LENGTH,DATA_TYPE FROM INFORMATION_SCHEMA.PARAMETERS WHERE SPECIFIC_NAME = '{functionName}' ORDER BY ORDINAL_POSITION;");
|
|
using (SqlCommand command = new SqlCommand(functionName, SqlHelper._connection))
|
|
{
|
|
string[] parametersArray = parameters.Split(',');
|
|
foreach (DataRow parameterRow in sqlParametersTab.Rows)
|
|
{
|
|
string parameterName = parameterRow["PARAMETER_NAME"] + "";
|
|
string parameterMode = parameterRow["PARAMETER_MODE"] + "";
|
|
int.TryParse(parameterRow["CHARACTER_MAXIMUM_LENGTH"] + "", out int dataLength);
|
|
string dataType = parameterRow["DATA_TYPE"] + "";
|
|
SqlParameter sqlParameter = null;
|
|
if (parameterMode.Equals("int"))
|
|
{
|
|
sqlParameter = new SqlParameter(parameterName, SqlDbType.Int);
|
|
}
|
|
else
|
|
{
|
|
sqlParameter = new SqlParameter(parameterName, SqlDbType.VarChar, dataLength);
|
|
}
|
|
if (parameterMode.Equals("IN"))
|
|
{
|
|
sqlParameter.Direction = ParameterDirection.Input;
|
|
}
|
|
else
|
|
{
|
|
sqlParameter.Direction = ParameterDirection.Output;
|
|
}
|
|
command.Parameters.Add(sqlParameter);
|
|
}
|
|
for (int i = 0; i < command.Parameters.Count; i++)
|
|
{
|
|
SqlParameter sqlParameter = command.Parameters[i];
|
|
if (parametersArray.Length > i)
|
|
{
|
|
string commandParameter = parametersArray[i];
|
|
string field = commandParameter.Replace("@", "").Replace("{", "").Replace("}", "");
|
|
string value = focusedRow.Table.Columns.Contains(field) ? focusedRow[field] + "" : commandParameter.Replace("@", "");
|
|
value = SearchObj.ReplaceControlValue(value);
|
|
value = TopControlObj.ReplaceControlValue(value);
|
|
value = ReplaceControlValue(value, MainControlPanel);
|
|
value = value.Replace("@", "").Replace("{", "").Replace("}", "");
|
|
sqlParameter.Value = value;
|
|
}
|
|
}
|
|
SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4);
|
|
returnValue.Direction = ParameterDirection.ReturnValue;
|
|
command.Parameters.Add(returnValue);
|
|
command.CommandType = CommandType.StoredProcedure;
|
|
command.ExecuteNonQuery();
|
|
if ((returnValue.Value + "").Equals("1"))
|
|
{
|
|
MessageUtil.Show("保存成功");
|
|
}
|
|
else
|
|
{
|
|
SqlParameter outSqlParameter = command.Parameters.Cast<SqlParameter>().Where(n => n.Direction == ParameterDirection.Output).FirstOrDefault();
|
|
if (outSqlParameter != null)
|
|
{
|
|
string outMessage = outSqlParameter.Value + "";
|
|
if (!string.IsNullOrEmpty(outMessage))
|
|
{
|
|
MessageUtil.Show(outSqlParameter.Value + "");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("保存逻辑配置错误");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("保存逻辑配置错误");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("保存逻辑配置错误,不能为空");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 自动刷新
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnSearchObjDataSourceBindCallBack(object sender, EventArgs e)
|
|
{
|
|
if (sysModel.CsHasDefultSearch)
|
|
{
|
|
SearchObj.SearchGrid();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 查询后事件
|
|
/// </summary>
|
|
/// < |