/******************************
* 说明:添加、修改界面模版
* 创建人:龚宇超
* 创建日期:2017-11-03
* 修改人:
* 修改日期:
* 修改备注:
* 版本: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.XtraBars;
using Lskj.Business.Impl;
using Lskj.Control.Model;
using Lskj.Model;
using Lskj.Control;
using Lskj.Data;
using Lskj.Util;
using System.IO;
using Lskj.Business;
using DevExpress.XtraEditors;
using System.Timers;
using System.Threading;
using System.Runtime.InteropServices;
using DevExpress.XtraTab;
using Lskj.Core;
using System.Diagnostics;
using System.Text.RegularExpressions;
using Lskj.Data.Api.BLL;
using Lskj.Control.BrowserSetting;
using System.Net;
using Newtonsoft.Json.Linq;
using System.Collections;
using Newtonsoft.Json;
using System.Web;
namespace Lskj.Control
{
///
/// 添加、修改界面模版
///
public partial class ModulePanelEx : UserControl
{
private readonly AltButtonShortcutManager mAltButtonShortcuts =
new AltButtonShortcutManager();
public LabelTextEdit ScanEdit { get { return this._scanEdit; } }
#region private property
///
/// 是否直接打印
///
private bool _isExcPrint;
///
/// 左侧树、表格配置字段
///
private string _leftField;
///
/// 主打印Sql
///
private string _mainPrintSql;
///
/// 打印主sql中关联打印次数返回条件
///
private string _printModeCond;
private Thread IDCardThread = null;
///
/// 打印完成后添加数据用到的参数
///
private List _printSaveParams;
///
/// 当前操作的ImageEdit
///
private LabelImageEdit _imageEdit;
///
/// 扫码控件
///
private LabelTextEdit _scanEdit;
///
/// 控件数据源
///
private DataTable _controlTable;
///
/// 清除页面、复制新增、附件管理、常规打印
///
//BarButtonItem bbi_clear, bbi_copy;
#endregion
#region public property
///
/// 底部操作控件面板
///
public TabControlEx TcButtom { get { return tcButtom; } }
///
/// 底部操作控件面板
///
public SplitContainerControl SplitContainerControl { get { return scc_container; } }
///
/// 下方显示的明细数据
///
public DataRow[] DetailsData;
///
/// 是否是新增保存
///
public bool SavaState;
///
/// 是否为身份证阅读器
///
public bool IsCard;
///
/// 控件高度
///
/// The height of the control.
public int ControlHeight { get; private set; }
///
/// 按钮是否可操作
///
public string IsView;
///
/// 主键Key
///
public string PrimaryKey;
///
/// 主键值
///
public string PrimaryValue;
///
/// 分类编号
///
/// The parent key.
public string ParentKey
{
get { return this.lteSpeciesNo.TextEdit.EditValue + ""; }
set { this.lteSpeciesNo.TextEdit.Text = value; }
}
///
/// 分类名称
///
/// The parent value.
public string ParentValue
{
get { return this.lteSpeciesName.TextEdit.EditValue + ""; }
set { this.lteSpeciesName.TextEdit.Text = value; }
}
///
/// 外面表格的搜索条件
///
public string SearchObject;
///
/// 关联模块Key
///
public string UnionKey;
///
/// 关联模块值
///
public string UnionValue;
///
/// 控件赋值sql
///
public string ControlSql;
///
/// 系统模块实体对象
///
/// The system model.
public ModuleModel SysModel { get; private set; }
///
/// 调用动态链接库默认传递参数
///
public DynamicModel Model { get; private set; }
///
/// 控件对象
///
public MyControl ControlObj { get; private set; }
///
/// 顶部操作按钮
///
/// The species panel control object.
public PanelControl SpeciesPanelControlObj { get { return pl_main_top; } }
///
/// 底部操作控件面板
///
/// The panel control object.
public PanelControl OperatePanelControlObj { get { return pl_buttom; } }
///
/// 动态控件加载面板
///
/// The panel control object.
public XtraScrollableControl plMainControlObj { get { return pl_main; } }
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool ShowScrollBar(IntPtr hWnd, int wBar, bool bShow);
private enum ScrollBarDirection { SB_HORZ = 0, SB_VERT = 1, SB_CTL = 2, SB_BOTH = 3 }
#endregion
#region public event
///
/// Occurs when [on add record call back].
///
public event EventHandler OnAddRecordCallBack;
///
/// Occurs when [on apply record call back].
///
public event EventHandler OnApplyRecordCallBack;
///
/// Occurs when [on clear call back].
///
public event EventHandler OnClearCallBack;
///
/// Occurs when [on copy record call back].
///
public event EventHandler OnCopyRecordCallBack;
///
/// Occurs when [on print call back].
///
public event EventHandler OnPrintCallBack;
///
/// Occurs when [on close callback].
///
public event EventHandler OnCloseCallback;
#endregion
public ModulePanelEx()
{
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.Selectable | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true);
InitializeComponent();
InitializeAltButtonShortcuts();
this.scc_container.PanelVisibility = SplitPanelVisibility.Panel1;
this.simpleButton1.Click += simpleButton1_Click;
this.btnClear.Click += OnBtnClearClick;
this.btnCopyNew.Click += OnBtnCopyNewClick;
this.btnAdd.Click += OnAddClick;
this.btnUpdate.Click += OnUpdateClick;
this.btnApply.Click += OnApplyClick;
this.btnAttach.Click += OnBtnAttachClick;
this.btnClose.Click += OnCloseClick;
this.BtnMesSave.Click += OnMesSaveClick;
this.BtnMesClose.Click += OnBtnMesCloseClick;
}
private void InitializeAltButtonShortcuts()
{
mAltButtonShortcuts.Register(btnAttach, Keys.F);
mAltButtonShortcuts.Register(btnUpdate, Keys.E);
mAltButtonShortcuts.Register(btnApply, Keys.R);
mAltButtonShortcuts.Register(btnAdd, Keys.A);
mAltButtonShortcuts.Register(btnClose, Keys.C);
}
protected override bool ProcessCmdKey(
ref System.Windows.Forms.Message msg, Keys keyData)
{
return mAltButtonShortcuts.ProcessKey(keyData) ||
base.ProcessCmdKey(ref msg, keyData);
}
#region private method
///
/// 说明:控制滚动条是否存在横向的
/// 创建人:王一帆
/// 创建日期:2021-03-19
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
//protected override void WndProc(ref System.Windows.Forms.Message m)
//{
// try
// {
// ShowScrollBar(this.panel1.Handle, (int)ScrollBarDirection.SB_HORZ, false); base.WndProc(ref m);
// }
// catch (Exception)
// {
// }
//}
///
/// 说明:初始化常用操作、打印
/// 创建人:龚宇超
/// 创建日期:2017-11-03
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
private void InitializeCommonOperation()
{
// 常用操作
//bbi_clear = new BarButtonItem();
//bbi_clear.Caption = "清除页面";
//bbi_clear.ItemClick += new ItemClickEventHandler(OnClearItemClick);
//bbi_copy = new BarButtonItem();
//bbi_copy.Caption = "复制新增";
//bbi_copy.ItemClick += new ItemClickEventHandler(OnCopyItemClick);
//bbi_attach = new BarButtonItem();
//bbi_attach.Caption = "附件管理";
//bbi_attach.Tag = "附件管理";
//bbi_attach.ItemClick += new ItemClickEventHandler(OnAttachItemClick);
//bbi_print = new BarButtonItem();
//bbi_print.Caption = "常规打印";
//bbi_print.ItemClick += new ItemClickEventHandler(bbi_print_ItemClick);
//pm_oper.AddItem(bbi_clear);
//pm_oper.AddItem(bbi_copy);
//pm_oper.AddItem(bbi_attach);
//pm_oper.AddItem(bbi_print);
// 常用打印
//if (!string.IsNullOrEmpty(this._printFile))
//{
// String[] strs = this._printFile.Split('|');
// for (int i = 0; i < strs.Length; i++)
// {
// BarButtonItem bbi = new BarButtonItem();
// int index = i + 1;
// bbi.Caption = strs[i].Replace(".rmf", "");
// bbi.Tag = strs[i];
// bbi.ItemClick += new ItemClickEventHandler(bbi_ItemClick);
// pm_print.AddItem(bbi);
// }
//}
}
///
/// 说明:初始化按钮
/// 创建人:龚宇超
/// 创建日期:2017-11-08
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
private void InitializeButton()
{
// 清除按钮是否可用
btnClear.Enabled = this.SysModel.ClearAllEnable;
// 修改状态时、有权限时 可用
btnCopyNew.Enabled = btnUpdate.Enabled = !string.IsNullOrWhiteSpace(this.PrimaryValue) && "0".Equals(IsView);
// 配置按钮可用 显示
btnCopyNew.Enabled = this.SysModel.AddEnable && this.SysModel.AddCopyEnabled;
// 配置有目录结构(显示)、修改状态(可用)
if (this.SysModel.HideAttachBtn)
{
btnAttach.Visible = false;
}
else
{
btnAttach.Visible = this.SysModel.MenuDirId > 0;
}
btnAttach.Enabled = !string.IsNullOrWhiteSpace(this.PrimaryValue);
int AttachCount = AttachImpl.GetFileCount(this.SysModel.MenuDirId + "", this.PrimaryValue);
this.btnAttach.Text = AttachCount > 0 ? "附件管理" + "(" + AttachCount + ")" : this.btnAttach.Text;
// 配置有打印模版(显示)、修改状态时(可用),已调整为支持多个打印文件
//bbi_print.Visibility = !string.IsNullOrWhiteSpace(this.SysModel.PrintFile) ? BarItemVisibility.Always : BarItemVisibility.Never;
//bbi_print.Enabled = !string.IsNullOrWhiteSpace(this.PrimaryValue);
// 添加状态时、有权限时 可用
btnAdd.Enabled = string.IsNullOrWhiteSpace(this.PrimaryValue) && "0".Equals(IsView);
// 配置有流转步骤(显示)、配置按钮可用、有权限时 可用
btnApply.Enabled = (this.SysModel.SaveApplyEnable || !string.IsNullOrWhiteSpace(this.PrimaryValue)) && "0".Equals(IsView) && BaseModuleImpl.HasStepFlow(this.Model.ModuleCode);
// 常用打印
this.InitializePrintFile();
// 常用工具
this.InitializeCommonTool();
if (!BaseModuleImpl.HasStepFlow(this.Model.ModuleCode)|| this.SysModel.HideReviewBut)
{
this.btnApply.Visible = false;
this.btnAdd.Location = this.btnUpdate.Location;
this.btnUpdate.Location = this.btnApply.Location;
}
// 设置文本
btnAdd.Text = !string.IsNullOrWhiteSpace(this.SysModel.AddCaption) ? this.SysModel.AddCaption : "添加保存(A)";
btnUpdate.Text = !string.IsNullOrWhiteSpace(this.SysModel.ModifyCaption) ? this.SysModel.ModifyCaption : "修改保存(E)";
btnApply.Text = !string.IsNullOrWhiteSpace(this.SysModel.ApplyCaption) ? this.SysModel.ApplyCaption : "提交审核(R)";
//隐藏帮助文档按钮
if (SystemInfo.Instance.HideHelpDocument) this.simpleButton1.Visible = false;
}
///
/// 说明:初始化打印模版
/// 创建人:龚宇超
/// 创建日期:2018-04-08
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
private void InitializePrintFile()
{
DataTable printTable = BaseImpl.GetPrintTemp70(this.Model.ModuleCode);
if (printTable.Rows.Count > 0)
{
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
{
string[] files = this.SysModel.PrintFile.Split('|');
for (int i = 0; i < files.Length; i++)
{
string fileName = files[i];
if (!string.IsNullOrWhiteSpace(fileName))
{
BarButtonItem itemPrint = new BarButtonItem();
int index = i + 1;
itemPrint.Caption = files[i].Replace(".rmf", "").Replace(".frx", "");
itemPrint.Tag = files[i];
itemPrint.ItemClick += new ItemClickEventHandler(OnCustomPrintItemClick);
pm_print.AddItem(itemPrint);
}
}
}
ddb_print.Visible = !string.IsNullOrEmpty(this.SysModel.PrintFile) && printTable.Rows.Count == 0;
}
///
/// 说明:初始化常用工具
/// 创建人:龚宇超
/// 创建日期:2018-04-09
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
private void InitializeCommonTool()
{
if (!ddb_print.Visible)
this.ddb_common.Location = new Point(81, 0);
DataTable 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
{
if (panelControl1.Visible == false)
{
BarButtonItem nitemCommon = new BarButtonItem();
nitemCommon.Caption = item["menuname"] + "";
nitemCommon.Tag = item;
nitemCommon.ItemClick += new ItemClickEventHandler(OnCommonItemClick);
pm_common.AddItem(nitemCommon);
}
else
{
SimpleButton itemCommon = new SimpleButton();
//itemCommon.AutoSize = true;
itemCommon.Text = item["menuname"] + "";
itemCommon.Tag = item;
itemCommon.Size = new System.Drawing.Size(120, 49);
itemCommon.Font = new Font("微软雅黑", 12);
itemCommon.Click += new EventHandler(itemCommon_Click);
itemCommon.Location = new Point(x + 6, 6);
x += itemCommon.Width + 6;
panelControl1.Controls.Add(itemCommon);
i++;
}
}
}
this.ddb_common.Visible = tableCommon != null && tableCommon.Rows.Count > 0;
this.ddb_common.Click += Ddb_common_Click;
}
///
/// 判断常用工具中的条件
///
///
///
private void Ddb_common_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;
menuCond = this.ControlObj.ReplaceControlValue(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);
}
}
}
}
}
///
/// 说明:常用工具点击
/// 创建人:龚宇超
/// 创建日期:2017-11-27
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
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.ControlObj);
menu.Apply(rowItem);
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 说明:初始化身份证阅读器
/// 创建人:龚宇超
/// 创建日期:2018-05-31
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
private void InitializeIDCard()
{
try
{
this.IsCard = this.ControlObj != null && this.ControlObj.ControlModels.FirstOrDefault(x => x.Sign > 0) != null;
if (this.IsCard)
{
this.IDCardThread = new Thread(OnReadCard);
this.IDCardThread.IsBackground = true;
this.IDCardThread.Start();
}
}
catch (Exception ex)
{
LogUtil.WriteError(SysModel.MenuName + "初始化身份证阅读器出错", ex);
LogHelper.Instance.WriteLog(ex.StackTrace);
MessageUtil.Show(SysModel.MenuName + "初始化身份证阅读器出错" + "\n" + ex.Message);
}
}
///
/// 说明:设置修改数据
/// 创建人:龚宇超
/// 创建日期:2017-11-09
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
private void SetUpdateData(bool FirstLoading = true)
{
//外面表格搜索条件赋值
if (!string.IsNullOrWhiteSpace(SearchObject) && SavaState)
{
foreach (string item in SearchObject.Split('|'))
{
string name = item.Split('=')[0];
string value = item.Split('=')[1];
this.ControlObj.SetControlValue(name, value);
}
}
if (!string.IsNullOrWhiteSpace(this.PrimaryValue))
{
// 修改默认赋值
string sqlValue = ReplaceHelper.ReplaceWhereCond(this.SysModel.MenuSql);
sqlValue = string.Format("{0} AND {1}='{2}'", sqlValue, this.PrimaryKey, this.PrimaryValue);
DataTable tableResult = BaseImpl.GetDataTableResult(sqlValue);
if (tableResult != null && tableResult.Rows.Count > 0)
{
DataRow rowItem = tableResult.Rows[0];
this.ControlObj.CurrentData = rowItem;
this.SetSpecies(rowItem);
this.ControlObj.SetAllControlValue(rowItem);
// 同步本地数据,用于关闭时检查数据是否已修改.
this.ControlObj.SyncLocalModel();
}
}
if (!string.IsNullOrWhiteSpace(UnionKey) && !string.IsNullOrWhiteSpace(UnionValue))
{
this.ControlObj.SetControlValue(UnionKey, UnionValue);
}
//不如不是初始化时进入,就不加载配置数据源sql(添加或者修改后,执行赋值sql会导致保存的数据被覆盖)
if (!string.IsNullOrWhiteSpace(this.ControlSql) && FirstLoading)
{
DataRow rowItem = BaseImpl.GetDataRowResult(this.ControlSql);
this.ControlObj.CurrentData = rowItem;
this.ControlObj.SetAllControlValue(rowItem);
this.ControlObj.SyncLocalModel();
}
this.ControlObj.CanExecControl = true;
if (this.scc_container.PanelVisibility == SplitPanelVisibility.Both)
{
OnSelectedPageChanged(null, null);
}
}
///
/// 说明:设置图片事件
/// 创建人:龚宇超
/// 创建日期:2018-02-27
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
private void SetImageEvent(DataTable table)
{
if (table == null || table.Rows.Count == 0) return;
DataRow[] imageRows = table.Select("fieldTypeId=" + (int)ControlType.LabPicEx);
foreach (DataRow item in imageRows)
{
string fieldName = item["fieldName"] + "";
LabelImageEdit imageEdit = this.ControlObj.FindControl(fieldName) as LabelImageEdit;
if (imageEdit != null)
{
//imageEdit.UnionEvent += new LabelImageEdit.UnionEventHander(OnImageUnionEvent);
imageEdit.UploadEvent += new LabelImageEdit.UploadEventHander(OnImageUploadEvent);
imageEdit.DeleteEvent += new LabelImageEdit.DeleteEventHander(OnImageDeleteEvent);
//AttachHelper.OnUploadSuccess += new EventHandler(OnAttachUploadSuccess);
//AttachHelper.OnDownLoadSuccess += new EventHandler(OnAttachDownLoadSuccess);
}
}
}
///
/// 说明:设置扫码控件事件
/// 创建人:龚宇超
/// 创建日期:2018-05-25
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
private void SetScanEvent()
{
if (this.ControlObj != null)
{
BaseUserControl[] controls = this.ControlObj.FindControls(ControlType.LabPcSacn);
controls = controls.Length > 0 ? controls : this.ControlObj.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();
}
}
}
}
///
/// 说明:设置分类数据
/// 创建人:龚宇超
/// 创建日期:2017-11-09
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
private void SetSpecies(DataRow rowItem)
{
try
{
int menuType = this.SysModel.MenuType;
if (menuType == 1 || menuType == 2)
{
DataRow leftField = BaseModuleImpl.GetBaseLeftTreeField(this.Model.ModuleCode);
if (leftField != null)
{
string leftSpeciesNo = leftField["fieldsqlid"] + "";
string leftSpeciesName = leftField["fieldsqlname"] + "";
string leftSpeciesSql = ReplaceHelper.ReplaceWhereCond(leftField["fieldsql"] + "");
string parentKeyValue = rowItem.Table.Columns.Contains(leftSpeciesNo) && !string.IsNullOrWhiteSpace(leftSpeciesNo) ? rowItem[leftSpeciesNo] + "" : "";
string parentNameValue = string.Empty;
DataTable leftTable = BaseImpl.GetDataTableResult(leftSpeciesSql + string.Format(" and {0}='{1}'", leftSpeciesNo, parentKeyValue));
if (leftTable != null && leftTable.Rows.Count > 0)
{
parentNameValue = leftTable.Rows[0][leftSpeciesName] + "";
}
// 设置父节点相关数据
this.ControlObj.ParentKey = this.ParentKey = parentKeyValue;
this.ControlObj.ParentValue = this.ParentValue = parentNameValue;
}
}
}
catch (Exception ex)
{
LogHelper.Instance.WriteError(ex);
LogUtil.WriteError(SysModel.MenuName + "分类数据出错", ex);
MessageUtil.Show(SysModel.MenuName + "分类数据出错" + ex.Message);
}
}
///
/// 说明:设置按钮位置
/// 创建人:龚宇超
/// 创建日期:
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
private void SetControlLocation()
{
int left = 2, space = 2;
int width = this.pl_buttom.Width;
System.Windows.Forms.Control[] list = this.panelControl2.Controls.Cast().Where(x => x.Visible).OrderBy(y => y.TabIndex).ToArray();
foreach (var item in list)
{
item.Left = left + space;
left = item.Left + item.Width;
}
this.panelControl2.Width = left;
}
#endregion
#region public method
///
/// 说明:初始化模块
/// 创建人:龚宇超
/// 创建日期:2017-11-03
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The menu row.
public void InitializeControl(ModuleModel sysModel, DynamicModel dyncModel, bool IsAutoScroll = false)
{
try
{
if (sysModel != null && dyncModel != null)
{
this.SysModel = sysModel;
this.Model = dyncModel;
this._leftField = BaseModuleImpl.GetBaseLeftField(this.Model.ModuleCode);
this._controlTable = BaseModuleImpl.GetControlLocation(this.SysModel.FormKey, this.Model.ModuleCode);
this.lteOper.EditText = ERPInfo.Instance.UserName;
this.InitializeCommonOperation();
this.InitializeButton();
this.pl_main.Click += new EventHandler(OnMainClick);
this.ControlObj = new MyControl()
{
ParentKey = this.ParentKey,
ParentValue = this.ParentValue,
SystemModel = sysModel,
CanExecControl = string.IsNullOrEmpty(this.PrimaryValue),
PrimaryValue = this.PrimaryValue,
OtherParams = dyncModel.OtherParams(),
rightItemLinks = pm_common.ItemLinks,
popUpDyncModel = this.Model,
Model = this.Model
};
this.ControlObj.SaveCondTab= BaseModuleImpl.GetClientCond(this.Model.ModuleCode);
this.SetButtonPanelVisible("lskj.pubadd4.dll".Equals(this.SysModel.MenuAddName.ToLower()));
bool topVisible = false;
if ("lskj.pubadd.dll".Equals((this.SysModel.MenuAddName).ToLower()) || "lskj.pubadd2.dll".Equals((this.SysModel.MenuAddName).ToLower()))
{
topVisible = true;
}
this.SetTopPanelVisible(topVisible);
//this.ControlHeight = this.ControlObj.InitControl(this._controlTable, this.pl_main, BaseModuleImpl.GetAddGroupData(this.SysModel.FormKey));
//DataTable divider = BaseModuleImpl.GetDividerData(this.SysModel.FormKey);
this.ControlHeight = this.ControlObj.InitControl(this._controlTable, this.pl_main, BaseModuleImpl.GetAddGroupData(this.SysModel.FormKey), true);//divider
this.pl_main.AutoScroll = IsAutoScroll;
this.InitSpeciesBtn();
this.pl_main.HorizontalScroll.Visible = false;//设置禁止水平滚动条
if (!this.pl_buttom.Visible)
{
pl_main.Height += pl_buttom.Height;
}
if (!this.pl_main_top.Visible)
{
pl_main.Height += pl_main_top.Height;
}
this.ControlObj.OnDataSourceBindCallBack += new EventHandler(OnControlObjOnDataSourceBindCallBack);
this.SetScanEvent();
this.InitializeIDCard();
this.SetImageEvent(this._controlTable);
this.GetPrintOtherParam();
if (Model.HasReadPrivilege())
{
btnUpdate.Enabled = btnApply.Enabled = btnCopyNew.Enabled = BtnMesSave.Enabled = btnClear.Enabled = false;
}
// 重排按钮位置
this.SetControlLocation();
//设置下方页签
if (DetailsData != null && DetailsData.Length > 0)
{
this.CreateTabDetail();
this.tcButtom.TabControlObj.SelectedPageChanged += this.OnSelectedPageChanged;
this.tcButtom.TabControlObj.SelectedPageChanging += this.OnSelectedPageChanging;
this.scc_container.PanelVisibility = SplitPanelVisibility.Both;
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 切换选项卡
///
///
///
protected void OnSelectedPageChanging(object sender, TabPageChangingEventArgs e)
{
try
{
XtraTabPage page = e.Page;
if (page != null)
{
if (e.PrevPage == this.tcButtom.TabControlObj.TabPages[0] && string.IsNullOrEmpty(this.PrimaryValue))
{
MessageUtil.Show(ResourceKeys.BeforeSaveData);
e.Cancel = true;
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 说明:切换标签刷新主键值
/// 创建人:龚宇超
/// 创建日期:2018-04-09
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
private void OnSelectedPageChanged(object sender, TabPageChangedEventArgs e)
{
try
{
XtraTabPage tabPage = null;
if (e == null)
{
tabPage = this.tcButtom.TabControlObj.SelectedTabPage;
}
else
{
tabPage = e.Page;
}
//OperatePanelControlObj.Visible = true;
//if (tabPage.Tag is ModuleGridEx) OperatePanelControlObj.Visible = false;
//if (!(tabPage.Tag is GridDetailModel)) return;
//OperatePanelControlObj.Visible = false;
if (tabPage.Controls.Count == 0)
{
GridDetailModel detailModel = tabPage.Tag as GridDetailModel;
ModuleModel moduleModel = null;
DynamicAddModel addModel = new DynamicAddModel(new string[] {
detailModel.DetailName,
ERPInfo.Instance.UserId,
ERPInfo.Instance.UserName,
"1",detailModel.UnionModule,"","",""
});
if (detailModel.IsWebView)
{
// 加载网页
string url = detailModel.DetailSql.StartsWith("http") ? detailModel.DetailSql : SystemInfo.Instance.OAUrl + detailModel.DetailSql;
if (!string.IsNullOrWhiteSpace(this.ParentKey))
{
string codeSql = "select";
codeSql += string.Format(" '{0}' as {1}", this.PrimaryValue, this.PrimaryKey);
url = ReplaceHelper.ReplaceRowParam(BaseImpl.GetDataRowResult(codeSql), ReplaceHelper.ReplaceWhereCond(detailModel.DetailSql));
}
if (this.ControlObj.CurrentData != null) url = ReplaceHelper.ReplaceRowParam(this.ControlObj.CurrentData, url);
//url= System.Web.HttpUtility.UrlEncode(url);
if (SystemInfo.Instance.PrimitiveBrowser)
{
FrmMiniBlink webView = new FrmMiniBlink();
webView.IsDownVerify = true;
webView.Dock = DockStyle.Fill;
webView.Tag = detailModel;
tabPage.Tag = webView;
tabPage.Controls.Add(webView);
webView.LoadUrl(ReplaceHelper.ReplaceUserInfo(url));
}
else
{
FrmWebBrowser webView = new FrmWebBrowser();
webView.Dock = DockStyle.Fill;
webView.Tag = detailModel;
tabPage.Tag = webView;
tabPage.Controls.Add(webView);
webView.FrmLoad(ReplaceHelper.ReplaceUserInfo(url));
}
}
else if (detailModel.IsWebView2)
{
// 加载网页
string url = detailModel.DetailSql.StartsWith("http") ? detailModel.DetailSql : SystemInfo.Instance.OAUrl + detailModel.DetailSql;
//url= System.Web.HttpUtility.UrlEncode(url);
if (SystemInfo.Instance.PrimitiveBrowser)
{
FrmMiniBlink webView = new FrmMiniBlink();
webView.Dock = DockStyle.Fill;
webView.Tag = detailModel;
tabPage.Tag = webView;
tabPage.Controls.Add(webView);
webView.LoadUrl(ReplaceHelper.ReplaceUserInfo(url));
}
else
{
FrmWebBrowser2 webView = new FrmWebBrowser2();
webView.Dock = DockStyle.Fill;
webView.Tag = detailModel;
tabPage.Tag = webView;
tabPage.Controls.Add(webView);
webView.FrmLoad(ReplaceHelper.ReplaceUserInfo(url));
}
}
else if (detailModel.IsWebView3)
{
// 加载网页
string url = detailModel.DetailSql.StartsWith("http") ? detailModel.DetailSql : SystemInfo.Instance.OAUrl + detailModel.DetailSql;
//url= System.Web.HttpUtility.UrlEncode(url);
if (SystemInfo.Instance.PrimitiveBrowser)
{
FrmMiniBlink webView = new FrmMiniBlink();
webView.AllowDownload = false;
webView.Dock = DockStyle.Fill;
webView.Tag = detailModel;
tabPage.Tag = webView;
tabPage.Controls.Add(webView);
webView.LoadUrl(ReplaceHelper.ReplaceUserInfo(url));
}
else
{
FrmWebBrowser2 webView = new FrmWebBrowser2();
webView.Dock = DockStyle.Fill;
webView.Tag = detailModel;
webView.AllowDownload = false;
tabPage.Tag = webView;
tabPage.Controls.Add(webView);
webView.FrmLoad(ReplaceHelper.ReplaceUserInfo(url));
}
}
else if (string.IsNullOrEmpty(detailModel.UnionModule))
{
PanelControl plBottom = new PanelControl();
plBottom.Dock = DockStyle.Bottom;
plBottom.Visible = false;
PanelControl plMain = new PanelControl();
plMain.Dock = DockStyle.Fill;
GridControlEx gridEx = detailModel.AutoMultiHeader == 1 ? new BandedGridControlEx() : new GridControlEx();
gridEx.Dock = DockStyle.Fill;
gridEx.Tag = detailModel;
gridEx.Parent = plMain;
gridEx.Model = this.Model;
gridEx.SysModel = this.SysModel;
gridEx.SetReadOnlyColumns(detailModel.GridColumns, detailModel.GridCustomColumnKey);
gridEx.SetGridRightMenus(BaseModuleImpl.GetBaseGridRightMenus(detailModel.FormKey), this.Model);
gridEx.SetGridRowColors(BaseModuleImpl.GetBaseGridRowColors(detailModel.FormKey));
if (detailModel.IsCheck == 1)//加载复选框
{
GridDragGrid.GridAddCheckBox(gridEx.GridView);
}
// 加载配置查询条件
if (Model != null && Model.IsDetailSearch)
{
plBottom.Visible = true;
MyControl searchObj = new MyControl(detailModel.DetailSql, gridEx);
plBottom.Height = searchObj.InitSearchControl(BaseModuleImpl.GetCustomQueryFields(detailModel.FormKey), plBottom);
}
tabPage.Tag = gridEx;
tabPage.Controls.AddRange(new PanelControl[] { plBottom, plMain });
if (detailModel.AutoRefresh)
{
if (tabPage == this.tcButtom.TabControlObj.TabPages[0] && string.IsNullOrEmpty(this.PrimaryValue))
{
return;
}
if (!string.IsNullOrWhiteSpace(this.ParentKey))
{
string codeSql = "select";
codeSql += string.Format(" '{0}' as {1}", this.PrimaryValue, this.PrimaryKey);
gridEx.SetGridViewDataSource(SqlHelper.ExecuteDataTable(ReplaceHelper.ReplaceRowParam(BaseImpl.GetDataRowResult(codeSql), ReplaceHelper.ReplaceWhereCond(detailModel.DetailSql))));
}
else if (this.ControlObj.CurrentData != null)
{
gridEx.SetGridViewDataSource(SqlHelper.ExecuteDataTable(ReplaceHelper.ReplaceRowParam(this.ControlObj.CurrentData, ReplaceHelper.ReplaceWhereCond(detailModel.DetailSql))));
}
// 自动刷新
}
}
else
{
moduleModel = new ModuleModel(MainImpl.GetSystemdllTab(detailModel.UnionModule));
ModuleGridEx moduleGrid = new ModuleGridEx();
moduleGrid.IsDetail = true;
moduleGrid.Dock = DockStyle.Fill;
moduleGrid.Tag = detailModel;
moduleGrid.ParentKeyField = string.IsNullOrEmpty(detailModel.UnionParentField) ? SysModel.ParmaryKey : detailModel.UnionParentField;
//直接在控件数据源中取值,控件可能是禁显状态(没用控件获取不到值)
if (!string.IsNullOrWhiteSpace(moduleGrid.ParentKeyField) && this.ControlObj.CurrentData.Table.Columns.Contains(moduleGrid.ParentKeyField))
{
moduleGrid.ParentKeyValue = moduleGrid.UnionValue = this.ControlObj.CurrentData[moduleGrid.ParentKeyField] + "";
}
if (detailModel.AddHideBottomPanel || detailModel.HideBottomPanel || detailModel.Library.Equals("Lskj.Report.dll", StringComparison.OrdinalIgnoreCase))
{
moduleGrid.VisibleOperPanel = false;
}
//moduleGrid.ParentKeyValue = this.ModuleAddControl.ControlObj.GetControlValue(moduleGrid.ParentKeyField);
moduleGrid.DetailKeyField = detailModel.UnionValue;
moduleGrid.UnionKey = detailModel.UnionValue;
//moduleGrid.UnionValue = this.ModuleAddControl.ControlObj.GetControlValue(moduleGrid.ParentKeyField); //Model.ObjectId;
//moduleGrid.SearchControlSql = Model.ControlSql;
moduleGrid.InitializeControl(moduleModel, addModel);
moduleGrid.SearchObj.OnSearchBeforeCallBack += new SearchEventHandler(OnSearchBefore);
moduleGrid.SearchObj.OnSearchAfterCallBack += new EventHandler(OnSearchAfter);
Lskj.Control.Model.AutoSizeChange.ControllInitializeSize(moduleGrid);
tabPage.Controls.Add(moduleGrid);
tabPage.Tag = moduleGrid;
if (detailModel.AutoRefresh)
{
if (tabPage == this.tcButtom.TabControlObj.TabPages[0] && string.IsNullOrEmpty(this.PrimaryValue))
{
return;
}
moduleGrid.SearchObj.OnDataSourceBindCallBack += new EventHandler(OnMainSearchDataSourceBindCallBack);
}
}
}
else
{
if (tabPage == this.tcButtom.TabControlObj.TabPages[0] && string.IsNullOrEmpty(this.PrimaryValue))
{
return;
}
if (tabPage.Tag != null && tabPage.Tag is GridControlEx gridControlEx)
{
GridDetailModel detailModel = gridControlEx.Tag as GridDetailModel;
if (!string.IsNullOrWhiteSpace(this.ParentKey))
{
string codeSql = "select";
codeSql += string.Format(" '{0}' as {1}", this.PrimaryValue, this.PrimaryKey);
gridControlEx.SetGridViewDataSource(SqlHelper.ExecuteDataTable(ReplaceHelper.ReplaceRowParam(BaseImpl.GetDataRowResult(codeSql), ReplaceHelper.ReplaceWhereCond(detailModel.DetailSql))));
}
else if (this.ControlObj.CurrentData != null)
{
gridControlEx.SetGridViewDataSource(SqlHelper.ExecuteDataTable(ReplaceHelper.ReplaceRowParam(this.ControlObj.CurrentData, ReplaceHelper.ReplaceWhereCond(detailModel.DetailSql))));
}
}
else if (tabPage.Tag != null && tabPage.Tag is ModuleGridEx moduleGridEx)
{
moduleGridEx.SearchObj.SearchGrid();
}
else if (tabPage.Tag is FrmWebBrowser)
{
// 加载网页
FrmWebBrowser webView = tabPage.Tag as FrmWebBrowser;
GridDetailModel detailModel = webView.Tag as GridDetailModel;
string url = detailModel.DetailSql.StartsWith("http") ? detailModel.DetailSql : SystemInfo.Instance.OAUrl + detailModel.DetailSql;
if (!string.IsNullOrWhiteSpace(this.ParentKey))
{
string codeSql = "select";
codeSql += string.Format(" '{0}' as {1}", this.PrimaryValue, this.PrimaryKey);
url = ReplaceHelper.ReplaceRowParam(BaseImpl.GetDataRowResult(codeSql), ReplaceHelper.ReplaceWhereCond(detailModel.DetailSql));
}
if (this.ControlObj.CurrentData != null) url = ReplaceHelper.ReplaceRowParam(this.ControlObj.CurrentData, url);
webView.LoadUrl(url);
webView.Dock = DockStyle.Fill;
}
else if (tabPage.Tag is FrmWebBrowser2)
{
// 加载网页
FrmWebBrowser2 webView = tabPage.Tag as FrmWebBrowser2;
GridDetailModel detailModel = webView.Tag as GridDetailModel;
string url = detailModel.DetailSql.StartsWith("http") ? detailModel.DetailSql : SystemInfo.Instance.OAUrl + detailModel.DetailSql;
if (!string.IsNullOrWhiteSpace(this.ParentKey))
{
string codeSql = "select";
codeSql += string.Format(" '{0}' as {1}", this.PrimaryValue, this.PrimaryKey);
url = ReplaceHelper.ReplaceRowParam(BaseImpl.GetDataRowResult(codeSql), ReplaceHelper.ReplaceWhereCond(detailModel.DetailSql));
}
if (this.ControlObj.CurrentData != null) url = ReplaceHelper.ReplaceRowParam(this.ControlObj.CurrentData, url);
webView.LoadUrl(url);
webView.Dock = DockStyle.Fill;
}
else if (tabPage.Tag is FrmMiniBlink)
{
// 加载网页
FrmMiniBlink webView = tabPage.Tag as FrmMiniBlink;
GridDetailModel detailModel = webView.Tag as GridDetailModel;
string url = detailModel.DetailSql.StartsWith("http") ? detailModel.DetailSql : SystemInfo.Instance.OAUrl + detailModel.DetailSql;
if (!string.IsNullOrWhiteSpace(this.ParentKey))
{
string codeSql = "select";
codeSql += string.Format(" '{0}' as {1}", this.PrimaryValue, this.PrimaryKey);
url = ReplaceHelper.ReplaceRowParam(BaseImpl.GetDataRowResult(codeSql), ReplaceHelper.ReplaceWhereCond(detailModel.DetailSql));
}
if (this.ControlObj.CurrentData != null) url = ReplaceHelper.ReplaceRowParam(this.ControlObj.CurrentData, url);
webView.LoadUrl(url);
webView.Dock = DockStyle.Fill;
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 说明:查询条件绑定完成查询数据
/// 创建人:龚宇超
/// 创建日期:
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
protected void OnMainSearchDataSourceBindCallBack(object sender, EventArgs e)
{
try
{
MyControl searchobj = sender as MyControl;
searchobj.SearchGrid();
OnSearchAfter(null, null);
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 说明:查询条件执行前
/// 创建人:龚宇超
/// 创建日期:2017-11-10
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The e.
protected void OnSearchBefore(object sender, SearchArgs e)
{
try
{
XtraTabPage tabPage = this.tcButtom.TabControlObj.SelectedTabPage;
if (plMainControlObj.Tag is XtraTabControl)
{
XtraTabControl xtr = plMainControlObj.Tag as XtraTabControl;
tabPage = xtr.SelectedTabPage;
}
if (tabPage != null)
{
ModuleGridEx moduleGrid = tabPage.Tag as ModuleGridEx;
GridDetailModel detailModel = moduleGrid.Tag as GridDetailModel;
moduleGrid.SearchObj.SearchGrid(detailModel.DetailSql + string.Format(" and {0}='{1}'", moduleGrid.DetailKeyField, moduleGrid.UnionValue));
}
e.Continue = false;
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 说明:查询条件执行后
/// 创建人:龚宇超
/// 创建日期:2017-11-10
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
protected void OnSearchAfter(object sender, EventArgs e)
{
try
{
XtraTabPage tabPage = this.tcButtom.TabControlObj.SelectedTabPage;
if (plMainControlObj.Tag is XtraTabControl)
{
XtraTabControl xtr = plMainControlObj.Tag as XtraTabControl;
tabPage = xtr.SelectedTabPage;
}
if (tabPage != null)
{
if (tabPage.Tag is ModuleGridEx)
{
ModuleGridEx moduleGrid = tabPage.Tag as ModuleGridEx;
GridDetailModel detailModel = moduleGrid.Tag as GridDetailModel;
tabPage.Text = detailModel.DetailName + "(" + moduleGrid.SearchObj.GridRowCount + "条)";
}
else if (tabPage.Tag is GridControlEx)
{
GridControlEx moduleGrid = tabPage.Tag as GridControlEx;
GridDetailModel detailModel = moduleGrid.Tag as GridDetailModel;
tabPage.Text = detailModel.DetailName + "(" + moduleGrid.DataRowCount() + "条)";
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 说明:初始化多标签
/// 创建人:龚宇超
/// 创建日期:2017-11-10
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
private void CreateTabDetail()
{
bool isInside = false;
foreach (DataRow item in this.DetailsData)
{
XtraTabPage tabPage = new XtraTabPage();
GridDetailModel detailModel = new GridDetailModel(item, null, GridCustomColumnStruct.BaseDetailGridView);
if (!string.IsNullOrEmpty(detailModel.UnionModule))
{
ModuleModel moduleModel = new ModuleModel(MainImpl.GetSystemdllTab(detailModel.UnionModule));
if (string.IsNullOrWhiteSpace(moduleModel.FormKey))
{
MessageUtil.Show(detailModel.DetailName + "模块配置错误");
return;
}
detailModel.DetailSql = moduleModel.MenuSql;
}
detailModel.GridColumns = ReportImpl.GetReportDetailColumns(Model.ModuleCode, item["id"] + "");
tabPage.Text = detailModel.DetailName;
tabPage.Tag = detailModel;
this.tcButtom.TabControlObj.TabPages.Add(tabPage);
}
}
///
/// 获取数据源缓存
///
///
///
///
///
public void GetDataCaches(Dictionary