Ejemplo n.º 1
0
        private void updateTimer_Tick(object sender, EventArgs e)
        {
            /* DOCSTRING
             *
             * updateTimer_Tick: private MainWindow -> void
             * parameters:
             *      - sender and e.
             * returns:
             *      - void
             * exceptions:
             *      - To be handled by the exception handler.
             * objective/operatory:
             *      -    The objective of the function that is called every time a timer 'ticks'
             *           with a pre-established interval, is to update the database with
             *           real-time data from the stock market. After that, it also must
             *           update the program UI with said data.
             *
             *          The operatory consists of creating an instance of a Data class and calling
             *          the Update method to update its values. After this we create a stockWindow
             *          that will be not null if a wpfShowStock is active and call an update method
             *          to update its values. The same is done for the current mainWindow WPF.
             */

            Entities.Data database = new Entities.Data();

            try
            {
                // Update database.
                database.Update();

                var stockWindow = System.Windows.Application.Current.Windows.OfType <wpfShowStock>().SingleOrDefault(w => w.IsActive);

                // this.UpdateData(database);

                // Sanity check
                if (stockWindow != null)
                {
                    // Update data from stock window in real time :p
                    stockWindow.UpdateUI(database);
                }

                // Also update current wpf
                this.UpdateUI(sender, e);
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Deleta uma Data
        /// throws BusinessData.BusinessLogic.DataAccess.DataAccessExceptiom
        /// </summary>
        /// <param name="id"></param>
        public void DeletaData(Guid calendarioId, Entities.Data data)
        {
            DbCommand cmd = baseDados.GetStoredProcCommand("DatasSemestreRemove");

            baseDados.AddInParameter(cmd, "@CalendarioId", DbType.Guid, calendarioId);
            baseDados.AddInParameter(cmd, "@Data", DbType.DateTime, data.Date);
            try
            {
                baseDados.ExecuteNonQuery(cmd);
            }
            catch (SqlException ex)
            {
                throw new DataAccessException(ErroMessages.GetErrorMessage(ex.Number), ex);
            }
        }
Ejemplo n.º 3
0
        private void dataGridFill(object sender, EventArgs e)
        {
            // Add data from database at initialization and after every update happens.
            Entities.Data database = new Entities.Data();
            try
            {
                // Get portfolio in a dataTable.
                this.CurrentData = database.GetPortfolio();

                // Fill datagrid
                dgPortfolio.DataContext = this.CurrentData.DefaultView;
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 4
0
 public void InsereData(Entities.Data data, Entities.Calendario cal)
 {
     if (usr.IsAdmin())
     {
         try
         {
             dao.InsereData(data, cal.Id);
         }
         catch (DataAccess.DataAccessException)
         {
             throw;
         }
     }
     else
     {
         throw new SecurityException("Acesso Negado.");
     }
 }
Ejemplo n.º 5
0
 public void DeletaData(Guid id, Entities.Data data)
 {
     if (usr.IsAdmin())
     {
         try
         {
             dao.DeletaData(id, data);
         }
         catch (DataAccess.DataAccessException)
         {
             throw;
         }
     }
     else
     {
         throw new SecurityException("Acesso Negado.");
     }
 }
Ejemplo n.º 6
0
        private void StoreData(JArray array, Layer layer)
        {
            List <Entities.Data> data = new List <Entities.Data>();

            foreach (var item in array)
            {
                Entities.Data d = new Entities.Data
                {
                    Id     = Guid.NewGuid(),
                    Layer  = layer,
                    Values = JObject.Parse(item.ToString())
                };
                data.Add(d);
            }

            using (var access = new DataAccess())
            {
                access.Data.BulkInsert(data);
            }
        }
Ejemplo n.º 7
0
        public void AddData(string buffer, string sourceType)
        {
            if (sourceType == Config.Configuration.dataSourceGoogleName)
            {
                JSONFormat jsonHandler = new JSONFormat();

                jsonHandler.Add(buffer);
                Dictionary <string, string> dictData = jsonHandler.DumpDataAsDictionary(sourceType);

                /* dictData:
                 * t : value_title (this plus e is the stock name)
                 * e : value_name (idem with t)
                 * l_fix : value_last
                 * ltt : value_time
                 * lt_dts : value_date (until character T is reached)
                 * c_fix : value_varday
                 * cp_fix : value_vardaypercent.
                 * pcls_fix : value_opening
                 */

                foreach (var keyValue in dictData)
                {
                    //MessageBox.Show("Key: " + keyValue.Key + ", Value: " + keyValue.Value);

                    // ParseValues(...) ?
                }

                Entities.Data database = new Entities.Data();

                // Name is the ticker's name.
                string ticker = dictData["e"] + ":" + dictData["t"];
                string name   = database.GetNamefromTicker(ticker);

                // Fill stock.
                this.Name           = name;
                this.Last           = Double.Parse(dictData["lfix"], System.Globalization.NumberStyles.AllowDecimalPoint);
                this.Var_day        = Double.Parse(dictData["cfix"]);
                this.Var_dayPorcent = Double.Parse(dictData["cpfix"]);
                this.Opening        = Double.Parse(dictData["pclsfix"], System.Globalization.NumberStyles.AllowDecimalPoint);
            }
        }
Ejemplo n.º 8
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            Entities.Data database = new Entities.Data();

            try
            {
                // Add to database
                database.Add(this.CurrentDisplayedStock);

                // Update current WPF current data (in other windows the update will come automatically
                // once the interval auto-update comes in.
                this.CurrentData = database.GetPortfolio();

                // Button disable.
                this.btnAddInitialize(this.CurrentDisplayedStock);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 9
0
        public void UpdateUI(Entities.Data database)
        {
            List <string> listData = database.ListData;

            Entities.Stock stock = new Entities.Stock();
            int            i     = 0;

            // Go through names in portfolio.. (this goes in ORDER!!)
            foreach (var name in database.ListNames)
            {
                // If name is the same as the current name displayed, it needs updating.
                if (this.lblName.Content.ToString().ToUpper() == name.ToUpper())
                {
                    // We can enter the listData because names and data is correlated
                    // pos[n] in listNames = pos[n] in listData
                    stock.AddData(database.ListData[i], Config.Configuration.dataSourceCurrent);
                    this.UpdateCurrentDisplayedStock(stock);
                }

                // Update counter.
                i++;
            }
        }
Ejemplo n.º 10
0
        public MainWindow()
        {
            /* DOCSTRING
             *
             * MainWindow() -> Constructor
             * parameters:
             *      - None
             * returns:
             *      - void
             * exceptions:
             *      - None
             * objective/operatory:
             *      -   Initialize MainWindow
             */

            InitializeComponent();

            Entities.Data database = new Entities.Data();

            database.Update();
            this.CurrentData        = database.GetPortfolio();
            dgPortfolio.DataContext = CurrentData.DefaultView;
        }
Ejemplo n.º 11
0
 public LoaiDAO()
 {
     data = new Entities.Data();
 }
Ejemplo n.º 12
0
        private void btnFindStock_Click(object sender, RoutedEventArgs e)
        {
            /* DOCSTRING
             *
             * btnFindStock_Click: private MainWindow -> void (Raised by Event Click)
             * parameters:
             *      - sender, e
             * returns:
             *      - void
             * exceptions:
             *      - Exceptions are handled by the exception handler.
             * objective/operatory:
             *      -    The objective of the function is to find a desired stock in the
             *           market, as long as the information to retreive this data is
             *           available in the program's database. The function must also
             *           manage what WPF should be created to display the found data
             *           depending on the information found.
             *
             *           The operatory consists in creating a Data instance and calling
             *           the Find method. If any information was found it wil be in a
             *           property called ListData in the database instance.
             *           It then adds into a list of stocks: the current data retreived
             *           and manages this information to show different WPF depending
             *           on how many stocks were found.
             *
             *           //TODO:
             *               In the property CurrentData the current Portfolio is stored,
             *               thus when calling find we should check if the data is in the
             *               portfolio before looking it up in the website because the data
             *               in the portfolio is already to be used in the CurrentData
             *               property (a DataTable) whilst the website information must be
             *               retreived in real-time.
             */


            // Code to find a stock (ANY) in the market.
            string stockStr = txbStock.Text.ToString();

            System.Windows.MessageBox.Show(stockStr);

            List <Entities.Stock> listStocks = new List <Entities.Stock>();

            Entities.Data database = new Entities.Data();

            // Try to find stock in web.
            try
            {
                // Stock data will be stored in a property in the database instance created.
                database.Find(stockStr, Config.Configuration.findMethodSimilar, true);

                if (database.ListData.Any())
                {
                    // There may be multiple "similar" stocks (e.g PAMP ADR, PAMP BCBA or substring of n strings
                    // e.g PAMP can be PAMPA ENERGIA or PETROLERA PAMPA).
                    for (int i = 0; i < database.ListData.Count; i++)
                    {
                        listStocks.Add(new Entities.Stock());
                        listStocks[i].AddData(database.ListData[i], Configuration.dataSourceCurrent);
                    }

                    if (listStocks.Count == 1)
                    {
                        // One stock found.
                        wpfShowStock wpfStock = new wpfShowStock(listStocks[0], this.CurrentData);
                        wpfStock.CurrentData = this.CurrentData;
                        wpfStock.Show();
                    }
                    else
                    {
                        // Multiple stocks found
                        System.Windows.MessageBox.Show("Please be more precise.", "Information", MessageBoxButton.OK, MessageBoxImage.Asterisk);

                        // TODO: Intermediate WPF to choose one of the found stocks and then open a wpfShowStock.
                    }
                }
                else
                {
                    // Either stock was found in the web (thus listData count is 0) or there is no data to show.
                    if (database.StockFoundInPortfolio.Rows.Count > 0)
                    {
                        // Load stock found as dataTable in a stock instance.
                        Entities.Stock stock = new Entities.Stock();
                        stock.AddData(database.StockFoundInPortfolio);

                        // Show stock
                        wpfShowStock wpfStock = new wpfShowStock(stock, this.CurrentData);
                        wpfStock.CurrentData = this.CurrentData;
                        wpfStock.Show();
                    }
                    else
                    {
                        System.Windows.MessageBox.Show("No information was found", "Information", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    }
                }
            }

            catch (Exception Ex)
            {
                System.Windows.MessageBox.Show(Ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 13
0
 public NhanHieuDAO()
 {
     data = new Entities.Data();
 }
Ejemplo n.º 14
0
        public ActionResult Copy([Bind(Include = "Id")] CopyMapViewModel model)
        {
            var newMapId = Guid.NewGuid();

            try
            {
                if (ModelState.IsValid)
                {
                    using (var access = new DataAccess())
                    {
                        var map = access.Maps.Get(m => m.Id == model.Id, includeProperties: "Layers,Layers.Columns,Layers.Data").SingleOrDefault();
                        if (map == null || !map.IsPublic)
                        {
                            logger.ErrorFormat("NOT_FOUND -- Map with id={0} not found.", model.Id);

                            ModelState.AddModelError("", Error.NOT_FOUND);
                        }
                        else
                        {
                            var userId = User.Identity.GetUser().Id;
                            var user   = access.Users.GetByID(userId);
                            if (user == null)
                            {
                                logger.ErrorFormat("NOT_FOUND -- User with id={0} not found.", userId);

                                ModelState.AddModelError("", Error.NOT_FOUND);
                            }
                            else
                            {
                                Map newMap = new Map()
                                {
                                    Id           = newMapId,
                                    CreationTime = DateTime.UtcNow,
                                    Name         = string.Concat("map", newMapId),
                                    User         = user,
                                };
                                access.Maps.Insert(newMap);

                                logger.InfoFormat("UserId={0} -- copy map object from map with id={1} to map with id={2}",
                                                  User.Identity.GetUser().Id, map.Id, newMapId);;

                                foreach (var layer in map.Layers)
                                {
                                    Layer newLayer = new Layer()
                                    {
                                        Id              = Guid.NewGuid(),
                                        Map             = newMap,
                                        HasColumns      = layer.HasColumns,
                                        HasData         = layer.HasData,
                                        IsVisible       = layer.IsVisible,
                                        Name            = layer.Name,
                                        Icon            = layer.Icon,
                                        Center_         = layer.Center_,
                                        IsFilterVisible = layer.IsFilterVisible
                                    };
                                    access.Layers.Insert(newLayer);
                                    foreach (var column in layer.Columns)
                                    {
                                        Column newColumn = new Column()
                                        {
                                            Id              = Guid.NewGuid(),
                                            DataType        = column.DataType,
                                            HasChart        = column.HasChart,
                                            Layer           = newLayer,
                                            Name            = column.Name,
                                            Filter_         = column.Filter_,
                                            Chart_          = column.Chart_,
                                            IsFilterVisible = column.IsFilterVisible,
                                        };
                                        access.Columns.Insert(newColumn);
                                    }

                                    access.Save();

                                    logger.InfoFormat("UserId={0} -- copy layer with id={1} with columns from map with id={2} to map with id={3}",
                                                      User.Identity.GetUser().Id, layer.Id, map.Id, newMapId);

                                    var dataList = new List <Entities.Data>();
                                    foreach (var data in layer.Data)
                                    {
                                        Entities.Data newData = new Entities.Data()
                                        {
                                            Id      = Guid.NewGuid(),
                                            Layer   = newLayer,
                                            Values_ = data.Values_,
                                        };
                                        dataList.Add(newData);
                                    }

                                    access.Data.BulkInsert(dataList);
                                    access.Save();

                                    logger.InfoFormat("UserId={0} -- copy data from layer with id={1} to layer with id={2}",
                                                      User.Identity.GetUser().Id, layer.Id, newLayer.Id);
                                }

                                ModelState.AddModelError("", "Successful copy!");
                                return(PartialView(model));
                            }
                        }
                    }
                }
                else
                {
                    logger.ErrorFormat("UserId={0} -- Model state is invalid", User.Identity.GetUser().Id);
                }
            }
            catch (Exception ex)
            {
                logger.Fatal("", ex);
                ModelState.AddModelError("", Error.ERROR);
                try
                {
                    using (var access = new DataAccess())
                    {
                        logger.InfoFormat("UserId={0} -- Delete new map with id={1} after failure", newMapId);

                        access.Maps.Delete(newMapId);
                    }
                }
                catch (Exception exc)
                {
                    logger.Fatal("", exc);
                    ModelState.AddModelError("", Error.ERROR);
                }
            }

            return(PartialView(model));
        }