using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraTab; using Lskj.Business; using Lskj.Business.Impl; using Lskj.Control; using Lskj.Control.Model; using Lskj.Core; using Lskj.Data; using Lskj.Model; using Lskj.ProductDynamic.Controls; using Lskj.Util; using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Linq; using System.Windows.Forms; namespace Lskj.ProductDynamic { public partial class FrmMain : BaseForm { public FrmMain() { InitializeComponent(); this.Load += new EventHandler(OnFrmMain_Load); } #region 变量 /// /// 入口模型 /// public DynamicProductModel SysModel; /// /// 基础模型 /// public ModuleModel Model; /// /// 按钮集合 /// public List imageButtonList = new List(); /// /// 当前选中行 /// public DataRow FocusedRow; /// /// 刷新按钮 /// public SimpleButton refreshBtn; /// /// 刷新按钮 /// public TabControlEx tabObject; public Dictionary tabMainListWith = new Dictionary(); public Dictionary tabDetilListWith = new Dictionary(); #endregion #region 事件 #region 窗体加载时 /// /// 窗体加载时 /// /// /// private void OnFrmMain_Load(object sender, EventArgs e) { IninControls(); InitRightMenuInBottom(); } #endregion #region 按钮点击事件 /// /// 右侧顶部按钮点击事件 /// /// /// private void OnSimpleButton_Click(object sender, EventArgs e) { DevExpress.XtraEditors.LabelControl simpleBtn = (DevExpress.XtraEditors.LabelControl)sender; ImageButton imageBtn = simpleBtn.Parent as ImageButton; this.FocusedRow = imageBtn.focusedRow; imageBtn.NumLabel.Text = imageBtn.productDynamicBtnModel.Amount; this.tipsLabel.Text = imageBtn.productDynamicBtnModel.ProductTip; this.leftTopPanel.Controls.Clear(); tabControl = tabMainListWith[imageBtn]; tabControl.Dock = System.Windows.Forms.DockStyle.Fill; tabControl.BringToFront(); this.leftTopPanel.Controls.Add(this.tabControl); this.bottomMainPanel.Visible = false; this.tipsLablelTitle.Visible = true; if (tabDetilListWith.ContainsKey(tabControl)) { this.bottomMainPanel.Controls.Clear(); tabDetails = tabDetilListWith[tabControl]; this.bottomMainPanel.Visible = true; tabDetails.Dock = System.Windows.Forms.DockStyle.Fill; this.bottomMainPanel.Controls.Add(tabDetails); this.tipsLablelTitle.Visible = false; } this.tabObject = tabControl;//构建主表明细 this.SetDetailGridDataSource(imageBtn.focusedRow); if (tabControl.TabControlObj.TabPages.Count == 1) { tabControl.TabControlObj.ShowTabHeader = DevExpress.Utils.DefaultBoolean.False; } if (tabDetails.TabControlObj.TabPages.Count == 1) { tabDetails.TabControlObj.ShowTabHeader = DevExpress.Utils.DefaultBoolean.False; } int detailPointX = 40; int detailPointY = 0; XtraTabPage RefreshPage = this.tabControl.TabControlObj.SelectedTabPage; GridDetailModel model = this.tabObject.GetGridDetailModel(RefreshPage); this.bottomBtnPanel.Controls.Clear(); if (model!=null&&!string.IsNullOrEmpty(model.UnionModule)) { //构造主表右键按钮 DataTable rightMenuTab = BaseModuleImpl.GetBaseGridRightMenus(model.UnionModule); foreach (DataRow detailRow in rightMenuTab.Rows) { SimpleButton buttonControl = new SimpleButton(); GridRightMenuModel menuModel = new GridRightMenuModel(detailRow); buttonControl.simpleButton.Tag = menuModel; buttonControl.simpleButton.Text = detailRow.Table.Columns.Contains("menuname") && !string.IsNullOrEmpty(detailRow["menuname"] + "") ? detailRow["menuname"] + "" : "按钮"; buttonControl.simpleButton.Click += new EventHandler(OnBottomDetailSimpleButton_Click); buttonControl.Parent = this.bottomBtnPanel; buttonControl.Anchor = AnchorStyles.Left | AnchorStyles.Top; detailPointY = (this.bottomBtnPanel.Height - buttonControl.Height) / 2; buttonControl.Location = new Point(detailPointX, detailPointY); detailPointX = detailPointX + buttonControl.Width + 10; } } } /// /// 说明:数据行发生改变加载明细 /// 创建人:龚宇超 /// 创建日期: /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. protected void OnGridViewFocusedRowObjectChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventArgs e) { try { WaitForm.ShowForm(); this.tabObject = tabDetails; GridView gridView = sender as GridView; this.SetDetailGridDataSource(gridView.GetFocusedDataRow()); } catch (Exception ex) { LogHelper.Instance.WriteError(ex); string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show("加载明细数据失败!" + Message); } finally { WaitForm.HideForm(); } } /// /// 刷新按钮点击事件 /// /// /// private void refreshBtn_Click(object sender, EventArgs e) { this.tipsLabel.Text = ""; //this.imageButtonList.Clear(); //this.rightTopBtnPanel.Controls.Clear(); //IninControls(); this.tabObject = tabControl;//构建主表明细 this.SetDetailGridDataSource(FocusedRow); } /// /// 右侧底部主按钮点击事件 /// /// /// private void OnBottomSimpleButton_Click(object sender, EventArgs e) { DevExpress.XtraEditors.SimpleButton simpleBtn = (DevExpress.XtraEditors.SimpleButton)sender; GridRightMenuModel model = simpleBtn.Tag as GridRightMenuModel; BaseRightMenu menu = new BaseRightMenu(); menu.Model = this.SysModel; if (menu.ExecRightMenu(model, new DataRow[] { FocusedRow }) && model.Refresh) { if (refreshBtn != null) refreshBtn_Click(refreshBtn, new EventArgs()); } } /// /// 右侧底部明细按钮点击事件 /// /// /// private void OnBottomDetailSimpleButton_Click(object sender, EventArgs e) { XtraTabPage tabPage = this.tabControl.TabControlObj.SelectedTabPage; Object moduleObject = tabPage.Controls.Cast().FirstOrDefault(); ModuleGridEx moduleGridEx = null; if (moduleObject is ModuleGridEx) { moduleGridEx = moduleObject as ModuleGridEx; DevExpress.XtraEditors.SimpleButton simpleBtn = (DevExpress.XtraEditors.SimpleButton)sender; GridRightMenuModel model = simpleBtn.Tag as GridRightMenuModel; BaseRightMenu menu = new BaseRightMenu(); menu.Model = moduleGridEx.Model; DataRow[] rowArray = null; if (tabPage.Tag != null && tabPage.Tag is GridControlEx) { GridControlEx gridControl = tabPage.Tag as GridControlEx; rowArray = gridControl.GetViewFocusedDataRows(); } if (!model.Mergeexec && !model.MoreClick && rowArray != null && rowArray.Length > 1) { MessageUtil.Show(string.Format(ResourceKeys.ExecRightMenuOnlyOne, model.MenuName)); return; } if (rowArray != null && rowArray.Length == 0 && model.IsMustSelectRow()) { MessageUtil.Show(ResourceKeys.SelectRowIsNull); return; } if (menu.ExecRightMenu(model, rowArray) && model.Refresh) { if (refreshBtn != null) refreshBtn_Click(refreshBtn, new EventArgs()); } } } #endregion #endregion #region 方法 /// /// 构造控件 /// private void IninControls() { DataRow modelRow = MainImpl.GetSystemdllTab(this.SysModel.ModuleCode); if (modelRow != null) Model = new ModuleModel(modelRow); if (Model != null && !string.IsNullOrEmpty(Model.MenuSql)) { //SysModel.controlSql = "select 1 as jtid"; DataRow row = BaseImpl.GetDataRowResult(SysModel.controlSql); Model.MenuSql = ReplaceHelper.ReplaceRowParam(row, Model.MenuSql); DataTable btnTable = SqlHelper.ExecuteDataTable(Model.MenuSql);//按钮控件表格 if (btnTable != null && btnTable.Rows.Count > 0) { int locationY = 20; for (int i = 0; i < btnTable.Rows.Count; i++) { DataRow btnRow = btnTable.Rows[i]; ImageButton imageBtn = new ImageButton(btnRow); this.imageButtonList.Add(imageBtn); int locationX = (this.rightTopBtnPanel.Width - imageBtn.Width) / 2; imageBtn.SimpleButton.Click += new EventHandler(OnSimpleButton_Click); imageBtn.ImageLabel.Click += new EventHandler(OnSimpleButton_Click); imageBtn.NumLabel.Click += new EventHandler(OnSimpleButton_Click); imageBtn.Location = new Point(locationX, locationY); imageBtn.Parent = this.rightTopBtnPanel; locationY += imageBtn.Height + 10; OnCacheBtn(imageBtn); } } } if (this.imageButtonList[0] != null) { OnSimpleButton_Click(this.imageButtonList[0].SimpleButton, new EventArgs());//默认执行第一个按钮 } } /// /// 加载下方按钮 /// private void InitRightMenuInBottom() { //构造主表右键按钮 DataTable rightMenuTab = BaseModuleImpl.GetBaseGridRightMenus(this.SysModel.ModuleCode); if (rightMenuTab != null && rightMenuTab.Rows.Count > 0) { if (rightMenuTab != null && rightMenuTab.Rows.Count > 0) { int pointX = 20; int pointY = 20; int simpleControlHeight = 0; for (int i = 0; i < rightMenuTab.Rows.Count + 1; i++) { SimpleButton buttonControl = new SimpleButton(); if (i == rightMenuTab.Rows.Count)//最后增加刷新按钮 { refreshBtn = buttonControl; simpleControlHeight = buttonControl.Height; buttonControl.simpleButton.Text = "刷新"; buttonControl.simpleButton.Click += new EventHandler(refreshBtn_Click); } else { DataRow menuRow = rightMenuTab.Rows[i]; GridRightMenuModel menuModel = new GridRightMenuModel(menuRow); simpleControlHeight = buttonControl.Height; buttonControl.simpleButton.Tag = menuModel; buttonControl.simpleButton.Text = menuRow.Table.Columns.Contains("menuname") && !string.IsNullOrEmpty(menuRow["menuname"] + "") ? menuRow["menuname"] + "" : "按钮"; buttonControl.simpleButton.Click += new EventHandler(OnBottomSimpleButton_Click); } buttonControl.Parent = this.rightBottomBtnPanel; buttonControl.Location = new Point(pointX, pointY); if ((i + 1) % 2 == 0) { pointX = 20; pointY += buttonControl.Height + 10; } else { pointX = this.rightBottomBtnPanel.Width - 20 - buttonControl.Width; } } int rowCount = (rightMenuTab.Rows.Count + 1) % 2 == 0 ? (rightMenuTab.Rows.Count + 1) / 2 : (rightMenuTab.Rows.Count + 2) / 2; this.rightBottomBtnPanel.Height = rowCount * simpleControlHeight + (rowCount - 1) * 10 + rowCount * 2 * 2 + 40; } } } /// /// 缓存数据 /// /// private void OnCacheBtn(ImageButton imageBtn = null) { this.FocusedRow = imageBtn.focusedRow; imageBtn.NumLabel.Text = imageBtn.productDynamicBtnModel.Amount; this.tipsLabel.Text = imageBtn.productDynamicBtnModel.ProductTip; TabControlEx tabListEx = new TabControlEx(); List details = new List();//表格明细对象的集合 if (!string.IsNullOrEmpty(imageBtn.productDynamicBtnModel.DetailId)) { string sqlValue = string.Format("select * from p_systemDlltabDetail where tab='{0}' and orderId={1} and ISNULL(isVisible,0)=0 order by orderid", this.SysModel.ModuleCode, imageBtn.productDynamicBtnModel.DetailId); DataTable table = SqlHelper.ExecuteDataTable(sqlValue); if (table == null) return; foreach (DataRow item in table.Rows) { DataTable gridColumns = new DataTable(); gridColumns = ReportImpl.GetReportDetailColumns(this.SysModel.ModuleCode, item["id"] + "");//获取报表明细列 details.Add(new GridDetailModel(item, gridColumns, GridCustomColumnStruct.BaseDetailGridView)); } tabListEx.Model = this.SysModel; tabListEx.InitTabPages(details); XtraTabPage tabPage = tabListEx.TabControlObj.SelectedTabPage; GridDetailModel model = tabListEx.GetGridDetailModel(tabPage); if (model!=null&&!string.IsNullOrEmpty(model.UnionModule)) { Object moduleObject = tabPage.Controls.Cast().FirstOrDefault(); ModuleGridEx moduleGridEx = null; if (moduleObject is ModuleGridEx) { moduleGridEx = moduleObject as ModuleGridEx; TabControlEx tabDetailListEx = new TabControlEx(); List Uniodetails = new List();//表格明细对象的集合 DataTable Uniotable = new DataTable();// 根据传入的模块编号获得基础档案底部标签的数据 Uniotable = BaseModuleImpl.GetBaseDetailPages(model.UnionModule);// 根据传入的模块编号获得基础档案底部标签的数据 foreach (DataRow item in Uniotable.Rows) { DataTable gridColumns = new DataTable(); gridColumns = ReportImpl.GetReportDetailColumns(model.UnionModule, item["id"] + "");//获取报表明细列 Uniodetails.Add(new GridDetailModel(item, gridColumns, GridCustomColumnStruct.BaseDetailGridView)); } if (details.Count > 0) { tabDetailListEx.Model = moduleGridEx.Model; tabDetailListEx.TabControlObj.TabPages.Clear(); tabDetailListEx.InitTabPages(Uniodetails); tabDetailListEx.Visible = true; this.tipsLablelTitle.Visible = false; if (tabPage.Tag is GridControlEx) { (tabPage.Tag as GridControlEx).GridView.FocusedRowObjectChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventHandler(OnGridViewFocusedRowObjectChanged); } tabDetilListWith.Add(tabListEx, tabDetailListEx); } } } tabMainListWith.Add(imageBtn, tabListEx); } } /// /// 说明:获取关联底部多标签数据 /// 创建人:王一帆 /// 创建日期:2022-09-08 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// public void SetUnioDetailGridDataSource(DataRow focusedRow, XtraTabPage tabPage = null) { if (tabPage != null) { this.SetTabPageDataSource(focusedRow, tabPage); } else { DataRow rowItem = focusedRow; if (this.Model.RefreshDetail == "0") { XtraTabPage RefreshPage = this.tabDetails.TabControlObj.SelectedTabPage; if (rowItem != null && RefreshPage != null) { this.SetTabPageDataSource(focusedRow, RefreshPage); } else { SetTabPageDataSource(focusedRow, RefreshPage, true); } } else { foreach (XtraTabPage page in this.tabDetails.TabControlObj.TabPages) { if (rowItem != null && page != null) { this.SetTabPageDataSource(focusedRow, page); } else { SetTabPageDataSource(focusedRow, page, true); } } } } } /// /// 说明:获取底部多标签数据 /// 创建人:龚宇超 /// 创建日期:2017-12-19 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// public void SetDetailGridDataSource(DataRow focusedRow, XtraTabPage tabPage = null) { if (tabPage != null) { this.SetTabPageDataSource(focusedRow, tabPage); } else { DataRow rowItem = focusedRow; if (this.Model.RefreshDetail == "0") { XtraTabPage RefreshPage = this.tabObject.TabControlObj.SelectedTabPage; if (rowItem != null && RefreshPage != null) { this.SetTabPageDataSource(focusedRow, RefreshPage); } else { SetTabPageDataSource(focusedRow, RefreshPage, true); } } else { foreach (XtraTabPage page in this.tabObject.TabControlObj.TabPages) { if (rowItem != null && page != null) { this.SetTabPageDataSource(focusedRow, page); } else { SetTabPageDataSource(focusedRow, page, true); } } } } } /// /// 说明:设置表格数据 /// 创建人:龚宇超 /// 创建日期:2018-01-29 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The tab page. /// The grid control. protected void SetTabPageDataSource(DataRow focusedRow, XtraTabPage tabPage, bool isNull = false) { if (isNull) { this.tabObject.SetGridDataSource(tabPage, new DataTable()); return; } GridDetailModel model = this.tabObject.GetGridDetailModel(tabPage); DataRow rowItem = focusedRow; Object moduleObject = tabPage.Controls.Cast().FirstOrDefault(); ModuleGridEx moduleGridEx = null; if (moduleObject is ModuleGridEx) { moduleGridEx = moduleObject as ModuleGridEx; } if (rowItem != null && model != null) { if (!string.IsNullOrEmpty(model.UnionModule) && (string.IsNullOrEmpty(model.UnionValue) && string.IsNullOrEmpty(model.UnionCond))) return; if (tabPage.Tag is FrmWebBrowser) { // 加载网页 string url = model.DetailSql.StartsWith("http") ? model.DetailSql : SystemInfo.Instance.OAUrl + model.DetailSql; FrmWebBrowser webView = tabPage.Tag as FrmWebBrowser; webView.LoadUrl(ReplaceHelper.ReplaceRowParam(rowItem, ReplaceHelper.ReplaceUserInfo(url))); webView.Dock = DockStyle.Fill; webView.Tag = model; } else { string searchSql = this.GetSearchSql(model, rowItem); if (tabPage.Tag is GridControlEx) { (tabPage.Tag as GridControlEx).LastSearchSql = searchSql; } this.tabObject.SetGridDataSource(tabPage, MainImpl.GetDataTableResult(searchSql)); if (tabPage.Tag is GridControlEx && (tabPage.Tag as GridControlEx).ParentControl != null) (tabPage.Tag as GridControlEx).ParentControl.SetAllControlValue(rowItem); //配置明细直接根据条件加载 if (model.SystemModel != null && 1 == model.SystemModel.isFirstLoad) { (tabPage.Tag as GridControlEx).ParentControl.SearchGrid(); tabPage.Text = model.DetailName + "(" + (tabPage.Tag as GridControlEx).ParentControl.GridRowCount + "条)"; } } if (moduleGridEx != null) moduleGridEx.ParentButtonState(rowItem); } else if (rowItem != null && tabPage.Tag is TabMultipledetails) { TabMultipledetails tabMultipledetails = tabPage.Tag as TabMultipledetails; GridControlEx grdExMain = (tabMultipledetails.SplitMain.Panel1.Tag as GridControlEx); GridControlEx grdExAdditional = (tabMultipledetails.SplitMain.Panel2.Tag as GridControlEx); GridDetailModel MainModel = grdExMain.Tag as GridDetailModel; GridDetailModel AdditionalModel = grdExAdditional.Tag as GridDetailModel; string searchMainSql = this.GetSearchSql(MainModel, rowItem); string searchAddSql = this.GetSearchSql(AdditionalModel, rowItem); DataTable firstTable = MainImpl.GetDataTableResult(searchMainSql); grdExMain.LastSearchSql = searchMainSql; grdExAdditional.LastSearchSql = searchAddSql; grdExMain.SetGridViewDataSource(firstTable); tabPage.Text = MainModel.DetailName + "(" + firstTable.Rows.Count + "条)"; grdExAdditional.SetGridViewDataSource(MainImpl.GetDataTableResult(searchAddSql)); } } /// /// 说明:获取查询条件 /// 创建人:龚宇超 /// 创建日期:2017-11-22 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The model. /// The row item. /// System.String. protected string GetSearchSql(GridDetailModel model, DataRow rowItem) { string fieldName = !string.IsNullOrEmpty(model.UnionParentField) && rowItem.Table.Columns.Contains(model.UnionParentField) ? model.UnionParentField : ""; string sqlValue = model.IsReadOnly || model.IsChart ? model.DetailSql : model.SystemModel.MenuSql; sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, sqlValue); if (ReplaceHelper.IsSelect(sqlValue) && !string.IsNullOrEmpty(model.UnionValue)) { sqlValue = ReplaceHelper.ReplaceWhereCond(sqlValue) + string.Format(" and {0}='{1}'", model.UnionValue, rowItem[fieldName] + ""); } if (!string.IsNullOrEmpty(model.UnionCond)) { string UnionCond = ReplaceHelper.ReplaceRowParam(rowItem, model.UnionCond); sqlValue += UnionCond; } return sqlValue; } #endregion } }