using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Text;
|
using Model;
|
using Common;
|
using System.Collections;
|
|
namespace BLL
|
{
|
public class DALResMenu : IDALResMenu
|
{
|
public IList<ResMenu> GetParentList()
|
{
|
try
|
{
|
IList<ResMenu> ls = new List<ResMenu>();
|
StringBuilder strSql = new StringBuilder();
|
strSql.Append("select ResNum, case ParentNum when '' then '>'+ ResName else ' ' + ResName end as ParentName,IsDel,[level] from dbo.ResMenu where IsDel !=1 and [level] in ('1','2') order by ord");
|
|
IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql);
|
ls = ModelConvertHelper<ResMenu>.DataReaderToModel(dt);
|
|
return ls;
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
}
|
|
public IList<ResMenu> GetList(AjaxResMenuList Json, ref PageInfo page)
|
{
|
try
|
{
|
|
IList<ResMenu> list = new List<ResMenu>();
|
StringBuilder strSql = new StringBuilder();
|
List<SqlParam> para = new List<SqlParam>();
|
strSql.Append("Select ResNum,ResName,ParentName,ResType,CssName,Url,CreatUser,CreatTime,UpdateUser,UpdateTime,Ord,IsDel from View_GetResMenu where IsDel = 0 ");
|
|
if (Json.ResNum != null && Json.ResNum != "")
|
{
|
//if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
|
strSql.Append(" and ResNum like '%' + @ResNum + '%' ");
|
para.Add(new SqlParam("@ResNum", Json.ResNum));
|
}
|
|
if (Json.ResName != null && Json.ResName != "")
|
{
|
//if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
|
strSql.Append(" and ResName like '%' + @ResName + '%' ");
|
para.Add(new SqlParam("@ResName", Json.ResName));
|
}
|
|
if (Json.ParentNum != null && Json.ParentNum != "")
|
{
|
//if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
|
strSql.Append(" and ( ParentNum = @ParentNum or ResNum = @ParentNumto )");
|
para.Add(new SqlParam("@ParentNum", Json.ParentNum));
|
para.Add(new SqlParam("@ParentNumto", Json.ParentNum));
|
}
|
|
|
//strSql.Append("Order By ResNum");
|
SqlParam[] param = null;
|
if (para != null)
|
param = para.ToArray();
|
|
DataTable dt = DataFactory.SqlDataBase().GetPageList(strSql.ToString(), param, "Ord", "ASC", ref page);
|
list = ModelConvertHelper<ResMenu>.DataTableToModel(dt);
|
|
return list;
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
|
}
|
|
public IList<AjaxResMenuInfo> GetList()
|
{
|
try
|
{
|
|
IList<AjaxResMenuInfo> list = new List<AjaxResMenuInfo>();
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("Select ResNum,ResName,ParentNum,CssName,Url,IsDel from ResMenu where IsDel != 1 order by ord asc");
|
|
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSql);
|
list = ModelConvertHelper<AjaxResMenuInfo>.DataTableToModel(dt);
|
|
return list;
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
|
}
|
public ResMenu GetModel(string ResNum)
|
{
|
try
|
{
|
ResMenu us = null;
|
StringBuilder strSql = new StringBuilder();
|
strSql.Append("Select ResNum,ResName,ParentName,ResType,CssName,Url,IsDel from View_GetResMenu where ");
|
strSql.Append("ResNum = @ResNum ");
|
strSql.Append("and IsDel != 1");
|
SqlParam[] para = new SqlParam[]
|
{
|
new SqlParam("@ResNum", ResNum),
|
};
|
|
IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql, para);
|
|
us = ModelConvertHelper<ResMenu>.ReaderToModel(dt);
|
|
return us;
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
}
|
|
public bool Add(ResMenu model)
|
{
|
bool result = false;
|
try
|
{
|
Hashtable ht = new Hashtable();
|
|
ht["ResNum"] = string.IsNullOrEmpty(model.ResNum) ? "''" : "'" + model.ResNum + "'";
|
ht["ResName"] = string.IsNullOrEmpty(model.ResName) ? "''" : "'" + model.ResName + "'";
|
ht["ParentNum"] = string.IsNullOrEmpty(model.ParentName) ? "''" : "(select ResNum from ResMenu where ResName = '" + model.ParentName + "')";
|
ht["Ord"] = 0;
|
ht["IsDel"] = 0;
|
ht["CreatUser"] = "'" + model.CreatUser + "'";
|
ht["UpdateTime"] = "GetDate()";
|
ht["CreatTime"] = "GetDate()";
|
ht["Url"] = string.IsNullOrEmpty(model.Url) ? "''" : "'" + model.Url + "'";
|
ht["UpdateUser"] = "'" + model.CreatUser + "'";
|
ht["CssName"] = string.IsNullOrEmpty(model.CssName) ? "''" : "'" + model.CssName + "'";
|
ht["ResType"] = string.IsNullOrEmpty(model.ResType) ? "''" : "'" + model.ResType + "'";
|
|
int _ret = DataFactory.SqlDataBase().InsertByHashtableNullParam("ResMenu", ht);
|
|
if (_ret == 1) result = true;
|
return result;
|
}
|
catch
|
{
|
return result;
|
}
|
}
|
|
public bool Update(ResMenu model)
|
{
|
bool result = false;
|
try
|
{
|
Hashtable ht = new Hashtable();
|
|
//ht["ResNum"] = string.IsNullOrEmpty(model.ResNum) ? "''" : "'" + model.ResNum + "'";
|
ht["ResName"] = string.IsNullOrEmpty(model.ResName) ? "''" : "'" + model.ResName + "'";
|
ht["ParentNum"] = string.IsNullOrEmpty(model.ParentName) ? "''" : "(select ResNum from ResMenu where ResName = '" + model.ParentName + "')";
|
ht["CssName"] = string.IsNullOrEmpty(model.CssName) ? "''" : "'" + model.CssName + "'";
|
ht["ResType"] = string.IsNullOrEmpty(model.ResType) ? "''" : "'" + model.ResType + "'";
|
ht["UpdateTime"] = "GetDate()";
|
ht["UpdateUser"] = string.IsNullOrEmpty(model.UpdateUser) ? "''" : "'" + model.UpdateUser + "'";
|
ht["Url"] = string.IsNullOrEmpty(model.Url) ? "''" : "'" + model.Url + "'";
|
|
string ResNum = "'" + model.ResNum + "'";
|
|
int _ret = DataFactory.SqlDataBase().UpdateByHashtable("ResMenu", nameof(model.ResNum), ResNum, ht);
|
|
if (_ret == 1) result = true;
|
|
return result;
|
|
}
|
catch
|
{
|
return result;
|
}
|
}
|
public bool IsExist(string name, string value)
|
{
|
bool result = false;
|
try
|
{
|
string[] para = new string[] { value };
|
int dt = DataFactory.SqlDataBase().IsExist("ResMenu", name, para);
|
if (dt > 0) result = true;
|
return result;
|
}
|
catch
|
{
|
return result;
|
}
|
|
}
|
|
public DataTable GetDataTable(string[] strWhere)
|
{
|
DataTable dt = null;
|
try
|
{
|
int index = 0;
|
string str = "@ResNum" + index;
|
SqlParam[] param = new SqlParam[strWhere.Length];
|
StringBuilder sql = new StringBuilder();
|
sql.Append("Select ResNum as 菜单编号, ResName as 菜单名称,ParentName as 父级菜单,ResType as 类型,CssName as 样式,Url as 路径,CreatUser as 创建人,CreatTime as 创建时间,UpdateUser as 更新人,UpdateTime as 更新时间 FROM View_GetResMenu where ResNum in (");
|
|
for (int i = 0; i < param.Length - 1; i++)
|
{
|
string obj2 = strWhere[i];
|
str = "@ResNum" + index;
|
sql.Append(str).Append(",");
|
param[index] = new SqlParam(str, obj2);
|
index++;
|
}
|
str = "@ResNum" + index;
|
sql.Append(str);
|
param[index] = new SqlParam(str, strWhere[index]);
|
sql.Append(")");
|
|
dt = DataFactory.SqlDataBase().GetDataTableBySQL(sql, param, "");
|
|
return dt;
|
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
|
}
|
public bool BatchDelete(string[] ResNum)
|
{
|
bool result = false;
|
try
|
{
|
int dt = DataFactory.SqlDataBase().IsExist("ResMenu", "ResNum", ResNum);
|
if (dt >= ResNum.Length)
|
{
|
int _ret = DataFactory.SqlDataBase().BatchDeleteData("ResMenu", "ResNum", ResNum);
|
if (_ret >= ResNum.Length)
|
{
|
result = true;
|
}
|
}
|
return result;
|
}
|
catch
|
{
|
return result;
|
}
|
}
|
}
|
}
|