Пример #1
0
        public static void SaveSecurity(ref int instrumentID, ref bool blnSaveSuccess, SecurityDetails secDetails)
        {
            if (!SecurityManager.IsCurrentUserInRole("Data Mtce: Instrument Edit"))
                throw new System.Security.SecurityException("You are not authorized to update instrument details.");

            IDalSession session = NHSessionFactory.CreateSession();

            try
            {
                SecurityInstrument sec = null;
                if (instrumentID != 0)
                    sec = (SecurityInstrument)InstrumentMapper.GetTradeableInstrument(session, instrumentID);
                else
                {
                    switch (secDetails.SecCategory)
                    {
                        case SecCategories.Stock:
                            sec = new Stock();
                            break;
                        case SecCategories.Bond:
                            sec = new Bond();
                            break;
                        case SecCategories.MutualFund:
                            sec = new MutualFund();
                            break;
                        case SecCategories.VirtualFund:
                            IVirtualFundTradingAccount tradingAcc = new VirtualFundTradingAccount();
                            tradingAcc.ShortName = secDetails.InstrumentName + " Trading Account";
                            if (string.IsNullOrEmpty(secDetails.TradingAccountNumber))
                                tradingAcc.Number = secDetails.InstrumentName + " TA";
                            else
                                tradingAcc.Number = secDetails.TradingAccountNumber;

                            IVirtualFundHoldingsAccount holdingAcc = new VirtualFundHoldingsAccount();
                            holdingAcc.ShortName = secDetails.InstrumentName + " Holding Account";
                            if (string.IsNullOrEmpty(secDetails.HoldingAccountNumber))
                                holdingAcc.Number = secDetails.InstrumentName + " HA";
                            else
                                holdingAcc.Number = secDetails.HoldingAccountNumber;

                            IJournal journal = new Journal(JournalTypes.Memorial,
                                secDetails.JournalNumber,
                                LoginMapper.GetCurrentManagmentCompany(session),
                                InstrumentMapper.GetCurrency(session, secDetails.NominalCurrencyID));
                            sec = new VirtualFund(holdingAcc, tradingAcc, journal);
                            break;
                        case SecCategories.CashManagementFund:
                            sec = new CashManagementFund();
                            break;
                        default:
                            throw new ApplicationException("This seccategory is not supported.");
                    }
                }
                if (sec == null)
                    throw new ApplicationException("The instrument could not be found.");

                if (secDetails.DefaultExchangeID != int.MinValue)
                    sec.DefaultExchange = ExchangeMapper.GetExchange(session, secDetails.DefaultExchangeID);
                else
                    throw new ApplicationException("The default exchange is mandatory.");

                sec.Name = secDetails.InstrumentName;
                sec.Isin = secDetails.ISIN;
                sec.CompanyName = secDetails.CompanyName;
                sec.IssueDate = secDetails.IssueDate;
                sec.PriceType = secDetails.PriceType;
                sec.IsGreenFund = secDetails.IsGreenFund;
                sec.IsCultureFund = secDetails.IsCultureFund;
                sec.AllowNetting = secDetails.AllowNetting;
                sec.DecimalPlaces = secDetails.DecimalPlaces;

                if (secDetails.HomeExchangeID != int.MinValue)
                    sec.HomeExchange = ExchangeMapper.GetExchange(session, secDetails.HomeExchangeID);
                else
                    sec.HomeExchange = null;
                if (secDetails.RouteID != int.MinValue)
                    sec.DefaultRoute = RouteMapper.GetRoute(session, secDetails.RouteID);
                else
                    sec.DefaultRoute = null;
                if (secDetails.CountryID != int.MinValue)
                    sec.Country = CountryMapper.GetCountry(session, secDetails.CountryID);
                else
                    sec.Country = null;
                if (secDetails.NominalCurrencyID != int.MinValue)
                    sec.CurrencyNominal = InstrumentMapper.GetCurrency(session, secDetails.NominalCurrencyID);
                else
                    sec.CurrencyNominal = null;

                // sec category specific stuff
                switch (secDetails.SecCategory)
                {
                    case SecCategories.Bond:
                        IBond bond = (IBond)sec;
                        bond.AccruedInterestCalcType = secDetails.AccruedInterestCalcType;
                        bond.NominalValue = new Money(secDetails.NominalValue, bond.CurrencyNominal);
                        bond.CouponRate = secDetails.CouponRate;
                        if ((int)secDetails.CouponFreq >= (int)Regularities.Annual)
                            bond.CouponFreq = secDetails.CouponFreq;
                        else
                            bond.CouponFreq = 0;
                        bond.MaturityDate = secDetails.MaturityDate;
                        bond.UltimoDating = secDetails.UltimoDating;
                        bond.FirstCouponPaymntDate = secDetails.FirstCouponPaymntDate;

                        if (secDetails.RedemptionAmount != 0)
                            bond.RedemptionAmount = new Money(secDetails.RedemptionAmount, bond.CurrencyNominal);
                        else
                            bond.RedemptionAmount = null;
                        bond.IsPerpetual = secDetails.IsPerpetual;
                        bond.IsFixedCouponRate = secDetails.IsFixedCouponRate;
                        break;
                    case SecCategories.VirtualFund:
                        IVirtualFundTradingAccount tradingAcc = ((IVirtualFund)sec).TradingAccount;
                        if (tradingAcc != null)
                        {
                            if (!string.IsNullOrEmpty(secDetails.TradingAccountNumber))
                                tradingAcc.Number = secDetails.TradingAccountNumber;
                        }
                        IVirtualFundHoldingsAccount holdingAcc = ((IVirtualFund)sec).HoldingsAccount;
                        if (holdingAcc != null)
                        {
                            if (!string.IsNullOrEmpty(secDetails.HoldingAccountNumber))
                                holdingAcc.Number = secDetails.HoldingAccountNumber;
                        }
                        IJournal journal = ((IVirtualFund)sec).JournalForFund;
                        if (journal != null)
                        {
                            journal.BankAccountDescription = secDetails.JournalDescription;
                            //journal.ExactJournal = secDetails.ExactJournalNumber;
                        }
                        ((IVirtualFund)sec).InitialNavPerUnit = new Money(secDetails.InitialNavPerUnit, sec.CurrencyNominal);
                        break;
                }

                // instrument exchange
                IInstrumentExchange ie = sec.InstrumentExchanges.GetDefault() ?? sec.InstrumentExchanges.FirstOrDefault();
                if (ie == null)
                {
                    ie = new InstrumentExchange(sec, sec.DefaultExchange, secDetails.NumberOfDecimals);
                    sec.InstrumentExchanges.Add(ie);
                }
                else
                {
                    ie.Exchange = sec.DefaultExchange;
                    ie.NumberOfDecimals = secDetails.NumberOfDecimals;
                }

                if (secDetails.DefaultCounterpartyID != int.MinValue)
                    ie.DefaultCounterParty = (ICounterPartyAccount)AccountMapper.GetAccount(session, secDetails.DefaultCounterpartyID);
                else
                    ie.DefaultCounterParty = null;
                ie.DefaultSettlementPeriod = secDetails.DefaultSettlementPeriod;
                ie.TickSize = secDetails.TickSize;
                ie.DoesSupportAmountBasedBuy = secDetails.DoesSupportAmountBasedBuy;
                ie.DoesSupportAmountBasedSell = secDetails.DoesSupportAmountBasedSell;
                ie.DoesSupportServiceCharge = secDetails.DoesSupportServiceCharge;
                ie.ServiceChargePercentageBuy = secDetails.ServiceChargePercentageBuy;
                ie.ServiceChargePercentageSell = secDetails.ServiceChargePercentageSell;
                ie.RegisteredInNameOf = secDetails.RegisteredInNameof;
                ie.DividendPolicy = secDetails.DividendPolicy;
                ie.CommissionRecipientName = secDetails.CommissionRecipientName;
                ie.CertificationRequired = secDetails.CertificationRequired;

                // set Activity
                if (sec.Key != 0)
                {
                    if ((sec.IsActive && !secDetails.IsActive) || (Util.IsNullDate(sec.InActiveDate) && Util.IsNotNullDate(secDetails.InActiveDate)))
                    {
                        int activePositions = GetNumberActivePositionsForInstrument(session, sec.Key);
                        if (activePositions > 0)
                            throw new ApplicationException(string.Format("There are still {0} open positions in {1}, close these positions before the instrument can be inactivated.", activePositions, sec.DisplayNameWithIsin));
                    }

                    sec.IsActive = secDetails.IsActive;
                    sec.InActiveDate = secDetails.InActiveDate;
                }

                if (sec.Validate())
                {
                    blnSaveSuccess = InstrumentMapper.Update(session, sec);
                    instrumentID = sec.Key;
                }
            }
            finally
            {
                session.Close();
            }
        }
