예제 #1
0
        public static void SaveCommissionRule(int ruleId, CommRuleDetails ruleDetails)
        {
            IDalSession session = NHSessionFactory.CreateSession();

            IAccount account = (ruleDetails.Account != 0 && ruleDetails.Account != int.MinValue ?
                AccountMapper.GetAccount(session, ruleDetails.Account) : null);
            IExchange exchange = (ruleDetails.Exchange != 0 && ruleDetails.Exchange != int.MinValue ?
                ExchangeMapper.GetExchange(session, ruleDetails.Exchange) : null);
            IPortfolioModel model = (ruleDetails.Model != 0 && ruleDetails.Model != int.MinValue ?
                (IPortfolioModel)ModelMapper.GetModel(session, ruleDetails.Model) : null);
            IInstrument instrument = (ruleDetails.Instrument != 0 && ruleDetails.Instrument != int.MinValue ?
                InstrumentMapper.GetInstrument(session, ruleDetails.Instrument) : null);
            ISecCategory secCategory = (ruleDetails.RuleSecCategory != 0 && ruleDetails.RuleSecCategory != int.MinValue ?
                SecCategoryMapper.GetSecCategory(session, (SecCategories)ruleDetails.RuleSecCategory) : null);

            CommRuleBuySell buySell = (CommRuleBuySell)ruleDetails.BuySell;

            CommRuleOpenClose openClose = (CommRuleOpenClose)ruleDetails.OpenClose;

            BaseOrderTypes originalOrderType = (BaseOrderTypes)ruleDetails.OriginalOrderType;

            CommRuleTypes commruleType = (CommRuleTypes)ruleDetails.CommRuleType;

            OrderActionTypes orderActionType = (OrderActionTypes)ruleDetails.OrderActionType;

            CommCalc commissionCalculation = CommCalcMapper.GetCommissionCalculation(session, ruleDetails.CommCalculation);

            CommCalc additionalCalculation = ruleDetails.AdditionalCalculation != 0 && ruleDetails.AdditionalCalculation != int.MinValue ?
                CommCalcMapper.GetCommissionCalculation(session, ruleDetails.AdditionalCalculation) : null;

            CommRule specificRule = null;
            if (ruleId != 0)
                specificRule = (CommRule)CommRuleMapper.GetCommissionRule(session, ruleId);
            else
                specificRule = new CommRule();

            specificRule.CommRuleName = ruleDetails.CommRuleName;
            specificRule.CommRuleType = commruleType;
            specificRule.AccountType = AccountTypes.Customer;
            specificRule.StartDate = ruleDetails.StartDate;
            specificRule.EndDate = ruleDetails.EndDate;
            specificRule.Account = account;
            specificRule.ModelPortfolio = model;
            specificRule.Instrument = instrument;
            specificRule.Exchange = exchange;
            specificRule.RuleSecCategory = secCategory;
            specificRule.BuySell = buySell;
            specificRule.OpenClose = openClose;
            specificRule.OriginalOrderType = originalOrderType;
            specificRule.CommCalculation = commissionCalculation;
            specificRule.AdditionalCalculation = additionalCalculation;
            specificRule.ActionType = orderActionType;
            specificRule.ApplyToAllAccounts = ruleDetails.ApplyToAll;
            specificRule.HasEmployerRelation = ruleDetails.HasEmployerRelation;

            InternalEmployeeLogin emp = LoginMapper.GetCurrentLogin(session) as InternalEmployeeLogin;
            if (emp != null)
                specificRule.AssetManager =  (IAssetManager)emp.Employer;

            CommRuleMapper.InsertOrUpdate(session, specificRule);

            session.Close();
        }
예제 #2
0
        public static CommRuleDetails GetCommRuleDetails(int ruleId)
        {
            IDalSession session = NHSessionFactory.CreateSession();
            ICommRule rule = CommRuleMapper.GetCommissionRule(session, ruleId);
            CommRuleDetails ruleDetails = new CommRuleDetails();

            ruleDetails.CommRuleName = rule.CommRuleName.Trim();
            ruleDetails.CommCalculation = rule.CommCalculation.Key;
            ruleDetails.CommRuleType = ((int)rule.CommRuleType);

            if (rule.AdditionalCalculation != null)
                ruleDetails.AdditionalCalculation = rule.AdditionalCalculation.Key;
            if (rule.StartDate != null)
                ruleDetails.StartDate = rule.StartDate;
            if (rule.EndDate != null)
                ruleDetails.EndDate = rule.EndDate;
            if (rule.ModelPortfolio != null)
                ruleDetails.Model = rule.ModelPortfolio.Key;
            if (rule.Account != null)
                ruleDetails.Account = rule.Account.Key;
            if (rule.Exchange != null)
                ruleDetails.Exchange = rule.Exchange.Key;
            if (rule.Instrument != null)
                ruleDetails.Instrument = rule.Instrument.Key;
            if (rule.RuleSecCategory != null)
                ruleDetails.RuleSecCategory = (int)rule.RuleSecCategory.Key;
            ruleDetails.OrderActionType = (int)rule.ActionType;
            ruleDetails.BuySell = (int)rule.BuySell;
            ruleDetails.OriginalOrderType = (int)rule.OriginalOrderType;
            ruleDetails.ApplyToAll = rule.ApplyToAllAccounts;
            ruleDetails.HasEmployerRelation = rule.HasEmployerRelation;

            session.Close();

            return ruleDetails;
        }