예제 #1
0
        private void HomePageForm_AccountUpdate()
        {
            if (Broker.Instance.IsSignedIn())
            {
                Broker.Instance.GetAccountInfo((account) =>
                {
                    // Set the account buying power
                    BeginInvoke((Action)(() => {
                        CashLabel.Text = string.Format("{0:c}", account.TotalValue);
                        decimal open = 1;
                        decimal current = account.TotalValue;
                        decimal delta = current - open;
                        ChangeLabel.Text = string.Format("{0}{1:c} ({2:P2})", (delta >= 0) ? "+" : "-", delta, (delta / open));

                        SummaryTotalLabel.Text = string.Format("Total\n{0:c}", current);
                        SummaryBuyingPowerLabel.Text = string.Format("Buying Power\n{0:c}", account.BuyingPower);
                    }));

                    // Set the list of positions
                    Dictionary <string, decimal> positions = Broker.Instance.GetPositions();
                    StockListHome.Clear(StockList.POSITIONS);
                    foreach (KeyValuePair <string, decimal> pair in positions)
                    {
                        StockListHome.Add(StockList.POSITIONS, pair.Key, new StockList.PositionChangeSummary(DataAccessor.Subscribe(pair.Key, DataAccessor.SUBSCRIBE_FIVE_SEC)));
                    }
                });
            }
        }
예제 #2
0
        /// <summary>
        /// 添加库存
        /// </summary>
        /// <param name="trackid"></param>
        /// <param name="goodid"></param>
        /// <param name="transid"></param>
        public uint AddStock(uint tile_id, uint trackid, uint goodid, byte fullqty, DateTime?producetime = null)
        {
            if (Monitor.TryEnter(_go, TimeSpan.FromSeconds(2)))
            {
                try
                {
                    uint   newid     = PubMaster.Dic.GenerateID(DicTag.NewStockId);
                    byte   stack     = PubMaster.Goods.GetGoodStack(goodid);
                    ushort allpieces = (ushort)(stack * fullqty);
                    Track  track     = PubMaster.Track.GetTrack(trackid);
                    Stock  stock     = new Stock()
                    {
                        id            = newid,
                        track_id      = trackid,
                        goods_id      = goodid,
                        produce_time  = producetime ?? DateTime.Now,
                        stack         = stack,
                        pieces        = allpieces, //总片数
                        tilelifter_id = tile_id,
                        area          = track.area,
                        track_type    = track.type
                    };

                    UpdateTrackPos(stock);
                    StockList.Add(stock);
                    PubMaster.Mod.GoodSql.AddStock(stock);
                    return(newid);
                }
                finally
                {
                    Monitor.Exit(_go);
                }
            }
            return(0);
        }
예제 #3
0
        private void _NewStockViewModel_TabClosed(object sender, EventArgs e)
        {
            StockList.Clear();
            switch (TransactionObject.TransactionType)
            {
            case TransactionType.Purchase:
                PurchaseOBJ.UpdateCurrentObject();
                foreach (var item in PurchaseOBJ.LinkedStock)
                {
                    StockList.Add(item);
                }

                break;

            case TransactionType.Sale:
                PurchaseOBJ.UpdateCurrentObject();
                foreach (var item in SaleOBJ.StockList)
                {
                    StockList.Add(item);
                }
                break;

                //  case TransactionType.Refund:
            }
        }
 private void getStockListCallback(IEnumerable <string> stockList)
 {
     StockList.Clear();
     foreach (string s in stockList)
     {
         StockList.Add(s);
     }
 }
예제 #5
0
 /// <summary>
 /// 显示条码规则列表
 /// </summary>
 public void ShowStockTable()
 {
     foreach (var model in GetStockList())
     {
         StockList.Add(model);
     }
     ShowStockList();
 }
예제 #6
0
    public Stock AddStock(string symbol, string companyName, Industry industry)
    {
        Stock stock = new Stock(symbol, companyName, industry, this);

        StockList.Add(stock);
        stock.OnProcess += HandleStockProcessed;
        OnStockAdded(stock);
        return(stock);
    }
