Esempio n. 1
0
    protected void bntSave_Click(object sender, EventArgs e)
    {
        try
        {
            Page.Validate();
            bool valid = Page.IsValid;
            int derivativeMasterID = DerivativeMasterID;
            bool blnSaveSuccess = false;

            if (valid)
            {
                DerivativeMasterDetails masterDetails = new DerivativeMasterDetails();

                masterDetails.Key = derivativeMasterID; ;
                masterDetails.SecCategory = SecCategory;
                masterDetails.ContractSize = Convert.ToInt32(dbContractSize.Value);
                masterDetails.DecimalPlaces = Convert.ToInt32(dbDecimalPlaces.Value);
                masterDetails.ExchangeID = Utility.GetKeyFromDropDownList(ddlExchange);
                masterDetails.Name = tbDerivativeMasterName.Text;
                masterDetails.Symbol = txtSymbol.Text;
                masterDetails.NominalCurrencyID = Utility.GetKeyFromDropDownList(ddCurrencyNominal);
                masterDetails.UnderlyingID = Utility.GetKeyFromDropDownList(ddlUnderlyingInstrument);
                masterDetails.UnderlyingSecCategory = (SecCategories)Utility.GetKeyFromDropDownList(ddlUnderlyingSecCategory);

                InstrumentEditAdapter.SaveDerivativeMaster(ref derivativeMasterID, ref blnSaveSuccess, masterDetails);
                Session["DerivativeMasterID"] = derivativeMasterID;
                Response.Redirect("DerivativeMaster.aspx");
            }
        }
        catch (Exception ex)
        {
            elbErrorMessage.Text = Utility.GetCompleteExceptionMessage(ex) + "<br />";
        }
    }
Esempio n. 2
0
        public static void SaveDerivativeMaster(ref int derivativeMasterId, ref bool blnSaveSuccess, DerivativeMasterDetails masterDetails)
        {
            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
            {
                DerivativeMaster master = null;
                IExchange exchange = null;
                if (masterDetails.ExchangeID != int.MinValue)
                    exchange = ExchangeMapper.GetExchange(session, masterDetails.ExchangeID);
                else
                    throw new ApplicationException("The default exchange is mandatory.");

                if (derivativeMasterId != 0)
                {
                    master = (DerivativeMaster)session.GetTypedList<DerivativeMaster, IDerivativeMaster>(derivativeMasterId).FirstOrDefault();
                    if (master == null)
                        throw new ApplicationException("The derivative master could not be found.");
                    master.Name = masterDetails.Name;
                    master.Exchange = exchange;
                }
                else
                    master = new DerivativeMaster(masterDetails.Name, masterDetails.SecCategory, exchange);

                master.ContractSize = masterDetails.ContractSize;
                master.DecimalPlaces = Convert.ToInt16(masterDetails.DecimalPlaces);
                master.UnderlyingSecCategory = masterDetails.UnderlyingSecCategory;
                master.DerivativeSymbol = masterDetails.Symbol;

                if (masterDetails.UnderlyingID != int.MinValue)
                    master.Underlying = InstrumentMapper.GetTradeableInstrument(session, masterDetails.UnderlyingID);
                else
                    master.Underlying = null;
                if (masterDetails.NominalCurrencyID != int.MinValue)
                    master.CurrencyNominal = InstrumentMapper.GetCurrency(session, masterDetails.NominalCurrencyID);
                else
                    master.CurrencyNominal = null;

                blnSaveSuccess = session.InsertOrUpdate(master);
                derivativeMasterId = master.Key;
            }
            finally
            {
                session.Close();
            }
        }
Esempio n. 3
0
        public static DerivativeMasterDetails GetDerivativeMasterDetails(int derivativeMasterId)
        {
            IDalSession session = NHSessionFactory.CreateSession();
            IDerivativeMaster master = session.GetTypedList<DerivativeMaster, IDerivativeMaster>(derivativeMasterId).FirstOrDefault();
            DerivativeMasterDetails returnValue = new DerivativeMasterDetails();

            if (master != null)
            {
                returnValue.Key = master.Key;
                returnValue.SecCategory = master.SecCategory;
                returnValue.Name = master.Name;
                returnValue.UnderlyingSecCategory = master.UnderlyingSecCategory;
                returnValue.ContractSize = master.ContractSize;
                returnValue.DecimalPlaces = master.DecimalPlaces;
                if (master.Exchange != null)
                    returnValue.ExchangeID = master.Exchange.Key;
                if (master.Underlying != null)
                    returnValue.UnderlyingID = master.Underlying.Key;
                if (master.CurrencyNominal != null)
                    returnValue.NominalCurrencyID = master.CurrencyNominal.Key;
                returnValue.Symbol = master.DerivativeSymbol;
            }
            session.Close();
            return returnValue;
        }