| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- using Castle.ActiveRecord;
- using System.Data;
- using System.Text;
- namespace BizCom
- {
- [ActiveRecord("CE_ErpModular")]
- public class CeErpModular : DicSysBase
- {
- public CeErpModular()
- {
- rootName = "系统模块";
- titleName = "系统模块根结点";
- tableName = "CE_ErpModular";
- }
- [Property]
- public new string Url
- {
- get { return _url; }
- set { _url = value; }
- }
- [Property]
- public new string Tag
- {
- get { return _tag; }
- set { _tag = value; }
- }
- /// <summary>
- ///是否操作
- /// </summary>
- [Property]
- public new bool isOperate
- {
- get { return _isOperate; }
- set { _isOperate = value; }
- }
- /// <summary>
- ///图标
- /// </summary>
- [Property]
- public new string Icon
- {
- get { return _icon; }
- set { _icon = value; }
- }
- public static DataTable GetModular()
- {
- return DbConn.ExecuteDataset("select * from CE_ErpModular where isdel=0 order by sort asc").Tables[0];
- }
- public static DataTable GetOrgModular(string oId)
- {
- 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";
- return DbConn.ExecuteDataset(sql).Tables[0];
- }
- public static DataTable GetModularNoOperate()
- {
- string sql = "select * from CE_ErpModular where isdel=0 and isoperate=0 order by path asc, sort asc";
- return DbConn.ExecuteDataset(sql).Tables[0];
- }
- //public static void TransModular(object id,object pId,int sort)
- //{
- // StringBuilder sql=new StringBuilder();
- // sql.AppendFormat("declare @oldid int;");
- // sql.AppendFormat("select @oldid=parentid from ce_erpmodular where id={0} ;",id);
- // 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);
- // sql.AppendFormat("update ce_erpmodular set parentid={0},sort={1} where id={2} ;", pId,sort,id);
- // TransExecuteNonQuery(sql.ToString());
- //}
- //获取角色模块
- public static DataTable GetResourceByRoleID(int roleId)
- {
- string sql = "select * from CE_ErpModular where Code in(select ResCode from LC_SysRoleToResource where RoleID={0}) and IsDel=0 order by parentid,ordernum ";
- return DbConn.ExecuteDataset(string.Format(sql, roleId)).Tables[0];
- }
- public static void BuilderOperate(string mId)
- {
- StringBuilder sql = new StringBuilder();
- DataTable dt = DbConn.ExecuteDataset("select * from ce_erpmodular where id=" + mId).Tables[0];
- if (dt == null || dt.Rows.Count < 1) return;
- DataRow dr = dt.Rows[0];
- string tag = dr["Tag"].ToString();
- string path = dr["Path"] + mId + "|";
- sql.AppendFormat("insert into ce_erpmodular(parentid,name,tag,path,sort,isoperate) Values({0},'{1}','{2}','{3}',{4},1) ;",
- mId, "查看", tag + "_view", path, 0);
- sql.AppendFormat("insert into ce_erpmodular(parentid,name,tag,path,sort,isoperate) Values({0},'{1}','{2}','{3}',{4},1) ;",
- mId, "添加", tag + "_add", path, 1);
- sql.AppendFormat("insert into ce_erpmodular(parentid,name,tag,path,sort,isoperate) Values({0},'{1}','{2}','{3}',{4},1) ;",
- mId, "修改", tag + "_edit", path, 2);
- sql.AppendFormat("insert into ce_erpmodular(parentid,name,tag,path,sort,isoperate) Values({0},'{1}','{2}','{3}',{4},1) ;",
- mId, "删除", tag + "_del", path, 3);
- TransExecuteNonQuery(sql.ToString());
- }
- public static void AddPermission(string mId)
- {
- StringBuilder sql = new StringBuilder();
- DataTable dt = DbConn.ExecuteDataset("select * from ce_erpmodular where id=" + mId).Tables[0];
- if (dt == null || dt.Rows.Count < 1) return;
- DataRow dr = dt.Rows[0];
- string pid = dr["ParentID"].ToString();
- //string tag = dr["Tag"].ToString();
- //string path = dr["Path"] + mId + "|";
- sql = new StringBuilder();
- sql.AppendFormat("select OrgID,postid from CE_ErpPermission where OrgID>0 and ModularID={0} group by orgid,postid;", pid);
- dt = DbConn.ExecuteDataset(sql.ToString()).Tables[0];
- sql = new StringBuilder();
- foreach (DataRow dr2 in dt.Rows)
- {
- 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);
- sql.AppendFormat("insert into CE_ErpPermission(orgid,postid,modularid) values({0},{1},{2}) ; end ", dr2["orgid"], dr2["postid"], mId);
- }
- if (sql.Length > 0)
- DbConn.ExecuteNonQuery(sql.ToString());
- //TransExecuteNonQuery(sql.ToString());
- }
- }
- }
|