void OnSetChanged(LeasingSet set) { if (set == null) { return; } switch (set.Monthes.Count) { case 0: break; case 1: FromMonth = set.Monthes[0].Month; ToMonth = set.Monthes[0].Month; break; default: FromMonth = set.Monthes[0].Month; ToMonth = set.Monthes[set.Monthes.Count - 1].Month; break; } if (m_Window != null) { m_Window.LeasingChart.LeasingSet = set; } Statistic = new StatisticModel(); Statistic.Load(set); }
public void Dispose() { if (LeasingSet != null) { LeasingSet.Dispose(); LeasingSet = null; } Statistic = null; }
public void Update() { if (FromMonth == null || ToMonth == null) { return; } var newSet = new LeasingSet() { Data = DataManager.GetDataset(FromMonth, ToMonth) }; LeasingSet = newSet; if (m_Window != null) { m_Window.LeasingChart.Draw(); } }
void SubscribeSet(LeasingSet set, bool subscribe) { if (set == null) { return; } if (subscribe) { set.CarsChanged += LeasingSet_CarsChanged; set.CommentsChanged += LeasingSet_CommentsChanged; Row row = null; if (set.CarModels.Count > 0) { foreach (var model in set.CarModels) { row = GetRow(model.RowIndex); row.Car = model; } } if (set.Comments.Count > 0) { foreach (var model in set.Comments) { row = GetRow(model.RowIndex); row.Comment = model; } } } else { set.CarsChanged -= LeasingSet_CarsChanged; set.CommentsChanged -= LeasingSet_CommentsChanged; } }
public MainWindow2() { var vm = new LeasingViewViewModel(this); var curentYear = DateTime.Now.Year; var rMonth = Randomizer.GetRandomMonth(curentYear); MonthBusiness[] monthBuisnesses = null; if (App.SearchSettings.TestData) { App.SetAvailable(Month.GetMonthes(new DateTime(curentYear, 1, 1), new DateTime(curentYear, 12, 1))); monthBuisnesses = DataManager.GetDataset(App.AvailableMonthesAll.First(), App.AvailableMonthesAll.Last()); } else { monthBuisnesses = DataManager.GetDataset(Month.Current.Previos(), Month.Current.Next()); } var set = new LeasingSet(); set.Data = monthBuisnesses; InitializeComponent(); set.Chart = LeasingChart; Subscribe(true); DataContext = vm; //Set проставляем после инициализации, т.к. не явно заполняется контрол vm.LeasingSet = set; Loaded += MainWindow2_Loaded; }
private void Button_Click_1(object sender, RoutedEventArgs e) { var curentVM = DataContext as MainWindowViewModel; var tabItem = (curentVM.TabItemsModels.First() as OneMonthItem); var w = new Views.MainWindow2(); var vm = w.DataContext as LeasingViewViewModel; var rMonth = Randomizer.GetRandomMonth(2018); MonthBusiness[] monthBuisnesses = App.SearchSettings.TestData ? DataManager.GetDataset(rMonth, rMonth.Next(2)) : DataManager.GetDataset(App.AvailableMonthesAll.First(), App.AvailableMonthesAll.Last()); var set = new LeasingSet(); set.Data = monthBuisnesses; vm.LeasingSet = set; vm.Cars = monthBuisnesses .SelectMany(mb => mb.CarBusiness) .Select(cb => cb.Name) .Distinct() .Select(name => new CarModel() { Text = name }).ToList(); vm.Comments = vm.Cars.Select(car => new CarCommentModel() { RowIndex = car.RowIndex, Comment = (car.Text + "_comment") }).ToList(); //tabItem.MonthLeasing.CarBusiness.Select(b => new CarHeaderModel() { Text = b.Name }).ToList(); var leasingBarModels = new List <LeasingElementModel> [monthBuisnesses.Length]; var index = 0; //foreach (var item in tabItem.MonthLeasing.CarBusiness) foreach (var business in monthBuisnesses) { foreach (var item in business.CarBusiness) { var car = vm.Cars.FirstOrDefault(c => c.Text.Equals(item.Name)); if (leasingBarModels[index] == null) { leasingBarModels[index] = new List <LeasingElementModel>(); } leasingBarModels[index].AddRange(item.Business.Select(b => new LeasingElementModel() { Leasing = b, RowIndex = car == null ? 0 : car.RowIndex, DayColumnWidth = 21d })); } index++; } index = 0; vm.MonthLeasings = new List <MonthLeasing>( monthBuisnesses.Select(bus => new MonthLeasing() { ColumnIndex = index, MonthHeader = new MonthHeaderModel(set) { Month = bus.Month }, Leasings = leasingBarModels[index++] })); w.ShowDialog(); }