Пример #1
0
        public static cSecurity CheckLogin(string user, string pass)
        {
            List <ParamStruct> paramList = new List <ParamStruct>();

            ParamStruct param0 = new ParamStruct("@userName", user, DbType.String, 8, ParameterDirection.Input);

            paramList.Add(param0);
            ParamStruct param1 = new ParamStruct("@password", pass, DbType.String, 8, ParameterDirection.Input);

            paramList.Add(param1);

            string sproc = "checkLogin";

            DbDataReader valid       = DAL.DAL.ReadData(sproc, paramList);
            cSecurity    currentUser = Repackage(valid);

            if (currentUser.Name == null)
            {
                throw new Exception("Access Denied");
            }
            else
            {
                return(currentUser);
            }
        }// end CheckLogin
Пример #2
0
        }//loadSecuritiesFromDb

        private void loadSecuritiesFromCollection(List <Entities.Sp.SecurityData> securities)
        { // Fills collection of securities from a given collection
            List <cSecurity> cFinalSecs = new List <cSecurity>();

            for (int iSecs = 0; iSecs < securities.Count; iSecs++)
            { // Goes through list of securities
                cSecurity cCurrSec = new cSecurity(m_objPortfolio, securities[iSecs].strName, securities[iSecs].strSymbol);
                cCurrSec.AvgYield    = securities[iSecs].avgYield;
                cCurrSec.AvgYieldNIS = securities[iSecs].avgYieldNIS;
                cCurrSec.DateRange   = new cDateRange((DateTime)m_objPortfolio.Details.StartDate, (DateTime)m_objPortfolio.Details.EndDate);
                cCurrSec.IdCurrency  = securities[iSecs].idCurrency;
                cCurrSec.Quantity    = securities[iSecs].flQuantity;
                cCurrSec.StdYield    = securities[iSecs].stdYield;
                cCurrSec.StdYieldNIS = securities[iSecs].stdYieldNIS;
                cCurrSec.Weight      = securities[iSecs].portSecWeight;
                cCurrSec.WeightNIS   = securities[iSecs].WeightNIS;
                cCurrSec.WeightUSA   = securities[iSecs].WeightUSA;

                cCurrSec.Properties.HebName        = securities[iSecs].strHebName;
                cCurrSec.Properties.PortSecurityId = securities[iSecs].idSecurity;
                cCurrSec.Properties.Market         = new cCategoryItem(enumCatType.StockMarket, securities[iSecs].marketName, securities[iSecs].idMarket, m_objErrorHandler, m_objPortfolio);
                cCurrSec.Properties.MarketName     = securities[iSecs].marketName;
                cCurrSec.Properties.Sector         = new cCategoryItem(enumCatType.Sector, securities[iSecs].sectorName, securities[iSecs].idSector, m_objErrorHandler, m_objPortfolio);
                cCurrSec.Properties.SecurityType   = new cCategoryItem(enumCatType.SecurityType, securities[iSecs].securityTypeName, securities[iSecs].idSecurityType, m_objErrorHandler, m_objPortfolio);

                cFinalSecs.Add(cCurrSec);
            }

            m_colFullCollection.Securities.AddRange(cFinalSecs);

            m_colSecurities.Securities.AddRange(cFinalSecs);
            //List<cSecurity> cFinalSecs = AutoMapper.Mapper.Map<List<cSecurity>>(securities);
        }//loadSecuritiesFromCollection