Пример #2
0
    protected void bntSave_Click(object sender, EventArgs e)
    {
        try
        {
            Page.Validate();
            bool valid = Page.IsValid;
            int instrumentID = InstrumentID;
            bool blnSaveSuccess = false;

            if (valid)
            {
                SecurityDetails secDetails = new SecurityDetails();

                secDetails.SecCategory = SecCategory;
                secDetails.InstrumentName = tbInstrumentName.Text;
                secDetails.ISIN = tbISIN.Text;
                secDetails.CompanyName = tbCompanyName.Text;
                secDetails.IssueDate = ucIssueDate.SelectedDate;
                secDetails.HomeExchangeID = Utility.GetKeyFromDropDownList(ddlHomeExchange);
                secDetails.DefaultExchangeID = Utility.GetKeyFromDropDownList(ddlDefaultExchange);
                secDetails.CountryID = Utility.GetKeyFromDropDownList(ddlCountry);
                secDetails.RouteID = Utility.GetKeyFromDropDownList(ddlDefaultRoute);
                secDetails.DecimalPlaces = Convert.ToInt32(dbDecimalPlaces.Value);
                secDetails.NominalCurrencyID = Utility.GetKeyFromDropDownList(ddCurrencyNominal);
                secDetails.PriceType = (PricingTypes)Convert.ToInt32(rbPricingType.SelectedValue);
                secDetails.AllowNetting = chkAllowNetting.Checked;
                secDetails.IsGreenFund = chkGreenFund.Checked;
                secDetails.IsCultureFund = chkCultureFund.Checked;
                if (pnlActivity.Visible)
                {
                    secDetails.IsActive = chkIsActive.Checked;
                    secDetails.InActiveDate = cldInActiveDate.SelectedDate;
                }

                switch (SecCategory)
                {
                    case SecCategories.Bond:
                        secDetails.AccruedInterestCalcType = (AccruedInterestCalcTypes)Utility.GetKeyFromDropDownList(ddlAccruedInterestCalcType);
                        secDetails.NominalValue = dbNominalValue.Value;
                        secDetails.CouponFreq = (Regularities)Utility.GetKeyFromDropDownList(ddlCouponFreq);
                        secDetails.CouponRate = dbCouponRate.Value;
                        secDetails.FirstCouponPaymntDate = dpFirstCouponPaymntDate.SelectedDate;
                        secDetails.UltimoDating = chkUltimoDating.Checked;
                        secDetails.MaturityDate = dpMaturityDate.SelectedDate;
                        secDetails.RedemptionAmount = dbRedemptionAmount.Value;
                        secDetails.IsPerpetual = chkIsPerpetual.Checked;
                        secDetails.IsFixedCouponRate = chkFixedCouponRate.Checked;

                        if (instrumentID != 0 && !secDetails.IsFixedCouponRate && gvCouponRates.Rows.Count == 0)
                            throw new ApplicationException("When the bond is not a fixed rate bond fill in some coupon rates.");
                        break;
                    case SecCategories.VirtualFund:
                        secDetails.TradingAccountNumber = txtTradingAccountNumber.Text;
                        secDetails.HoldingAccountNumber = txtHoldingAccountNumber.Text;
                        secDetails.InitialNavPerUnit = dbInitailNAVperUnit.Value;
                        secDetails.ExactJournalNumber = dbExactJournalNumber.Text;
                        secDetails.JournalNumber = dbJournalNumber.Text;
                        secDetails.JournalDescription = txtJournalDescription.Text;
                        break;
                }

                secDetails.DefaultCounterpartyID = Utility.GetKeyFromDropDownList(ddlDefaultCounterparty);
                secDetails.DefaultSettlementPeriod = Convert.ToInt16(dbDefaultSettlementPeriod.Value);
                secDetails.NumberOfDecimals = Convert.ToByte(dbNumberOfDecimals.Value);
                secDetails.TickSize = dbTickSize.Value;
                secDetails.DoesSupportAmountBasedBuy = chkDoesSupportAmountBasedBuy.Checked;
                secDetails.DoesSupportAmountBasedSell = chkDoesSupportAmountBasedSell.Checked;
                secDetails.DoesSupportServiceCharge = chkDoesSupportServiceCharge.Checked;
                secDetails.ServiceChargePercentageBuy = dbServiceChargePercentageBuy.Value;
                secDetails.ServiceChargePercentageSell = dbServiceChargePercentageSell.Value;
                secDetails.RegisteredInNameof = tbRegisteredInNameof.Text;
                secDetails.DividendPolicy = tbDividendPolicy.Text;
                secDetails.CommissionRecipientName = tbCommissionRecipientName.Text;
                secDetails.CertificationRequired = chkCertificationRequired.Checked;

                InstrumentEditAdapter.SaveSecurity(ref instrumentID, ref blnSaveSuccess, secDetails);

                if (InstrumentToConvertID != 0)
                {
                    string qStr = QueryStringModule.Encrypt(string.Format("InstrumentToConvertID={0}&NewInstrumentID={1}&Edit={2}",
                        InstrumentToConvertID,
                        instrumentID,
                        false));
                    Response.Redirect(string.Format("~/BackOffice/CorporateActions/InstrumentConversionDetails.aspx{0}", qStr));
                }
                else
                {
                    Session["instrumentid"] = instrumentID;
                    Response.Redirect("Security.aspx");
                }
            }
        }
        catch (Exception ex)
        {
            elbErrorMessage.Text = Utility.GetCompleteExceptionMessage(ex) + "<br />";
        }
    }
