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