ab56a9bcf7
SVN-Revision: r240
320 lines
12 KiB
C#
320 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using Lskj.Control.Model;
|
|
using Lskj.Model;
|
|
using DevExpress.XtraReports.Design;
|
|
using Lskj.Business.Impl;
|
|
using DevExpress.XtraGrid.Views.Grid;
|
|
using Lskj.Util;
|
|
using DevExpress.XtraGrid.Columns;
|
|
using Lskj.Business;
|
|
using Lskj.Data;
|
|
using DevExpress.XtraEditors;
|
|
|
|
namespace Lskj.Control
|
|
{
|
|
public partial class TabAddControl : UserControl
|
|
{
|
|
|
|
|
|
public SplitContainerControl splitContainerControl { get { return this.splitMainControl; } }
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 是否加载明细刷新
|
|
/// </summary>
|
|
/// <value><c>true</c> if [_ un refresh]; otherwise, <c>false</c>.</value>
|
|
private bool _UnRefresh
|
|
{
|
|
get
|
|
{
|
|
return Model is DynamicModuleDetailModel || Model is DynamicModuleModel || Model is DynamicProductionModel;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 表一
|
|
/// </summary>
|
|
public GridControlEx gridEx=new GridControlEx();
|
|
/// <summary>
|
|
/// 表二
|
|
/// </summary>
|
|
public ModuleGridEx gridEx2=new ModuleGridEx();
|
|
/// <summary>
|
|
/// 拖拽模式
|
|
/// </summary>
|
|
public bool IsDragDetail;
|
|
/// <summary>
|
|
/// 拖拽目标主键字段
|
|
/// </summary>
|
|
public string DrgaParentPrimaryKey;
|
|
/// <summary>
|
|
/// 主键字段
|
|
/// </summary>
|
|
public string PrimaryKey;
|
|
/// <summary>
|
|
/// 添加数据sql赋值
|
|
/// </summary>
|
|
public string ControlSql;
|
|
/// <summary>
|
|
/// tab标签
|
|
/// </summary>
|
|
private List<GridDetailModel> _gridDetail;
|
|
/// <summary>
|
|
/// tab标签内页签
|
|
/// </summary>
|
|
private List<GridDetailModel> _gridDetail2;
|
|
/// <summary>
|
|
/// The system model
|
|
/// </summary>
|
|
public DynamicModel Model;
|
|
/// <summary>
|
|
/// 父表格
|
|
/// </summary>
|
|
public GridControlEx ParentGridEx;
|
|
/// <summary>
|
|
/// 父容器
|
|
/// </summary>
|
|
public MyControl ParentControlEx;
|
|
|
|
/// <summary>
|
|
/// 右键菜单执行后调用
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
public event EventHandler OnRightCallback;
|
|
|
|
public TabAddControl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:绑定选项卡</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-01-09</para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
public void InitTabPages(List<GridDetailModel> gridDetail)
|
|
{
|
|
this._gridDetail = gridDetail;
|
|
|
|
foreach (GridDetailModel model in this._gridDetail)
|
|
{
|
|
if (model.IsReadOnly)
|
|
{
|
|
GroupBox groupBox = new GroupBox();
|
|
groupBox.Dock = DockStyle.Fill;
|
|
groupBox.Text = model.DetailName;
|
|
|
|
gridEx = new GridControlEx();
|
|
gridEx.Dock = DockStyle.Fill;
|
|
gridEx.Tag = model;
|
|
gridEx.GridView.DoubleClick -= new EventHandler(OnDoubleGridClic);
|
|
gridEx.Model = this.Model;
|
|
gridEx.SetReadOnlyColumns(model.GridColumns, model.GridCustomColumnKey);
|
|
gridEx.SetGridRightMenus(BaseModuleImpl.GetBaseGridRightMenus(model.FormKey), this.Model, OnGridViewRightCallBack);
|
|
gridEx.SetGridRowColors(BaseModuleImpl.GetBaseGridRowColors(model.FormKey));
|
|
|
|
if (model.IsDrag)
|
|
{
|
|
gridEx.GridView.DoubleClick += new EventHandler(OnDoubleGridClic);
|
|
}
|
|
groupBox.Controls.Add(gridEx);
|
|
splitMainControl.Panel1.Controls.Add(groupBox);
|
|
}
|
|
else
|
|
{
|
|
GroupBox groupBox2 = new GroupBox();
|
|
groupBox2.Dock = DockStyle.Fill;
|
|
groupBox2.Text = model.DetailName;
|
|
DynamicModel dyncModel = new DynamicModuleModel(new string[] { model.DetailName, ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, "1", model.UnionModule, "0" });
|
|
model.SystemModel = new ModuleModel(MainImpl.GetSystemdllTab(model.UnionModule));
|
|
if (Model != null)
|
|
model.SystemModel.ParmaryKey = BaseImpl.GetBasePrimaryKey(Model.ModuleCode);
|
|
|
|
gridEx2 = new ModuleGridEx();
|
|
gridEx2.Name = "gridEx";
|
|
gridEx2.Dock = DockStyle.Fill;
|
|
gridEx2.OperShortMode = false; // 不显示简短模式
|
|
gridEx2.VisibleSearchPanel = false;
|
|
gridEx2.VisibleOperPanel = !model.IsReadOnly;
|
|
gridEx2.InitializeControl(model.SystemModel, dyncModel);
|
|
gridEx2.GridControlObj.Tag = model;
|
|
gridEx2.ParentControlEx = this.ParentControlEx;
|
|
this.ParentGridEx = gridEx2.GridControlObj;
|
|
gridEx2.ParentKeyField = string.IsNullOrEmpty(model.UnionParentField) ? model.SystemModel.ParmaryKey : model.UnionParentField;
|
|
gridEx2.DetailKeyField = model.UnionValue;
|
|
//if (IsDragDetail && this.ParentGridEx != null && model.IsDrag)
|
|
//{
|
|
// // 拖拽模式,绑定拖拽对象
|
|
// GridDragGrid dragGrid = new GridDragGrid(gridEx.GridControlObj.GridView, this.ParentGridEx.GridView);
|
|
// dragGrid.OnDragComplete += new GridFragGridCompleteEventHandler(OnDragGridCompleted);
|
|
//}
|
|
|
|
if (model.AutoRefresh && !_UnRefresh)
|
|
gridEx2.SearchObj.SearchGrid();
|
|
groupBox2.Controls.Add(gridEx2);
|
|
splitMainControl.Panel2.Controls.Add(groupBox2);
|
|
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-02-24 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
protected void OnGridViewRightCallBack(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (this.OnRightCallback != null)
|
|
this.OnRightCallback(sender, e);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:加载tab标签里得明细数据</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2018-09-28 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="RowCellClickEventArgs"/> instance containing the event data.</param>
|
|
protected void GridView_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
WaitForm.ShowForm();
|
|
GridDetailModel model = gridEx2.GridControlObj.Tag as GridDetailModel;
|
|
DataRow rowItem = gridEx.GridView.GetFocusedDataRow();
|
|
|
|
if (rowItem != null && model != null)
|
|
{
|
|
string searchSql = this.GetSearchSql(model, rowItem);
|
|
gridEx2.GridControlObj.LastSearchSql = searchSql;
|
|
gridEx2.GridControlObj.SetGridViewDataSource(MainImpl.GetDataTableResult(gridEx2.GridControlObj.LastSearchSql));
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Instance.WriteError(ex);
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
WaitForm.HideForm();
|
|
}
|
|
|
|
}
|
|
/// <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 : this.PrimaryKey;
|
|
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] + "");
|
|
}
|
|
return sqlValue;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:表格双击完成</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2019-08-29 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The e.</param>
|
|
protected void OnDoubleGridClic(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
DataRow[] rowItems = new DataRow[] { gridEx.GridView.GetFocusedDataRow() };
|
|
GridColumnCollection gridColumns = this.ParentGridEx.GridView.Columns;
|
|
DataTable table = this.ParentGridEx.gridControl.DataSource as DataTable;
|
|
foreach (DataRow rowItem in rowItems)
|
|
{
|
|
DataRow newRow = table.NewRow();
|
|
foreach (GridColumn col in gridColumns)
|
|
{
|
|
if ("id".Equals(col.FieldName) || col.FieldName.Equals(this.DrgaParentPrimaryKey)) continue;
|
|
|
|
if (rowItem.Table.Columns.Contains(col.FieldName))
|
|
{
|
|
// 列中是否包含对应字段,包含则使用值
|
|
newRow[col.FieldName] = rowItem[col.FieldName];
|
|
}
|
|
else
|
|
{
|
|
// 未包含字段,则使用控件默认值.
|
|
GridColumnModel model = col.Tag as GridColumnModel;
|
|
string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue);
|
|
|
|
if (!string.IsNullOrEmpty(model.DefaultValue))
|
|
{
|
|
newRow[col.FieldName] = fieldValue;
|
|
}
|
|
}
|
|
}
|
|
table.Rows.Add(newRow);
|
|
}
|
|
|
|
this.ParentGridEx.GridView.ClearSelection();
|
|
this.ParentGridEx.GridView.SelectRowHandler(table.Rows.Count - 1);
|
|
this.ParentGridEx.GridView.UpdateCurrentRow();
|
|
this.ParentGridEx.GridView.ShowEditor();
|
|
}
|
|
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
LogHelper.Instance.WriteError(ex);
|
|
|
|
}
|
|
}
|
|
}
|
|
} |