Пример #3
0
        private static cSecurity getCurrSecurity(Security security, IPortfolioBL cCurrPort)
        {                                                                                        // Retrieves an instance of a security based on its datarow info
            cSecurity cCurrSec = new cSecurity(cCurrPort, security.strName, security.strSymbol); //111An

            cCurrSec.Properties.PortSecurityId = security.idSecurity;

            //cCurrSec.Properties.HebName = security.HebName;

            //cCurrSec.FAC = Convert.ToDouble(security.FAC);

            if (cCurrSec.FAC <= 0D)
            {
                cCurrSec.FAC = 1D;
            }

            cCurrSec.AvgYield = security.AvgYield;
            cCurrSec.StdYield = security.StdYield;

            cCurrSec.AvgYieldNIS = security.AvgYieldNIS;
            cCurrSec.StdYieldNIS = security.StdYieldNIS;

            cCurrSec.ValueUSA = security.dValueUSA;
            cCurrSec.ValueNIS = security.dValueNIS;

            cCurrSec.WeightUSA = security.WeightUSA;
            cCurrSec.WeightNIS = security.WeightNIS;

            //cCurrSec.Properties.ISIN = security.strISIN;

            cCurrSec.DateRange = new cDateRange(security.dtPriceStart, security.dtPriceEnd);

            //lock (lockObject)
            //{
            cCurrSec.Properties.Sector = cColHandler.getCatItemByID(enumCatType.Sector, security.idSector,
                                                                    cColHandler.Sectors);

            cCurrSec.Properties.Market     = cColHandler.getCatItemByID(enumCatType.StockMarket, security.idMarket, cColHandler.Markets);
            cCurrSec.Properties.MarketName = getSecMarketName(security.idMarket);

            cCurrSec.Properties.SecurityType = cColHandler.getCatItemByID(enumCatType.SecurityType,
                                                                          security.idSecurityType, cColHandler.SecTypes);
            //}
            var priceRepository = Resolver.Resolve <IRepository>();

            try
            {
                priceRepository.Execute(session =>
                {
                    // cCurrSec.PriceTable = AutoMapper.Mapper.Map<List<Models.dbo.Price>>(session.Query<TFI.Entities.dbo.Price>().Where(x => x.Securities.idSecurity == security.idSecurity).OrderByDescending(x => x.dDate).ToList());
                });
            }
            catch (Exception ex)
            {
                //m_objErrorHandler.LogInfo(ex);
            }
            Resolver.Release(priceRepository);
            return(cCurrSec);
        }//getCurrSecurity
Пример #4
0
        }//getCategoryMatchingItems

        public Boolean isWithSecurity(cSecurity cCurrSec)
        { // Verifies the specified security is found within the collection
            for (int iSecs = 0; iSecs < m_colSecurities.Count; iSecs++)
            {
                if (m_colSecurities[iSecs].Properties.PortSecurityId == cCurrSec.Properties.PortSecurityId)
                {
                    return(true);
                }
            }
            return(false);
        }//isWithSecurity
Пример #5
0
        }//getArrOfWeights

        public int getSecurityPos(cSecurity cCurrSec)
        { // Retrieves the position of the security by its symbol
            //TODO: Don't we have to check also by MARKET ID????
            for (int iSecs = 0; iSecs < m_colExtSecurities.Count; iSecs++)
            {
                //if (m_colExtSecurities[iSecs].Symbol == cCurrSec.Properties.SecuritySymbol)
                if (m_colExtSecurities[iSecs].Symbol == cCurrSec.Properties.SecuritySymbol && m_colExtSecurities[iSecs].ExchangeId == cCurrSec.Properties.Market.ID)
                {
                    return(iSecs);
                }
            }
            return(-1);
        }//getSecurityPosBySymbol
Пример #6
0
        }// end CheckLogin

        private static cSecurity Repackage(IDataReader datareader)
        {
            using (datareader)
            {
                cSecurity user = new cSecurity();

                while (datareader.Read())
                {
                    user.Name   = (string)datareader["name"];
                    user.Access = (string)datareader["access"];
                }

                datareader.Close();
                return(user);
            }
        } // end Repackage
Пример #7
0
        public List <cSecurity> convertListToCSecurity(List <Security> colOrigSecs)
        { // Converts list of Security objects to a list of cSecurity objects
            List <cSecurity> colFinalSecs = new List <cSecurity>();

            //List<Models.dbo.Price> colPrices = getFullPrices();
            try
            {
                for (int iSecs = 0; iSecs < colOrigSecs.Count; iSecs++)
                {
                    cSecurity cCurrSec = getCurrSecurity(colOrigSecs[iSecs], m_objPortfolio);
                    if (cCurrSec != null)
                    {
                        colFinalSecs.Add(cCurrSec);
                    }
                }
            }
            catch (Exception ex)
            {
                m_objErrorHandler.LogInfo(ex);
            }
            return(colFinalSecs);
        }//convertListToCSecurity
Пример #8
0
        public Rate GetPrice(string secId, string currency, DateTime date)
        {
            List <cSecurity> lst;
            Rate             rate = new Rate();

            if (StaticData <cSecurity, ISecurities> .lst == null)
            {
                lst = new List <cSecurity>();
            }
            else
            {
                lst = StaticData <cSecurity, ISecurities> .lst;
            }

            cSecurity sec   = lst.FirstOrDefault(x => x.Properties.PortSecurityId == secId);
            Price     price = null;

            if (sec == null)
            {
                _repository.Execute(session =>
                {
                    price = session.Query <Price>().Where(x => x.idSecurity == secId && x.dDate <= date).FirstOrDefault();
                });
            }
            else
            {
                price = sec.PriceTable.Where(x => x.dDate <= date).FirstOrDefault();
            }
            if (price != null)
            {
                rate = new Rate {
                    Date = price.dDate, RateVal = (currency == "9001" ? price.fClose : price.fNISClose)
                }
            }
            ;
            return(rate);
        }