예제 #7
0
        private async Task Restore()
        {
            using (DataBaseHelper dbh = new DataBaseHelper())
            {
                if (this.IsVisible)
                {
                    var res = await dbh.GetStocks();

                    StockList.Clear();
                    foreach (var stock in res)
                    {
                        StockList.Add(stock);
                    }
                }
            }
        }
예제 #8
0
 private void RemoveStockFromSaleMethod()
 {
     try
     {
         if (SelectedStock != null && StockSaleList.Contains(SelectedStock))
         {
             TransactionDetails.Amount -= SelectedStock.SaleValue;
             StockList.Add(SelectedStock);
             StockSaleList.Remove(SelectedStock);
             SelectedStock = new skStock();
         }
     }
     catch (Exception E)
     {
         ExepionLogger.Logger.LogException(E);
         ExepionLogger.Logger.Show(E);
     }
 }
예제 #9
0
        private void LinkExtraStock()
        {
            switch (TransactionObject.TransactionType)
            {
            case TransactionType.Purchase:
                try
                {
                    Stocky.UI.Enviroment.LoadDialog("StockLingView", TransactionObject, "TRANLEDGEROBJ");
                    PurchaseOBJ.UpdateCurrentObject();
                    StockList.Clear();

                    foreach (var item in PurchaseOBJ.LinkedStock)
                    {
                        StockList.Add(item);
                    }
                }
                catch (Exception E)
                {
                    ExepionLogger.Logger.LogException(E);
                    ExepionLogger.Logger.Show(E);
                }
                break;

            case TransactionType.Sale:
                try
                {
                    Stocky.UI.Enviroment.LoadDialog("StockLingView", TransactionObject, "TRANLEDGEROBJ");
                    SaleOBJ.UpdateCurrentObject();
                    StockList.Clear();

                    foreach (var item in SaleOBJ.StockList)
                    {
                        StockList.Add(item);
                    }
                }
                catch (Exception E)
                {
                    ExepionLogger.Logger.LogException(E);
                    ExepionLogger.Logger.Show(E);
                }
                break;
            }
        }
예제 #10
0
 private void ClearStockFromSaleMethod()
 {
     try
     {
         if (StockSaleList.Count() > 0)
         {
             foreach (var item in StockSaleList)
             {
                 StockList.Add(item);
             }
             StockSaleList.Clear();
             TransactionDetails.Amount = 0;
         }
     }
     catch (Exception E)
     {
         ExepionLogger.Logger.LogException(E);
         ExepionLogger.Logger.Show(E);
     }
 }
예제 #11
0
        // Uses Firestore service for reading stocks available on the market
        public async Task <bool> ReadStocks()
        {
            var stocks = await FirestoreDatabase.RetrieveStock("");

            StockList.Clear();
            foreach (var s in stocks)
            {
                StockList.Add(s);
            }
            IsLoading = false;
            OnPropertyChanged("StockList");

            // No stocks on the market
            if (StockList.Count == 0)
            {
                ShowNoStocks = true;
                OnPropertyChanged("ShowNoStocks");
            }

            return(true);
        }
예제 #12
0
        /// <summary>
        /// Function To Pull Stock Data
        /// </summary>
        private void PullData()
        {
            StockList     stocklist  = new StockList();
            List <string> verifylist = new List <string>();

            lock (list)
            {
                foreach (string quote in list)
                {
                    Stock stock = new Stock(quote);
                    if (!verifylist.Contains(stock.Quote))
                    {
                        verifylist.Add(stock.Quote);

                        if (!string.IsNullOrEmpty(stock.Quote))
                        {
                            stocklist.Add(stock);
                        }
                    }
                }
            }
            currentDispatcher.Invoke(() => dg_StockList.ItemsSource = stocklist);
        }
