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 ExchangeRateDA { private const string PARM_EXCHANGERATE_GID = "@gid"; private const string PARM_EXCHANGERATE_CURRENCYID = "@currency_id"; private const string PARM_EXCHANGERATE_VALUE = "@value"; private const string PARM_EXCHANGERATE_TYPE = "@type"; private const string PARM_EXCHANGERATE_STARTTIME = "@start_time"; private const string PARM_EXCHANGERATE_ENDTIME = "@end_time"; private const string PARM_EXCHANGERATE_CREATEUSER = "@create_user"; private const string PARM_EXCHANGERATE_CREATETIME = "@create_time"; private const string PARM_EXCHANGERATE_MODIFIEDUSER = "@modified_user"; private const string PARM_EXCHANGERATE_MODIFIEDTIME = "@modified_time"; private const string PARM_EXCHANGERATE_COMPANY_ID = "@company_id"; private const string PARM_EXCHANGERATE_IS_DELETE = "@is_delete"; private const string PARM_EXCHANGERATE_DELETE_USER = "@delete_user"; private const string PARM_EXCHANGERATE_DELETE_TIME = "@delete_time"; private const string SQL_SELECT_EXCHANGERATE_ALL = " SELECT GID, CURRENCYID, VALUE, TYPE, STARTTIME, ENDTIME, CREATEUSER, CREATETIME, MODIFIEDUSER, MODIFIEDTIME,COMPANYID,ISDELETE,DELETEUSER,DELETETIME " + " FROM currency_exchange WHERE ISNULL(ISDELETE,0) <> 1 "; private const string SQL_SELECT_EXCHANGERATE_BY_GID = " SELECT GID, CURRENCYID, VALUE, TYPE, STARTTIME, ENDTIME, CREATEUSER, CREATETIME, MODIFIEDUSER, MODIFIEDTIME,COMPANYID,ISDELETE,DELETEUSER,DELETETIME " + " FROM currency_exchange WHERE GID = @gid AND ISNULL(ISDELETE,0) <> 1 "; private const string SQL_SELECT_EXCHANGERATE_BY_CURRENCYID = " SELECT GID, CURRENCYID, VALUE, TYPE, STARTTIME, ENDTIME, CREATEUSER, CREATETIME, MODIFIEDUSER, MODIFIEDTIME,COMPANYID,ISDELETE,DELETEUSER,DELETETIME " + " FROM currency_exchange WHERE CURRENCYID = @currency_id AND ISNULL(ISDELETE,0) <> 1 AND COMPANYID = @company_id "; private const string SQL_INSERT_EXCHANGERATE = " INSERT INTO currency_exchange(GID,CURRENCYID,VALUE,TYPE,STARTTIME,ENDTIME,CREATEUSER,CREATETIME,COMPANYID)" + " VALUES(@gid,@currency_id,@value,@type,@start_time,@end_time,@create_user,GETDATE(),@company_id) "; private const string SQL_INSERT_EXCHANGERATE_NO_TIME = " INSERT INTO currency_exchange(GID,CURRENCYID,VALUE,TYPE,CREATEUSER,CREATETIME,COMPANYID)" + " VALUES(@gid,@currency_id,@value,@type,@create_user,GETDATE(),@company_id) "; private const string SQL_UPDATE_EXCHANGERATE = " UPDATE currency_exchange SET CURRENCYID = @currency_id,VALUE = @value,TYPE = @type,STARTTIME = @start_time,ENDTIME = @end_time," + " MODIFIEDUSER = @modified_user,MODIFIEDTIME = GETDATE() WHERE GID = @gid "; private const string SQL_UPDATE_EXCHANGERATE_NO_TIME = " UPDATE currency_exchange SET CURRENCYID = @currency_id,VALUE = @value,TYPE = @type," + " MODIFIEDUSER = @modified_user,MODIFIEDTIME = GETDATE() WHERE GID = @gid "; private const string SQL_DELETE_EXCHANGERATE = " UPDATE currency_exchange SET ISDELETE = 1,DELETEUSER = @delete_user,DELETETIME = GETDATE() WHERE GID = @gid "; #region 插入汇率信息 /// /// 插入汇率信息 /// /// 汇率实体类 /// 值1表示插入成功 值不等于1表示插入失败 public int InsertExchangeRate(ExchangeRateEntity exchangeRateEntity) { int iResult = 0; using (SqlConnection sqlConnection = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) { try { if (exchangeRateEntity.StartTime != DateTime.MinValue) { SqlParameter[] parms = new SqlParameter[]{ new SqlParameter(PARM_EXCHANGERATE_GID, SqlDbType.VarChar, 36), new SqlParameter(PARM_EXCHANGERATE_CURRENCYID, SqlDbType.VarChar, 36), new SqlParameter(PARM_EXCHANGERATE_VALUE,SqlDbType.Decimal,20), new SqlParameter(PARM_EXCHANGERATE_TYPE,SqlDbType.VarChar,20), new SqlParameter(PARM_EXCHANGERATE_STARTTIME,SqlDbType.DateTime), new SqlParameter(PARM_EXCHANGERATE_ENDTIME,SqlDbType.DateTime), new SqlParameter(PARM_EXCHANGERATE_COMPANY_ID,SqlDbType.VarChar,36), new SqlParameter(PARM_EXCHANGERATE_CREATEUSER,SqlDbType.VarChar,36) }; parms[0].Value = exchangeRateEntity.GID; parms[1].Value = exchangeRateEntity.CurrencyID; parms[2].Value = exchangeRateEntity.Value; parms[3].Value = exchangeRateEntity.Type; parms[4].Value = exchangeRateEntity.StartTime; parms[5].Value = exchangeRateEntity.EndTime; parms[6].Value = exchangeRateEntity.CompanyID; parms[7].Value = exchangeRateEntity.CreateUserID; iResult = SqlHelper.ExecuteNonQuery(sqlConnection, CommandType.Text, SQL_INSERT_EXCHANGERATE, parms); } else { SqlParameter[] parms = new SqlParameter[]{ new SqlParameter(PARM_EXCHANGERATE_GID, SqlDbType.VarChar, 36), new SqlParameter(PARM_EXCHANGERATE_CURRENCYID, SqlDbType.VarChar, 36), new SqlParameter(PARM_EXCHANGERATE_VALUE,SqlDbType.Decimal,20), new SqlParameter(PARM_EXCHANGERATE_TYPE,SqlDbType.VarChar,20), new SqlParameter(PARM_EXCHANGERATE_COMPANY_ID,SqlDbType.VarChar,36), new SqlParameter(PARM_EXCHANGERATE_CREATEUSER,SqlDbType.VarChar,36) }; parms[0].Value = exchangeRateEntity.GID; parms[1].Value = exchangeRateEntity.CurrencyID; parms[2].Value = exchangeRateEntity.Value; parms[3].Value = exchangeRateEntity.Type; parms[4].Value = exchangeRateEntity.CompanyID; parms[5].Value = exchangeRateEntity.CreateUserID; iResult = SqlHelper.ExecuteNonQuery(sqlConnection, CommandType.Text, SQL_INSERT_EXCHANGERATE_NO_TIME, parms); } } catch { iResult = -1;//执行异常失败 } } return iResult; } #endregion #region 更新汇率信息 /// /// 更新汇率信息 /// /// 汇率实体类 /// 值1表示更新成功 值不等于1表示更新失败 public int UpdateExchangeRate(ExchangeRateEntity exchangeRateEntity) { int iResult = 0; using (SqlConnection sqlConnection = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) { try { if (exchangeRateEntity.StartTime != DateTime.MinValue) { SqlParameter[] parms = new SqlParameter[]{ new SqlParameter(PARM_EXCHANGERATE_GID, SqlDbType.VarChar, 36), new SqlParameter(PARM_EXCHANGERATE_CURRENCYID, SqlDbType.VarChar, 36), new SqlParameter(PARM_EXCHANGERATE_VALUE,SqlDbType.Decimal,20), new SqlParameter(PARM_EXCHANGERATE_TYPE,SqlDbType.VarChar,20), new SqlParameter(PARM_EXCHANGERATE_STARTTIME,SqlDbType.DateTime), new SqlParameter(PARM_EXCHANGERATE_ENDTIME,SqlDbType.DateTime), new SqlParameter(PARM_EXCHANGERATE_COMPANY_ID,SqlDbType.VarChar,36), new SqlParameter(PARM_EXCHANGERATE_MODIFIEDUSER,SqlDbType.VarChar,36) }; parms[0].Value = exchangeRateEntity.GID; parms[1].Value = exchangeRateEntity.CurrencyID; parms[2].Value = exchangeRateEntity.Value; parms[3].Value = exchangeRateEntity.Type; parms[4].Value = exchangeRateEntity.StartTime; parms[5].Value = exchangeRateEntity.EndTime; parms[6].Value = exchangeRateEntity.CompanyID; parms[7].Value = exchangeRateEntity.ModifiedUserID; iResult = SqlHelper.ExecuteNonQuery(sqlConnection, CommandType.Text, SQL_UPDATE_EXCHANGERATE, parms); } else { SqlParameter[] parms = new SqlParameter[]{ new SqlParameter(PARM_EXCHANGERATE_GID, SqlDbType.VarChar, 36), new SqlParameter(PARM_EXCHANGERATE_CURRENCYID, SqlDbType.VarChar, 36), new SqlParameter(PARM_EXCHANGERATE_VALUE,SqlDbType.Decimal,20), new SqlParameter(PARM_EXCHANGERATE_TYPE,SqlDbType.VarChar,20), new SqlParameter(PARM_EXCHANGERATE_COMPANY_ID,SqlDbType.VarChar,36), new SqlParameter(PARM_EXCHANGERATE_MODIFIEDUSER,SqlDbType.VarChar,36) }; parms[0].Value = exchangeRateEntity.GID; parms[1].Value = exchangeRateEntity.CurrencyID; parms[2].Value = exchangeRateEntity.Value; parms[3].Value = exchangeRateEntity.Type; parms[4].Value = exchangeRateEntity.CompanyID; parms[5].Value = exchangeRateEntity.ModifiedUserID; iResult = SqlHelper.ExecuteNonQuery(sqlConnection, CommandType.Text, SQL_UPDATE_EXCHANGERATE_NO_TIME, parms); } } catch { iResult = -1;//执行异常失败 } } return iResult; } #endregion #region 删除汇率信息(汇率删除不做实际删除操作,只是将ISDELETE字段置1) /// /// 删除汇率信息(汇率删除不做实际删除操作,只是将ISDELETE字段置1) /// /// 汇率GID /// 操作人GID /// 值表示删除成功 值不等于1表示删除失败 public int DeleteExchangeRate(string tempExchangeRateID,string tempOperatorID) { int iResult = 0; using (SqlConnection sqlConnection = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) { try { SqlParameter[] parms = new SqlParameter[]{ new SqlParameter(PARM_EXCHANGERATE_GID, SqlDbType.VarChar, 36), new SqlParameter(PARM_EXCHANGERATE_DELETE_USER, SqlDbType.VarChar, 36), }; parms[0].Value = tempExchangeRateID; parms[1].Value = tempOperatorID; iResult = SqlHelper.ExecuteNonQuery(sqlConnection, CommandType.Text, SQL_DELETE_EXCHANGERATE, parms); } catch { iResult = -1;//执行异常失败 } } return iResult; } #endregion #region 通过字段值CURRENCYID获取汇率信息 /// /// 通过字段值CURRENCYID获取相关所有汇率信息 /// /// /// public IList GetExchangeRateByCurrencyID(string strCurrencyID,string strCompanyID) { IList exchangeRateEntities = new List(); //GID参数 SqlParameter[] parms = new SqlParameter[] { new SqlParameter(PARM_EXCHANGERATE_CURRENCYID, SqlDbType.VarChar, 36), new SqlParameter(PARM_EXCHANGERATE_COMPANY_ID,SqlDbType.VarChar,36) }; parms[0].Value = strCurrencyID; parms[1].Value = strCompanyID; //执行查询 using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_EXCHANGERATE_BY_CURRENCYID, parms)) { try { //读取字段值 while (sqlRead.Read()) { ExchangeRateEntity exchangeRateEntity = new ExchangeRateEntity(); if (!sqlRead.IsDBNull(0)) { exchangeRateEntity.GID = sqlRead.GetString(0); } if (!sqlRead.IsDBNull(1)) { exchangeRateEntity.CurrencyID = sqlRead.GetString(1); } if (!sqlRead.IsDBNull(2)) { exchangeRateEntity.Value = sqlRead.GetDecimal(2); } if (!sqlRead.IsDBNull(3)) { exchangeRateEntity.Type = sqlRead.GetString(3); } if (!sqlRead.IsDBNull(4)) { exchangeRateEntity.StartTime = sqlRead.GetDateTime(4); } if (!sqlRead.IsDBNull(5)) { exchangeRateEntity.EndTime = sqlRead.GetDateTime(5); } if (!sqlRead.IsDBNull(6)) { exchangeRateEntity.CreateUserID = sqlRead.GetString(6); } if (!sqlRead.IsDBNull(7)) { exchangeRateEntity.CreateTime = sqlRead.GetDateTime(7); } if (!sqlRead.IsDBNull(8)) { exchangeRateEntity.ModifiedUserID = sqlRead.GetString(8); } if (!sqlRead.IsDBNull(9)) { exchangeRateEntity.ModifiedTime = sqlRead.GetDateTime(9); } if (!sqlRead.IsDBNull(10)) { exchangeRateEntity.CompanyID = sqlRead.GetString(10); } if (!sqlRead.IsDBNull(11)) { exchangeRateEntity.IsDelete = sqlRead.GetBoolean(11); } if (!sqlRead.IsDBNull(12)) { exchangeRateEntity.DeleteUser = sqlRead.GetString(12); } if (!sqlRead.IsDBNull(13)) { exchangeRateEntity.DeleteTime = sqlRead.GetDateTime(13); } //添加到实体组中 if (exchangeRateEntity.GID != null) { exchangeRateEntities.Add(exchangeRateEntity); } } } catch (Exception exceError) { //抛出异常 throw exceError; } } return exchangeRateEntities; } #endregion #region 通过汇率GID获取汇率信息 /// /// 通过汇率GID获取汇率信息 /// /// /// public ExchangeRateEntity GetExchangeRateByID(string strGID) { //初始化汇率实体类 ExchangeRateEntity exchangeRateEntity = null; //GID参数 SqlParameter parm = new SqlParameter(PARM_EXCHANGERATE_GID, SqlDbType.VarChar, 36); parm.Value = strGID; //执行查询 using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_EXCHANGERATE_BY_GID, parm)) { try { exchangeRateEntity = new ExchangeRateEntity(); //读取字段值 while (sqlRead.Read()) { if (!sqlRead.IsDBNull(0)) { exchangeRateEntity.GID = sqlRead.GetString(0); } if (!sqlRead.IsDBNull(1)) { exchangeRateEntity.CurrencyID = sqlRead.GetString(1); } if (!sqlRead.IsDBNull(2)) { exchangeRateEntity.Value = sqlRead.GetDecimal(2); } if (!sqlRead.IsDBNull(3)) { exchangeRateEntity.Type = sqlRead.GetString(3); } if (!sqlRead.IsDBNull(4)) { exchangeRateEntity.StartTime = sqlRead.GetDateTime(4); } if (!sqlRead.IsDBNull(5)) { exchangeRateEntity.EndTime = sqlRead.GetDateTime(5); } if (!sqlRead.IsDBNull(6)) { exchangeRateEntity.CreateUserID = sqlRead.GetString(6); } if (!sqlRead.IsDBNull(7)) { exchangeRateEntity.CreateTime = sqlRead.GetDateTime(7); } if (!sqlRead.IsDBNull(8)) { exchangeRateEntity.ModifiedUserID = sqlRead.GetString(8); } if (!sqlRead.IsDBNull(9)) { exchangeRateEntity.ModifiedTime = sqlRead.GetDateTime(9); } if (!sqlRead.IsDBNull(10)) { exchangeRateEntity.CompanyID = sqlRead.GetString(10); } if (!sqlRead.IsDBNull(11)) { exchangeRateEntity.IsDelete = sqlRead.GetBoolean(11); } if (!sqlRead.IsDBNull(12)) { exchangeRateEntity.DeleteUser = sqlRead.GetString(12); } if (!sqlRead.IsDBNull(13)) { exchangeRateEntity.DeleteTime = sqlRead.GetDateTime(13); } } } catch (Exception exceError) { //抛出异常 throw exceError; } } return exchangeRateEntity; } #endregion #region 获取所有汇率实体类信息 /// /// 获取所有汇率实体类信息 /// /// public IList GetAllExchangeRate() { //实体类组 IList exchangeRateEntities = new List(); using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_EXCHANGERATE_ALL, null)) { try { //读取字段值 while (sqlRead.Read()) { ExchangeRateEntity exchangeRateEntity = new ExchangeRateEntity(); if (!sqlRead.IsDBNull(0)) { exchangeRateEntity.GID = sqlRead.GetString(0); } if (!sqlRead.IsDBNull(1)) { exchangeRateEntity.CurrencyID = sqlRead.GetString(1); } if (!sqlRead.IsDBNull(2)) { exchangeRateEntity.Value = sqlRead.GetDecimal(2); } if (!sqlRead.IsDBNull(3)) { exchangeRateEntity.Type = sqlRead.GetString(3); } if (!sqlRead.IsDBNull(4)) { exchangeRateEntity.StartTime = sqlRead.GetDateTime(4); } if (!sqlRead.IsDBNull(5)) { exchangeRateEntity.EndTime = sqlRead.GetDateTime(5); } if (!sqlRead.IsDBNull(6)) { exchangeRateEntity.CreateUserID = sqlRead.GetString(6); } if (!sqlRead.IsDBNull(7)) { exchangeRateEntity.CreateTime = sqlRead.GetDateTime(7); } if (!sqlRead.IsDBNull(8)) { exchangeRateEntity.ModifiedUserID = sqlRead.GetString(8); } if (!sqlRead.IsDBNull(9)) { exchangeRateEntity.ModifiedTime = sqlRead.GetDateTime(9); } if (!sqlRead.IsDBNull(10)) { exchangeRateEntity.CompanyID = sqlRead.GetString(10); } if (!sqlRead.IsDBNull(11)) { exchangeRateEntity.IsDelete = sqlRead.GetBoolean(11); } if (!sqlRead.IsDBNull(12)) { exchangeRateEntity.DeleteUser = sqlRead.GetString(12); } if (!sqlRead.IsDBNull(13)) { exchangeRateEntity.DeleteTime = sqlRead.GetDateTime(13); } exchangeRateEntities.Add(exchangeRateEntity); } } catch (Exception exceError) { //抛出异常 throw exceError; } } return exchangeRateEntities; } #endregion #region 获取SQL语句查询数据集 /// /// 获取SQL语句查询数据集 /// /// /// public DataSet GetExcuteSql(string strSql) { DataSet tempSet = new DataSet(); tempSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql); return tempSet; } #endregion } }