/****************************** * 说明:基础档案添加界面 * 创建人:龚宇超 * 创建日期:2017-11-02 * 修改人: * 修改日期: * 修改备注: * 版本: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.Control.Model; using Lskj.Util; using Lskj.Business.Impl; using Lskj.Model; using DevExpress.XtraTab; using DevExpress.Utils; using Lskj.Data; namespace Lskj.PubAdd { /// /// 基础档案添加界面 /// public partial class FrmMain : BaseForm { /// /// 系统模块实体对象 /// /// The system model. public ModuleModel SysModel { get; private set; } /// /// 调用动态链接库默认传递参数 /// public DynamicAddModel Model; /// /// 第一页控件 /// public ModulePanelEx FirstModulePageEx; /// /// 除主页剩下页面 /// public List OtherModulePageEx = new List(); public FrmMain() { InitializeComponent(); } protected override void OnLoad(EventArgs e) { WaitForm.ShowForm(); try { this.SysModel = new ModuleModel(MainImpl.GetSystemdllTab(Model.ModuleCode)); this.CreateControlLocation(); this.SetControlPanelSize(); this.CreateTabDetail(); } catch (Exception ex) { LogHelper.Instance.WriteError(ex); MessageUtil.Show(ex.Message + "\r\n" + ex.StackTrace); } this.Text = Model.FormText + (string.IsNullOrWhiteSpace(Model.ObjectId) ? "" : "[" + Model.ObjectId + "]"); WaitForm.HideForm(); } /// /// 说明:设置窗口大小 /// 创建人:龚宇超 /// 创建日期:2017-11-03 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The menu code. private void SetControlPanelSize() { DataRow item = BaseModuleImpl.GetControlParentSize(this.SysModel.FormKey); if (item != null) { int otherHeight = 80; bool topVisible = false; if ("lskj.pubadd.dll".Equals((this.SysModel.MenuAddName).ToLower()) && !this.SysModel.AnyAdd) { otherHeight = 130; topVisible = true; } this.FirstModulePageEx.SetTopPanelVisible(topVisible); this.Width = Convert.ToInt32(item["width"] + ""); this.Height =Convert.ToInt32(item["height"] + "") + otherHeight; this.Left = (Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2; this.Top = (Screen.PrimaryScreen.WorkingArea.Height - this.Height) / 2; if ((this.Width > Screen.PrimaryScreen.WorkingArea.Width) || (this.Height > Screen.PrimaryScreen.WorkingArea.Height)) this.WindowState = FormWindowState.Maximized; } } /// /// 说明:初始化多标签 /// 创建人:龚宇超 /// 创建日期:2017-11-10 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void CreateTabDetail() { DataTable details = BaseModuleImpl.GetBaseAddTabDetail(Model.ModuleCode); foreach (DataRow item in details.Rows) { string cacheKey = this.Model.ModuleCode + "_" + item["id"] + ""; bool isCache = CacheHelper.Exsits(cacheKey); XtraTabPage tabPage = new XtraTabPage(); GridDetailModel detailModel = new GridDetailModel(item, null, GridCustomColumnStruct.BaseDetailGridView); ModuleModel moduleModel = new ModuleModel(MainImpl.GetSystemdllTab(detailModel.UnionModule)); if (isCache) { tabPage = CacheHelper.Get(cacheKey); } else { detailModel.GridColumns = ReportImpl.GetReportDetailColumns(Model.ModuleCode, item["id"] + ""); detailModel.DetailSql = moduleModel.MenuSql; DynamicAddModel addModel = new DynamicAddModel(new string[] { detailModel.DetailName, ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, "1",detailModel.UnionModule,"","","" }); ModuleGridEx moduleGrid = new ModuleGridEx(); moduleGrid.Dock = DockStyle.Fill; moduleGrid.Tag = detailModel; moduleGrid.ParentKeyField = string.IsNullOrEmpty(detailModel.UnionParentField) ? SysModel.ParmaryKey : detailModel.UnionParentField; moduleGrid.DetailKeyField = detailModel.UnionValue; moduleGrid.UnionKey = moduleGrid.ParentKeyField; moduleGrid.UnionValue = this.FirstModulePageEx.ControlObj.GetControlValue(moduleGrid.UnionKey); //Model.ObjectId; moduleGrid.InitializeControl(moduleModel, addModel); moduleGrid.SearchObj.OnSearchBeforeCallBack += new SearchEventHandler(OnSearchBefore); moduleGrid.SearchObj.OnSearchAfterCallBack += new EventHandler(OnSearchAfter); tabPage.Text = detailModel.DetailName; tabPage.Tag = moduleGrid; tabPage.Controls.Add(moduleGrid); CacheHelper.Add(cacheKey, tabPage); } if (detailModel.AutoRefresh) { // 自动刷新 ModuleGridEx moduleGrid = tabPage.Tag as ModuleGridEx; moduleGrid.SearchObj.SearchGrid(ReplaceHelper.ReplaceWhereCond(moduleModel.MenuSql) + string.Format(" and {0}='{1}'", moduleGrid.DetailKeyField, moduleGrid.UnionValue)); tabPage.Text = detailModel.DetailName + "(" + moduleGrid.SearchObj.GridRowCount + "条)"; } this.xtcControl.TabPages.Add(tabPage); } this.xtcControl.ShowTabHeader = this.xtcControl.TabPages.Count > 1 ? DefaultBoolean.True : DefaultBoolean.False; } /// /// 说明:创建控件 /// 创建人:龚宇超 /// 创建日期:2017-11-03 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void CreateControlLocation() { DataTable table = BaseModuleImpl.GetControlLocation(this.SysModel.FormKey, this.Model.ModuleCode); DataTable pagingTable = BaseModuleImpl.GetAddPageData(this.SysModel.FormKey); List tableList = new List(); if (pagingTable != null && pagingTable.Rows.Count > 0) { for (int i = 0; i <= pagingTable.Rows.Count; i++) { if (i == 0) { // 第一页默认详细信息 DataTable pageTable = new DataTable(); DataRow nextItem = pagingTable.Rows[i]; DataRow[] rows = table.Select(string.Format("controlTop<={0}", Convert.ToInt32(nextItem["controlTop"] + ""))); if (rows != null && rows.Length > 0) pageTable = rows.CopyToDataTable(); ModulePanelEx moduleAddControl = this.CreatePageControlLocation(pageTable); moduleAddControl.Dock = DockStyle.Fill; XtraTabPage tabPage = new XtraTabPage(); tabPage.Text = "详细信息"; tabPage.Controls.Add(moduleAddControl); this.xtcControl.TabPages.Add(tabPage); this.FirstModulePageEx = moduleAddControl; } else { // 第二页根据分页显示 DataTable pageTable = new DataTable(); DataRow rowItem = pagingTable.Rows[i - 1]; DataRow nextItem = pagingTable.Rows.Count > i ? pagingTable.Rows[i] : null; DataRow[] rows = table.Select(string.Format("controlTop>={0} and controlTop<={1}", Convert.ToInt32(rowItem["controlTop"] + ""), nextItem == null ? 99999 : Convert.ToInt32(nextItem["controlTop"] + ""))); if (rows != null && rows.Length > 0) pageTable = rows.CopyToDataTable(); ModulePanelEx moduleAddControl = this.CreatePageControlLocation(pageTable); moduleAddControl.Dock = DockStyle.Fill; XtraTabPage tabPage = new XtraTabPage(); tabPage.Text = rowItem["GroupName"] + ""; tabPage.Controls.Add(moduleAddControl); this.xtcControl.TabPages.Add(tabPage); this.OtherModulePageEx.Add(moduleAddControl); } } } else { ModulePanelEx moduleAddControl = this.CreatePageControlLocation(table); moduleAddControl.Dock = DockStyle.Fill; XtraTabPage tabPage = new XtraTabPage(); tabPage.Text = "详细信息"; tabPage.Controls.Add(moduleAddControl); this.xtcControl.TabPages.Add(tabPage); this.FirstModulePageEx = moduleAddControl; } } /// /// 说明:创建单页控件 /// 创建人:龚宇超 /// 创建日期:2019-07-10 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The table. private ModulePanelEx CreatePageControlLocation(DataTable table) { ModulePanelEx moduleAddControl = new ModulePanelEx(); moduleAddControl.IsView = Model.IsView; moduleAddControl.ParentKey = Model.ParentKey; moduleAddControl.ParentValue = Model.ParentValue; moduleAddControl.PrimaryKey = BaseImpl.GetBasePrimaryKey(Model.ModuleCode); moduleAddControl.UnionKey = Model.UnionKey; moduleAddControl.UnionValue = Model.UnionValue; moduleAddControl.PrimaryValue = Model.ObjectId; moduleAddControl.ControlSql = Model.ControlSql; moduleAddControl.OnCloseCallback += new EventHandler(OnCloseCallback); moduleAddControl.InitializeControl(SysModel, Model, table); return moduleAddControl; } /// /// 说明:关闭按钮回调 /// 创建人:龚宇超 /// 创建日期:2017-11-08 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnCloseCallback(object sender, EventArgs e) { this.DialogResult = DialogResult.OK; this.Close(); } /// /// 说明:查询条件执行前 /// 创建人:龚宇超 /// 创建日期:2017-11-10 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The e. protected void OnSearchBefore(object sender, SearchArgs e) { XtraTabPage tabPage = xtcControl.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; } /// /// 说明:查询条件执行后 /// 创建人:龚宇超 /// 创建日期:2017-11-10 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnSearchAfter(object sender, EventArgs e) { XtraTabPage tabPage = xtcControl.SelectedTabPage; if (tabPage != null) { ModuleGridEx moduleGrid = tabPage.Tag as ModuleGridEx; GridDetailModel detailModel = moduleGrid.Tag as GridDetailModel; tabPage.Text = detailModel.DetailName + "(" + moduleGrid.SearchObj.GridRowCount + "条)"; } } /// /// 说明:切换选项卡 /// 创建人:龚宇超 /// 创建日期:2018-04-09 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnSelectedPageChanging(object sender, TabPageChangingEventArgs e) { XtraTabPage page = e.Page; if (page != null) { if (e.PrevPage == xtcControl.TabPages[0] && string.IsNullOrEmpty(this.FirstModulePageEx.PrimaryValue)) { MessageUtil.Show(ResourceKeys.BeforeSaveData); e.Cancel = true; } else { foreach (ModulePanelEx item in OtherModulePageEx) { item.PrimaryValue = this.FirstModulePageEx.PrimaryValue; } } } } /// /// 说明:切换标签刷新主键值 /// 创建人:龚宇超 /// 创建日期:2018-04-09 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void OnSelectedPageChanged(object sender, TabPageChangedEventArgs e) { //XtraTabPage page = e.Page; //if (page != null && page.Tag is ModuleGridEx) //{ // ModuleGridEx gridEx = page.Tag as ModuleGridEx; // GridDetailModel detailModel = gridEx.Tag as GridDetailModel; // gridEx.SearchObj.SearchGrid(); // gridEx.UnionValue = this.ModuleAddControl.PrimaryValue; // page.Text = detailModel.DetailName + "(" + gridEx.SearchObj.GridRowCount + "条)"; //} } private void FrmMain_FormClosed(object sender, FormClosedEventArgs e) { } private void FrmMain_FormClosing(object sender, FormClosingEventArgs e) { if (this.FirstModulePageEx != null && this.FirstModulePageEx.IsCard) { this.FirstModulePageEx.CloseIDCardThread(); } } } }