예제 #13
0
        public HomePageForm()
        {
            InitializeComponent();
            this.FormClosing += HomePageForm_FormClosing;

            // Load the configuration
            this.Config = UserConfig.Load(UserConfig.CONFIG_FILE);

            // Create the interface to the stock data
            Robinhood = new RobinhoodInterface();
            DataAccessor.SetAccessor(new DataTableCache(Robinhood));
            Broker.SetBroker(Robinhood);

            if (String.IsNullOrEmpty(Config.DeviceToken))
            {
                Config.DeviceToken = Broker.Instance.GenerateDeviceToken();
                Config.Save(UserConfig.CONFIG_FILE);
            }

            UIList = new Panel();
            UIList.HorizontalScroll.Maximum = 0;
            UIList.AutoScroll             = false;
            UIList.VerticalScroll.Enabled = false;
            UIList.Resize += (sender, e) =>
            {
                foreach (Control c in UIList.Controls)
                {
                    c.Size = new Size(UIList.Width - 10, c.Height);
                }
            };
            UIList.ControlAdded   += UIList_Pack;
            UIList.ControlRemoved += UIList_Pack;
            UIList.Location        = new Point(340, 20);
            this.Controls.Add(UIList);

            UiScrollBar             = new CustomControls.CustomScrollbar();
            UiScrollBar.Minimum     = 0;
            UiScrollBar.Maximum     = UIList.Height;
            UiScrollBar.LargeChange = UiScrollBar.Maximum / UiScrollBar.Height;
            UiScrollBar.SmallChange = 15;
            UiScrollBar.Value       = 0;
            UiScrollBar.Scroll     += (sender, e) =>
            {
                //UIList.AutoScrollPosition = new Point(0, UiScrollBar.Value);
                UiScrollBar.Invalidate();
                //Application.DoEvents();
                UIList_Pack(sender, e);
            };
            UIList.Resize += (sender, e) =>
            {
                UiScrollBar.Bounds = new Rectangle(UIList.Right + 5, UIList.Top, 10, UIList.Height);
            };
            this.Controls.Add(UiScrollBar);

            // Create the account summary panel
            AccountSummaryPanel          = new Panel();
            AccountSummaryPanel.Location = new Point(50, 20);
            AccountSummaryPanel.Size     = new Size(270, 60);
            AccountSummaryPanel.Visible  = true;
            Controls.Add(AccountSummaryPanel);
            AccountSummaryPanel.Controls.Add(SummaryTotalLabel       = new Label());
            AccountSummaryPanel.Controls.Add(SummaryBuyingPowerLabel = new Label());
            int idx = 0;

            foreach (Label l in AccountSummaryPanel.Controls)
            {
                l.Size      = new Size(AccountSummaryPanel.Width / AccountSummaryPanel.Controls.Count, AccountSummaryPanel.Height);
                l.Location  = new Point(l.Width * idx++, 0);
                l.BackColor = GuiStyle.BACKGROUND_COLOR;
                l.ForeColor = GuiStyle.TEXT_COLOR;
                l.Font      = new Font(GuiStyle.Font.Name, 12, FontStyle.Bold);
                l.TextAlign = ContentAlignment.TopCenter;
            }
            UiUpdateTick       = new Timer();
            UiUpdateTick.Tick += (sender, e) =>
            {
                AccountSummaryPanel.Visible = AccountSummaryPanel.Bounds.Contains(PointToClient(MousePosition));
            };
            UiUpdateTick.Interval = 50;
            UiUpdateTick.Start();

            // Create the labels to show the account value and daily change
            CashLabel           = new Label();
            CashLabel.Location  = new Point(50, 20);
            CashLabel.Size      = new Size(270, 40);
            CashLabel.BackColor = GuiStyle.BACKGROUND_COLOR;
            CashLabel.ForeColor = GuiStyle.TEXT_COLOR;
            CashLabel.Font      = new Font(GuiStyle.Font.Name, 18, FontStyle.Bold);
            CashLabel.TextAlign = ContentAlignment.MiddleCenter;
            Controls.Add(CashLabel);
            ChangeLabel           = new Label();
            ChangeLabel.Location  = new Point(CashLabel.Location.X, CashLabel.Location.Y + CashLabel.Height);
            ChangeLabel.Size      = new Size(CashLabel.Size.Width, 20);
            ChangeLabel.BackColor = GuiStyle.BACKGROUND_COLOR;
            ChangeLabel.ForeColor = GuiStyle.TEXT_COLOR;
            ChangeLabel.Font      = new Font(GuiStyle.Font.Name, 8, FontStyle.Bold);
            ChangeLabel.TextAlign = ContentAlignment.MiddleCenter;
            Controls.Add(ChangeLabel);


            // Create the buy/sell menu
            BuySell          = new BuySellPanel();
            BuySell.Location = new Point(0, AccountSummaryPanel.Location.Y + AccountSummaryPanel.Height);
            BuySell.Size     = new Size(AccountSummaryPanel.Location.X + AccountSummaryPanel.Width, this.Height - BuySell.Location.Y);
            BuySell.Visible  = false;
            //BuySell.SubmitOrderButton.MouseClick += (sender, e) => {
            System.Threading.Tasks.Task orderMonitor = new Task((Action)(() =>
            {
                List <Broker.Order> orders;
                while ((orders = Broker.Instance.GetOrders()).Count > 0)
                {
                    // Check if the order gui matches the current state
                    List <StockList.StockLine> guiOrders = StockListHome.Stocks[StockList.ORDERS];
                    foreach (Broker.Order o in orders)
                    {
                        if (guiOrders.Find((a) => { return(a.Symbol.Equals(o.Symbol)); }) == null)
                        {
                            // Add the new order
                            StockListHome.Add(StockList.ORDERS, o.Symbol, new StockList.OrderSummary(o));
                        }
                    }

                    // Remove inactive orders from the GUI if needed
                    if (orders.Count < guiOrders.Count)
                    {
                        for (int i = 0; i < guiOrders.Count; i++)
                        {
                            if (orders.Find((a) => { return(a.Symbol.Equals(guiOrders[i].Symbol)); }) == null)
                            {
                                // Remove the order
                                guiOrders.RemoveAt(i--);
                            }
                        }
                    }

                    System.Threading.Thread.Sleep(250);
                }
            }));
            orderMonitor.Start();
            //};
            Controls.Add(BuySell);


            // Create the search box
            SearchHome                 = new SearchList();
            SearchHome.Size            = new Size(CashLabel.Width, 50);
            SearchHome.Location        = new Point(CashLabel.Location.X, ChangeLabel.Location.Y + ChangeLabel.Height);
            SearchHome.AutoSize        = true;
            SearchHome.AddToWatchlist += (string symbol) => { StockListHome.Add("Watchlist", symbol); };
            SearchHome.AddStockUi     += CreateStockChart;
            Controls.Add(SearchHome);

            // Create the list of stocks being examined
            StockListHome             = new StockList();
            StockListHome.Location    = new Point(SearchHome.Location.X, SearchHome.Location.Y + 100);
            StockListHome.Size        = new Size(300, 300);
            StockListHome.AddStockUi += CreateStockChart;
            StockListHome.GroupOrder  = new List <string>()
            {
                StockList.NOTIFICATIONS,
                StockList.ORDERS,
                StockList.POSITIONS,
                StockList.WATCHLIST
            };
            Controls.Add(StockListHome);

            // Create the menu
            Menu = new MenuBar(Config);
            Menu.ToggleButton.Location       = new Point(20, 20);
            Menu.LogIn.RememberLogIn.Checked = Config.RememberLogin;
            Menu.LogIn.LogInButton.MouseUp  += (sender, e) => {
                HomePageForm_AccountUpdate();
                if (Broker.Instance.IsSignedIn())
                {
                    SaveConfig();
                }
            };
            Controls.Add(Menu.ToggleButton);

            // Set up the resize handler
            this.ResizeEnd += HomePageForm_ResizeEnd;
            HomePageForm_ResizeEnd(this, EventArgs.Empty);

            // Sign in if authentification is available
            if (Config.RememberLogin && !string.IsNullOrEmpty(Config.AuthenticationToken))
            {
                Broker.Instance.SignIn(Config.AuthenticationToken);
            }

            // Wait to request stock data until after the window has been created
            this.HandleCreated += (sender, e) =>
            {
                foreach (var configObj in Config.StockCharts)
                {
                    CreateStockChart(StockChartPanel.LoadConfig(configObj));
                }
                foreach (string symbol in Config.LocalWatchlist)
                {
                    StockListHome.Add(StockList.WATCHLIST, symbol);
                }
                HomePageForm_AccountUpdate();
            };
        }
예제 #14
0
        public void AddStock(int quantity, double price, StockType stockType)
        {
            StockList.Add(StockFactory.GetStock(quantity, price, GetNextStockName(stockType), stockType));

            UpdateStockWeight();
        }