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.

392 lines
15 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.Data;
using System.Data.SqlClient;
using DSWeb.Models;
using WebSqlHelper;
namespace DSWeb.EntityDA
{
public class AttributeDA
{
private const string PARM_ATTR_GID = "@gid";
private const string PARM_ATTR_NAME = "@name";
private const string PARM_ATTR_DESCRIPTION = "@description";
private const string PARM_ATTR_DEFAULT_VALUE = "@default_value";
private const string PARM_ATTR_CREATE_USER = "@create_user";
private const string PARM_ATTR_CREATE_TIME = "@create_time";
private const string PARM_ATTR_MODIFIED_USER = "@modified_user";
private const string PARM_ATTR_MODIFIED_TIME = "@modified_time";
private const string PARM_ATTR_IS_DELETE = "@is_delete";
private const string PARM_ATTR_DELETE_USER = "@delete_user";
private const string PARM_ATTR_DELETE_TIME = "@delete_time";
private const string PARM_ATTR_STATE = "@state";
private const string PARM_ATTR_SORT = "@sort";
private const string PARM_ATTR_TYPE_ID = "@type_id";
private const string SQL_SELECT_ATTR_BY_GID = " SELECT GID, NAME, DESCRIPTION, DEFAULTVALUE, CREATEUSER, CREATETIME, MODIFIEDUSER, MODIFIEDTIME, ISDELETE, DELETEUSER, DELETETIME, STATE, SORT, TYPEID "
+ " FROM attribute WHERE GID = @gid ";
private const string SQL_SELECT_ATTR_BY_NAME = " SELECT GID, NAME, DESCRIPTION, DEFAULTVALUE, CREATEUSER, CREATETIME, MODIFIEDUSER, MODIFIEDTIME, ISDELETE, DELETEUSER, DELETETIME, STATE, SORT, TYPEID "
+ " FROM attribute WHERE NAME = @name ";
private const string SQL_INSERT_ATTR_BY_GID = " INSERT INTO attribute (GID, NAME, DESCRIPTION, DEFAULTVALUE, CREATEUSER, CREATETIME,STATE, SORT, TYPEID) VALUES "
+ " (@gid,@name,@description,@default_value,@create_user,GETDATE(),@state,@sort,@type_id) ";
private const string SQL_UPDATE_ATTR_BY_GID = " UPDATE attribute SET NAME = @name,DESCRIPTION = @description,DEFAULTVALUE = @default_value,MODIFIEDUSER = @modified_user,STATE = @state,SORT = @sort,TYPEID = @type_id"
+ " WHERE GID = @gid ";
private const string SQL_DELETE_ATTR_BY_GID = " UPDATE attribute SET ISDELETE = 1,DELETEUSER = @delete_user,DELETETIME = GETDATE() WHERE GID = @gid ";
#region 通过GID删除参数信息
/// <summary>
/// 通过GID删除参数信息
/// </summary>
/// <param name="tempAttributeID">参数GID</param>
/// <param name="tempOperatorID">操作人GID</param>
/// <returns>值1表示参数删除成功 值不等于1表示删除失败</returns>
public int DeleteAttributeByGID(string tempAttributeID,string tempOperatorID)
{
int iResult = 0;
using (SqlConnection sqlConn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlParameter[] parms = new SqlParameter[] {
new SqlParameter(PARM_ATTR_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_ATTR_DELETE_USER,SqlDbType.VarChar,36)
};
parms[0].Value = tempAttributeID;
parms[1].Value = tempOperatorID;
iResult = SqlHelper.ExecuteNonQuery(sqlConn, CommandType.Text, SQL_DELETE_ATTR_BY_GID, parms);
}
catch (Exception)
{
iResult = -1;
}
}
return iResult;
}
#endregion
#region 根据参数GID获取相关参数
/// <summary>
/// 根据参数GID获取相关参数
/// </summary>
/// <param name="tempAttributeID">参数GID</param>
/// <returns>返回实体类</returns>
public AttributeEntity GetAttributeByID(string tempAttributeID)
{
AttributeEntity attributeEntity = null;
SqlParameter parm = new SqlParameter(PARM_ATTR_GID, SqlDbType.VarChar, 36);
parm.Value = tempAttributeID;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_ATTR_BY_GID, parm))
{
try
{
while (sqlRead.Read())
{
attributeEntity = new AttributeEntity();
if (!sqlRead.IsDBNull(0))
{
attributeEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
attributeEntity.Name = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
attributeEntity.Description = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
attributeEntity.DefaultValue = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
attributeEntity.CreateUser = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
attributeEntity.CreateTime = sqlRead.GetDateTime(5);
}
if (!sqlRead.IsDBNull(6))
{
attributeEntity.ModifiedUser = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
attributeEntity.ModifiedTime = sqlRead.GetDateTime(7);
}
if (!sqlRead.IsDBNull(8))
{
attributeEntity.IsDelete = sqlRead.GetBoolean(8);
}
if (!sqlRead.IsDBNull(9))
{
attributeEntity.DeleteUser = sqlRead.GetString(9);
}
if (!sqlRead.IsDBNull(10))
{
attributeEntity.DeleteTime = sqlRead.GetDateTime(10);
}
if (!sqlRead.IsDBNull(11))
{
attributeEntity.State = sqlRead.GetInt32(11);
}
if (!sqlRead.IsDBNull(12))
{
attributeEntity.Sort = sqlRead.GetInt32(12);
}
if (!sqlRead.IsDBNull(13))
{
attributeEntity.TypeID = sqlRead.GetString(13);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return attributeEntity;
}
#endregion
#region 根据参数NAME获取相关参数attribute
/// <summary>
/// 根据参数NAME获取相关参数attribute
/// </summary>
/// <param name="tempAttributeName">参数NAME</param>
/// <returns>返回实体类</returns>
public AttributeEntity GetAttributeByName(string tempAttributeName)
{
AttributeEntity attributeEntity = null;
SqlParameter parm = new SqlParameter(PARM_ATTR_NAME, SqlDbType.VarChar, 50);
parm.Value = tempAttributeName;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_ATTR_BY_NAME, parm))
{
try
{
while (sqlRead.Read())
{
attributeEntity = new AttributeEntity();
if (!sqlRead.IsDBNull(0))
{
attributeEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
attributeEntity.Name = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
attributeEntity.Description = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
attributeEntity.DefaultValue = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
attributeEntity.CreateUser = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
attributeEntity.CreateTime = sqlRead.GetDateTime(5);
}
if (!sqlRead.IsDBNull(6))
{
attributeEntity.ModifiedUser = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
attributeEntity.ModifiedTime = sqlRead.GetDateTime(7);
}
if (!sqlRead.IsDBNull(8))
{
attributeEntity.IsDelete = sqlRead.GetBoolean(8);
}
if (!sqlRead.IsDBNull(9))
{
attributeEntity.DeleteUser = sqlRead.GetString(9);
}
if (!sqlRead.IsDBNull(10))
{
attributeEntity.DeleteTime = sqlRead.GetDateTime(10);
}
if (!sqlRead.IsDBNull(11))
{
attributeEntity.State = sqlRead.GetInt32(11);
}
if (!sqlRead.IsDBNull(12))
{
attributeEntity.Sort = sqlRead.GetInt32(12);
}
if (!sqlRead.IsDBNull(13))
{
attributeEntity.TypeID = sqlRead.GetString(13);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return attributeEntity;
}
#endregion
#region 插入参数
/// <summary>
/// 插入参数类型
/// </summary>
/// <param name="tempAttributeEntity">参数实体类</param>
/// <returns>值1表示插入完成 值不等于1表示插入失败</returns>
public int InsertAttribute(AttributeEntity tempAttributeEntity)
{
int iResult = 0;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
SqlParameter[] parms = new SqlParameter[] {
new SqlParameter(PARM_ATTR_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_ATTR_NAME,SqlDbType.VarChar,50),
new SqlParameter(PARM_ATTR_DESCRIPTION,SqlDbType.VarChar,50),
new SqlParameter(PARM_ATTR_DEFAULT_VALUE,SqlDbType.VarChar,50),
new SqlParameter(PARM_ATTR_CREATE_USER,SqlDbType.VarChar,36),
new SqlParameter(PARM_ATTR_STATE,SqlDbType.Int),
new SqlParameter(PARM_ATTR_SORT,SqlDbType.Int),
new SqlParameter(PARM_ATTR_TYPE_ID,SqlDbType.VarChar,36)
};
parms[0].Value = tempAttributeEntity.GID;
parms[1].Value = tempAttributeEntity.Name;
parms[2].Value = tempAttributeEntity.Description;
parms[3].Value = tempAttributeEntity.DefaultValue;
parms[4].Value = tempAttributeEntity.CreateUser;
parms[5].Value = tempAttributeEntity.State;
parms[6].Value = tempAttributeEntity.Sort;
parms[7].Value = tempAttributeEntity.TypeID;
try
{
iResult = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, SQL_INSERT_ATTR_BY_GID, parms);
}
catch (Exception error)
{
iResult = -1;//插入异常
throw error;
}
}
return iResult;
}
#endregion
#region 更新参数
/// <summary>
/// 更新参数类型
/// </summary>
/// <param name="tempAttributeEntity">参数实体类</param>
/// <returns>值1表示更新完成 值不等于1表示更新失败</returns>
public int UpdateAttribute(AttributeEntity tempAttributeEntity)
{
int iResult = 0;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
SqlParameter[] parms = new SqlParameter[] {
new SqlParameter(PARM_ATTR_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_ATTR_NAME,SqlDbType.VarChar,50),
new SqlParameter(PARM_ATTR_DESCRIPTION,SqlDbType.VarChar,50),
new SqlParameter(PARM_ATTR_DEFAULT_VALUE,SqlDbType.VarChar,50),
new SqlParameter(PARM_ATTR_MODIFIED_USER,SqlDbType.VarChar,36),
new SqlParameter(PARM_ATTR_STATE,SqlDbType.Int),
new SqlParameter(PARM_ATTR_SORT,SqlDbType.Int),
new SqlParameter(PARM_ATTR_TYPE_ID,SqlDbType.VarChar,36)
};
parms[0].Value = tempAttributeEntity.GID;
parms[1].Value = tempAttributeEntity.Name;
parms[2].Value = tempAttributeEntity.Description;
parms[3].Value = tempAttributeEntity.DefaultValue;
parms[4].Value = tempAttributeEntity.ModifiedUser;
parms[5].Value = tempAttributeEntity.State;
parms[6].Value = tempAttributeEntity.Sort;
parms[7].Value = tempAttributeEntity.TypeID;
try
{
iResult = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, SQL_UPDATE_ATTR_BY_GID, parms);
}
catch (Exception error)
{
iResult = -1;//插入异常
throw error;
}
}
return iResult;
}
#endregion
#region 获取SQL语句查询数据集
/// <summary>
/// 获取SQL语句查询数据集
/// </summary>
/// <param name="strSql"></param>
/// <returns></returns>
public DataSet GetExcuteSql(string strSql)
{
DataSet tempSet = new DataSet();
tempSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql);
return tempSet;
}
#endregion
}
}