jqentitymanage
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web;
using System.Xml;
using HraWeb.Common;
using System.Web.UI.WebControls;
using Spring.Expressions.Parser.antlr.debug;
using Utility;
using Elmah;
using System.Xml.Serialization;
namespace WebApp.Common
{
public class EntityDetail<T> : BasePage where T : Framework.Domain.Entity,new()
{
protected string TableName = string.Empty;
//在edit页面上,bpEdit是一个用来展示查询数据的控件
protected WebControls.Web.UI.BindingControl bpEdit
{
get;
set;
}
/// <summary>
/// 操作日志的保存
/// </summary>
/// <param name="obj"></param>
/// <param name="optype"></param>
protected virtual void SaveLog(T obj,int optype)
{
Contract.Domain.SysOplog op = new Contract.Domain.SysOplog();
op.CreateDate = DateTime.Now;
op.CreateOid = CurrentUser.OfficeId;
op.CreatePid = CurrentUser.PositionId;
op.CreateUid = CurrentUser.UserId;
op.CreateUname = CurrentUser.UserName;
op.Moudleid = Request["_menuId"];
switch (optype)
{
case 0:
op.Opcommand ="新增";
op.OpType = "新增";
break;
case 1:
op.Opcommand = "修改";
op.OpType = "修改";
break;
case 2:
op.Opcommand = "删除";
op.OpType = "删除";
break;
}
op.Entity = typeof(T).ToString();
op.Opdata = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
op.State.MarkNew();
Dao.SaveOrUpdate(op);
}
protected virtual void Page_Load(object sender, EventArgs e)
{
switch (HttpContext.Current.Request["_method"])
{
case null:
case "":
InitPage(HttpContext.Current.Request["Id"]);
//编辑操作
if (!string.IsNullOrEmpty(HttpContext.Current.Request["Id"]))
{
try
{
LoadData(HttpContext.Current.Request["Id"]);
}
catch (Exception ex)
{
JSUtil.log(ex);
ErrorSignal.FromCurrentContext().Raise(ex);
// Utility.JSUtil.ExecuteScript(string.Format(" $.messager.alert('异常提示', '改记录可能不存在请尝试刷新页面', '改记录可能不存在请尝试刷新页面');"));
}
}
else
{
//新增操作,如果页面有重用,那么就传入一个辨识页面的参数
//例如,tranBond有定息和浮息之分,那么可以用instrumentTypeId来分辨这个页面是定息的还是浮息的
//如果页面没有重用,那么这个参数为空
LoadDefaultSeetings(Request["InstrumentTypeId"]);
var t = this.FindControl("txt_Id_") as TextBox;
if (t != null)
{
t.Text = string.Empty;
}
ControlModify();
}
break;
case "Save":
T a = SaveData();
//移除实体缓存
if(a!=null)
{
RemoveCache(a.GetType().Name);
}
if (a == null)
{
return ;
}
string s = Newtonsoft.Json.JsonConvert.SerializeObject(a);
if (!string.IsNullOrEmpty(Request["txt_Id_"]))
{
SaveLog(a, 1);
}
else
{
SaveLog(a, 0);
}
HttpContext.Current.Response.Write(s);
HttpContext.Current.Response.End();
break;
case "Delete":
T aa = Activator.CreateInstance<T>();
aa.Id = HttpContext.Current.Request["Id"];
SaveLog(aa, 2);
Delete();
break;
//将页面的选项设置成默认配置
case "SaveSettings":
T seetingInfo = SetData();
setXmlInfo(seetingInfo, "rewrite", Request["InstrumentTypeId"]);
Response.Write("1");
Response.End();
break;
}
}
/// <summary>
/// 调整默认配置中的一些配置
/// </summary>
protected virtual void ControlModify()
{
}
protected Contract.IService.IEntityService<T> svc
{
get;
set;
}
/// <summary>
/// 初始化页面
/// </summary>
/// <param name="id"></param>
protected virtual void InitPage(string id)
{
}
/// <summary>
/// 在查询的时候加载数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
protected virtual T LoadData(string id)
{
T a;
try
{
if (svc == null)
{
a = Dao.FindById(typeof(T).Name, id) as T;
}
else
{
a = svc.FindById(id);
}
}
catch (Exception ex)
{
a=new T();
}
if (bpEdit == null)
{
bpEdit = this.FindControl("bpEdit") as WebControls.Web.UI.BindingControl;
if (bpEdit == null)
{
throw new Exception("请设置绑定bpEdit");
}
}
bpEdit.LoadData(a, 0);
return a;
}
/// <summary>
/// 在新增的时候加载默认配置
/// </summary>
/// <param name="TypeId">页面类型Id,如果页面不是共用情况,那么设置为空</param>
/// <returns></returns>
protected virtual T LoadDefaultSeetings(string TypeId)
{
T a;
a = new T();
a = getXmlInfo(a, TypeId) as T;
if (bpEdit == null)
{
bpEdit = this.FindControl("bpEdit") as WebControls.Web.UI.BindingControl;
if (bpEdit == null)
{
throw new Exception("请设置绑定bpEdit");
}
}
bpEdit.LoadData(a, 0);
return a;
}
/// <summary>
/// 删除
/// </summary>
protected virtual void Delete()
{
T a = Activator.CreateInstance<T>();
string typeName = a.GetType().Name;
a.Id = HttpContext.Current.Request["Id"];
a.State.MarkDeleted();
if (svc == null)
{
a = Dao.SaveOrUpdate(a) as T;
}
else
{
a = svc.SaveOrUpdate(a);
}
RemoveCache(typeName);
//svc.SaveOrUpdate(a);
HttpContext.Current.Response.Write("1");
HttpContext.Current.Response.End();
}
/// <summary>
/// 将form表单的数据封装成一个泛型
/// </summary>
/// <returns></returns>
protected virtual T SetData()
{
return WebHelper.Web.UI.BindingPanel.SaveData<T>(HttpContext.Current.Request.Form, 0);
}
/// <summary>
/// 新增或者保存来自前台的数据
/// </summary>
/// <returns></returns>
protected virtual T SaveData()
{
T a = SetData();
if (string.IsNullOrEmpty(a.Id))
{
a.State.MarkNew();
}
else
{
a.State.MarkDirty();
}
if (svc == null)
{
a = Dao.SaveOrUpdate(a) as T;
}
else
{
try
{
a = svc.SaveOrUpdate(a);
}
catch (Exception ex)
{
;
}
}
try
{
if (!string.IsNullOrEmpty(Request["EntityLog"]))
{
Contract.Domain.BaseEntityLog log = new Contract.Domain.BaseEntityLog();
log.Change = Request["EntityLog"];
log.FormId = a.Id;
log.CreateUid = CurrentUser.UserId;
log.CreateUname = CurrentUser.UserName;
log.TableName = TableName;
log.State.MarkNew();
if (!string.IsNullOrEmpty(log.Change))
{
var list = Newtonsoft.Json.JsonConvert.DeserializeObject<IList<jsonLog>>(log.Change);
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (var l in list)
{
if (sb.Length == 0)
{
sb.Append(l.title.Replace("\n", "").Replace(" ", "") + l.change.Replace("\n", "").Replace(" ", "")+"\r\n");
}
else
{
sb.Append(l.title.Replace("\n", "").Replace(" ", "") + l.change.Replace("\n", "").Replace(" ", "")+"\r\n");
}
}
log.ChangeContext = sb.ToString();
}
log.TableName = TableName;
Dao.SaveOrUpdate(log);
}
}
catch (Exception ex)
{
Utility.JSUtil.log(ex);
ErrorSignal.FromCurrentContext().Raise(ex);
}
return a;
}
/// <summary>
/// 在xml中获得实体
/// </summary>
/// <param name="obj">传入一个实体泛型</param>
/// <param name="uiTypeId">从用户界面传入的辨识页面的id</param>
/// <returns></returns>
public virtual object getXmlInfo(T obj, string uiTypeId)
{
object s;
using (MemoryStream ms = new MemoryStream())
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(HttpContext.Current.Server.MapPath("~/Config/DefaultFormValue.xml"));
XmlNode tempNode = xmlDoc.SelectSingleNode("/Initialization/" + typeof(T).Name);
if (!string.IsNullOrEmpty(uiTypeId))
{
tempNode = xmlDoc.SelectSingleNode("/Initialization/" + typeof(T).Name + uiTypeId + "/" + typeof(T).Name);
}
if (tempNode != null)
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
XmlDocument tempDoc = new XmlDocument();
XmlDeclaration xmldecl;
xmldecl = tempDoc.CreateXmlDeclaration("1.0", "utf-8", null);
tempDoc.AppendChild(xmldecl);
XmlNode temRoot = tempDoc.CreateElement(typeof(T).Name);
tempDoc.AppendChild(temRoot);
temRoot.InnerXml = tempNode.InnerXml;
tempDoc.Save(ms);
ms.Seek(0, SeekOrigin.Begin);
s = serializer.Deserialize(ms);
}
else
{
s = null;
}
}
return s;
}
/// <summary>
/// 设置xml默认配置
/// </summary>
/// <param name="obj">传入一个实体泛型</param>
/// <param name="method">当mehod为“rewrite”的时候,重写xml配置</param>
/// <param name="uiTypeId"></param>
public virtual void setXmlInfo(T obj, string method, string uiTypeId)
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
using (MemoryStream ms = new MemoryStream())
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(HttpContext.Current.Server.MapPath("~/Config/DefaultFormValue.xml"));
XmlNode tempNode = xmlDoc.SelectSingleNode("/Initialization/" + typeof(T).Name);
if (!string.IsNullOrEmpty(uiTypeId))
{
tempNode = xmlDoc.SelectSingleNode("/Initialization/" + typeof(T).Name + uiTypeId);
}
if (method == "rewrite" || tempNode == null)
{
serializer.Serialize(ms, obj);
XmlDocument tempDoc = new XmlDocument();
tempDoc.LoadXml(Encoding.UTF8.GetString(ms.ToArray()));
XmlElement instrumentTypeelElement = xmlDoc.CreateElement(typeof(T).Name);
if (!string.IsNullOrEmpty(uiTypeId))
{
instrumentTypeelElement = xmlDoc.CreateElement(typeof(T).Name + uiTypeId);
XmlElement typeElement = xmlDoc.CreateElement(typeof(T).Name);
typeElement.InnerXml = tempDoc.SelectSingleNode(typeof(T).Name).InnerXml;
instrumentTypeelElement.AppendChild(typeElement);
}
else
{
instrumentTypeelElement.InnerXml = tempDoc.SelectSingleNode(typeof(T).Name).InnerXml;
}
XmlNode root = xmlDoc.SelectSingleNode("Initialization");
if (tempNode == null)
{
root.AppendChild(instrumentTypeelElement);
}
else
{
if (method == "rewrite")
{
root.ReplaceChild(instrumentTypeelElement, tempNode);
}
}
xmlDoc.Save(HttpContext.Current.Server.MapPath("~/Config/DefaultFormValue.xml"));
}
}
}
}
}
jqentitymanage的更多相关文章
- jqgrid子表格
.前台 <%-- builed by manage.aspx.cmt [ver:] at // :: --%> <%@ Page Language="C#" Au ...
- hra 直线
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ...
- .net正则查询
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ...
- Siverlight MarkerSize 控制数据点半径大小 LineThickness 控制点与点之间直线的厚度
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ...
- easyui-tabs 页签绑定click事件,动态加载jqgrid
.前台代码 <%-- builed by manage.aspx.cmt [ver:] at // :: --%> <%@ Page Language="C#" ...
- jqgrid控件列分组
<%-- builed by manage.aspx.cmt [ver:2014.48.11] at 2014/10/11 16:48:33 --%> <%@ Page Langua ...
- jqentitydetail
using System;using System.Collections;using System.Collections.Generic;using System.Linq;using Syste ...
- 动态tab页
1.前台代码 <%-- builed by manage.aspx.cmt [ver:2015.25.26] at 2015-06-26 15:25:42 --%> <%@ Pag ...
随机推荐
- 【BZOJ2908】又是nand 树链剖分+线段树
[BZOJ2908]又是nand escription 首先知道A nand B=not(A and B) (运算操作限制了数位位数为K)比如2 nand 3,K=3,则2 nand 3=not (2 ...
- bzoj 1044 [HAOI2008]木棍分割——前缀和优化dp
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1044 前缀和优化. 但开成long long会T.(仔细一看不用开long long) #i ...
- selenium定位方法
- 分布式缓存系统 Memcached 基本配置与命令
为了方便测试,给出一个C客户端libmemcached链接:https://launchpad.net/libmemcached/ 以及memcacheclient-2.0 : http://code ...
- TELNET协议规范
ARPA Internet上的主机被要求采用并实现此标准. 介绍 TELNET Protocol的目的是提供一个相对通用的,双向的,面向八位字节的通信方法.它主要的目标是允许接口终端设备的标准方法和面 ...
- 杂项:UN-标准通用置标语言
ylbtech-杂项:标准通用置标语言 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 6.返回顶部 7.返回顶部 8.返回顶部 9.返回顶部 ...
- python开发socket套接字:粘包问题&udp套接字&socketserver
一,发生粘包 服务器端 from socket import * phone=socket(AF_INET,SOCK_STREAM) #套接字 phone.setsockopt(SOL_SOCKET, ...
- Hadoop入门介绍一
Hadoop1.是一个由Apache基金会所开发的分布式系统基础架构.用户可以在不了解分布式底层细节的情况下,开发分布式程序.充分利用集群的威力进行高速运算和存储.2.Hadoop实现了一个分布式文件 ...
- Py修行路 python基础 (三)字典
names=["zhang"]names2=["jack","jie"]names.clear()print(names) #清空整个列表 ...
- Py修行路 python基础 (十三)匿名函数 与 内置函数
一.匿名函数 1.定义: 匿名函数顾名思义就是指:是指一类无需定义标识符(函数名)的函数或子程序. 2.语法格式:lambda 参数:表达式 lambda语句中,开头先写关键字lambda,冒号前是 ...