CeErpModular.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using Castle.ActiveRecord;
  2. using System.Data;
  3. using System.Text;
  4. namespace BizCom
  5. {
  6. [ActiveRecord("CE_ErpModular")]
  7. public class CeErpModular : DicSysBase
  8. {
  9. public CeErpModular()
  10. {
  11. rootName = "系统模块";
  12. titleName = "系统模块根结点";
  13. tableName = "CE_ErpModular";
  14. }
  15. [Property]
  16. public new string Url
  17. {
  18. get { return _url; }
  19. set { _url = value; }
  20. }
  21. [Property]
  22. public new string Tag
  23. {
  24. get { return _tag; }
  25. set { _tag = value; }
  26. }
  27. /// <summary>
  28. ///是否操作
  29. /// </summary>
  30. [Property]
  31. public new bool isOperate
  32. {
  33. get { return _isOperate; }
  34. set { _isOperate = value; }
  35. }
  36. /// <summary>
  37. ///图标
  38. /// </summary>
  39. [Property]
  40. public new string Icon
  41. {
  42. get { return _icon; }
  43. set { _icon = value; }
  44. }
  45. public static DataTable GetModular()
  46. {
  47. return DbConn.ExecuteDataset("select * from CE_ErpModular where isdel=0 order by sort asc").Tables[0];
  48. }
  49. public static DataTable GetOrgModular(string oId)
  50. {
  51. string sql = "select * from CE_ErpModular where ID in( select ModularID from ce_erppermission where orgid=" + oId + " and postID=0) and isDel=0 order by sort asc";
  52. return DbConn.ExecuteDataset(sql).Tables[0];
  53. }
  54. public static DataTable GetModularNoOperate()
  55. {
  56. string sql = "select * from CE_ErpModular where isdel=0 and isoperate=0 order by path asc, sort asc";
  57. return DbConn.ExecuteDataset(sql).Tables[0];
  58. }
  59. //public static void TransModular(object id,object pId,int sort)
  60. //{
  61. // StringBuilder sql=new StringBuilder();
  62. // sql.AppendFormat("declare @oldid int;");
  63. // sql.AppendFormat("select @oldid=parentid from ce_erpmodular where id={0} ;",id);
  64. // sql.AppendFormat("update ce_erpmodular set path=REPLACE(Path,@oldid,'{0}') where path like '%|'+(select Convert(varchar,id) from CE_ErpModular where ID={1})+'%|' or ID={1} ;", pId, id);
  65. // sql.AppendFormat("update ce_erpmodular set parentid={0},sort={1} where id={2} ;", pId,sort,id);
  66. // TransExecuteNonQuery(sql.ToString());
  67. //}
  68. //获取角色模块
  69. public static DataTable GetResourceByRoleID(int roleId)
  70. {
  71. string sql = "select * from CE_ErpModular where Code in(select ResCode from LC_SysRoleToResource where RoleID={0}) and IsDel=0 order by parentid,ordernum ";
  72. return DbConn.ExecuteDataset(string.Format(sql, roleId)).Tables[0];
  73. }
  74. public static void BuilderOperate(string mId)
  75. {
  76. StringBuilder sql = new StringBuilder();
  77. DataTable dt = DbConn.ExecuteDataset("select * from ce_erpmodular where id=" + mId).Tables[0];
  78. if (dt == null || dt.Rows.Count < 1) return;
  79. DataRow dr = dt.Rows[0];
  80. string tag = dr["Tag"].ToString();
  81. string path = dr["Path"] + mId + "|";
  82. sql.AppendFormat("insert into ce_erpmodular(parentid,name,tag,path,sort,isoperate) Values({0},'{1}','{2}','{3}',{4},1) ;",
  83. mId, "查看", tag + "_view", path, 0);
  84. sql.AppendFormat("insert into ce_erpmodular(parentid,name,tag,path,sort,isoperate) Values({0},'{1}','{2}','{3}',{4},1) ;",
  85. mId, "添加", tag + "_add", path, 1);
  86. sql.AppendFormat("insert into ce_erpmodular(parentid,name,tag,path,sort,isoperate) Values({0},'{1}','{2}','{3}',{4},1) ;",
  87. mId, "修改", tag + "_edit", path, 2);
  88. sql.AppendFormat("insert into ce_erpmodular(parentid,name,tag,path,sort,isoperate) Values({0},'{1}','{2}','{3}',{4},1) ;",
  89. mId, "删除", tag + "_del", path, 3);
  90. TransExecuteNonQuery(sql.ToString());
  91. }
  92. public static void AddPermission(string mId)
  93. {
  94. StringBuilder sql = new StringBuilder();
  95. DataTable dt = DbConn.ExecuteDataset("select * from ce_erpmodular where id=" + mId).Tables[0];
  96. if (dt == null || dt.Rows.Count < 1) return;
  97. DataRow dr = dt.Rows[0];
  98. string pid = dr["ParentID"].ToString();
  99. //string tag = dr["Tag"].ToString();
  100. //string path = dr["Path"] + mId + "|";
  101. sql = new StringBuilder();
  102. sql.AppendFormat("select OrgID,postid from CE_ErpPermission where OrgID>0 and ModularID={0} group by orgid,postid;", pid);
  103. dt = DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  104. sql = new StringBuilder();
  105. foreach (DataRow dr2 in dt.Rows)
  106. {
  107. sql.AppendFormat("if (select count(0) from CE_ErpPermission where orgid={0} and postid={1} and modularid={2})<1 begin ", dr2["orgid"], dr2["postid"], mId);
  108. sql.AppendFormat("insert into CE_ErpPermission(orgid,postid,modularid) values({0},{1},{2}) ; end ", dr2["orgid"], dr2["postid"], mId);
  109. }
  110. if (sql.Length > 0)
  111. DbConn.ExecuteNonQuery(sql.ToString());
  112. //TransExecuteNonQuery(sql.ToString());
  113. }
  114. }
  115. }