using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Collections.Generic;
using DSWeb.Models;
using WebSqlHelper;
namespace DSWeb.EntityDA
{
public class ReportDBSourceDA
{
private const string PARM_REPORT_DB_SOURCE_GID = "@gid";
private const string PARM_REPORT_DB_SOURCE_REPORT_ID = "@report_id";
private const string PARM_REPORT_DB_SOURCE_NAME = "@name";
private const string PARM_REPORT_DB_SOURCE_DESCRIPTION = "@description";
private const string PARM_REPORT_DB_SOURCE_CREATE_USER = "@create_user";
private const string PARM_REPORT_DB_SOURCE_CREATE_TIME = "@create_time";
private const string PARM_REPORT_DB_SOURCE_MODIFIED_USER = "@modified_user";
private const string PARM_REPORT_DB_SOURCE_MODIFIED_TIME = "@modified_time";
private const string PARM_REPORT_DB_SOURCE_IS_DELETE = "@IS_DELETE";
private const string PARM_REPORT_DB_SOURCE_DELETE_TIME = "@delete_time";
private const string PARM_REPORT_DB_SOURCE_TYPE = "@type";
private const string PARM_REPORT_DB_SOURCE_USER_ID = "@user_id";
private const string PARM_REPORT_DB_SOURCE_SQLSTRING_1 = "@sqlstring_1";
private const string PARM_REPORT_DB_SOURCE_SQLSTRING_2 = "@sqlstring_2";
private const string PARM_REPORT_DB_SOURCE_SQLSTRING_3 = "@sqlstring_3";
private const string PARM_REPORT_DB_SOURCE_SQLSTRING_4 = "@sqlstring_4";
private const string PARM_REPORT_DB_SOURCE_SQLSTRING_5 = "@sqlstring_5";
private const string PARM_REPORT_DB_SOURCE_SQLSTRING_6 = "@sqlstring_6";
private const string PARM_REPORT_DB_SOURCE_SQLSTRING_7 = "@sqlstring_7";
private const string PARM_REPORT_DB_SOURCE_SQLSTRING_8 = "@sqlstring_8";
private const string SQL_SELECT_REPORT_DB_SOURCE_BY_USERID_AND_TYPE = " SELECT GID, REPORTID, NAME, DESCRIPTION, CREATEUSER, CREATETIME, MODIFIEDUSER, MODIFIEDTIME, ISDELETE, DELETETIME, TYPE, USERID,"
+ " SQLSTRING1, SQLSTRING2, SQLSTRING3, SQLSTRING4, SQLSTRING5, SQLSTRING6, SQLSTRING7, SQLSTRING8 "
+ " FROM sys_report_dbsource WHERE USERID = @user_id AND TYPE = @type ";
private const string SQL_INSERT_REPORT_DB_SOURCE = " INSERT INTO sys_report_dbsource (GID,CREATEUSER, CREATETIME,TYPE, USERID,SQLSTRING1, SQLSTRING2, SQLSTRING3, SQLSTRING4, SQLSTRING5, SQLSTRING6, SQLSTRING7, SQLSTRING8,DESCRIPTION,[NAME] )"
+ " VALUES(@gid,@create_user,GETDATE(),@type,@user_id,@sqlstring_1,@sqlstring_2,@sqlstring_3,@sqlstring_4,@sqlstring_5,@sqlstring_6,@sqlstring_7,@sqlstring_8,@description,@name) ";
private const string SQL_UPDATE_REPORT_DB_SOURCE_SQLSTRING = " UPDATE sys_report_dbsource SET SQLSTRING1 = @sqlstring_1,SQLSTRING2 = @sqlstring_2,SQLSTRING3 = @sqlstring_3, SQLSTRING4 = @sqlstring_4,SQLSTRING5 = @sqlstring_5,"
+ " SQLSTRING6 = @sqlstring_6,SQLSTRING7 = @sqlstring_7,SQLSTRING8 = @sqlstring_8,DESCRIPTION=@description,[name]=@name WHERE TYPE = @type AND USERID = @user_id ";
#region 根据用户GID和报表类型获取报表数据源(sys_report_dbsource)
///
/// 根据用户GID和报表类型获取报表数据源(sys_report_dbsource)
///
/// 用户GID
/// 报表类型
/// 返回ReportDBSourceEntity报表数据源实体类
public ReportDBSourceEntity GetReportDBSourceByUserIDAndType(string tempUserID,string tempType)
{
ReportDBSourceEntity reportDBSourceEntity = null;
SqlParameter[] parms = new SqlParameter[]{
new SqlParameter(PARM_REPORT_DB_SOURCE_USER_ID, SqlDbType.VarChar, 36),
new SqlParameter(PARM_REPORT_DB_SOURCE_TYPE,SqlDbType.VarChar,50)
};
parms[0].Value = tempUserID;
parms[1].Value = tempType;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_REPORT_DB_SOURCE_BY_USERID_AND_TYPE, parms))
{
try
{
reportDBSourceEntity = new ReportDBSourceEntity();
//读取字段值
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
reportDBSourceEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
reportDBSourceEntity.ReportID = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
reportDBSourceEntity.Name = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
reportDBSourceEntity.Description = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
reportDBSourceEntity.CreateUser = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
reportDBSourceEntity.CreateTime = sqlRead.GetDateTime(5);
}
if (!sqlRead.IsDBNull(6))
{
reportDBSourceEntity.ModifiedUser = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
reportDBSourceEntity.ModifiedTime = sqlRead.GetDateTime(7);
}
if (!sqlRead.IsDBNull(8))
{
reportDBSourceEntity.IsDelete = sqlRead.GetBoolean(8);
}
if (!sqlRead.IsDBNull(9))
{
reportDBSourceEntity.DeleteTime = sqlRead.GetDateTime(9);
}
if (!sqlRead.IsDBNull(10))
{
reportDBSourceEntity.Type = sqlRead.GetString(10);
}
if (!sqlRead.IsDBNull(11))
{
reportDBSourceEntity.UserID = sqlRead.GetString(11);
}
if (!sqlRead.IsDBNull(12))
{
reportDBSourceEntity.SqlString_1 = sqlRead.GetString(12);
}
if (!sqlRead.IsDBNull(13))
{
reportDBSourceEntity.SqlString_2 = sqlRead.GetString(13);
}
if (!sqlRead.IsDBNull(14))
{
reportDBSourceEntity.SqlString_3 = sqlRead.GetString(14);
}
if (!sqlRead.IsDBNull(15))
{
reportDBSourceEntity.SqlString_4 = sqlRead.GetString(15);
}
if (!sqlRead.IsDBNull(16))
{
reportDBSourceEntity.SqlString_5 = sqlRead.GetString(16);
}
if (!sqlRead.IsDBNull(17))
{
reportDBSourceEntity.SqlString_6 = sqlRead.GetString(17);
}
if (!sqlRead.IsDBNull(18))
{
reportDBSourceEntity.SqlString_7 = sqlRead.GetString(18);
}
if (!sqlRead.IsDBNull(19))
{
reportDBSourceEntity.SqlString_8 = sqlRead.GetString(19);
}
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return reportDBSourceEntity;
}
#endregion
#region 插入数据源信息
///
/// 插入数据源信息
///
/// 实体类数据源信息
/// 值1表示插入正常 值不等于表示插入失败
public int InsertReportDBSource(ReportDBSourceEntity tempReportDBSourceEntity)
{
int iResult = 0;
SqlParameter[] parms = new SqlParameter[] {
new SqlParameter(PARM_REPORT_DB_SOURCE_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_REPORT_DB_SOURCE_REPORT_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_REPORT_DB_SOURCE_NAME,SqlDbType.VarChar,50),
new SqlParameter(PARM_REPORT_DB_SOURCE_DESCRIPTION,SqlDbType.VarChar,50),
new SqlParameter(PARM_REPORT_DB_SOURCE_CREATE_USER,SqlDbType.VarChar,36),
new SqlParameter(PARM_REPORT_DB_SOURCE_TYPE,SqlDbType.VarChar,50),
new SqlParameter(PARM_REPORT_DB_SOURCE_USER_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_REPORT_DB_SOURCE_SQLSTRING_1,SqlDbType.VarChar,-1),
new SqlParameter(PARM_REPORT_DB_SOURCE_SQLSTRING_2,SqlDbType.VarChar,-1),
new SqlParameter(PARM_REPORT_DB_SOURCE_SQLSTRING_3,SqlDbType.VarChar,8000),
new SqlParameter(PARM_REPORT_DB_SOURCE_SQLSTRING_4,SqlDbType.VarChar,8000),
new SqlParameter(PARM_REPORT_DB_SOURCE_SQLSTRING_5,SqlDbType.VarChar,8000),
new SqlParameter(PARM_REPORT_DB_SOURCE_SQLSTRING_6,SqlDbType.VarChar,8000),
new SqlParameter(PARM_REPORT_DB_SOURCE_SQLSTRING_7,SqlDbType.VarChar,8000),
new SqlParameter(PARM_REPORT_DB_SOURCE_SQLSTRING_8,SqlDbType.VarChar,8000)
};
parms[0].Value = tempReportDBSourceEntity.GID;
parms[1].Value = tempReportDBSourceEntity.ReportID;
parms[2].Value = tempReportDBSourceEntity.Name;
parms[3].Value = tempReportDBSourceEntity.Description;
parms[4].Value = tempReportDBSourceEntity.CreateUser;
parms[5].Value = tempReportDBSourceEntity.Type;
parms[6].Value = tempReportDBSourceEntity.UserID;
parms[7].Value = tempReportDBSourceEntity.SqlString_1;
parms[8].Value = tempReportDBSourceEntity.SqlString_2;
parms[9].Value = tempReportDBSourceEntity.SqlString_3;
parms[10].Value = tempReportDBSourceEntity.SqlString_4;
parms[11].Value = tempReportDBSourceEntity.SqlString_5;
parms[12].Value = tempReportDBSourceEntity.SqlString_6;
parms[13].Value = tempReportDBSourceEntity.SqlString_7;
parms[14].Value = tempReportDBSourceEntity.SqlString_8;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, SQL_INSERT_REPORT_DB_SOURCE, parms);
if (existVal > 0)
{
iResult = 1;
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
#endregion
#region 更新系统报表SQL语句
///
/// 更新系统报表SQL语句
///
/// ReportDBSourceEntity实体类
/// 值1表示更新成功 值不等于1表示更新失败
public int UpdateReportSql(ReportDBSourceEntity tempReportDBSource)
{
int iResult = 0;
SqlParameter[] parms = new SqlParameter[] {
new SqlParameter(PARM_REPORT_DB_SOURCE_USER_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_REPORT_DB_SOURCE_TYPE,SqlDbType.VarChar,50),
new SqlParameter(PARM_REPORT_DB_SOURCE_SQLSTRING_1,SqlDbType.VarChar,-1),
new SqlParameter(PARM_REPORT_DB_SOURCE_SQLSTRING_2,SqlDbType.VarChar,-1),
new SqlParameter(PARM_REPORT_DB_SOURCE_SQLSTRING_3,SqlDbType.VarChar,-1),
new SqlParameter(PARM_REPORT_DB_SOURCE_SQLSTRING_4,SqlDbType.VarChar,-1),
new SqlParameter(PARM_REPORT_DB_SOURCE_SQLSTRING_5,SqlDbType.VarChar,-1),
new SqlParameter(PARM_REPORT_DB_SOURCE_SQLSTRING_6,SqlDbType.VarChar,-1),
new SqlParameter(PARM_REPORT_DB_SOURCE_SQLSTRING_7,SqlDbType.VarChar,-1),
new SqlParameter(PARM_REPORT_DB_SOURCE_SQLSTRING_8,SqlDbType.VarChar,-1),
new SqlParameter(PARM_REPORT_DB_SOURCE_DESCRIPTION,SqlDbType.VarChar,50),
new SqlParameter(PARM_REPORT_DB_SOURCE_NAME,SqlDbType.VarChar,50)
};
parms[0].Value = tempReportDBSource.UserID;
parms[1].Value = tempReportDBSource.Type;
parms[2].Value = tempReportDBSource.SqlString_1;
parms[3].Value = tempReportDBSource.SqlString_2;
parms[4].Value = tempReportDBSource.SqlString_3;
parms[5].Value = tempReportDBSource.SqlString_4;
parms[6].Value = tempReportDBSource.SqlString_5;
parms[7].Value = tempReportDBSource.SqlString_6;
parms[8].Value = tempReportDBSource.SqlString_7;
parms[9].Value = tempReportDBSource.SqlString_8;
parms[10].Value = tempReportDBSource.Description;
parms[11].Value = tempReportDBSource.Name;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, SQL_UPDATE_REPORT_DB_SOURCE_SQLSTRING, parms);
if (existVal > 0)
{
iResult = 1;
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
#endregion
}
}