using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using CoreFS.CA06; using DbHelp = Core.StlMes.Client.Sale.DbHelp; namespace Core.StlMes.Client.Sale.SaleFundMgt.FundBLL.FundSecondLevelAccount { public class FundSecondlevelAccountMgt:FundBaseBLL.FundBaseBLL { private OpeBase _ob; public FundSecondlevelAccountMgt(OpeBase ob) : base(ob) { _ob = ob; } public DataSet GetSecondLevelAccountByBalanceAndBuyercode(string balanceSubject,string buyercode) { return this.GetSecondLevelAccountInstance().GetSelFundSecondLevelAccountInfoByBalanceSubjectAndBuyerCode(balanceSubject, buyercode, true); } private FundDAL.FundSecondLevelAccountDAL.FundSecondlevelAccountDAL GetSecondLevelAccountInstance() { return new FundDAL.FundSecondLevelAccountDAL.FundSecondlevelAccountDAL(this._ob); } private FundDAL.FundSecondLevelAccountDAL.FundSecondUsedDetailDAL GetSecondLevelDetailInstance() { return new FundDAL.FundSecondLevelAccountDAL.FundSecondUsedDetailDAL(this._ob); } /// /// 通过结算单位,客户单位,二级单位返回二级账户资金转移信息 /// /// /// /// /// public DataSet GetSelFundSecondUsedDetailByBalanceSubjectAndBuyercodeAndSecondName(string balancesubject, string buyercode, string secondacct) { return GetSecondLevelDetailInstance().GetSelFundSecondUsedDetailBybalAndBuyercodeAndsecondName(balancesubject,buyercode,secondacct); } /// /// 获取所有二级账户,并组合成数组返回 /// /// public string[] GetAllSecondLevelAccount() { List list = new List(); DataSet ds = this.GetSecondLevelAccountInstance().GetSelFundSecondlevelAccountInfo(""); if (Util.DataSetUtil.Count(ds) == 0) return null; foreach (DataRow dr in ds.Tables[0].Rows) { if (!list.Contains(dr[_columnNameSecAct].ToString())) { list.Add(dr[_columnNameSecAct].ToString()); } } return list.ToArray(); } /// /// 获取所有二级账户信息,list返回 /// /// public List GetAllSecondLevelAccountList() { List list = new List(); DataSet ds = this.GetSecondLevelAccountInstance().GetSelFundSecondlevelAccountInfo(""); if (Util.DataSetUtil.Count(ds) == 0) return null; foreach (DataRow dr in ds.Tables[0].Rows) { if (!list.Contains(dr[_columnNameSecAct].ToString())) { list.Add(dr[_columnNameSecAct].ToString()); } } return list; } private string _columnNameSecAct = "SECONDACCOUNT"; /// /// 创建二级账户 /// /// /// public void CreateSecondLevelAccount(Model.SEL_FUND_SECONDLEVEL_ACCOUNT act, out string errMsg) { errMsg = ""; // 检查二级账户是否存在 Model.SEL_FUND_SECONDLEVEL_ACCOUNT secacct = this.GetSecondLevelAccountInstance().GetSelFundSecondAccountBySecondAccount(act.BALANCESUBJECT,act.BUYERCODE,act.SECONDACCOUNT); if (secacct != null) { errMsg = "二级账户已经存在"; return; } this.GetSecondLevelAccountInstance().CreateSecondLevelAccount(act,out errMsg); } /// /// 顺延创建二级账户和三级账户,有则不创建,没有则创建 /// /// /// public void CreateSecondLevelAccountAndPactAccount(Model.SEL_FUND_PACT_ACCOUNT act, out string errMsg) { errMsg = ""; DbHelp.DbTransaction transaction = base.GetTransaction(); try { transaction.BeginTransaction(); // 检查二级账户是否存在 Model.SEL_FUND_SECONDLEVEL_ACCOUNT secacct = this.GetSecondLevelAccountInstance().GetSelFundSecondAccountBySecondAccount(act.BALANCESUBJECT, act.BUYERCODE, act.SECONDACCOUNT); if (secacct == null) { // 不存在则创建 Model.SEL_FUND_SECONDLEVEL_ACCOUNT acct = new Model.SEL_FUND_SECONDLEVEL_ACCOUNT (act.BALANCESUBJECT, act.BUYERCODE, act.SECONDACCOUNT, 0, 0, "System", Util.DateTimeUtil.GetSystemDate(), Util.DateTimeUtil.GetSystemDate()); this.GetSecondLevelAccountInstance().CreateSecondLevelAccount(acct, transaction); } // 原则上同结算单位,同客户,一个合同号只能在一个二级账户,不能多个二级账户分布 List acctmodel = this.GetFundPactAccountInstance(). GetSelFundPactAccountByBalanceAndPactno(act.BALANCESUBJECT, act.BUYERCODE, act.PACTNO); if (acctmodel == null || acctmodel.Count == 0) { this.GetFundPactAccountInstance().CreateFundPactAccount(act, transaction); } // 提交 transaction.Commit(); } catch(Exception ex) { errMsg = ex.Message; transaction.RollBack(); } } public void DeleteSecondLevelAccount(Model.SEL_FUND_SECONDLEVEL_ACCOUNT act, out string errMsg) { errMsg = ""; if (!FundVariable.FundConstVariable.isDefaultAccountCanBeDelete && act.SECONDACCOUNT == FundVariable.FundConstVariable.defaultSecondLevelAccount) { errMsg = "默认账号,不允许删除"; return; } Model.SEL_FUND_SECONDLEVEL_ACCOUNT le = null; le = this.GetSecondLevelAccountInstance().GetSelFundSecondAccountBySecondAccount(act.BALANCESUBJECT,act.BUYERCODE,act.SECONDACCOUNT); if (le != null) { if (le.LEAVEMONEY > 0) { errMsg = "有剩余资金,不允许删除"; return; } } // 检查其是否有合同子账户 FundBLL.FundPactAccount.FundPactAccountMgt pactaccountBLL = new FundBLL.FundPactAccount.FundPactAccountMgt (this._ob); List pactAccount = null; pactAccount = pactaccountBLL.GetFundPactAccountModelListByBalanceAndBuyercodeAndSecondAccount(act.BALANCESUBJECT,act.BUYERCODE,act.SECONDACCOUNT); if (pactAccount != null) { errMsg = "账户存在子账户"; return; } this.GetSecondLevelAccountInstance().DeleteSecondLevelAccount(act,out errMsg); } } }