private void load() { string filename = @"Z:\MyData\OneDrive\Corsi\WPF\MachineData.txt"; if (File.Exists(filename)) { string[] parts; string[] csvContent = File.ReadAllLines(filename); foreach (var line in csvContent) { parts = line.Split(new char[] { ';' }); Machine machine = new Machine(); machine.ID = Int32.Parse(parts[0]); machine.Code = parts[1]; machine.Name = parts[2]; machine.WorkHours = Int32.Parse(parts[3]); MachineViewModel vm = new MachineViewModel(machine); this.Items.Add(vm); } this.Item = this.Items[0]; } }
private async void addCommandExecute() { this.IsBusy = true; Random rnd = new Random((int)DateTime.Now.Ticks); await Task.Run(() => { // Attesa "inutile" int id = Thread.CurrentThread.ManagedThreadId; Debug.WriteLine(id); int number = 100000; List <MachineViewModel> cache = new List <MachineViewModel>(); cache.AddRange(this.Items); for (int i = 0; i < number; i++) { MachineViewModel m = new MachineViewModel(new Machine()); m.Code = "COD"; m.WorkHours = rnd.Next(1, this.MaximumWorkHours); cache.Add(m); } this.Items = new ObservableCollection <MachineViewModel>(cache); base.RaisePropertyChanged(nameof(Items)); }); this.Item = this.Items[rnd.Next(0, this.Items.Count)]; Messenger.Default.Send <ShowMessage>( new ShowMessage("OK!", "Operazione completata!")); this.IsBusy = false; }
private void resetCommandExecute(MachineViewModel parameter) { parameter.WorkHours = 0; parameter.Maintenance = true; }