using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Data;
namespace WpfApp2
{
///
/// Interaction logic for Window1.xaml
///
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
}
public class BillsViewModel2 : ViewModelBase
{
public BillsViewModel2() { ResetYear(); }
private CultureInfo culture = new CultureInfo("en-IN");
public IEnumerable AdjBills
{
get
{
return AdjBillss.Where(o => ((Bills)o).Vendor == SelectedCBItem && String.IsNullOrEmpty(((Bills)o).UsedOn));
}
}
private ObservableCollection _adjBillss;
public ObservableCollection AdjBillss
{
get
{
if (this._adjBillss == null) this._adjBillss = DatabaseLayer.GetAllAdjBillsFromDB();
return this._adjBillss;
}
}
private IEnumerable _allBills;
public IEnumerable AllBills
{
get
{
return AllBillss.Where(o => ((Bills)o).Party == SelectedCBItem2);
}
}
private ObservableCollection _allBillss;
public ObservableCollection AllBillss
{
get
{
if (this._allBillss == null) this._allBillss = DatabaseLayer.GetAllBillsFromDB();
return this._allBillss;
}
}
public object CityName { get; set; }
public object Cnt { get; set; }
public object Cnt2 { get; set; }
private ObservableCollection _comboItems;
public ObservableCollection ComboItems
{
get
{
if (this._comboItems == null) this._comboItems = new ObservableCollection(AllBillss.Select(b => b.Party).Distinct().OrderBy(b => b).ToList());
return this._comboItems;
}
}
private ObservableCollection _comboItems2;
public object ComboItems2
{
get
{
if (this._comboItems2 == null) this._comboItems2 = new ObservableCollection(AllBillss.Select(b => b.Party).Distinct().OrderBy(b => b).ToList());
return this._comboItems2;
}
}
public object DocxButtonClicked { get; set; }
public IEnumerable FilteredBills
{
get
{
return AllBillss.Where(o => ((Bills)o).Party == SelectedCBItem && String.IsNullOrEmpty(((Bills)o).Remarks));
}
}
public object FilterString { get; set; }
public object myInfo { get; set; }
private ICollectionView _pendingBills;
public ICollectionView PendingBills
{
get
{
if (_pendingBills == null)
this._pendingBills = new ListCollectionView(AllBillss)
{
Filter = o => String.IsNullOrEmpty(((Bills)o).Remarks)
&& (DateTime.ParseExact(((Bills)o).DueDt, "yyyy-MM-dd", culture) >= DateTime.Today.AddDays(-10)
&& DateTime.ParseExact(((Bills)o).DueDt, "yyyy-MM-dd", culture) < DateTime.Today.AddDays(11)
)
};
return this._pendingBills;
}
}
public object SearchButtonClicked { get; set; }
public object SelectedButtonClicked { get; set; }
public object SelButtonClicked { get; set; }
public object SelecedItme { get; set; }
private string _selectedCBItem;
public string SelectedCBItem
{
get { return this._selectedCBItem; }
set
{
if (this._selectedCBItem != value)
{
this._selectedCBItem = value;
OnPropertyChanged(nameof(FilteredBills));
OnPropertyChanged(nameof(AdjBills));
}
}
}
private string _selectedCBItem2;
public string SelectedCBItem2
{
get { return this._selectedCBItem2; }
set
{
if (this._selectedCBItem2 != value)
{
this._selectedCBItem2 = value;
OnPropertyChanged(nameof(AllBills));
}
}
}
public object SelectedIndex { get; set; }
public object SelectedInv { get; set; }
public IList ListOfYears { get { return new List() { "2020", "2021", "2022" }; } }
private string _selectedYear = DateTime.Now.Year.ToString();
public string SelectedYear
{
get { return this._selectedYear; }
set
{
if (this._selectedYear != value)
{
this._selectedYear = value;
ResetYear();
}
}
}
private void ResetYear()
{
DatabaseLayer.dbloc = $"Data Source = {this._selectedYear}.db";
this._pendingBills = null;
this._allBills = null;
this._allBillss = null;
this._adjBillss = null;
this._comboItems = null;
this._comboItems2 = null;
OnPropertyChanged(string.Empty);
}
}
}