public TimeNumberInquirerViewModel(PluginInfo m) { this.m = m; this.m.PropertyChanged += new PropertyChangedEventHandler((sender, e) => { switch (e.PropertyName) { case nameof(m.CurrentTextBox): CurrentTextBox = (InputControlTextBox)m.CurrentTextBox; break; case nameof(m.TimeNumberInquirerStatus): if (m.TimeNumberInquirerStatus == TimeNumberInquirerStatus.PreparingToSend) { DateTime now = DateTime.Now; TextBoxes[InputControlTextBox.TimeNumberInquirerStartHour] = Strings.StrConv(now.Hour.ToString(), VbStrConv.Wide); TextBoxes[InputControlTextBox.TimeNumberInquirerStartMinute] = Strings.StrConv(now.Minute.ToString(), VbStrConv.Wide); Visibility = Visibility.Visible; CurrentTextBox = InputControlTextBox.TimeNumberInquirerEndHour; } else { Visibility = Visibility.Hidden; } break; } }); m.TextBoxes.CollectionChanged += new NotifyCollectionChangedEventHandler((sender, e) => { try { TextBoxes[(InputControlTextBox)e.OldStartingIndex] = m.TextBoxes[e.NewStartingIndex]; } catch { } }); TextBoxes = new ObservableDictionary <InputControlTextBox, string>(); foreach (InputControlTextBox i in Enum.GetValues(typeof(InputControlTextBox))) { TextBoxes.Add(i, ""); } TextBoxes.CollectionChanged += new NotifyCollectionChangedEventHandler((sender, e) => { try { KeyValuePair <InputControlTextBox, string> textBox = TextBoxes.First(t => m.TextBoxes[(int)t.Key] != t.Value); m.TextBoxes[(int)textBox.Key] = textBox.Value; } catch { } if (TextBoxes[CurrentTextBox].Length == 2) { CurrentTextBox++; } }); GotFocus = new DelegateCommand <string>(param => { CurrentTextBox = (InputControlTextBox)Enum.Parse(typeof(InputControlTextBox), param); }); Cancel = new DelegateCommand(() => { m.TimeNumberInquirerStatus = TimeNumberInquirerStatus.Hidden; }); Send = new DelegateCommand(() => { m.Times = ((Sender)m.Sender).InquireTimeNumbers((Game)(SelectedGameIndex + 1)); m.TimeNumberInquirerStatus = m.Times == null ? TimeNumberInquirerStatus.Hidden : TimeNumberInquirerStatus.Sent; }); }
public TimeNumberInquirerResultPresenterViewModel(PluginInfo m) { this.m = m; this.m.PropertyChanged += new PropertyChangedEventHandler((sender, e) => { switch (e.PropertyName) { case nameof(m.CurrentTextBox): CurrentTextBox = (InputControlTextBox)m.CurrentTextBox; break; case nameof(m.TimeNumberInquirerStatus): if (m.TimeNumberInquirerStatus == TimeNumberInquirerStatus.Sent) { GameName = m.Times.Count > 0 ? m.Times[0].Game.GetEnumDisplayName() : ""; Times = m.Times.ConvertAll(t => t.String); Visibility = Visibility.Visible; } else { Visibility = Visibility.Hidden; } break; } }); m.TextBoxes.CollectionChanged += new NotifyCollectionChangedEventHandler((sender, e) => { try { TextBoxes[(InputControlTextBox)e.OldStartingIndex] = m.TextBoxes[e.NewStartingIndex]; } catch { } }); TextBoxes = new ObservableDictionary <InputControlTextBox, string>(); foreach (InputControlTextBox i in Enum.GetValues(typeof(InputControlTextBox))) { TextBoxes.Add(i, ""); } TextBoxes.CollectionChanged += new NotifyCollectionChangedEventHandler((sender, e) => { try { KeyValuePair <InputControlTextBox, string> textBox = TextBoxes.First(t => m.TextBoxes[(int)t.Key] != t.Value); m.TextBoxes[(int)textBox.Key] = textBox.Value; } catch { } if (TextBoxes[CurrentTextBox].Length == 2) { CurrentTextBox++; } }); GotFocus = new DelegateCommand <string>(param => { CurrentTextBox = (InputControlTextBox)Enum.Parse(typeof(InputControlTextBox), param); }); Cancel = new DelegateCommand(() => { m.TimeNumberInquirerStatus = TimeNumberInquirerStatus.Hidden; }); Finish = new DelegateCommand(() => { m.TextBoxes[(int)InputControlTextBox.Service] = m.Times[SelectedTimeIndex].Game.GetEnumDisplayName(); m.TextBoxes[(int)InputControlTextBox.Number] = Strings.StrConv(m.Times[SelectedTimeIndex].TimeNumber.ToString(), VbStrConv.Wide); m.TimeNumberInquirerStatus = TimeNumberInquirerStatus.Hidden; }, () => SelectedTimeIndex != -1).ObservesProperty(() => SelectedTimeIndex); }
public Sender(PluginInfo m) { this.m = m; }