/// <summary> /// Create Account Number /// </summary> /// <param name="newClient"></param> /// <returns></returns> public static void CreateAccountNumberForUser(Client newClient, out string tradingAcn, out string landingAcn, out long actualAccount) { try { var accountCreationRuleBO = new AccountCreationRuleBO(); AccountCurrencyBO curencyBO = new AccountCurrencyBO(); string tradingAccountNumber = string.Empty; var landingAccountNumber = string.Empty; string landingAccCurrencyCode = string.Empty; long lAccNumber = 0; var rulelist = accountCreationRuleBO.GetRule().OrderBy(c => c.Position); var currencyID = curencyBO.GetCurrencyLookUpID(newClient.FK_AccountCurrencyID); //Iterating through each rule/steps of account creation foreach (var item in rulelist) { //Currency if (item.Meaning == Constants.K_ACC_RULE_CURRENCY) { L_CurrencyValueBO currencyBO = new L_CurrencyValueBO(); tradingAccountNumber += currencyBO.GetCurrencyAccountCode(currencyID) + "-"; } //Account Number Belonging to that Currency else if (item.Meaning == Constants.K_ACC_RULE_CURR_NUMBER) { var template = item.Template; Client_AccountBO clientAccBO = new Client_AccountBO(); var tradingAccCount = clientAccBO.GetNumberOfSameCurrencyTradingAccountForUser(LoginAccountType.LiveAccount, newClient.PK_ClientID, currencyID); tradingAccountNumber += (tradingAccCount + 1).ToString("D" + template.Length) + "-"; //Required while creating landing account for (var ctDigit = 0; ctDigit < template.Length; ctDigit++) { landingAccCurrencyCode += "0"; } } //Client Account Number else if (item.Meaning == Constants.K_ACC_RULE_ACC_NUMBER) { var template = item.Template; Client_AccountBO clientAccBO = new Client_AccountBO(); var existingAccNumber = clientAccBO.GetUserExistingAccountNumber(LoginAccountType.LiveAccount, newClient.PK_ClientID); var latestAccNumber = clientAccBO.GetLatestAccountNumber(); //If no previous account exists for the user if (existingAccNumber == "") { //If any acc number exists in db if (latestAccNumber != "") { lAccNumber = Convert.ToInt64(latestAccNumber); tradingAccountNumber += (lAccNumber + 1).ToString("D" + template.Length) + "-"; lAccNumber++; } //If no acc number exists in db else { lAccNumber = 1; tradingAccountNumber += lAccNumber.ToString("D" + template.Length) + "-"; } } //If user has acc number in system else { tradingAccountNumber += existingAccNumber.Split('-')[((int)item.Position - 1)] + "-"; lAccNumber = Convert.ToInt64(existingAccNumber.Split('-')[((int)item.Position - 1)]); } } } //Landing account landingAccountNumber = tradingAccountNumber.Split('-')[0] + "-" + landingAccCurrencyCode + "-" + tradingAccountNumber.Split('-')[2]; landingAcn = landingAccountNumber; tradingAcn = tradingAccountNumber.TrimEnd('-'); actualAccount = lAccNumber; } catch (Exception ex) { CommonErrorLogger.CommonErrorLog(ex, System.Reflection.MethodBase.GetCurrentMethod().Name); throw; } }