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; } /// /// 新增 /// /// /// public bool InserModel(Infrastructure.Domain.IAggregateRoot model) { Model.OA_FirmAccount trueModel = model as Model.OA_FirmAccount; if (trueModel == null) { return false; } IList sqlParms = new List() { 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()); } catch (Exception ex) { throw ex; } return true; } /// /// 修改 /// /// /// public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model) { Model.OA_FirmAccount trueModel = model as Model.OA_FirmAccount; if (trueModel == null) { return false; } IList sqlParms = new List() {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()); } catch (Exception ex) { throw ex; } return true; } /// /// 删除 /// /// /// public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model) { Model.OA_FirmAccount trueModel = model as Model.OA_FirmAccount; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@Keyid",trueModel.Keyid) }; try { _dataBase.Query("sp_OA_FirmAccount_DeleteRow", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 分页查询 /// /// /// /// public IEnumerable SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination) { throw new NotImplementedException(); } /// /// 单个查询 /// /// /// public IEnumerable SelectAllModel(Infrastructure.Query.Query query) { throw new NotImplementedException(); } /// /// 获取单个账户 /// /// /// public OA_FirmAccount getSingleSubject(int? Keyid) { string selectTarget = "*"; string fromSource = "OA_FirmAccount where Keyid='" + Keyid + "'"; return _dataBase.SelectModel(selectTarget, fromSource)[0]; } /// /// 根据firmid 获取全部账户 /// /// /// public IEnumerable 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(pa, selectTarget, fromSource, " AccountType DESC, Balance DESC"); } /// /// 根据firmid 获取全部账户统计金额 /// /// /// /// /// /// /// 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 m_OA_FirmAccountList = _dataBase.SelectModel(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 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(selectTarget, fromSource); } /// /// 采购批量付款 /// /// /// /// /// public bool PurchasePayList(List OA_FirmAccountRecordList, List 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; } } } }