コード例 #1
0
ファイル: Turbo.aspx.cs プロジェクト: kiquenet/B4F
    protected void bntSave_Click(object sender, EventArgs e)
    {
        try
        {
            Page.Validate();
            bool valid = Page.IsValid;
            int instrumentID = InstrumentID;
            bool blnSaveSuccess = false;

            if (valid)
            {
                TurboDetails turboDetails = new TurboDetails();

                turboDetails.DerivativeMasterID = DerivativeMasterID;
                turboDetails.InstrumentName = tbDerivativeName.Text;
                turboDetails.ISIN = tbISIN.Text;
                turboDetails.Sign = (B4F.TotalGiro.Accounts.Portfolios.IsLong)Convert.ToInt32(rblSign.SelectedValue);
                turboDetails.StopLoss = dbStopLoss.Value;
                turboDetails.Leverage = dbLeverage.Value;
                turboDetails.FinanceLevel = dbFinanceLevel.Value;
                turboDetails.Ratio = Convert.ToInt16(dbRatio.Value);

                InstrumentEditAdapter.SaveTurbo(ref instrumentID, ref blnSaveSuccess, turboDetails);
                Session["instrumentid"] = instrumentID;
                Response.Redirect("Turbo.aspx");
            }
        }
        catch (Exception ex)
        {
            elbErrorMessage.Text = Utility.GetCompleteExceptionMessage(ex) + "<br />";
        }
    }
コード例 #2
0
ファイル: InstrumentEditAdapter.cs プロジェクト: kiquenet/B4F
        public static void SaveTurbo(ref int instrumentID, ref bool blnSaveSuccess, TurboDetails turboDetails)
        {
            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
            {
                Turbo turbo = null;
                if (instrumentID != 0)
                    turbo = (Turbo)InstrumentMapper.GetTradeableInstrument(session, instrumentID);
                else
                {
                    IDerivativeMaster master = session.GetTypedList<DerivativeMaster, IDerivativeMaster>(turboDetails.DerivativeMasterID).FirstOrDefault();
                    if (master == null)
                        throw new ApplicationException("The derivative master is mandatory.");
                    turbo = new Turbo(master);
                }

                if (turbo == null)
                    throw new ApplicationException("The instrument could not be found.");

                if (turbo.Master == null)
                    throw new ApplicationException("The turbo needs a master.");

                if (instrumentID == 0 && turbo.Master.Series != null && turbo.Master.Series.Count > 0)
                {
                    if ((from a in turbo.Master.Series.Cast<ITurbo>()
                         where a.StopLoss.Quantity == turboDetails.StopLoss
                         && a.Sign == turboDetails.Sign
                         select a).Count() > 0)
                        throw new ApplicationException("This turbo already exists");
                }

                turbo.Name = turboDetails.InstrumentName;
                turbo.Isin = turboDetails.ISIN;
                turbo.Sign = turboDetails.Sign;
                turbo.StopLoss = new Price(turboDetails.StopLoss, turbo.CurrencyNominal, turbo);
                turbo.Leverage = turboDetails.Leverage;
                turbo.FinanceLevel = turboDetails.FinanceLevel;
                turbo.Ratio = turboDetails.Ratio;

                if (turbo.Validate())
                {
                    blnSaveSuccess = InstrumentMapper.Update(session, turbo);
                    instrumentID = turbo.Key;
                }
            }
            finally
            {
                session.Close();
            }
        }
コード例 #3
0
ファイル: InstrumentEditAdapter.cs プロジェクト: kiquenet/B4F
        public static TurboDetails GetTurboDetails(int instrumentId)
        {
            IDalSession session = NHSessionFactory.CreateSession();
            ITurbo turbo = (ITurbo)InstrumentMapper.GetTradeableInstrument(session, instrumentId);
            TurboDetails returnValue = new TurboDetails();

            if (turbo != null)
            {
                returnValue.Key = turbo.Key;
                returnValue.InstrumentName = turbo.Name;
                returnValue.ISIN = turbo.Isin;
                returnValue.DerivativeMasterID = turbo.Master.Key;
                returnValue.Sign = turbo.Sign;

                if (turbo.StopLoss != null && turbo.StopLoss.IsNotZero)
                    returnValue.StopLoss = turbo.StopLoss.Quantity;
                returnValue.Leverage = turbo.Leverage;
                returnValue.FinanceLevel = turbo.FinanceLevel;
                returnValue.Ratio = turbo.Ratio;
            }
            session.Close();
            return returnValue;
        }