/****************************** * 说明:添加、修改界面模版 * 创建人:龚宇超 * 创建日期: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 cachesDic, ModuleModel sysModel, DynamicModel dyncModel, bool IsAutoScroll = false) { } /// /// 说明:默认控件值触发改变事件 /// 创建人:王一帆 /// 创建日期:2021-04-28 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void InitSpeciesBtn() { //DataRow[]ControlTree=_controlTable.Select("fieldTypeld=" + "3"); //if (ControlTree != null && ControlTree.Count() > 0) { // ControlModel model = this.ControlObj._models.FirstOrDefault(x => x.Sign == (int)cardType); //} // ControlModel model = new ControlModel(); // //lteSpeciesNo.TextEdit.KeyDown += new KeyEventHandler(OnTextEditKeyDown); // lteSpeciesNo.TextEdit.TextChanged += new EventHandler(OnTextEditTextChanged); //baseControl = textEdit; } /// /// 说明:默认控件值触发改变事件 /// 创建人:王一帆 /// 创建日期:2021-04-28 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. void OnTextEditTextChanged(object sender, EventArgs e) { } /// /// 说明:点击空白处获取焦点 /// 创建人:王一帆 /// 创建日期: /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. void OnMainClick(object sender, EventArgs e) { try { this.pl_main.Focus(); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:数据绑定完成后加载数据 /// 创建人:龚宇超 /// 创建日期: /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. void OnControlObjOnDataSourceBindCallBack(object sender, EventArgs e) { try { this.SetUpdateData(); if (this.scc_container.PanelVisibility == SplitPanelVisibility.Both) { this.tcButtom.TabControlObj.SelectedTabPageIndex = 0; this.OnSelectedPageChanged(null, null); } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:设置顶部分类是否显示 /// 创建人:龚宇超 /// 创建日期:2017-11-03 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// if set to true [visible]. public void SetTopPanelVisible(bool visible) { this.pl_main_top.Visible = visible; } /// /// 说明:设置底部按钮是否显示 /// 创建人:龚宇超 /// 创建日期:2019-01-11 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// if set to true [visible]. public void SetButtonPanelVisible(bool visible) { this.pl_buttom.Visible = !visible; this.panelControl1.Visible = visible; } /// /// 关闭线程 /// public void CloseIDCardThread() { if (this.IDCardThread != null) { this.IDCardThread.Abort(); IDCardUtil.CloseIDCard(); } } /// /// 说明:添加数据 /// 创建人:龚宇超 /// 创建日期:2018-04-03 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// public bool AddControlRecord(bool isClose = true, bool isTip = true) { if (this.ControlObj.VerifyNull()) { string primaryKey = this.ControlObj.GetControlValue(this.PrimaryKey); if (this.ControlObj.SaveBaseModuleData(this.Model.ModuleCode, this.SysModel.MenuTable, this.PrimaryKey, ref primaryKey, true, _leftField, isTip, this.SysModel.NewVer)) { LogUtil.WriteDebug(Model.ModuleCode, Model.FormText + "-->添加", Model.FormText + "[" + primaryKey + "]", Model.FormText, Model.ModuleId + ""); // 保存成功. this.PrimaryValue = this.SysModel.NewVer == 0 ? this.ControlObj.GetControlValue(this.PrimaryKey) : primaryKey; if (primaryKey.Contains("LskjIdebtity")) this.PrimaryValue = primaryKey.Replace("LskjIdebtity", ""); this.ControlObj.SetControlValue(this.PrimaryKey, this.PrimaryValue); DataRow rowItem = BaseImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", this.SysModel.MenuTable, this.PrimaryKey, this.PrimaryValue)); this.ControlObj.CanExecControl = false; this.ControlObj.SetAllControlValue(rowItem); this.ControlObj.CanExecControl = true; btnAdd.Enabled = false; btnApply.Enabled = btnUpdate.Enabled = btnCopyNew.Enabled = btnAttach.Enabled = true; SavaState = false; // 同步本地数据,用于关闭时检查数据是否已修改. this.ControlObj.SyncLocalModel(); if (this.OnAddRecordCallBack != null && isClose) this.OnAddRecordCallBack(null, null); if (1 == SysModel.CloseAfterAdd) { this.OnCloseCallback(null, null); } else { SetUpdateData(false);//重新加载数据 } return true; } } return false; } /// /// 说明:修改数据 /// 创建人:龚宇超 /// 创建日期:2018-04-03 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// public bool UpdateControlRecord(bool isClose = true) { if (this.ControlObj.VerifyNull()) { if (this.ControlObj.SaveBaseModuleData(this.Model.ModuleCode, this.SysModel.MenuTable, this.PrimaryKey, ref this.PrimaryValue, false, this._leftField, true, this.SysModel.NewVer)) { LogUtil.WriteDebug(Model.ModuleCode, Model.FormText + "-->修改", Model.FormText + "[" + PrimaryValue + "]", Model.FormText, Model.ModuleId + ""); if (this.SysModel.ModifyClose && this.OnCloseCallback != null && isClose) { this.OnCloseCallback(null, null); } else { SetUpdateData(false);//重新加载数据 btnApply.Enabled = btnCopyNew.Enabled = btnAttach.Enabled = true; } return true; } } return false; } /// /// 说明:测试身份证刷卡 /// 创建人:龚宇超 /// 创建日期:2018-05-31 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. public void OnReadCard() { while (true) { var cards = IDCardUtil.ReadCardAllMessage(); if (cards != null && cards.Count > 0) { this.Invoke(new MethodInvoker(delegate { this.ControlObj.SetAllControlValue(cards); })); } } } #endregion #region protected event /// /// 说明:清除页面 /// 创建人:龚宇超 /// 创建日期:2017-11-03 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnClearItemClick(object sender, EventArgs e) { try { if (this.ControlObj.ResetControlValue()) { btnAdd.Enabled = true; btnUpdate.Enabled = btnCopyNew.Enabled = btnAttach.Enabled = false; if (this.OnClearCallBack != null) { this.OnClearCallBack(sender, e); } } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:复制新增 /// 创建人:龚宇超 /// 创建日期:2017-11-03 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnCopyItemClick(object sender, EventArgs e) { try { this.PrimaryValue = string.Empty; BaseUserControl baseControl = this.ControlObj.FindControl(PrimaryKey); if (baseControl != null) { this.ControlObj.CopyControlValue(); baseControl.EditText = BaseImpl.GetDefaultValue(baseControl.Model.Default, ParentKey); lteSpeciesNo.TextEdit.EditValue = this.ParentKey; lteSpeciesName.TextEdit.EditValue = this.ParentValue; ControlObj.ParentKey = this.ParentKey; // 设置按钮状态 btnAdd.Enabled = true; btnUpdate.Enabled = btnCopyNew.Enabled = btnAttach.Enabled = false; if (this.OnCopyRecordCallBack != null) { this.OnCopyRecordCallBack(sender, e); } } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:附件管理 /// 创建人:龚宇超 /// 创建日期:2017-11-03 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnAttachItemClick(object sender, ItemClickEventArgs e) { try { if (string.IsNullOrWhiteSpace(this.PrimaryValue)) { MessageUtil.Show(ResourceKeys.UnSaveData); } 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 = { string.Format(ModuleArgs.PubPhotoViewArgs, this.PrimaryValue), "0", this.SysModel.MenuDirId + "", "" }; string[] args = defaultArgs.Concat(menuArgs).ToArray(); IForm form = FormHelper.LoadDllForm(ResourceDynamic.PhotoView, args); DialogResult result = form.SubForm.ShowDialog(); } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:常规打印 /// 创建人:龚宇超 /// 创建日期:2017-11-03 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnNormalPrintItemClick(object sender, ItemClickEventArgs e) { try { if (this.OnPrintCallBack != null) { this.OnPrintCallBack(sender, e); } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:添加数据 /// 创建人:龚宇超 /// 创建日期:2017-11-03 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnAddClick(object sender, EventArgs e) { try { WaitForm.ShowForm(ResourceKeys.DataSaving); bool results = this.AddControlRecord(); if (this.SysModel.AddAndSubmit&& results) { if (this.btnApply.Visible && this.btnApply.Enabled) this.OnApplyClick(null,null); } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } finally { WaitForm.HideForm(); } } /// /// 说明:更新保存 /// 创建人:龚宇超 /// 创建日期:2017-11-03 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnUpdateClick(object sender, EventArgs e) { try { WaitForm.ShowForm(ResourceKeys.DataSaving); this.UpdateControlRecord(); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } finally { WaitForm.HideForm(); } } /// /// 说明:提交保存 /// 创建人:龚宇超 /// 创建日期:2017-11-03 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnApplyClick(object sender, EventArgs e) { try { bool isApply = false; string primaryValue = this.PrimaryValue; //if (SavaState && string.IsNullOrWhiteSpace(this.PrimaryValue)) //{ // primaryValue=this.ControlObj.GetControlValue(this.PrimaryKey); //} WaitForm.ShowForm(ResourceKeys.Handing); if (this.ControlObj.VerifyNull()) { if (this.ControlObj.VerifyUpdated()) { isApply = this.ControlObj.SaveBaseModuleData(this.Model.ModuleCode, this.SysModel.MenuTable, this.PrimaryKey, ref primaryValue, false, this._leftField, false, this.SysModel.NewVer); // isApply = this.ControlObj.SaveBaseModuleData(this.Model.ModuleCode, this.SysModel.MenuTable, this.PrimaryKey, ref primaryValue, SavaState, this._leftField, true, this.SysModel.NewVer); } else { isApply = true; // 无需保存 } } if (isApply) { // 提交数据 this.PrimaryValue = this.SysModel.NewVer == 0 ? this.ControlObj.GetControlValue(this.PrimaryKey) : this.PrimaryValue; if (string.IsNullOrEmpty(PrimaryValue) || SavaState) { isApply=this.AddControlRecord(true, false); if (!isApply) return;//保存失败不执行提交 } DialogResult result = MessageUtil.Show(ResourceKeys.BillApply, MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { string tipMsg = string.Empty; if (BaseModuleImpl.ApplyBaseData(this.Model.ModuleCode, this.PrimaryValue, 1, out tipMsg) == 1) { if (!this.SysModel.ApplyHideSccesMessage) { MessageUtil.Show(ResourceKeys.ApplySuccess); } #region api提交审核时推送 if (ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.AfterModuleAuditStateChange, this.Model.ModuleCode, 0)) { ApiHelper apiHelper = new ApiHelper(this.Model.ModuleCode, this.PrimaryValue, this.PrimaryKey, this.SysModel.MenuTable, 0); apiHelper.OnEvent(Interface.Api.OperateEvent.AfterModuleAuditStateChange, Interface.Api.ActionType.Submit); if (!string.IsNullOrEmpty(apiHelper.apiResutMsg)) MessageUtil.Show(apiHelper.apiResutMsg); } #endregion // 推送消息 PushHelper push = new PushHelper(this.PrimaryValue, "0", this.Model.ModuleCode, "", "", 0); push.Push_Base_Oper_Message(); if (this.OnApplyRecordCallBack != null) this.OnApplyRecordCallBack(sender, e); if (this.OnCloseCallback != null) this.OnCloseCallback(sender, e); } else { MessageUtil.Show(ResourceKeys.ApplyFault + "\r\n" + tipMsg); } } } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } finally { WaitForm.HideForm(); } } /// /// 说明:关闭 /// 创建人:龚宇超 /// 创建日期:2017-11-03 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnCloseClick(object sender, EventArgs e) { try { //bool isClose = true; //if (!string.IsNullOrWhiteSpace(this.PrimaryValue) && this.btnUpdate.Enabled && this.ControlObj.VerifyUpdated()) //{ // DialogResult result = MessageUtil.Show(ResourceKeys.DataChanged, MessageBoxButtons.YesNo); // if (result == DialogResult.Yes) // { // isClose = this.ControlObj.VerifyNull(); // if (isClose) // { // // 保存数据 // isClose = this.ControlObj.SaveBaseModuleData(this.Model.ModuleCode, this.SysModel.MenuTable, this.PrimaryKey, ref this.PrimaryValue, false, this._leftField, true, this.SysModel.NewVer); // } // } //} //if (isClose) //{ if (this.OnCloseCallback != null) this.OnCloseCallback(sender, e); //} } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:打印完成需要参数 /// 创建人:龚宇超 /// 创建日期:2018-07-09 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// protected void GetPrintOtherParam() { //取得打印完成后的参数 if (this.SysModel.PrintSql.Contains("<<")) { string[] strs = this.SysModel.PrintSql.Split(new[] { ">>" }, 2, StringSplitOptions.None); _mainPrintSql = strs[1]; _printModeCond = strs[0].Replace("<<", ""); } else { _mainPrintSql = this.SysModel.PrintSql; _isExcPrint = true; } //if (!string.IsNullOrEmpty(_printModeCond) && _printModeCond.IndexOf(';') > 0) //{ string[] str = { "", "" }; if (!string.IsNullOrEmpty(_printModeCond)) str = _printModeCond.Split(';'); DataRow item = string.IsNullOrEmpty(str[0]) ? null : AttachImpl.GetSystemModule(str[0]); string tableName = "temp"; string modetype = string.Empty; string comprefix = string.Empty; string primaryKey = string.Empty; if (item != null) { tableName = item["TableName"] + ""; modetype = item["modType"] + ""; comprefix = BaseImpl.GetColumnPrefix(tableName); primaryKey = modetype == "1" ? BaseImpl.GetBasePrimaryKey(str[0]) : comprefix + "billdocument_id"; } //表名,列前缀,主键字段,主键值,模块编号,主打印Sql _printSaveParams = new List() { 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; } //} } /// /// 说明:打印模版 /// 创建人:龚宇超 /// 创建日期:2018-04-08 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. 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; } bool isPrint = !string.IsNullOrEmpty(this.PrimaryValue); if (!isPrint) { if (MessageUtil.Show(ResourceKeys.BillNotSavedAndNotPrint, MessageBoxButtons.YesNo) == DialogResult.Yes) isPrint = this.AddControlRecord(); } if (isPrint) { try { // 判断是否满足打印条件 string printCond = this.ControlObj.ReplaceControlValue(this.SysModel.PrintCond); if (!string.IsNullOrEmpty(printCond) && !ReplaceHelper.EvalCond(printCond)) { MessageUtil.Show(ResourceKeys.DisSatisfyPrintCond); return; } string tmpSql = this.ControlObj.ReplaceControlValue(this.SysModel.PrintSql); string tmpSql1 = this.ControlObj.ReplaceControlValue(this.SysModel.PrintSql1); string tmpSql2 = this.ControlObj.ReplaceControlValue(this.SysModel.PrintSql2); if (printFile.Contains(PrintUtil.TemplateFlag)) { //主Sql string mainSql = string.Empty; List tmpSqls = new List(); if (_printSaveParams != null && _printSaveParams.Count > 0) { _printSaveParams[5] = mainSql = this.ControlObj.ReplaceControlValue(_mainPrintSql); _printSaveParams[3] = this.ControlObj.ReplaceControlValue(_printSaveParams[2]); tmpSqls.Add(mainSql); tmpSqls.Add(tmpSql1); tmpSqls.AddRange(tmpSql2.Split(';').ToList()); } 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) { LogHelper.Instance.WriteError(ex); string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } } /// /// 说明:模版新版打印 /// 创建人:龚宇超 /// 创建日期:2018-01-25 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. 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; if (!File.Exists(printPath)) { MessageUtil.Show(ResourceKeys.NotFoundPrintFile); return; } try { printParams = this.ControlObj.ReplaceControlValue(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); } } /// /// 说明:打印完成后回调 /// 创建人:龚宇超 /// 创建日期:2018-07-05 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The e. 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); } } /// /// 说明:常用工具点击 /// 创建人:龚宇超 /// 创建日期:2017-11-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnCommonItemClick(object sender, ItemClickEventArgs e) { try { DataRow rowItem = e.Item.Tag as DataRow; GridRightMenuModel model = new GridRightMenuModel(rowItem); //if (!string.IsNullOrWhiteSpace(model.MenuCond)) //{ // try // { // string cond = this.ControlObj.ReplaceControlValue(model.MenuCond); // bool result = ReplaceHelper.EvalCond(cond); // if (!result) return; // } // catch (Exception) // { // MessageUtil.Show(ResourceKeys.SetRightMenuCondFault); // } //} 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-02-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. protected void OnImageDeleteEvent(object sender) { try { LabelImageEdit imageEdit = sender as LabelImageEdit; if (imageEdit != null) { int result = BaseModuleImpl.UpdateRecord(this.SysModel.MenuTable, imageEdit.Model.FieldName, "", this.PrimaryKey, this.PrimaryValue); MessageUtil.Show(result > 0 ? ResourceKeys.OperSuccess : ResourceKeys.OperFault); } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:上传附件 /// 创建人:龚宇超 /// 创建日期:2018-02-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. protected void OnImageUploadEvent(object sender) { try { _imageEdit = sender as LabelImageEdit; if (string.IsNullOrWhiteSpace(this.PrimaryValue)) { MessageUtil.Show(ResourceKeys.UnSaveData); } else { //string prefix = "001"; //string imagePath = _imageEdit.SaveImageToLocal(prefix); OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == DialogResult.OK) { WaitForm.ShowForm("上传中..."); if (!string.IsNullOrEmpty(openFileDialog.FileName)) { Image image = null; bool isImage = true; try { image = Image.FromFile(openFileDialog.FileName); } catch (Exception) { isImage = false; } if (image != null && isImage) { _imageEdit.TextEdit.Image = image; } else { _imageEdit.TextEdit.Image = global::Lskj.Control.Properties.Resources.file; } _imageEdit.CurrentImagePath = openFileDialog.FileName; } else { _imageEdit.CurrentImagePath = string.Empty; } string imagePath = _imageEdit.CurrentImagePath; if (!string.IsNullOrEmpty(imagePath)) { //string speciesNo = string.IsNullOrEmpty(lteSpeciesNo.TextEdit.Text) ? "01" : lteSpeciesNo.TextEdit.Text; //int directotyId = AttachImpl.GetAttachDirectoryId(this.SysModel.MenuDirId + "", this.PrimaryValue); //AttachHelper.UpLoadFile(this.Handle, directotyId + "", speciesNo, "001", imagePath); bool isSuccess = UploadFile(imagePath); if (!isSuccess) { _imageEdit.CurrentImagePath = string.Empty; _imageEdit.TextEdit.Image = null; } } else { MessageUtil.Show("未选择上传文件"); } WaitForm.HideForm(); } } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 上传附件(新) /// private bool UploadFile(string filePath) { bool isUpload = true; try { string token = ""; string loginUrl = $"{SystemInfo.Instance.OAUrl}/Api/SysUserAjaxApi.ashx"; HttpTools.setting("application/x-www-form-urlencoded", null, null, HttpTools.Encode.UTF8); Dictionary loginPmsDic = new Dictionary(); loginPmsDic.Add("method", "Login"); loginPmsDic.Add("username", ERPInfo.Instance.UserName); loginPmsDic.Add("password", ERPInfo.Instance.InPassWord); HttpWebResponse loginResponse = HttpTools.Post(loginUrl, "", loginPmsDic, HttpTools.Method.POST, out CookieCollection loginCookie, out string loginResult); if (loginResponse != null && !string.IsNullOrEmpty(loginResult)) { JObject jObject = JsonConvert.DeserializeObject(loginResult); if (jObject.ContainsKey("success")) { if ((jObject["success"] + "").Equals("True")) { if (jObject.ContainsKey("token")) { token = jObject["token"] + ""; } } } } if (!string.IsNullOrEmpty(token)) { byte[] fileBytes = ConvertFileToBytes(filePath); string fileBase64Str = Convert.ToBase64String(fileBytes) + ""; string postUrl = "{0}Api/FileUploadApi.ashx?moduleId={1}&idValue={2}&folder={3}&totsize={4}&position={5}&filename={6}&method={7}"; Dictionary headerDic = new Dictionary(); headerDic.Add("Authorization", $"Bearer {token}"); postUrl = string.Format(postUrl, SystemInfo.Instance.OAUrl, this.Model.ModuleCode, this.PrimaryValue, "UploadFilesTemp", fileBytes.Length, 0, HttpUtility.UrlEncode($"{Guid.NewGuid()}_{Path.GetFileName(_imageEdit.CurrentImagePath)}"), "DoWebUpload"); HttpTools.setting("application/x-www-form-urlencoded", null, null); HttpWebResponse webResponse = HttpTools.Post(postUrl, fileBase64Str, null, headerDic, HttpTools.Method.POST, out CookieCollection cookieCollection, out string result); if (webResponse != null && !string.IsNullOrEmpty(result)) { JObject jsonObject = (JObject)JsonConvert.DeserializeObject(result); string isSuccess = jsonObject["success"] + ""; if (isSuccess.Equals("True", StringComparison.CurrentCultureIgnoreCase)) { string fileId = jsonObject["other"] + ""; string webpath = jsonObject["data"]["WebRelPath"] + ""; BaseModuleImpl.UpdateRecord(this.SysModel.MenuTable, _imageEdit.Model.FieldName, webpath, this.PrimaryKey, this.PrimaryValue); //string searchSql = @"update P_fm_FileTab set author='{2}',CreationTime='{3}' ,Uploader='{4}' ,UploadTime='{5}' // where dllcoid = '{0}' and // parentid = (select dirid from P_fm_DirectoryTab where // ParentId = (select dirid from v_systemdlltab where DllCoid = '{0}') and PID = '{1}') and fileId='{6}' "; //searchSql = string.Format(searchSql, this.Model.ModuleCode, this.leftTreeGridIdValue, dataRow["author"], fi.CreationTime, ERPInfo.Instance.UserName, dataRow["UploadTime"], fileId); //SqlHelper.ExecuteNonQuery(searchSql); } else { if (jsonObject.ContainsKey("msg")) { string returnMsg = jsonObject["msg"] + ""; MessageUtil.Show(string.Format("上传失败,原因:{0}", returnMsg)); } isUpload = false; } } else { MessageUtil.Show(string.Format("上传失败,原因:{0}", result)); } } else { MessageUtil.Show(string.Format("验证失败,原因:{0}", loginResult)); } } catch (Exception ex) { MessageUtil.Show(string.Format("上传失败,原因:{0}", ex.Message)); isUpload = false; } return isUpload; } /// /// 附件转换byte[] /// /// 附件路径 /// 二进制 private byte[] ConvertFileToBytes(string filePath) { byte[] bytContent = null; System.IO.FileStream fs = null; System.IO.BinaryReader br = null; try { fs = new FileStream(filePath, System.IO.FileMode.Open, FileAccess.Read, FileShare.Read); } catch (Exception) { throw; } if (fs != null) br = new BinaryReader((Stream)fs); if (br != null) bytContent = br.ReadBytes((Int32)fs.Length); if (fs != null) fs.Dispose(); return bytContent; } /// /// 说明:关联附件 /// 创建人:龚宇超 /// 创建日期:2018-02-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. protected void OnImageUnionEvent(object sender) { _imageEdit = sender as LabelImageEdit; if (string.IsNullOrWhiteSpace(this.PrimaryValue)) { MessageUtil.Show(ResourceKeys.UnSaveData); } else { try { // 固定传入参数(窗口标题、操作员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 = { string.Format(ModuleArgs.PubPhotoViewArgs, this.PrimaryValue), "0", this.SysModel.MenuDirId + "", "", "1", _imageEdit.Model.FieldName, lteSpeciesNo.TextEdit.Text }; string[] args = defaultArgs.Concat(menuArgs).ToArray(); IForm form = FormHelper.LoadDllForm(ResourceDynamic.PhotoView, args); DialogResult result = form.SubForm.ShowDialog(); // 刷新数据 string unionPath = BaseImpl.GetRecord(this.SysModel.MenuTable, _imageEdit.Model.FieldName, this.PrimaryKey, this.PrimaryValue) + ""; if (!string.IsNullOrEmpty(unionPath)) _imageEdit.LoadImage(unionPath, false); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } } /// /// 说明:消息处理 /// 创建人:龚宇超 /// 创建日期:2018-03-23 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// 要处理的 Windows。 protected override void DefWndProc(ref Message m) { base.DefWndProc(ref m); if (this.Handle == m.HWnd) AttachHelper.DefWndProc(m); } /// /// 说明:上传成功 /// 创建人:龚宇超 /// 创建日期:2018-03-23 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnAttachUploadSuccess(object sender, EventArgs e) { try { if (AttachHelper.IsDefWndProc(this.Handle, (System.Windows.Forms.Message)sender) && _imageEdit != null && File.Exists(_imageEdit.CurrentImagePath)) { int result = BaseModuleImpl.UpdateRecord(this.SysModel.MenuTable, _imageEdit.Model.FieldName, Path.GetFileName(_imageEdit.CurrentImagePath), this.PrimaryKey, this.PrimaryValue); } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:下载成功 /// 创建人:龚宇超 /// 创建日期:2018-03-23 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnAttachDownLoadSuccess(object sender, EventArgs e) { try { if (AttachHelper.IsDefWndProc(this.Handle, (System.Windows.Forms.Message)sender) && _imageEdit != null && File.Exists(_imageEdit.CurrentImagePath)) { this._imageEdit.TextEdit.Image = Image.FromFile(Path.Combine(new string[] { PubUtil.FileDownLoadTempPath, _imageEdit.CurrentImagePath })); } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:扫码模块回车处理 /// 创建人:龚宇超 /// 创建日期:2018-05-25 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. protected void OnScanTextEditKeyDown(object sender, KeyEventArgs e) { try { if (e.KeyCode == Keys.Enter) { BaseUserControl baseControl = null; var ctr = sender as System.Windows.Forms.Control; if (ctr != null && ctr.Parent != null && ctr.Parent.Parent != null) baseControl = ctr.Parent.Parent as BaseUserControl; bool isSaveSkip = false; BaseUserControl nextControl = this.ControlObj.FindNextControl(baseControl, out isSaveSkip); if (nextControl != null && !isSaveSkip) { nextControl.Focus();//存在跳转控件则直接跳转 } else { if (SavaState) { this.AddControlRecord(true, false); } else { this.UpdateControlRecord(true); } if (this._scanEdit != null) { // 保存成功后重新设置值. BaseUserControl control = this.ControlObj.FindControl(PrimaryKey); if (control != null) { this.PrimaryValue = MainImpl.GetDefaultValue(control.Model.Default); this.ControlObj.SetControlValue(control.Model, this.PrimaryValue); } SynchronizationContext.Current.Post(o => { this._scanEdit.Focus(); this._scanEdit.TextEdit.Focus(); }, null); } if (nextControl != null && !isSaveSkip) { nextControl.Focus(); } } } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明: /// 创建人:龚宇超 /// 创建日期:2019-06-05 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnMesSaveClick(object sender, EventArgs e) { try { bool success = false; if (string.IsNullOrWhiteSpace(this.PrimaryValue)) success = this.AddControlRecord(false); else success = this.UpdateControlRecord(false); if (success && this.OnCloseCallback != null) this.OnCloseCallback(sender, e); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:Mes系统关闭窗口 /// 创建人:龚宇超 /// 创建日期:2019-06-05 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. protected void OnBtnMesCloseClick(object sender, EventArgs e) { try { if (this.OnCloseCallback != null) this.OnCloseCallback(sender, e); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:附件管理 /// 创建人:龚宇超 /// 创建日期:2019-06-05 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. protected void OnBtnAttachClick(object sender, EventArgs e) { try { string idValue = this.PrimaryValue; if (!string.IsNullOrWhiteSpace(this.SysModel.AttachmentAssociated)) { idValue = this.ControlObj.GetControlValue(this.SysModel.AttachmentAssociated); } if (string.IsNullOrWhiteSpace(this.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, idValue, this.btnUpdate.Enabled ? "0" : "1"); if (!string.IsNullOrWhiteSpace(this.ParentKey) && this.SysModel.AttachmentSelectNode) { url = string.Format("pages/PhotoView.html?left=1&username={0}&password={1}&id={2}&isview={3}&specno={4}&dllcoid=", ERPInfo.Instance.UserName, ERPInfo.Instance.Password, idValue, this.btnUpdate.Enabled ? "0" : "1", this.ParentKey); } // 固定传入参数(窗口标题、操作员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, this.PrimaryValue), "0", this.SysModel.MenuDirId + "", "" }; string[] args = defaultArgs.Concat(menuArgs).ToArray(); if (SystemInfo.Instance.BsAttachFlag.Equals("2")) { IForm form = FormHelper.LoadDllForm(ResourceDynamic.PubBrower, args); form.SubForm.Controls.Clear(); form.SubForm.WindowState = FormWindowState.Maximized; ProcessStartInfo processStartInfo = new ProcessStartInfo() { FileName = "WebBrowser\\Lskj.WebBrowser.exe", Arguments = HandleHelper.CombineArgs(args), UseShellExecute = false, RedirectStandardOutput = false, RedirectStandardError = false, CreateNoWindow = false }; Process startedProcess = Process.Start(processStartInfo); if (startedProcess == null) { MessageUtil.Show("进程启动失败"); return; } startedProcess.WaitForInputIdle(); int retry = 0; while (startedProcess.MainWindowHandle == IntPtr.Zero && retry < 50) { Thread.Sleep(100); startedProcess.Refresh(); retry++; } IntPtr exeMainHandle = startedProcess.MainWindowHandle; if (exeMainHandle == IntPtr.Zero) { MessageBox.Show("无法获取启动程序的主窗口句柄"); return; } HandleHelper.SetFormNoneStyle(exeMainHandle, form.SubForm); DialogResult result = form.SubForm.ShowDialog(); startedProcess.Kill(); form.SubForm.Dispose(); } else { IForm form = FormHelper.LoadDllForm(SystemInfo.Instance.BsAttachFlag.Equals("1") ? ResourceDynamic.PubBrower : ResourceDynamic.PhotoView, args); DialogResult result = form.SubForm.ShowDialog(); form.SubForm.Dispose(); } } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:清除 /// 创建人:龚宇超 /// 创建日期:2019-06-05 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. protected void OnBtnClearClick(object sender, EventArgs e) { try { if (this.ControlObj.ResetControlValue()) { btnAdd.Enabled = true; btnUpdate.Enabled = btnCopyNew.Enabled = btnAttach.Enabled = false; if (this.OnClearCallBack != null) { this.OnClearCallBack(sender, e); } } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:复制新增 /// 创建人:龚宇超 /// 创建日期:2019-06-05 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. protected void OnBtnCopyNewClick(object sender, EventArgs e) { try { this.PrimaryValue = string.Empty; BaseUserControl baseControl = this.ControlObj.FindControl(PrimaryKey); if (baseControl != null) { this.ControlObj.CopyControlValue(this.SysModel.CancelCopyAssociation); baseControl.EditText = BaseImpl.GetDefaultValue(baseControl.Model.Default, ParentKey); lteSpeciesNo.TextEdit.EditValue = this.ParentKey; lteSpeciesName.TextEdit.EditValue = this.ParentValue; ControlObj.ParentKey = this.ParentKey; // 设置按钮状态 btnAdd.Enabled = true; btnUpdate.Enabled = btnCopyNew.Enabled = btnAttach.Enabled = false; if (this.OnCopyRecordCallBack != null) { this.OnCopyRecordCallBack(sender, e); } } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } #endregion private void simpleButton1_Click(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); } } protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x02000000; return cp; } } } }