public void Time_DateTime_ValueChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { TimePicker time = (TimePicker)sender; string nestedname = ""; string oldvalue = ""; string description = ""; DatePicker date = new DatePicker(); StackLayout stackLayout = (StackLayout)time.Parent; foreach (var element in stackLayout.Children) { if (element.GetType() == typeof(DatePicker)) { date = (DatePicker)element; } } ComosWebSDK.UI.UIDateTime b = (ComosWebSDK.UI.UIDateTime)time.BindingContext; nestedname = b.NestedName; oldvalue = b.Value; description = b.Text; DateTime dateTime = new DateTime(date.Date.Year, date.Date.Month, date.Date.Day, time.Time.Hours, time.Time.Minutes, time.Time.Seconds); string comosDate = dateTime.ToOADate().ToString(); CheckValue(nestedname, comosDate, oldvalue, description); }
public View UpdateAttributesUI(ComosWebSDK.UI.UIDateTime ui) { if (!ui.ReadOnly) { editablevalues.Add(ui); } StackLayout layout = new StackLayout() { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.FillAndExpand }; var lbl = new Label() { Text = ui.Text, WidthRequest = App.WidthPixels / 3, VerticalTextAlignment = TextAlignment.Center, HorizontalTextAlignment = TextAlignment.Start, }; layout.Children.Add(lbl); if (ui.ReadOnly) { var txt = new Label() { Text = ui.Value, }; layout.Children.Add(txt); } else { var date = new DatePicker() { HorizontalOptions = LayoutOptions.FillAndExpand, BindingContext = ui, }; var time = new TimePicker() { HorizontalOptions = LayoutOptions.End, BindingContext = ui, }; if (ui.CachedValue != "" && ui.CachedValue != ui.Value && ui.CachedValue != null) { string[] dateAndTime = ui.CachedValue.Split(' '); date.Date = Convert.ToDateTime(dateAndTime[0]); time.Time = TimeSpan.Parse(dateAndTime[1]); date.TextColor = (Color)App.Current.Resources["spec-only-cache"]; time.TextColor = (Color)App.Current.Resources["spec-only-cache"]; DateTime dateTime = new DateTime(date.Date.Year, date.Date.Month, date.Date.Day, time.Time.Hours, time.Time.Minutes, time.Time.Seconds); string comosDate = dateTime.ToOADate().ToString(); CheckValue(ui.NestedName, comosDate, "", ui.Text); } else { if (!ui.Value.Equals("")) { string[] dateAndTime = ui.Value.Split(' '); DateTime _date = Convert.ToDateTime(dateAndTime[0]); TimeSpan _time = TimeSpan.Parse(dateAndTime[1]); DateTime dateTime = (new DateTime(_date.Year, _date.Month, _date.Day, _time.Hours, _time.Minutes, _time.Seconds)).ToLocalTime(); date.Date = dateTime.Date; time.Time = dateTime.TimeOfDay; string comosDate = dateTime.ToOADate().ToString(); CheckValue(ui.NestedName, comosDate, comosDate, ui.Text); } else { CheckValue(ui.NestedName, "", ui.Value, ui.Text); } } date.DateSelected += Date_DateTime_ValueChanged; time.PropertyChanged += Time_DateTime_ValueChanged; layout.Children.Add(date); layout.Children.Add(time); } AbsoluteLayout.SetLayoutBounds(layout, new Rectangle( ui.x, ui.y, ui.width, ui.height)); return(layout); }