Files
lserp_cs_6.0/插件库/Lskj.ProductDynamic/FrmMain.cs
T
cyf ab56a9bcf7 基线 SVN r240
SVN-Revision: r240
2025-02-06 06:46:06 +00:00

587 lines
27 KiB
C#

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 变量
/// <summary>
/// 入口模型
/// </summary>
public DynamicProductModel SysModel;
/// <summary>
/// 基础模型
/// </summary>
public ModuleModel Model;
/// <summary>
/// 按钮集合
/// </summary>
public List<ImageButton> imageButtonList = new List<ImageButton>();
/// <summary>
/// 当前选中行
/// </summary>
public DataRow FocusedRow;
/// <summary>
/// 刷新按钮
/// </summary>
public SimpleButton refreshBtn;
/// <summary>
/// 刷新按钮
/// </summary>
public TabControlEx tabObject;
public Dictionary<ImageButton, TabControlEx> tabMainListWith = new Dictionary<ImageButton, TabControlEx>();
public Dictionary<TabControlEx, TabControlEx> tabDetilListWith = new Dictionary<TabControlEx, TabControlEx>();
#endregion
#region 事件
#region 窗体加载时
/// <summary>
/// 窗体加载时
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnFrmMain_Load(object sender, EventArgs e)
{
IninControls();
InitRightMenuInBottom();
}
#endregion
#region 按钮点击事件
/// <summary>
/// 右侧顶部按钮点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
}
}
}
/// <summary>
/// <para>说明:数据行发生改变加载明细</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期: </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventArgs"/> instance containing the event data.</param>
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();
}
}
/// <summary>
/// 刷新按钮点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
/// <summary>
/// 右侧底部主按钮点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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());
}
}
/// <summary>
/// 右侧底部明细按钮点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnBottomDetailSimpleButton_Click(object sender, EventArgs e)
{
XtraTabPage tabPage = this.tabControl.TabControlObj.SelectedTabPage;
Object moduleObject = tabPage.Controls.Cast<Object>().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 方法
/// <summary>
/// 构造控件
/// </summary>
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());//默认执行第一个按钮
}
}
/// <summary>
/// 加载下方按钮
/// </summary>
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;
}
}
}
/// <summary>
/// 缓存数据
/// </summary>
/// <param name="imageBtn"></param>
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<GridDetailModel> details = new List<GridDetailModel>();//表格明细对象的集合
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<Object>().FirstOrDefault();
ModuleGridEx moduleGridEx = null;
if (moduleObject is ModuleGridEx)
{
moduleGridEx = moduleObject as ModuleGridEx;
TabControlEx tabDetailListEx = new TabControlEx();
List<GridDetailModel> Uniodetails = new List<GridDetailModel>();//表格明细对象的集合
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);
}
}
/// <summary>
/// <para>说明:获取关联底部多标签数据</para>
/// <para>创建人:王一帆</para>
/// <para>创建日期:2022-09-08 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
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);
}
}
}
}
}
/// <summary>
/// <para>说明:获取底部多标签数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-12-19 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
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);
}
}
}
}
}
/// <summary>
/// <para>说明:设置表格数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-29 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="tabPage">The tab page.</param>
/// <param name="gridControl">The grid control.</param>
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<Object>().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));
}
}
/// <summary>
/// <para>说明:获取查询条件</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-22 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="model">The model.</param>
/// <param name="rowItem">The row item.</param>
/// <returns>System.String.</returns>
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
}
}