You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/EntityDA/ModuleDA.cs

1357 lines
58 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
using DSWeb.Models;
using System.Data;
using System.Data.SqlClient;
using WebSqlHelper;
namespace DSWeb.EntityDA
{
public class ModuleDA
{
private const string PARM_MODULE_GID = "@gid";
private const string PARM_MODULE_NAME = "@name";
private const string PARM_MODULE_DESCRIPTION = "@description";
private const string PARM_MODULE_MODULE_URL = "@module_url";
private const string PARM_MODULE_MODULE_ICON = "@module_icon";
private const string PARM_MODULE_PARENT_ID = "@parent_id";
private const string PARM_MODULE_SORT = "@sort";
private const string PARM_MODULE_STATE = "@state";
private const string PARM_MODULE_TYPE = "@type";
private const string PARM_MODULE_CREATE_USER = "@create_user";
private const string PARM_MODULE_CREATE_TIME = "@create_time";
private const string PARM_MODULE_MODIFIED_USER = "@modified_user";
private const string PARM_MODULE_MODIFIED_TIME = "@modified_time";
private const string PARM_MODULE_SHOW_ROOT_STATES = "@show_root_states";
//user_action
private const string PARM_USER_ACTION_USER_ID = "@user_id";
private const string PARM_USER_ACTION_ACTION_ID = "@action_id";
//action
private const string PARM_ACTION_GID = "@gid";
private const string PARM_ACTION_NAME = "@name";
private const string PARM_ACTION_DESCRIPTION = "@description";
private const string PARM_ACTION_CREATE_USER = "@create_user";
private const string PARM_ACTION_MODULE_ID = "@module_id";
private ModuleType _module_type;//模块类型
private const string SQL_SELECT_MODULE = "SELECT GID,NAME,DESCRIPTION,MODULEURL,MODULEICON,SORT,STATE,PARENTID,SHOWROOTSTATE,TYPE FROM sys_module WHERE GID = @gid ORDER BY SORT ASC ";
private const string SQL_SELECT_MODULE_BY_NAME = "SELECT GID,NAME,DESCRIPTION,MODULEURL,MODULEICON,SORT,STATE,PARENTID,SHOWROOTSTATE,TYPE FROM sys_module WHERE NAME = @name ";
private const string SQL_SELECT_MODULE_ALL = "SELECT GID,NAME,DESCRIPTION,MODULEURL,MODULEICON,SORT,STATE,PARENTID,SHOWROOTSTATE,TYPE FROM sys_module WHERE STATE <> 1 ORDER BY SORT ASC ";
private const string SQL_SELECT_MODULE_USER_ALL = " SELECT GID,NAME,DESCRIPTION,MODULEURL,MODULEICON,SORT,STATE,PARENTID,SHOWROOTSTATE,TYPE FROM sys_module WHERE STATE <> 1 AND GID IN "
+ " ( SELECT B.MODULEID FROM user_action as A INNER JOIN [action] as B ON A.ACTIONID = B.GID WHERE USERID = @user_id ) ORDER BY SORT ASC ";
private const string SQL_SELECT_MODULE_PARENT = "SELECT GID,NAME,DESCRIPTION,MODULEURL,MODULEICON,SORT,STATE,PARENTID,SHOWROOTSTATE,TYPE FROM sys_module WHERE PARENTID = '0' AND STATE <> 1 AND TYPE = 0 ORDER BY SORT ASC ";
private const string SQL_SELECT_MODULE_USER_PARENT = " SELECT GID,NAME,DESCRIPTION,MODULEURL,MODULEICON,SORT,STATE,PARENTID,SHOWROOTSTATE,TYPE FROM sys_module "
+ " WHERE PARENTID = '0' AND STATE <> 1 AND TYPE = 0 AND GID IN "
+ "( SELECT B.MODULEID FROM user_action as A INNER JOIN [action] as B ON A.ACTIONID = B.GID WHERE USERID = @user_id ) ORDER BY SORT ASC ";
private const string SQL_SELECT_MODULE_SUB = "SELECT GID,NAME,DESCRIPTION,MODULEURL,MODULEICON,SORT,STATE,PARENTID,SHOWROOTSTATE,TYPE FROM sys_module WHERE PARENTID <> '0' AND PARENTID = @gid AND STATE <> 1 ORDER BY SORT ASC ";
private const string SQL_SELECT_MODULE_ALLSUB = "SELECT GID,NAME,DESCRIPTION,MODULEURL,MODULEICON,SORT,STATE,PARENTID,SHOWROOTSTATE,TYPE FROM sys_module WHERE PARENTID <> '0' AND STATE <> 1 ORDER BY SORT ASC ";
private const string SQL_SELECT_MODULE_USER_ALLSUB = " SELECT GID,NAME,DESCRIPTION,MODULEURL,MODULEICON,SORT,STATE,PARENTID,SHOWROOTSTATE,TYPE FROM sys_module WHERE PARENTID <> '0' AND STATE <> 1 "
+ " AND GID IN ( SELECT B.MODULEID FROM user_action as A INNER JOIN [action] as B ON A.ACTIONID = B.GID WHERE USERID = @user_id ) ORDER BY SORT ASC ";
private const string SQL_SELECT_MODULE_USERBASE = "SELECT GID,NAME,DESCRIPTION,MODULEURL,MODULEICON,SORT,STATE,PARENTID,SHOWROOTSTATE,TYPE FROM sys_module WHERE PARENTID = '1'AND STATE <> 1 ORDER BY SORT ASC ";
private const string SQL_SELECT_MODULE_USERBASE_SUB = "SELECT GID,NAME,DESCRIPTION,MODULEURL,MODULEICON,SORT,STATE,PARENTID,SHOWROOTSTATE,TYPE FROM sys_module WHERE PARENTID <> '1' AND PARENTID <> '0' ORDER BY SORT ASC ";
//根据模块TYPE类型获取相应的操作模块
private const string SQL_SELECT_MODULE_BY_TYPE = "SELECT GID,NAME,DESCRIPTION,MODULEURL,MODULEICON,SORT,STATE,PARENTID,SHOWROOTSTATE,TYPE FROM sys_module WHERE PARENTID = '0' AND STATE <> 1 AND TYPE = @type ORDER BY SORT ASC ";
private const string SQL_UPDATE_MODULE = " UPDATE sys_module SET NAME = @name,DESCRIPTION = @DESCRIPTION,MODULEURL = @module_url,MODULEICON = @module_icon,STATE = @state,SORT = @sort,PARENTID = @parent_id,"
+ " MODIFIEDUSER = @modified_user,MODIFIEDTIME = GETDATE(),SHOWROOTSTATE = @show_root_states, TYPE = @type WHERE GID = @gid ";
private const string SQL_INSERT_MODULE = " INSERT INTO sys_module(GID,NAME,DESCRIPTION,MODULEURL,MODULEICON,STATE,SORT,PARENTID,CREATEUSER,CREATETIME,SHOWROOTSTATE,TYPE) "
+ " VALUES(@gid,@name,@description,@module_url,@module_icon,@state,@sort,@parent_id,@create_user,GETDATE(),@show_root_states,@type) ";
private const string SQL_DELETE_MODULE = " DELETE FROM sys_module WHERE GID = @gid";
private const string SQL_SELECT_MODULE_BY_DESCRIPTION_LIKE = " SELECT GID,NAME,DESCRIPTION,MODULEURL,MODULEICON,SORT,STATE,PARENTID,SHOWROOTSTATE,TYPE FROM sys_module WHERE DESCRIPTION LIKE '%{0}%' ";
private const string SQL_SELECT_ACTION_BY_MODULE_ID = " SELECT COUNT(*) FROM [action] WHERE MODULEID = @module_id ";
private const string SQL_INSERT_ACTION = " INSERT INTO [action](GID,NAME,DESCRIPTION,MODULEID,CREATEUSER,CREATETIME,STATE,SORT) VALUES(@gid,@name,@description,@module_id,@create_user,GETDATE(),0,0) ";
private const string SQL_SELECT_ACTIONID_BY_MODULE_ID = " SELECT GID FROM [action] WHERE MODULEID = @module_id ";
private const string SQL_DELETE_USER_ACTION = " DELETE FROM user_action WHERE ACTIONID = @action_id ";
private const string SQL_DELETE_ACTION = " DELETE FROM [action] WHERE GID = @gid ";
#region 根据模板GID获取模板信息
/// <summary>
/// 根据模板GID获取模板信息
/// </summary>
/// <param name="moduleID"></param>
/// <returns></returns>
public ModuleEntity GetModuleByID(string moduleID)
{
//初始化返回变量
ModuleEntity moduleEntity = null;
//初始化参数并赋值
SqlParameter parm = new SqlParameter(PARM_MODULE_GID, SqlDbType.VarChar, 36);
parm.Value = moduleID;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_MODULE, parm))
{
try
{
moduleEntity = new ModuleEntity();
//读取字段值
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
moduleEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
moduleEntity.ModuleName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
moduleEntity.ModuleDescription = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
moduleEntity.ModuleUrl = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
moduleEntity.ModuleIcon = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
moduleEntity.ModuleSort = sqlRead.GetInt32(5);
}
if (!sqlRead.IsDBNull(6))
{
moduleEntity.ModuleState = sqlRead.GetInt32(6);
}
if (!sqlRead.IsDBNull(7))
{
moduleEntity.ParentID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
moduleEntity.ShowRootState = sqlRead.GetInt32(8);
}
if (!sqlRead.IsDBNull(9))
{
moduleEntity.ModuleType = sqlRead.GetInt32(9);
}
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return moduleEntity;
}
#endregion
#region 根据模糊查询模板NAME获取模板信息
/// <summary>
/// 根据模糊查询模板NAME获取模板信息
/// </summary>
/// <param name="moduleName"></param>
/// <returns></returns>
public IList<ModuleEntity> GetModuleByDescriptionLike(string tempModuleName)
{
IList<ModuleEntity> moduleEntities = new List<ModuleEntity>();
string strSql = String.Format(SQL_SELECT_MODULE_BY_DESCRIPTION_LIKE, tempModuleName);
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql, null))
{
try
{
//读取字段值
while (sqlRead.Read())
{
ModuleEntity moduleEntity = new ModuleEntity();
if (!sqlRead.IsDBNull(0))
{
moduleEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
moduleEntity.ModuleName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
moduleEntity.ModuleDescription = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
moduleEntity.ModuleUrl = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
moduleEntity.ModuleIcon = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
moduleEntity.ModuleSort = sqlRead.GetInt32(5);
}
if (!sqlRead.IsDBNull(6))
{
moduleEntity.ModuleState = sqlRead.GetInt32(6);
}
if (!sqlRead.IsDBNull(7))
{
moduleEntity.ParentID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
moduleEntity.ShowRootState = sqlRead.GetInt32(8);
}
if (!sqlRead.IsDBNull(9))
{
moduleEntity.ModuleType = sqlRead.GetInt32(9);
}
moduleEntities.Add(moduleEntity);
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return moduleEntities;
}
#endregion
#region 根据模板NAME获取模板信息
/// <summary>
/// 根据模板NAME获取模板信息
/// </summary>
/// <param name="moduleName"></param>
/// <returns></returns>
public ModuleEntity GetModuleByName(string moduleName)
{
//初始化返回变量
ModuleEntity moduleEntity = null;
//初始化参数并赋值
SqlParameter parm = new SqlParameter(PARM_MODULE_NAME, SqlDbType.VarChar, 36);
parm.Value = moduleName;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_MODULE_BY_NAME, parm))
{
try
{
moduleEntity = new ModuleEntity();
//读取字段值
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
moduleEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
moduleEntity.ModuleName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
moduleEntity.ModuleDescription = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
moduleEntity.ModuleUrl = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
moduleEntity.ModuleIcon = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
moduleEntity.ModuleSort = sqlRead.GetInt32(5);
}
if (!sqlRead.IsDBNull(6))
{
moduleEntity.ModuleState = sqlRead.GetInt32(6);
}
if (!sqlRead.IsDBNull(7))
{
moduleEntity.ParentID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
moduleEntity.ShowRootState = sqlRead.GetInt32(8);
}
if (!sqlRead.IsDBNull(9))
{
moduleEntity.ModuleType = sqlRead.GetInt32(9);
}
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return moduleEntity;
}
#endregion
#region 获取所有模板信息
/// <summary>
/// 获取所有模板信息
/// </summary>
/// <returns></returns>
public List<ModuleEntity> GetAll()
{
//初始化返回变量
List<ModuleEntity> moduleEntities = new List<ModuleEntity>();
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_MODULE_ALL, null))
{
try
{
//读取字段值
while (sqlRead.Read())
{
ModuleEntity moduleEntity = new ModuleEntity();
if (!sqlRead.IsDBNull(0))
{
moduleEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
moduleEntity.ModuleName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
moduleEntity.ModuleDescription = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
moduleEntity.ModuleUrl = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
moduleEntity.ModuleIcon = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
moduleEntity.ModuleSort = sqlRead.GetInt32(5);
}
if (!sqlRead.IsDBNull(6))
{
moduleEntity.ModuleState = sqlRead.GetInt32(6);
}
if (!sqlRead.IsDBNull(7))
{
moduleEntity.ParentID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
moduleEntity.ShowRootState = sqlRead.GetInt32(8);
}
if (!sqlRead.IsDBNull(9))
{
moduleEntity.ModuleType = sqlRead.GetInt32(9);
}
moduleEntities.Add(moduleEntity);
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return moduleEntities;
}
#endregion
#region 获取所选用户所有模板信息
/// <summary>
/// 获取所选用户所有模板信息
/// </summary>
/// <returns></returns>
public List<ModuleEntity> GetUserAll(string tempSelectedUserID)
{
//初始化返回变量
List<ModuleEntity> moduleEntities = new List<ModuleEntity>();
SqlParameter parm = new SqlParameter(PARM_USER_ACTION_USER_ID, SqlDbType.VarChar, 36);
parm.Value = tempSelectedUserID;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_MODULE_USER_ALL, parm))
{
try
{
//读取字段值
while (sqlRead.Read())
{
ModuleEntity moduleEntity = new ModuleEntity();
if (!sqlRead.IsDBNull(0))
{
moduleEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
moduleEntity.ModuleName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
moduleEntity.ModuleDescription = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
moduleEntity.ModuleUrl = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
moduleEntity.ModuleIcon = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
moduleEntity.ModuleSort = sqlRead.GetInt32(5);
}
if (!sqlRead.IsDBNull(6))
{
moduleEntity.ModuleState = sqlRead.GetInt32(6);
}
if (!sqlRead.IsDBNull(7))
{
moduleEntity.ParentID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
moduleEntity.ShowRootState = sqlRead.GetInt32(8);
}
if (!sqlRead.IsDBNull(9))
{
moduleEntity.ModuleType = sqlRead.GetInt32(9);
}
moduleEntities.Add(moduleEntity);
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return moduleEntities;
}
#endregion
#region 获取所有主模板的信息
/// <summary>
/// 获取所有主模板的信息
/// </summary>
/// <returns></returns>
public List<ModuleEntity> GetParentModule()
{
//初始化返回变量
List<ModuleEntity> moduleEntities = new List<ModuleEntity>();
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_MODULE_PARENT, null))
{
try
{
//读取字段值
while (sqlRead.Read())
{
ModuleEntity moduleEntity = new ModuleEntity();
if (!sqlRead.IsDBNull(0))
{
moduleEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
moduleEntity.ModuleName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
moduleEntity.ModuleDescription = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
moduleEntity.ModuleUrl = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
moduleEntity.ModuleIcon = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
moduleEntity.ModuleSort = sqlRead.GetInt32(5);
}
if (!sqlRead.IsDBNull(6))
{
moduleEntity.ModuleState = sqlRead.GetInt32(6);
}
if (!sqlRead.IsDBNull(7))
{
moduleEntity.ParentID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
moduleEntity.ShowRootState = sqlRead.GetInt32(8);
}
if (!sqlRead.IsDBNull(9))
{
moduleEntity.ModuleType = sqlRead.GetInt32(9);
}
moduleEntities.Add(moduleEntity);
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return moduleEntities;
}
#endregion
#region 获取选中用户所有主模板的信息
/// <summary>
/// 获取选中用户所有主模板的信息
/// </summary>
/// <returns></returns>
public List<ModuleEntity> GetUserParentModule(string tempSelectedUserID)
{
//初始化返回变量
List<ModuleEntity> moduleEntities = new List<ModuleEntity>();
SqlParameter parm = new SqlParameter(PARM_USER_ACTION_USER_ID, SqlDbType.VarChar, 36);
parm.Value = tempSelectedUserID;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_MODULE_USER_PARENT, parm))
{
try
{
//读取字段值
while (sqlRead.Read())
{
ModuleEntity moduleEntity = new ModuleEntity();
if (!sqlRead.IsDBNull(0))
{
moduleEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
moduleEntity.ModuleName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
moduleEntity.ModuleDescription = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
moduleEntity.ModuleUrl = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
moduleEntity.ModuleIcon = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
moduleEntity.ModuleSort = sqlRead.GetInt32(5);
}
if (!sqlRead.IsDBNull(6))
{
moduleEntity.ModuleState = sqlRead.GetInt32(6);
}
if (!sqlRead.IsDBNull(7))
{
moduleEntity.ParentID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
moduleEntity.ShowRootState = sqlRead.GetInt32(8);
}
if (!sqlRead.IsDBNull(9))
{
moduleEntity.ModuleType = sqlRead.GetInt32(9);
}
moduleEntities.Add(moduleEntity);
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return moduleEntities;
}
#endregion
#region 获得所有子模板
/// <summary>
/// 获得所有子模板
/// </summary>
/// <returns></returns>
public List<ModuleEntity> GetAllSubModules()
{
//初始化返回变量
List<ModuleEntity> moduleEntities = new List<ModuleEntity>();
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_MODULE_ALLSUB, null))
{
try
{
//读取字段值
while (sqlRead.Read())
{
ModuleEntity moduleEntity = new ModuleEntity();
if (!sqlRead.IsDBNull(0))
{
moduleEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
moduleEntity.ModuleName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
moduleEntity.ModuleDescription = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
moduleEntity.ModuleUrl = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
moduleEntity.ModuleIcon = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
moduleEntity.ModuleSort = sqlRead.GetInt32(5);
}
if (!sqlRead.IsDBNull(6))
{
moduleEntity.ModuleState = sqlRead.GetInt32(6);
}
if (!sqlRead.IsDBNull(7))
{
moduleEntity.ParentID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
moduleEntity.ShowRootState = sqlRead.GetInt32(8);
}
if (!sqlRead.IsDBNull(9))
{
moduleEntity.ModuleType = sqlRead.GetInt32(9);
}
moduleEntities.Add(moduleEntity);
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return moduleEntities;
}
#endregion
#region 获得所选用户的所有子模板
/// <summary>
/// 获得所选用户的所有子模板
/// </summary>
/// <returns></returns>
public List<ModuleEntity> GetUserAllSubModules(string tempSelectedUserID)
{
//初始化返回变量
List<ModuleEntity> moduleEntities = new List<ModuleEntity>();
SqlParameter parm = new SqlParameter(PARM_USER_ACTION_USER_ID, SqlDbType.VarChar, 36);
parm.Value = tempSelectedUserID;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_MODULE_USER_ALLSUB, parm))
{
try
{
//读取字段值
while (sqlRead.Read())
{
ModuleEntity moduleEntity = new ModuleEntity();
if (!sqlRead.IsDBNull(0))
{
moduleEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
moduleEntity.ModuleName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
moduleEntity.ModuleDescription = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
moduleEntity.ModuleUrl = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
moduleEntity.ModuleIcon = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
moduleEntity.ModuleSort = sqlRead.GetInt32(5);
}
if (!sqlRead.IsDBNull(6))
{
moduleEntity.ModuleState = sqlRead.GetInt32(6);
}
if (!sqlRead.IsDBNull(7))
{
moduleEntity.ParentID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
moduleEntity.ShowRootState = sqlRead.GetInt32(8);
}
if (!sqlRead.IsDBNull(9))
{
moduleEntity.ModuleType = sqlRead.GetInt32(9);
}
moduleEntities.Add(moduleEntity);
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return moduleEntities;
}
#endregion
#region 获取与主模板相关联的所有子模板的信息
/// <summary>
/// 获取所有子模板的信息
/// </summary>
/// <returns></returns>
public List<ModuleEntity> GetSubModule(string strParentGid)
{
//初始化返回变量
List<ModuleEntity> moduleEntities = new List<ModuleEntity>();
//初始化参数并赋值
SqlParameter parm = new SqlParameter(PARM_MODULE_GID, SqlDbType.VarChar, 36);
parm.Value = strParentGid;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_MODULE_SUB, parm))
{
try
{
//读取字段值
while (sqlRead.Read())
{
ModuleEntity moduleEntity = new ModuleEntity();
if (!sqlRead.IsDBNull(0))
{
moduleEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
moduleEntity.ModuleName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
moduleEntity.ModuleDescription = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
moduleEntity.ModuleUrl = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
moduleEntity.ModuleIcon = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
moduleEntity.ModuleSort = sqlRead.GetInt32(5);
}
if (!sqlRead.IsDBNull(6))
{
moduleEntity.ModuleState = sqlRead.GetInt32(6);
}
if (!sqlRead.IsDBNull(7))
{
moduleEntity.ParentID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
moduleEntity.ShowRootState = sqlRead.GetInt32(8);
}
if (!sqlRead.IsDBNull(9))
{
moduleEntity.ModuleType = sqlRead.GetInt32(9);
}
moduleEntities.Add(moduleEntity);
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return moduleEntities;
}
#endregion
#region 获取模板信息
/// <summary>
/// 获取模板信息
/// </summary>
/// <param name="strType">SQL_SELECT_MODULE_ALLSQL_SELECT_MODULE_PARENTSQL_SELECT_MODULE_SUB</param>
/// <returns></returns>
public List<ModuleEntity> GetModules(string strSql, string strGid)
{
//初始化返回变量
List<ModuleEntity> moduleEntities = new List<ModuleEntity>();
//初始化参数并赋值
SqlParameter parm = null;
if (!strGid.Trim().Equals(""))
{
parm = new SqlParameter(PARM_MODULE_GID, SqlDbType.VarChar, 36);
parm.Value = strGid;
}
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_MODULE_ALL, null))
{
try
{
//读取字段值
while (sqlRead.Read())
{
ModuleEntity moduleEntity = new ModuleEntity();
if (!sqlRead.IsDBNull(0))
{
moduleEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
moduleEntity.ModuleName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
moduleEntity.ModuleDescription = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
moduleEntity.ModuleUrl = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
moduleEntity.ModuleIcon = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
moduleEntity.ModuleSort = sqlRead.GetInt32(5);
}
if (!sqlRead.IsDBNull(6))
{
moduleEntity.ModuleState = sqlRead.GetInt32(6);
}
if (!sqlRead.IsDBNull(7))
{
moduleEntity.ParentID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
moduleEntity.ShowRootState = sqlRead.GetInt32(8);
}
if (!sqlRead.IsDBNull(9))
{
moduleEntity.ModuleType = sqlRead.GetInt32(9);
}
moduleEntities.Add(moduleEntity);
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return moduleEntities;
}
#endregion
#region 获取用户基本设置页面主模板的信息
/// <summary>
/// 获取用户基本设置页面主模板的信息
/// </summary>
/// <returns></returns>
public List<ModuleEntity> GetUserBaseParentModule()
{
//初始化返回变量
List<ModuleEntity> moduleEntities = new List<ModuleEntity>();
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_MODULE_USERBASE, null))
{
try
{
//读取字段值
while (sqlRead.Read())
{
ModuleEntity moduleEntity = new ModuleEntity();
if (!sqlRead.IsDBNull(0))
{
moduleEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
moduleEntity.ModuleName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
moduleEntity.ModuleDescription = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
moduleEntity.ModuleUrl = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
moduleEntity.ModuleIcon = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
moduleEntity.ModuleSort = sqlRead.GetInt32(5);
}
if (!sqlRead.IsDBNull(6))
{
moduleEntity.ModuleState = sqlRead.GetInt32(6);
}
if (!sqlRead.IsDBNull(7))
{
moduleEntity.ParentID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
moduleEntity.ShowRootState = sqlRead.GetInt32(8);
}
if (!sqlRead.IsDBNull(9))
{
moduleEntity.ModuleType = sqlRead.GetInt32(9);
}
moduleEntities.Add(moduleEntity);
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return moduleEntities;
}
#endregion
#region 获得用户基本设置页面所有子模板
/// <summary>
/// 获得用户基本设置页面所有子模板
/// </summary>
/// <returns></returns>
public List<ModuleEntity> GetAllUserBaseSubModules()
{
//初始化返回变量
List<ModuleEntity> moduleEntities = new List<ModuleEntity>();
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_MODULE_USERBASE_SUB, null))
{
try
{
//读取字段值
while (sqlRead.Read())
{
ModuleEntity moduleEntity = new ModuleEntity();
if (!sqlRead.IsDBNull(0))
{
moduleEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
moduleEntity.ModuleName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
moduleEntity.ModuleDescription = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
moduleEntity.ModuleUrl = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
moduleEntity.ModuleIcon = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
moduleEntity.ModuleSort = sqlRead.GetInt32(5);
}
if (!sqlRead.IsDBNull(6))
{
moduleEntity.ModuleState = sqlRead.GetInt32(6);
}
if (!sqlRead.IsDBNull(7))
{
moduleEntity.ParentID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
moduleEntity.ShowRootState = sqlRead.GetInt32(8);
}
if (!sqlRead.IsDBNull(9))
{
moduleEntity.ModuleType = sqlRead.GetInt32(9);
}
moduleEntities.Add(moduleEntity);
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return moduleEntities;
}
#endregion
#region 获取操作模块所有主模板
/// <summary>
/// 获取操作模块所有主模板
/// </summary>
/// <param name="iType">所要查找的type类型 值为1表示查找用户管理操作模块; 值为2表示查找海运出口操作模块; 值为3表示查找海运进口操作模块</param>
/// <returns></returns>
public List<ModuleEntity> GetModuleByType(ModuleType moduleType)
{
_module_type = moduleType;
//初始化返回变量
List<ModuleEntity> moduleEntities = new List<ModuleEntity>();
SqlParameter parm = new SqlParameter(PARM_MODULE_TYPE, SqlDbType.Int);
parm.Value = ModuleType.USER;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_MODULE_BY_TYPE, parm))
{
try
{
//读取字段值
while (sqlRead.Read())
{
ModuleEntity moduleEntity = new ModuleEntity();
if (!sqlRead.IsDBNull(0))
{
moduleEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
moduleEntity.ModuleName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
moduleEntity.ModuleDescription = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
moduleEntity.ModuleUrl = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
moduleEntity.ModuleIcon = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
moduleEntity.ModuleSort = sqlRead.GetInt32(5);
}
if (!sqlRead.IsDBNull(6))
{
moduleEntity.ModuleState = sqlRead.GetInt32(6);
}
if (!sqlRead.IsDBNull(7))
{
moduleEntity.ParentID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
moduleEntity.ShowRootState = sqlRead.GetInt32(8);
}
if (!sqlRead.IsDBNull(9))
{
moduleEntity.ModuleType = sqlRead.GetInt32(9);
}
moduleEntities.Add(moduleEntity);
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return moduleEntities;
}
#endregion
public enum ModuleType
{
USER = 1,//用户管理操作
SEAEXPORT = 2,//海运出口管理操作
SEAIMPORT = 3,//海运进口管理操作
SEAILCLMPORT = 4,//海运进口散货管理操作
}
public ModuleType Type
{
get { return _module_type; }
set { _module_type = value; }
}
#region 返回执行SQL语句获取的数据集
/// <summary>
/// 返回执行SQL语句获取的数据集
/// </summary>
/// <param name="strSql">执行查询SQL语句</param>
/// <returns>返回数据集</returns>
public DataSet GetExcuteSql(string strSql)
{
DataSet tempSet = new DataSet();
tempSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql);
return tempSet;
}
#endregion
#region 更新模块信息
/// <summary>
/// 更新模块信息
/// </summary>
/// <param name="moduleEntity">模块实体类moduleEntity</param>
/// <returns>值1表示更新成功 值不等于1表示更新失败</returns>
public int UpdateModule(ModuleEntity moduleEntity)
{
int iResult = 0;
SqlParameter[] updateParms = new SqlParameter[] {
new SqlParameter(PARM_MODULE_NAME,SqlDbType.VarChar,150),
new SqlParameter(PARM_MODULE_DESCRIPTION,SqlDbType.VarChar,150),
new SqlParameter(PARM_MODULE_MODULE_URL,SqlDbType.VarChar,50),
new SqlParameter(PARM_MODULE_MODULE_ICON,SqlDbType.VarChar,50),
new SqlParameter(PARM_MODULE_PARENT_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_MODULE_SORT,SqlDbType.Int),
new SqlParameter(PARM_MODULE_STATE,SqlDbType.Int),
new SqlParameter(PARM_MODULE_MODIFIED_USER,SqlDbType.VarChar,36),
new SqlParameter(PARM_MODULE_SHOW_ROOT_STATES,SqlDbType.Int),
new SqlParameter(PARM_MODULE_TYPE,SqlDbType.Int),
new SqlParameter(PARM_MODULE_GID,SqlDbType.VarChar,36)
};
updateParms[0].Value = moduleEntity.ModuleName;
updateParms[1].Value = moduleEntity.ModuleDescription;
updateParms[2].Value = moduleEntity.ModuleUrl;
updateParms[3].Value = moduleEntity.ModuleIcon;
updateParms[4].Value = moduleEntity.ParentID;
updateParms[5].Value = moduleEntity.ModuleSort;
updateParms[6].Value = moduleEntity.ModuleState;
updateParms[7].Value = moduleEntity.ModifiedUser;
updateParms[8].Value = moduleEntity.ShowRootState;
updateParms[9].Value = moduleEntity.ModuleType;
updateParms[10].Value = moduleEntity.Gid;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, SQL_UPDATE_MODULE, updateParms);
if (existVal > 0)
{
iResult = 1;
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
#endregion
#region 插入模块信息
/// <summary>
/// 插入模块信息
/// </summary>
/// <param name="moduleEntity">模块实体类ModuleEntity</param>
/// <returns>值1表示插入成功 值不等于1表示插入失败</returns>
public int InsertModule(ModuleEntity moduleEntity,ActionEntity actionEntity)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
//插入模块信息
SqlParameter[] insertParms = new SqlParameter[] {
new SqlParameter(PARM_MODULE_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_MODULE_NAME,SqlDbType.VarChar,150),
new SqlParameter(PARM_MODULE_DESCRIPTION,SqlDbType.VarChar,150),
new SqlParameter(PARM_MODULE_MODULE_URL,SqlDbType.VarChar,50),
new SqlParameter(PARM_MODULE_MODULE_ICON,SqlDbType.VarChar,50),
new SqlParameter(PARM_MODULE_PARENT_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_MODULE_SORT,SqlDbType.Int),
new SqlParameter(PARM_MODULE_STATE,SqlDbType.Int),
new SqlParameter(PARM_MODULE_CREATE_USER,SqlDbType.VarChar,36),
new SqlParameter(PARM_MODULE_SHOW_ROOT_STATES,SqlDbType.Int),
new SqlParameter(PARM_MODULE_TYPE,SqlDbType.Int)
};
insertParms[0].Value = moduleEntity.Gid;
insertParms[1].Value = moduleEntity.ModuleName;
insertParms[2].Value = moduleEntity.ModuleDescription;
insertParms[3].Value = moduleEntity.ModuleUrl;
insertParms[4].Value = moduleEntity.ModuleIcon;
insertParms[5].Value = moduleEntity.ParentID;
insertParms[6].Value = moduleEntity.ModuleSort;
insertParms[7].Value = moduleEntity.ModuleState;
insertParms[8].Value = moduleEntity.CreateUser;
insertParms[9].Value = moduleEntity.ShowRootState;
insertParms[10].Value = moduleEntity.ModuleType;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_MODULE, insertParms);
//先判断action是否有重复的信息
SqlParameter[] existParms = new SqlParameter[] {
new SqlParameter(PARM_ACTION_MODULE_ID,SqlDbType.VarChar,36)
};
existParms[0].Value = moduleEntity.Gid;
int existState = (int)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_SELECT_ACTION_BY_MODULE_ID, existParms);
if (existState == 0)
{
SqlParameter[] actionParms = new SqlParameter[] {
new SqlParameter(PARM_ACTION_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_ACTION_NAME,SqlDbType.VarChar,50),
new SqlParameter(PARM_ACTION_DESCRIPTION,SqlDbType.VarChar,50),
new SqlParameter(PARM_ACTION_MODULE_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_ACTION_CREATE_USER,SqlDbType.VarChar,36)
};
actionParms[0].Value = actionEntity.GID;
actionParms[1].Value = actionEntity.ActionName;
actionParms[2].Value = actionEntity.Description;
actionParms[3].Value = actionEntity.ModuleID;
actionParms[4].Value = actionEntity.CreateUserID;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_ACTION, actionParms);
}
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
#endregion
#region 删除模块
/// <summary>
/// 删除模块
/// </summary>
/// <param name="tempModuleGID">模块GID</param>
/// <returns>值1表示删除成功 值不等于1表示删除失败</returns>
public int DeleteModule(string tempModuleGID)
{
int iResult = 0;
string strActionID = "";
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
//先判断当前要删除的模块是否已经制定给用户
SqlParameter getActionParm = new SqlParameter(PARM_ACTION_MODULE_ID, SqlDbType.VarChar, 36);
getActionParm.Value = tempModuleGID;
strActionID = (string)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_SELECT_ACTIONID_BY_MODULE_ID, getActionParm);
//如果已指定到客户则先将指定到客户的action删除
if (strActionID != "")
{
SqlParameter delUserActionParm = new SqlParameter(PARM_USER_ACTION_ACTION_ID, SqlDbType.VarChar, 36);
delUserActionParm.Value = strActionID;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_DELETE_USER_ACTION, delUserActionParm);
//删除action表信息
SqlParameter delActionParm = new SqlParameter(PARM_ACTION_GID, SqlDbType.VarChar, 36);
delActionParm.Value = strActionID;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_DELETE_ACTION, delActionParm);
//删除模块信息
SqlParameter[] deleteParms = new SqlParameter[] {
new SqlParameter(PARM_MODULE_GID,SqlDbType.VarChar,36)
};
deleteParms[0].Value = tempModuleGID;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_DELETE_MODULE, deleteParms);
}
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
#endregion
}
}