Files
lserp_cs_6.0/插件库/Lskj.PubBillSpecial/FrmSource.cs
T
cyf 6eeb29c8f7 SVN r781
SVN-Revision: r781
2025-06-24 08:07:32 +00:00

701 lines
28 KiB
C#

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
{
/// <summary>
/// 系统模块实体对象
/// </summary>
/// <value>The system model.</value>
public ModuleModel SysModel { get; private set; }
/// <summary>
/// 底部表格数据
/// </summary>
public List<GridDetailModel> Details;
/// <summary>
///主表条件控件
/// </summary>
public MyControl SearchMainObj;
/// <summary>
/// 底部多标签控件
/// </summary>
public XtraTabControl TabObj { get { return this.tcButtom.TabControlObj; } }
/// <summary>
/// 调用动态链接库默认传递参数对象
/// </summary>
public DynamicModel Model { get; private set; }
/// <summary>
/// 上一次选中行
/// </summary>
public int LastFocusedRowHandle;
/// <summary>
/// 主键字段
/// </summary>
public string PrimaryKey;
/// <summary>
/// 主键值
/// </summary>
public string PrimaryValue;
public FrmSource()
{
InitializeComponent();
}
public FrmSource(string moduleCode, DynamicModel dyncModel, bool MaxWindow)
{
InitializeComponent();
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;
}
/// <summary>
/// 初始化主表
/// </summary>
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;
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(simpleButton1.Left-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();
}
/// <summary>
/// 按钮点击
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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.Apply(TagItem);
if (model != null && model.Refresh)
{
this.SearchMainObj.SearchLastGrid();
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// 判断按钮条件
/// </summary>
/// <param name="rowItem"></param>
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);
}
}
}
}
/// <summary>
/// <para>说明:初始化底部多标签数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-21 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
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;
}
}
}
/// <summary>
/// <para>说明:拿到底部表格数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-21 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <returns>List&lt;GridDetailModel&gt;.</returns>
private List<GridDetailModel> GetDetails()
{
List<GridDetailModel> details = new List<GridDetailModel>();//表格明细对象的集合
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;
}
/// <summary>
/// <para>说明:设置分割条位置</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-02-01 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
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);
}
}
/// <summary>
/// 分隔符移动
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
}
/// <summary>
/// 加载明细数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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();
}
}
}
/// <summary>
/// 主表数据查询后发生
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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();
}
}
/// <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();
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();
}
}
/// <summary>
/// <para>说明:获取底部多标签数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-12-19 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
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);
}
}
}
}
/// <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(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<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)
{
// 加载网页
FrmWebBrowser webView = tabPage.Tag as FrmWebBrowser;
string url = ReplaceHelper.ReplaceRowParam(rowItem, ReplaceHelper.ReplaceUserInfo(model.DetailSql));
url = url.StartsWith("http") ? url : SystemInfo.Instance.OAUrl + url;
//webView.FrmLoad(url);
webView.LoadUrl(url);
webView.Dock = DockStyle.Fill;
webView.Tag = model;
}
else if (tabPage.Tag is FrmWebBrowser2)
{
// 加载网页
FrmWebBrowser2 webView = tabPage.Tag as FrmWebBrowser2;
string url = ReplaceHelper.ReplaceRowParam(rowItem, ReplaceHelper.ReplaceUserInfo(model.DetailSql));
url = url.StartsWith("http") ? url : SystemInfo.Instance.OAUrl + url;
webView.LoadUrl(url);
webView.Dock = DockStyle.Fill;
webView.Tag = model;
}
else if (tabPage.Tag is FrmMiniBlink)
{
// 加载网页
FrmMiniBlink webView = tabPage.Tag as FrmMiniBlink;
string url = ReplaceHelper.ReplaceRowParam(rowItem, ReplaceHelper.ReplaceUserInfo(model.DetailSql));
url = url.StartsWith("http") ? url : SystemInfo.Instance.OAUrl + url;
webView.LoadUrl(url);
webView.Dock = DockStyle.Fill;
webView.Tag = model;
}
else if (tabPage.Tag is TabMultipledetails)
{
TabMultipledetails tabMultipledetails = tabPage.Tag as TabMultipledetails;
tabMultipledetails.SetConditionValues(rowItem);
GridControlEx grdExMain = (tabMultipledetails.SplitMain.Panel1.Tag as GridControlEx);
GridDetailModel MainModel = grdExMain.Tag as GridDetailModel;
string searchMainSql = this.GetSearchSql(MainModel, rowItem);
DataTable firstTable = MainImpl.GetDataTableResult(searchMainSql);
grdExMain.LastSearchSql = searchMainSql;
grdExMain.SetGridViewDataSource(firstTable);
if (tabMultipledetails.SplitMain.Panel2.Tag is GridControlEx)
{
GridControlEx grdExAdditional = (tabMultipledetails.SplitMain.Panel2.Tag as GridControlEx);
GridDetailModel AdditionalModel = grdExAdditional.Tag as GridDetailModel;
string searchAddSql = this.GetSearchSql(AdditionalModel, rowItem);
if (!MainModel.IsUnioDetail)
{
grdExAdditional.LastSearchSql = searchAddSql;
grdExAdditional.SetGridViewDataSource(MainImpl.GetDataTableResult(searchAddSql));
}
//右侧是左侧的明细,左侧没有数据时。右侧赋空值(因为无法触发左侧行改变事件)
if (MainModel.IsUnioDetail && firstTable.Rows.Count == 0)
{
grdExAdditional.LastSearchSql = "";
grdExAdditional.SetGridViewDataSource(new DataTable());
}
}
else if (tabMultipledetails.SplitMain.Panel2.Tag is ChartControlEx)
{
ChartControlEx grdExAdditional = (tabMultipledetails.SplitMain.Panel2.Tag as ChartControlEx);
GridDetailModel AdditionalModel = grdExAdditional.Tag as GridDetailModel;
string searchAddSql = this.GetSearchSql(AdditionalModel, rowItem);
DataTable table = MainImpl.GetDataTableResult(searchAddSql);
grdExAdditional.CreateChart(table);
}
tabPage.Text = MainModel.DetailName + "(" + firstTable.Rows.Count + "条)";
tabPage.Appearance.Header.ForeColor = firstTable.Rows.Count > 0 ? Color.Red : Color.FromArgb(0, 0, 0);
}
else
{
if (model.IsDrag)
{
return;
}
string searchSql = this.GetSearchSql(model, rowItem);
//if (moduleGridEx != null&& moduleGridEx.SearchObj!=null)
//{
// searchSql= moduleGridEx.SearchObj.SetSearchSqlValue(searchSql);
//}
if (tabPage.Tag is GridControlEx)
{
(tabPage.Tag as GridControlEx).LastSearchSql = searchSql;
}
GridView view = this.gcMain.GridView;
//DataTable dataTable = MainImpl.GetDataTableResult(searchSql);//明细数据源
if (model.DynamicDetails && rowItem.Table.Columns.Contains("DisplayColumns")) //
{
this.tcButtom.SetGridDisplayColumns(tabPage, rowItem["DisplayColumns"] + "");
}
this.tcButtom.SetGridDataSource(tabPage, MainImpl.GetDataTableResult(searchSql), view);
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);
moduleGridEx.SelectTheSpecifiedRow();
}
}
}
/// <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, bool isLeft = false)
{
string fieldName = model.UnionParentField;
string sqlValue = model.IsReadOnly || model.IsChart ? model.DetailSql : model.SystemModel.MenuSql;
sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, sqlValue);
DataRow row = this.gcMain.GetViewFocusedDataRow();
if (row != null && isLeft)
{
//先替换左侧选中行,在替换主表
sqlValue = ReplaceHelper.ReplaceRowParam(row, sqlValue);
}
if (ReplaceHelper.IsSelect(sqlValue) && !string.IsNullOrEmpty(model.UnionValue))
{
string Conditions = string.Empty;
//是左侧选中行,并且没有替换字段,则使用主表选中行
Conditions = isLeft ? rowItem.Table.Columns.Contains(fieldName) ? rowItem[fieldName] + "" : row[fieldName] + "" : rowItem[fieldName] + "";
sqlValue = ReplaceHelper.ReplaceWhereCond(sqlValue) + string.Format(" and {0}='{1}'", model.UnionValue, Conditions);
}
if (!string.IsNullOrEmpty(model.UnionCond))
{
string UnionCond = ReplaceHelper.ReplaceRowParam(rowItem, model.UnionCond);
sqlValue += UnionCond;
}
return sqlValue;
}
/// <summary>
/// <para>说明:检查可用条件</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-09 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cond">The cond.</param>
/// <param name="dataRow">The data row.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
private bool ValidateCond(string cond, DataRow dataRow)
{
bool result = false;
string condition = cond;
try
{
if (string.IsNullOrWhiteSpace(cond)) return true;//如果值是空格或者空行,默认正确
cond = ReplaceHelper.ReplaceRowParam(dataRow, cond);
if (cond.StartsWith("@") || cond.StartsWith("!"))
{
result = "1".Equals(BaseImpl.GetDefaultValue(cond));
}
else if (dataRow == null)
{