Пример #9
0
        }//clearCalcData

        #endregion Consturctors, Initialization & Destructor

        #region Methods

        #region Global datatable

        public Price getPriceReturn(string secId, string currency, DateTime date)
        {                                   // Retrieves a specific Price return data segment
            // INIT VARIABLES
            List <cSecurity> lstSecurities; // List of securities
            Price            pReturn = new Price();

            lstSecurities = (StaticData <cSecurity, ISecurities> .lst == null)? new List <cSecurity>(): StaticData <cSecurity, ISecurities> .lst; // New / Existing list of securities

            cSecurity currSec = lstSecurities.FirstOrDefault(x => x.Properties.PortSecurityId == secId);

            TFI.Entities.dbo.Price price = null;

            // GET SPECIFIC PRICE
            if (currSec == null)
            {                                                                                                                                                     // If Security isn't found in StaticData -> take price from repository
                _repository.Execute(session =>
                                    { price = session.Query <TFI.Entities.dbo.Price>().Where(x => x.idSecurity == secId && x.dDate <= date).FirstOrDefault(); }); // Get price from repository
            }
            else                                                                                                                                                  // Get price from StaticData
            {
                price = currSec.PriceTable.Where(x => x.dDate <= date).FirstOrDefault();
            }

            if (price != null)
            {
                pReturn = new Price {
                    dDate = price.dDate, dAdjRtn = (currency == "9001" ? price.fClose : price.fNISClose)
                }
            }
            ;
            return(pReturn);
        }//getPriceReturn

        #endregion Global datatable

        #endregion Methods
    }//of class
Пример #10
0
        }//getCurrSecurity

        private cSecurity getCurrBMSecurity_with_EntitySec(Entities.dbo.Security drSec, IPortfolioBL cCurrPort)
        { // Retrieves an instance of a security based on its datarow info
            ICollectionsHandler cColHandler = cCurrPort.ColHandler;

            cSecurity cCurrSec = new cSecurity(cCurrPort, drSec.strName, drSec.strSymbol);  //111An

            cCurrSec.Properties.PortSecurityId = drSec.idSecurity;

            cCurrSec.Properties.HebName = drSec.strHebName;
            cCurrSec.FAC = 1D;

            ////if (drSec["FAC"] != DBNull.Value) cCurrSec.FAC = Convert.ToDouble(drSec["FAC"]);
            ////else cCurrSec.FAC = 1D;
            ////if (cCurrSec.FAC <= 0D) cCurrSec.FAC = 1D;

            if (drSec.AvgYield.HasValue)
            {
                cCurrSec.AvgYield = Convert.ToDouble(drSec.AvgYield);
            }
            if (drSec.StdYield.HasValue)
            {
                cCurrSec.StdYield = Convert.ToDouble(drSec.StdYield);
            }

            if (drSec.AvgYieldNIS.HasValue)
            {
                cCurrSec.AvgYieldNIS = Convert.ToDouble(drSec.AvgYieldNIS);
            }
            if (drSec.StdYieldNIS.HasValue)
            {
                cCurrSec.StdYieldNIS = Convert.ToDouble(drSec.StdYieldNIS);
            }

            if (drSec.MonetaryAvg.HasValue)
            {
                cCurrSec.ValueUSA = Convert.ToDouble(drSec.MonetaryAvg);
            }
            if (drSec.MonetaryAvgNIS.HasValue)
            {
                cCurrSec.ValueNIS = Convert.ToDouble(drSec.MonetaryAvgNIS);
            }

            if (drSec.WeightUSA.HasValue)
            {
                cCurrSec.WeightUSA = Convert.ToDouble(drSec.WeightUSA);
            }
            if (drSec.WeightNIS.HasValue)
            {
                cCurrSec.WeightNIS = Convert.ToDouble(drSec.WeightNIS);
            }

            //cCurrSec.Properties.ISIN = drSec.strISIN;

            ////if ((drSec["dtPriceStart"] != DBNull.Value) && (drSec["dtPriceEnd"] != DBNull.Value))
            ////    cCurrSec.DateRange = new cDateRange(Convert.ToDateTime(drSec["dtPriceStart"]), Convert.ToDateTime(drSec["dtPriceEnd"]));
            cCurrSec.DateRange = new cDateRange(DateTime.Today.AddYears(-cProperties.DatesInterval), DateTime.Today.AddDays(-1));

            if (drSec.idSector.HasValue)
            {
                cCurrSec.Properties.Sector = cColHandler.getCatItemByID(enumCatType.Sector, Convert.ToInt32(drSec.idSector),
                                                                        cColHandler.Sectors);
            }
            if (drSec.idMarket.HasValue)
            { // Exchange values
                cCurrSec.Properties.Market     = cColHandler.getCatItemByID(enumCatType.StockMarket, drSec.idMarket.Value, cColHandler.Markets);
                cCurrSec.Properties.MarketName = getSecMarketName(drSec.idMarket.Value);
            }
            if (drSec.idSecurityType.HasValue)
            {
                cCurrSec.Properties.SecurityType = cColHandler.getCatItemByID(enumCatType.SecurityType,
                                                                              drSec.idSecurityType.Value, cColHandler.SecTypes);
            }

            //if (drSec["idCurrency"] != DBNull.Value) cCurrSec.IdCurrency = drSec["IdCurrency"].ToString();
            cCurrSec.IdCurrency = cProperties.CurrencyId;

            try
            { // Only exists in portfolio securities
              // For Benchmark we assign 'true'
              //if (drSec["isActiveSecurity"] != DBNull.Value) cCurrSec.setSecurityActivity(Convert.ToBoolean(drSec["isActiveSecurity"]));
              //else cCurrSec.setSecurityActivity(true);



                // LR: at this point security already has .PriceTable filled in, so commenting the line, because it crashes here
                //cCurrSec.PriceTable = drSec.Prices.ToList();

                //////foreach (var p in cCurrSec.PriceTable)
                //////{
                //////    p.dAdjPrice = p.fClose;
                //////}

                cCurrSec.setSecurityActivity(true);
            }
            catch (Exception ex)
            {
            }

            return(cCurrSec);
        }//getCurrSecurity
