private void Init(Model model) { //Save model handle this.model = model; originPosixTz = PosixTz.TryParse(model.timeZone); if (model.utcDateTime != null) { originUtcDateTime = model.utcDateTime.Value; } else if ((object)originPosixTz != null && model.localDateTime != null) { try{ originUtcDateTime = originPosixTz.ConvertLocalTimeToUtc( (DateTime)model.localDateTime, model.origin.daylightSavings ); }catch (Exception err) { dbg.Error(err); } } //Init command OnCompleted += () => { disposables.Dispose(); }; //var applyCommand = new DelegateCommand( // () => OnApplyChanges(), // () => true //); //ApplyCommand = applyCommand; var closeCommand = new DelegateCommand( () => Success(new Result.Close()), () => true ); CloseCommand = closeCommand; var cancelCommand = new DelegateCommand( () => { OnRevertChanges(); }, () => true ); CancelCommand = cancelCommand; //init all UI controls InitializeComponent(); //Init time zones InitTimeZones(); //Init and fill Init(); //set up local strings Localization(); }
void ValidateUI() { var pos = PosixTz.TryParse(posixTZ); if (pos == null) { borderTZ.BorderBrush = Brushes.Red; } else { borderTZ.BorderBrush = Brushes.Transparent; } }
public ManualTZ(string posixTZ) { InitializeComponent(); this.DataContext = this; btnApply.Content = LocalButtons.instance.apply; valueTZ.CreateBinding(TextBox.TextProperty, this, t => t.posixTZ, (m, o) => { m.posixTZ = o; posix = PosixTz.TryParse(o); ValidateUI(); } ); this.posixTZ = posixTZ; Loaded += new RoutedEventHandler((o, e) => { ValidateUI(); }); Closing += new System.ComponentModel.CancelEventHandler(Upgrade_Closing); }
public static TimeZoneViewModel[] GetManualTimeZones(string fileName) { ManualTimeZones mtzs = null; try { var doc = new XmlDocument(); doc.Load(fileName); mtzs = doc.DocumentElement.Deserialize <TimeZoneViewModel.ManualTimeZones>(); } catch (Exception err) { dbg.Error(err); return(new TimeZoneViewModel[0]); } if (mtzs == null || mtzs.timeZones == null || mtzs.timeZones.Length == 0) { return(new TimeZoneViewModel[0]); } var tz_list = new List <TimeZoneViewModel>(256); foreach (var tz in mtzs.timeZones) { if (tz.posixTz != null) { var posixTz = PosixTz.TryParse(tz.posixTz); tz_list.Add(new TimeZoneViewModel( tz.displayName, tz.posixTz, posixTz )); } } return(tz_list.OrderBy(x => { if (x.posixTz != null) { return new Tuple <int, int, string>(0, -x.posixTz.offset, x.displayName); } else { return new Tuple <int, int, string>(1, 0, x.displayName); } }).ToArray()); }
TimeZoneViewModel GetTimeZoneSelection() { TimeZoneViewModel timezonemosel = null; if (timeZonesComboBox.SelectedIndex == -1) { timezonemosel = new TimeZoneViewModel(timeZonesComboBox.Text, timeZonesComboBox.Text, PosixTz.TryParse(timeZonesComboBox.Text)); } else { var tmodel = timeZonesComboBox.SelectedItem as TimeZoneViewModel; if (tmodel != null) { timezonemosel = tmodel; } } return(timezonemosel); }