二开系列之表单保存二开示例
2020-06-22 17:18:56
16273次阅读
0个评论
using ES.LibraryV2.Database;
using ES.UIV2.WebControl.Form;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using ES.LibraryV2.Helper;
namespace ES.DMV1.Form.FormEventHandler
{
/// <summary>
/// 表单主子表保存二开取值示例
/// </summary>
public class FormDemoEventHandler : IESFormEventHandler
{
public IESFormEventHandler Create()
{
return new FormDemoEventHandler();
}
public void FormLoaded(ESFormArgs formArgs)
{
}
public void FormLoading(ESFormArgs formArgs)
{
}
/// <summary>
/// 保存后(推荐)
/// </summary>
/// <param name="formArgs"></param>
public void FormSaved(ESFormArgs formArgs)
{
//if (formArgs.DataOperationType == ESDataOperationType.Add)
{
// 启用事务
ESSessionFactoryManager.Instance.BeginTrans();
#region [获取主表信息]
string id = formArgs.KeyValue;
var mainFormData = formArgs.FormDbData.GetByTableName("ES_HEAD");
IDictionary mainData = new Hashtable();
mainData["ID"] = id;
mainData["NAME"] = mainFormData[0].ESGetProperty("NAME", true).ESConvert2StringEmptyDefault(); // 主表字段
mainData["CODE"] = mainFormData[0].ESGetProperty("CODE", true).ESConvert2StringEmptyDefault(); // 主表字段
#endregion
#region [获取子表信息]
IList childFormDatas = formArgs.FormDbData.GetByTableName("ES_HEAD_DETAIL");
IList<IDictionary> childDatas = new List<IDictionary>();
IDictionary childData;
foreach (var childFromdata in childFormDatas)
{
childData = new Hashtable();
childData["ID"] = childFromdata.ESGetProperty("ID", true).ESConvert2StringEmptyDefault(); // 子表字段
childData["NAME"] = childFromdata.ESGetProperty("NAME", true).ESConvert2StringEmptyDefault(); // 子表字段
childDatas.Add(childData);
}
#endregion
// 事务回滚
// ESSessionFactoryManager.Instance.Rollback();
//formArgs.FormEventResult = ESFormEventResult.SaveFailure;
//formArgs.EventMessage = "没有新增权限";
//return;
}
}
/// <summary>
/// 保存前
/// </summary>
/// <param name="formArgs"></param>
public void FormSaving(ESFormArgs formArgs)
{
if (formArgs.DataOperationType == ESDataOperationType.Add)
{
#region [获取主表信息]
string xpath = string.Format("//d:{0}", "ES_HEAD"); // 主表表名
XmlElement xElem = (System.Xml.XmlElement)formArgs.FormDataXml.SelectSingleNode(xpath, formArgs.FormDataNsResolver);
IDictionary mainData = new Hashtable();
mainData["ID"] = xElem.GetAttribute("ID"); // 主表字段
mainData["NAME"] = xElem.GetAttribute("NAME"); // 主表字段
#endregion
#region [获取子表信息]
IList<IDictionary> childDatas = new List<IDictionary>();
IDictionary childData;
string childxpath = string.Format("//d:{0}", "ES_HEAD_DETAIL"); // 子表表名
XmlNodeList childNodes = formArgs.FormDataXml.SelectNodes(childxpath, formArgs.FormDataNsResolver);
foreach (XmlElement xelem in childNodes)
{
childData = new Hashtable();
childData["ID"] = xelem.GetAttribute("ID"); // 子表字段
childData["NAME"] = xelem.GetAttribute("NAME"); // 子表字段
childDatas.Add(childData);
}
// 推荐使用上面的不推荐下面的,上面的能避免空指针
//foreach (XmlNode xNode in nodes)
//{
// childData = new Hashtable();
// childData["ID"] = xNode.Attributes["ID"].Value; // 子表字段
// childData["WEIGHT"] = xNode.Attributes["WEIGHT"].Value; // 子表字段
// childDatas.Add(childData);
//}
#endregion
//formArgs.FormEventResult = ESFormEventResult.SaveFailure;
//formArgs.EventMessage = "没有新增权限";
//return;
}
}
}
}
using ES.UIV2.WebControl.Form;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using ES.LibraryV2.Helper;
namespace ES.DMV1.Form.FormEventHandler
{
/// <summary>
/// 表单主子表保存二开取值示例
/// </summary>
public class FormDemoEventHandler : IESFormEventHandler
{
public IESFormEventHandler Create()
{
return new FormDemoEventHandler();
}
public void FormLoaded(ESFormArgs formArgs)
{
}
public void FormLoading(ESFormArgs formArgs)
{
}
/// <summary>
/// 保存后(推荐)
/// </summary>
/// <param name="formArgs"></param>
public void FormSaved(ESFormArgs formArgs)
{
//if (formArgs.DataOperationType == ESDataOperationType.Add)
{
// 启用事务
ESSessionFactoryManager.Instance.BeginTrans();
#region [获取主表信息]
string id = formArgs.KeyValue;
var mainFormData = formArgs.FormDbData.GetByTableName("ES_HEAD");
IDictionary mainData = new Hashtable();
mainData["ID"] = id;
mainData["NAME"] = mainFormData[0].ESGetProperty("NAME", true).ESConvert2StringEmptyDefault(); // 主表字段
mainData["CODE"] = mainFormData[0].ESGetProperty("CODE", true).ESConvert2StringEmptyDefault(); // 主表字段
#endregion
#region [获取子表信息]
IList childFormDatas = formArgs.FormDbData.GetByTableName("ES_HEAD_DETAIL");
IList<IDictionary> childDatas = new List<IDictionary>();
IDictionary childData;
foreach (var childFromdata in childFormDatas)
{
childData = new Hashtable();
childData["ID"] = childFromdata.ESGetProperty("ID", true).ESConvert2StringEmptyDefault(); // 子表字段
childData["NAME"] = childFromdata.ESGetProperty("NAME", true).ESConvert2StringEmptyDefault(); // 子表字段
childDatas.Add(childData);
}
#endregion
// 事务回滚
// ESSessionFactoryManager.Instance.Rollback();
//formArgs.FormEventResult = ESFormEventResult.SaveFailure;
//formArgs.EventMessage = "没有新增权限";
//return;
}
}
/// <summary>
/// 保存前
/// </summary>
/// <param name="formArgs"></param>
public void FormSaving(ESFormArgs formArgs)
{
if (formArgs.DataOperationType == ESDataOperationType.Add)
{
#region [获取主表信息]
string xpath = string.Format("//d:{0}", "ES_HEAD"); // 主表表名
XmlElement xElem = (System.Xml.XmlElement)formArgs.FormDataXml.SelectSingleNode(xpath, formArgs.FormDataNsResolver);
IDictionary mainData = new Hashtable();
mainData["ID"] = xElem.GetAttribute("ID"); // 主表字段
mainData["NAME"] = xElem.GetAttribute("NAME"); // 主表字段
#endregion
#region [获取子表信息]
IList<IDictionary> childDatas = new List<IDictionary>();
IDictionary childData;
string childxpath = string.Format("//d:{0}", "ES_HEAD_DETAIL"); // 子表表名
XmlNodeList childNodes = formArgs.FormDataXml.SelectNodes(childxpath, formArgs.FormDataNsResolver);
foreach (XmlElement xelem in childNodes)
{
childData = new Hashtable();
childData["ID"] = xelem.GetAttribute("ID"); // 子表字段
childData["NAME"] = xelem.GetAttribute("NAME"); // 子表字段
childDatas.Add(childData);
}
// 推荐使用上面的不推荐下面的,上面的能避免空指针
//foreach (XmlNode xNode in nodes)
//{
// childData = new Hashtable();
// childData["ID"] = xNode.Attributes["ID"].Value; // 子表字段
// childData["WEIGHT"] = xNode.Attributes["WEIGHT"].Value; // 子表字段
// childDatas.Add(childData);
//}
#endregion
//formArgs.FormEventResult = ESFormEventResult.SaveFailure;
//formArgs.EventMessage = "没有新增权限";
//return;
}
}
}
}
0
0