using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using CY.IDAL;
|
using System.Data.SqlClient;
|
using System.Data;
|
using CY.Infrastructure.DESEncrypt;
|
using CY.Infrastructure.Common;
|
using CY.Infrastructure.Query;
|
using CY.Model;
|
using System.Transactions;
|
|
namespace CY.SQLDAL
|
{
|
public class OA_FirmAccountDAL : IOA_FirmAccountDAL
|
{
|
|
private Database _dataBase = null;
|
public OA_FirmAccountDAL()
|
{
|
_dataBase = new Database();
|
}
|
|
public OA_FirmAccountDAL(Database dataBase)
|
{
|
_dataBase = dataBase;
|
}
|
|
/// <summary>
|
/// 新增
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.OA_FirmAccount trueModel = model as Model.OA_FirmAccount;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
IList<SqlParameter> sqlParms = new List<SqlParameter>()
|
{
|
new SqlParameter("@FirmId",trueModel.FirmId),
|
new SqlParameter("@AccountName",trueModel.AccountName),
|
new SqlParameter("@AccountType",trueModel.AccountType),
|
new SqlParameter("@UserName",trueModel.UserName),
|
new SqlParameter("@ResponsiblePerson",trueModel.ResponsiblePerson),
|
new SqlParameter("@Status",trueModel.Status),
|
new SqlParameter("@Balance",trueModel.Balance),
|
new SqlParameter("@AllIncome",trueModel.AllIncome),
|
new SqlParameter("@AllExpenses",trueModel.AllExpenses),
|
new SqlParameter("@CreateTime",trueModel.CreateTime),
|
new SqlParameter("@LastUpdateTime",trueModel.LastUpdateTime),
|
new SqlParameter("@Operator",trueModel.Operator),
|
new SqlParameter("@Remark",trueModel.Remark)
|
};
|
try
|
{
|
_dataBase.Query("sp_OA_FirmAccount_Insert", CommandType.StoredProcedure, sqlParms.ToArray<SqlParameter>());
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 修改
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.OA_FirmAccount trueModel = model as Model.OA_FirmAccount;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
IList<SqlParameter> sqlParms = new List<SqlParameter>()
|
{new SqlParameter("@Keyid",trueModel.Keyid),
|
new SqlParameter("@FirmId",trueModel.FirmId),
|
new SqlParameter("@AccountName",trueModel.AccountName),
|
new SqlParameter("@AccountType",trueModel.AccountType),
|
new SqlParameter("@UserName",trueModel.UserName),
|
new SqlParameter("@ResponsiblePerson",trueModel.ResponsiblePerson),
|
new SqlParameter("@Status",trueModel.Status),
|
new SqlParameter("@Balance",trueModel.Balance),
|
new SqlParameter("@AllIncome",trueModel.AllIncome),
|
new SqlParameter("@AllExpenses",trueModel.AllExpenses),
|
new SqlParameter("@CreateTime",trueModel.CreateTime),
|
new SqlParameter("@LastUpdateTime",trueModel.LastUpdateTime),
|
new SqlParameter("@Operator",trueModel.Operator),
|
new SqlParameter("@Remark",trueModel.Remark)
|
};
|
try
|
{
|
_dataBase.Query("sp_OA_FirmAccount_Update", CommandType.StoredProcedure, sqlParms.ToArray<SqlParameter>());
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 删除
|
/// </summary>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.OA_FirmAccount trueModel = model as Model.OA_FirmAccount;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
IList<SqlParameter> sqlParms = new List<SqlParameter>()
|
{
|
new SqlParameter("@Keyid",trueModel.Keyid)
|
};
|
try
|
{
|
_dataBase.Query("sp_OA_FirmAccount_DeleteRow", CommandType.StoredProcedure, sqlParms.ToArray<SqlParameter>());
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 分页查询
|
/// </summary>
|
/// <param name="query"></param>
|
/// <param name="pagination"></param>
|
/// <returns></returns>
|
public IEnumerable<Model.OA_FirmAccount> SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination)
|
{
|
throw new NotImplementedException();
|
}
|
|
/// <summary>
|
/// 单个查询
|
/// </summary>
|
/// <param name="query"></param>
|
/// <returns></returns>
|
public IEnumerable<Model.OA_FirmAccount> SelectAllModel(Infrastructure.Query.Query query)
|
{
|
throw new NotImplementedException();
|
}
|
|
/// <summary>
|
/// 获取单个账户
|
/// </summary>
|
/// <param name="Keyid"></param>
|
/// <returns></returns>
|
public OA_FirmAccount getSingleSubject(int? Keyid)
|
{
|
|
string selectTarget = "*";
|
string fromSource = "OA_FirmAccount where Keyid='" + Keyid + "'";
|
return _dataBase.SelectModel<Model.OA_FirmAccount>(selectTarget, fromSource)[0];
|
|
}
|
|
/// <summary>
|
/// 根据firmid 获取全部账户
|
/// </summary>
|
/// <param name="FirmId"></param>
|
/// <returns></returns>
|
public IEnumerable<OA_FirmAccount> getAllSubject(Pagination pa, Guid FirmId, string AccountType, string AccountStatus, string AccountName)
|
{
|
string selectTarget = "*";
|
string condition = " where FirmId='" + FirmId + "'";
|
if (!string.IsNullOrEmpty(AccountType))
|
{
|
condition += string.Format(" and AccountType='{0}' ", AccountType);
|
}
|
|
if (!string.IsNullOrEmpty(AccountStatus))
|
{
|
condition += string.Format(" and Status='{0}' ", AccountStatus);
|
}
|
if (!string.IsNullOrEmpty(AccountName))
|
{
|
condition += " and AccountName like '%" + AccountName + "%'";
|
}
|
string fromSource = " OA_FirmAccount " + condition;
|
return _dataBase.SelectModelPage<Model.OA_FirmAccount>(pa, selectTarget, fromSource, " AccountType DESC, Balance DESC");
|
}
|
|
/// <summary>
|
/// 根据firmid 获取全部账户统计金额
|
/// </summary>
|
/// <param name="pa"></param>
|
/// <param name="FirmId"></param>
|
/// <param name="AccountType"></param>
|
/// <param name="AccountStatus"></param>
|
/// <param name="AccountName"></param>
|
/// <returns></returns>
|
public OA_FirmAccount SumRecordMoney(Pagination pa, Guid FirmId, string AccountType, string AccountStatus, string AccountName)
|
{
|
try
|
{
|
string selectTarget = " sum(Balance) as SumBalance,sum(AllIncome) as SumAllIncome,sum(AllExpenses) as SumAllExpenses ";
|
string condition = " where FirmId='" + FirmId + "'";
|
if (!string.IsNullOrEmpty(AccountType))
|
{
|
condition += string.Format(" and AccountType='{0}' ", AccountType);
|
}
|
|
if (!string.IsNullOrEmpty(AccountStatus))
|
{
|
condition += string.Format(" and Status='{0}' ", AccountStatus);
|
}
|
if (!string.IsNullOrEmpty(AccountName))
|
{
|
condition += " and AccountName like '%" + AccountName + "%'";
|
}
|
string fromSource = " OA_FirmAccount " + condition;
|
|
|
IList<OA_FirmAccount> m_OA_FirmAccountList = _dataBase.SelectModel<Model.OA_FirmAccount>(selectTarget, fromSource, "");
|
if (m_OA_FirmAccountList != null && m_OA_FirmAccountList.Count == 2)
|
{
|
m_OA_FirmAccountList[0].SumBalance = m_OA_FirmAccountList[0].SumBalance > 0 ? m_OA_FirmAccountList[0].SumBalance : m_OA_FirmAccountList[1].SumBalance;
|
m_OA_FirmAccountList[0].SumAllIncome = m_OA_FirmAccountList[0].SumAllIncome > 0 ? m_OA_FirmAccountList[0].SumAllIncome : m_OA_FirmAccountList[1].SumAllIncome;
|
m_OA_FirmAccountList[0].SumAllExpenses = m_OA_FirmAccountList[0].SumAllExpenses > 0 ? m_OA_FirmAccountList[0].SumAllExpenses : m_OA_FirmAccountList[1].SumAllExpenses;
|
return m_OA_FirmAccountList[0];
|
}
|
else if (m_OA_FirmAccountList != null && m_OA_FirmAccountList.Count > 0)
|
{
|
return m_OA_FirmAccountList[0];
|
}
|
else
|
{
|
return null;
|
}
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
public IEnumerable<OA_FirmAccount> getAllSubject(Guid FirmId, string AccountType)
|
{
|
string selectTarget = " Keyid,AccountName,AccountType,UserName,Balance";
|
string condition = " where FirmId='" + FirmId + "' and Status = 'true'";
|
if (!string.IsNullOrEmpty(AccountType))
|
{
|
condition += string.Format(" and AccountType='{0}' ", AccountType);
|
}
|
|
string fromSource = " OA_FirmAccount " + condition;
|
return _dataBase.SelectModel<Model.OA_FirmAccount>(selectTarget, fromSource);
|
}
|
|
/// <summary>
|
/// 采购批量付款
|
/// </summary>
|
/// <param name="OA_FirmAccountRecordList"></param>
|
/// <param name="m_OA_ProcurementList"></param>
|
/// <param name="m_OA_FirmAccountOut"></param>
|
/// <returns></returns>
|
public bool PurchasePayList(List<OA_FirmAccountRecord> OA_FirmAccountRecordList, List<OA_Procurement> m_OA_ProcurementList, OA_FirmAccount m_OA_FirmAccountOut)
|
{
|
try
|
{
|
OA_FirmAccountRecordDAL dal_OA_FirmAccountRecordDAL = new OA_FirmAccountRecordDAL(_dataBase);
|
OA_ProcurementDAL dal_OA_ProcurementDAL = new OA_ProcurementDAL(_dataBase);
|
OA_FirmAccountDAL dal_OA_FirmAccountDAL = new OA_FirmAccountDAL(_dataBase);
|
bool IsSuccess = true;
|
using (TransactionScope t_TransactionScope = new TransactionScope())
|
{
|
if (IsSuccess)
|
{
|
for (int i = 0; i < OA_FirmAccountRecordList.Count; i++)
|
{
|
if (IsSuccess)
|
{
|
IsSuccess = dal_OA_FirmAccountRecordDAL.InserModel(OA_FirmAccountRecordList[i]);
|
if (IsSuccess)
|
{
|
IsSuccess = dal_OA_ProcurementDAL.UpdateModel(m_OA_ProcurementList[i]);
|
}
|
else
|
break;
|
}
|
else
|
break;
|
}
|
if (IsSuccess)
|
{
|
IsSuccess = dal_OA_FirmAccountDAL.UpdateModel(m_OA_FirmAccountOut);
|
if (IsSuccess)
|
t_TransactionScope.Complete();
|
}
|
}
|
}
|
return IsSuccess;
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
}
|
}
|