/****************************** * 说明:单据模版 * 创建人:龚宇超 * 创建日期:2017-11-23 * 修改人: * 修改日期: * 修改备注: * 版本:1.0.0.0 ******************************/ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Lskj.Control; using Lskj.Model; using Lskj.Control.Model; using Lskj.Util; using Lskj.Business.Impl; using DevExpress.XtraGrid.Views.Grid; using Lskj.Data; using DevExpress.XtraBars; using DevExpress.XtraTab; using DevExpress.XtraEditors; using System.Collections; using Lskj.PubBillSpecial.Model; using DevExpress.Data; using DevExpress.XtraGrid.Columns; using System.IO; using Lskj.Business; using Lskj.Main.Model; using System.Threading.Tasks; using Lskj.Core; namespace Lskj.PubBillSpecial { /// /// 单据模版 /// public partial class FrmMain : BaseForm { /// /// 入口参数 /// public DynamicBillModel SysModel; /// /// 第一次进入页面 /// public bool isInitialization = true; public FrmMain() { InitializeComponent(); } protected override void OnLoad(EventArgs e) { try { WaitForm.ShowForm(); Dictionary dataCaches = SysModel != null ? SysModel.DataCaches : null; if (!dataCaches.GetValue(this, "Privilege", out string privilege)) { privilege = SysModel.ModuleId > 0 ? BaseImpl.GetUserPurviewsByMenuId(SysModel.ModuleId + "") + "" : BaseImpl.GetUserPurviewsByMenuCode(SysModel.ModuleCode) + ""; } this.SysModel.Privilege = privilege; if (!this.SysModel.HasPrivilege()) { MessageUtil.Show(ResourceKeys.UnPurview); this.Close(); } else { billModule1.OnLoad(SysModel); // 右键菜单调用方式,则模块名称按照系统设置设定 if (!string.IsNullOrEmpty(this.SysModel.BillMasterSql) || !string.IsNullOrEmpty(this.SysModel.BillDetailSql) || !string.IsNullOrEmpty(this.SysModel.BillOrderNo)) { this.Text = this.billModule1.BillModel.TypeName; if (this.SysModel.BillDetailSql.StartsWith("*")) { string rightid = this.SysModel.BillDetailSql.TrimStart('*'); string sqlValue = "select AllowNullExec,* from p_systempopupmenu "; sqlValue = $"{sqlValue} where id = '{rightid}'"; DataRow rowItem = BaseImpl.GetDataRowResult(sqlValue); if (rowItem != null) { CommonMenu menu = new CommonMenu(this.SysModel, this.billModule1.ControlObj, this.billModule1.gcMainDetilObj); menu.DynamicLinkAfter += new CommonToolAfterDynamicLinkEventHandler(OnDynamicLinkAfter); menu.Apply(rowItem); } } } this.FormClosing += new FormClosingEventHandler(OnClose); } if (this.billModule1.MainBottomInputObj.Visible && this.billModule1.txtinputobj.Enabled) { this.Activated += FrmMain_Activated; } } catch (Exception ex) { LogHelper.Instance.WriteError(ex); //MessageUtil.Show(ex); string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } finally { Lskj.Control.Model.AutoSizeChange.ControllInitializeSize(this); WaitForm.HideForm(); } } /// /// 执行完成后若是取消状态则关闭当前界面 /// /// private void OnDynamicLinkAfter(object sender, ApplyArgs e) { if (e.DialogModel != null && e.DialogModel.PubDialogType == DialogType.Pubcolsed) { this.Close(); } } /// /// 获取数据源缓存 /// /// public void GetDataCaches(Dictionary cachesDic) { //全局数据 Task dynamicModelTask = cachesDic.AddTask(this, "DynamicModel", new Task(() => { return SysModel;//动态链接库对象 })); Task systemDllRowTask = cachesDic.AddTask(this, "SystemDllRow", new Task(() => { return MainImpl.GetSystemdllTab(SysModel.ModuleCode);//获取单个模块信息 })); Task sysModelTask = cachesDic.AddTask(this, "SysModel", new Task(() => { ModuleModel sysModel = new ModuleModel(systemDllRowTask.Result); return sysModel;//系统模块实体对象 })); Task formTypeTask = cachesDic.AddTask(this, "FormType", new Task(() => { return BaseImpl.GetBillDetailType(SysModel.ModuleCode); })); Task privilegeTask = cachesDic.AddTask(this, "Privilege", new Task(() => { return SysModel.ModuleId > 0 ? BaseImpl.GetUserPurviewsByMenuId(SysModel.ModuleId + "") + "" : BaseImpl.GetUserPurviewsByMenuCode(SysModel.ModuleCode) + ""; })); //获取billModule1控件的数据 if (dynamicModelTask.Result.HasPrivilege()) { //添加数据到billModule1 cachesDic.AddTask(billModule1, "DynamicModel", dynamicModelTask); cachesDic.AddTask(billModule1, "SystemDllRow", systemDllRowTask); cachesDic.AddTask(billModule1, "SysModel", sysModelTask); billModule1.GetDataCaches(cachesDic); } } private void FrmMain_Activated(object sender, EventArgs e) { if (isInitialization) { this.billModule1.txtinputobj.Focus();//如果有扫码框,就默认获得焦点 isInitialization = false; } } private void OnClose(object sender, FormClosingEventArgs e) { string guid = this.Tag + ""; if (string.IsNullOrWhiteSpace(guid)) return; DllModule m = Manager.ModuleForms[guid]; m.IsClose = true; if (billModule1.closeTheJudgment()) { if (string.IsNullOrWhiteSpace(guid)) return; DialogResult result = MessageUtil.Show(("数据未保存,是否确定关闭?"), MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { m.IsClose = true; e.Cancel = false; } else { m.IsClose = false; e.Cancel = true; } } } } }