using Castle.ActiveRecord; using System; using System.Data; using System.Text; namespace BizCom { public class DicSysBase : ComBase { private string _code = ""; private string _memo = ""; private string _name = ""; private string _path = ""; public string _url = ""; public string _tag = ""; public string _icon = ""; public bool _isOperate = false; public bool _oldOrder; /// /// 根结点名 /// public string rootName; /// /// 页面标题显示 /// public string titleName; public string tableName; [PrimaryKey(PrimaryKeyType.Identity)] public int ID { get; set; } /// ///父节点ID /// [Property] public int ParentID { get; set; } /// ///名称 /// [Property] public string Name { get { return _name; } set { _name = value; } } /// ///编号 /// [Property] public string Code { get { return _code; } set { _code = value; } } /// /// 老订单权限 /// [Property] public bool OldOrder { get { return _oldOrder; } set { _oldOrder = value; } } /// ///路径 /// [Property] public string Path { get { return _path; } set { _path = value; } } /// ///排序号 /// [Property] public int Sort { get; set; } /// ///删除标志 /// [Property] public bool IsDel { get; set; } /// ///备注 /// [Property] public string Memo { get { return _memo; } set { _memo = value; } } //关联店铺 public string _pemShop = ""; public string pemShop { get { return _pemShop; } set { _pemShop = value; } } public string Url { get { return _url; } set { _url = value; } } public string Tag { get { return _tag; } set { _tag = value; } } public string Icon { get { return _icon; } set { _icon = value; } } public string _pCode = ""; /// ///父代号 /// public string PCode { get { return _pCode; } set { _pCode = value; } } /// ///是否操作 /// public bool isOperate { get { return _isOperate; } set { _isOperate = value; } } public string _hostFieldName = ""; /// ///字段名 /// public string HostFieldName { get { return _hostFieldName; } set { _hostFieldName = value; } } public string _hostName = ""; /// ///主机楼名称 /// public string HostName { get { return _hostName; } set { _hostName = value; } } public double _maxStock = 0; public double _warningStock = 0; public double MaxStock { get { return _maxStock; } set { _maxStock = value; } } public double WarningStock { get { return _warningStock; } set { _warningStock = value; } } #region 事件 /// /// 获取Code /// /// /// /// public virtual string GetCode(string pCode, int pId) { return ""; } public void TransModular(object id, object pId, int sort, string table) { if (table == "") return; StringBuilder sql = new StringBuilder(); sql.AppendFormat("declare @oldid int;"); sql.AppendFormat("select @oldid=parentid from {1} where id={0} ;", id, table); sql.AppendFormat("update {2} set path=REPLACE(Path,@oldid,'{0}') where path like '%|'+(select Convert(varchar,id) from {2} where ID={1})+'%|' or ID={1} ;", pId, id, table); sql.AppendFormat("update {3} set parentid={0},sort={1} where id={2} ;", pId, sort, id, table); TransExecuteNonQuery(sql.ToString()); } public void SaveLine(object id, string prev, int st, int et, string table) { StringBuilder sql = new StringBuilder(); for (int i = st; i < st + et; i++) { sql.AppendFormat("insert into {0}(parentid,name,sort,pemShop)values({1},'{2}',{3}) ;", table, id, prev + (i < 10 ? ("0" + i) : i.ToString()), i); } TransExecuteNonQuery(sql.ToString()); } /// /// 获取数据 /// /// public DataTable GetDataTable() { return GetDataTable(""); } public DataTable GetDataTable(string sWhere) { return GetDataTable(0, sWhere); } public DataTable GetDataTable(int top, string sWhere) { string sTop = top > 0 ? "Top " + top : ""; string sql = "select {2} * from {0} {1} order by ParentID,Sort"; DataSet ds = DbConn.ExecuteDataset(string.Format(sql, TName, sWhere == "" ? "" : " where " + sWhere, sTop)); if (ds != null && ds.Tables.Count > 0) return ds.Tables[0]; else return null; } public static DataTable GetTable(string sName, string sWhere) { string sql = "select * from {0} {1} Order By ParentID,Sort"; DataSet ds = DbConn.ExecuteDataset(string.Format(sql, sName, sWhere == "" ? "" : " where " + sWhere)); if (ds != null && ds.Tables.Count > 0) return ds.Tables[0]; else return null; } public object GetEntity(object id) { DataTable dt = GetDataTable("ID=" + id); ID = Convert.ToInt32(dt.Rows[0]["ID"]); Name = dt.Rows[0]["Name"].ToString(); ParentID = Convert.ToInt32(dt.Rows[0]["ParentID"]); if (dt.Columns.Contains("Url")) Url = dt.Rows[0]["Url"].ToString(); if (dt.Columns.Contains("Tag")) Tag = dt.Rows[0]["Tag"].ToString(); if (dt.Columns.Contains("isOperate")) isOperate = Convert.ToBoolean(dt.Rows[0]["isOperate"]); Code = dt.Rows[0]["Code"].ToString(); Path = dt.Rows[0]["Path"].ToString(); Sort = Convert.ToInt32(dt.Rows[0]["Sort"]); IsDel = Convert.ToBoolean(dt.Rows[0]["IsDel"]); OldOrder = Convert.ToBoolean(dt.Rows[0]["OldOrder"]); Memo = dt.Rows[0]["Memo"].ToString(); return this; } public object GetParentName(int pId) { string sql = "select Name from {0} where ID={1}"; object result = DbConn.ExecuteScalar(string.Format(sql, TName, pId)); return result; } public object GetParentPath(int pId) { string sql = "select Path from {0} where ID={1}"; object result = DbConn.ExecuteScalar(string.Format(sql, TName, pId)); return result; } public DataRow GetParentFields(string fields, int pId) { string sql = "select {2} from {0} where ID={1}"; DataTable dt = ExecuteDataset(string.Format(sql, TName, pId, fields)).Tables[0]; if (dt != null && dt.Rows.Count > 0) return dt.Rows[0]; return null; } public static object GetFieldByName(string field, string table, string name) { string sql = "select {0} from {1} where Name='{2}'"; object result = DbConn.ExecuteScalar(string.Format(sql, field, table, name)); return result; } public static int GetIDByName(string table, string name) { object result = GetFieldByName("ID", table, name); if (result != null) return (int)result; return 0; } public static void UpdatePath(string table) { string sql = "select * from " + table; DataTable dt = ExecuteDataset(sql).Tables[0]; DataView dv = new DataView(dt); DataView dv2 = new DataView(dt); dv.RowFilter = "parentid<>0 and path=''"; StringBuilder tmpSql = new StringBuilder(); string spath = ""; foreach (DataRowView drv in dv) { dv2.RowFilter = "id=" + drv["parentid"]; if (dv2.Count > 0) { if (dv2[0]["parentid"].ToString() == "0") { spath = "|" + dv2[0]["id"] + "|"; } else { spath = dv2[0]["path"].ToString() + dv2[0]["id"] + "|"; } tmpSql.Append("update " + table + " set path ='" + spath + "' where id=" + drv["id"] + " ;"); } if (tmpSql.Length > 0) { ExecuteNonQuery(tmpSql.ToString()); } } } public void DelChild(int id) { string sql = string.Format("delete from {0} where Path like '%|{1}|%' ", TName, id); ExecuteNonQuery(sql); } #endregion } }