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.

397 lines
16 KiB
C#

12 months ago
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Collections.Generic;
using DSWeb.Models;
using System.Text;
using DSWeb.DataAccess;
namespace DSWeb.EntityDA
{
public class CurrencyDA
{
private const string PARM_CURRENCY_GID = "@gid";
private const string PARM_CURRENCY_CODENAME = "@codename";
private const string PARM_CURRENCY_NAME = "@name";
private const string PARM_CURRENCY_DESCRIPTION = "@description";
private const string PARM_CURRENCY_DEFAULTRATE = "@default_rate";
private const string PARM_CURRENCY_CREATEUSER = "@create_user";
private const string PARM_CURRENCY_CREATETIME = "@create_time";
private const string PARM_CURRENCY_MODIFIEDUSER = "@modified_user";
private const string PARM_CURRENCY_MODIFIEDTIME = "@modified_time";
private const string SQL_SELECT_CURRENCY_ALL = " SELECT GID, CODENAME, NAME, DESCRIPTION, DEFAULTRATE, CREATEUSER, CREATETIME, MODIFIEDUSER, MODIFIEDTIME,FINANCESOFTCODE FROM code_currency ";
private const string SQL_SELECT_CURRENCY_BY_ID = " SELECT GID, CODENAME, NAME, DESCRIPTION, DEFAULTRATE, CREATEUSER, CREATETIME, MODIFIEDUSER, MODIFIEDTIME,FINANCESOFTCODE FROM code_currency WHERE GID = @gid ";
private const string SQL_SELECT_CURRENCY_BY_CODENAME = " SELECT GID, CODENAME, NAME, DESCRIPTION, DEFAULTRATE, CREATEUSER, CREATETIME, MODIFIEDUSER, MODIFIEDTIME,FINANCESOFTCODE FROM code_currency WHERE CODENAME = @codename ";
private const string SQL_SELECT_CURRENCY_LIST = "SELECT CODENAME,DESCRIPTION FROM code_currency";
private const string SQL_DELETE_CURRENCY_BY_GID = "DELETE FROM code_currency WHERE GID = @GID";
#region 根据CODENAME获取币别信息
/// <summary>
/// 通过币别GID获取币别信息
/// </summary>
/// <param name="strGID"></param>
/// <returns></returns>
public CurrencyEntity GetCurrencyByCodeName(string strCurCodeName)
{
CurrencyEntity currencyEntity = null;
SqlParameter parm = new SqlParameter(PARM_CURRENCY_CODENAME, SqlDbType.VarChar, 36);
parm.Value = strCurCodeName;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_CURRENCY_BY_CODENAME, parm))
{
try
{
currencyEntity = new CurrencyEntity();
//读取字段值
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
currencyEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
currencyEntity.CodeName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
currencyEntity.Name = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
currencyEntity.Description = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
currencyEntity.DefaultRate = sqlRead.GetDecimal(4);
}
if (!sqlRead.IsDBNull(5))
{
currencyEntity.CreateUserID = sqlRead.GetString(5);
}
if (!sqlRead.IsDBNull(6))
{
currencyEntity.CreateTime = sqlRead.GetDateTime(6);
}
if (!sqlRead.IsDBNull(7))
{
currencyEntity.ModifiedUserID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
currencyEntity.ModifiedTime = sqlRead.GetDateTime(8);
}
if (!sqlRead.IsDBNull(9))
{
currencyEntity.FINANCESOFTCODE = sqlRead.GetString(9);
}
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return currencyEntity;
}
#endregion
#region 通过币别GID获取币别信息
/// <summary>
/// 通过币别GID获取币别信息
/// </summary>
/// <param name="strGID"></param>
/// <returns></returns>
public CurrencyEntity GetCurrencyByID(string strGID)
{
CurrencyEntity currencyEntity = null;
SqlParameter parm = new SqlParameter(PARM_CURRENCY_GID, SqlDbType.VarChar, 36);
parm.Value = strGID;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_CURRENCY_BY_ID, parm))
{
try
{
currencyEntity = new CurrencyEntity();
//读取字段值
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
currencyEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
currencyEntity.CodeName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
currencyEntity.Name = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
currencyEntity.Description = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
currencyEntity.DefaultRate = sqlRead.GetDecimal(4);
}
if (!sqlRead.IsDBNull(5))
{
currencyEntity.CreateUserID = sqlRead.GetString(5);
}
if (!sqlRead.IsDBNull(6))
{
currencyEntity.CreateTime = sqlRead.GetDateTime(6);
}
if (!sqlRead.IsDBNull(7))
{
currencyEntity.ModifiedUserID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
currencyEntity.ModifiedTime = sqlRead.GetDateTime(8);
}
if (!sqlRead.IsDBNull(9))
{
currencyEntity.FINANCESOFTCODE = sqlRead.GetString(9);
}
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return currencyEntity;
}
#endregion
#region 获取所有币别实体类信息
/// <summary>
/// 获取所有币别实体类信息
/// </summary>
/// <returns></returns>
public IList<CurrencyEntity> GetAllCurrency()
{
IList<CurrencyEntity> currencyEntities = new List<CurrencyEntity>();
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_CURRENCY_ALL, null))
{
try
{
//读取字段值
while (sqlRead.Read())
{
CurrencyEntity currencyEntity = new CurrencyEntity();
if (!sqlRead.IsDBNull(0))
{
currencyEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
currencyEntity.CodeName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
currencyEntity.Name = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
currencyEntity.Description = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
currencyEntity.DefaultRate = sqlRead.GetDecimal(4);
}
if (!sqlRead.IsDBNull(5))
{
currencyEntity.CreateUserID = sqlRead.GetString(5);
}
if (!sqlRead.IsDBNull(6))
{
currencyEntity.CreateTime = sqlRead.GetDateTime(6);
}
if (!sqlRead.IsDBNull(7))
{
currencyEntity.ModifiedUserID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
currencyEntity.ModifiedTime = sqlRead.GetDateTime(8);
}
if (!sqlRead.IsDBNull(9))
{
currencyEntity.FINANCESOFTCODE = sqlRead.GetString(9);
}
currencyEntities.Add(currencyEntity);
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return currencyEntities;
}
#endregion
#region 返回所有币别信息数据集用于绑定select
/// <summary>
/// 返回所有币别信息数据集用于绑定select
/// </summary>
/// <param name="strSql"></param>
/// <returns>取币别表code_currency 字段CODENAME,DESCRIPTION</returns>
public DataSet GetCurrencyList()
{
DataSet userSet = new DataSet();
userSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_CURRENCY_LIST);
return userSet;
}
#endregion
public DataSet GetExcuteSql(string strSql)
{
DataSet dataSet = new DataSet();
dataSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql);
return dataSet;
}
#region 更新账户列表信息
/// <summary>
/// 更新账户列表信息
/// </summary>
/// <param name="sqlList">更新SQL语句组,将所有要执行的更新语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作</param>
/// <returns>返回状态值 为1表示更新完成;为-1更新出现异常但未正确回滚事务;为-2更新异常,事务已经成功回滚;默认状态为0</returns>
public int UpdateCodeCurrencySetFromGrid(ArrayList sqlList)
{
int result = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
for (int i = 0; i < sqlList.Count; i++)
{
string strUpdateSql = sqlList[i].ToString();
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strUpdateSql, null);
}
sqlTran.Commit();
result = 1;//状态为1表示更新成功
}
catch (Exception execError)
{
result = -1;//有异常,更新失败
sqlTran.Rollback();
result = -2;//更新异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return result;
}
#endregion
#region 通过账户GID删除单条账户
public int DeleteCodeCtnSetByGid(string tempGid)
{
int result = 0;
SqlParameter parm = new SqlParameter("GID", SqlDbType.VarChar, 36);
parm.Value = tempGid;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_DELETE_CURRENCY_BY_GID, parm);
result = 1;//状态为1表示删除成功
sqlTran.Commit();
}
catch (Exception execError)
{
result = -1;//有异常,插入失败
sqlTran.Rollback();
result = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return result;
}
#endregion
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(CurrencyEntity model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into code_currency(");
strSql.Append("GID,FINANCESOFTCODE,CODENAME,NAME,DESCRIPTION,DEFAULTRATE,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME");
strSql.Append(") values (");
strSql.Append("@GID,@FINANCESOFTCODE,@CODENAME,@NAME,@DESCRIPTION,@DEFAULTRATE,@CREATEUSER,getdate(),@MODIFIEDUSER,getdate()");
strSql.Append(") ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
new SqlParameter("@FINANCESOFTCODE", SqlDbType.VarChar,20) ,
new SqlParameter("@CODENAME", SqlDbType.VarChar,3) ,
new SqlParameter("@NAME", SqlDbType.VarChar,20) ,
new SqlParameter("@DESCRIPTION", SqlDbType.VarChar,20) ,
new SqlParameter("@DEFAULTRATE", SqlDbType.Decimal,9) ,
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36)
};
parameters[0].Value = model.GID;
parameters[1].Value = model.FINANCESOFTCODE;
parameters[2].Value = model.CodeName;
parameters[3].Value = model.Name;
parameters[4].Value = model.Description;
parameters[5].Value = model.DefaultRate;
parameters[6].Value = model.CreateUserID;
parameters[7].Value = model.ModifiedUserID;
//
int iResult = 0;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters);
if (existVal > 0)
{
iResult = 1;
//
//string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('增加信息','增加操作','GID=" + model.GID.ToString() + "','" + model.MODIFIEDUSER.ToString() + "')";
//bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0);
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
//
}
}