/******************************
* 说明:添加、修改界面模版
* 创建人:龚宇超
* 创建日期: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;
namespace Lskj.Control
{
///
/// 添加、修改界面模版
///
public partial class ModulePanelEx : UserControl
{
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 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();
}
#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;
// 配置有目录结构(显示)、修改状态(可用)
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.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;
}
///
/// 说明:常用工具点击
/// 创建人:龚宇超
/// 创建日期: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()
{
//外面表格搜索条件赋值
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);
}
if (!string.IsNullOrWhiteSpace(this.ControlSql))
{
DataRow rowItem = BaseImpl.GetDataRowResult(this.ControlSql);
this.ControlObj.CurrentData = rowItem;
this.ControlObj.SetAllControlValue(rowItem);
this.ControlObj.SyncLocalModel();
}
this.ControlObj.CanExecControl = true;
}
///
/// 说明:设置图片事件
/// 创建人:龚宇超
/// 创建日期: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.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();
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 获取数据源缓存
///
///
///
///
///
public void GetDataCaches(Dictionary