Пример #3
0
        public static SecurityDetails GetSecurityDetails(int instrumentId)
        {
            IDalSession session = NHSessionFactory.CreateSession();
            ISecurityInstrument sec = (ISecurityInstrument)InstrumentMapper.GetTradeableInstrument(session, instrumentId);
            SecurityDetails returnValue = new SecurityDetails();

            if (sec != null)
            {
                returnValue.Key = sec.Key;
                returnValue.SecCategory = sec.SecCategory.Key;
                returnValue.InstrumentName = sec.Name;
                returnValue.ISIN = sec.Isin;
                returnValue.CompanyName = sec.CompanyName;
                returnValue.IssueDate = sec.IssueDate;
                if (sec.HomeExchange != null)
                    returnValue.HomeExchangeID = sec.HomeExchange.Key;
                if (sec.DefaultExchange != null)
                    returnValue.DefaultExchangeID = sec.DefaultExchange.Key;
                if (sec.DefaultRoute != null)
                    returnValue.RouteID = sec.DefaultRoute.Key;
                if (sec.Country != null)
                    returnValue.CountryID = sec.Country.Key;
                if (sec.CurrencyNominal != null)
                {
                    returnValue.NominalCurrencyID = sec.CurrencyNominal.Key;
                    returnValue.IsCurrencyActive = sec.CurrencyNominal.IsActive;
                }
                returnValue.DecimalPlaces = sec.DecimalPlaces;
                returnValue.IsGreenFund = sec.IsGreenFund;
                returnValue.IsCultureFund = sec.IsCultureFund;
                returnValue.AllowNetting = sec.AllowNetting;
                returnValue.PriceType = sec.PriceType;
                if (sec.ParentInstrument != null)
                    returnValue.ParentInstrumentName = sec.ParentInstrument.DisplayNameWithIsin;
                returnValue.InActiveDate = sec.InActiveDate;
                returnValue.IsActive = sec.IsActive;

                IInstrumentExchange ie = sec.InstrumentExchanges.GetDefault() ?? sec.InstrumentExchanges.FirstOrDefault();
                if (ie != null)
                {
                    returnValue.NumberOfDecimals = ie.NumberOfDecimals;
                    returnValue.DefaultSettlementPeriod = ie.DefaultSettlementPeriod;
                    returnValue.CertificationRequired = ie.CertificationRequired;
                    returnValue.DoesSupportAmountBasedBuy = ie.DoesSupportAmountBasedBuy;
                    returnValue.DoesSupportAmountBasedSell = ie.DoesSupportAmountBasedSell;
                    returnValue.DoesSupportServiceCharge = ie.DoesSupportServiceCharge;
                    returnValue.RegisteredInNameof = ie.RegisteredInNameOf;
                    returnValue.DividendPolicy = ie.DividendPolicy;
                    returnValue.CommissionRecipientName = ie.CommissionRecipientName;
                    returnValue.ServiceChargePercentageBuy = ie.ServiceChargePercentageBuy;
                    returnValue.ServiceChargePercentageSell = ie.ServiceChargePercentageSell;
                    returnValue.TickSize = ie.TickSize;
                    if (ie.DefaultCounterParty != null)
                        returnValue.DefaultCounterpartyID = ie.DefaultCounterParty.Key;
                }

                switch (sec.SecCategory.Key)
                {
                    case SecCategories.Bond:
                        IBond bond = sec as IBond;
                        if (bond != null)
                        {
                            if (bond.NominalValue != null)
                                returnValue.NominalValue = bond.NominalValue.Quantity;
                            returnValue.CouponRate = bond.CouponRate;
                            returnValue.CouponFreq = bond.CouponFreq;
                            returnValue.MaturityDate = bond.MaturityDate;
                            returnValue.FirstCouponPaymntDate = bond.FirstCouponPaymntDate;
                            returnValue.AccruedInterestCalcType = bond.AccruedInterestCalcType;
                            if (bond.RedemptionAmount != null)
                                returnValue.RedemptionAmount = bond.RedemptionAmount.Quantity;
                            returnValue.IsPerpetual = bond.IsPerpetual;
                            returnValue.UltimoDating = bond.UltimoDating;
                            returnValue.IsFixedCouponRate = bond.IsFixedCouponRate;
                        }
                        break;
                    case SecCategories.VirtualFund:
                        IVirtualFund vf = sec as IVirtualFund;
                        if (vf != null)
                        {
                            if (vf.TradingAccount != null)
                                returnValue.TradingAccountNumber = vf.TradingAccount.Number;
                            if (vf.HoldingsAccount != null)
                                returnValue.HoldingAccountNumber = vf.HoldingsAccount.Number;
                            if (vf.InitialNavPerUnit != null && vf.InitialNavPerUnit.IsNotZero)
                                returnValue.InitialNavPerUnit = vf.InitialNavPerUnit.Quantity;
                            if (vf.JournalForFund != null)
                            {
                                returnValue.JournalNumber = vf.JournalForFund.JournalNumber;
                                returnValue.JournalDescription = vf.JournalForFund.BankAccountDescription;
                                //returnValue.ExactJournalNumber = vf.JournalForFund.ExactJournal;
                            }
                        }
                        break;
                }
            }
            session.Close();
            return returnValue;
        }