Files
lserp_cs_6.0/插件库/Lskj.Control/ModuleGridEx.cs
T
2026-08-04 13:49:05 +08:00

6088 lines
272 KiB
C#

/******************************
* 说明:带操作表格的自定义控件
* 创建人:龚宇超
* 创建日期:2017-09-01
* 修改人:
* 修改日期:
* 修改备注:
* 版本:1.0.0.0
******************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraGrid;
using Lskj.Control;
using Lskj.Data;
using Lskj.Business.Impl;
using Lskj.Control.Model;
using DevExpress.XtraBars;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Columns;
using System.Collections;
using Lskj.Business;
using Lskj.Util;
using Lskj.Model;
using System.Data.SqlClient;
using System.IO;
using DevExpress.XtraGrid.Views.Layout;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraTab;
using DevExpress.XtraEditors;
using System.Text.RegularExpressions;
using System.Diagnostics;
using Lskj.Core;
using Lskj.Util.HttpUtil;
using Lskj.WebErp.Core.BLL.Abstract;
using Lskj.Data.Api.BLL;
using DevExpress.XtraGrid.Views.Base;
using System.Threading.Tasks;
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.XtraTreeList.Nodes;
namespace Lskj.Control
{
/// <summary>
/// 带操作表格的自定义控件
/// </summary>
public partial class ModuleGridEx : UserControl
{
#region private property
/// <summary>
/// 常用打印对象,用于加载时暂时获取焦点
/// </summary>
/// <value>The title label object.</value>
public DevExpress.XtraEditors.DropDownButton ddbOperObj { get { return ddbOper; } }
/// <summary>
/// 扫码控件
/// </summary>
private LabelTextEdit _scanEdit;
/// <summary>
/// 设置操作按钮是否可用(包含添加、删除、保存、导入)
/// </summary>
private bool _visibleOperPanel = true;
/// <summary>
/// 设置查询面板是否显示
/// </summary>
private bool _visibleSearchPanel = true;
/// <summary>
/// mrp模式下查询面板显示
/// </summary>
private bool _visibleMrpSearchPanel;
/// <summary>
/// 底部操作按钮是否显示简短模式,默认为简短模式
/// </summary>
private bool _operShortMode = true;
/// <summary>
/// 是否直接打印
/// </summary>
private bool _isExcPrint;
/// <summary>
/// 主打印Sql
/// </summary>
private string _mainPrintSql;
/// <summary>
/// 打印主sql中关联打印次数返回条件
/// </summary>
private string _printModeCond;
/// <summary>
/// 无需更新的列
/// </summary>
private string[] _disUpdateColumns = { "id" };
/// <summary>
/// 主键
/// </summary>
private string _parmaryKey = string.Empty;
/// <summary>
/// 树结构、表格、配置字段
/// </summary>
private string _parentKey = string.Empty;
/// <summary>
/// 打印完成后添加数据用到的参数
/// </summary>
private List<string> _printSaveParams;
/// <summary>
/// The bbi_import
/// </summary>
private BarButtonItem bbi_import, bbi_export, bbi_word, bbi_print, bbi_detail_export, bbi_Allexport;
/// <summary>
/// 左侧表格列字段
/// </summary>
private DataRow _leftGridField;
/// <summary>
/// 必须录入字段
/// </summary>
private DataRow[] _nullFields = new DataRow[] { };
/// <summary>
/// 查询条件
/// </summary>
private DataTable _queryTable = new DataTable();
/// <summary>
/// 固定查询条件
/// </summary>
private DataTable _fixedQueryTable = new DataTable();
/// <summary>
/// 表格列
/// </summary>
private DataTable _gridColumns = new DataTable();
/// <summary>
/// The _grid all columns
/// </summary>
private DataTable _gridAllColumns = new DataTable();
/// <summary>
/// 高级查询条件设置
/// </summary>
private DataTable _schemesTable = new DataTable();
/// <summary>
/// 保存验证条件表
/// </summary>
public DataTable SaveCondTab = new DataTable();
/// <summary>
/// 判断明细是否是拖拽中
/// </summary>
private bool isSortDrag;
/// <summary>
/// 按钮形式展示的右键信息
/// </summary>
private List<DataRow> ButtonModeRightMenus = new List<DataRow>();
/// <summary>
/// 按钮形式展示的右键
/// </summary>
private List<SimpleButton> RightButtons = new List<SimpleButton>();
/// <summary>
/// 附加右键菜单集合
/// </summary>
public List<SimpleButton> itemCommonList = new List<SimpleButton>();
/// <summary>
/// 排序关联值
/// </summary>
private string DetailOrderField = string.Empty;
private Point m_mouseDownLocation;
private int m_dragHandle;
private int[] dragRowsIndex;
private DragForm m_dragRowShadow;
/// <summary>
/// Occurs when [on Save Grid call back].
/// </summary>
public event EventHandler OnSaveGridCallBack;
/// <summary>
/// 删除按钮点击后
/// </summary>
public event EventHandler AfterDeleteGridCallBack;
/// <summary>
/// 右键执行后回调
/// </summary>
public event EventHandler RightGridCallBack;
/// <summary>
/// 下面明细表右键执行后回调
/// </summary>
public event EventHandler DetailRightGridCallBack;
/// <summary>
/// Occurs when [on close callback].
/// </summary>
public event EventHandler OnCloseCallback;
/// <summary>
/// 点击刷新按钮后执行后回调
/// </summary>
public event EventHandler AfterRefreshingCallBack;
/// <summary>
/// 初始数据源对应
/// </summary>
public Dictionary<DataRow, DataRow> LineStatus = new Dictionary<DataRow, DataRow>();
/// <summary>
/// 拖拽模式
/// </summary>
public bool isDrag = false;
/// <summary>
/// 是否保存成功(Lskj.PubBillSpecial点击保存后,先执行右上方表格保存)
/// </summary>
public bool isSuccessfullySaved;
/// <summary>
/// 扫码添加行
/// </summary>
public DataRow SweepCodeRow = null;
/// <summary>
/// 浏览器添加行是否成功
/// </summary>
public bool BrowserAddRow = false;
#endregion
#region public set property
/// <summary>
/// 公有化下标签
/// </summary>
public PanelControl ObjPanel
{
get
{
return this.pl_buttom;
}
}
/// <summary>
/// 搜索界面
/// </summary>
public Panel TipsobjPanel
{
get { return this.TipsPanel; }
}
public SimpleButton BtnSave
{
get { return this.btnSave; }
}
/// <summary>
/// 搜索界面
/// </summary>
public PanelControl SearchPanel
{
get { return this.pl_top_search; }
}
[Description("设置操作按钮是否可用(包含添加、删除、保存、导入)")]
public bool VisibleOperPanel
{
get
{
return this._visibleOperPanel;
}
set
{
this._visibleOperPanel = value;
this.pl_buttom.Visible = value;
}
}
[Description("设置查询面板是否显示")]
public bool VisibleSearchPanel
{
get
{
return this._visibleSearchPanel;
}
set
{
this._visibleSearchPanel = value;
this.pl_top.Visible = value;
if (!value)
{
this.pl_top_search.Visible = value;
this.pl_top_fix_search.Visible = value;
}
}
}
/// <summary>
/// mrp状态下查询控件显示
/// </summary>
public bool VisibleMrpSearchPanel
{
get
{
return this._visibleMrpSearchPanel;
}
set
{
this._visibleMrpSearchPanel = value;
if (value)
{
this.pl_top.Visible = value;
this.pl_top_search.Visible = value;
this.pl_top_right.Visible = false;
}
//this.pl_top_fix_search.Visible = false;
}
}
/// <summary>
/// 底部操作按钮是否显示简短模式,默认为简短模式
/// </summary>
/// <value><c>true</c> if [oper short mode]; otherwise, <c>false</c>.</value>
[Description("底部操作按钮是否显示简短模式,默认为简短模式")]
public bool OperShortMode
{
get { return _operShortMode; }
set
{
int width = 72, whiteSpace = 6;
if (value)
{
int left = this.Width - 232;
this.btnAdd.Left = left;
this.btnDel.Left = this.btnAdd.Left + width + whiteSpace;
this.btnSave.Left = this.btnDel.Left + width + whiteSpace;
}
else
{
int left = this.Width - 544;
this.btnAdd.Left = left;
this.btnDel.Left = this.btnAdd.Left + width + whiteSpace;
this.btnUpdate.Left = this.btnDel.Left + width + whiteSpace;
this.btnSave.Left = this.btnUpdate.Left + width + whiteSpace;
this.btnImport.Left = this.btnSave.Left + width + whiteSpace;
this.btnExport.Left = this.btnImport.Left + width + whiteSpace;
this.btnPrint.Left = this.btnExport.Left + width + whiteSpace;
}
this.btnUpdate.Visible = this.btnImport.Visible = this.btnExport.Visible = this.btnPrint.Visible = !value;
this._operShortMode = value;
}
}
#endregion
#region public property
/// <summary>
/// 是否为明细表格
/// </summary>
public bool IsDetail;
/// <summary>
/// 主键
/// </summary>
public string ParmaryKey;
/// <summary>
/// 左侧树结构、表格主键
/// </summary>
public string ParentKeyField;
/// <summary>
/// 特殊情况带入关联值,比如右键菜单调用
/// </summary>
public string ParentKeyValue;
/// <summary>
/// 左侧树结构、表格主键关联右侧数据字段
/// </summary>
public string ParentUnionField;
/// <summary>
/// 取底部数据字段
/// </summary>
public string DetailKeyField;
/// <summary>
/// 关联Key
/// </summary>
public string UnionKey;
/// <summary>
/// 关联Value
/// </summary>
public string UnionValue;
/// <summary>
/// 添加时给控件赋值
/// </summary>
public string ControlSql;
/// <summary>
/// 查询控件赋值
/// </summary>
public string SearchControlSql;
/// <summary>
/// 系统模块实体对象
/// </summary>
/// <value>The system model.</value>
public ModuleModel SysModel { get; private set; }
/// <summary>
/// 调用动态链接库默认传递参数
/// </summary>
public DynamicModel Model { get; private set; }
/// <summary>
/// 左侧树结构
/// </summary>
public TreeViewEx LeftTreeViewEx;
/// <summary>
/// 左侧表格
/// </summary>
public GridControlEx LeftGridEx;
/// <summary>
///特殊左侧表
/// </summary>
public GridControlEx SpecialLeftTable;
/// <summary>
/// 主表查询时,左侧树表格是否为精确查询(like改成=)
/// </summary>
public bool TreeExactQuery = false;
/// <summary>
/// 父容器表格
/// </summary>
public GridControlEx ParentGridEx;
/// <summary>
/// 用于随工单
///
/// 标签添加数据
/// </summary>
public MyControl ParentControlEx;
/// <summary>
/// 自定义查询条件
/// </summary>
public MyControl SearchObj { get; private set; }
/// <summary>
/// 左查询条件
/// </summary>
public MyControl _leftGridSearchObj;
/// <summary>
/// 表格对象
/// </summary>
/// <value>The grid view object.</value>
public GridControlEx GridControlObj
{
get { return this.gcMain; }
set { this.gcMain = value; }
}
/// <summary>
/// 底部多标签控件
/// </summary>
public XtraTabControl TabObj;
public event SaveEventHander SaveEvent;
/// <summary>
/// 保存完成事件
/// </summary>
/// <param name="sender">The sender.</param>
public delegate void SaveEventHander(string where = "");
/// 所有导出程序的回调函数
/// </summary>
public event EventHandler OnExportCallBack;
/// <summary>
/// 注册设置公共事件私有类
/// </summary>
private static PubEvenImpl _eventHandler;
/// <summary>
/// 注册设置公共事件类
/// </summary>
private static PubEvenImpl eventHandler;
/// <summary>
/// 父级条件控件,子控件的值替换父控件的值
/// </summary>
public MyControl ParentControlObj;
/// <summary>
/// 保存结果
/// </summary>
private bool SaveResults = false;
/// <summary>
/// 作为明细时对应的标签名
/// </summary>
public string TagName;
/// <summary>
/// 上方提示框是否创建
/// </summary>
public bool CreatePromptBox = false;
/// <summary>
/// 上方提示框
/// </summary>
public LabelRichEdit PromptBox = null;
/// <summary>
/// 上方高度
/// </summary>
public int TopHeight = 0;
/// <summary>
/// 附加模块关联主表的树型模式
/// </summary>
public bool AdditionalAssociatedMain = false;
/// <summary>
/// 点击搜索时,判断当前表的明细是否有修改或新增状态的行
/// </summary>
/// <param name="sender">The sender.</param>
public event VerifyDetailsTab verifyDetailsTab;
public delegate void VerifyDetailsTab();
#endregion
#region private method
/// <summary>
/// <para>说明:初始化查询条件(查询条件不自动查询)</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-09-05 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void InitializeQueryCondition(bool ProcessExists = false)
{
bool fixedQuery = _queryTable == null || _queryTable.Rows.Count == 0;
if (!Model.DataCaches.GetValue(this, "SearchObj", out MyControl searchObj))
{
searchObj = new MyControl(ReplaceBmpField(this.SysModel.MenuSql), gcMain, LeftTreeViewEx, LeftGridEx, _leftGridSearchObj);//替换sql语句中的bmp字段
searchObj.SpecialLeftTable = this.SpecialLeftTable;
searchObj.Model = Model;
}
this.SearchObj = searchObj;
if (this._leftGridField != null)
{
this.SearchObj.ParentKey = this._parentKey = this._leftGridField["fieldname"] + "";
}
this.SearchObj.ModuleId = Model.ModuleId;
this.SearchObj.ParentKeyField = this.ParentKeyField;
this.SearchObj.ParentUnionField = this.ParentUnionField;
//this.SearchObj.preSearchVerification += new PreSearchVerification(OnPreSearchVerification);// 查询条件执行前
this.SearchObj.OnSearchBeforeCallBack += new SearchEventHandler(OnSearchBeforeCallBack);// 查询条件执行前
this.SearchObj.OnSearchAfterCallBack += new EventHandler(OnSearchAfterCallBack);// 查询条件执行后
this.SearchObj.TreeExactQuery = this.TreeExactQuery;
// 明细表格默认不查询
this.SearchObj.OnDataSourceBindCallBack += new EventHandler(OnMainSearchDataSourceBindCallBack);// 数据源绑定完成触发
if (!string.IsNullOrEmpty(ParentKeyValue) && !string.IsNullOrEmpty(DetailKeyField))
this.SearchObj.WhereCond = string.Format(" and {0}='{1}'", DetailKeyField, ParentKeyValue);
if (fixedQuery)
{
//固定条件不显示,隐藏上方。(只显示表格)
if (SystemInfo.Instance.HideFixedConditions)
{
this.pl_top.Visible = false;
return;
}
this.pl_top_fix_search.Visible = true;
// 加载固定查询条件
if (!Model.DataCaches.GetValue(this, "FixedQueryFields", out DataTable table))
{
table = BaseModuleImpl.GetFixedQueryFields(this.Model.ModuleCode);//加载固定查询条件
}
if (Business.Impl.LanguageTranslation.Translatable)
{
table = Business.Impl.LanguageTranslation.TranslationTableColumn(table, "fieldText");
}
// DataTable
this.cbField.DisplayMember = "fieldText";
this.cbField.ValueMember = "fieldName";
this.cbField.DataSource = table;
if (this.VisibleMrpSearchPanel)
this.SearchObj.InitDefaultSearchControl(table, this.pl_top_fix_search, false);
else
this.SearchObj.InitDefaultSearchControl(table, this.pl_top_fix_search);
}
else
{
this.gcMain.gridControl.Tag = pl_top_search;
// 加载配置查询条件
this.pl_top_fix_search.Visible = false;
this.SearchObj.OtherParams = Model.OtherParams();
if (this.VisibleMrpSearchPanel)
this.pl_top.Height = this.SearchObj.InitSearchControl(_queryTable, this.pl_top_search, false, this._schemesTable, Model);
else
this.pl_top.Height = this.SearchObj.InitSearchControl(_queryTable, this.pl_top_search, this._schemesTable, Model);
}
}
/// <summary>
/// <para>说明:初始化常用操作</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-09-05 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void InitializeCommonOperation()
{
// 常用操作
bbi_import = new BarButtonItem();
bbi_import.Caption = "数据导入";
bbi_import.ItemClick += new ItemClickEventHandler(OnImportItemClick);
bbi_export = new BarButtonItem();
bbi_export.Caption = "数据导出";
bbi_export.ItemClick += new ItemClickEventHandler(OnExportItemClick);
bbi_Allexport = new BarButtonItem();
bbi_Allexport.Caption = "所有数据导出";
bbi_Allexport.ItemClick += new ItemClickEventHandler(OnAllExportItemClick);
bbi_detail_export = new BarButtonItem();
bbi_detail_export.Caption = "明细导出";
bbi_detail_export.ItemClick += new ItemClickEventHandler(btnExportInfo_Click);
bbi_print = new BarButtonItem();
bbi_print.Caption = "常规打印";
bbi_print.ItemClick += new ItemClickEventHandler(OnNormalPrintItemClick);
bbi_word = new BarButtonItem();
bbi_word.Caption = "帮助文档";
bbi_word.ItemClick += new ItemClickEventHandler(OnWordItemClick);
//string[] authorizedPersonnel = SysModel.ImportPermissions.Split(',');//有导入权限的人员
//if (string.IsNullOrWhiteSpace(SysModel.ImportPermissions) || Array.IndexOf(authorizedPersonnel, ERPInfo.Instance.UserName) != -1 || ERPInfo.Instance.UserName.Equals("管理员"))
//{
// pm_oper.AddItem(bbi_import);
//}
DataRow dr = null;
// 判断导入权限
if (this.SysModel.ImportEnable && this.ValidateCond(this.SysModel.ImportCond, dr, "P_SystemDllTab", "importCond"))
{
pm_oper.AddItem(bbi_import);
}
// 判断导出权限
this.gcMain.ExportPermission = false;
if (this.SysModel.ExportEnable && this.ValidateCond(this.SysModel.ExportCond, dr, "P_SystemDllTab", "exportCond") && this.SysModel.ExportPermission)
{
bbi_export.Tag = SysModel;
pm_oper.AddItem(bbi_export);
this.gcMain.ExportPermission = true; //this.SysModel.ExportPermission;
}
if (this.SysModel.ExportPermission && SystemInfo.Instance.DetailExportDisplay)
{
pm_oper.AddItem(bbi_detail_export);
}
//判断帮助文档
if (!SystemInfo.Instance.HideHelpDocument)
{
pm_oper.AddItem(bbi_word);
}
//pm_oper.AddItem(bbi_export);
//pm_oper.AddItem(bbi_Allexport);
// pm_oper.AddItem(bbi_detail_export);
if (SystemInfo.Instance.ConventionalPrintingDisplay)
{
pm_oper.AddItem(bbi_print);
}
//pm_oper.AddItem(bbi_word);
}
/// <summary>
/// <para>说明:初始化常用工具</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-04-09 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void InitializeCommonTool()
{
Dictionary<object, Hashtable> dataCaches = Model != null ? Model.DataCaches : null;
if (!dataCaches.GetValue(this, "CommonToolGridRightMenus", out DataTable tableCommon))
{
tableCommon = BaseModuleImpl.GetBaseGridRightMenus(this.Model.ModuleCode, ModuleType.BaseModuleAdd);
}
int i = 0, x = 4;
foreach (DataRow item in tableCommon.Rows)
{
if (i > 1)
{
BarButtonItem itemCommon = new BarButtonItem();
itemCommon.Caption = item["menuname"] + "";
itemCommon.Tag = item;
itemCommon.ItemClick += new ItemClickEventHandler(OnCommonItemClick);
pm_common.AddItem(itemCommon);
}
else
{
SimpleButton itemCommon = new SimpleButton();
//itemCommon.AutoSize = true;
itemCommon.Text = item["menuname"] + "";
itemCommon.Tag = item;
itemCommon.Size = new System.Drawing.Size(90, 26);
itemCommon.Click += new EventHandler(itemCommon_Click);
itemCommon.Location = new Point(x + 6, 6);
x += itemCommon.Width + 6;
pl_buttom.Controls.Add(itemCommon);
itemCommonList.Add(itemCommon);
i++;
}
}
if (tableCommon.Rows.Count > 0) this.pl_buttom.Visible = true;
this.dpbTools.Visible = tableCommon != null && pm_common.ItemLinks.Count > 0;
this.dpbTools.Click += DpbTools_Click;
//this.dpbTools.Location = new Point(x + 6, 6);
}
private void DpbTools_Click(object sender, EventArgs e)
{
foreach (BarItemLink itemLink in this.pm_common.ItemLinks)
{
DataRow rowItem = itemLink.Item.Tag as DataRow;
if (rowItem != null && rowItem.Table.Columns.Contains("MenuCond"))
{
string menuCond = rowItem["MenuCond"] + "";
string menuCaption = itemLink.Caption;
if (!string.IsNullOrEmpty(menuCond))
{
try
{
bool result = true;
DataRow parentitem = this.gcMain.GridView.GetFocusedDataRow();
menuCond = ReplaceHelper.ReplaceRowParam(parentitem, menuCond) + "";
if (menuCond.StartsWith("@") || menuCond.StartsWith("!"))
{
result = "1".Equals(BaseImpl.GetDefaultValue(menuCond));
}
else
{
result = ReplaceHelper.EvalCond(menuCond);
}
itemLink.Item.Enabled = result;
}
catch (Exception ex)
{
MessageUtil.Show("[" + menuCaption + "] " + ResourceKeys.SetRightMenuCondFault);
LogHelper.Instance.WriteError(ex);
LogUtil.WriteError("验证可操作条件出错!", ex);
}
}
}
}
}
/// <summary>
/// <para>说明:常用工具点击</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-27 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="ItemClickEventArgs"/> instance containing the event data.</param>
protected void OnCommonItemClick(object sender, ItemClickEventArgs e)
{
try
{
DataRow rowItem = e.Item.Tag as DataRow;
CommonMenu menu = new CommonMenu(this.Model, this.SearchObj, this.GridControlObj);
menu.Apply(rowItem);
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:常用工具点击</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-27 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="ItemClickEventArgs"/> instance containing the event data.</param>
protected void itemCommon_Click(object sender, EventArgs e)
{
try
{
SimpleButton btn = sender as SimpleButton;
DataRow rowItem = btn.Tag as DataRow;
CommonMenu menu = new CommonMenu(this.Model, this.SearchObj, this.GridControlObj);
StaticControl.RightMenuGridView = gcMain.GridView;
StaticControl.Comprefix = this.SysModel.PrefixKey;
menu.Apply(rowItem);
if (StaticControl.ReturnRowLisy.Count > 0)
{
DataRow[] dataRows = StaticControl.ReturnRowLisy.ToArray();
GridColumnCollection gridColumns = this.gcMain.GridView.Columns;
foreach (DataRow item in dataRows)
{
DataTable table = gcMain.GridControl.DataSourceTable();
int rowNumber = table.Rows.Count;
this.BrowserAddRow = false;
//新增一行
this.AddGridViewRecord();
if (this.gcMain.GridView.FocusedRowHandle == rowNumber && BrowserAddRow)
{
//成功新增行,把网页返回的行赋值
foreach (GridColumn col in gridColumns)
{
if (item.Table.Columns.Contains(col.FieldName))
{
// 来源列中是否包含对应字段,包含则使用值
gcMain.GridView.SetRowCellValue(this.gcMain.GridView.FocusedRowHandle, col.FieldName, item[col.FieldName]);
}
}
}
}
}
GridRightMenuModel model = new GridRightMenuModel(rowItem);
if (model != null && model.Refresh)
{
this.ParentGridEx.gridControl.DataSource = SqlHelper.ExecuteDataTable(this.ParentGridEx.LastSearchSql);
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:常用工具的明细导出</para>
/// <para>创建人:王一帆</para>
/// <para>创建日期:2020-05-28 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void btnExportInfo_Click(object sender, EventArgs e)
{
try
{
if (TabObj.TabPages.Count > 0)
{
LogUtil.WriteDebug(this.Model.ModuleCode, "导出数据", this.SysModel.MenuText, "明细导出");
XtraTabPage tabPage = TabObj.SelectedTabPage;
if (tabPage.Tag is GridControlEx)
{
(tabPage.Tag as GridControlEx).GridControl.ToExcel(this.Model.FormText);
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:自身表格的拖拽类</para>
/// <para>创建人:王一帆</para>
/// <para>创建日期:2017-09-05 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
public class DragForm : DevExpress.Utils.Win.TopFormBase
{
Bitmap m_buff;
Graphics m_buffG;
/// <summary>
/// 拖拽方法
/// </summary>
/// <param name="_size"></param>
public DragForm(Rectangle _bound)
{
this.Text = "";
this.FormBorderStyle = FormBorderStyle.None;
this.ControlBox = false;
this.Size = _bound.Size;
this.ShowInTaskbar = false;
this.StartPosition = FormStartPosition.Manual;
this.Opacity = 0.0d; //TopFormBase已经有默认值了;
//m_buff = new Bitmap(_bound.Width, _bound.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
//m_buffG = Graphics.FromImage(m_buff);
//m_buffG.CopyFromScreen(_bound.Location, new Point(0, 0), _bound.Size);
//this.BackgroundImageLayout = ImageLayout.None;
//this.BackgroundImage = m_buff;
this.BackColor = ColorTranslator.FromHtml("#0078D7");
this.Location = _bound.Location;
}
/// <summary>
///
/// </summary>
/// <param name="e"></param>
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
// e.Graphics.DrawImage(m_buff, 0, 0);
}
}
/// <summary>
/// <para>说明:初始化打印</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-22 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void InitializePrint()
{
Dictionary<object, Hashtable> dataCaches = Model != null ? Model.DataCaches : null;
if (!dataCaches.GetValue(this, "PrintTemp70", out DataTable printTable))
{
printTable = BaseImpl.GetPrintTemp70(this.Model.ModuleCode);
}
if (printTable.Rows.Count > 0 && !string.IsNullOrWhiteSpace(printTable.Rows[0][0].ToString()))
{
for (int i = 0; i < printTable.Rows.Count; i++)
{
DataRow item = printTable.Rows[i];
BarButtonItem bbi = new BarButtonItem();
int index = i + 1;
bbi.Caption = (item["printFile"] + "").Replace(".rmf", "").Replace(".frx", "");
bbi.Tag = item;
bbi.ItemClick += new ItemClickEventHandler(OnPrintItem70Click);
pm_print.AddItem(bbi);
}
}
else
{
if (!string.IsNullOrEmpty(this.SysModel.PrintFile))
{
String[] strs = this.SysModel.PrintFile.Split('|');
for (int i = 0; i < strs.Length; i++)
{
BarButtonItem bbi = new BarButtonItem();
int index = i + 1;
bbi.Caption = strs[i].Replace(".rmf", "").Replace(".frx", "");
bbi.Tag = strs[i];
bbi.ItemClick += new ItemClickEventHandler(OnCustomPrintItemClick);
pm_print.AddItem(bbi);
}
}
}
}
/// <summary>
/// <para>说明:初始化表格操作</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-09-05 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void InitializeGridView()
{
this.gcMain.Model = this.Model;
this.gcMain.SysModel = this.SysModel;
Dictionary<object, Hashtable> dataCaches = Model != null ? Model.DataCaches : null;
//显示筛选行
if (this.SysModel.LoadFilter) this.gcMain.GridView.OptionsView.ShowAutoFilterRow = true;
if (SysModel.AutoMultiHeader == 1 && SysModel.TreeAutoMultiHeader == 1)
{
// 创建 多表头,树表格
this.panelControl1.Controls.Clear();
this.gcMain = new TreeBandedGridControlEx() { Expansion = SysModel.TreeTableExpand };
this.gcMain.Model = this.Model;
this.gcMain.SysModel = this.SysModel;
(this.gcMain as TreeBandedGridControlEx).moduleModel = this.SysModel;
this.gcMain.Dock = DockStyle.Fill;
if (this._gridColumns.Rows.Count == 0 && !string.IsNullOrWhiteSpace(SysModel.TreeKeyFieldName) && !string.IsNullOrWhiteSpace(SysModel.TreeParentFieldName))
{
//节点编号
(this.gcMain as TreeBandedGridControlEx).TreeListObj.KeyFieldName = SysModel.TreeKeyFieldName;
//父节点编号
(this.gcMain as TreeBandedGridControlEx).TreeListObj.ParentFieldName = SysModel.TreeParentFieldName;
}
if (this.SysModel.GridObjIsCheck == 1)//主表加载复选框
{
GridDragGrid.TreeListAddCheckBox((this.gcMain as TreeBandedGridControlEx).TreeListObj);
}
this.panelControl1.Controls.Add(this.gcMain);
}
else if (this.Model.GridEnumObj == GridEnum.BandedGridView || SysModel.AutoMultiHeader == 1)
{
// 创建多表头,默认标准表格
PanelControl panel = null;
if (this.gcMain.gridControl.Tag is PanelControl) panel = this.gcMain.gridControl.Tag as PanelControl;
this.panelControl1.Controls.Clear();
this.gcMain = new BandedGridControlEx();
(this.gcMain as BandedGridControlEx).moduleModel = this.SysModel;
this.gcMain.Model = this.Model;
this.gcMain.SysModel = this.SysModel;
this.gcMain.Dock = DockStyle.Fill;
this.panelControl1.Controls.Add(this.gcMain);
if (this.SysModel.LoadFilter) (this.gcMain as BandedGridControlEx).GridView.OptionsView.ShowAutoFilterRow = true;
(this.gcMain as BandedGridControlEx).gridControl.Tag = panel;
}
else if (this.Model.GridEnumObj == GridEnum.TreeListGridView || SysModel.TreeAutoMultiHeader == 1)
{
// 创建树表格
this.panelControl1.Controls.Clear();
this.gcMain = new TreeGridControlEx() { Expansion = SysModel.TreeTableExpand };
this.gcMain.Model = this.Model;
this.gcMain.SysModel = this.SysModel;
this.gcMain.Dock = DockStyle.Fill;
if (this._gridColumns.Rows.Count == 0 && !string.IsNullOrWhiteSpace(SysModel.TreeKeyFieldName) && !string.IsNullOrWhiteSpace(SysModel.TreeParentFieldName))
{
//节点编号
(this.gcMain as TreeGridControlEx).TreeListObj.KeyFieldName = SysModel.TreeKeyFieldName;
//父节点编号
(this.gcMain as TreeGridControlEx).TreeListObj.ParentFieldName = SysModel.TreeParentFieldName;
}
if (this.SysModel.GridObjIsCheck == 1)//主表加载复选框
{
GridDragGrid.TreeListAddCheckBox((this.gcMain as TreeGridControlEx).TreeListObj);
}
this.panelControl1.Controls.Add(this.gcMain);
}
//如果配置了聚合模式则构建多表头覆盖当前表格
if (SysModel.IsCustomGroup == 1)
{
BandedGridControlEx bandedGridControlEx = new BandedGridControlEx();
bandedGridControlEx.moduleModel = this.SysModel;
bandedGridControlEx.Model = this.Model;
bandedGridControlEx.SysModel = this.SysModel;
bandedGridControlEx.Dock = DockStyle.Fill;
bandedGridControlEx.TotalQuantity = this.SysModel.TotalQuantity;
// 明确设置禁止自动调整列宽
bandedGridControlEx.BandedView.OptionsView.ColumnAutoWidth = false;
gcMain.CustomGroupBandEx = bandedGridControlEx;
gcMain.AggregationFreeze = this.SysModel.AggregationFreeze;
this.panelControl1.Controls.Add(bandedGridControlEx);
bandedGridControlEx.BringToFront();
}
else if (SysModel.IsCustomGroup == 2)
{
TreeBandedGridControlEx treeBandedGridControlEx = new TreeBandedGridControlEx();
treeBandedGridControlEx.moduleModel = this.SysModel;
treeBandedGridControlEx.Model = this.Model;
treeBandedGridControlEx.SysModel = this.SysModel;
treeBandedGridControlEx.Dock = DockStyle.Fill;
// 明确设置禁止自动调整列宽
treeBandedGridControlEx.TreeListObj.OptionsView.AutoWidth = false;
gcMain.CustomGroupTreeBandEx = treeBandedGridControlEx;
gcMain.AggregationFreeze = this.SysModel.AggregationFreeze;
this.panelControl1.Controls.Add(treeBandedGridControlEx);
treeBandedGridControlEx.BringToFront();
}
// 报表类型创建只读列
if (this.Model is DynamicReportModel)
{
this.gcMain.SetReadOnlyColumns(this._gridColumns, GridCustomColumnStruct.BaseMainGridView + this.SysModel.FormKey);
}
else
{
if (SysModel.CanEdit)
{
this.gcMain.SetEditColumns(this._gridColumns, GridCustomColumnStruct.BaseMainGridView + this.SysModel.FormKey);
}
else
{
this.gcMain.SetReadOnlyColumns(this._gridColumns, GridCustomColumnStruct.BaseMainGridView + this.SysModel.FormKey);
}
}
if (!dataCaches.GetValue(this, "BaseGridRowColors", out DataTable dtGridRowColors))
{
dtGridRowColors = BaseModuleImpl.GetBaseGridRowColors(this.Model.ModuleCode);
}
this.gcMain.SetGridRowColors(dtGridRowColors);
if (!dataCaches.GetValue(this, "BaseGridRightMenus", out DataTable dt))
{
dt = BaseModuleImpl.GetBaseGridRightMenus(this.Model.ModuleCode);
}
//获取要以上方按钮形式加载的按钮
if (dt.Columns.Contains("ButtonMode"))
{
ButtonModeRightMenus = dt.Rows.Cast<DataRow>().Where(x => "1".Equals(x["ButtonMode"] + "")).ToList();
}
if (this.gcMain is TreeGridControlEx)
{
(this.gcMain as TreeGridControlEx).SetGridRightMenus(dt, this.Model, OnGridViewRightCallBack, this.SearchObj, (this.gcMain as TreeGridControlEx).MenuStrip);
}
if (this.gcMain is BandedGridControlEx)
{
BandedGridControlEx banGridControlEx = (this.gcMain as BandedGridControlEx);
banGridControlEx.SetGridRightMenus(dt, this.Model, OnGridViewRightCallBack, this.SearchObj, null);
banGridControlEx.GridView.FocusedRowObjectChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventHandler(OnGridViewFocusedRowObjectChanged);
banGridControlEx.GridView.ShowingEditor += new CancelEventHandler(OnGridViewShowingEditor);
}
else
{
this.gcMain.SetGridRightMenus(dt, this.Model, OnGridViewRightCallBack, this.SearchObj, null);
}
if (gcMain.CustomGroupBandEx != null)
{
gcMain.CustomGroupBandEx.SetGridRowColors(dtGridRowColors);
gcMain.CustomGroupBandEx.SetGridRightMenus(dt, this.Model, OnGridViewRightCallBack, this.SearchObj, null);
gcMain.CustomGroupBandEx.GridView.FocusedRowObjectChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventHandler(OnGridViewFocusedRowObjectChanged);
gcMain.CustomGroupBandEx.GridView.ShowingEditor += new CancelEventHandler(OnGridViewShowingEditor);
}
if (gcMain.CustomGroupTreeBandEx != null)
{
gcMain.CustomGroupTreeBandEx.SetGridRowColors(dtGridRowColors);
gcMain.CustomGroupTreeBandEx.SetGridRightMenus(dt, this.Model, OnGridViewRightCallBack, this.SearchObj, (this.gcMain as TreeGridControlEx).MenuStrip);
}
//如果配置了聚合模式则构建多表头覆盖当前表格
//if (SysModel.IsCustomGroup == 1)
//{
// BandedGridControlEx bandedGridControlEx = new BandedGridControlEx();
// bandedGridControlEx.moduleModel = this.SysModel;
// bandedGridControlEx.Model = this.Model;
// bandedGridControlEx.SysModel = this.SysModel;
// bandedGridControlEx.Dock = DockStyle.Fill;
// // 明确设置禁止自动调整列宽
// bandedGridControlEx.BandedView.OptionsView.ColumnAutoWidth = false;
// gcMain.CustomGroupBandEx = bandedGridControlEx;
// bandedGridControlEx.SetGridRightMenus(dt, this.Model, OnGridViewRightCallBack, this.SearchObj, null);
// this.panelControl1.Controls.Add(bandedGridControlEx);
// bandedGridControlEx.BringToFront();
//}
InitializedragState();
SetGridRowHeightAndFont();
if (Model.IsBaseModule)
this.gcMain.GridView.DoubleClick += new EventHandler(OnGridViewDoubleClick);
if (Model.HasReadPrivilege())
this.gcMain.GridView.OptionsBehavior.Editable = false;
if (this.SysModel.DefaultAddEmptyRow)
{
this.gcMain.GridView.OptionsNavigation.AutoFocusNewRow = true;
this.gcMain.GridView.OptionsNavigation.EnterMoveNextColumn = true;
this.gcMain.GridView.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom;
this.gcMain.GridView.MouseDown += new MouseEventHandler(OnGridViewMouseDown);
}
if (this.LeftTreeViewEx != null || this.LeftGridEx != null)
{
if (this.gcMain is BandedGridControlEx)
{
(this.gcMain as BandedGridControlEx).OnParseGridDataCallBack += new GridControlEx.ParseGridDataEventHandler(OnGridViewParseGridDataCallBack);
}
else
{
this.gcMain.OnParseGridDataCallBack += new GridControlEx.ParseGridDataEventHandler(OnGridViewParseGridDataCallBack);
}
}
if (this.gcMain != null)
{
this.gcMain.OnGridColumnCallDLL += new GridControlEx.GridColumnCallDLL(OnGridColumnCallDLL);
}
}
private void AdapterObj_RowUpdated(object sender, SqlRowUpdatedEventArgs e)
{
}
#region 当前表格的拖拽方法
/// <summary>
/// <para>说明:判断是否需要绑定拖拽</para>
/// <para>创建人:王一帆</para>
/// <para>创建日期:2020-05-22 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void InitializedragState()
{
if (!_gridColumns.Columns.Contains("dragflag")) return;
//判断是否可拖拽
DataRow dragContainRow = this._gridColumns.Rows.Cast<DataRow>().FirstOrDefault(x => x["dragflag"] + "" == "1");
if (dragContainRow != null)
{
this.DetailOrderField = dragContainRow["fieldname"] + "";
gcMain.GridView.MouseDown += new MouseEventHandler(OnGridMouseDown);
gcMain.GridView.MouseMove += new MouseEventHandler(OnGridMouseMove);
gcMain.GridView.MouseUp += new MouseEventHandler(OnGridMouseUp);
this.isDrag = true;
//绑定值改变事件,拖拽后保存时判断列是否修改
if (this.gcMain is BandedGridControlEx)
{
(this.gcMain as BandedGridControlEx).GridControl.DataSourceChanged += (sender, e) =>
{
LineStatus.Clear();
DataTable sourceTable = (this.gcMain as BandedGridControlEx).GridControl.DataSourceTable();
DataTable copyTable = sourceTable.Copy();
for (int i = 0; i < copyTable.Rows.Count; i++)
{
LineStatus.Add(sourceTable.Rows[i], copyTable.Rows[i]);
}
};
}
else if (this.gcMain is TreeGridControlEx)
{
}
else
{
this.gcMain.GridControl.DataSourceChanged += (sender, e) =>
{
LineStatus.Clear();
DataTable sourceTable = this.gcMain.GridControl.DataSourceTable();
DataTable copyTable = sourceTable.Copy();
for (int i = 0; i < copyTable.Rows.Count; i++)
{
LineStatus.Add(sourceTable.Rows[i], copyTable.Rows[i]);
}
};
}
}
}
/// <summary>
/// <para>说明:设置当前基础档案或报表表格行高、行字体大小(默认微软雅黑)</para>
/// <para>创建人:王一帆</para>
/// <para>创建日期:2020-06-11 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void SetGridRowHeightAndFont()
{
if (!_gridColumns.Columns.Contains("FontSize") || _gridColumns.Rows.Count == 0) return;
//判断是否有字体设置
DataRow GridRowFont = this._gridColumns.Rows.Cast<DataRow>().FirstOrDefault(x => x["FontSize"] + "" != null);
int FontSize = string.IsNullOrEmpty(GridRowFont["FontSize"] + "") ? 0 : Convert.ToInt32(GridRowFont["FontSize"] + "");
if (FontSize > 0)
{
//this.gcMain.GridView.Appearance.Row.Font = new Font("微软雅黑", FontSize);
this.gcMain.GridView.Appearance.Row.Font = new Font(this.gcMain.GridView.Appearance.Row.Font.FontFamily, FontSize);
}
if (SysModel.RowHeight > 0)
{
this.gcMain.GridView.OptionsView.RowAutoHeight = false;
this.gcMain.GridView.ColumnPanelRowHeight = this.gcMain.GridView.RowHeight = SysModel.RowHeight;
}
}
/// <summary>
/// <para>说明:拖拽鼠标按下事件</para>
/// <para>创建人:王一帆</para>
/// <para>创建日期:2020-05-22 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void OnGridMouseDown(object sender, MouseEventArgs e)
{
try
{
if (e.Button == MouseButtons.Left)
{
isSortDrag = false;
var _hit = gcMain.GridView.CalcHitInfo(e.Location);
if (_hit.RowHandle >= 0)
{
dragRowsIndex = gcMain.GridView.GetSelectedRows();
// 复选框多选时,只允许从已选中行发起拖拽。
// 如果从未选中行拖拽,不移动已勾选行,避免拖拽对象和选中对象不一致。
if (dragRowsIndex != null
&& dragRowsIndex.Length > 1
&& !dragRowsIndex.Contains(_hit.RowHandle))
{
m_dragHandle = -1;
isSortDrag = false;
return;
}
m_dragHandle = _hit.RowHandle;
m_mouseDownLocation = e.Location;
}
else
{
m_dragHandle = -1;
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// 拖拽鼠标移动事件
/// </summary>
/// <param name="ev"></param>
private void OnGridMouseMove(object sender, MouseEventArgs e)
{
try
{
if (e.Button == MouseButtons.Left && m_dragHandle >= 0)
{
if (m_dragRowShadow == null)
{
double _x2 = Math.Pow((e.Location.X - m_mouseDownLocation.X), 2);
double _y2 = Math.Pow((e.Location.Y - m_mouseDownLocation.Y), 2);
double _d2 = Math.Sqrt(_x2 + _y2);
if (_d2 > 3)
{
isSortDrag = true;
//执行拖拽;
this.BeginDrag(m_dragHandle);
//var _info = (DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo)gv22.GetViewInfo();
//_info.GetGridRowInfo(0).CalcRectangle
}
}
else
{
m_dragRowShadow.Location = new Point(m_dragRowShadow.Location.X, this.PointToScreen(e.Location).Y);
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// 拖拽鼠标放开事件
/// </summary>
/// <param name="ev"></param>
private void OnGridMouseUp(object sender, MouseEventArgs e)
{
try
{
int startIndex = this.m_dragHandle;
int endIndex = -1;
if (m_dragRowShadow != null)
{
bool isMultiDrag = dragRowsIndex != null && dragRowsIndex.Length > 1;
if (isMultiDrag)
{
bool hasOtherSort = gcMain.GridView.SortedColumns
.Cast<DevExpress.XtraGrid.Columns.GridColumn>()
.Any(x => !string.Equals(x.FieldName, DetailOrderField, StringComparison.OrdinalIgnoreCase));
if (hasOtherSort)
{
m_dragRowShadow.Close();
m_dragRowShadow.Dispose();
m_dragRowShadow = null;
isSortDrag = false;
m_dragHandle = -1;
gcMain.GridView.Columns.ClearAllSort();
MessageUtil.Show("多选时不能存在其它列排序,已清除排序,请重新拖拽排序。");
return;
}
}
var _hit = gcMain.GridView.CalcHitInfo(e.Location);
this.EndDrag(_hit.RowHandle);
endIndex = _hit.RowHandle;
}
if (!string.IsNullOrEmpty(DetailOrderField) && isSortDrag)
{
int sourceStartIndex = startIndex > 0 ? gcMain.GridView.GetDataSourceRowIndex(startIndex) : startIndex;
int sourceEndIndex = endIndex > 0 ? gcMain.GridView.GetDataSourceRowIndex(endIndex) : endIndex;
this.gcMain.gridControl.DataSourceTable().OrderBy(this.DetailOrderField, sourceStartIndex, sourceEndIndex);
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// 绑定拖拽
/// </summary>
/// <param name="_handle"></param>
private void BeginDrag(int _handle)
{
var _info = (DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo)gcMain.GridView.GetViewInfo();
//_info.GetGridRowInfo(0).CalcRectangle
Rectangle _bound = _info.GetGridRowInfo(_handle).Bounds;
_bound.Location = this.PointToScreen(_bound.Location);
m_dragRowShadow = new DragForm(_bound);
m_dragRowShadow.Show();
}
/// <summary>
/// 停止拖拽
/// </summary>
/// <param name="_handle"></param>
private void EndDrag(int _handle)
{
int[] selectSourceIndex = null;
if (m_dragRowShadow != null)
{
m_dragRowShadow.Close();
m_dragRowShadow.Dispose();
m_dragRowShadow = null;
DataTable sourceTable = this.gcMain.gridControl.DataSourceTable();
if (dragRowsIndex.Length > 1)
{
int _rowIndex = gcMain.GridView.GetDataSourceRowIndex(_handle);
int[] selectRowsIndex = dragRowsIndex;
selectSourceIndex = new int[selectRowsIndex.Length];
List<DataRow> selectRows = new List<DataRow>();
List<DataRow> newRowSelectRows = new List<DataRow>();
for (int i = 0; i < selectRowsIndex.Length; i++)
{
int sourceIndex = gcMain.GridView.GetDataSourceRowIndex(selectRowsIndex[i]);
selectSourceIndex[i] = sourceIndex;
selectRows.Add(sourceTable.Rows[sourceIndex]);
}
gcMain.gridControl.BeginUpdate();
foreach (DataRow row in selectRows)
{
DataRow newRow = sourceTable.NewRow();
newRow.ItemArray = row.ItemArray;
LineStatus.Add(newRow, LineStatus[row]);
LineStatus.Remove(row);
newRowSelectRows.Add(newRow);
}
//移除目标行;
int IntermediateRow = 0;
for (int i = selectSourceIndex.Length - 1; i >= 0; i--)
{
((DataTable)this.gcMain.gridControl.DataSource).Rows.RemoveAt(selectSourceIndex[i]);
if (_handle > selectSourceIndex[i]) IntermediateRow++;//拖动行如果在目标行上面,拖动行在删除后,插入行要跟着删一行
}
_handle = _handle - IntermediateRow;
if (_handle >= 0)
{
foreach (DataRow row in newRowSelectRows)
{
sourceTable.Rows.InsertAt(row, _handle);
//row.AcceptChanges();
//row.SetModified();
_handle += 1;
}
}
else
{
foreach (DataRow row in newRowSelectRows)
{
sourceTable.Rows.Add(row);
//row.AcceptChanges();
//row.SetModified();
}
}
}
else
{
int _rowIndex = gcMain.GridView.GetDataSourceRowIndex(m_dragHandle);
DataRow _row = ((DataTable)this.gcMain.gridControl.DataSource).Rows[_rowIndex];
DataRow insertRow = ((DataTable)this.gcMain.gridControl.DataSource).NewRow();
insertRow.ItemArray = _row.ItemArray;
gcMain.gridControl.BeginUpdate();
((DataTable)this.gcMain.gridControl.DataSource).Rows.RemoveAt(_rowIndex);
LineStatus.Add(insertRow, LineStatus[_row]);
LineStatus.Remove(_row);
if (_handle > m_dragHandle) _handle = _handle - 1;//拖动行如果在目标行上面,拖动行在删除后,插入行的行号要减1
if (_handle >= 0)
{
DataTable screenTable = this.gcMain.GridView.GetGridViewFilteredAndSortedDataToDataTable();
DataTable AllTable = this.gcMain.gridControl.DataSourceTable();
//行数不同,为筛选状态。传入行的行号要设置为数据源中的行号
if (screenTable.Rows.Count != AllTable.Rows.Count)
{
DataRow dataRow = screenTable.Rows[_handle];
IEqualityComparer<DataRow> comparer = DataRowComparer.Default;
DataRow dr = AllTable.Rows.Cast<DataRow>().Where(x => comparer.Equals(x, dataRow)).ToArray()[0];
int index = AllTable.Rows.IndexOf(dr);
((DataTable)this.gcMain.gridControl.DataSource).Rows.InsertAt(insertRow, index);
gcMain.GridView.FocusedRowHandle = _handle;
}
else
{
//插入指定位置;
((DataTable)this.gcMain.gridControl.DataSource).Rows.InsertAt(insertRow, _handle);
gcMain.GridView.FocusedRowHandle = _handle;
}
}
else
{
//添加;
((DataTable)this.gcMain.gridControl.DataSource).Rows.Add(insertRow);
gcMain.GridView.FocusedRowHandle = gcMain.GridView.RowCount - 1;
}
//insertRow.AcceptChanges();
//insertRow.SetModified();
}
gcMain.gridControl.EndUpdate();
gcMain.GridView.ClearSelection();
}
}
private int GetDragEndRowIndex(DataTable sourceTab, int dragEndRowIndex, List<DataRow> selectRows, out bool isContain)
{
int returnIndex = 0;
isContain = false;
DataRow dragEndRow = sourceTab.Rows[dragEndRowIndex];
if (selectRows.Contains(dragEndRow))
{
isContain = true;
dragEndRowIndex = dragEndRowIndex - 1;
if (dragEndRowIndex >= 0)
{
dragEndRow = sourceTab.Rows[dragEndRowIndex];
if (selectRows.Contains(dragEndRow))
{
bool iscontain = false;
returnIndex = GetDragEndRowIndex(sourceTab, dragEndRowIndex, selectRows, out iscontain);
}
else
{
returnIndex = dragEndRowIndex;
}
}
else
{
returnIndex = -1;
}
}
else
{
returnIndex = dragEndRowIndex;
}
return returnIndex;
}
#endregion
/// <summary>
/// <para>说明:初始化按钮状态</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-13 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void InitializeButtonState()
{
try
{
if (Model != null && Model.HasOperPrivilege())
{
this.btnAttach.Visible = this.SysModel.AttachReveal;
this.btnAdd.Enabled = this.SysModel.AddEnable;
this.btnDel.Enabled = this.SysModel.DeleteEnable;
this.btnSave.Enabled = this.gcMain.GridView.OptionsBehavior.Editable = this.SysModel.ModifyEnable && this.SysModel.CanEdit;
this.btnImport.Enabled = this.bbi_import.Enabled = this.SysModel.ImportEnable;
this.bbi_import.Visibility = VisibleOperPanel ? BarItemVisibility.Always : BarItemVisibility.Never;
this.bbi_export.Enabled = this.SysModel.ExportEnable;
this.pl_top_fix_search.Enabled = this.pl_top_search.Enabled = this.SysModel.SearchEnable;
this.pl_buttom.Visible = this.VisibleOperPanel && (this.SysModel.AddEnable || this.SysModel.DeleteEnable || (this.SysModel.ModifyEnable && this.SysModel.CanEdit));
this.btnUpdate.Enabled = this.SysModel.ModifyEnable && this.SysModel.CanEdit;
this.gcMain.GridView.FocusedRowObjectChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventHandler(OnGridViewFocusedRowObjectChanged);
if (this.LeftGridEx != null) this.LeftGridEx.GridView.FocusedRowObjectChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventHandler(OnGridViewFocusedRowObjectChanged);
this.gcMain.GridView.ShowingEditor += new CancelEventHandler(OnGridViewShowingEditor);
}
else
{
this.btnUpdate.Enabled=this.btnAdd.Enabled = this.btnDel.Enabled = this.btnSave.Enabled = this.bbi_import.Enabled = false;
this.gcMain.GridView.OptionsBehavior.Editable = false;
this.pl_buttom.Visible = false;
}
}
catch (Exception ex)
{
LogHelper.Instance.WriteError(ex);
throw;
}
}
/// <summary>
/// <para>说明:删除存储过程验证</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-10 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="rowData">The row data.</param>
/// <returns>1.允许删除,0.不允许删除</returns>
private int ValidateDeleteProc(DataRow rowData)
{
SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000);
pMsg.Direction = ParameterDirection.Output;
SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4);
returnValue.Direction = ParameterDirection.ReturnValue;
SqlParameter[] param =
{
new SqlParameter("@modid",SqlDbType.VarChar,20),
new SqlParameter("@keyvalue",SqlDbType.VarChar,40),
pMsg,
returnValue
};
param[0].Value = this.Model.ModuleCode;
param[1].Value = rowData[this._parmaryKey];
BaseImpl.ExecProcedure("p_VerifyCanDelete", param);
return Convert.ToInt32(returnValue.Value.ToString());
}
/// <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))
{
result = true;//如果值是空格或者空行,默认正确
}
else
{
//cond = ReplaceHelper.ReplaceRowParam(dataRow, cond);
cond = ReplaceHelper.ReplaceRowParamEmptyWrapQuote(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);
}
}
}
catch (Exception ex)
{
//string Tips = string.Empty;
//if (!string.IsNullOrWhiteSpace(TableName) && !string.IsNullOrWhiteSpace(ColumnName))
//{
// Tips = string.Format("{0}表中{1}字段{2},判断条件失败\r\n", TableName, ColumnName, condition);
//}
//else
//{
// Tips = string.Format("条件为:{0}\r\n", condition);
//}
//Tips = "条件判断错误:\r\n" + Tips;
//string Message = ErrorMessage.PromptErrorMessage(ex, "", Tips);
////MessageUtil.Show("条件判断错误:\r\n" + Tips);
if (!ex.Message.Equals("该字符串未被识别为有效的布尔值。")) LogHelper.Instance.WriteError(ex);
}
return result;
}
/// <summary>
/// <para>说明:检查按钮是否可用</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-21 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void ValidateButtonState(DataRow rowItem, bool isValidation = true)
{
if (rowItem == null && isValidation)
{
return;
}
try
{
Dictionary<object, Hashtable> dataCaches = new Dictionary<object, Hashtable>();
Task<bool> validateAddTask = dataCaches.AddTask(this, "ValidateAdd", new Task<bool>(() =>
{
return ValidateCond(SysModel.AddCond, rowItem, "P_SystemDllTab", "addCond");
}));
Task<bool> validateDelTask = dataCaches.AddTask(this, "ValidateDel", new Task<bool>(() =>
{
return ValidateCond(SysModel.DeleteCond, rowItem, "P_SystemDllTab", "deleteCond");
}));
Task<bool> validateSaveTask = dataCaches.AddTask(this, "ValidateSave", new Task<bool>(() =>
{
return ValidateCond(SysModel.ModifyCond, rowItem, "P_SystemDllTab", "modifyCond");
}));
Task<bool> validateImportTask = dataCaches.AddTask(this, "ValidateImport", new Task<bool>(() =>
{
return ValidateCond(SysModel.ImportCond, rowItem, "P_SystemDllTab", "importCond");
}));
Task<bool> validateExportTask = dataCaches.AddTask(this, "ValidateExport", new Task<bool>(() =>
{
return ValidateCond(SysModel.ExportCond, rowItem, "P_SystemDllTab", "exportCond");
}));
if (!Model.HasOperPrivilege())
{
this.btnAdd.Enabled = this.btnDel.Enabled = this.btnDel.Enabled = false;
}
else
{
if (!dataCaches.GetValue(this, "ValidateAdd", out bool validateAdd))
{
validateAdd = ValidateCond(this.SysModel.AddCond, rowItem, "P_SystemDllTab", "addCond");
}
if (!dataCaches.GetValue(this, "ValidateDel", out bool validateDel))
{
validateDel = ValidateCond(this.SysModel.DeleteCond, rowItem, "P_SystemDllTab", "deleteCond");
}
if (!dataCaches.GetValue(this, "ValidateSave", out bool validateSave))
{
validateSave = ValidateCond(this.SysModel.ModifyCond, rowItem, "P_SystemDllTab", "modifyCond");
}
if (!dataCaches.GetValue(this, "ValidateImport", out bool validateImport))
{
validateImport = ValidateCond(this.SysModel.ImportCond, rowItem, "P_SystemDllTab", "importCond");
}
if (!dataCaches.GetValue(this, "ValidateExport", out bool validateExport))
{
validateExport = ValidateCond(this.SysModel.ExportCond, rowItem, "P_SystemDllTab", "exportCond");
}
this.btnAdd.Enabled = this.SysModel.AddEnable && validateAdd; // 判断添加权限
//this.btnAdd.Enabled = true;
this.btnDel.Enabled = this.SysModel.DeleteEnable && validateDel; // 判断删除权限
this.btnSave.Enabled = this.SysModel.ModifyEnable && validateSave; // 判断修改权限
this.btnImport.Enabled = this.SysModel.ImportEnable && validateImport; // 判断导入权限
this.btnExport.Enabled = this.SysModel.ExportEnable && this.SysModel.ExportPermission && validateExport; // 判断导出权限
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
/// <summary>
/// <para>说明:添加表格数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-31 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void AddGridRecord()
{
if (!string.IsNullOrWhiteSpace(this.SysModel.PreSQL))//如果配置预新增界面则弹出
{
GridDetailModel gridDetailModel = this.GridControlObj.Tag as GridDetailModel;
DataRow parentDataRow = this.ParentGridEx != null ? this.ParentGridEx.GridView.GetFocusedDataRow() : null;
FrmAddDynamic frmAddDynamic = new FrmAddDynamic();
frmAddDynamic.Text = this.SysModel.MenuText;
frmAddDynamic.DynamicSql = this.SysModel.PreSQL;
frmAddDynamic.ModuleCode = this.SysModel.ModeCode;
frmAddDynamic.MaxHeight = this.SysModel.AddDynamicMaxHeight;
frmAddDynamic.UnionKey = gridDetailModel.UnionValue;
frmAddDynamic.UnionValue = parentDataRow != null && parentDataRow.Table.Columns.Contains(gridDetailModel.UnionParentField) ? parentDataRow[gridDetailModel.UnionParentField] + "" : "";
frmAddDynamic.keyValue = "";
if (frmAddDynamic.ShowDialog() == DialogResult.OK)
{
//this.RefreshColumn();
this.SearchObj.SearchLastGrid();
if (OnSaveGridCallBack != null)
{
this.OnSaveGridCallBack(null, null);
}
}
}
else
{
if (string.IsNullOrWhiteSpace(this.SysModel.MenuAddName))
{
this.AddGridViewRecord();
}
else
{
this.AddPanelViewRecord();
}
}
}
/// <summary>
/// <para>说明:直接表格添加数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-31 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void AddGridViewRecord()
{
try
{
DataTable dt = this.gcMain.GridControl.DataSource as DataTable;
if (dt == null)
{
MessageUtil.Show("请查询后添加!");
return;
}
if (!SysModel.CanEdit)
{
MessageUtil.Show("表格不可编辑,增加失败");
return;
}
if (!(dt.Columns.Contains(ERPInfo.Instance.isAddRows)))
{
dt.Columns.Add(ERPInfo.Instance.isAddRows, typeof(String));
}
GridView view = gcMain.GridView;
view.InitNewRow += GridView_InitNewRow;
view.AddNewRow();
view.UpdateCurrentRow();
view.ShowEditor();
view.InitNewRow -= GridView_InitNewRow;
if (!string.IsNullOrEmpty(this.SysModel.addDetilOrderField))
{
view.GridControl.DataSourceTable().OrderBy(this.SysModel.addDetilOrderField);
}
this.OnGridViewFocusedRowObjectChanged(view, null);//默认值添加完成后执行改变按钮状态(行改变事件)
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// 表格行添加事件(AddNewRow时触发)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void GridView_InitNewRow(object sender, InitNewRowEventArgs e)
{
DataTable dt = this.gcMain.GridControl.DataSource as DataTable;
string parentKey = string.Empty;
string parentValue = string.Empty;
if (LeftTreeViewEx != null && !this.SysModel.AnyAdd)
{
// 树结构添加数据
if (LeftTreeViewEx.TreeView.SelectedNode == null)
{
MessageUtil.Show(ResourceKeys.SelectedNodeIsNull);
return;
}
if (LeftTreeViewEx.TreeView.SelectedNode.Nodes.Count > 0 && (!SystemInfo.Instance.AddingARootNode && !this.SysModel.selectLeaf))
{
MessageUtil.Show(ResourceKeys.SelectedNodeContainNode);
return;
}
//if (LeftTreeViewEx.TreeView.SelectedNode.Nodes.Count > 0)
//{
// MessageUtil.Show(ResourceKeys.SelectedNodeContainNode);
// return;
//}
parentKey = this.ParentKeyField;
parentValue = LeftTreeViewEx.TreeView.SelectedNode.Name;
}
else if (LeftGridEx != null && !this.SysModel.AnyAdd)
{
// 表格添加
DataRow rowItem = LeftGridEx.GridView.GetFocusedDataRow();
if (LeftGridEx is TreeGridControlEx)
{
TreeListNode selectedNode = (LeftGridEx as TreeGridControlEx).TreeListObj.FocusedNode;
if (selectedNode.HasChildren && (!SystemInfo.Instance.AddingARootNode && !this.SysModel.selectLeaf))
{
MessageUtil.Show(ResourceKeys.SelectedNodeContainNode);
return;
}
rowItem = LeftGridEx.GetViewFocusedDataRow();
}
if (rowItem == null)
{
MessageUtil.Show(ResourceKeys.SelectRowIsNull);
return;
}
//parentKey = !string.IsNullOrEmpty(DetailKeyField) ? DetailKeyField : this._parentKey;
parentKey = this.ParentKeyField;
parentValue = rowItem[ParentKeyField] + "";
}
DataRow controlRowItem = null;
if (!string.IsNullOrEmpty(this.ControlSql))
{
controlRowItem = MainImpl.GetDataRowResult(this.ControlSql);
}
GridView view = gcMain.GridView;
// 添加表格数据,此时数据还未保存.
foreach (GridColumn column in this.gcMain.GridView.Columns)
{
GridColumnModel model = column.Tag as GridColumnModel;
if (model == null) continue;
if (model.FieldType == ControlType.LabTreeType && model.ValueMember.Equals(parentKey, StringComparison.OrdinalIgnoreCase))
{
// 设置树节点关联值
view.SetRowCellValue(view.FocusedRowHandle, column, parentValue);
}
else if (model.AdditionalAssociations && model.ValueMember.Equals(parentKey, StringComparison.OrdinalIgnoreCase) && AdditionalAssociatedMain)
{
// 设置树节点关联值
view.SetRowCellValue(view.FocusedRowHandle, column, parentValue);
}
else if (model.FieldName.Equals(UnionKey, StringComparison.OrdinalIgnoreCase))
{
// 设置关联模块关联值
view.SetRowCellValue(view.FocusedRowHandle, column, UnionValue);
}
else if (!string.IsNullOrEmpty(ParentKeyField) &&
this.ParentGridEx != null &&
model.FieldName.Equals(DetailKeyField, StringComparison.OrdinalIgnoreCase))
{
DataRow SelectTheLine = this.ParentGridEx.GetViewFocusedDataRow();
if (this.ParentGridEx is TreeGridControlEx) SelectTheLine = this.ParentGridEx.GetViewFocusedDataRow();
// 设置上下结构关联值
string fieldValue = SelectTheLine != null ? SelectTheLine[ParentKeyField] + "" : string.Empty;
view.SetRowCellValue(view.FocusedRowHandle, column, fieldValue);
}
else if (!string.IsNullOrEmpty(ParentKeyField) &&
this.ParentControlEx != null &&
model.FieldName.Equals(DetailKeyField, StringComparison.OrdinalIgnoreCase))
{
// 设置上下结构关联值
string fieldValue = this.ParentControlEx.GetControlValue(ParentKeyField);
view.SetRowCellValue(view.FocusedRowHandle, column, fieldValue);
}
else
{
string fieldValue = model.DefaultValue;
string replaceKey = "{" + DetailKeyField + "}";
string replaceValue = "{" + ParentKeyField + "}";
if (SweepCodeRow != null && SweepCodeRow.Table.Columns.Contains(model.FieldName))
{
//如果有扫码数据,优先以扫码数据为准
fieldValue = ReplaceHelper.ReplaceRowParam(SweepCodeRow, "{" + model.FieldName + "}");
}
if (!string.IsNullOrEmpty(ParentKeyField) && fieldValue.Contains(replaceKey))
{
fieldValue = fieldValue.Replace(replaceKey, replaceValue);
}
if (this.ParentGridEx != null)
{
DataRow SelectTheLine = this.ParentGridEx.GetViewFocusedDataRow();
fieldValue = ReplaceHelper.ReplaceRowParam(SelectTheLine, fieldValue);
}
fieldValue = BaseImpl.GetDefaultValue(fieldValue, "", Model.OtherParams());
if (Model.GetMaintabFocusedRow() != null)
{
fieldValue = ReplaceHelper.ReplaceRowParam(Model.GetMaintabFocusedRow(), fieldValue);
}
//if (ParentControlObj != null)
//{
// fieldValue = ParentControlObj.ReplaceControlValue(fieldValue);
//}
//string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue, "", Model.OtherParams());
string parentDefault = (model.DefaultValue + "").Replace("{", "").Replace("}", "");
if (this.ParentGridEx != null && this.ParentGridEx.GridView.Columns.ColumnByName(parentDefault) != null)
{
object valueObj = this.ParentGridEx.GridView.GetRowCellValue(this.ParentGridEx.GridView.FocusedRowHandle, parentDefault);
view.SetRowCellValue(view.FocusedRowHandle, column, valueObj);
}
else if (this.ParentGridEx != null && this.ParentGridEx is TreeGridControlEx)
{
TreeGridControlEx treeGridControlEx = this.ParentGridEx as TreeGridControlEx;
if (treeGridControlEx.TreeListObj.Columns.ColumnByName(parentDefault) != null)
{
object valueObj = treeGridControlEx.GetViewFocusedDataRow()[parentDefault];
view.SetRowCellValue(view.FocusedRowHandle, column, valueObj);
}
}
if (!string.IsNullOrEmpty(fieldValue))
{
if (fieldValue.StartsWith("{") && fieldValue.EndsWith("}"))
{
if (fieldValue.StartsWith("{#") && this.SearchObj != null)
{
// 带条件值
fieldValue = this.SearchObj.GetControlValue(model.FieldName);
if (!string.IsNullOrEmpty(fieldValue))
view.SetRowCellValue(view.FocusedRowHandle, column, fieldValue);
}
else
{
// 表格添加相同字段则直接使用值
fieldValue = fieldValue.Replace("{", "").Replace("}", "");
if (this.ParentGridEx != null && this.ParentGridEx.GridView.Columns.ColumnByName(fieldValue) != null)
{
object valueObj = this.ParentGridEx.GridView.GetRowCellValue(this.ParentGridEx.GridView.FocusedRowHandle, fieldValue);
view.SetRowCellValue(view.FocusedRowHandle, column, valueObj);
}
else if (this.ParentGridEx != null && this.ParentGridEx is TreeGridControlEx)
{
TreeGridControlEx treeGridControlEx = this.ParentGridEx as TreeGridControlEx;
if (treeGridControlEx.TreeListObj.Columns.ColumnByName(fieldValue) != null)
{
object valueObj = treeGridControlEx.GetViewFocusedDataRow()[fieldValue];
view.SetRowCellValue(view.FocusedRowHandle, column, valueObj);
}
}
}
}
else
{
view.SetRowCellValue(view.FocusedRowHandle, column, fieldValue);
}
}
else
{
// 检查是否配置有查询条件
if (this.SearchObj != null)
{
fieldValue = this.SearchObj.GetControlValue(model.FieldName);
if (!string.IsNullOrEmpty(fieldValue))
view.SetRowCellValue(view.FocusedRowHandle, column, fieldValue);
}
// 表格添加相同字段则直接使用表格值
if (this.ParentGridEx != null && this.ParentGridEx.GridView.Columns.ColumnByName(model.FieldName) != null && this.SysModel.TakeMainTableValue)
{
object valueObj = this.ParentGridEx.GridView.GetRowCellValue(this.ParentGridEx.GridView.FocusedRowHandle, model.FieldName);
view.SetRowCellValue(view.FocusedRowHandle, column, valueObj);
}
else if (this.ParentGridEx != null && this.ParentGridEx is TreeGridControlEx)
{
TreeGridControlEx treeGridControlEx = this.ParentGridEx as TreeGridControlEx;
if (treeGridControlEx.TreeListObj.Columns.ColumnByName(model.FieldName) != null)
{
object valueObj = treeGridControlEx.GetViewFocusedDataRow()[model.FieldName];
view.SetRowCellValue(view.FocusedRowHandle, column, valueObj);
}
}
// 右键调用赋值
if (this.DetailKeyField == model.FieldName)
{
view.SetRowCellValue(view.FocusedRowHandle, column, ParentKeyValue);
}
}
// 右键菜单调用时赋值sql语句
if (controlRowItem != null && controlRowItem.Table.Columns.Contains(column.FieldName))
{
DataRow dataRow = view.GetDataRow(view.FocusedRowHandle);
if (dataRow != null && !(dataRow[ERPInfo.Instance.isAddRows] + "").Equals("1"))
{
view.SetRowCellValue(view.FocusedRowHandle, column, controlRowItem[column.FieldName]);
}
}
}
}
this.BrowserAddRow = true;
view.UpdateCurrentRow();
view.ShowEditor();
}
/// <summary>
/// 表格老版粘贴后新增行(和新增行相同的操作)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void GcMain_OnAfterPasting(object sender, EventArgs e)
{
AddGridViewRecord();
}
/// <summary>
/// 表格触发右键功能
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnAfterLinkCilkCall(object sender, EventArgs e)
{
string unioright = sender + "";
DataRow rightrowitem = this.GridControlObj.gridViewRightMenu.MenuTable.Rows.Cast<DataRow>().FirstOrDefault(x => (x["orderid"] + "").Equals(unioright));
GridRightMenuModel model = new GridRightMenuModel(rightrowitem);
DataRow rowItem = this.GridControlObj.GetViewFocusedDataRow();
if (!string.IsNullOrWhiteSpace(model.MenuCond))
{
//判断条件
DataRow row = this.gcMain.GridView.GetFocusedDataRow();
string cond = ReplaceHelper.ReplaceRowParam(row, model.MenuCond);
bool condResult = ValidateCond(cond, null);
if (!condResult) return;
}
CommonMenu menu = new CommonMenu(this.Model, this.SearchObj, this.gcMain);
menu.Apply(rightrowitem);
}
/// <summary>
/// <para>说明:</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期: </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="rowItem">The row item.</param>
private void AddGridViewRecord(DataRow curItem)
{
try
{
string parentKey = string.Empty;
string parentValue = string.Empty;
if (LeftTreeViewEx != null && !this.SysModel.AnyAdd)
{
// 树结构添加数据
if (LeftTreeViewEx.TreeView.SelectedNode == null)
{
MessageUtil.Show(ResourceKeys.SelectedNodeIsNull);
return;
}
if (LeftTreeViewEx.TreeView.SelectedNode.Nodes.Count > 0)
{
MessageUtil.Show(ResourceKeys.SelectedNodeContainNode);
return;
}
parentKey = this.ParentKeyField;
parentValue = LeftTreeViewEx.TreeView.SelectedNode.Name;
}
else if (LeftGridEx != null && !this.SysModel.AnyAdd)
{
// 表格添加
DataRow rowItem = LeftGridEx.GridView.GetFocusedDataRow();
if (LeftGridEx is TreeGridControlEx) rowItem = LeftGridEx.GetViewFocusedDataRow();
if (rowItem == null)
{
MessageUtil.Show(ResourceKeys.SelectRowIsNull);
return;
}
//parentKey = !string.IsNullOrEmpty(DetailKeyField) ? DetailKeyField : this._parentKey;
parentKey = this.ParentKeyField;
parentValue = rowItem[ParentKeyField] + "";
}
DataRow controlRowItem = null;
if (!string.IsNullOrEmpty(this.ControlSql))
{
controlRowItem = MainImpl.GetDataRowResult(this.ControlSql);
}
GridView view = gcMain.GridView;
// 添加表格数据,此时数据还未保存.
foreach (GridColumn column in this.gcMain.GridView.Columns)
{
GridColumnModel model = column.Tag as GridColumnModel;
if (model == null) continue;
if (model.FieldType == ControlType.LabTreeType && model.ValueMember.Equals(parentKey, StringComparison.OrdinalIgnoreCase))
{
// 设置树节点关联值
view.SetRowCellValue(view.FocusedRowHandle, column, parentValue);
}
else if (model.FieldName.Equals(UnionKey, StringComparison.OrdinalIgnoreCase))
{
// 设置关联模块关联值
view.SetRowCellValue(view.FocusedRowHandle, column, UnionValue);
}
else if (!string.IsNullOrEmpty(ParentKeyField) &&
this.ParentGridEx != null &&
model.FieldName.Equals(DetailKeyField, StringComparison.OrdinalIgnoreCase))
{
// 设置上下结构关联值
string fieldValue = this.ParentGridEx.GridView.GetRowCellValue(this.ParentGridEx.GridView.FocusedRowHandle, ParentKeyField) + "";
if (this.ParentGridEx is TreeGridControlEx) fieldValue = this.ParentGridEx.GetViewFocusedDataRow()[ParentKeyField] + "";
view.SetRowCellValue(view.FocusedRowHandle, column, fieldValue);
}
else
{
string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue);
if (!string.IsNullOrEmpty(fieldValue))
{
if (fieldValue.StartsWith("{") && fieldValue.EndsWith("}"))
{
// 表格添加相同字段则直接使用值
fieldValue = fieldValue.Replace("{", "").Replace("}", "");
if (this.ParentGridEx != null && this.ParentGridEx.GridView.Columns.ColumnByName(fieldValue) != null)
{
object valueObj = this.ParentGridEx.GridView.GetRowCellValue(this.ParentGridEx.GridView.FocusedRowHandle, fieldValue);
view.SetRowCellValue(view.FocusedRowHandle, column, valueObj);
}
else if (this.ParentGridEx != null && this.ParentGridEx is TreeGridControlEx)
{
TreeGridControlEx treeGridControlEx = this.ParentGridEx as TreeGridControlEx;
if (treeGridControlEx.TreeListObj.Columns.ColumnByName(fieldValue) != null)
{
object valueObj = treeGridControlEx.GetViewFocusedDataRow()[fieldValue];
view.SetRowCellValue(view.FocusedRowHandle, column, valueObj);
}
}
}
else
{
view.SetRowCellValue(view.FocusedRowHandle, column, fieldValue);
}
}
else
{
// 检查是否配置有查询条件
if (this.SearchObj != null)
{
fieldValue = this.SearchObj.GetControlValue(model.FieldName);
if (!string.IsNullOrEmpty(fieldValue))
view.SetRowCellValue(view.FocusedRowHandle, column, fieldValue);
}
// 表格添加相同字段则直接使用值
if (this.ParentGridEx != null && this.ParentGridEx.GridView.Columns.ColumnByName(model.FieldName) != null)
{
object valueObj = this.ParentGridEx.GridView.GetRowCellValue(this.ParentGridEx.GridView.FocusedRowHandle, model.FieldName);
view.SetRowCellValue(view.FocusedRowHandle, column, valueObj);
}
else if (this.ParentGridEx != null && this.ParentGridEx is TreeGridControlEx)
{
TreeGridControlEx treeGridControlEx = this.ParentGridEx as TreeGridControlEx;
if (treeGridControlEx.TreeListObj.Columns.ColumnByName(model.FieldName) != null)
{
object valueObj = treeGridControlEx.GetViewFocusedDataRow()[model.FieldName];
view.SetRowCellValue(view.FocusedRowHandle, column, valueObj);
}
}
// 右键调用赋值
if (this.DetailKeyField == model.FieldName)
view.SetRowCellValue(view.FocusedRowHandle, column, ParentKeyValue);
}
// 右键菜单调用时赋值sql语句
if (controlRowItem != null && controlRowItem.Table.Columns.Contains(column.FieldName))
{
view.SetRowCellValue(view.FocusedRowHandle, column, controlRowItem[column.FieldName]);
}
}
}
view.UpdateCurrentRow();
view.ShowEditor();
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:弹出添加数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-31 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void AddPanelViewRecord()
{
StaticControl.AddParentGrid = new KeyValuePair<string, GridControlEx>(Model.ModuleCode, gcMain);
string mLeftFieldId = string.Empty;
string mLeftFieldName = string.Empty;
string mLeftTreeData = string.Empty;
string mLeftGridData = string.Empty;
try
{
if (this.SysModel.MenuAddName.Equals("Lskj.PubAdd4.dll", StringComparison.OrdinalIgnoreCase))
{
string url = string.Format("pages/app/app.html?username={0}&password={1}&xtype={2}&dllcoid=", ERPInfo.Instance.UserName, ERPInfo.Instance.Password, this.SysModel.BsAdddllname);
// 固定传入参数(窗口标题、操作员ID、操作员名称、权限、模版编号)
string[] defaultArgs = string.Format(ModuleArgs.DefaultArgs, this.Model.FormText, ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, this.Model.Privilege, this.Model.ModuleCode).Split('~');
string[] menuArgs = new string[] { "", "", url };
string[] args = defaultArgs.Concat(menuArgs).ToArray();
IForm form = FormHelper.LoadDllForm(ResourceDynamic.PubBrower, args);
form.SubForm.WindowState = FormWindowState.Maximized;
DialogResult result = form.SubForm.ShowDialog();
}
else
{
// 弹出添加数据
if (LeftTreeViewEx != null && !this.SysModel.AnyAdd)
{
if (LeftTreeViewEx.TreeView.SelectedNode == null)
{
MessageUtil.Show(ResourceKeys.SelectedNodeIsNull);
return;
}
if (LeftTreeViewEx.TreeView.SelectedNode.Nodes.Count > 0 && (!SystemInfo.Instance.AddingARootNode && !this.SysModel.selectLeaf))
{
MessageUtil.Show(ResourceKeys.SelectedNodeContainNode);
return;
}
if (this.SysModel.NewVer == 0)
{
string seqNo = BaseModuleImpl.GetBillSeq(LeftTreeViewEx.TreeView.SelectedNode.Name, this.Model.ModuleCode);
if (string.IsNullOrWhiteSpace(seqNo))
{
MessageUtil.Show(ResourceKeys.UpdateTreeNodeSeq);
return;
}
}
mLeftFieldId = LeftTreeViewEx.TreeView.SelectedNode.Name;
mLeftFieldName = LeftTreeViewEx.TreeView.SelectedNode.Text;
mLeftTreeData = LeftTreeViewEx.TreeView.SelectedNode.Tag + "";
}
else if (LeftGridEx != null && !this.SysModel.AnyAdd)
{
DataRow row = LeftGridEx.GridView.GetFocusedDataRow();
if (LeftGridEx is TreeGridControlEx)
{
TreeListNode selectedNode = (LeftGridEx as TreeGridControlEx).TreeListObj.FocusedNode;
if (selectedNode.HasChildren && (!SystemInfo.Instance.AddingARootNode && !this.SysModel.selectLeaf))
{
MessageUtil.Show(ResourceKeys.SelectedNodeContainNode);
return;
}
row = LeftGridEx.GetViewFocusedDataRow();
}
if (row != null && _leftGridField != null)
{
mLeftFieldId = row[_leftGridField["fieldsqlid"] + ""] + "";
mLeftFieldName = row[_leftGridField["fieldsqlname"] + ""] + "";
mLeftGridData = row.ToJsonObject();
}
else if (row != null && AdditionalAssociatedMain)
{
mLeftFieldId = row[ParentKeyField] + "";
mLeftFieldName = row[ParentKeyField] + "";
mLeftGridData = row.ToJsonObject();
}
}
// 固定传入参数(窗口标题、操作员ID、操作员名称、权限、模版编号)
string unionKey = string.Empty, unionValue = string.Empty;
string maintabFocusedRowJson = "";
if (!string.IsNullOrWhiteSpace(DetailKeyField) && !string.IsNullOrEmpty(ParentKeyValue))
{
unionKey = DetailKeyField;
unionValue = ParentKeyValue;
}
if (Model.GetMaintabFocusedRow() != null)
{
DataRow row = Model.GetMaintabFocusedRow();
if (row != null)
{
maintabFocusedRowJson = JsonUtil.ToJsonObject(row);
}
}
// 上下结构底部添加数据处理
if (ParentGridEx != null)
{
DataRow row = ParentGridEx.GridView.GetFocusedDataRow();
if (this.ParentGridEx is TreeGridControlEx) row = this.ParentGridEx.GetViewFocusedDataRow();
if (row != null)
{
maintabFocusedRowJson = row.ToJsonObject();
unionKey = DetailKeyField;
unionValue = !string.IsNullOrEmpty(ParentKeyField) && row.Table.Columns.Contains(ParentKeyField) ? row[ParentKeyField] + "" : row.Table.Columns.Contains(DetailKeyField) ? row[DetailKeyField] + "" : string.Empty;
}
}
if (string.IsNullOrWhiteSpace(maintabFocusedRowJson) && this.SearchObj.SystemModel.maintabFocusedRow != null)
{
maintabFocusedRowJson = this.SearchObj.SystemModel.maintabFocusedRow.ToJsonObject();
}
// 上下结构父容器为面板
if (ParentControlEx != null)
{
unionKey = DetailKeyField;
unionValue = !string.IsNullOrEmpty(ParentKeyField) && this.ParentControlEx.FindControl(ParentKeyField) != null ? this.ParentControlEx.GetControlValue(ParentKeyField) : unionValue;
}
string controlValue = this.SysModel.AddReplaceConditionValue && this.SysModel.MenuAddName.ToLower().StartsWith("lskj.pubadd") ? this.SearchObj.GetAllControlValue() : "";
string[] defaultArgs = string.Format(ModuleArgs.DefaultArgs, this.Model.FormText, ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, this.Model.Privilege, this.Model.ModuleCode).Split('~');
string[] menuArgs = { string.Format(ModuleArgs.PubAddArgs, ""), "0", "", mLeftFieldId, mLeftFieldName, this.ControlSql, "1", "", controlValue, mLeftGridData == null ? mLeftTreeData : mLeftGridData, unionKey, unionValue };
string[] maintabFocusedRowArg = { maintabFocusedRowJson };
string[] args = defaultArgs.Concat(menuArgs).ToArray();
args = args.Concat(maintabFocusedRowArg).ToArray();
IForm form = FormHelper.LoadDllForm((this.SysModel.MenuAddName).ToLower().StartsWith("lskj.pubadd") ? ResourceDynamic.PubAdd : this.SysModel.MenuAddName, args);
//form.SubForm.Show();
DialogResult result = form.SubForm.ShowDialog();
if (result == DialogResult.OK)
{
//this.RefreshColumn();
this.SearchObj.SearchLastGrid();
if (OnSaveGridCallBack != null)
{
this.OnSaveGridCallBack(null, null);
}
}
form.SubForm.Dispose();
form = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:删除表格数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-31 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void DeleteGridRecord()
{
try
{
int[] rowids = this.gcMain.GridView.GetSelectedRows();
if (rowids == null || rowids.Length == 0)
{
MessageUtil.Show(ResourceKeys.SelectDeleteRows);
}
else
{
int rowhandle = rowids[0] - 1;
string deleteCond = this.SysModel.DeleteCond;
DialogResult result = MessageUtil.Show(string.Format(ResourceKeys.DeleteRows, rowids.Length), MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
string needDeletes = string.Empty;
string noDeletes = string.Empty;
ArrayList localDeletes = new ArrayList();
List<string> delToPosts = new List<string>();
foreach (int rowid in rowids)
{
DataRow rowData = this.gcMain.GridView.GetDataRow(rowid);
bool canDelete = string.IsNullOrWhiteSpace(deleteCond);
if (!canDelete)
{
// 检查条件
canDelete = ValidateCond(deleteCond, rowData, "P_SystemDllTab", "deleteCond");
}
if (canDelete)
{
// 存储过程检查
int rValue = ValidateDeleteProc(rowData);
if (rValue == 1)
{
if (rowData.RowState != DataRowState.Added)
{
needDeletes += string.Format("'{0}',", rowData[this._parmaryKey]);
if (!string.IsNullOrWhiteSpace(SysModel.DelToPostSql) && !string.IsNullOrWhiteSpace(SysModel.SynchronizationToolSQL))
{
delToPosts.Add(ReplaceHelper.ReplaceRowParam(rowData, SysModel.DelToPostSql).Trim());
}
}
else
localDeletes.Add(rowid);
}
else
{
noDeletes += string.Format("[{0}]-->{1}\n", rowData[this._parmaryKey], ResourceKeys.DisDeleteCond);
}
}
}
if (!string.IsNullOrWhiteSpace(needDeletes))
{
//删除触发的接口所要用到的参数,先把参数存到表中,同步工具去处理
if (!string.IsNullOrWhiteSpace(SysModel.DelToPostSql) && !string.IsNullOrWhiteSpace(SysModel.SynchronizationToolSQL))
{
for (int i = 0; i < delToPosts.Count; i++)
{
string parametersql = delToPosts[i];
DataTable dt = BaseModuleImpl.GetDataTableResult(parametersql);
foreach (DataRow dr in dt.Rows)
{
SqlHelper.ExecuteNonQuery(ReplaceHelper.ReplaceRowParam(dr, SysModel.SynchronizationToolSQL).Replace("''", "null"));
}
}
}
#region 删除前缓存接口数据
List<ApiHelper> apiHelpers = new List<ApiHelper>();
if (ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.AfterModuleDataDelete, this.Model.ModuleCode, 0))
{
string[] primaryValues = needDeletes.Trim(',').Split(',');
for (int i = 0; i < primaryValues.Length; i++)
{
string primaryValue = primaryValues[i];
if (primaryValue.StartsWith("'") && primaryValue.EndsWith("'"))
primaryValue = primaryValues[i].Substring(1, primaryValues[i].Length - 2);
ApiHelper apiHelper = new ApiHelper(this.Model.ModuleCode, primaryValue, _parmaryKey, this.SysModel.MenuTable, 0);
Interface.Api.ActionType actionType = Interface.Api.ActionType.Delete;
apiHelper.OnEvent(Interface.Api.OperateEvent.AfterModuleDataDelete, actionType, false);
apiHelpers.Add(apiHelper);
}
}
#endregion
int records = BaseModuleImpl.DeleteBaseGridData(this.SysModel.MenuTable, _parmaryKey, needDeletes);
if (records > 0)
{
BaseImpl.ExecSqlValue(string.Format("delete from p_baseflowoper where keyvalue in ({0}) and modid='{1}'", needDeletes, this.Model.ModuleCode));
string hintMsg = ResourceKeys.DeleteSuccess;
if (!string.IsNullOrWhiteSpace(noDeletes))
{
hintMsg += string.Format("\n发现如下{0}:\n" + noDeletes, ResourceKeys.DisDeleteCond);
}
this.SearchObj.SearchLastGrid();
this.gcMain.GridView.SelectRowHandler(rowhandle);
MessageUtil.Show(hintMsg);
if (!string.IsNullOrEmpty(this.SysModel.addDetilOrderField))//删除后排序字段
{
this.gcMain.gridControl.DataSourceTable().OrderBy(this.SysModel.addDetilOrderField);
}
#region 删除后调用api接口
string apiMsg = "";
foreach (ApiHelper apiHelper in apiHelpers)
{
apiHelper.OnEvent();
apiMsg = apiMsg + apiHelper.apiResutMsg;
}
if (!string.IsNullOrEmpty(apiMsg))
MessageUtil.Show(apiMsg);
#endregion
string primaryKey = (needDeletes.Replace("'", ""));
primaryKey = primaryKey.Substring(0, primaryKey.Length - 1);
LogUtil.WriteDebug(Model.ModuleCode, Model.FormText + "-->删除", Model.FormText + "[" + primaryKey + "]", Model.FormText, Model.ModuleId + "");
}
else
{
MessageUtil.Show(ResourceKeys.DeleteFault);
}
}
else
{
if (localDeletes.Count > 0)
{
// 删除选中且未保存的数据
for (int i = localDeletes.Count - 1; i >= 0; i--)
{
this.gcMain.GridView.DeleteRow((int)localDeletes[i]);
}
this.gcMain.GridView.SelectRowHandler(rowhandle);
MessageUtil.Show(ResourceKeys.DeleteSuccess);
if (!string.IsNullOrEmpty(this.SysModel.addDetilOrderField))
{
this.gcMain.gridControl.DataSourceTable().OrderBy(this.SysModel.addDetilOrderField);
}
}
else
{
MessageUtil.Show(ResourceKeys.DisDeleteCond);
}
}
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:新版本删除数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-05-27 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void DeleteGridRecordByNew()
{
try
{
int[] rowids = this.gcMain.GridView.GetSelectedRows();
if (rowids == null || rowids.Length == 0)
{
MessageUtil.Show(ResourceKeys.SelectDeleteRows);
}
else
{
if (this.gcMain.IsDataNotSaved())
{
DialogResult dialog = MessageUtil.Show("有数据未保存,是否保存", MessageBoxButtons.YesNo);
if (dialog == DialogResult.Yes)
{
if (this.btnSave.Visible && this.btnSave.Enabled)
{
this.OnSaveClick(null, null);
return;
}
else
{
MessageUtil.Show("没有保存权限,无法保存");
}
}
}
string deleteCond = this.SysModel.DeleteCond;
DialogResult result = MessageUtil.Show(string.Format(ResourceKeys.DeleteRows, rowids.Length), MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
ArrayList localDeletes = new ArrayList();
List<BaseSaveModel> mList = new List<BaseSaveModel>();
List<string> delToPosts = new List<string>();
foreach (int rowid in rowids)
{
DataRow rowData = this.gcMain.GridView.GetDataRow(rowid);
bool canDelete = string.IsNullOrWhiteSpace(deleteCond);
if (!canDelete)
{
// 检查条件
canDelete = ValidateCond(deleteCond, rowData, "P_SystemDllTab", "deleteCond");
}
if (canDelete)
{
if (rowData.RowState != DataRowState.Added)
{
string fieldValue = rowData[this._parmaryKey] + "";
string sqlValue = string.Format("delete from {0} where {1} = '{2}'", this.SysModel.MenuTable, this._parmaryKey, rowData[this._parmaryKey] + "");
BaseSaveModel model = new BaseSaveModel
{
BaseSaveType = SaveType.Delete,
BaseSql = sqlValue,
KeyField = _parmaryKey,
FieldValue = fieldValue,
NewVer = this.SysModel.NewVer,
MenuCode = this.Model.ModuleCode,
TableName = this.SysModel.MenuTable
};
mList.Add(model);
if (!string.IsNullOrWhiteSpace(SysModel.DelToPostSql) && !string.IsNullOrWhiteSpace(SysModel.SynchronizationToolSQL))
{
delToPosts.Add(ReplaceHelper.ReplaceRowParam(rowData, SysModel.DelToPostSql).Trim());
}
}
else
{
localDeletes.Add(rowid);
}
}
}
if (mList.Count > 0)
{
//删除触发的接口所要用到的参数,先把参数存到表中,同步工具去处理
if (!string.IsNullOrWhiteSpace(SysModel.DelToPostSql) && !string.IsNullOrWhiteSpace(SysModel.SynchronizationToolSQL))
{
for (int i = 0; i < delToPosts.Count; i++)
{
string parametersql = delToPosts[i];
DataTable dt = BaseModuleImpl.GetDataTableResult(parametersql);
foreach (DataRow dr in dt.Rows)
{
SqlHelper.ExecuteNonQuery(ReplaceHelper.ReplaceRowParam(dr, SysModel.SynchronizationToolSQL).Replace("''", "null"));
}
}
}
string apiReturnMsg = "";
bool success = BaseModuleImpl.SaveBaseGridData(mList, out apiReturnMsg);
string hintMsg = "删除结果如下:\n";
foreach (BaseSaveModel item in mList)
{
hintMsg += string.IsNullOrEmpty(item.FaultMsg) ? "记录[" + item.FieldValue + "]删除成功.\n" : "记录[" + item.FieldValue + "]删除失败,原因:" + item.FaultMsg + "\n";
if (string.IsNullOrEmpty(item.FaultMsg))
{
LogUtil.WriteDebug(Model.ModuleCode, Model.FormText + "-->删除", Model.FormText + "[" + item.FieldValue + "]", Model.FormText, Model.ModuleId + "");
}
}
this.SearchObj.SearchLastGrid();
MessageUtil.Show(hintMsg);
if (!string.IsNullOrEmpty(apiReturnMsg))
MessageUtil.Show(apiReturnMsg);
}
else
{
if (localDeletes.Count > 0)
{
// 删除选中且未保存的数据
for (int i = localDeletes.Count - 1; i >= 0; i--)
{
this.gcMain.GridView.DeleteRow((int)localDeletes[i]);
}
MessageUtil.Show(ResourceKeys.DeleteSuccess);
}
else
{
MessageUtil.Show(ResourceKeys.DisDeleteCond);
}
}
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:替换sql语句中的bmp字段</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-03-07 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sqlValue">The SQL value.</param>
/// <returns>System.String.</returns>
private string ReplaceBmpField(string sqlValue)
{
if (this._gridAllColumns == null || string.IsNullOrEmpty(sqlValue)) return sqlValue;
foreach (DataRow item in this._gridAllColumns.Rows)
{
string fieldName = item["fieldname"] + "";
//sqlValue = sqlValue.Replace(" ", "-").Replace("-", "").Replace(", ", ",").Replace(" ,", ",");
sqlValue = sqlValue.Replace("," + fieldName + ",", ",").Replace("," + fieldName, " ");
}
return sqlValue;
}
/// <summary>
/// <para>说明:获取固定菜单</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-02-08 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private ContextMenuStrip GetMenus()
{
ContextMenuStrip menu = new ContextMenuStrip();
ToolStripMenuItem tsmExport = new ToolStripMenuItem("导出Excel", null, OnTsmExportClick);
menu.Items.AddRange(new ToolStripMenuItem[] { tsmExport });
return menu;
}
/// <summary>
/// <para>说明:保存表格数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-10-23 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
public void SaveGridRecord(bool isErrorTips = true)
{
this.SaveResults = false;
this.isSuccessfullySaved = false;
string tableName = this.SysModel.MenuTable;
//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", tableName)) + "";
//DataTable DatabasePropertySheet = BaseImpl.GetDataTableResult(string.Format("select COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH from information_schema.columns where table_name = '{0}'", tableName));//数据库属性表
string Autogrowcolumn = MainImpl.GetAutogrowcolumn(tableName);
DataTable DatabasePropertySheet = MainImpl.GetDatabaseProperty(tableName);
string SaveErrorMessage = "失败列表:\r\n";
if (string.IsNullOrEmpty(tableName))
{
MessageUtil.Show(ResourceKeys.MenuTableNameIsNull);
return;
}
List<BaseSaveModel> mList = new List<BaseSaveModel>();
DataRow[] modifiedRows = (gcMain.GridControl.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
{
DataColumnCollection columns = BaseImpl.GetTableColumns(tableName).Columns;
//Dictionary<int, string> modifyThePosition = this.gcMain.modifyThePosition;//修改过的单元格
//DataTable screeningDt = this.gcMain.GridControl.DataSourceTable();
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.Model.ModuleCode,
TableName = tableName,
KeyField = _parmaryKey,
NewVer = this.SysModel.NewVer
};
// int theLineNumbers = screeningDt.Rows.IndexOf(row);//当前行的行号
//string[] columnNames = null;
//if (modifyThePosition.ContainsKey(index))columnNames = modifyThePosition[theLineNumbers].Split(',');
foreach (DataColumn col in columns)
{
// 区分大小写匹配列
DataRow hasContainRow = _gridColumns.Rows.Cast<DataRow>().FirstOrDefault(x => (x["fieldname"] + "").ToLower() == col.ColumnName.ToLower());
if (hasContainRow != null && col.ColumnName != _parmaryKey && !_disUpdateColumns.Contains(col.ColumnName) && Autogrowcolumn.ToLower() != col.ColumnName.ToLower())
{
if (row.RowState == DataRowState.Modified && string.IsNullOrEmpty(SysModel.CustomColumnSQL))
{
string newValue = string.Empty;
string oldValue = string.Empty;
if (isDrag)
{
newValue = row[col.ColumnName] + "";
oldValue = LineStatus[row][col.ColumnName] + "";
}
else
{
oldValue = row[col.ColumnName, DataRowVersion.Original] + "";
newValue = row[col.ColumnName, DataRowVersion.Current] + "";
}
//如果是修改状态,没有改变的值就不拼接,以免造成多人同时修改同一行不同列的值混乱情况
if (oldValue != newValue)
{
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}]=N'{1}',", col.ColumnName, (row[col.ColumnName] + "").Replace("'", "''"));
}
}
}
}
else if (row.RowState == DataRowState.Added || (row.RowState == DataRowState.Modified && !string.IsNullOrEmpty(SysModel.CustomColumnSQL)))
{
// 动态生成列,保存时默认全部为新增
string fieldValue = string.Empty;
if (col.ColumnName == this.DetailKeyField && this.ParentGridEx != null)
{
// 处理关联值
DataRow rowItem = this.ParentGridEx.GetViewFocusedDataRow();
if (this.ParentGridEx is TreeGridControlEx) rowItem = this.ParentGridEx.GetViewFocusedDataRow();
if (rowItem.Table.Columns.Contains(this.ParentKeyField))
fieldValue = rowItem[this.ParentKeyField] + "";
else if (rowItem.Table.Columns.Contains(this.DetailKeyField))
fieldValue = rowItem[this.DetailKeyField] + "";
}
else
{
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") + "'," : "N'" + fieldValue + "',";
}
else
{
if (col.DataType == typeof(Decimal) || col.DataType == typeof(Int32))
insertValues += "0,";
else if (col.DataType == typeof(DateTime))
insertValues += "NULL,";
else
insertValues += "'',";
}
}
SaveErrorMessage = SaveErrorMessage + DatabaseFormatJudgment.SaveOrModifyBalidation(_gridColumns, DatabasePropertySheet, row, col, (row[col.ColumnName] + "").Replace("'", "''"));
}
}
// 检查是否保存主键字段
if (row.RowState == DataRowState.Added && !insertFields.Contains($"[{(_parmaryKey)}]") && !"ID".Equals($"[{(_parmaryKey)}]", StringComparison.OrdinalIgnoreCase))
{
// 跳过自动增长列处理
if (Autogrowcolumn.ToLower() != _parmaryKey.ToLower())
{
insertFields += "[" + _parmaryKey + "],";
insertValues += "N'" + row[_parmaryKey] + "',";
}
}
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);
}
if (!string.IsNullOrWhiteSpace(model.BaseSql)) mList.Add(model);
}
try
{
if (mList.Count == 0)
{
MessageUtil.Show(ResourceKeys.UnUpdateData);
return;
}
string retuenMsg = "";
string apiRetMsg = "";
// 批量保存数据v
if (BaseModuleImpl.SaveBaseGridData(mList, out retuenMsg, out apiRetMsg))
{
if (retuenMsg == "9")
{
if (MessageUtil.Show(mList[0].FaultMsg, MessageBoxButtons.YesNo) == DialogResult.Yes)
{
if (BaseModuleImpl.SaveBaseGridData(mList, "1"))
{
(gcMain.GridControl.DataSource as DataTable).AcceptChanges();
if (this.SearchObj != null)
{
this.SearchObj.SearchLastGrid();
}
if (_leftGridSearchObj != null)
{
this._leftGridSearchObj.SearchGrid();
}
if (SaveEvent != null)
{
SaveEvent(null);
}
if (isErrorTips)
MessageUtil.Show(ResourceKeys.SaveSuccess);
}
}
}
else
{
this.SaveResults = true;
this.isSuccessfullySaved = true;
(gcMain.GridControl.DataSource as DataTable).AcceptChanges();
if (this.SearchObj != null)
{
this.SearchObj.SearchLastGrid();
}
if (_leftGridSearchObj != null)
{
this._leftGridSearchObj.SearchGrid();
}
if (SaveEvent != null)
{
SaveEvent(null);
}
if (isErrorTips && this.SysModel.SaveHint)
MessageUtil.Show(ResourceKeys.SaveSuccess);
if (!string.IsNullOrEmpty(apiRetMsg))
MessageUtil.Show(apiRetMsg);
}
}
else
{
StringBuilder builder = new StringBuilder();
builder.Append("失败列表\r\n");
foreach (BaseSaveModel item in mList)
{
if (!string.IsNullOrEmpty(item.FaultMsg))
SaveErrorMessage += item.FaultMsg + "\r\n";
}
LogHelper.Instance.WriteLog(builder.ToString());
MessageUtil.Show(SaveErrorMessage);
//if (SaveErrorMessage.StartsWith("@") && false)
//{
// //根据tipMsg中数据找到pMenu中对应的右键
// foreach (BarItemLink itemLink in pm_common.ItemLinks)
// {
// if (false)
// {
// ErrorRestriction errorRestriction = new ErrorRestriction(SaveErrorMessage, this.Model, this.SearchObj, itemLink);
// DialogResult drr = errorRestriction.ShowDialog();
// errorRestriction.Dispose();
// }
// }
//}
if (!isErrorTips)
this.SearchObj.SearchLastGrid();
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
}
/// <summary>
/// <para>说明:保存树表格数据</para>
/// <para>创建人:王一帆</para>
/// <para>创建日期:2020-01-31 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void SaveTreeRecord()
{
TreeGridControlEx treeMain = gcMain as TreeGridControlEx;
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
{
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.Model.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 = string.Empty;
if (col.ColumnName == this.DetailKeyField && this.ParentGridEx != null)
{
// 处理关联值
DataRow rowItem = this.ParentGridEx.GridView.GetFocusedDataRow();
if (this.ParentGridEx is TreeGridControlEx) rowItem = this.ParentGridEx.GetViewFocusedDataRow();
if (rowItem.Table.Columns.Contains(this.ParentKeyField))
fieldValue = rowItem[this.ParentKeyField] + "";
else if (rowItem.Table.Columns.Contains(this.DetailKeyField))
fieldValue = rowItem[this.DetailKeyField] + "";
}
else
{
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 && _leftGridSearchObj != null)
{
this.SearchObj.SearchLastGrid();
this._leftGridSearchObj.SearchGrid();
}
if (SaveEvent != null)
{
SaveEvent(null);
}
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>
/// <para>说明:修改数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-31 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void UpdateGridRecord()
{
try
{
StaticControl.AddParentGrid = new KeyValuePair<string, GridControlEx>(Model.ModuleCode, gcMain);
if (!string.IsNullOrWhiteSpace(this.SysModel.MenuAddName))
{
string modifyCond = this.SysModel.ModifyCond;
bool canUpdate = this.SysModel.ModifyEnable;
DataRow selectRow = gcMain.GridView.GetFocusedDataRow();
if (selectRow == null) return;
if (canUpdate)
{
if (!string.IsNullOrWhiteSpace(modifyCond))
{
// 检查条件
canUpdate = ValidateCond(modifyCond, selectRow, "P_SystemDllTab", "modifyCond");
}
}
else
{
canUpdate = false;
}
if (this.SysModel.MenuAddName.Equals("Lskj.PubAdd4.dll", StringComparison.OrdinalIgnoreCase))
{
string url = string.Format("pages/app/app.html?username={0}&password={1}&xtype={2}&idValue={3}&detail=1&dllcoid=", ERPInfo.Instance.UserName, ERPInfo.Instance.Password, this.SysModel.BsAdddllname, selectRow[this.ParmaryKey]);
// 固定传入参数(窗口标题、操作员ID、操作员名称、权限、模版编号)
string[] defaultArgs = string.Format(ModuleArgs.DefaultArgs, this.Model.FormText, ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, this.Model.Privilege, this.Model.ModuleCode).Split('~');
string[] menuArgs = new string[] { "", "", url };
string[] args = defaultArgs.Concat(menuArgs).ToArray();
IForm form = FormHelper.LoadDllForm(ResourceDynamic.PubBrower, args);
form.SubForm.WindowState = FormWindowState.Maximized;
DialogResult result = form.SubForm.ShowDialog();
}
else
{
// 固定传入参数(窗口标题、操作员ID、操作员名称、权限、模版编号)
string[] defaultArgs = string.Format(ModuleArgs.DefaultArgs, this.Model.FormText, ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, this.Model.Privilege, this.Model.ModuleCode).Split('~');
string[] menuArgs = { "", canUpdate ? "0" : "1", selectRow[_parmaryKey] + "" };
string[] args = defaultArgs.Concat(menuArgs).ToArray();
IForm form = FormHelper.LoadDllForm(ResourceDynamic.PubAdd, args);
DialogResult result = form.SubForm.ShowDialog();
//RefreshColumn();
if (result == DialogResult.OK)
{
this.SearchObj.SearchLastGrid();
if (OnSaveGridCallBack != null)
{
this.OnSaveGridCallBack(null, null);
}
}
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show("基础模块修改数据出错!" + Message);
}
}
/// <summary>
/// <para>说明:刷新数据前判断刷新表格列</para>
/// <para>创建人:王一帆</para>
/// <para>创建日期:2020-01-15 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void RefreshColumn()
{
try
{
foreach (GridColumn gridColum in this.GridControlObj.GridView.Columns)
{
GridColumnModel model = gridColum.Tag as GridColumnModel;
if (model == null) continue;
if (model.FieldType == ControlType.LabAutoCompleteValueParam)
{
RepositoryItemGridLookUpEdit lookupEdit = gridColum.ColumnEdit as RepositoryItemGridLookUpEdit;
if (lookupEdit != null)
{
lookupEdit.DataSource = MainImpl.GetDataTableResult(model.SqlSource);
}
}
}
}
catch (Exception ex)
{
LogHelper.Instance.WriteError(ex);
}
}
/// <summary>
/// <para>说明:导入表格数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-31 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void ImportGridRecord()
{
try
{
//取左边树结构或者表中的关键值
string leftField = _leftGridField != null ? _leftGridField["fieldname"] + "" : "SpeciesNo"; ;
string leftValue = string.Empty;
if (this.LeftGridEx != null && this.LeftGridEx.DataRowCount() > 0 && this._leftGridField != null)
{
leftValue = this.LeftGridEx.GridView.GetDataRow(LeftGridEx.GridView.FocusedRowHandle)[ParentKeyField] + "";
if (LeftGridEx is TreeGridControlEx)
{
leftValue = LeftGridEx.GetViewFocusedDataRow()[ParentKeyField] + "";
}
}
else if (this.LeftTreeViewEx != null && this.LeftTreeViewEx.TreeView.GetNodeCount(true) > 0 && this._leftGridField != null)
{
if (LeftTreeViewEx.TreeView.SelectedNode == null)
{
MessageUtil.Show("设置导入错误,未选中树节点");
return;
}
else
{
leftValue = LeftTreeViewEx.TreeView.SelectedNode.Tag + "";
}
}
else if (this.ParentGridEx != null && this.ParentGridEx is TreeGridControlEx)
{
TreeGridControlEx treeGridControlEx = this.ParentGridEx as TreeGridControlEx;
if (treeGridControlEx.GetGridViewDataSource().Rows.Count > 0)
{
leftValue = treeGridControlEx.GetViewFocusedDataRow()[ParentKeyField] + "";
leftField = this.DetailKeyField;
}
}
else if (this.ParentGridEx != null && this.ParentGridEx.DataRowCount() > 0)
{
leftValue = this.ParentGridEx.GridView.GetDataRow(ParentGridEx.GridView.FocusedRowHandle)[ParentKeyField] + "";
leftField = this.DetailKeyField;
}
else if (!string.IsNullOrEmpty(this.ParentKeyValue))
{
leftField = this.ParentKeyField;
leftValue = this.ParentKeyValue;
}
List<string> ImportReturnName = this.SearchObj.getImportReturnValueControl();
List<string> ImportReturnValue = new List<string>();
if (ImportReturnName.Count > 0)
{
foreach (string item in ImportReturnName)
{
BaseUserControl baseUserControl = this.SearchObj.FindControl(item);
string Value = "";
if (baseUserControl.Model.ImportReturnValue)
{
Value = BaseImpl.GetDefaultValue(baseUserControl.Model.Default);
this.SearchObj.SetControlValue(item, Value);
}
else if (baseUserControl.Model.ImportCurrentValue)
{
Value = this.SearchObj.GetControlValue(item);
}
ImportReturnValue.Add(Value);
}
}
//快速导入
if (SystemInfo.Instance.QuickImportMode)
{
bool ImportResults = this.gcMain.GridView.QuickImport(this.SysModel, _parmaryKey, leftField, leftValue, ImportReturnName, ImportReturnValue, this.ParentGridEx);
// 刷新数据
if (ImportResults)
{
if (ImportReturnName.Count > 0)
{
this.SearchObj.SearchGrid();
}
else
{
this.SearchObj.SearchLastGrid();
}
if (!string.IsNullOrWhiteSpace(this.SysModel.afterimportSql))
{
string sql = this.SearchObj.ReplaceControlValue(this.SysModel.afterimportSql);
string newResult = SqlHelper.ExecuteScalar(sql) + "";
}
}
//GridColumnCollection gridColumns = this.gcMain.GridView.Columns;
//DataTable NewTable = this.gcMain.GridControl.DataSourceTable();
//foreach (DataRow rowItem in ImportTable.Rows)
//{
// DataRow newRow = NewTable.NewRow();
// foreach (GridColumn col in gridColumns)
// {
// if ("id".Equals(col.FieldName) || col.FieldName.Equals(this.ParmaryKey)) continue;
// if (rowItem.Table.Columns.Contains(col.FieldName))
// {
// // 列中是否包含对应字段,包含则使用值
// newRow[col.FieldName] = rowItem[col.FieldName];
// }
// else
// {
// // 未包含字段,则使用控件默认值.
// GridColumnModel model = col.Tag as GridColumnModel;
// string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue);
// if (!string.IsNullOrEmpty(fieldValue))
// {
// newRow[col.FieldName] = fieldValue;
// }
// }
// }
// NewTable.Rows.Add(newRow);
//}
}
else
{
FrmImport import = new FrmImport(this.SysModel.MenuTable, this.Model.ModuleCode, _parmaryKey, this.gcMain, this.SysModel.PrefixKey, leftField, leftValue, this.Model.FormText, this.SysModel.ConcatenatedPrefix);
import.ParentGridEx = this.ParentGridEx;
import.ImportReturnName = ImportReturnName;
import.ImportReturnValue = ImportReturnValue;
DialogResult result = import.ShowDialog();
if (result == DialogResult.OK)
{
// 刷新数据
if (ImportReturnName.Count > 0)
{
this.SearchObj.SearchGrid();
}
else
{
this.SearchObj.SearchLastGrid();
}
if (!string.IsNullOrWhiteSpace(this.SysModel.afterimportSql))
{
string sql = this.SearchObj.ReplaceControlValue(this.SysModel.afterimportSql);
string newResult = SqlHelper.ExecuteScalar(sql) + "";
//if (!string.IsNullOrEmpty(newResult)) MessageUtil.Show(newResult);
}
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show("基础档案导入错误!" + Message);
}
}
/// <summary>
/// <para>说明:导出表格数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-31 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void ExportGridRecord()
{
LogUtil.WriteDebug(this.Model.ModuleCode, "导出数据", this.SysModel.MenuText, "导出数据");
this.gcMain.ExportNameWithoutDate = SysModel.ExportNameWithoutDate;
if (this.gcMain is TreeGridControlEx)
{
TreeGridControlEx treeControlEx = this.gcMain as TreeGridControlEx;
treeControlEx.TreeListObj.ToExcelTreeList(this.Model.FormText);
}
else if (this.gcMain is BandedGridControlEx)
{
BandedGridControlEx bandedGridControEx = this.gcMain as BandedGridControlEx;
bandedGridControEx.ToExcel(this.Model.FormText);
}
else
{
bool merger = gcMain.GridView.OptionsView.AllowCellMerge;
this.gcMain.GridControl.ToExcel(this.Model.FormText, merger, GridCustomColumnStruct.BaseMainGridView + this.SysModel.FormKey);
}
}
/// <summary>
/// <para>说明:打印表格数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-31 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void PrintGridRecord()
{
PrintUtil.Print(this.gcMain.GridControl);
}
/// <summary>
/// <para>说明:打印完成需要参数</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-07-09 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void GetPrintOtherParam()
{
//取得打印完成后的参数
if (this.SysModel.PrintSql.Contains("<<"))
{
string[] strs = this.SysModel.PrintSql.Split(new[] { ">>" }, 2, StringSplitOptions.None);
_mainPrintSql = strs[1];
_printModeCond = strs[0].Replace("<<", "");
}
if (!string.IsNullOrEmpty(_printModeCond) && _printModeCond.IndexOf(';') > 0)
{
string[] str = _printModeCond.Split(';');
DataRow item = AttachImpl.GetSystemModule(str[0]);
string tableName = item["TableName"] + "";
string modetype = item["modType"] + "";
string comprefix = BaseImpl.GetColumnPrefix(tableName);
string primaryKey = modetype == "1" ? BaseImpl.GetBasePrimaryKey(str[0]) : comprefix + "billdocument_id";
//表名,列前缀,主键字段,主键值,模块编号,主打印Sql
_printSaveParams = new List<string>() { tableName, comprefix, primaryKey, str[1], str[0], _mainPrintSql };
//判断是否直接打印 modetype 区别单据和基础档案模块
switch (modetype)
{
case "1":
ModuleModel mode = new ModuleModel(MainImpl.GetSystemdllTab(str[0]));
if (mode != null) _isExcPrint = mode.PrintType == 3;
break;
case "2":
BaseAccraditationModel model = new BaseAccraditationModel(BillAuditImpl.GetPubAuditProperty(str[0]));
if (model != null) _isExcPrint = model.BillPrintType == 3;
break;
}
}
}
/// <summary>
/// 传入模块号打印完成需要参数
/// </summary>
private void GetPrintOtherParam(string ModeCond)
{
//取得打印完成后的参数
if (!string.IsNullOrEmpty(ModeCond))
{
DataRow item = AttachImpl.GetSystemModule(ModeCond);
string tableName = item["TableName"] + "";
string modetype = item["modType"] + "";
string comprefix = BaseImpl.GetColumnPrefix(tableName);
string primaryKey = modetype == "1" ? BaseImpl.GetBasePrimaryKey(ModeCond) : comprefix + "billdocument_id";
//表名,列前缀,主键字段,主键值,模块编号,主打印Sql
_printSaveParams = new List<string>() { tableName, comprefix, primaryKey, "", ModeCond, _mainPrintSql };
//判断是否直接打印 modetype 区别单据和基础档案模块
switch (modetype)
{
case "1":
ModuleModel mode = new ModuleModel(MainImpl.GetSystemdllTab(ModeCond));
if (mode != null) _isExcPrint = mode.PrintType == 3;
break;
case "2":
BaseAccraditationModel model = new BaseAccraditationModel(BillAuditImpl.GetPubAuditProperty(ModeCond));
if (model != null) _isExcPrint = model.BillPrintType == 3;
break;
}
}
}
#endregion
#region public method
public ModuleGridEx()
{
InitializeComponent();
this.OperShortMode = true;
}
/// <summary>
/// 明细父表格点击后刷新明细按钮权限
/// </summary>
/// <param name="dataRow"></param>
public void ParentButtonState(DataRow rowItem)
{
if (rowItem == null) return;
try
{
if (!Model.HasOperPrivilege())
{
this.btnAdd.Enabled = this.btnDel.Enabled = this.btnDel.Enabled = false;
}
else
{
//获得所有的权限条件
string conditions = this.SysModel.AddCond + this.SysModel.DeleteCond + this.SysModel.ModifyCond + this.SysModel.ImportCond + this.SysModel.ExportCond;
//替换固定字段
conditions = ReplaceHelper.ReplaceUserInfo(conditions);
List<string> conditionList = ReplaceHelper.GetParamFields(conditions);
//判断传进来的行是否包含条件中的字段
bool isContains = false;
foreach (string item in conditionList)
{
if (rowItem.Table.Columns.Contains(item.Replace("{", "").Replace("}", ""))) isContains = true;
}
//cond.StartsWith("@") || cond.StartsWith("!")
if (isContains)
{
DataRow currentRow = this.gcMain.GridView.GetFocusedDataRow();
//把父表选中行和当前行都替换后在判断,避免传入行为null时,默认为true的情况
this.btnAdd.Enabled = this.SysModel.AddEnable && this.ValidateCond(ReplaceHelper.ReplaceRowParam(currentRow, ReplaceHelper.ReplaceRowParam(rowItem, this.SysModel.AddCond)), null, "P_SystemDllTab", "addCond"); // 判断添加权限
this.btnDel.Enabled = this.SysModel.DeleteEnable && this.ValidateCond(ReplaceHelper.ReplaceRowParam(currentRow, ReplaceHelper.ReplaceRowParam(rowItem, this.SysModel.DeleteCond)), null, "P_SystemDllTab", "deleteCond"); // 判断删除权限
this.btnSave.Enabled = this.SysModel.ModifyEnable && this.ValidateCond(ReplaceHelper.ReplaceRowParam(currentRow, ReplaceHelper.ReplaceRowParam(rowItem, this.SysModel.ModifyCond)), null, "P_SystemDllTab", "modifyCond"); // 判断修改权限
this.btnImport.Enabled = this.SysModel.ImportEnable && this.ValidateCond(ReplaceHelper.ReplaceRowParam(currentRow, ReplaceHelper.ReplaceRowParam(rowItem, this.SysModel.ImportCond)), null, "P_SystemDllTab", "importCond"); // 判断导入权限
this.btnExport.Enabled = this.SysModel.ExportEnable && this.ValidateCond(ReplaceHelper.ReplaceRowParam(currentRow, ReplaceHelper.ReplaceRowParam(rowItem, this.SysModel.ExportCond)), null, "P_SystemDllTab", "exportCond") && this.SysModel.ExportPermission; // 判断导出权限
}
}
}
catch (Exception)
{
}
}
/// <summary>
/// <para>说明:初始化控件</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-09-12 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="menuRow">模块p_systemdlltab相关数据</param>
public void InitializeControl(ModuleModel sysModel, DynamicModel model)
{
try
{
if (sysModel != null && model != null)
{
this.SysModel = sysModel;
this.Model = model;
this.gcMain.DisableFieldSources = this.SysModel.DisableFieldSources;
this.gcMain.UpdateColumns = this.SysModel.UpdateColumns;
//if (this.Model is DynamicModuleDetailModelInfo)
//{
// DynamicModuleDetailModelInfo dynamic = this.Model as DynamicModuleDetailModelInfo;
// this.ControlSql = dynamic.ControlSql;
//}
Dictionary<object, Hashtable> dataCaches = Model != null ? Model.DataCaches : null;
if (!dataCaches.GetValue(this, "BasePrimaryKey", out string parmaryKey))
{
parmaryKey = BaseImpl.GetBasePrimaryKey(this.Model.ModuleCode);//获取主键
}
this._parmaryKey = this.ParmaryKey = parmaryKey;
if (!dataCaches.GetValue(this, "CustomQueryFields", out _queryTable))
{
_queryTable = BaseModuleImpl.GetCustomQueryFields(this.SysModel.CondKey);//加载自定义配置字段
}
if (!dataCaches.GetValue(this, "ColumnPrefix", out this.SysModel.PrefixKey))
{
this.SysModel.PrefixKey = BaseImpl.GetColumnPrefix(sysModel.MenuTable);//获取列前缀
}
if (!dataCaches.GetValue(this, "SchemesList", out this._schemesTable))
{
this._schemesTable = BaseModuleImpl.GetSchemesList(this.Model.ModuleId);//获取高级查询条件模版
}
this.InitializeQueryCondition();
if (!dataCaches.GetValue(this, "BaseGridColumns", out this._gridColumns))
{
this._gridColumns = BaseModuleImpl.GetBaseGridColumns(this.Model.ModuleCode);
}
if (!dataCaches.GetValue(this, "BaseGridAllColumns", out this._gridAllColumns))
{
this._gridAllColumns = BaseModuleImpl.GetBaseGridAllColumns(this.Model.ModuleCode);
}
if (!dataCaches.GetValue(this, "SaveCondTab", out this.SaveCondTab))
{
this.SaveCondTab = BaseModuleImpl.GetClientCond(this.Model.ModuleCode);
}
if (this.SearchObj != null)
{
this.SearchObj.SystemModel = sysModel;
}
//禁用条件
if (this.SysModel.ForbiddenCondition)
{
this.pl_top_search.Visible = false;
}
if (this._gridColumns != null && this._gridColumns.Rows.Count > 0)
{
this._nullFields = this._gridColumns.Select("nullable=1");
this._leftGridField = this._gridColumns.Select("fieldsqlTag=3").FirstOrDefault();
//DataRow dr = this._gridColumns.Select("username='机构编号'").FirstOrDefault();
}
this.InitializeCommonOperation();
this.InitializePrint();
this.InitializeButtonState();
this.InitializeGridView();
this.GetPrintOtherParam();
this.SearchObj.SetGridControlEx(this.gcMain); // 因创建条件时还GridView还未确定,需确定后在进行绑定
//修改条件
this.gcMain.ModifyCond = this.SysModel.ModifyCond;
//主键
this.gcMain.MultiplePrimary = parmaryKey;
//合计是否只显示行数
this.gcMain.TotalQuantity = this.SysModel.TotalQuantity;
//判断是否禁用排序和筛选
if (!string.IsNullOrWhiteSpace(this.SysModel.HeaderSortCriteria))
{
this.gcMain.GridView.OptionsCustomization.AllowFilter = this.gcMain.GridView.OptionsCustomization.AllowSort = ValidateCond(this.SysModel.HeaderSortCriteria, null);
}
// 常用工具
this.InitializeCommonTool();
if (SysModel.isLeftRightMode) this.pl_top_right.Visible = false;
this.gcMain.OnNewLine += new GridControlEx.ModuleAddLine(AddGridRows);
//隐藏按钮,改变pl_top_right宽度,重新计算按钮坐标(显示比列放大的话,左侧条件可能会别遮住,需要减去宽度后重新算坐标)
this.CalculateCoordinates();
//设置上方按钮形式的右键
InitializeUpperRightMenu();
//绑定老版粘贴回调新增行事件
this.gcMain.OnAfterPasting += GcMain_OnAfterPasting;
//触发右键回调
this.gcMain.OnAfterLinkCilk += OnAfterLinkCilkCall;
if (!string.IsNullOrWhiteSpace(this.SysModel.SelectDisplayColumn))
{
//this.gcMain.GridView.CustomColumnDisplayText += GridView_CustomColumnDisplayText;
this.gcMain.GridView.CustomDrawCell += OnGridViewCustomDrawCell;
}
if (this.SysModel.IgnoreTab)
{
this.gcMain.IgnoreTab = this.SysModel.IgnoreTab;
}
//判断是否隐藏数据导入按钮
string[] authorizedPersonnel = SysModel.ImportPermissions.Split(',');//有导入权限的人员
this.btnImport.Enabled = false;
if (string.IsNullOrWhiteSpace(SysModel.ImportPermissions) || Array.IndexOf(authorizedPersonnel, ERPInfo.Instance.UserName) != -1 || ERPInfo.Instance.UserName.Equals("管理员"))
{
this.btnImport.Enabled = true;
}
if (!string.IsNullOrEmpty(SysModel.PreSQL))//动态表格只保留新增
{
this.dpbTools.Visible = this.btnDel.Visible = this.btnUpdate.Visible = this.btnSave.Visible = this.btnImport.Visible = this.btnExport.Visible = this.btnPrint.Visible = false;
this.btnAdd.Location = new Point(this.pl_buttom.Width - this.btnAdd.Width - 5, this.btnAdd.Location.Y);
}
this.SetScanEvent();
this.ValidateButtonState(null, false);
if (SystemInfo.Instance.TabAddLine || this.SysModel.EnterToNextRow)
{
this.gcMain.GridView.KeyDown += OnGcMain_KeyDown;
}
if (!string.IsNullOrWhiteSpace(this.SysModel.SweepCodeSql))
{
this.pl_SweepCode.Visible = true;
this.txt_SweepCode.KeyDown += Txt_SweepCode_KeyDown;
}
}
//按钮翻译
//this.ButtonTranslation();
}
catch (Exception ex)
{
//throw new Exception("经过进一步包装的异常", ex);
// throw;
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
private void Txt_SweepCode_KeyDown(object sender, KeyEventArgs e)
{
try
{
if (e.KeyCode == Keys.Enter)
{
this.SweepCodeRow = null;
string text = this.txt_SweepCode.Text;
string Sql = ReplaceHelper.ReplaceParamToValue(ReplaceHelper.ReplaceUserInfo(this.SysModel.SweepCodeSql), "{keyvalue}", text);
DataTable dataTable = SqlHelper.ExecuteDataTable(Sql);
if (dataTable == null || dataTable.Rows.Count == 0) return;
foreach (DataRow item in dataTable.Rows)
{
this.SweepCodeRow = item;
this.AddGridViewRecord();
}
this.txt_SweepCode.Text = "";
if (btnSave.Enabled)
{
this.OnSaveClick(null, null);
}
this.txt_SweepCode.Focus();
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
finally
{
this.SweepCodeRow = null;
}
}
/// <summary>
/// 获取数据源缓存
/// </summary>
/// <param name="cachesDic"></param>
/// <param name="sysModel"></param>
/// <param name="dynamicModel"></param>
public void GetDataCaches(Dictionary<object, Hashtable> cachesDic)
{
//获取通用数据
Task<ModuleModel> sysModelTask = cachesDic.GetTask<ModuleModel>(this, "SysModel");
Task<DynamicModel> dynamicModelTask = cachesDic.GetTask<DynamicModel>(this, "DynamicModel");
ModuleModel sysModel = sysModelTask.Result;
DynamicModel dynamicModel = dynamicModelTask.Result;
if (sysModel != null && dynamicModel != null)
{
Task<string> basePrimaryKeyTask = cachesDic.AddTask(this, "BasePrimaryKey", new Task<string>(() =>
{
return BaseImpl.GetBasePrimaryKey(dynamicModel.ModuleCode);//获取主键
}));
Task<DataTable> customQueryFieldsTask = cachesDic.AddTask(this, "CustomQueryFields", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetCustomQueryFields(sysModel.CondKey);//加载自定义配置字段
}));
Task<string> columnPrefixTask = cachesDic.AddTask(this, "ColumnPrefix", new Task<string>(() =>
{
return BaseImpl.GetColumnPrefix(sysModel.MenuTable);//获取列前缀
}));
Task<DataTable> schemesListTask = cachesDic.AddTask(this, "SchemesList", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetSchemesList(dynamicModel.ModuleId);//获取高级查询条件模版
}));
//InitializeQueryCondition
Task<MyControl> searchObjTask = cachesDic.AddTask(this, "SearchObj", new Task<MyControl>(() =>
{
DataTable queryTable = customQueryFieldsTask.Result;
bool fixedQuery = queryTable == null || queryTable.Rows.Count == 0;
MyControl myControl = new MyControl(sysModel.MenuSql, gcMain, LeftTreeViewEx, LeftGridEx, _leftGridSearchObj)
{
SpecialLeftTable = this.SpecialLeftTable,
Model = dynamicModel
};
if (!fixedQuery)
{
myControl.OtherParams = dynamicModel.OtherParams();
cachesDic.AddTask(myControl, "DynamicModel", dynamicModelTask);
cachesDic.AddTask(myControl, "ControlsTable", customQueryFieldsTask);
myControl.GetSearchDataCaches(cachesDic);
}
return myControl;
}));
Task<ModuleModel> searchSysModelTask = cachesDic.AddTask(pl_top_search, "SysModel", new Task<ModuleModel>(() =>
{
return new ModuleModel(MainImpl.GetSystemdllTab(dynamicModel.ModuleCode));
}));
Task<DataTable> searchBaseGridRightMenusTask = cachesDic.AddTask(pl_top_search, "BaseGridRightMenus", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetBaseGridRightMenus(dynamicModel.ModuleCode, ModuleType.MrpClickBtn);
}));
Task<DataTable> fixedQueryFieldsTask = cachesDic.AddTask(this, "FixedQueryFields", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetFixedQueryFields(dynamicModel.ModuleCode);//加载固定查询条件
}));
Task<DataTable> baseGridAllColumnsTask = cachesDic.AddTask(this, "BaseGridAllColumns", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetBaseGridAllColumns(dynamicModel.ModuleCode);
}));
Task<DataTable> saveCondTabTask = cachesDic.AddTask(this, "SaveCondTab", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetClientCond(dynamicModel.ModuleCode);
}));
Task<DataTable> baseGridColumnsTask = cachesDic.AddTask(this, "BaseGridColumns", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetBaseGridColumns(dynamicModel.ModuleCode);
}));
//设置表格列
string customColumKey = GridCustomColumnStruct.BaseMainGridView + sysModel.FormKey;
cachesDic.AddTask(gcMain, "DynamicModel", dynamicModelTask);
gcMain.GetDataCaches(cachesDic, customColumKey);
//GetPrintOtherParam
Task<DataTable> printTemp70Task = cachesDic.AddTask(this, "PrintTemp70", new Task<DataTable>(() =>
{
return BaseImpl.GetPrintTemp70(dynamicModel.ModuleCode);
}));
Task<DataTable> baseGridRowColorsTask = cachesDic.AddTask(this, "BaseGridRowColors", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetBaseGridRowColors(dynamicModel.ModuleCode);
}));
Task<DataTable> baseGridRightMenusTask = cachesDic.AddTask(this, "BaseGridRightMenus", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetBaseGridRightMenus(dynamicModel.ModuleCode);
}));
//GetPrintOtherParam();
// 常用工具
Task<DataTable> commonToolGridRightMenusTask = cachesDic.AddTask(this, "CommonToolGridRightMenus", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetBaseGridRightMenus(dynamicModel.ModuleCode, ModuleType.BaseModuleAdd);
}));
//ValidateButtonState
if (dynamicModel.HasOperPrivilege())
{
Task<bool> validateAddTask = cachesDic.AddTask(this, "ValidateAdd", new Task<bool>(() =>
{
return ValidateCond(sysModel.AddCond, null, "P_SystemDllTab", "addCond");
}));
Task<bool> validateDelTask = cachesDic.AddTask(this, "ValidateDel", new Task<bool>(() =>
{
return ValidateCond(sysModel.DeleteCond, null, "P_SystemDllTab", "deleteCond");
}));
Task<bool> validateSaveTask = cachesDic.AddTask(this, "ValidateSave", new Task<bool>(() =>
{
return ValidateCond(sysModel.ModifyCond, null, "P_SystemDllTab", "modifyCond");
}));
Task<bool> validateImportTask = cachesDic.AddTask(this, "ValidateImport", new Task<bool>(() =>
{
return ValidateCond(sysModel.ImportCond, null, "P_SystemDllTab", "importCond");
}));
Task<bool> validateExportTask = cachesDic.AddTask(this, "ValidateExport", new Task<bool>(() =>
{
return ValidateCond(sysModel.ExportCond, null, "P_SystemDllTab", "exportCond");
}));
}
//Task<DataTable> searchSourceTable = cachesDic.AddTask(this, "SearchSourceTable", new Task<DataTable>(() =>
//{
// DataTable dataTable = null;
// MyControl searchObj = searchObjTask.Result;
// string sqlValue = sysModel.MenuSql;
// if (!string.IsNullOrWhiteSpace(sqlValue))
// {
// sqlValue = ReplaceHelper.ReplaceUserInfo(sqlValue);
// sqlValue = ReplaceHelper.ReplaceWhereCond(sqlValue);
// sqlValue = searchObj.SetSearchSqlValue(sqlValue, true, true);
// //sqlValue = MainImpl.GetDefaultValue(sqlValue, ParentKey, OtherParams);
// sqlValue = BaseImpl.GetDefaultValue(sqlValue);
// // 处理图片
// //if (gcMain != null && gcMain.ImageList != null && gcMain.ImageList.Count > 0)
// //{
// // foreach (string item in gcMain.ImageList)
// // {
// // sqlValue = sqlValue.Replace(string.Format(",{0}", item), "").Replace(string.Format("{0},", item), "");
// // }
// //}
// try
// {
// dataTable = SqlHelper.ExecuteDataTable(sqlValue);
// }
// catch (Exception ex)
// {
// Console.WriteLine(ex.Message);
// }
// dataTable = BaseImpl.GetDataTableResult(sqlValue);
// }
// return dataTable;
//}));
}
}
/// <summary>
/// <para>说明:设置扫码控件事件方法</para>
/// <para>创建人:王一帆</para>
/// <para>创建日期:2021-11-18 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void SetScanEvent()
{
if (this.SearchObj != null)
{
BaseUserControl[] controls = this.SearchObj.FindControls(ControlType.LabPcSacn);
controls = controls.Length > 0 ? controls : this.SearchObj.FindControls(ControlType.LabPcSacn);
if (controls != null && controls.Length > 0)
{
// 为第一个扫码控件绑定回车事件
this._scanEdit = controls[0] as LabelTextEdit;
if (this._scanEdit != null)
{
this._scanEdit.TabIndex = 1;
this._scanEdit.TextEdit.KeyDown += new KeyEventHandler(OnScanTextEditKeyDown);
this._scanEdit.Focus();
this._scanEdit.TextEdit.Focus();
}
}
}
}
#endregion
#region protected event
/// <summary>
/// <para>说明:扫码模块回车处理</para>
/// <para>创建人:王一帆</para>
/// <para>创建日期:2021-11-18 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="KeyEventArgs"/> instance containing the event data.</param>
protected void OnScanTextEditKeyDown(object sender, KeyEventArgs e)
{
try
{
if (e.KeyCode == Keys.Enter)
{
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:数据导入</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-09-13 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="ItemClickEventArgs"/> instance containing the event data.</param>
protected void OnImportItemClick(object sender, ItemClickEventArgs e)
{
try
{
this.ImportGridRecord();
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:数据导出</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-09-13 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="ItemClickEventArgs"/> instance containing the event data.</param>
protected void OnExportItemClick(object sender, ItemClickEventArgs e)
{
try
{
this.ExportGridRecord();
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:所有数据导出(包含明细)</para>
/// <para>创建人:王一帆</para>
/// <para>创建日期:2021-04-21 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="ItemClickEventArgs"/> instance containing the event data.</param>
protected void OnAllExportItemClick(object sender, ItemClickEventArgs e)
{
try
{
if (OnExportCallBack != null)
{
LogUtil.WriteDebug(this.Model.ModuleCode, "导出数据", this.SysModel.MenuText, "导出所有数据");
OnExportCallBack(this, e);
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:常规打印</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-09-13 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="ItemClickEventArgs"/> instance containing the event data.</param>
protected void OnNormalPrintItemClick(object sender, ItemClickEventArgs e)
{
try
{
this.PrintGridRecord();
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:帮助文档</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-09-13 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="ItemClickEventArgs"/> instance containing the event data.</param>
/// <exception cref="System.NotImplementedException"></exception>
protected void OnWordItemClick(object sender, ItemClickEventArgs e)
{
}
/// <summary>
/// <para>说明:模版打印</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-09-13 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="ItemClickEventArgs"/> instance containing the event data.</param>
protected void OnCustomPrintItemClick(object sender, ItemClickEventArgs e)
{
string printFile = e.Item.Tag + "";
string printPath = PubUtil.PrintFileAbsolutelyPath;
if (!File.Exists(printPath))
{
MessageUtil.Show(ResourceKeys.NotFoundPrintFile);
return;
}
DataRow dataRow = gcMain.GetViewFocusedDataRow();
if (dataRow == null)
{
MessageUtil.Show(ResourceKeys.SelectRowIsNull);
return;
}
try
{
string ids = string.Empty;
string tmpSql = ReplaceHelper.ReplaceUserInfo(this.SysModel.PrintSql);
string tmpSql1 = ReplaceHelper.ReplaceUserInfo(this.SysModel.PrintSql1);
string tmpSql2 = ReplaceHelper.ReplaceUserInfo(this.SysModel.PrintSql2);
tmpSql = this.SearchObj.ReplaceParentControlValue(tmpSql);
tmpSql1 = this.SearchObj.ReplaceParentControlValue(tmpSql1);
tmpSql2 = this.SearchObj.ReplaceParentControlValue(tmpSql2);
tmpSql = ReplaceHelper.ReplaceRowParam(dataRow, tmpSql);
tmpSql1 = ReplaceHelper.ReplaceRowParam(dataRow, tmpSql1);
tmpSql2 = ReplaceHelper.ReplaceRowParam(dataRow, tmpSql2);
if (this.LeftTreeViewEx != null || this.LeftGridEx != null)
{
string nodeKey = string.Empty;
if (this.LeftTreeViewEx != null)
{
nodeKey = this.LeftTreeViewEx.GetSelectNodeValue();
ids = LeftTreeViewEx.GetCheckValues();
}
if (this.LeftGridEx != null)
{
nodeKey = this.LeftGridEx.GetViewFocusedDataRow()[ParentKeyField] + "";
if (LeftGridEx is TreeGridControlEx) nodeKey = LeftGridEx.GetViewFocusedDataRow()[ParentKeyField] + "";
}
nodeKey = string.IsNullOrEmpty(ids) ? nodeKey : ids;
// select语句追加条件
tmpSql = ReplaceHelper.ReplaceTreeViewParentKeyCond(tmpSql, nodeKey);
tmpSql1 = ReplaceHelper.ReplaceTreeViewParentKeyCond(tmpSql1, nodeKey);
tmpSql2 = ReplaceHelper.ReplaceTreeViewParentKeyCond(tmpSql2, nodeKey);
}
//主Sql
string mainSql = string.Empty;
List<string> tmpSqls = new List<string>();
if (_printSaveParams != null && _printSaveParams.Count > 0)
{
_printSaveParams[5] = mainSql = ReplaceHelper.ReplaceRowParam(dataRow, _mainPrintSql);
_printSaveParams[3] = dataRow[_printSaveParams[2]] + "";
tmpSqls.Add(mainSql);
tmpSqls.Add(tmpSql1);
tmpSqls.AddRange(tmpSql2.Split(';').ToList());
}
if (printFile.Contains(PrintUtil.TemplateFlag))
{
PrintUtil.OnAfterPrint -= new EventHandler(OnReportPrintAfter);
PrintUtil.OnAfterPrint += new EventHandler(OnReportPrintAfter);
PrintUtil.FastReportPrint(tmpSqls, printFile, _isExcPrint);
}
else
{
DelphiHelper.LoadDelphiDll(printPath, printPath, printFile, tmpSql, tmpSql1, this.SysModel.PrintType, tmpSql2);
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
LogHelper.Instance.WriteError(ex);
}
}
/// <summary>
/// <para>说明:模版新版打印</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-25</para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="ItemClickEventArgs"/> instance containing the event data.</param>
protected void OnPrintItem70Click(object sender, ItemClickEventArgs e)
{
DataRow printRowItem = e.Item.Tag as DataRow;
string printFile = printRowItem["printFile"] + "";
string printName = printRowItem["printName"] + "";
string printParams = printRowItem["printParams"] + "";
string printType = printRowItem["printType"] + "";
string sourceType = printRowItem["sourceType"] + "";
string printPath = PubUtil.PrintFileAbsolutelyPath70;
string modid = printRowItem["modid"] + "";
if (!File.Exists(printPath))
{
MessageUtil.Show(ResourceKeys.NotFoundPrintFile);
return;
}
try
{
if (printFile.Contains(PrintUtil.TemplateFlag))
{
this.GetPrintOtherParam(modid);
DataRow dataRow = gcMain.GetViewFocusedDataRow();
string ids = string.Empty;
string tmpSql = printRowItem["printSQL"] + "";
string tmpSql1 = printRowItem["printSQL1"] + "";
string tmpSql2 = printRowItem["printSQL2"] + "";
tmpSql = this.SearchObj.ReplaceParentControlValue(tmpSql);
tmpSql1 = this.SearchObj.ReplaceParentControlValue(tmpSql1);
tmpSql2 = this.SearchObj.ReplaceParentControlValue(tmpSql2);
//目前固定替换焦点行数据,数据来源类型(sourceType)和Delphi里的用法有冲突,先不考虑
tmpSql = ReplaceHelper.ReplaceRowParam(dataRow, tmpSql);
tmpSql1 = ReplaceHelper.ReplaceRowParam(dataRow, tmpSql1);
tmpSql2 = ReplaceHelper.ReplaceRowParam(dataRow, tmpSql2);
//替换左侧数据
if (this.LeftTreeViewEx != null || this.LeftGridEx != null)
{
string nodeKey = string.Empty;
if (this.LeftTreeViewEx != null)
{
nodeKey = this.LeftTreeViewEx.GetSelectNodeValue();
ids = LeftTreeViewEx.GetCheckValues();
}
if (this.LeftGridEx != null)
{
nodeKey = this.LeftGridEx.GetViewFocusedDataRow()[ParentKeyField] + "";
if (LeftGridEx is TreeGridControlEx) nodeKey = LeftGridEx.GetViewFocusedDataRow()[ParentKeyField] + "";
}
nodeKey = string.IsNullOrEmpty(ids) ? nodeKey : ids;
// select语句追加条件
tmpSql = ReplaceHelper.ReplaceTreeViewParentKeyCond(tmpSql, nodeKey);
tmpSql1 = ReplaceHelper.ReplaceTreeViewParentKeyCond(tmpSql1, nodeKey);
tmpSql2 = ReplaceHelper.ReplaceTreeViewParentKeyCond(tmpSql2, nodeKey);
}
//主Sql
string mainSql = string.Empty;
List<string> tmpSqls = new List<string>();
tmpSqls.Add(tmpSql);
tmpSqls.Add(tmpSql1);
tmpSqls.AddRange(tmpSql2.Split(';').ToList());
if (_printSaveParams != null && _printSaveParams.Count > 0)
{
_printSaveParams[5] = tmpSql + tmpSql1 + tmpSql2;
_printSaveParams[3] = dataRow[_printSaveParams[2]] + "";
}
if (printFile.Contains(PrintUtil.TemplateFlag))
{
PrintUtil.OnAfterPrint -= new EventHandler(OnReportPrintAfter);
PrintUtil.OnAfterPrint += new EventHandler(OnReportPrintAfter);
PrintUtil.FastReportPrint(tmpSqls, printFile, _isExcPrint);
}
}
else
{
if ("2".Equals(sourceType) || "3".Equals(sourceType))
{
//int[] rows = this.gcMain.GridView.GetSelectedRows();
//List<DataRow> rowList = new List<DataRow>();
//for (int i = 0; i < rows.Length; i++)
//{
// rowList.Add(this.gcMain.GridView.GetDataRow(rows[i]));
//}
DataRow[] dataRows = this.gcMain.GetViewFocusedDataRows();
printParams = dataRows != null && dataRows.Length > 0 ? dataRows.CopyToDataTable().ToJsonArray() : "";
}
else
{
printParams = ReplaceHelper.ReplaceRowParam(this.gcMain.GetViewFocusedDataRow(), printParams);
}
DelphiHelper.LoadDelphiDll(printPath, printPath, this.Model.ModuleCode, printName, printParams, Convert.ToInt32(printType), "");
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
LogHelper.Instance.WriteError(ex);
}
}
/// <summary>
/// <para>说明:右键菜单执行后刷新数据,刷新规则按照上一次查询条件刷新</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-02 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void OnGridViewRightCallBack(object sender, EventArgs e)
{
try
{
if (DetailRightGridCallBack == null)//刷新所有页签本身会刷新自己
{
int oldRowHandle = gcMain.GridView.FocusedRowHandle;
if (!(gcMain is TreeGridControlEx) && oldRowHandle < 0) return;
DataTable dt = this.gcMain.GridView.GetGridViewFilteredAndSortedDataToDataTable();
if (gcMain is TreeGridControlEx) dt = (gcMain as TreeGridControlEx).GetGridViewDataSource();
if (dt == null || dt.Rows.Count == 0) return;
DataRow SelectTheLine = gcMain is TreeGridControlEx ? (gcMain as TreeGridControlEx).GetViewFocusedDataRow() : dt.Rows[oldRowHandle];
this.SearchObj.RememberRow = (this.SysModel.AccordingNameSelected == 0);
this.SearchObj.SearchLastGrid();
if (this.SysModel.AccordingNameSelected != 0)//根据主键刷新目标选中行
{
DataRow items = dt.Rows.Cast<DataRow>().FirstOrDefault(x => x[ParmaryKey].Equals(SelectTheLine[ParmaryKey]));
dt = this.gcMain.GridView.GetGridViewFilteredAndSortedDataToDataTable();
BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = dt;
int numberOfRows = bindingSource.Find(ParmaryKey, SelectTheLine[ParmaryKey].ToString());
this.gcMain.GridView.ClearSelection();
this.gcMain.GridView.FocusedRowHandle = numberOfRows;
this.gcMain.GridView.SelectRow(numberOfRows);
}
}
if (this.RightGridCallBack != null) this.RightGridCallBack(sender, e);
if (DetailRightGridCallBack != null) this.DetailRightGridCallBack(sender, e);
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:双击修改界面</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-09 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void OnGridViewDoubleClick(object sender, EventArgs e)
{
try
{
GridColumn gridColumn = this.gcMain.GridView.FocusedColumn;
if (gridColumn != null && !gridColumn.FieldName.Equals("DX$CheckboxSelectorColumn"))
{
//双击的是url图片框就不打开修改界面(会打开图片框)
GridColumnModel columnModel = gridColumn.Tag as GridColumnModel;
if (columnModel != null && columnModel.FieldType == ControlType.LabPicUrl) return;
}
if (!string.IsNullOrWhiteSpace(this.SysModel.PreSQL))//如果配置预新增界面则弹出
{
GridDetailModel gridDetailModel = this.GridControlObj.Tag as GridDetailModel;
DataRow parentDataRow = this.ParentGridEx != null ? this.ParentGridEx.GridView.GetFocusedDataRow() : null;
DataRow dataRow = this.gcMain.GridView.GetFocusedDataRow();
FrmAddDynamic frmAddDynamic = new FrmAddDynamic();
frmAddDynamic.Text = this.SysModel.MenuText;
frmAddDynamic.DynamicSql = this.SysModel.PreSQL;
frmAddDynamic.ModuleCode = this.SysModel.ModeCode;
frmAddDynamic.MaxHeight = this.SysModel.AddDynamicMaxHeight;
frmAddDynamic.UnionKey = gridDetailModel.UnionValue;
frmAddDynamic.UnionValue = parentDataRow != null && parentDataRow.Table.Columns.Contains(gridDetailModel.UnionParentField) ? parentDataRow[gridDetailModel.UnionParentField] + "" : "";
frmAddDynamic.keyValue = dataRow != null && dataRow.Table.Columns.Contains("keyvalue") ? dataRow["keyvalue"] + "" : "";
if (frmAddDynamic.ShowDialog() == DialogResult.OK)
{
this.SearchObj.SearchLastGrid();
if (OnSaveGridCallBack != null)
{
this.OnSaveGridCallBack(null, null);
}
}
}
else
{
this.UpdateGridRecord();
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:查询条件</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-08 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void OnFixSearchClick(object sender, EventArgs e)
{
}
/// <summary>
/// 外部触发新增
/// </summary>
public void ExternallyTriggeredAdd()
{
OnAddClick(null, null);
}
/// <summary>
/// <para>说明:添加数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-10-23 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void OnAddClick(object sender, EventArgs e)
{
try
{
this.AddGridRecord();
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:删除数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-10-23 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void OnDelClick(object sender, EventArgs e)
{
try
{
this.DeleteGridRecordByNew();
if (this.AfterDeleteGridCallBack != null) this.AfterDeleteGridCallBack(sender, e);
//if (this.SysModel.NewVer == 1)
//{
// this.DeleteGridRecordByNew();
// if (this.AfterDeleteGridCallBack != null) this.AfterDeleteGridCallBack(sender, e);
//}
//else
//{
// this.DeleteGridRecord();
// if (this.AfterDeleteGridCallBack != null) this.AfterDeleteGridCallBack(sender, e);
//}
if (OnSaveGridCallBack != null)
{
this.OnSaveGridCallBack(sender, e);
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:修改数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-31 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void OnUpdateClick(object sender, EventArgs e)
{
try
{
this.UpdateGridRecord();
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:保存表格数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-10-09 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void OnSaveClick(object sender, EventArgs e)
{
this.isSuccessfullySaved = false;
if (this.GridControlObj.CustomGroupBandEx != null || this.GridControlObj.CustomGroupTreeBandEx != null)//保存前若存在虚拟多表头则反写修改
{
this.GridControlObj.callbackUpdData();
}
int dataNumber = (this.GridControlObj.GridView.GetGridViewFilteredAndSortedDataToDataTable() as DataTable).Rows.Count;
for (int i = 0; i < dataNumber; i++)
{
if (this.GridControlObj.GridView.GetDataRow(i).GetColumnsInError().Count() > 0)
{
MessageUtil.Show("表格中数据不符合要求,保存失败!");
return;
}
}
if (this.SaveCondTab != null && this.SaveCondTab.Rows.Count > 0)
{
//获取新增和修改行
DataRow[] modifiedRows = this.gcMain is TreeGridControlEx ? ((gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable)
.Rows
.Cast<DataRow>()
.Where(x => x.RowState == DataRowState.Modified || x.RowState == DataRowState.Added)
.ToArray() : (gcMain.GridControl.DataSource as DataTable)
.Rows
.Cast<DataRow>()
.Where(x => x.RowState == DataRowState.Modified || x.RowState == DataRowState.Added)
.ToArray();
foreach (DataRow CondItem in SaveCondTab.Rows)
{
string condition = CondItem["condition"] + "";
if (!string.IsNullOrWhiteSpace(condition))
{
foreach (DataRow item in modifiedRows)
{
if (!ValidateCond(condition, item))
{
MessageUtil.Show(string.IsNullOrWhiteSpace(CondItem["hintmsg"] + "") ? "条件验证失败" : CondItem["hintmsg"] + "");
return;
}
}
}
}
}
if (this.gcMain is TreeGridControlEx)
{
bool isExec = true;
try
{
TreeGridControlEx treeList = gcMain as TreeGridControlEx;
if (this.GridControlObj != null && this.GridControlObj.AdapterObj != null)
{
if (ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.AfterModuleDataChange, this.Model.ModuleCode, 0))
{
goto IsApi;
}
if (this.SysModel.DefaultStoredProcedureSaves)
{
goto IsApi;
}
else
{
int result = this.GridControlObj.AdapterObj.Update(treeList.TreeListObj.DataSource as DataTable);
if (result > 0)
{
this.isSuccessfullySaved = true;
isExec = false;
MessageUtil.Show(ResourceKeys.SaveSuccess);
if (OnSaveGridCallBack != null)
{
this.OnSaveGridCallBack(sender, e);
}
}
}
}
}
catch (Exception)
{
}
IsApi: if (isExec)
{
this.SaveTreeRecord();
if (OnSaveGridCallBack != null)
{
this.OnSaveGridCallBack(sender, e);
}
if (this.SysModel.ModifyClose && this.OnCloseCallback != null)
{
this.OnCloseCallback(null, null);
}
}
}
else
{
if (this.gcMain.GridView.ValidateNullRequired(this._nullFields))
{
//判断重复验证列
if (this.gcMain.RepeatedVerificationNames.Count > 0 && this.gcMain.VerifyDuplicateColumns())
{
MessageUtil.Show("表格中数据内容重复,保存失败!");
return;
}
bool isExec = true;
try
{
if (this.GridControlObj != null && this.GridControlObj.AdapterObj != null && !this.GridControlObj.LastSearchSql.Contains("exec"))
{
if (ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.AfterModuleDataChange, this.Model.ModuleCode, 0))
{
goto IsApi;
}
if (this.SysModel.DefaultStoredProcedureSaves)
{
goto IsApi;
}
else
{
int result = this.GridControlObj.AdapterObj.Update(this.gcMain.GridControl.DataSource as DataTable);
if (result > 0)
{
this.isSuccessfullySaved = true;
isExec = false;
MessageUtil.Show(ResourceKeys.SaveSuccess);
if (this.SearchObj != null)
{
this.SearchObj.SearchLastGrid();
}
if (OnSaveGridCallBack != null)
{
this.OnSaveGridCallBack(sender, e);
}
}
}
}
}
catch (Exception ex)
{
LogUtil.WriteError("基础档案明细保存失败", ex);
}
IsApi: if (isExec)
{
this.SaveGridRecord();
if (OnSaveGridCallBack != null)
{
this.OnSaveGridCallBack(sender, e);
}
if (this.SysModel.ModifyClose && this.OnCloseCallback != null)
{
this.OnCloseCallback(null, null);
}
}
//保存后记录表名
//CacheRefresh.SetRefKeyDic(ERPInfo.Instance.PageControl.SelectedTabPage, SysModel.MenuTable);
}
}
//this.gcMain.gridControl.DataSourceTable().AcceptChanges();//保存后提交表格修改
}
/// <summary>
/// <para>说明:导入数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-31 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void OnImportClick(object sender, EventArgs e)
{
try
{
this.ImportGridRecord();
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:
/// 数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-31 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void OnExportClick(object sender, EventArgs e)
{
try
{
this.ExportGridRecord();
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:打印数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-31 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void OnPrintClick(object sender, EventArgs e)
{
try
{
this.PrintGridRecord();
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:附件管理</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-06-05 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void OnBtnAttachClick(object sender, EventArgs e)
{
try
{
string primaryValue = this.gcMain.GetViewFocusedDataRow()[_parmaryKey] + "";
if (string.IsNullOrWhiteSpace(primaryValue))
{
MessageUtil.Show(ResourceKeys.UnSaveData);
}
else
{
string url = string.Format("pages/PhotoView.html?left=1&username={0}&password={1}&id={2}&isview={3}&dllcoid=", ERPInfo.Instance.UserName, ERPInfo.Instance.Password, primaryValue, this.btnUpdate.Enabled ? "0" : "1");
// 固定传入参数(窗口标题、操作员ID、操作员名称、权限、模版编号)
string[] defaultArgs = string.Format(ModuleArgs.DefaultArgs, this.Model.FormText, ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, this.Model.Privilege, this.Model.ModuleCode).Split('~');
string[] menuArgs = SystemInfo.Instance.BsAttachFlag.Equals("1") ? new string[] { "", "", url } : new string[] { string.Format(ModuleArgs.PubPhotoViewArgs, primaryValue), "0", this.SysModel.MenuDirId + "", "" };
string[] args = defaultArgs.Concat(menuArgs).ToArray();
IForm form = FormHelper.LoadDllForm(SystemInfo.Instance.BsAttachFlag.Equals("1") ? ResourceDynamic.PubBrower : ResourceDynamic.PhotoView, args);
DialogResult result = form.SubForm.ShowDialog();
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:行选中发生变化,判断是否是否可用</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-06-10 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventArgs"/> instance containing the event data.</param>
void OnGridViewFocusedRowObjectChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventArgs e)
{
try
{
GridView gridView = sender as GridView;
DataRow rowItem = gridView.GetFocusedDataRow();
this.ValidateButtonState(rowItem);
this.RightButtonCondition(rowItem);
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// 搜索前执行高效验证
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <returns></returns>
//private bool OnPreSearchVerification(object sender, SearchArgs e)
//{
// if (SystemInfo.Instance.EfficientVerification)
// {
// //验证当前表
// if (this.gcMain.IsDataNotSaved())
// {
// bool SaveResults = this.SaveWhenSwitching();
// if (!SaveResults) return false;
// }
// //验证对应明细页签中的表格
// if (verifyDetailsTab != null)
// {
// this.verifyDetailsTab();
// }
// }
//}
/// <summary>
/// <para>说明:搜索之前</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-05-21 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
protected void OnSearchBeforeCallBack(object sender, SearchArgs e)
{
if (!SearchObj.VerifyNull())
{
e.Continue = false;
}
if (!string.IsNullOrEmpty(this.SysModel.CustomColumnSQL))
{
WaitForm.ShowForm();
try
{
//if (this.SysModel.RefreshTableColumn) this.gcMain.RefreshDataSource();
BaseImpl.ExecSqlValue(this.SearchObj.ReplaceControlValue(this.SysModel.CustomColumnSQL));
this._gridColumns = BaseModuleImpl.GetBaseGridColumns(this.Model.ModuleCode);
this._gridAllColumns = BaseModuleImpl.GetBaseGridAllColumns(this.Model.ModuleCode);
// 报表类型创建只读列
if (this.Model is DynamicReportModel)
{
this.gcMain.SetReadOnlyColumns(this._gridColumns, GridCustomColumnStruct.BaseMainGridView + this.SysModel.FormKey);
}
else
{
if (SysModel.CanEdit)
{
this.gcMain.SetEditColumns(this._gridColumns, GridCustomColumnStruct.BaseMainGridView + this.SysModel.FormKey);
}
else
{
this.gcMain.SetReadOnlyColumns(this._gridColumns, GridCustomColumnStruct.BaseMainGridView + this.SysModel.FormKey);
}
}
}
catch (Exception)
{
}
finally
{
WaitForm.HideForm();
}
}
if (!string.IsNullOrEmpty(this.SysModel.BeforeStored))
{
WaitForm.ShowForm();
try
{
string sql = this.SearchObj.ReplaceControlValue(this.SysModel.BeforeStored);
string result = SqlHelper.ExecuteScalar(sql) + "";
if (!string.IsNullOrEmpty(result)) MessageUtil.Show(result);
}
catch (Exception)
{
}
finally
{
WaitForm.HideForm();
}
}
}
/// <summary>
/// <para>说明:搜索之后</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-05-21 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
protected void OnSearchAfterCallBack(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.SysModel.AfterStored))
{
WaitForm.ShowForm();
try
{
string sql = this.SearchObj.ReplaceControlValue(this.SysModel.AfterStored);
string result = SqlHelper.ExecuteScalar(sql) + "";
if (!string.IsNullOrEmpty(result)) MessageUtil.Show(result);
}
catch (Exception)
{
}
finally
{
WaitForm.HideForm();
}
}
}
/// <summary>
/// <para>说明:表格编辑时,判断是否是否编辑</para>
/// <para>创建人:hongxing</para>
/// <para>创建日期:2019-01-21 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="CancelEventArgs"/> instance containing the event data.</param>
protected void OnGridViewShowingEditor(object sender, CancelEventArgs e)
{
try
{
GridView gridView = (GridView)sender;
GridColumn gridColumn = gridView.FocusedColumn;
GridColumnModel gridColumnModel = null;
if (gridColumn.Tag != null)
{
gridColumnModel = (GridColumnModel)gridColumn.Tag;
}
DataRow focusedRow = gridView.GetFocusedDataRow();
if (!gridView.FocusedColumn.FieldName.Equals("RightMenuBtnEdit"))//操作列可点击
{
e.Cancel = !btnSave.Enabled;
//如果是备注框,显示编辑框,但不能修改(编辑框弹出和取消编辑冲突,只能改变只读状态后,开始编辑)
if (gridColumnModel != null && gridColumnModel.FieldType == ControlType.LabMemoEdit)
{
RepositoryItemMemoExEdit memoEdit = gridColumn.ColumnEdit as RepositoryItemMemoExEdit;
if (e.Cancel)
{
//设置只读
memoEdit.ReadOnly = true;
//只读状态允许下拉列表
memoEdit.AllowDropDownWhenReadOnly = DevExpress.Utils.DefaultBoolean.True;
//允许编辑(编辑框弹出)
e.Cancel = false;
}
else
{
if (gridColumn.OptionsColumn.AllowEdit && memoEdit.ReadOnly)
{
memoEdit.ReadOnly = false;
}
}
}
}
if (!string.IsNullOrEmpty(this.SysModel.RowAllowEditCond) && focusedRow != null)
{
//e.Cancel = ReplaceHelper.EvalCond(ReplaceHelper.ReplaceRowParam(focusedRow, this.SysModel.RowAllowEditCond));
e.Cancel = !ValidateCond(this.SysModel.RowAllowEditCond, focusedRow, "P_SystemDllTab", "rowAllowEditCond");
}
else if (gridColumnModel != null && !string.IsNullOrEmpty(gridColumnModel.DisableCond))
{
//e.Cancel = !ReplaceHelper.EvalCond(ReplaceHelper.ReplaceRowParam(focusedRow, gridColumnModel.DisableCond));
e.Cancel = !ValidateCond(gridColumnModel.DisableCond, focusedRow);
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:打印完成后回调</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-07-05 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
protected void OnReportPrintAfter(object sender, EventArgs e)
{
try
{
if (_printSaveParams != null && _printSaveParams.Count > 0)
{
//打印完成后添加数据库
int result = BaseModuleImpl.SavePrintRecord(_printSaveParams[0], _printSaveParams[1], _printSaveParams[2], _printSaveParams[3], _printSaveParams[4]);
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:帮助文档</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期: </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void OnBtnHelpClick(object sender, EventArgs e)
{
try
{
WebBrowserUtil.StartWebBrowser(this.Model.ModuleCode, this.SysModel.MenuText);
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:刷新表格数据源</para>
/// <para>创建人:曹屹峰</para>
/// <para>创建日期: </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private void btnRefresh_Click(object sender, EventArgs e)
{
try
{
WaitForm.ShowForm();
//刷新当前表格
if (this.gcMain is TreeGridControlEx)
{
(this.gcMain as TreeGridControlEx).RefreshDataSource();
}
else
{
this.gcMain.RefreshDataSource();
}
//刷新子模块表格
if (AfterRefreshingCallBack != null) AfterRefreshingCallBack(sender, e);
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
finally
{
WaitForm.HideForm();
}
}
/// <summary>
/// 右键导出数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void OnTsmExportClick(object sender, EventArgs e)
{
try
{
this.ExportGridRecord();
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:添加空行</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期: </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void OnGridViewMouseDown(object sender, MouseEventArgs e)
{
try
{
int rowNumber = this.gcMain.GridView.FocusedRowHandle;
if (e.Button == System.Windows.Forms.MouseButtons.Left && rowNumber < 0)
{
AddGridViewRecord();
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:查询条件绑定完成查询数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期: </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void OnMainSearchDataSourceBindCallBack(object sender, EventArgs e)
{
try
{
if (!string.IsNullOrEmpty(this.SysModel.CustomColumnSQL))
{
BaseImpl.ExecSqlValue(this.SearchObj.ReplaceControlValue(this.SysModel.CustomColumnSQL));
}
if (!string.IsNullOrWhiteSpace(this.SearchControlSql))
{
DataRow rowItem = BaseImpl.GetDataRowResult(this.SearchControlSql);
this.SearchObj.SetAllControlValue(rowItem);
this.SearchObj.SyncLocalModel();
if (!string.IsNullOrEmpty(this.SysModel.SearchCondFormModuleCode) && StaticControl.ConditionsPanelDic.ContainsKey(this.SysModel.ModeCode))
{
ModuleConditionsPanelEx conditionsPanel = StaticControl.ConditionsPanelDic[this.SysModel.ModeCode];
this.SearchObj.MainGridEx.LastSearchSql = conditionsPanel.CondSql;
conditionsPanel.ReplaceParentControlObj(this.SearchObj);
if (!string.IsNullOrWhiteSpace(conditionsPanel.CondSql))
{
this.SearchObj.SearchLastGrid();
}
}
else
{
this.SearchObj.SearchGrid();
}
}
if (ParentControlObj != null)
{
foreach (ControlModel item in this.SearchObj.mControlList)
{
BaseUserControl baseUserControl = ParentControlObj.FindControl(item.FieldName);
if (baseUserControl != null)
{
this.SearchObj.SetControlValue(item, baseUserControl.EditText);
}
}
}
if (!IsDetail)
{
DynamicReportModel reportModel = this.Model as DynamicReportModel;
//if (this.SysModel.CsHasDefultSearch || (reportModel != null && reportModel.AutoQuery))
//{
// this.SearchObj.SearchGrid();
//}
if (!string.IsNullOrEmpty(this.SysModel.SearchCondFormModuleCode) && StaticControl.ConditionsPanelDic.ContainsKey(this.SysModel.ModeCode))
{
ModuleConditionsPanelEx conditionsPanel = StaticControl.ConditionsPanelDic[this.SysModel.ModeCode];
this.SearchObj.MainGridEx.LastSearchSql = conditionsPanel.CondSql;
conditionsPanel.ReplaceParentControlObj(this.SearchObj);
if (!string.IsNullOrWhiteSpace(conditionsPanel.CondSql))
{
this.SearchObj.SearchLastGrid();
}
}
else if (this.SysModel.CsHasDefultSearch || (reportModel != null && reportModel.AutoQuery))
{
if (!Model.DataCaches.GetValue(this, "SearchSourceTable", out DataTable sourceTable))
{
this.SearchObj.SearchGrid();
}
else
{
this.SearchObj.SearchGrid(sourceTable);
}
if (this.SysModel.RecordRowUponExit)
{
string Handle = IniHelper.Read(string.Format("RecordRowUponExit_{0}", this.Model.ModuleCode));
if (!string.IsNullOrWhiteSpace(Handle) && int.Parse(Handle) > 0)
{
this.gcMain.GridView.SelectRowHandler(int.Parse(Handle));
}
}
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:粘贴表格后更新树结构关联字段</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期: </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="rowItem">The row item.</param>
protected void OnGridViewParseGridDataCallBack(DataRow rowItem)
{
try
{
if (rowItem != null && rowItem.Table.Columns.Contains(ParentKeyField))
{
if (this.LeftTreeViewEx != null)
{
rowItem[ParentKeyField] = this.LeftTreeViewEx.GetSelectNodeValue();
}
if (this.LeftGridEx != null)
{
rowItem[ParentKeyField] = this.LeftGridEx.GetViewFocusedDataRow()[ParentKeyField] + "";
if (LeftGridEx is TreeGridControlEx) rowItem[ParentKeyField] = LeftGridEx.GetViewFocusedDataRow()[ParentKeyField] + "";
}
}
}
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 OnGridViewCustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo gridViewInfo = gcMain.GridView.GetViewInfo() as DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo;
DevExpress.XtraGrid.Views.Grid.ViewInfo.GridCellInfo cellInfo = gridViewInfo.GetGridCellInfo(gcMain.GridView.FocusedRowHandle, e.Column);
List<int> mergedRowHandle = new List<int>();
if (cellInfo != null && cellInfo.IsMerged && cellInfo.MergedCell != null)
{
DevExpress.XtraGrid.Views.Grid.ViewInfo.GridMergedCellInfo gridMergedCellInfo = cellInfo.MergedCell as DevExpress.XtraGrid.Views.Grid.ViewInfo.GridMergedCellInfo;
foreach (var item in gridMergedCellInfo.MergedCells)
{
mergedRowHandle.Add(item.RowHandle);
}
}
if (this.SysModel.SelectDisplayColumn.Split(',').Contains(e.Column.FieldName) && (e.RowHandle != gcMain.GridView.FocusedRowHandle && !mergedRowHandle.Contains(e.RowHandle)))
{
e.Cache.FillRectangle(ColorTranslator.FromHtml(SystemInfo.Instance.SelectRowBackColor), e.Bounds);
e.Handled = true;
}
}
/// <summary>
/// <para>说明:右键列调用dll</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期: </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="rowItem">The row item.</param>
protected void OnGridColumnCallDLL(string type)
{
if (type.Equals("1"))
{
// 固定传入参数(窗口标题、操作员ID、操作员名称、权限、模版编号)
string[] defaultArgs = string.Format(ModuleArgs.DefaultArgs, this.Model.FormText, this.Model.UserId, this.Model.UserName, this.Model.Privilege, "GrouP001").Split('~');
string[] menuArgs = new string[] { "", "GrouP001", "", "", "" };
string[] args = defaultArgs.Concat(menuArgs).ToArray();
IForm form = FormHelper.LoadDllForm(ResourceDynamic.PubModuleDetail, args);
DialogResult result = form.SubForm.ShowDialog();
}
else
{
string url = string.Format("/Lserp_v8/app.html?dll=Lskj.pubmoduledetail.dll&dllcoid={0}&username={1}&password={2}", "GrouP001", ERPInfo.Instance.UserName, ERPInfo.Instance.Password);
// 固定传入参数(窗口标题、操作员ID、操作员名称、权限、模版编号)
string[] defaultArgs = string.Format(ModuleArgs.DefaultArgs, this.Model.FormText, this.Model.UserId, this.Model.UserName, this.Model.Privilege, "").Split('~');
string[] menuArgs = new string[] { "", "", url };
string[] args = defaultArgs.Concat(menuArgs).ToArray();
IForm form = FormHelper.LoadDllForm(ResourceDynamic.PubBrower, args);
DialogResult result = form.SubForm.ShowDialog();
}
}
/// <summary>
/// 重新计算右上角按钮坐标
/// </summary>
private void CalculateCoordinates()
{
List<SimpleButton> buttons = new List<SimpleButton>();//没有隐藏的按钮集合
//刷新按钮
//刷新按钮
if (SystemInfo.Instance.FoundationHideTableRefresh)
{
this.btnRefresh.Visible = false;
pl_top_right.Width = pl_top_right.Width - this.btnRefresh.Width;
}
else
{
buttons.Add(this.btnRefresh);
}
//帮助文档按钮
if (SystemInfo.Instance.HideHelpDocument)
{
this.btnHelp.Visible = false;
pl_top_right.Width = pl_top_right.Width - this.btnHelp.Width;
}
else
{
buttons.Add(this.btnHelp);
}
//打印按钮
if (this.SysModel.HiddenPrint)
{
this.ddbPrint.Visible = false;
pl_top_right.Width = pl_top_right.Width - this.ddbPrint.Width;
}
else
{
buttons.Add(this.ddbPrint);
}
//常用操作按钮
buttons.Add(this.ddbOper);
//附件管理按钮
if (this.SysModel.AttachReveal)
{
buttons.Add(this.btnAttach);
}
else
{
pl_top_right.Width = pl_top_right.Width - this.btnAttach.Width;
}
//从最后开始计算
int x = 10;
if (buttons.Count != 5)
{
foreach (SimpleButton item in buttons)
{
item.Location = new Point(pl_top_right.Width - x - item.Width, 4);
x += item.Width + 6;
}
}
}
/// <summary>
/// 设置上方按钮形式的右键
/// </summary>
private void InitializeUpperRightMenu()
{
if (ButtonModeRightMenus.Count > 0)
{
this.pl_top_RightMenus.Visible = true;
List<SimpleButton> buttons = new List<SimpleButton>();
//条件左侧的4个按钮
if (this.SysModel.AttachReveal) buttons.Add(this.btnAttach);
buttons.Add(this.ddbOper);
if (!this.SysModel.HiddenPrint) buttons.Add(this.ddbPrint);
if (!SystemInfo.Instance.HideHelpDocument) buttons.Add(this.btnHelp);
buttons.Add(this.btnRefresh);
int x = 5;
int y = 4;
foreach (SimpleButton item in buttons)
{
item.Parent = this.pl_top_RightMenus;
item.Location = new Point(x, 4);
x += 80;
}
foreach (DataRow item in ButtonModeRightMenus)
{
GridRightMenuModel menuModel = new GridRightMenuModel(item);
SimpleButton button = new SimpleButton();
button.Font = new Font("宋体", 9);
button.Text = menuModel.MenuName;
button.Height = 24;
//按钮最小大小
button.MinimumSize = new Size(75, 24);
//根据名字和字体设置宽度
Size size = TextRenderer.MeasureText(button.Text, button.Font);
button.Width = size.Width;
button.Tag = menuModel;
button.Click += new EventHandler(OnModuleClick);
button.Parent = this.pl_top_RightMenus;
button.Location = new Point(x, 4);
RightButtons.Add(button);
x += button.Width + 5;
}
}
}
/// <summary>
/// 判断右键按钮
/// </summary>
private void RightButtonCondition(DataRow rowItem)
{
if (rowItem == null) return;
//判断 mrp按钮对象
if (this.SearchObj.mrpBtnDic.Count > 0)
{
foreach (SimpleButton toolButton in this.SearchObj.mrpBtnDic.Values)
{
GridRightMenuModel model = toolButton.Tag as GridRightMenuModel;
if (model == null) continue;
if (model.PrivilegeOper.Length > 1 && !model.PrivilegeOper.Contains(ERPInfo.Instance.UserName + ","))
{
toolButton.Enabled = false;
}
else
{
if (!string.IsNullOrWhiteSpace(model.MenuCond))
{
try
{
string cond = string.Empty;
cond = ReplaceHelper.ReplaceRowParam(rowItem, model.MenuCond);
if (this.gcMain.GridView != null)
{
GridCell[] cells = this.gcMain.GridView.GetSelectedCells();
if (cells != null && cells.Length > 0 && cond.Contains("{COLUMN_"))
{
GridCell cell = cells[0];
DataRow focusedRow = this.gcMain.GridView.GetFocusedDataRow();
string colValue = focusedRow == null || !focusedRow.Table.Columns.Contains(cell.Column.Name) ? "" : focusedRow[cell.Column.Name] + "";
cond = cond.ReplaceColumnParam(cell.Column.Name, cell.Column.Caption, colValue);
}
}
toolButton.Enabled = ReplaceHelper.EvalCond(cond);
}
catch (Exception ex)
{
}
}
}
}
}
// 判断顶部右键菜单是否可用
if (RightButtons.Count > 0)
{
foreach (SimpleButton toolButton in RightButtons)
{
DataRow dr = toolButton.Tag as DataRow;
GridRightMenuModel model = new GridRightMenuModel(dr);
if (model == null) continue;
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)
{
}
}
}
}
}
//辅助功能按钮
foreach (SimpleButton item in itemCommonList)
{
if (item.Visible == true && item.Tag is DataRow rightRow)
{
GridRightMenuModel model = new GridRightMenuModel(rightRow);
if (!string.IsNullOrEmpty(model.MenuCond))
{
item.Enabled = ValidateCond(model.MenuCond, rowItem);
}
}
}
}
/// <summary>
/// 按钮形式的右键点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void OnModuleClick(object sender, EventArgs e)
{
try
{
//WaitForm.ShowForm();
SimpleButton button = sender as SimpleButton;
if (button != null)
{
if (button.Tag is GridRightMenuModel)
{
DataRow rowItem = this.gcMain.GridView.GetFocusedDataRow();
GridRightMenuModel model = button.Tag as GridRightMenuModel;
if (rowItem == null && !model.isStartRun)
{
MessageUtil.Show(ResourceKeys.SelectRowIsNull);
return;
}
BaseRightMenu menu = new BaseRightMenu();
menu.Model = this.Model;
if (menu.ExecRightMenu(model, new DataRow[] { rowItem }) && model.Refresh)
{
this.OnGridViewRightCallBack(null, null);
}
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
finally
{
//WaitForm.HideForm();
}
}
/// <summary>
/// 表格键盘事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnGcMain_KeyDown(object sender, KeyEventArgs e)
{
try
{
//点击Tab键时,如果是最后一行,最后一列,就新增一行
if (e.KeyCode == Keys.Tab && SystemInfo.Instance.TabAddLine)
{
if (this.btnAdd.Enabled)
{
int focusedRowHandle = this.gcMain.GridView.FocusedRowHandle;
GridColumn[] Columns = this.gcMain.GridView.GetSelectedCells(focusedRowHandle);//当前选中的单元格
//判断是否为最后一行,最后一列
if (Columns.Length > 0 && Columns[0].VisibleIndex == this.gcMain.GridView.Columns.Count - 1 && focusedRowHandle == this.gcMain.GridView.RowCount - 1)
{
this.AddGridViewRecord();
}
//判断表格是否为空
if (this.gcMain.GridView.RowCount == 0)
{
this.AddGridViewRecord();
}
}
}
if (e.KeyCode == Keys.Enter && this.SysModel.EnterToNextRow)
{
// 获取当前行和列
int currentRow = this.gcMain.GridView.FocusedRowHandle;
int currentColumn = this.gcMain.GridView.FocusedColumn.VisibleIndex;
//移动到下一行
int targetRow = currentRow + 1;
if (targetRow < this.gcMain.GridView.RowCount)
{
this.gcMain.GridView.FocusedRowHandle = targetRow;
this.gcMain.GridView.FocusedColumn = this.gcMain.GridView.VisibleColumns[currentColumn];
//gridView.MakeRowVisible(targetRow);
}
else
{
// 取消默认行为(避免在最后一行点击回车时向右移动)
e.SuppressKeyPress = true;
}
}
}
catch (Exception ex)
{
}
}
#endregion
/// <summary>
/// 切换时保存(作为明细页签被切换时)
/// </summary>
/// <returns></returns>
public bool SaveWhenSwitching()
{
this.SaveResults = false;
if (this.pl_buttom.Visible && this.btnSave.Visible && this.btnSave.Enabled)
{
this.OnSaveClick(null, null);
}
return SaveResults;
}
public void SelectTheSpecifiedRow()
{
if (!string.IsNullOrWhiteSpace(this.TagName) && ParentGridEx != null && ParentGridEx.GridView.OptionsSelection.MultiSelect == true && GridControlObj.GridView.OptionsSelection.MultiSelect == true && this.ParentControlEx.DetailSelection.ContainsKey(this.TagName))
{
DataRow rowItem = this.ParentGridEx.GridView.GetFocusedDataRow();
Dictionary<DataRow, string> dictionary = this.ParentControlEx.DetailSelection[this.TagName];
if (dictionary.ContainsKey(rowItem))
{
DataTable dataTable = GridControlObj.GridControl.DataSource as DataTable;
string value = dictionary[rowItem];
for (int rowHandle = 0; rowHandle < GridControlObj.GridView.RowCount; rowHandle++)
{
string cellValue = GridControlObj.GridView.GetRowCellValue(rowHandle, ParmaryKey) + "";
if (value.Split(',').Contains(cellValue))
{
GridControlObj.GridView.SelectRow(rowHandle); // 勾选
}
}
}
}
}
/// <summary>
/// 设置动态列提示信息
/// </summary>
/// <param name="ColumnName"></param>
public void SetDisplayColumns(string text)
{
if (!this.SysModel.SearchEnable)
{
PromptBox.EditText = text;
// 获取文档对象
Document document = this.PromptBox.TextEdit.Document;
document.BeginUpdate();
try
{
// 获取段落属性并设置行间距
ParagraphProperties pp = document.BeginUpdateParagraphs(document.Range);
// 设置行间距为1.2倍
pp.LineSpacingType = ParagraphLineSpacing.Multiple;
pp.LineSpacingMultiplier = 1.2f;
document.EndUpdateParagraphs(pp);
}
finally
{
document.EndUpdate();
}
//前4行高度
//int textHeight = (int)Math.Round(this.GetFirstThreeLinesHeight(PromptBox.TextEdit)*1.2) +20;
//if (textHeight > this.TopHeight)
//{
// this.pl_top.Height = textHeight;
//}
//else
//{
// this.pl_top.Height = this.TopHeight;
//}
}
}
/// <summary>
/// <para>说明:设置分割条位置</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-02-01 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void OnSplitterMoved(object sender, EventArgs e)
{
try
{
if (this.Model != null)
{
IniHelper.Write(string.Format("base_grid_height_{0}", this.Model.ModuleCode), this.scc_container.SplitterPosition + "");
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:设置分割条位置</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-02-01 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
public void InitlizeSpiltLocation()
{
try
{
string htight = IniHelper.Read(string.Format("base_grid_height_{0}", this.Model.ModuleCode));
if (!string.IsNullOrEmpty(htight))
{
this.scc_container.SplitterPosition = Convert.ToInt32(htight);
}
else
{
this.scc_container.SplitterPosition = 250;
}
}
catch (Exception ex)
{
LogHelper.Instance.WriteError(ex);
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
public int GetFirstThreeLinesHeight(RichEditControl richEdit)
{
if (string.IsNullOrEmpty(richEdit.Text)) return 0;
// 获取字体和最大宽度
Document document = richEdit.Document;
Font font = richEdit.Font;
int maxWidth = richEdit.ClientSize.Width - richEdit.Padding.Horizontal;
// 获取前3行文本
string[] lines = richEdit.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
int lineCount = Math.Min(4, lines.Length);
string firstThreeLines = string.Join(Environment.NewLine, lines.Take(lineCount));
// 创建StringFormat
StringFormat format = new StringFormat(StringFormat.GenericTypographic);
format.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
// 测量文本高度
using (Graphics g = richEdit.CreateGraphics())
{
SizeF textSize = g.MeasureString(
firstThreeLines,
font,
maxWidth,
format
);
return (int)Math.Ceiling(textSize.Height);
}
}
/// <summary>
/// 新增行,并替换指定字段值
/// </summary>
/// <param name="FieldName"></param>
/// <param name="list"></param>
public void AddGridRows(string FieldName, List<string> list)
{
if (string.IsNullOrWhiteSpace(this.SysModel.MenuAddName))
{
DataTable dt = this.gcMain.GridControl.DataSource as DataTable;
if (dt == null)
{
MessageUtil.Show("请查询后添加!");
return;
}
if (!SysModel.CanEdit)
{
MessageUtil.Show("表格不可编辑,增加失败");
return;
}
if (!(dt.Columns.Contains(ERPInfo.Instance.isAddRows)))
{
dt.Columns.Add(ERPInfo.Instance.isAddRows, typeof(String));
}
try
{
foreach (string item in list)
{
this.AddGridViewRecord();
int lastRowHandle = gcMain.GridView.GetRowHandle(gcMain.GridView.DataRowCount - 1);
if (gcMain.GridView.IsValidRowHandle(lastRowHandle))
{
gcMain.GridView.SetRowCellValue(lastRowHandle, FieldName, item);
gcMain.GridView.RefreshRow(lastRowHandle);
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
}
}
}