Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Runtime.CompilerServices;
- using System.Windows.Input;
- using CommunityToolkit.Mvvm.ComponentModel;
- using Microsoft.Maui.Platform;
- namespace MM2.Views;
- public partial class NewPage1 : ContentPage
- {
- public partial class item : ObservableObject
- {
- //[ObservableProperty]
- //public ObservableCollection<item> items;
- //[ObservableProperty] public bool isSelected;
- //[ObservableProperty] public Color backgroundColor;
- [ObservableProperty] public string acct;
- [ObservableProperty] public decimal amount;
- public int tag;
- public event PropertyChangedEventHandler PropertyChanged;
- protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
- {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
- }
- public partial class MyViewModel : ObservableObject
- {
- //[ObservableProperty] public item? itemMaybe { get; set; }
- //[ObservableProperty] public DateOnly theDate { get; set; }
- // [ObservableProperty] int anInt;
- item _SelectedItem;
- public item SelectedItem
- {
- get { return _SelectedItem; }
- set
- {
- if (_SelectedItem == value) return;
- _SelectedItem = value;
- //OnPropertyChanged();
- } // OnPropertyChanged needed/okay/bad?
- }
- private DateTime _theDate;
- public DateTime theDate
- {
- get { return _theDate; }
- set
- {
- if (_theDate == value) return;
- _theDate = value;
- OnPropertyChanged();
- }
- }
- private int _anInt;
- public int anInt
- {
- get { return _anInt; }
- set
- {
- if (_anInt == value) return;
- _anInt = value;
- OnPropertyChanged();
- }
- }
- private item _itemMaybe;
- public item itemMaybe
- {
- get { return _itemMaybe; }
- set
- {
- if (_itemMaybe == value) return;
- _itemMaybe = value;
- OnPropertyChanged();
- }
- }
- public event PropertyChangedEventHandler PropertyChanged;
- protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
- {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
- }
- public ObservableCollection<item> itemsOC { get; set; }
- item OneItem { get; set; }
- item OneMini { get; set; }
- item itemMaybe { get; set; }
- item SelectedItem { get; set; }
- //public DateOnly theDate { get; set; }
- string Q;
- MyTable tbl;
- int MiniIndex = 0;
- MyViewModel vm = new();
- public NewPage1()
- {
- InitializeComponent();
- BindingContext = vm;
- //theDate = DateTime.Today;
- //anInt = 1234;
- Setup();
- }
- void Setup()
- {
- Q = "SELECT AcctName, AcctBalance FROM Assets;";
- tbl = new(Q);
- int NumRows = tbl.numRows; //3
- int NumCols = tbl.numCols; //2
- itemsOC = new();
- BindingContext = this;
- for (int i = 0; i < NumRows; i++)
- {
- OneItem = new();
- string[] aRow = tbl.GetRow(i);
- OneItem.acct = aRow[0];
- OneItem.amount = Convert.ToDecimal(aRow[1]);
- OneItem.tag = i;
- //zzz OneItem.isSelected = false; //Not useful??
- //OneItem.backgroundColor = Colors.Grey;
- //OneItem.backgroundColor = (Color)Resources["ColorUnSel"];
- itemsOC.Add(OneItem);
- }
- }
- private void SelectItemByIndex(object sender, EventArgs e)
- {
- // Not used?
- MiniView.SelectedItem = itemsOC[MiniIndex];
- }
- void DummyForNow(object o, EventArgs e)
- {
- }
- // fake private item for itemsClicked()
- // No longer used: item PriorItem = null;
- private void itemsTapped(object s, EventArgs e)
- {
- // aparently s = ItemsSource
- if (SelectedItem is null)
- {
- return;
- }
- OneMini = itemMaybe;
- int tag = itemMaybe.tag;
- int index = itemsOC.IndexOf(itemsOC.Where
- (X => X.tag == tag).FirstOrDefault());
- if (index == -1)
- {
- return; // trap this line for debug
- }
- // index is valid
- MiniIndex = 2;// = index;DEBUG!!
- //make it look selected
- //OneMini.backgroundColor = (Color)Resources["ColorSel"];
- //OneMini.isSelected = true;
- //MiniView.SelectedItem = itemsOC[2];
- #if false // make the prior one look unsected
- // try removing this
- if (PriorItem is not null)
- {
- PriorItem.backgroundColor =
- (Color)Resources["ColorUnSel"];
- PriorItem.isSelected = false;
- PriorItem = itemMaybe; // for next time
- }
- #endif
- SetButtonsVisible(); // up/down/remove
- silli.Text = "ABC";
- var zzz = silli.BackgroundColor;
- // both of these were null
- var q1 = silli.Command;
- var q2 = silli.CommandParameter;
- } // END itemsTapped(object s, EventArgs e)
- void click(object sender, EventArgs e)
- {
- int c = itemsOC.Count;
- if (c < 1) return;
- // swap bottom to top
- itemsOC.Move(c - 1, 0);
- // reverse the above
- itemsOC.Move(0, c - 1);
- }
- void SetButtonsVisible()
- {
- int max = itemsOC.Count - 1;
- if (max < 0)
- {
- bDel.IsVisible = false;
- return;
- }
- bTop.IsVisible = true;
- bDwn.IsVisible = true;
- bDel.IsVisible = true;
- bUp.IsVisible = true;
- if (MiniIndex == 0) bTop.IsVisible = false;
- if (MiniIndex == 0) bUp.IsVisible = false;
- if (MiniIndex >= max) bDwn.IsVisible = false;
- }
- void clickDown(object s, EventArgs e)
- {
- itemsOC.Move(MiniIndex, MiniIndex+1);
- MiniIndex++;
- MiniView.SelectedItem = itemsOC[MiniIndex];
- }
- void clickToTop(object s, EventArgs e)
- {
- itemsOC.Move(MiniIndex, 0);
- MiniIndex = 0;
- MiniView.SelectedItem = itemsOC[MiniIndex];
- }
- void clickDelete(object s, EventArgs e)
- {
- itemsOC.RemoveAt(MiniIndex);
- MiniIndex = -1;
- }
- void clickUp(object s, EventArgs e)
- {
- itemsOC.Move(MiniIndex, MiniIndex-1);
- MiniIndex--;
- MiniView.SelectedItem = itemsOC[MiniIndex];
- }
- } // END partial class NewPage1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement