Ejemplo n.º 1
0
        private async void ClearAndResetItems(object sender, EventArgs e)
        {
            try
            {
                var res = await DisplayAlert("Confirm Clear", "Are you sure you want to clear all items in the list?", "OK",
                                             "Cancel");

                if (!res)
                {
                    return;
                }


                CurrentViewModel.SpendData = new ObservableCollection <SpendObject>();
                CurrentViewModel.SpendData.Clear();
                CalculateTotals();

                var dt    = CurrentViewModel.SerializeDataBase(CurrentViewModel.SpendData);
                var saved = await CurrentViewModel.SaveAnyString(dt, Constants.CurrentSpendList);

                await OptionsGrid.TranslateTo(-LocalHeight / 2, 0, duration, Easing.SinOut);

                CurrentViewModel.ShowOptions = false;
                CalculateTotals();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 2
0
        private async void CancelUpdateClicked(object sender, EventArgs e)
        {
            SpendListViewItems.SelectedItem = null;
            await OptionsGrid.TranslateTo(0, LocalHeight, duration, Easing.SinOut);

            CurrentViewModel.ShowDetails = false;
        }
Ejemplo n.º 3
0
        private async void ShowOptions(object sender, EventArgs e)
        {
            try
            {
                CurrentViewModel.ShowOptions = true;
                await OptionsGrid.TranslateTo(0, 0, duration, Easing.SinOut);

                //  await AddGrid.TranslateTo(0, 0, duration, Easing.SinOut);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 4
0
        private async void ShowItemTapped(object sender, EventArgs e)
        {
            try
            {
                if (!(sender is Grid lv))
                {
                    return;
                }

                if (!(lv.BindingContext is BudgetDataMain sel))
                {
                    return;
                }
                CurrentBudgetIndex = CurrentViewModel.BudgetDataEntry.IndexOf(sel);
                CurrentViewModel.CurrentBudgetItem = sel;
                CurrentViewModel.ShowStats         = false;
                CurrentViewModel.ShowAdd           = false;
                switch (sel.Frequency)
                {
                case FrequencyOfIncomeExpenses.Weekly:
                    FrequencyPicker.SelectedIndex = 0;
                    break;

                case FrequencyOfIncomeExpenses.Fortnightly:
                    FrequencyPicker.SelectedIndex = 1;
                    break;

                case FrequencyOfIncomeExpenses.Monthly:
                    FrequencyPicker.SelectedIndex = 2;
                    break;

                case FrequencyOfIncomeExpenses.Annually:
                    FrequencyPicker.SelectedIndex = 3;
                    break;

                default:
                    FrequencyPicker.SelectedIndex = 0;
                    break;
                }


                CurrentViewModel.ShowDetails = true;
                await OptionsGrid.TranslateTo(0, 0, duration, Easing.SinOut);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 5
0
        private void ReinitGrid(string pair, int timeToFirstOption, int optionLen, double priceSize, int nPriceIndex, int nTimeIndex)
        {
            var cfg          = _settings.Instruments.First(s => s.Name == pair);
            var grid         = new OptionsGrid(timeToFirstOption, optionLen, priceSize, nPriceIndex, nTimeIndex, cfg.MarginHit, cfg.MarginMiss, cfg.MaxPayoutCoeff, cfg.BookingFee, cfg.HasWeekend);
            var activities   = _activities[pair];
            var history      = _historyHolder.GetHistory(pair);
            var currentPrice = history.Last();

            grid.InitiateGrid(activities, history.ToList(), cfg.Delta, cfg.MovingWindow, currentPrice, cfg.SmileVar);
            _grids[pair] = grid;
            string msg = $"{DateTime.UtcNow.ToTimeString()} | [{pair}] Updated. History size:{history.Length}. Current Price:{currentPrice.Date.ToDateTimeString()}";

            Console.WriteLine(msg);
            _logger.WriteInfoAsync("Calculator.ReinitGrid", null, msg);
        }
Ejemplo n.º 6
0
        private async void AddItemClicked(object sender, EventArgs e)
        {
            try
            {
                CurrentViewModel.ShowStats   = false;
                CurrentViewModel.ShowDetails = true;
                await OptionsGrid.TranslateTo(0, 0, duration, Easing.SinOut);

                CurrentViewModel.ShowAdd           = true;
                CurrentViewModel.CurrentBudgetItem = new BudgetDataMain();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 7
0
        private async void HideOptionsCancel(object sender, EventArgs e)
        {
            try
            {
                await SaveIncome();

                CalculateTotals();
                await OptionsGrid.TranslateTo(0, LocalHeight, duration, Easing.SinOut);

                CurrentViewModel.ShowOptions = false;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 8
0
        private async void SaveItemClicked(object sender, EventArgs e)
        {
            try
            {
                CurrentViewModel.BudgetDataEntry.Add(CurrentViewModel.CurrentBudgetItem);
                var ord = CurrentViewModel.BudgetDataEntry.OrderByDescending(c => c.IncomeOrExpense).ThenBy(ed => ed.Frequency).ToList();
                CurrentViewModel.BudgetDataEntry.Replace(ord);
                CalculateTotals(currentFequencyUsedToCalculate);
                await OptionsGrid.TranslateTo(0, LocalHeight, duration, Easing.SinOut);

                CurrentViewModel.ShowDetails = false;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 9
0
        private async void ShowSelectedItem(object sender, SelectedItemChangedEventArgs e)
        {
            if (!(sender is ListView lv))
            {
                return;
            }

            if (!(lv.SelectedItem is BudgetDataMain sel))
            {
                return;
            }
            CurrentBudgetIndex = CurrentViewModel.BudgetDataEntry.IndexOf(sel);
            CurrentViewModel.CurrentBudgetItem = sel;
            CurrentViewModel.ShowStats         = false;

            switch (sel.Frequency)
            {
            case FrequencyOfIncomeExpenses.Weekly:
                FrequencyPicker.SelectedIndex = 0;
                break;

            case FrequencyOfIncomeExpenses.Fortnightly:
                FrequencyPicker.SelectedIndex = 1;
                break;

            case FrequencyOfIncomeExpenses.Monthly:
                FrequencyPicker.SelectedIndex = 2;
                break;

            case FrequencyOfIncomeExpenses.Annually:
                FrequencyPicker.SelectedIndex = 3;
                break;

            default:
                FrequencyPicker.SelectedIndex = 0;
                break;
            }


            CurrentViewModel.ShowDetails = true;
            await OptionsGrid.TranslateTo(0, 0, duration, Easing.SinOut);

            //lv.SelectedItem = null;
        }
Ejemplo n.º 10
0
        private async Task Initialize()
        {
            _grids      = new Dictionary <string, OptionsGrid>();
            _activities = new Dictionary <string, List <double> >();
            Dictionary <string, DateTime> lastreport = new Dictionary <string, DateTime>();

            foreach (var instrument in _settings.Instruments)
            {
                lastreport.Add(instrument.Name, DateTime.UtcNow);
                var activity = await _activityManager.GetActivityByName(instrument.Name, instrument.ActivityFileName);

                _activities.Add(instrument.Name, activity.ActivityArray.ToList());

                var grid = new OptionsGrid(instrument.TimeToFirstOption, instrument.OptionLen, instrument.PriceSize, instrument.NPriceIndex, instrument.NTimeIndex,
                                           instrument.MarginHit, instrument.MarginMiss, instrument.MaxPayoutCoeff, instrument.BookingFee, instrument.HasWeekend);

                var history = _historyHolder.GetHistory(instrument.Name);
                if (history != null && history.Length > 0)
                {
                    var currentPrice = history.Last();
                    await _logger.WriteInfoAsync("Calculator.Initialize", null, $"Current Price[{instrument.Name}] Date: {currentPrice.Date.ToDateTimeString()}");

                    grid.InitiateGrid(_activities[instrument.Name], history.ToList(), instrument.Delta, instrument.MovingWindow, currentPrice, instrument.SmileVar);
                    _grids.Add(instrument.Name, grid);

                    Timer instrumentTimer = new Timer(instrument.Period);
                    instrumentTimer.Elapsed += (sender, args) =>
                    {
                        instrumentTimer.Stop();
                        if (isDisposing)
                        {
                            return;
                        }

                        var now       = DateTime.UtcNow;
                        var newPrices = _priceCache.GetPrices(instrument.Name);

                        Price newPrice;
                        if (newPrices.Length > 0)
                        {
                            var lastPrice = newPrices.Last();
                            newPrice = new Price
                            {
                                Date = now,
                                Ask  = lastPrice.Ask,
                                Bid  = lastPrice.Bid
                            };
                        }
                        else
                        {
                            var lastHistoryPrice = _historyHolder.GetHistory(instrument.Name).Last();
                            newPrice = new Price
                            {
                                Date = now,
                                Ask  = lastHistoryPrice.Ask,
                                Bid  = lastHistoryPrice.Bid
                            };
                        }
                        _grids[instrument.Name].UpdateCoefficients(newPrices.ToList(), newPrice, instrument.SmileVar);
                        if (newPrices.Length > 0 && DateTime.UtcNow > lastreport[instrument.Name].AddMinutes(30))
                        {
                            string msg = $"{DateTime.UtcNow.ToTimeString()}[{instrument.Name}] Updated. New prices size:{newPrices.Length}. Current Price:{newPrice.Date.ToDateTimeString()}";
                            Console.WriteLine(msg);
                            _logger.WriteInfoAsync("Calculator.instrumentTimer.Elapsed", null, msg);
                            lastreport[instrument.Name] = DateTime.UtcNow;
                        }

                        instrumentTimer.Start();
                    };
                    instrumentTimer.Start();
                }
            }
            StartSubscriber();
        }
        private void WorkAllocationGrid_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                btnCancle.Enabled   = true;
                btnSaveOpts.Enabled = true;
                if (UserGridView.FocusedColumn.FieldName == "ProgCode" || UserGridView.FocusedColumn.FieldName == "ProgDesc")
                {
                    var     row = UserGridView.GetDataRow(UserGridView.FocusedRowHandle);
                    DataSet ds  = ProjectFunctions.GetDataSet("  [sp_LoadUserAlloactedPerForm] @NProgCode='" + row["ProgCode"].ToString() + "'");
                    ds.Tables[0].Merge(ds.Tables[1]);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        ds.Tables[0].Columns.Add("SPLRIGHTS", typeof(bool));
                        ds.Tables[0].Columns.Add("&Add", typeof(bool));
                        ds.Tables[0].Columns.Add("EDIT", typeof(bool));
                        ds.Tables[0].Columns.Add("DELETE", typeof(bool));
                        ds.Tables[0].Columns.Add("SELECTFIELD", typeof(bool));
                        ds.Tables[0].Columns.Add("MASTER", typeof(bool));
                        ds.Tables[0].Columns.Add("TRANSACTION", typeof(bool));
                        ds.Tables[0].Columns.Add("REPORT", typeof(bool));
                        ds.Tables[0].Columns.Add("ADMIN", typeof(bool));
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            dr["SPLRIGHTS"]   = false;
                            dr["&Add"]        = false;
                            dr["EDIT"]        = false;
                            dr["DELETE"]      = false;
                            dr["SELECTFIELD"] = false;
                            dr["MASTER"]      = false;
                            dr["TRANSACTION"] = false;
                            dr["REPORT"]      = false;
                            dr["ADMIN"]       = false;
                        }
                        for (var j = 0; j < ds.Tables[0].Rows.Count; j++)
                        {
                            if (ds.Tables[0].Rows[j]["ProgAdd_F"].ToString() == "-1")
                            {
                                ds.Tables[0].Rows[j]["&Add"] = true;
                            }
                            else
                            {
                                ds.Tables[0].Rows[j]["&Add"] = false;
                            }
                            if (ds.Tables[0].Rows[j]["ProgUpd_F"].ToString() == "-1")
                            {
                                ds.Tables[0].Rows[j]["EDIT"] = true;
                            }
                            else
                            {
                                ds.Tables[0].Rows[j]["EDIT"] = false;
                            }
                            if (ds.Tables[0].Rows[j]["ProgDel_F"].ToString() == "-1")
                            {
                                ds.Tables[0].Rows[j]["DELETE"] = true;
                            }
                            else
                            {
                                ds.Tables[0].Rows[j]["DELETE"] = false;
                            }

                            if (ds.Tables[0].Rows[j]["MasterMenu"].ToString() == "-1")
                            {
                                ds.Tables[0].Rows[j]["MASTER"] = true;
                            }
                            else
                            {
                                ds.Tables[0].Rows[j]["MASTER"] = false;
                            }
                            if (ds.Tables[0].Rows[j]["TransactionsMenu"].ToString() == "-1")
                            {
                                ds.Tables[0].Rows[j]["TRANSACTION"] = true;
                            }
                            else
                            {
                                ds.Tables[0].Rows[j]["TRANSACTION"] = false;
                            }
                            if (ds.Tables[0].Rows[j]["AdministratorMenu"].ToString() == "-1")
                            {
                                ds.Tables[0].Rows[j]["ADMIN"] = true;
                            }
                            else
                            {
                                ds.Tables[0].Rows[j]["ADMIN"] = false;
                            }
                            if (ds.Tables[0].Rows[j]["ReportMenu"].ToString() == "-1")
                            {
                                ds.Tables[0].Rows[j]["REPORT"] = true;
                            }
                            else
                            {
                                ds.Tables[0].Rows[j]["REPORT"] = false;
                            }
                            if (ds.Tables[0].Rows[j]["SelectField"].ToString() == "-1")
                            {
                                ds.Tables[0].Rows[j]["SELECTFIELD"] = true;
                            }
                            else
                            {
                                ds.Tables[0].Rows[j]["SELECTFIELD"] = false;
                            }

                            if (ds.Tables[0].Rows[j]["ProgSpl_U"].ToString() == "-1")
                            {
                                ds.Tables[0].Rows[j]["SPLRIGHTS"] = true;
                            }
                            else
                            {
                                ds.Tables[0].Rows[j]["SPLRIGHTS"] = false;
                            }
                        }
                    }
                    OptionsGrid.DataSource = ds.Tables[0];
                    OptionsGrid.Visible    = true;
                    OptionsGrid.Focus();
                }
            }
            catch (Exception ex)
            {
                ProjectFunctions.SpeakError(ex.Message);
            }
        }
Ejemplo n.º 12
0
 protected void BindOptionsGrid()
 {
     OptionsGrid.DataSource = _Options;
     OptionsGrid.DataBind();
 }