Пример #11
0
        }//getSecDatarowPosition

        #endregion Static methods

        #region Load Benchmarks from SQL Srv

        private cSecurity getCurrBMSecurity(BMsecurity drSec, IPortfolioBL cCurrPort)
        { // Retrieves an instance of a security based on its datarow info
            ICollectionsHandler cColHandler = cCurrPort.ColHandler;

            cSecurity cCurrSec = new cSecurity(cCurrPort, drSec.strName, drSec.strSymbol);  //111An

            cCurrSec.Properties.PortSecurityId = drSec.idSecurity;

            cCurrSec.Properties.HebName = drSec.strHebName;
            cCurrSec.FAC = 1D;

            cCurrSec.AvgYield = Convert.ToDouble(drSec.AvgYield);
            cCurrSec.StdYield = Convert.ToDouble(drSec.StdYield);

            cCurrSec.AvgYieldNIS = Convert.ToDouble(drSec.AvgYieldNIS);
            cCurrSec.StdYieldNIS = Convert.ToDouble(drSec.StdYieldNIS);

            //////cCurrSec.ValueUSA = Convert.ToDouble(drSec.dValueUSA);        // THEY ARE NULLS for BM sec
            //////cCurrSec.ValueNIS = Convert.ToDouble(drSec.dValueNIS);

            //////cCurrSec.WeightUSA = Convert.ToDouble(drSec.WeightUSA);
            //////cCurrSec.WeightNIS = Convert.ToDouble(drSec.WeightNIS);

            cCurrSec.DateRange = new cDateRange(DateTime.Today.AddYears(-cProperties.DatesInterval), DateTime.Today.AddDays(-1));
            lock (lockObject)
            {
                cCurrSec.Properties.Sector = cColHandler.getCatItemByID(enumCatType.Sector, Convert.ToInt32(drSec.idSector),
                                                                        cColHandler.Sectors);
                // Exchange values
                cCurrSec.Properties.Market     = cColHandler.getCatItemByID(enumCatType.StockMarket, drSec.idMarket, cColHandler.Markets);
                cCurrSec.Properties.MarketName = getSecMarketName(drSec.idMarket);

                cCurrSec.Properties.SecurityType = cColHandler.getCatItemByID(enumCatType.SecurityType,
                                                                              drSec.idSecurityType, cColHandler.SecTypes);
            }
            //if (drSec["idCurrency"] != DBNull.Value) cCurrSec.IdCurrency = drSec["IdCurrency"].ToString();
            cCurrSec.IdCurrency = drSec.idCurrency; // WHY WAS IT HERE????? cProperties.CurrencyId;

            try
            { // Only exists in portfolio securities
              // For Benchmark we assign 'true'
              //if (drSec["isActiveSecurity"] != DBNull.Value) cCurrSec.setSecurityActivity(Convert.ToBoolean(drSec["isActiveSecurity"]));
              //else cCurrSec.setSecurityActivity(true);


                // LR: at this point security already has .PriceTable filled in, so commenting the line, because it crashes here
                //cCurrSec.PriceTable = drSec.Prices.ToList();

                //////foreach (var p in cCurrSec.PriceTable)
                //////{
                //////    p.dAdjPrice = p.fClose;
                //////}

                cCurrSec.setSecurityActivity(true);
            }
            catch (Exception ex)
            {
            }

            //// Made separate entity for tbl_IndexPrices
            //var priceRepository = Resolver.Resolve<IRepository>();
            //List<Entities.dbo.BMPrice> laura;
            //try
            //{
            //    priceRepository.Execute(session =>
            //    {
            //        ////cCurrSec.PriceTable = AutoMapper.Mapper.Map<List<Entities.dbo.Price>>(session.Query<Entities.dbo.BMPrice>().Where(x => x.idSecurity == "'" + drSec.idSecurity + "'").OrderByDescending(x => x.dDate).ToList());
            //        laura = session.Query<Entities.dbo.BMPrice>().Where(x => x.idSecurity == "'" + drSec.idSecurity + "'").OrderByDescending(x => x.dDate).ToList();
            //    });
            //}
            //catch (Exception ex)
            //{
            //    m_objErrorHandler.LogInfo(ex);
            //}
            //Resolver.Release(priceRepository);

            return(cCurrSec);
        }//getCurrSecurity
