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.FundCustAccount { public class FundCustAccountMgt : FundBaseBLL.FundBaseBLL { private OpeBase _ob; public FundCustAccountMgt(OpeBase ob) : base(ob) { _ob = ob; } /// /// 通过结算单位和客户名称,返回客户账户信息 /// /// /// /// public System.Data.DataSet GetCustAccountByBalanceSubjectAndBuyercode(string balanceSubject, string buyercode) { return GetFundCustAccountInstance().GetSelFundCustAccountInfo(balanceSubject, buyercode, true); } /// ///通过结算单位 获取所有客户账户数据集 /// /// /// public DataSet GetCustAccountByBalanceSubject(string balanceSubject) { return base.GetFundCustAccountInstance().GetSelFundCustAccountInfo(balanceSubject); } /// /// 返回一个结算单位下的所有账户信息 /// /// /// public List GetSelFundCustAccountByBalanceSubject(string balanceSub) { return this.GetFundCustAccountInstance().GetSelFundCustAccountModelByBalanceList(balanceSub); } public Model.SEL_FUND_CUST_ACCOUNT GetSelFundCustAccountByBalanceSubjectAndBuyercode(string balanceSubject, string buyercode) { return this.GetFundCustAccountInstance().GetSelFundCustAccountModelByBalanceAndBuyercode(balanceSubject,buyercode); } /// /// 通过结算单位,客户名称返回其资金转移明细数据 /// /// /// /// public DataSet GetSelFundUsedDetailByBalancesubjectAndBuyercode(string balanceSubject, string buyercode) { return base.GetFundCustUsedDetailInstance().GetSelFundUsedDetail(balanceSubject,buyercode); } public System.Collections.ArrayList GetAllSaleAre() { System.Collections.ArrayList list = new System.Collections.ArrayList(); DataSet ds = new DataSet(); string sql = "SELECT distinct A.SALE_AREA_DESC FROM SLM_BASE_SALE_AREA_TYP A where a.validflag='1'"; ds = base.ExecuteReader(sql); try { foreach (DataRow dr in ds.Tables[0].Rows) { list.Add(dr[0].ToString()); } } catch { } return list; } public void CreateCustAccount(Model.SEL_FUND_CUST_ACCOUNT acct, string creator,out string err) { err = ""; // 检查同结算单位和合同号是否存在 Model.SEL_FUND_CUST_ACCOUNT fund = null; DbHelp.DbTransaction transaction = base.GetTransaction(); fund = GetFundCustAccountInstance().GetSelFundCustAccountModelByBalanceAndBuyercode(acct.BALANCESUBJECT, acct.BUYERCODE); //if (fund != null) //{ // err = "客户信息已经存在"; // return; //} bool isCreateSecAccountBySaleArea = true; System.Collections.ArrayList list = GetAllSaleAre(); if (!isCreateSecAccountBySaleArea) { list.Clear(); } try { Model.SEL_FUND_PACT_ACCOUNT pactact = new Model.SEL_FUND_PACT_ACCOUNT(); //secact.BALANCESUBJECT = acct.BALANCESUBJECT; //secact.BUYERCODE = acct.BUYERCODE; //secact.SECONDACCOUNT = FundVariable.FundConstVariable.defaultSecondLevelAccount; //secact.IMPORTOR = creator; //secact.IMPORTTIME = Util.DateTimeUtil.GetSystemDate(); pactact.BALANCESUBJECT = acct.BALANCESUBJECT; pactact.BUYERCODE = acct.BUYERCODE; pactact.SECONDACCOUNT = FundVariable.FundConstVariable.defaultSecondLevelAccount; pactact.PACTNO = FundVariable.FundConstVariable.defaultPactLevelAccount; pactact.IMPORTOR = creator; pactact.IMPORTTIME = Util.DateTimeUtil.GetSystemDate(); System.Collections.ArrayList listsql = new System.Collections.ArrayList(); // 写入记录 // 创建客户账户 // GetFundCustAccountInstance().Insert_SelFundCustAccount(acct, transaction); if (fund == null) listsql.Add(GetFundCustAccountInstance().Sql_Insert_SelFundCustAccount(acct)); // 创建默认二级账户 // 是否创建默认的二级账户和合同账户 if (FundVariable.FundConstVariable.isCreateDefaultAccount) { Model.SEL_FUND_SECONDLEVEL_ACCOUNT secact = null; secact = new Core.StlMes.Client.Sale.SaleFundMgt.Model.SEL_FUND_SECONDLEVEL_ACCOUNT(); secact.BALANCESUBJECT = acct.BALANCESUBJECT; secact.BUYERCODE = acct.BUYERCODE; secact.SECONDACCOUNT = FundVariable.FundConstVariable.defaultSecondLevelAccount; secact.IMPORTOR = creator; secact.IMPORTTIME = Util.DateTimeUtil.GetSystemDate(); Model.SEL_FUND_SECONDLEVEL_ACCOUNT secacct1 = base.GetFundSecondAccountInstance().GetSelFundSecondAccountBySecondAccount(secact.BALANCESUBJECT, secact.BUYERCODE, secact.SECONDACCOUNT); if (secacct1 == null) { // listsql.Add(GetFundSecondAccountInstance().SqlCreateSecondLevelAccount(secact)); // GetFundSecondAccountInstance().CreateSecondLevelAccount(secact, transaction); } List acctmodel = base.GetFundPactAccountInstance(). GetSelFundPactAccountByBalanceAndPactno(pactact.BALANCESUBJECT, pactact.BUYERCODE, pactact.PACTNO); if (acctmodel == null || acctmodel.Count == 0) { // 创建默认合同账户 // GetFundPactAccountInstance().CreateFundPactAccount(pactact, transaction); // listsql.Add(GetFundPactAccountInstance().Sql_CreateFundPactAccount(pactact)); } if (list.Count > 0) { foreach (string s in list) { secact = new Core.StlMes.Client.Sale.SaleFundMgt.Model.SEL_FUND_SECONDLEVEL_ACCOUNT(); secact.BALANCESUBJECT = acct.BALANCESUBJECT; secact.BUYERCODE = acct.BUYERCODE; secact.SECONDACCOUNT = s; secact.IMPORTOR = creator; secact.IMPORTTIME = Util.DateTimeUtil.GetSystemDate(); Model.SEL_FUND_SECONDLEVEL_ACCOUNT secacct = base.GetFundSecondAccountInstance().GetSelFundSecondAccountBySecondAccount(secact.BALANCESUBJECT, secact.BUYERCODE, secact.SECONDACCOUNT); if (secacct == null) { listsql.Add(GetFundSecondAccountInstance().SqlCreateSecondLevelAccount(secact)); // GetFundSecondAccountInstance().CreateSecondLevelAccount(secact, transaction); } pactact.SECONDACCOUNT = s; // List acctmodel1 = base.GetFundPactAccountInstance(). //GetSelFundPactAccountByBalanceAndPactno(pactact.BALANCESUBJECT, pactact.BUYERCODE, pactact.PACTNO); // if (acctmodel1 == null || acctmodel1.Count == 0) // { // // 创建默认合同账户 // // GetFundPactAccountInstance().CreateFundPactAccount(pactact, transaction); // listsql.Add(GetFundPactAccountInstance().Sql_CreateFundPactAccount(pactact)); // } } } } string errMsg = ""; base.ExecuteNoReader(listsql, out err); // 提交 } catch(Exception ex) { } } /// /// 在集合中搜寻一个客户单位 /// /// /// /// /// public Boolean IsCustAccountExists(string balanceSubject, string buyercode, List list) { if (list == null) return false; if (list.Count == 0) return false; foreach (Model.SEL_FUND_CUST_ACCOUNT acc in list) { if (acc.BALANCESUBJECT == balanceSubject && acc.BUYERCODE == buyercode) { return true; } } return false; } /// /// 删除一个客户账户信息 /// /// /// /// public void DeleCustAccount(string balanceSubject, string buyercode, string deletor,out string errMsg) { errMsg = ""; // 检查账户信息 Model.SEL_FUND_CUST_ACCOUNT cust = GetSelFundCustAccountByBalanceSubjectAndBuyercode(balanceSubject,buyercode); if (cust == null) return; // 有剩余资金,不允许删除 if (cust.LEAVEMONEY > 0) { errMsg = "剩余资金大于0"; return; } // 有二级账户,不允许删除 FundDAL.FundSecondLevelAccountDAL.FundSecondlevelAccountDAL secacct = new FundDAL.FundSecondLevelAccountDAL.FundSecondlevelAccountDAL(this._ob); List seclist = secacct.GetSelFundSecondAccountByBalanceSubjectAndBuyercode(balanceSubject,buyercode); if (seclist != null) { if (seclist.Count > 0) { errMsg = "该账户存在子账户"; return; } } // 删除 GetFundCustAccountInstance().DeleteCustAccount(balanceSubject, buyercode, out errMsg); } } }