Esempio n. 1
0
        public DailyGoldBalance AddDaily()
        {
            string date = DateUtils.GetTodaysDate();

            foreach (var entry in this.GoldBalanceView.Items)
            {
                if (entry is DailyGoldBalance e)
                {
                    if (e.Date == date)
                    {
                        return(e);
                    }
                }
            }
            var newDaily = new DailyGoldBalance();
            List <DailyGoldBalance> tempList = new List <DailyGoldBalance>(this.mainWindow.DailyGoldBalances)
            {
                newDaily
            };

            tempList = tempList.OrderByDescending(s => s.Date).ToList();
            this.mainWindow.DailyGoldBalances = new System.Collections.ObjectModel.ObservableCollection <DailyGoldBalance>(tempList);
            this.GoldBalanceView.ItemsSource  = this.mainWindow.DailyGoldBalances;
            this.UpdateTreeView();
            return(newDaily);
        }
Esempio n. 2
0
        /// <summary>
        /// Function to load a daily gold balance from json
        /// </summary>
        /// <param name="path">
        /// path to a file containing a daily gold balance
        /// </param>
        private void LoadBalanceFromJson(string path)
        {
            if (String.IsNullOrWhiteSpace(path) || !File.Exists(path))
            {
                return;
            }

            DailyGoldBalance gb = null;

            using (var reader = new StreamReader(path)) {
                gb = JsonConvert.DeserializeObject <DailyGoldBalance>(reader.ReadToEnd());
            }

            lock (balanceThreadLock) {
                this.DailyGoldBalances.Add(gb);
            }
        }
Esempio n. 3
0
        public GoldBalancePage()
        {
            this.InitializeComponent();
            this.mainWindow = Application.Current.Windows.OfType <MainWindow>().ElementAt(0);
            #region TREEVIEW_TEST
#if DEBUG
            DailyGoldBalance balance = new DailyGoldBalance();
            DailyExpenses    expense = new DailyExpenses();
            DailyEarnings    earning = new DailyEarnings();
            expense.BoughtItems.Add(new Item("Arrow Shaft", 20, 24));
            earning.Add(new Item("Arrow Shaft", 40, 80));
            balance.EarningsAndExpenses.Add(earning);
            balance.EarningsAndExpenses.Add(expense);
            mainWindow.DailyGoldBalances.Add(balance);
            this.GoldBalanceView.ItemsSource = mainWindow.DailyGoldBalances;
#endif
            #endregion
        }
 public virtual void SetOwner(DailyGoldBalance gb)
 {
 }
Esempio n. 5
0
        public void AddItem()
        {
            Item item = this.CreateItem();

            if (item == null)
            {
                MessageBox.Show("Error! Can't add a new item. Check if the values provided are correct.", "AddError", MessageBoxButton.OK);
                return;
            }

            ItemType soldOrBought = (ItemType)Enum.Parse(typeof(ItemType), this.ItemTypeComboBox.SelectedItem as string);

            object o = this.GoldBalanceView.SelectedItem;

            if (o == null)
            {
                var daily = this.AddDaily();
                switch (soldOrBought)
                {
                case ItemType.Bought:
                    (daily.EarningsAndExpenses[1] as DailyExpenses)?.Add(item);
                    break;

                case ItemType.Sold:
                    (daily.EarningsAndExpenses[0] as DailyEarnings)?.Add(item);
                    break;
                }
            }
            else
            {
                if (o is DailyGoldBalance gb)
                {
                    switch (soldOrBought)
                    {
                    case ItemType.Bought:
                        (gb.EarningsAndExpenses[1] as DailyExpenses)?.Add(item);
                        break;

                    case ItemType.Sold:
                        (gb.EarningsAndExpenses[0] as DailyEarnings)?.Add(item);
                        break;
                    }
                }
                else if (o is DailyExpenses ex)
                {
                    if (soldOrBought == ItemType.Sold)
                    {
                        MessageBox.Show("You are trying to add Sold item to the Expenses!");
                        return;
                    }
                    ex?.Add(item);
                }
                else if (o is DailyEarnings er)
                {
                    if (soldOrBought == ItemType.Bought)
                    {
                        MessageBox.Show("You are trying to add Bought item to the Earnings!");
                        return;
                    }
                    er?.Add(item);
                }
                else if (o is Item i)
                {
                    DailyGoldBalance _gb = i.GetOwner()?.GetOwner();
                    switch (soldOrBought)
                    {
                    case ItemType.Bought:
                        (_gb?.EarningsAndExpenses[1] as DailyExpenses)?.Add(item);
                        break;

                    case ItemType.Sold:
                        (_gb?.EarningsAndExpenses[0] as DailyEarnings)?.Add(item);
                        break;
                    }
                }
            }
            this.UpdateTreeView();
            this.AmountTextBox.Text = "";
            this.PriceTextBox.Text  = "";
        }
 public override void SetOwner(DailyGoldBalance owner) => this.owner = owner;
 public override void SetOwner(DailyGoldBalance gb) => this.owner = gb;