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.
DS7/DSWeb/EntityDA/AccountDA.cs

659 lines
28 KiB
C#

3 years ago
using System;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using DSWeb.Models;
using DSWeb.DataAccess;
namespace DSWeb.EntityDA
{
public class AccountDA
{
private const string PARM_Account_GID = "@gid";
private const string SQL_SELECT_Account_ALL = " SELECT GID,LINKID,CODENAME,CURRENCY,BANKNAME,ACCOUNT,SubjectCode,REMARK,FINANCESOFTCODE,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME FROM sys_bank order by CODENAME";
private const string SQL_SELECT_Account_BYGID = " SELECT GID,LINKID,CODENAME,CURRENCY,BANKNAME,ACCOUNT,SubjectCode,REMARK,FINANCESOFTCODE,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME FROM sys_bank WHERE GID = @gid";
private const string SQL_SELECT_Account_TOP1 = " SELECT top 1 GID,LINKID,CODENAME,CURRENCY,BANKNAME,ACCOUNT,SubjectCode,REMARK,FINANCESOFTCODE,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME FROM sys_bank order by CODENAME";
private string strSqlInsertInfo = "insert into [sys_bank](GID,LINKID,CODENAME,CURRENCY,BANKNAME,ACCOUNT,SubjectCode,REMARK,CREATEUSER,MODIFIEDUSER,FINANCESOFTCODE) values(@GID,@LINKID,@CODENAME,@CURRENCY,@BANKNAME,@ACCOUNT,@SubjectCode,@REMARK,@CREATEUSER,@MODIFIEDUSER,@FINANCESOFTCODE)";
private string strSqlUpdateInfo = "update [sys_bank] set LINKID=@LINKID,CODENAME=@CODENAME,CURRENCY=@CURRENCY,BANKNAME=@BANKNAME,ACCOUNT=@ACCOUNT,SubjectCode=@SubjectCode,REMARK=@REMARK,MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=GETDATE(),FINANCESOFTCODE=@FINANCESOFTCODE where GID=@GID";
private const string SQL_DELETE_Account_BY_GID = "DELETE FROM sys_bank WHERE GID = @gid";
#region 获取所有公司信息
/// <summary>
/// 获取所有公司信息
/// </summary>
/// <returns>List<AccountEntity></returns>
public IList<AccountEntity> GetAllAccount()
{
IList<AccountEntity> AccountEntites = new List<AccountEntity>();
AccountEntity AccountEntity = null;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_Account_ALL, null))
{
try
{
while (sqlRead.Read())
{
AccountEntity = new AccountEntity();
if (!sqlRead.IsDBNull(0))
{
AccountEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
AccountEntity.LINKID = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
AccountEntity.CODENAME = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
AccountEntity.CURRENCY = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
AccountEntity.BANKNAME = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
AccountEntity.ACCOUNT = sqlRead.GetString(5);
}
if (!sqlRead.IsDBNull(6))
{
AccountEntity.SubjectCode = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
AccountEntity.REMARK = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
AccountEntity.FINANCESOFTCODE = sqlRead.GetString(8);
}
if (!sqlRead.IsDBNull(9))
{
AccountEntity.CREATEUSER = sqlRead.GetString(9);
}
if (!sqlRead.IsDBNull(10))
{
AccountEntity.CREATETIME = sqlRead.GetDateTime(10);
}
if (!sqlRead.IsDBNull(11))
{
AccountEntity.MODIFIEDUSER = sqlRead.GetString(11);
}
if (!sqlRead.IsDBNull(12))
{
AccountEntity.MODIFIEDTIME = sqlRead.GetDateTime(12);
}
AccountEntites.Add(AccountEntity);
}
}
catch (Exception execError)
{
throw execError;
}
}
return AccountEntites;
}
#endregion
#region 根据公司GID获取公司信息
/// <summary>
/// 根据公司GID获取公司信息
/// </summary>
/// <param name="strGid"></param>
/// <returns></returns>
public AccountEntity GetAccountByID(string strGid)
{
AccountEntity AccountEntity = null;
SqlParameter parm = new SqlParameter(PARM_Account_GID, SqlDbType.VarChar, 36);
parm.Value = strGid;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_Account_BYGID, parm))
{
try
{
while (sqlRead.Read())
{
AccountEntity = new AccountEntity();
if (!sqlRead.IsDBNull(0))
{
AccountEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
AccountEntity.LINKID = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
AccountEntity.CODENAME = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
AccountEntity.CURRENCY = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
AccountEntity.BANKNAME = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
AccountEntity.ACCOUNT = sqlRead.GetString(5);
}
if (!sqlRead.IsDBNull(6))
{
AccountEntity.SubjectCode = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
AccountEntity.REMARK = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
AccountEntity.FINANCESOFTCODE = sqlRead.GetString(8);
}
if (!sqlRead.IsDBNull(9))
{
AccountEntity.CREATEUSER = sqlRead.GetString(9);
}
if (!sqlRead.IsDBNull(10))
{
AccountEntity.CREATETIME = sqlRead.GetDateTime(10);
}
if (!sqlRead.IsDBNull(11))
{
AccountEntity.MODIFIEDUSER = sqlRead.GetString(11);
}
if (!sqlRead.IsDBNull(12))
{
AccountEntity.MODIFIEDTIME = sqlRead.GetDateTime(12);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return AccountEntity;
}
#endregion
#region 根据公司GID获取公司信息
/// <summary>
/// 根据公司GID获取公司信息
/// </summary>
/// <param name="strGid"></param>
/// <returns></returns>
public AccountEntity GetAccountTop1()
{
AccountEntity AccountEntity = null;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_Account_TOP1, null))
{
try
{
while (sqlRead.Read())
{
AccountEntity = new AccountEntity();
if (!sqlRead.IsDBNull(0))
{
AccountEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
AccountEntity.LINKID = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
AccountEntity.CODENAME = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
AccountEntity.CURRENCY = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
AccountEntity.BANKNAME = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
AccountEntity.ACCOUNT = sqlRead.GetString(5);
}
if (!sqlRead.IsDBNull(6))
{
AccountEntity.SubjectCode = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
AccountEntity.REMARK = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
AccountEntity.FINANCESOFTCODE = sqlRead.GetString(8);
}
if (!sqlRead.IsDBNull(9))
{
AccountEntity.CREATEUSER = sqlRead.GetString(9);
}
if (!sqlRead.IsDBNull(10))
{
AccountEntity.CREATETIME = sqlRead.GetDateTime(10);
}
if (!sqlRead.IsDBNull(11))
{
AccountEntity.MODIFIEDUSER = sqlRead.GetString(11);
}
if (!sqlRead.IsDBNull(12))
{
AccountEntity.MODIFIEDTIME = sqlRead.GetDateTime(12);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return AccountEntity;
}
#endregion
/// <summary>
/// 插入信息
/// </summary>
/// <param name="AccountEntity">实体类</param>
/// <returns>值为1插入数据正常,-1操作异常</returns>
public int InserInfo(AccountEntity infoEntity)
{
int iResult = 0;
//获取参数
SqlParameter[] parms = GetInsertParms();
parms[0].Value = infoEntity.GID;//惟一编号
parms[1].Value = infoEntity.LINKID;//公司关联id
parms[2].Value = infoEntity.CODENAME;//代码
parms[3].Value = infoEntity.CURRENCY;//币别
parms[4].Value = infoEntity.BANKNAME;//银行名称
parms[5].Value = infoEntity.ACCOUNT;//银行账户
parms[6].Value = infoEntity.SubjectCode;//科目代码
parms[7].Value = infoEntity.REMARK;//备注
parms[8].Value = infoEntity.CREATEUSER;//创建人gid
parms[9].Value = infoEntity.MODIFIEDUSER;//更新人gid
parms[10].Value = infoEntity.FINANCESOFTCODE;//
//parms[10].Value = infoEntity.MODIFIEDTIME;//更新时间
//parms[11].Value = infoEntity.CREATETIME;//创建时间
strSqlInsertInfo = String.Format(strSqlInsertInfo);
//
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSqlInsertInfo, parms);
if (existVal > 0)
{
iResult = 1;
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
/// <summary>
/// 更新信息
/// </summary>
/// <param name="AccountEntity">实体类</param>
/// <returns>值为1更新数据正常,-1操作异常</returns>
public int UpdateInfo(AccountEntity infoEntity)
{
int iResult = 0;
//获取参数
SqlParameter[] parms = GetUpdateParms();
parms[0].Value = infoEntity.GID;//惟一编号
parms[1].Value = infoEntity.LINKID;//公司关联id
parms[2].Value = infoEntity.CODENAME;//代码
parms[3].Value = infoEntity.CURRENCY;//币别
parms[4].Value = infoEntity.BANKNAME;//银行名称
parms[5].Value = infoEntity.ACCOUNT;//银行账户
parms[6].Value = infoEntity.SubjectCode;//科目代码
parms[7].Value = infoEntity.REMARK;//备注
parms[8].Value = infoEntity.MODIFIEDUSER;//更新人gid
parms[9].Value = infoEntity.FINANCESOFTCODE;//
//parms[9].Value = infoEntity.CREATEUSER;//创建人gid
//parms[10].Value = infoEntity.MODIFIEDTIME;//更新时间
//parms[11].Value = infoEntity.CREATETIME;//创建时间
//
//string strMODIFIEDTIME = infoEntity.MODIFIEDTIME.ToString().IndexOf("0001")>-1 ? "null" : "'" + infoEntity.MODIFIEDTIME.ToString() + "'";
//string strMODIFIEDTIME_name = "MODIFIEDTIME="; //strETA.Equals("") ? "" : "ETA=";
//
strSqlUpdateInfo = String.Format(strSqlUpdateInfo);//, strMODIFIEDTIME_name, strMODIFIEDTIME);
//
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSqlUpdateInfo, parms);
if (existVal > 0)
{
iResult = 1;
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
#region 生成插入语句参数
/// <summary>
/// 生成插入语句参数
/// </summary>
/// <returns>返回SqlParameter数组</returns>
private SqlParameter[] GetInsertParms()
{
SqlParameter[] parms = new SqlParameter[]
{
new SqlParameter("@GID",SqlDbType.VarChar,36),//惟一编号
new SqlParameter("@LINKID",SqlDbType.VarChar,36),//公司关联id
new SqlParameter("@CODENAME",SqlDbType.VarChar,20),//代码
new SqlParameter("@CURRENCY",SqlDbType.VarChar,20),//币别
new SqlParameter("@BANKNAME",SqlDbType.VarChar,100),//银行名称
new SqlParameter("@ACCOUNT",SqlDbType.VarChar,40),//银行账户
new SqlParameter("@SubjectCode",SqlDbType.VarChar,20),//代码
new SqlParameter("@REMARK",SqlDbType.VarChar,100),//备注
new SqlParameter("@CREATEUSER",SqlDbType.VarChar,36),//创建人gid
new SqlParameter("@MODIFIEDUSER",SqlDbType.VarChar,36),//更新人gid
new SqlParameter("@FINANCESOFTCODE",SqlDbType.VarChar,20)//
//new SqlParameter("@MODIFIEDTIME",SqlDbType.datetime),//更新时间
//new SqlParameter("@CREATETIME",SqlDbType.datetime),//创建时间
};
return parms;
}
#endregion
#region 生成更新语句参数
/// <summary>
/// 生成更新语句参数
/// </summary>
/// <returns>返回SqlParameter数组</returns>
private SqlParameter[] GetUpdateParms()
{
SqlParameter[] parms = new SqlParameter[]{
new SqlParameter("@GID",SqlDbType.VarChar,36),//惟一编号
new SqlParameter("@LINKID",SqlDbType.VarChar,36),//公司关联id
new SqlParameter("@CODENAME",SqlDbType.VarChar,20),//代码
new SqlParameter("@CURRENCY",SqlDbType.VarChar,20),//币别
new SqlParameter("@BANKNAME",SqlDbType.VarChar,100),//银行名称
new SqlParameter("@ACCOUNT",SqlDbType.VarChar,40),//银行账户
new SqlParameter("@SubjectCode",SqlDbType.VarChar,20),//代码
new SqlParameter("@REMARK",SqlDbType.VarChar,100),//备注
new SqlParameter("@MODIFIEDUSER",SqlDbType.VarChar,36),//更新人gid
new SqlParameter("@FINANCESOFTCODE",SqlDbType.VarChar,20)//
//new SqlParameter("@CREATEUSER",SqlDbType.VarChar,36),//创建人gid
//new SqlParameter("@MODIFIEDTIME",SqlDbType.DateTime),//更新时间
//new SqlParameter("@CREATETIME",SqlDbType.datetime),//创建时间
};
return parms;
}
#endregion
#region 返回数据集 公司表Account信息
/// <summary>
/// 返回 公司表Account信息
/// </summary>
/// <returns></returns>
public DataSet GetAccountSQL(string strSQL)
{
string str = "select * from [sys_bank] where 1=1 " + strSQL;
DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str);
try
{
if (DS.Tables[0].Rows.Count <= 0)
{
DS = null;
}
}
catch
{
DS = null;
}
return DS;
}
#endregion
#region 返回数据集 公司表Account信息
/// 返回 公司表Account删除
/// </summary>
/// <returns></returns>
/// <summary>
public String GetAccountDel(string strGid, string strUserID)
{
string alt = "";
string str = "update sys_bank set ISDELETED=1 where Gid='" + strGid + "'";
bool bl = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str);
if (bl == false)
{
alt = "账户表sys_bank删除操作出错";
return alt;
}
else
{
//string str1 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('删除账户表sys_bank的信息','更新操作','" + str + "','" + strUserID + "')";
//bool bl1 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str1);
}
return alt;
}
#endregion
/// <summary>
/// 根据SQL语句查询账户数据集
/// </summary>
/// <param name="strSql"></param>
/// <returns></returns>
public DataSet GetExcuteSql(string strSql)
{
DataSet userSet = new DataSet();
userSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql);
return userSet;
}
#region 插入账户列表信息
/// <summary>
/// 插入账户列表信息
/// </summary>
/// <param name="sqlList">插入SQL语句组,将所有要执行的插入语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作</param>
/// <returns>返回状态值 为1表示插入完成;为-1插入出现异常但未正确回滚事务;为-2插入异常,事务已经成功回滚;默认状态为0</returns>
public int InsertAccountFromGrid(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 更新账户列表信息
/// <summary>
/// 更新账户列表信息
/// </summary>
/// <param name="sqlList">更新SQL语句组,将所有要执行的更新语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作</param>
/// <returns>返回状态值 为1表示更新完成;为-1更新出现异常但未正确回滚事务;为-2更新异常,事务已经成功回滚;默认状态为0</returns>
public int UpdateAccountFromGrid(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 通过关联编号LINKID与账户类型获取账户信息
/// <summary>
/// 通过关联编号LINKID与账户类型获取账户信息
/// </summary>
/// <param name="strGID"></param>
/// <returns></returns>
public AccountEntity GetAccountByLINKIDAndType(string strLINKID)
{
AccountEntity AccountEntity = null;
string strSql = " SELECT top 1 GID,LINKID,CODENAME,CURRENCY,BANKNAME,ACCOUNT,SubjectCode,REMARK,FINANCESOFTCODE,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME FROM sys_bank WHERE LINKID = '" + strLINKID + "'";
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql, null))
{
try
{
while (sqlRead.Read())
{
AccountEntity = new AccountEntity();
if (!sqlRead.IsDBNull(0))
{
AccountEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
AccountEntity.LINKID = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
AccountEntity.CODENAME = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
AccountEntity.CURRENCY = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
AccountEntity.BANKNAME = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
AccountEntity.ACCOUNT = sqlRead.GetString(5);
}
if (!sqlRead.IsDBNull(6))
{
AccountEntity.SubjectCode = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
AccountEntity.REMARK = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
AccountEntity.FINANCESOFTCODE = sqlRead.GetString(8);
}
if (!sqlRead.IsDBNull(9))
{
AccountEntity.CREATEUSER = sqlRead.GetString(9);
}
if (!sqlRead.IsDBNull(10))
{
AccountEntity.CREATETIME = sqlRead.GetDateTime(10);
}
if (!sqlRead.IsDBNull(11))
{
AccountEntity.MODIFIEDUSER = sqlRead.GetString(11);
}
if (!sqlRead.IsDBNull(12))
{
AccountEntity.MODIFIEDTIME = sqlRead.GetDateTime(12);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return AccountEntity;
}
#endregion
#region 通过账户GID删除单条账户
public int DeleteAccountByGid(string tempGid)
{
int result = 0;
SqlParameter parm = new SqlParameter(PARM_Account_GID, SqlDbType.VarChar, 36);
parm.Value = tempGid;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_DELETE_Account_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
}
}