using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraTab;
using Lskj.Business;
using Lskj.Business.Impl;
using Lskj.Control;
using Lskj.Control.Model;
using Lskj.Model;
using Lskj.Util;
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;
namespace Lskj.PubBillSpecial
{
public partial class FrmSource : BaseForm
{
///
/// 系统模块实体对象
///
/// The system model.
public ModuleModel SysModel { get; private set; }
///
/// 底部表格数据
///
public List Details;
///
///主表条件控件
///
public MyControl SearchMainObj;
///
/// 底部多标签控件
///
public XtraTabControl TabObj { get { return this.tcButtom.TabControlObj; } }
///
/// 调用动态链接库默认传递参数对象
///
public DynamicModel Model { get; private set; }
///
/// 上一次选中行
///
public int LastFocusedRowHandle;
///
/// 主键字段
///
public string PrimaryKey;
///
/// 主键字段
///
public string PrimaryValue;
///
/// 返回主键值
///
public string ReturnPrimaryValue;
///
/// 红蓝单据
///
public string DocumentColor;
///
/// 隐藏固定按钮(继续制单)
///
public bool isHideButton;
public FrmSource()
{
InitializeComponent();
}
public FrmSource(string moduleCode, DynamicModel dyncModel, bool MaxWindow, bool ishidebutton=false)
{
InitializeComponent();
this.isHideButton = ishidebutton;
this.WindowState = MaxWindow ? FormWindowState.Maximized : FormWindowState.Normal;
this.Model = dyncModel;
//根据传入的模块号获取模块信息
DataRow modelRow = MainImpl.GetSystemdllTab(moduleCode);//获取模块信息
if (modelRow == null)
{
MessageUtil.Show("模块编号[" + moduleCode + "],配置错误!\r\n该模块信息未找到!");
return;
}
this.SysModel = new ModuleModel(modelRow);
this.InitializeControl();
this.InitializePages();
this.scc_container.SplitterMoved += Scc_container_SplitterMoved;
}
///
/// 初始化主表
///
public void InitializeControl()
{
DataTable mainGridColumns = BaseModuleImpl.GetBaseGridColumns(this.SysModel.ModeCode);
this.gcMain.SetReadOnlyColumns(mainGridColumns, GridCustomColumnStruct.BaseMainGridView + this.SysModel.FormKey);//主表列配置
DataTable RightMenus = BaseModuleImpl.GetBaseGridRightMenus(this.SysModel.ModeCode);//右键
int j = 0, x = simpleButton1.Left;
if (isHideButton)
{
x = simpleButton1.Left + simpleButton1.Width;
this.simpleButton1.Visible = false;
}
foreach (DataRow item in RightMenus.Rows)
{
SimpleButton itemCommon = new SimpleButton();
//itemCommon.Enabled = false;
//itemCommon.AutoSize = true;
if (item["orderid"].Equals("9999")) continue;
itemCommon.Text = item["menuname"] + "";
itemCommon.Tag = item;
itemCommon.Size = new System.Drawing.Size(90, 30);
itemCommon.Font = new Font("宋体", 10);
itemCommon.Click += new EventHandler(itemCommon_Click);
itemCommon.Location = new Point(x-100, simpleButton1.Top);
itemCommon.Anchor = AnchorStyles.Top | AnchorStyles.Right;
plm_bottom.Controls.Add(itemCommon);
x -= 100;
if (RightMenus.Columns.Contains("menuCond"))
{
itemCommon.Enabled = ValidateCond(item["menuCond"] + "", null);
}
j++;
}
this.SearchMainObj = new MyControl(this.SysModel.MenuSql, gcMain, null, null, null);//构建主表条件,mycontrol
this.SearchMainObj.OnDataSourceBindCallBack += new EventHandler(OnDataSourceBindCallBack);
DataTable queryTable = BaseModuleImpl.GetCustomQueryFields(this.SysModel.CondKey);//加载自定义配置字段
if (queryTable != null && queryTable.Rows.Count > 0)
{
plm_top.Controls.Clear();
this.SearchMainObj.InitSearchControl(queryTable, this.plm_top, null, null, this.SysModel.ConditionRefresh);
}
else
{
this.plm_top.Visible = false;
}
}
private void OnDataSourceBindCallBack(object sender, EventArgs e)
{
this.SearchMainObj.SearchGrid();
}
///
/// 按钮点击
///
///
///
private void itemCommon_Click(object sender, EventArgs e)
{
try
{
DataRow rowItem = this.gcMain.GetViewFocusedDataRow();
if (rowItem != null)
{
SimpleButton btn = sender as SimpleButton;
DataRow TagItem = btn.Tag as DataRow;
GridRightMenuModel model = new GridRightMenuModel(TagItem);
CommonMenu menu = new CommonMenu(this.Model, this.SearchMainObj, this.gcMain);
menu.ApplyBefore += new CommonToolApplyEventHandler(OnMenuApplyBefore);
if ((TagItem["orderid"]+"").Equals("8888"))
{
menu.ReturnStoredProcedureValue += Menu_ReturnStoredProcedureValue;
}
menu.Apply(TagItem);
if (model != null && model.Refresh)
{
this.SearchMainObj.SearchLastGrid();
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 替换参数前执行
///
///
private void OnMenuApplyBefore(ApplyArgs e)
{
string[] paramList = new string[e.MemuModel.ParamList.Count];
DataRow rowItem = this.gcMain.GetViewFocusedDataRow();
for (int i = 0; i < e.MemuModel.ParamList.Count; i++)
{
string item = e.MemuModel.ParamList[i];
List condition = ReplaceHelper.GetParamFields(item);
foreach (string cond in condition)
{
if (cond.Equals("{DocumentColor}", StringComparison.OrdinalIgnoreCase))
{
item = ReplaceHelper.ReplaceParamToValue(item, cond, this.DocumentColor);
}
if (cond.Equals("{" + this.PrimaryKey + "}", StringComparison.OrdinalIgnoreCase))
{
if (!rowItem.Table.Columns.Contains(this.PrimaryKey))
{
item = ReplaceHelper.ReplaceParamToValue(item, cond, this.PrimaryValue);
}
}
}
paramList[i] = item;
}
e.MemuModel.ParamList = paramList.ToList();
}
///
/// 判断按钮条件
///
///
public void SetButtonStatus(DataRow rowItem = null)
{
foreach (System.Windows.Forms.Control control in plm_bottom.Controls)
{
if (control is SimpleButton)
{
SimpleButton button = control as SimpleButton;
DataRow dr = button.Tag as DataRow;
if (dr != null && dr.Table.Columns.Contains("menuCond"))
{
string menuCond = dr["menuCond"] + "";
button.Enabled = ValidateCond(menuCond, rowItem);
}
}
}
}
///
/// 说明:初始化底部多标签数据
/// 创建人:龚宇超
/// 创建日期:2017-11-21
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
protected void InitializePages()
{
//获取对应的明细
this.Details = GetDetails();
if (this.Details == null || this.Details.Count == 0)
{
this.scc_container.PanelVisibility = SplitPanelVisibility.Panel1;
}
else
{
this.InitlizeSpiltLocation();
this.gcMain.GridView.FocusedRowObjectChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventHandler(OnGridViewFocusedRowObjectChanged);
this.gcMain.GridView.MouseDown += new MouseEventHandler(GridView_MouseDown);
this.SearchMainObj.OnSearchAfterCallBack += SearchObj_ClearDetails;
this.SearchMainObj.OnLastQueryTriggered += SearchObj_ClearDetails;
//this.InitilizeGridViewEvent();
////下方明细中ModuleGridEx执行右键后是否刷新明细
//if (this.SysModel.RefreshDetails)
//{
// tcButtom.OnDetailRightCallback += OnGridViewRightCallBack;
//}
this.tcButtom.Model = this.Model;
this.tcButtom.DrgaParentPrimaryKey = this.SysModel.ParmaryKey;
//this.tcButtom.IsDragDetail = this.IsDragDetail;
this.tcButtom.ParentControlEx = this.SearchMainObj;
this.tcButtom.ParentGridEx = this.gcMain;
this.tcButtom.InitTabPages(this.Details);
//this.tcButtom.OnRightCallback += new EventHandler(OnGridViewRightCallBack);
//明细只有一个选项卡时是否隐藏
if (SystemInfo.Instance.HidingIndividualDetails)
{
this.TabObj.ShowTabHeader = this.TabObj.TabPages.Count == 1 ? DefaultBoolean.False : DefaultBoolean.Default;
}
}
}
///
/// 说明:拿到底部表格数据
/// 创建人:龚宇超
/// 创建日期:2017-11-21
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// List<GridDetailModel>.
private List GetDetails()
{
List details = new List();//表格明细对象的集合
DataTable table = BaseModuleImpl.GetBaseDetailPages(this.SysModel.ModeCode);// 根据传入的模块编号获得基础档案底部标签的数据
foreach (DataRow item in table.Rows)
{
DataTable gridColumns = ReportImpl.GetReportDetailColumns(this.SysModel.ModeCode, item["id"] + "");//获取报表明细列
details.Add(new GridDetailModel(item, gridColumns, GridCustomColumnStruct.BaseDetailGridView));
}
return details;
}
///
/// 说明:设置分割条位置
/// 创建人:龚宇超
/// 创建日期:2018-02-01
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
protected void InitlizeSpiltLocation()
{
try
{
string htight = IniHelper.Read(string.Format("PubBillSpecial_height_{0}", this.SysModel.ModeCode));
if (!string.IsNullOrEmpty(htight))
{
this.scc_container.SplitterPosition = Convert.ToInt32(htight);
}
}
catch (Exception ex)
{
LogHelper.Instance.WriteError(ex);
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 分隔符移动
///
///
///
private void Scc_container_SplitterMoved(object sender, EventArgs e)
{
try
{
if (this.SysModel != null)
{
IniHelper.Write(string.Format("PubBillSpecial_height_{0}", this.SysModel.ModeCode), this.scc_container.SplitterPosition + "");
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 加载明细数据
///
///
///
private void GridView_MouseDown(object sender, MouseEventArgs e)
{
GridView view = sender as GridView;
// 计算点击位置的信息
DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hitInfo = view.CalcHitInfo(e.X, e.Y);
// 检查点击是否在行内
if (hitInfo.InRowCell)
{
// 获取点击的行句柄
int rowHandle = hitInfo.RowHandle;
if (LastFocusedRowHandle == rowHandle)
{
//和上一次点击行一致就刷新数据原
this.SetDetailGridDataSource();
}
}
}
///
/// 主表数据查询后发生
///
///
///
private void SearchObj_ClearDetails(object sender, EventArgs e)
{
try
{
//主表内容为空时清空所有明细数据
if (this.gcMain.gridControl.DataSourceTable().Rows.Count == 0)
{
OnGridViewFocusedRowObjectChanged(null, null);
}
}
catch (Exception ex)
{
LogHelper.Instance.WriteError(ex);
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show("加载明细数据失败!" + Message);
}
finally
{
WaitForm.HideForm();
}
}
///
/// 说明:数据行发生改变加载明细
/// 创建人:龚宇超
/// 创建日期:
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
protected void OnGridViewFocusedRowObjectChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventArgs e)
{
try
{
WaitForm.ShowForm();
if (e != null) this.LastFocusedRowHandle = e.RowHandle;
this.SetDetailGridDataSource();
}
catch (Exception ex)
{
LogHelper.Instance.WriteError(ex);
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show("加载明细数据失败!" + Message);
}
finally
{
WaitForm.HideForm();
}
}
///
/// 说明:获取底部多标签数据
/// 创建人:龚宇超
/// 创建日期:2017-12-19
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
public void SetDetailGridDataSource(XtraTabPage tabPage = null)
{
DataRow rowItem = this.gcMain.GetViewFocusedDataRow();
this.SetButtonStatus(rowItem);
if (tabPage != null)
{
this.SetTabPageDataSource(tabPage);
}
else
{
foreach (XtraTabPage page in this.TabObj.TabPages)
{
if (rowItem != null && page != null)
{
this.SetTabPageDataSource(page);
}
else
{
SetTabPageDataSource(page, true);
}
}
}
}
///
/// 说明:设置表格数据
/// 创建人:龚宇超
/// 创建日期:2018-01-29
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The tab page.
/// The grid control.
protected void SetTabPageDataSource(XtraTabPage tabPage, bool isNull = false)
{
GridDetailModel model = this.tcButtom.GetGridDetailModel(tabPage);
if (isNull)
{
DataRow leftrow = null;
if (model.IsUnionleft && leftrow != null)//为空状态下若明细关联左侧则去替换数据源
{
string sqlValue = model.IsReadOnly || model.IsChart ? model.DetailSql : model.SystemModel.MenuSql;
if (ReplaceHelper.IsSelect(sqlValue) && !string.IsNullOrEmpty(model.UnionValue))
{
string Conditions = string.Empty;
//是左侧选中行,并且没有替换字段,则使用主表选中行
sqlValue = ReplaceHelper.ReplaceWhereCond(sqlValue) + string.Format(" and {0}='{1}'", model.UnionValue, Conditions);
}
if (!string.IsNullOrEmpty(model.UnionCond))
{
string UnionCond = ReplaceHelper.ReplaceRowParam(leftrow, model.UnionCond);
sqlValue += UnionCond;
}
sqlValue = ReplaceHelper.ReplaceRowParam(leftrow, sqlValue);
this.tcButtom.SetGridDataSource(tabPage, MainImpl.GetDataTableResult(sqlValue));
return;
}
this.tcButtom.SetGridDataSource(tabPage, new DataTable());
return;
}
DataRow rowItem = this.gcMain.GetViewFocusedDataRow();
if (!string.IsNullOrEmpty(SysModel.PageVisbleCond))
{
string condSql = ReplaceHelper.ReplaceRowParam(rowItem, ReplaceHelper.ReplaceUserInfo(SysModel.PageVisbleCond));
// 形如 "1,2,3" 的返回值
string numberList = MainImpl.GetResult(condSql) + "";
// ---------- 判断当前 orderid 是否在列表中 ----------
string orderIdStr = model.Orderid.ToString(); // 统一转成字符串
string[] idArr = numberList.Split(new[] { ',' },
StringSplitOptions.RemoveEmptyEntries);
if (!string.IsNullOrEmpty(numberList) && !idArr.Contains(orderIdStr))
{
tabPage.PageVisible = false;
return; // 不包含当前 orderid,直接退出
}
else
{
tabPage.PageVisible = true;
}
}
Object moduleObject = tabPage.Controls.Cast