Пример #12
0
        }//getCatItemByID

        #endregion Load from DB


        #region Static methods

        private cSecurity getCurrSecurity(Security security, IPortfolioBL cCurrPort)
        { // Retrieves an instance of a security based on its datarow info
            ICollectionsHandler cColHandler = cCurrPort.ColHandler;

            cSecurity cCurrSec = new cSecurity(cCurrPort, security.strName, security.strSymbol);//111An

            cCurrSec.Properties.PortSecurityId = security.idSecurity;

            cCurrSec.Properties.HebName = security.strHebName;

            //cCurrSec.FAC = Convert.ToDouble(security.FAC);

            if (cCurrSec.FAC <= 0D)
            {
                cCurrSec.FAC = 1D;
            }

            cCurrSec.AvgYield = security.AvgYield;       //* 52;
            cCurrSec.StdYield = security.StdYield;       // * Math.Sqrt(52);

            cCurrSec.AvgYieldNIS = security.AvgYieldNIS; // * 52;
            cCurrSec.StdYieldNIS = security.StdYieldNIS; // * Math.Sqrt(52);

            cCurrSec.ValueUSA = security.dValueUSA;
            cCurrSec.ValueNIS = security.dValueNIS;

            cCurrSec.WeightUSA = security.WeightUSA;
            cCurrSec.WeightNIS = security.WeightNIS;

            //cCurrSec.Properties.ISIN = security.strISIN;
            cCurrSec.IdCurrency = security.idCurrency;
            cCurrSec.DateRange  = new cDateRange(security.dtPriceStart, security.dtPriceEnd);
            cCurrSec.setSecurityActivity(true);

            lock (lockObject)
            {
                cCurrSec.Properties.Sector = cColHandler.getCatItemByID(enumCatType.Sector, security.idSector,
                                                                        cColHandler.Sectors);

                cCurrSec.Properties.Market     = cColHandler.getCatItemByID(enumCatType.StockMarket, security.idMarket, cColHandler.Markets);
                cCurrSec.Properties.MarketName = getSecMarketName(security.idMarket);

                cCurrSec.Properties.SecurityType = cColHandler.getCatItemByID(enumCatType.SecurityType,
                                                                              security.idSecurityType, cColHandler.SecTypes);
            }


            //var priceRepository = Resolver.Resolve<IRepository>();
            //try
            //{
            //    priceRepository.Execute(session =>
            //    {
            //        cCurrSec.PriceTable = session.Query<Entities.dbo.Price>().Where(x => x.idSecurity == security.idSecurity).ToList(); //.OrderByDescending(x => x.dDate)
            //    });
            //}
            //catch (Exception ex)
            //{
            //    m_objErrorHandler.LogInfo(ex);
            //}
            //Resolver.Release(priceRepository);


            //List<Models.dbo.Price> BMprices = getFullPrices();
            //cCurrSec.PriceTable = AutoMapper.Mapper.Map<List<Price>, List<Entities.dbo.Price>>(BMprices.Where(x => x.idSecurity == cCurrSec.Properties.PortSecurityId).OrderByDescending(x => x.dDate).ToList());


            return(cCurrSec);
        }//getCurrSecurity