Files
cyf ab56a9bcf7 基线 SVN r240
SVN-Revision: r240
2025-02-06 06:46:06 +00:00

412 lines
17 KiB
C#

/******************************
* 说明:基础档案添加界面
* 创建人:龚宇超
* 创建日期:2017-11-02
* 修改人:
* 修改日期:
* 修改备注:
* 版本:1.0.0.0
******************************/
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;
using Lskj.Control;
using Lskj.Control.Model;
using Lskj.Util;
using Lskj.Business.Impl;
using Lskj.Model;
using DevExpress.XtraTab;
using DevExpress.Utils;
using Lskj.Data;
namespace Lskj.PubAdd
{
/// <summary>
/// 基础档案添加界面
/// </summary>
public partial class FrmMain : BaseForm
{
/// <summary>
/// 系统模块实体对象
/// </summary>
/// <value>The system model.</value>
public ModuleModel SysModel { get; private set; }
/// <summary>
/// 调用动态链接库默认传递参数
/// </summary>
public DynamicAddModel Model;
/// <summary>
/// 第一页控件
/// </summary>
public ModulePanelEx FirstModulePageEx;
/// <summary>
/// 除主页剩下页面
/// </summary>
public List<ModulePanelEx> OtherModulePageEx = new List<ModulePanelEx>();
public FrmMain()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
WaitForm.ShowForm();
try
{
this.SysModel = new ModuleModel(MainImpl.GetSystemdllTab(Model.ModuleCode));
this.CreateControlLocation();
this.SetControlPanelSize();
this.CreateTabDetail();
}
catch (Exception ex)
{
LogHelper.Instance.WriteError(ex);
MessageUtil.Show(ex.Message + "\r\n" + ex.StackTrace);
}
this.Text = Model.FormText + (string.IsNullOrWhiteSpace(Model.ObjectId) ? "" : "[" + Model.ObjectId + "]");
WaitForm.HideForm();
}
/// <summary>
/// <para>说明:设置窗口大小</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-03 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="menuCode">The menu code.</param>
private void SetControlPanelSize()
{
DataRow item = BaseModuleImpl.GetControlParentSize(this.SysModel.FormKey);
if (item != null)
{
int otherHeight = 80;
bool topVisible = false;
if ("lskj.pubadd.dll".Equals((this.SysModel.MenuAddName).ToLower()) && !this.SysModel.AnyAdd)
{
otherHeight = 130;
topVisible = true;
}
this.FirstModulePageEx.SetTopPanelVisible(topVisible);
this.Width = Convert.ToInt32(item["width"] + "");
this.Height =Convert.ToInt32(item["height"] + "") + otherHeight;
this.Left = (Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2;
this.Top = (Screen.PrimaryScreen.WorkingArea.Height - this.Height) / 2;
if ((this.Width > Screen.PrimaryScreen.WorkingArea.Width) || (this.Height > Screen.PrimaryScreen.WorkingArea.Height))
this.WindowState = FormWindowState.Maximized;
}
}
/// <summary>
/// <para>说明:初始化多标签</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-10 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void CreateTabDetail()
{
DataTable details = BaseModuleImpl.GetBaseAddTabDetail(Model.ModuleCode);
foreach (DataRow item in details.Rows)
{
string cacheKey = this.Model.ModuleCode + "_" + item["id"] + "";
bool isCache = CacheHelper.Exsits(cacheKey);
XtraTabPage tabPage = new XtraTabPage();
GridDetailModel detailModel = new GridDetailModel(item, null, GridCustomColumnStruct.BaseDetailGridView);
ModuleModel moduleModel = new ModuleModel(MainImpl.GetSystemdllTab(detailModel.UnionModule));
if (isCache)
{
tabPage = CacheHelper.Get<XtraTabPage>(cacheKey);
}
else
{
detailModel.GridColumns = ReportImpl.GetReportDetailColumns(Model.ModuleCode, item["id"] + "");
detailModel.DetailSql = moduleModel.MenuSql;
DynamicAddModel addModel = new DynamicAddModel(new string[] {
detailModel.DetailName,
ERPInfo.Instance.UserId,
ERPInfo.Instance.UserName,
"1",detailModel.UnionModule,"","",""
});
ModuleGridEx moduleGrid = new ModuleGridEx();
moduleGrid.Dock = DockStyle.Fill;
moduleGrid.Tag = detailModel;
moduleGrid.ParentKeyField = string.IsNullOrEmpty(detailModel.UnionParentField) ? SysModel.ParmaryKey : detailModel.UnionParentField;
moduleGrid.DetailKeyField = detailModel.UnionValue;
moduleGrid.UnionKey = moduleGrid.ParentKeyField;
moduleGrid.UnionValue = this.FirstModulePageEx.ControlObj.GetControlValue(moduleGrid.UnionKey); //Model.ObjectId;
moduleGrid.InitializeControl(moduleModel, addModel);
moduleGrid.SearchObj.OnSearchBeforeCallBack += new SearchEventHandler(OnSearchBefore);
moduleGrid.SearchObj.OnSearchAfterCallBack += new EventHandler(OnSearchAfter);
tabPage.Text = detailModel.DetailName;
tabPage.Tag = moduleGrid;
tabPage.Controls.Add(moduleGrid);
CacheHelper.Add(cacheKey, tabPage);
}
if (detailModel.AutoRefresh)
{
// 自动刷新
ModuleGridEx moduleGrid = tabPage.Tag as ModuleGridEx;
moduleGrid.SearchObj.SearchGrid(ReplaceHelper.ReplaceWhereCond(moduleModel.MenuSql) + string.Format(" and {0}='{1}'", moduleGrid.DetailKeyField, moduleGrid.UnionValue));
tabPage.Text = detailModel.DetailName + "(" + moduleGrid.SearchObj.GridRowCount + "条)";
}
this.xtcControl.TabPages.Add(tabPage);
}
this.xtcControl.ShowTabHeader = this.xtcControl.TabPages.Count > 1 ? DefaultBoolean.True : DefaultBoolean.False;
}
/// <summary>
/// <para>说明:创建控件</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-03 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void CreateControlLocation()
{
DataTable table = BaseModuleImpl.GetControlLocation(this.SysModel.FormKey, this.Model.ModuleCode);
DataTable pagingTable = BaseModuleImpl.GetAddPageData(this.SysModel.FormKey);
List<DataTable> tableList = new List<DataTable>();
if (pagingTable != null && pagingTable.Rows.Count > 0)
{
for (int i = 0; i <= pagingTable.Rows.Count; i++)
{
if (i == 0)
{
// 第一页默认详细信息
DataTable pageTable = new DataTable();
DataRow nextItem = pagingTable.Rows[i];
DataRow[] rows = table.Select(string.Format("controlTop<={0}", Convert.ToInt32(nextItem["controlTop"] + "")));
if (rows != null && rows.Length > 0)
pageTable = rows.CopyToDataTable();
ModulePanelEx moduleAddControl = this.CreatePageControlLocation(pageTable);
moduleAddControl.Dock = DockStyle.Fill;
XtraTabPage tabPage = new XtraTabPage();
tabPage.Text = "详细信息";
tabPage.Controls.Add(moduleAddControl);
this.xtcControl.TabPages.Add(tabPage);
this.FirstModulePageEx = moduleAddControl;
}
else
{
// 第二页根据分页显示
DataTable pageTable = new DataTable();
DataRow rowItem = pagingTable.Rows[i - 1];
DataRow nextItem = pagingTable.Rows.Count > i ? pagingTable.Rows[i] : null;
DataRow[] rows = table.Select(string.Format("controlTop>={0} and controlTop<={1}", Convert.ToInt32(rowItem["controlTop"] + ""), nextItem == null ? 99999 : Convert.ToInt32(nextItem["controlTop"] + "")));
if (rows != null && rows.Length > 0)
pageTable = rows.CopyToDataTable();
ModulePanelEx moduleAddControl = this.CreatePageControlLocation(pageTable);
moduleAddControl.Dock = DockStyle.Fill;
XtraTabPage tabPage = new XtraTabPage();
tabPage.Text = rowItem["GroupName"] + "";
tabPage.Controls.Add(moduleAddControl);
this.xtcControl.TabPages.Add(tabPage);
this.OtherModulePageEx.Add(moduleAddControl);
}
}
}
else
{
ModulePanelEx moduleAddControl = this.CreatePageControlLocation(table);
moduleAddControl.Dock = DockStyle.Fill;
XtraTabPage tabPage = new XtraTabPage();
tabPage.Text = "详细信息";
tabPage.Controls.Add(moduleAddControl);
this.xtcControl.TabPages.Add(tabPage);
this.FirstModulePageEx = moduleAddControl;
}
}
/// <summary>
/// <para>说明:创建单页控件</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-10 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="table">The table.</param>
private ModulePanelEx CreatePageControlLocation(DataTable table)
{
ModulePanelEx moduleAddControl = new ModulePanelEx();
moduleAddControl.IsView = Model.IsView;
moduleAddControl.ParentKey = Model.ParentKey;
moduleAddControl.ParentValue = Model.ParentValue;
moduleAddControl.PrimaryKey = BaseImpl.GetBasePrimaryKey(Model.ModuleCode);
moduleAddControl.UnionKey = Model.UnionKey;
moduleAddControl.UnionValue = Model.UnionValue;
moduleAddControl.PrimaryValue = Model.ObjectId;
moduleAddControl.ControlSql = Model.ControlSql;
moduleAddControl.OnCloseCallback += new EventHandler(OnCloseCallback);
moduleAddControl.InitializeControl(SysModel, Model, table);
return moduleAddControl;
}
/// <summary>
/// <para>说明:关闭按钮回调</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-08 </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="EventArgs"/> instance containing the event data.</param>
protected void OnCloseCallback(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
this.Close();
}
/// <summary>
/// <para>说明:查询条件执行前</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-10 </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 OnSearchBefore(object sender, SearchArgs e)
{
XtraTabPage tabPage = xtcControl.SelectedTabPage;
if (tabPage != null)
{
ModuleGridEx moduleGrid = tabPage.Tag as ModuleGridEx;
GridDetailModel detailModel = moduleGrid.Tag as GridDetailModel;
moduleGrid.SearchObj.SearchGrid(detailModel.DetailSql + string.Format(" and {0}='{1}'", moduleGrid.DetailKeyField, moduleGrid.UnionValue));
}
e.Continue = false;
}
/// <summary>
/// <para>说明:查询条件执行后</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-10 </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="EventArgs"/> instance containing the event data.</param>
protected void OnSearchAfter(object sender, EventArgs e)
{
XtraTabPage tabPage = xtcControl.SelectedTabPage;
if (tabPage != null)
{
ModuleGridEx moduleGrid = tabPage.Tag as ModuleGridEx;
GridDetailModel detailModel = moduleGrid.Tag as GridDetailModel;
tabPage.Text = detailModel.DetailName + "(" + moduleGrid.SearchObj.GridRowCount + "条)";
}
}
/// <summary>
/// <para>说明:切换选项卡</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-04-09 </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="TabPageChangingEventArgs"/> instance containing the event data.</param>
protected void OnSelectedPageChanging(object sender, TabPageChangingEventArgs e)
{
XtraTabPage page = e.Page;
if (page != null)
{
if (e.PrevPage == xtcControl.TabPages[0] && string.IsNullOrEmpty(this.FirstModulePageEx.PrimaryValue))
{
MessageUtil.Show(ResourceKeys.BeforeSaveData);
e.Cancel = true;
}
else
{
foreach (ModulePanelEx item in OtherModulePageEx)
{
item.PrimaryValue = this.FirstModulePageEx.PrimaryValue;
}
}
}
}
/// <summary>
/// <para>说明:切换标签刷新主键值</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-04-09 </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="TabPageChangedEventArgs"/> instance containing the event data.</param>
private void OnSelectedPageChanged(object sender, TabPageChangedEventArgs e)
{
//XtraTabPage page = e.Page;
//if (page != null && page.Tag is ModuleGridEx)
//{
// ModuleGridEx gridEx = page.Tag as ModuleGridEx;
// GridDetailModel detailModel = gridEx.Tag as GridDetailModel;
// gridEx.SearchObj.SearchGrid();
// gridEx.UnionValue = this.ModuleAddControl.PrimaryValue;
// page.Text = detailModel.DetailName + "(" + gridEx.SearchObj.GridRowCount + "条)";
//}
}
private void FrmMain_FormClosed(object sender, FormClosedEventArgs e)
{
}
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (this.FirstModulePageEx != null && this.FirstModulePageEx.IsCard)
{
this.FirstModulePageEx.CloseIDCardThread();
}
}
}
}