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.

399 lines
16 KiB
C#

10 months ago
using System;
using System.Data;
using System.Data.SqlClient;
using DSWeb.Models;
using WebSqlHelper;
namespace DSWeb.EntityDA
{
public class AttributeCompanyDA
{
private const string PARM_ATTR_COMP_GID = "@gid";
private const string PARM_ATTR_COMP_COMPANYID = "@company_id";
private const string PARM_ATTR_COMP_ATTRIBUTEID = "@attribute_id";
private const string PARM_ATTR_COMP_VALUE = "@value";
private const string PARM_ATTR_COMP_CREATE_USER = "@create_user";
private const string PARM_ATTR_COMP_CREATE_TIME = "@create_time";
private const string PARM_ATTR_COMP_MODIFIED_USER = "@modified_user";
private const string PARM_ATTR_COMP_MODIFIED_TIME = "@modified_time";
private const string PARM_ATTR_COMP_IS_DELETE = "@is_delete";
private const string PARM_ATTR_COMP_DELETE_USER = "@delete_user";
private const string PARM_ATTR_COMP_DELETE_TIME = "@delete_time";
private const string SQL_INSERT_ATTR_COMP = " INSERT INTO company_attribute(GID,COMPANYID,ATTRIBUTEID,VALUE,CREATEUSER,CREATETIME) "
+ " VALUES(@gid,@company_id,@attribute_id,@value,@create_user,GETDATE()) ";
private const string SQL_UPDATE_ATTR_COMP = " UPDATE company_attribute SET COMPANYID = @company_id,ATTRIBUTEID = @attribute_id,VALUE = @value,MODIFIEDUSER = @modified_user,MODIFIEDTIME = GETDATE() WHERE GID = @gid";
private const string SQL_SELECT_ATTR_COMP_BY_GID = "SELECT GID,COMPANYID, ATTRIBUTEID, VALUE, CREATEUSER, CREATETIME, MODIFIEDUSER, MODIFIEDTIME, ISDELETE, DELETEUSER,DELETETIME FROM company_attribute WHERE GID = @gid";
private const string SQL_SELECT_ATTR_COMP_BY_ATTRID_AND_COMPID = " SELECT GID,COMPANYID, ATTRIBUTEID, VALUE, CREATEUSER, CREATETIME, MODIFIEDUSER, MODIFIEDTIME, ISDELETE, DELETEUSER,DELETETIME FROM company_attribute "
+ " WHERE ATTRIBUTEID = @attribute_id AND COMPANYID = @company_id AND ISNULL(ISDELETE,0) <> 1 ";
private const string SQL_SELECT_ATTR_COMP_CHECK = " SELECT COUNT(*) FROM company_attribute WHERE ATTRIBUTEID = @attribute_id AND COMPANYID = @company_id AND GID <> @gid AND ISNULL(ISDELETE,0) <> 1 ";
private const string SQL_DELETE_ATTR_COMP = " UPDATE company_attribute SET ISDELETE = 1,DELETEUSER = @delete_user,DELETETIME = GETDATE() WHERE GID = @gid ";
#region 删除公司参数信息
/// <summary>
/// 删除公司参数信息
/// </summary>
/// <param name="tempCompanyAttributeID">公司参数GID</param>
/// <param name="tempOperatorID">操作人GID</param>
/// <returns>值1表示删除成功 值不等于1表示删除失败</returns>
public int DeleteCompanyAttributeByID(string tempCompanyAttributeID,string tempOperatorID)
{
int iResult = 0;
using (SqlConnection sqlConn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlParameter[] parms = new SqlParameter[] {
new SqlParameter(PARM_ATTR_COMP_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_ATTR_COMP_DELETE_USER,SqlDbType.VarChar,36)
};
parms[0].Value = tempCompanyAttributeID;
parms[1].Value = tempOperatorID;
iResult = SqlHelper.ExecuteNonQuery(sqlConn, CommandType.Text, SQL_DELETE_ATTR_COMP, parms);
}
catch (Exception)
{
iResult = -1;
}
}
return iResult;
}
#endregion
#region 是否存在同样的参数
/// <summary>
/// 是否存在同样的参数
/// </summary>
/// <param name="tempCompanyAttributeID">公司参数GID</param>
/// <param name="tempAttributeID">参数GID</param>
/// <param name="tempCompanyID">公司GID</param>
/// <returns>值True不存在已经添加的参数 值False存在已经添加的参数</returns>
public bool IsSameAttribute(string tempCompanyAttributeID,string tempAttributeID,string tempCompanyID)
{
bool bResult = false;
using (SqlConnection sqlConn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlParameter[] parms = new SqlParameter[] {
new SqlParameter(PARM_ATTR_COMP_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_ATTR_COMP_ATTRIBUTEID,SqlDbType.VarChar,36),
new SqlParameter(PARM_ATTR_COMP_COMPANYID,SqlDbType.VarChar,36)
};
parms[0].Value = tempCompanyAttributeID;
parms[1].Value = tempAttributeID;
parms[2].Value = tempCompanyID;
int tempCount = (int)SqlHelper.ExecuteScalar(sqlConn, CommandType.Text, SQL_SELECT_ATTR_COMP_CHECK, parms);
if (tempCount > 0)
{
bResult = true;
}
else
{
bResult = false;
}
}
catch(Exception)
{
bResult = false;
}
}
return bResult;
}
#endregion
#region 根据公司参数GID获取分公司参数
/// <summary>
/// 根据参数GID获取分公司参数
/// </summary>
/// <param name="tempCompanyAttributeID">分公司参数GID</param>
/// <returns>返回实体类</returns>
public AttributeCompanyEntity GetCompanyAttributeByID(string tempCompanyAttributeID)
{
AttributeCompanyEntity attributeCompanyEntity = null;
SqlParameter parm = new SqlParameter(PARM_ATTR_COMP_GID, SqlDbType.VarChar, 36);
parm.Value = tempCompanyAttributeID;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_ATTR_COMP_BY_GID, parm))
{
try
{
while (sqlRead.Read())
{
attributeCompanyEntity = new AttributeCompanyEntity();
if (!sqlRead.IsDBNull(0))
{
attributeCompanyEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
attributeCompanyEntity.CompanyID = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
attributeCompanyEntity.AttributeID = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
attributeCompanyEntity.AttributeValue = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
attributeCompanyEntity.CreateUser = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
attributeCompanyEntity.CreateTime = sqlRead.GetDateTime(5);
}
if (!sqlRead.IsDBNull(6))
{
attributeCompanyEntity.ModifiedUser = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
attributeCompanyEntity.ModifiedTime = sqlRead.GetDateTime(7);
}
if (!sqlRead.IsDBNull(8))
{
attributeCompanyEntity.IsDelete = sqlRead.GetBoolean(8);
}
if (!sqlRead.IsDBNull(9))
{
attributeCompanyEntity.DeleteUser = sqlRead.GetString(9);
}
if (!sqlRead.IsDBNull(10))
{
attributeCompanyEntity.DeleteTime = sqlRead.GetDateTime(10);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return attributeCompanyEntity;
}
#endregion
#region 根据参数GID和公司GID获取公司参数company_attribute
/// <summary>
/// 根据参数GID和公司GID获取公司参数company_attribute
/// </summary>
/// <param name="tempAttributeID">参数GID</param>
/// <param name="tempCompanyID">公司GID</param>
/// <returns>返回实体类</returns>
public AttributeCompanyEntity GetCompanyAttributeByAttributeAndCompany(string tempAttributeID,string tempCompanyID)
{
AttributeCompanyEntity attributeCompanyEntity = null;
SqlParameter[] parms = new SqlParameter[] {
new SqlParameter(PARM_ATTR_COMP_ATTRIBUTEID, SqlDbType.VarChar, 36),
new SqlParameter(PARM_ATTR_COMP_COMPANYID, SqlDbType.VarChar, 36)
};
parms[0].Value = tempAttributeID;
parms[1].Value = tempCompanyID;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_ATTR_COMP_BY_ATTRID_AND_COMPID, parms))
{
try
{
while (sqlRead.Read())
{
attributeCompanyEntity = new AttributeCompanyEntity();
if (!sqlRead.IsDBNull(0))
{
attributeCompanyEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
attributeCompanyEntity.CompanyID = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
attributeCompanyEntity.AttributeID = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
attributeCompanyEntity.AttributeValue = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
attributeCompanyEntity.CreateUser = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
attributeCompanyEntity.CreateTime = sqlRead.GetDateTime(5);
}
if (!sqlRead.IsDBNull(6))
{
attributeCompanyEntity.ModifiedUser = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
attributeCompanyEntity.ModifiedTime = sqlRead.GetDateTime(7);
}
if (!sqlRead.IsDBNull(8))
{
attributeCompanyEntity.IsDelete = sqlRead.GetBoolean(8);
}
if (!sqlRead.IsDBNull(9))
{
attributeCompanyEntity.DeleteUser = sqlRead.GetString(9);
}
if (!sqlRead.IsDBNull(10))
{
attributeCompanyEntity.DeleteTime = sqlRead.GetDateTime(10);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return attributeCompanyEntity;
}
#endregion
#region 插入分公司参数
/// <summary>
/// 插入分公司参数
/// </summary>
/// <param name="tempAttributeEntity">分公司参数实体类</param>
/// <returns>值1表示插入完成 值不等于1表示插入失败</returns>
public int InsertCompanyAttribute(AttributeCompanyEntity tempAttributeCompanyEntity)
{
int iResult = 0;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
SqlParameter[] parms = new SqlParameter[] {
new SqlParameter(PARM_ATTR_COMP_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_ATTR_COMP_COMPANYID,SqlDbType.VarChar,36),
new SqlParameter(PARM_ATTR_COMP_ATTRIBUTEID,SqlDbType.VarChar,36),
new SqlParameter(PARM_ATTR_COMP_VALUE,SqlDbType.VarChar,100),
new SqlParameter(PARM_ATTR_COMP_CREATE_USER,SqlDbType.VarChar,36),
};
parms[0].Value = tempAttributeCompanyEntity.GID;
parms[1].Value = tempAttributeCompanyEntity.CompanyID;
parms[2].Value = tempAttributeCompanyEntity.AttributeID;
parms[3].Value = tempAttributeCompanyEntity.AttributeValue;
parms[4].Value = tempAttributeCompanyEntity.CreateUser;
try
{
iResult = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, SQL_INSERT_ATTR_COMP, parms);
}
catch (Exception error)
{
iResult = -1;//插入异常
throw error;
}
}
return iResult;
}
#endregion
#region 更新分公司参数
/// <summary>
/// 更新分公司参数
/// </summary>
/// <param name="tempAttributeCompanyEntity">分公司参数实体类</param>
/// <returns>值1表示更新完成 值不等于1表示更新失败</returns>
public int UpdateCompanyAttribute(AttributeCompanyEntity tempAttributeCompanyEntity)
{
int iResult = 0;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
SqlParameter[] parms = new SqlParameter[] {
new SqlParameter(PARM_ATTR_COMP_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_ATTR_COMP_COMPANYID,SqlDbType.VarChar,36),
new SqlParameter(PARM_ATTR_COMP_ATTRIBUTEID,SqlDbType.VarChar,36),
new SqlParameter(PARM_ATTR_COMP_VALUE,SqlDbType.VarChar,100),
new SqlParameter(PARM_ATTR_COMP_MODIFIED_USER,SqlDbType.VarChar,36),
};
parms[0].Value = tempAttributeCompanyEntity.GID;
parms[1].Value = tempAttributeCompanyEntity.CompanyID;
parms[2].Value = tempAttributeCompanyEntity.AttributeID;
parms[3].Value = tempAttributeCompanyEntity.AttributeValue;
parms[4].Value = tempAttributeCompanyEntity.ModifiedUser;
try
{
iResult = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, SQL_UPDATE_ATTR_COMP, 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
}
}