Exemple #1
0
        //PUSH - Prova
        protected override void OnElementChanged(ElementChangedEventArgs <TimePicker> e)
        {
            base.OnElementChanged(e);

            CustomTimePicker timePicker = (CustomTimePicker)Element;

            if (timePicker != null)
            {
                Control.TextSize = 14f;

                /*var shape = new ShapeDrawable(new RectShape());
                 * shape.Paint.Alpha = 0;
                 * shape.Paint.SetStyle(Paint.Style.Stroke);
                 * Control.SetBackgroundDrawable(shape);*/


                Control.Background.SetAlpha(10);
                Control.Background.SetColorFilter(Android.Graphics.Color.Black, PorterDuff.Mode.SrcAtop);

                //Typeface font = Typeface.CreateFromAsset(Forms.Context.Assets, "Avenir");  // font name specified here
                //Control.Typeface = font;
                //Control.Typeface =
                //Control.FontFeatureSettings =
                //Control.BorderStyle = UITextBorderStyle.None;
                //Control.Font = UIFont.FromName("Avenir", 14f);
                SetPlaceholder(timePicker);
                SetTextColor(timePicker);
            }
        }
Exemple #2
0
        protected override void OnElementChanged(ElementChangedEventArgs <TimePicker> e)
        {
            base.OnElementChanged(e);
            //if (e.OldElement == null)
            //{
            //Control.Background = null;

            //var layoutParams = new MarginLayoutParams(Control.LayoutParameters);
            //layoutParams.SetMargins(0, 0, 0, 0);
            //LayoutParameters = layoutParams;
            //GradientDrawable gd = new GradientDrawable();
            //gd.SetStroke(0, Android.Graphics.Color.LightGray);
            //Control.SetBackgroundDrawable(gd);
            //Control.LayoutParameters = layoutParams;
            //Control.SetPadding(0, 0, 0, 0);
            //SetPadding(0, 0, 0, 0);


            element = (CustomTimePicker)this.Element;

            if (Control != null && this.Element != null && !string.IsNullOrEmpty(element.Image))
            {
                Control.Background = AddPickerStyles(element.Image);
            }
            //}
        }
Exemple #3
0
        private void TimePicker_OkButtonClicked(object sender, Syncfusion.SfPicker.XForms.SelectionChangedEventArgs e)
        {
            CustomTimePicker customTimePicker = sender as CustomTimePicker;
            ////////GET DATA FROM IEnumerableList
            IList listTimePicker = (IList)customTimePicker.SelectedItem;

            if (strTimePickerCode == "MASUK")
            {
                GlobalVar._listScheduling.Find(x => x.NPK == _selectedScheduling.NPK).Masuk = string.Format("{0}:{1}:{2}", listTimePicker[0], listTimePicker[1], listTimePicker[2]);
            }
            //if (strTimePickerCode == "MASUKAKTUAL")
            //{
            //    GlobalVar._listScheduling.Find(x => x.NPK == _selectedScheduling.NPK).MasukAktual = string.Format("{0}:{1}:{2}", listTimePicker[0], listTimePicker[1], listTimePicker[2]);

            //}
            if (strTimePickerCode == "PULANG")
            {
                GlobalVar._listScheduling.Find(x => x.NPK == _selectedScheduling.NPK).Pulang = string.Format("{0}:{1}:{2}", listTimePicker[0], listTimePicker[1], listTimePicker[2]);
            }
            //if (strTimePickerCode == "PULANGAKTUAL")
            //{
            //    GlobalVar._listScheduling.Find(x => x.NPK == _selectedScheduling.NPK).PulangAktual = string.Format("{0}:{1}:{2}", listTimePicker[0], listTimePicker[1], listTimePicker[2]);

            //}
        }
        /// <summary>
        /// Clears the date field
        /// </summary>
        private void ClearDate(object parameter)
        {
            var dic = (Dictionary <String, Object>)parameter;

            dic.TryGetValue("text", out var textData);
            TextData text = (TextData)textData;

            dic.TryGetValue("date", out var dateObj);
            CustomDatePicker dateField = (CustomDatePicker)dateObj;

            dic.TryGetValue("time", out var timeObj);
            CustomTimePicker timeField = (CustomTimePicker)timeObj;

            dateField.NullableDate = null;
            timeField.NullableDate = null;
            DateTime?date    = (DateTime?)dateField.NullableDate;
            int      valueId = (int)dateField.ValueId;

            if (dateField.Mandatory)
            {
                var empty = (date == null);
                Validation[valueId] = !empty;
                SaveCommand.ChangeCanExecute();
            }

            using (SQLiteConnection conn = new SQLiteConnection(Preferences.Get("databaseLocation", "")))
            {
                text.value = String.Empty;
                //conn.Update(text);
                Record.UpdateRecord(text.record_fk);
            }
        }
        /// <summary>
        /// When date field entries change, we can trigger a reevaluation of the page here
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DateFieldChanged(object sender, EventArgs e)
        {
            var      dateField = (CustomDatePicker)sender;
            DateTime?date      = (DateTime?)dateField.NullableDate;
            int      valueId   = (int)dateField.ValueId;

            if (dateField.Mandatory)
            {
                var empty = (date == null);
                Validation[valueId] = !empty;
                SaveCommand.ChangeCanExecute();
            }

            if (date != null)
            {
                CustomStackLayout stack = (CustomStackLayout)dateField.Parent;
                foreach (var el in stack.Children)
                {
                    if (el is CustomTimePicker)
                    {
                        CustomTimePicker tp = (CustomTimePicker)el;
                        if (tp.NullableDate == null)
                        {
                            tp.NullableDate = new TimeSpan(0);
                        }
                    }
                }
            }
        }
        protected override void OnElementChanged(ElementChangedEventArgs <TimePicker> e)
        {
            base.OnElementChanged(e);
            this.SetNativeControl(new Android.Widget.EditText(this.Context));
            this.Control.Click       += Control_Click;
            this.Control.Text         = DateTime.Now.ToString("HH:mm");
            this.Control.TextSize     = 14;
            this.Control.KeyListener  = null;
            this.Control.FocusChange += Control_FocusChange;

            CustomTimePicker element = Element as CustomTimePicker;
            GradientDrawable gd      = new GradientDrawable();

            if (!string.IsNullOrWhiteSpace(element.Placeholder))
            {
                this.Control.Text = element.Placeholder;
            }
            if (!string.IsNullOrWhiteSpace(element.PlaceholderColor))
            {
                Control.SetTextColor(Android.Graphics.Color.ParseColor(element.PlaceholderColor));
            }
            if (!element.Underline)
            {
                gd.SetColor(global::Android.Graphics.Color.Transparent);
                Control.SetBackground(gd);
            }
        }
Exemple #7
0
        /// <summary>
        /// Sets the time of the alarm being edited.
        /// </summary>
        /// <param name="time">
        /// The time to set the alarm to.
        /// </param>
        /// <returns>
        /// The <see cref="EditAlarmPage"/>.
        /// </returns>
        public EditAlarmPage SetAlarmTime(TimeSpan time)
        {
            CustomTimePicker customTimePicker = this.WindowsApp.FindElement(this.alarmTimePicker);

            customTimePicker.SetTime(time);
            return(this);
        }
 protected override void OnElementChanged(ElementChangedEventArgs <TimePicker> e)
 {
     base.OnElementChanged(e);
     if (Control != null)
     {
         CustomTimePicker customControl = (CustomTimePicker)Element;
         Control.MinuteIncrement = customControl.MinutesInterval;
     }
 }
 protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     base.OnElementPropertyChanged(sender, e);
     if (e.PropertyName == nameof(CustomTimePicker.MinutesInterval))
     {
         CustomTimePicker customControl = (CustomTimePicker)Element;
         Control.MinuteIncrement = customControl.MinutesInterval;
     }
 }
Exemple #10
0
        protected override void OnElementChanged(ElementChangedEventArgs <TimePicker> e)
        {
            base.OnElementChanged(e);
            try
            {
                element = Element as CustomTimePicker;
                if (e.NewElement != null)
                {
                    element = Element as CustomTimePicker;
                }
                else
                {
                    element = e.OldElement as CustomTimePicker;
                }

                if (Control != null)
                {
                    GradientDrawable gd = new GradientDrawable();
                    //gd.SetCornerRadius(45); // increase or decrease to changes the corner look
                    gd.SetColor(global::Android.Graphics.Color.Transparent);
                    //gd.SetStroke(2, global::Android.Graphics.Color.Gray);
                    this.Control.SetBackgroundDrawable(gd);
                    Control.SetRawInputType(InputTypes.TextFlagNoSuggestions);
                    Control.Gravity = global::Android.Views.GravityFlags.CenterVertical;
                    if (!string.IsNullOrWhiteSpace(element.EnterText))
                    {
                        Control.Text = element.EnterText;
                    }
                    Control.SetHintTextColor(ColorStateList.ValueOf(global::Android.Graphics.Color.Black)); //for placeholder
                                                                                                            //this.Control.InputType = InputTypes.TextVariationPassword;
                    if (element.CustomFontSize != 0.0)
                    {
                        Control.SetTextSize(ComplexUnitType.Dip, element.CustomFontSize);
                        //Control.SetTextSize(Android.Util.ComplexUnitType.Dip, element.CustomFontSize);
                    }
                    if (element.CustomFontFamily == "Avenir65")
                    {
                        Graphicss.Typeface font = Graphicss.Typeface.CreateFromAsset(Forms.Context.Assets, "AvenirLTStd-Medium.ttf");
                        Control.Typeface = font;
                    }
                    else if (element.CustomFontFamily == "Avenir45")
                    {
                        Graphicss.Typeface font = Graphicss.Typeface.CreateFromAsset(Forms.Context.Assets, "AvenirLTStd-Book.ttf");
                        Control.Typeface = font;
                    }
                    else
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                var msg = ex.Message;
            }
        }
        protected override void OnElementChanged(ElementChangedEventArgs <TimePicker> e)
        {
            base.OnElementChanged(e);

            element = (CustomTimePicker)this.Element;

            if (Control != null && this.Element != null && !string.IsNullOrEmpty(element.Image))
            {
                Control.Background = AddPickerStyles(element.Image);
            }
        }
        // Setta il FONT_SIZE
        private void SetFont(CustomTimePicker timePicker)
        {
            UIFont uiFont;

            if (timePicker.Font != Font.Default && (uiFont = timePicker.Font.ToUIFont()) != null)
            {
                Control.Font = uiFont;
            }
            else if (timePicker.Font == Font.Default)
            {
                Control.Font = UIFont.SystemFontOfSize(17f);
            }
        }
Exemple #13
0
 protected override void OnElementChanged(ElementChangedEventArgs <TimePicker> e)
 {
     base.OnElementChanged(e);
     try
     {
         CustomTimePicker element = Element as CustomTimePicker;
         if (e.NewElement != null)
         {
             element = Element as CustomTimePicker;
         }
         else
         {
             element = e.OldElement as CustomTimePicker;
         }
         if (Control != null)
         {
             //var element = Element as CustomTimePicker;
             //var textGiven = element.EnterText;
             Control.BorderStyle = UITextBorderStyle.None;
             Control.AdjustsFontSizeToFitWidth = true;
             Control.Layer.CornerRadius        = 10;
             Control.ExclusiveTouch            = true;
             //Control.Text = textGiven;
             Control.TextColor = UIColor.Black;
             if (element.CustomFontFamily == "Avenir65")
             {
                 Control.Font = UIFont.FromName("Avenir LT Std 65 Medium.ttf", 17f);
             }
             else if (element.CustomFontFamily == "Avenir45")
             {
                 Control.Font = UIFont.FromName("Avenir LT Std 45 Book.ttf", 17f);
             }
             else
             {
             }
             if (element.CustomFontSize != 0)
             {
                 UIFont font = Control.Font.WithSize(element.CustomFontSize);
                 Control.Font = font;
             }
             else
             {
             }
         }
     }
     catch (Exception ex)
     {
         var msg = ex.Message;
     }
 }
Exemple #14
0
        public override void Draw(Canvas canvas)
        {
            CustomTimePicker customTimePicker = (CustomTimePicker)this.Element;

            // Create path to clip
            var path = new Path();

            path.AddRoundRect(0, 0, Width, Height, DpToPixels(this.Context, Convert.ToSingle(customTimePicker.CornerRadius)),
                              DpToPixels(this.Context, Convert.ToSingle(customTimePicker.CornerRadius)), Path.Direction.Ccw);

            canvas.Save();
            canvas.ClipPath(path);

            base.Draw(canvas);
        }
Exemple #15
0
        protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs <Xamarin.Forms.TimePicker> e)
        {
            base.OnElementChanged(e);

            CustomTimePicker timePicker = (CustomTimePicker)Element;


            if (e.OldElement == null)
            {
                Control.Background = null;

                var layoutParams = new MarginLayoutParams(Control.LayoutParameters);
                LayoutParameters         = layoutParams;
                Control.LayoutParameters = layoutParams;
            }
        }
Exemple #16
0
        protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (Control == null)
            {
                return;
            }

            CustomTimePicker timePicker = (CustomTimePicker)Element;

            if (e.PropertyName == CustomTimePicker.TextColorProperty.PropertyName)
            {
                this.Control.SetTextColor(timePicker.TextColor.ToAndroid());
            }
        }
        protected override void OnElementChanged(ElementChangedEventArgs <TimePicker> e)
        {
            base.OnElementChanged(e);

            CustomTimePicker timePicker = (CustomTimePicker)Element;

            if (timePicker != null)
            {
                //TOGLIE IL BORDO
                Control.BorderStyle = UITextBorderStyle.None;
                //FONT
                Control.Font = UIFont.FromName("Avenir", 14f);
                SetPlaceholder(timePicker);
                //SetFont(timePicker);
                SetTextColor(timePicker);
            }
        }
        /// <summary>
        /// Fill out the date field with today's date
        /// </summary>
        private void FillOutDate(object parameter)
        {
            var dic = (Dictionary <String, Object>)parameter;

            dic.TryGetValue("text", out var textData);
            TextData text = (TextData)textData;

            dic.TryGetValue("date", out var dateObj);
            CustomDatePicker dateField = (CustomDatePicker)dateObj;

            dic.TryGetValue("time", out var timeObj);
            CustomTimePicker timeField = (CustomTimePicker)timeObj;
            var dt = DateTime.Now;

            dateField.NullableDate = dt.Date;
            timeField.NullableDate = new TimeSpan(dt.TimeOfDay.Hours, dt.TimeOfDay.Minutes, 0);
        }
Exemple #19
0
        public MainPage()
        {
            InitializeComponent();

            CurvedStackLayout curvedStackLayout = new CurvedStackLayout()
            {
                BackgroundColor = Color.White
                , Padding       = 15, Margin = 15
            };



            RoundedRectangle rr = new RoundedRectangle {
                WidthRequest = 100, HeightRequest = 50, Radius = 1, Color = Color.BlueViolet
            };



            curvedStackLayout.Children.Add(new CustomFontLabel
            {
                FontSize = 25,
                FontName = "agencyr",
                Text     = "This is a label with a custom Font"
            });


            CustomDatePicker customDatePicker = new CustomDatePicker {
                Text = "Pick a day"
            };


            CustomTimePicker ctp = new CustomTimePicker(DateTime.Now)
            {
                Text = "Pick a time"
            };



            Editor editor = new Editor
            {
                Text          = "regular editor",
                HeightRequest = 100,
                WidthRequest  = 200
            };


            CustomEditor customEditor = new CustomEditor
            {
                HeightRequest     = 200,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                FontSize          = 25,
                FontName          = "agencyr",
                Text = "This is a custom editor with a custom Font"
            };

            //   curvedStackLayout.Children.Add(editor);

            curvedStackLayout.Children.Add(customEditor);
            curvedStackLayout.Children.Add(new Circle
            {
                Radius            = 20,
                Color             = Color.Black,
                HeightRequest     = 100,
                HorizontalOptions = LayoutOptions.CenterAndExpand
            });



            curvedStackLayout.Children.Add(rr);
            curvedStackLayout.Children.Add(customDatePicker);
            curvedStackLayout.Children.Add(ctp);

            curvedStackLayout.Children.Add(new Calendar {
                HorizontalOptions = LayoutOptions.FillAndExpand, HeightRequest = 200
            });


            Label label = new Label {
                Text = "This is an image from a database"
            };

            curvedStackLayout.Children.Add(label);
            ResourceImage ri = new ResourceImage
            {
                SourceType    = ResourceImage.SourceTypes.Database,
                ResourceName  = "2",
                HeightRequest = 300,
                WidthRequest  = 300
            };

            curvedStackLayout.Children.Add(ri);

            scrollyScroll.Content = curvedStackLayout;
        }
Exemple #20
0
        protected override void OnElementChanged(ElementChangedEventArgs <TimePicker> e)
        {
            base.OnElementChanged(e);

            try
            {
                CustomTimePicker element = Element as CustomTimePicker;
                if (e.NewElement != null)
                {
                    element = Element as CustomTimePicker;
                }
                else
                {
                    element = e.OldElement as CustomTimePicker;
                }

                if (Control != null)
                {
                    #region TimePicker 24H
                    this.SetNativeControl(new Android.Widget.EditText(Forms.Context));
                    this.Control.Click       += Control_Click;
                    this.Control.Text         = "00:00";
                    this.Control.KeyListener  = null;
                    this.Control.FocusChange += Control_FocusChange;

                    #endregion

                    GradientDrawable gd = new GradientDrawable();
                    //gd.SetCornerRadius(45); // increase or decrease to changes the corner look
                    gd.SetColor(global::Android.Graphics.Color.Transparent);
                    //gd.SetStroke(2, global::Android.Graphics.Color.Gray);
                    this.Control.SetBackgroundDrawable(gd);
                    this.Control.SetRawInputType(InputTypes.TextFlagNoSuggestions);
                    if (!string.IsNullOrWhiteSpace(element.EnterText))
                    {
                        Control.Text = element.EnterText;
                    }
                    Control.SetHintTextColor(ColorStateList.ValueOf(global::Android.Graphics.Color.Black));                    //for placeholder
                    //this.Control.InputType = InputTypes.TextVariationPassword;
                    if (element.CustomFontSize != 0.0)
                    {
                        Control.SetTextSize(ComplexUnitType.Dip, element.CustomFontSize);
                        //Control.SetTextSize(Android.Util.ComplexUnitType.Dip, element.CustomFontSize);
                    }
                    if (element.CustomFontFamily == "MontserratBold")
                    {
                        Graphicss.Typeface font = Graphicss.Typeface.CreateFromAsset(Forms.Context.Assets, "Montserrat-Bold.ttf");
                        Control.Typeface = font;
                    }
                    else if (element.CustomFontFamily == "MontserratLight")
                    {
                        Graphicss.Typeface font = Graphicss.Typeface.CreateFromAsset(Forms.Context.Assets, "Montserrat-Light.ttf");
                        Control.Typeface = font;
                    }
                    else
                    {
                        Graphicss.Typeface font = Graphicss.Typeface.CreateFromAsset(Forms.Context.Assets, "Montserrat-Regular.ttf");
                        Control.Typeface = font;
                    }
                }
            }
            catch (Exception ex)
            {
                var msg = ex.Message;
            }
        }
        /// <summary>
        /// On creating the view controller for a specific recordId, the form is checked to see which parameters are required, and the relevant input fields are queued up for adding to the page.
        /// The relevant data is then extracted from the database for the specific field, and added as the initial value for that field.
        /// </summary>
        /// <param name="recId">recordID</param>
        public FormPageVM(int recId)
        {
            using (SQLiteConnection conn = new SQLiteConnection(Preferences.Get("databaseLocation", "")))
            {
                //Get the record and its corresponding variable values
                var queriedrec = conn.GetWithChildren <Record>(recId);
                ReadOnly = queriedrec.readOnly;
                RecId    = recId;
                var txts  = queriedrec.texts;
                var nums  = queriedrec.numerics;
                var bools = queriedrec.booleans;
                //Compile the GUID
                BDCGUIDtext = "<<BDC><" + queriedrec.recordId + ">>";

                var formId   = queriedrec.formId;
                var formTemp = conn.Table <Form>().Where(Form => Form.formId == formId).FirstOrDefault();
                formType = conn.GetWithChildren <Form>(formTemp.Id);
                foreach (var formField in formType.formFields.OrderBy(f => f.order))
                {
                    var label = new Label();
                    if (formField.title != null && formField.title != String.Empty)
                    {
                        label.Text = formField.title;
                    }
                    else
                    {
                        label.Text = formField.description;
                    }
                    if (formField.mandatory)
                    {
                        label.Text = label.Text + " *";
                    }
                    label.FontAttributes = FontAttributes.Bold;
                    label.Margin         = new Thickness(0, 10, 0, 0);
                    label.SetAppThemeColor(Label.TextColorProperty, Color.Black, Color.White);
                    if (formField.typeId != 31) //Add label next to checkbox for boolean
                    {
                        Assets.Add(label);
                    }



                    if (formField.typeId == 11 || formField.typeId == 61)
                    {
                        try
                        {
                            var text      = conn.Table <TextData>().Select(t => t).Where(TextData => TextData.record_fk == RecId).Where(TextData => TextData.formFieldId == formField.fieldId).FirstOrDefault();
                            var textField = new CustomEntry();

                            if (text == null)
                            {
                                //CreateNew
                                var txt = new TextData {
                                    textId = Guid.NewGuid().ToString(), title = String.Empty, value = String.Empty, formFieldId = formField.fieldId, record_fk = recId
                                };
                                conn.Insert(txt);
                                txts.Add(txt);
                                queriedrec.texts = txts;
                                conn.UpdateWithChildren(queriedrec);
                                text = txt;
                            }
                            textField = new CustomEntry {
                                Text = text.value.ToString()
                            };
                            textField.Keyboard              = Keyboard.Text;
                            textField.Placeholder           = formField.description;
                            textField.ClearButtonVisibility = ClearButtonVisibility.WhileEditing;
                            textField.ReturnType            = ReturnType.Done;
                            textField.Margin       = new Thickness(0, 0, 0, 10);
                            textField.ValueId      = text.Id;
                            textField.TypeId       = formField.typeId;
                            textField.TextChanged += TextFieldChanged;
                            textField.IsEnabled    = !ReadOnly;
                            textField.Mandatory    = formField.mandatory;
                            var empty = String.IsNullOrEmpty(textField.Text);
                            if (formField.mandatory)
                            {
                                Validation.Add((int)textField.ValueId, !empty);
                            }
                            if (ReadOnly)
                            {
                                textField.SetAppThemeColor(Label.BackgroundColorProperty, Color.FromRgb(0.95, 0.95, 0.95), Color.FromRgb(0.2, 0.2, 0.2));
                            }
                            Assets.Add(textField);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Could not create field" + e);
                        }
                    }
                    else if (formField.typeId == 41)
                    {
                        try
                        {
                            var text        = conn.Table <TextData>().Select(t => t).Where(TextData => TextData.record_fk == RecId).Where(TextData => TextData.formFieldId == formField.fieldId).Take(1).FirstOrDefault();
                            var dateField   = new CustomDatePicker();
                            var timeField   = new CustomTimePicker();
                            var nowButton   = new Button();
                            var clearButton = new Button();

                            var stack = new CustomStackLayout()
                            {
                                Orientation = StackOrientation.Horizontal,
                                Children    =
                                {
                                    dateField, timeField, nowButton, clearButton
                                }
                            };
                            stack.WidthRequest      = 350;
                            stack.HorizontalOptions = LayoutOptions.Start;

                            if (text == null)
                            {
                                //CreateNew
                                var txt = new TextData {
                                    textId = Guid.NewGuid().ToString(), title = String.Empty, value = String.Empty, formFieldId = formField.fieldId, record_fk = recId
                                };
                                conn.Insert(txt);
                                txts.Add(txt);
                                queriedrec.texts = txts;
                                conn.UpdateWithChildren(queriedrec);
                                text = txt;
                            }
                            List <string> choices = Form.FetchFormChoicesForDropdown(formField.fieldId);

                            try
                            {
                                var dt = DateTime.ParseExact(text.value, "yyyy-MM-ddTHH:mm:sszzz", null);

                                if (text.value != null && text.value != String.Empty)
                                {
                                    dateField.NullableDate = dt.Date;
                                    timeField.NullableDate = new TimeSpan(dt.TimeOfDay.Hours, dt.TimeOfDay.Minutes, 0);
                                }
                            }
                            catch (Exception exp)
                            {
                                Console.WriteLine(exp);
                            }

                            dateField.Margin           = new Thickness(0, 0, 0, 10);
                            dateField.ValueId          = text.Id;
                            dateField.TypeId           = formField.typeId;
                            dateField.Format           = "dd MMMM yyyy";
                            dateField.IsEnabled        = !ReadOnly;
                            dateField.WidthRequest     = 170;
                            dateField.HeightRequest    = 40;
                            dateField.Mandatory        = formField.mandatory;
                            dateField.VerticalOptions  = LayoutOptions.StartAndExpand;
                            dateField.PropertyChanged += DateFieldChanged;
                            var empty = (dateField.NullableDate == null);
                            if (formField.mandatory)
                            {
                                Validation.Add((int)dateField.ValueId, !empty);
                            }
                            if (ReadOnly)
                            {
                                dateField.SetAppThemeColor(Label.BackgroundColorProperty, Color.FromRgb(0.95, 0.95, 0.95), Color.FromRgb(0.2, 0.2, 0.2));
                            }
                            timeField.Margin           = new Thickness(0, 0, 0, 0);
                            timeField.ValueId          = text.Id;
                            timeField.TypeId           = formField.typeId;
                            timeField.Format           = "HH:mm";
                            timeField.IsEnabled        = !ReadOnly;
                            timeField.WidthRequest     = 70;
                            timeField.HeightRequest    = 40;
                            timeField.VerticalOptions  = LayoutOptions.StartAndExpand;
                            timeField.Mandatory        = formField.mandatory;
                            timeField.PropertyChanged += TimeFieldChanged;
                            if (ReadOnly)
                            {
                                timeField.SetAppThemeColor(Label.BackgroundColorProperty, Color.FromRgb(0.95, 0.95, 0.95), Color.FromRgb(0.2, 0.2, 0.2));
                            }


                            Dictionary <String, Object> dic = new Dictionary <string, object>();
                            dic.Add("text", text);
                            dic.Add("date", dateField);
                            dic.Add("time", timeField);

                            var nowCommand = new Command(FillOutDate);

                            nowButton.Text             = "JETZT";
                            nowButton.TextTransform    = TextTransform.Uppercase;
                            nowButton.FontSize         = 12;
                            nowButton.Style            = (Style)Xamarin.Forms.Application.Current.Resources["TransparentButtonStyle"];
                            nowButton.Command          = nowCommand;
                            nowButton.CommandParameter = dic;
                            nowButton.Margin           = new Thickness(10, 0, 0, 0);
                            nowButton.WidthRequest     = 40;
                            nowButton.HeightRequest    = 40;
                            nowButton.VerticalOptions  = LayoutOptions.StartAndExpand;
                            nowButton.IsVisible        = !ReadOnly;

                            var clearCommand = new Command(ClearDate);

                            clearButton.Text             = "ⓧ";
                            clearButton.FontSize         = 20;
                            clearButton.Style            = (Style)Xamarin.Forms.Application.Current.Resources["TransparentButtonStyle"];
                            clearButton.Command          = clearCommand;
                            clearButton.CommandParameter = dic;
                            clearButton.Margin           = new Thickness(10, 0, 10, 0);
                            clearButton.WidthRequest     = 30;
                            clearButton.HeightRequest    = 40;
                            clearButton.VerticalOptions  = LayoutOptions.StartAndExpand;
                            clearButton.IsVisible        = !ReadOnly;

                            stack.Margin  = new Thickness(0, 0, 0, 10);
                            stack.ValueId = text.Id;
                            stack.TypeId  = formField.typeId;

                            Assets.Add(stack);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Could not create field" + e);
                        }
                    }
                    else if (formField.typeId == 51)
                    {
                        try
                        {
                            var text      = conn.Table <TextData>().Select(t => t).Where(TextData => TextData.record_fk == RecId).Where(TextData => TextData.formFieldId == formField.fieldId).Take(1).FirstOrDefault();
                            var textField = new CustomPicker();
                            if (text == null)
                            {
                                //CreateNew
                                var txt = new TextData {
                                    textId = Guid.NewGuid().ToString(), title = String.Empty, value = String.Empty, formFieldId = formField.fieldId, record_fk = recId
                                };
                                conn.Insert(txt);
                                txts.Add(txt);
                                queriedrec.texts = txts;
                                conn.UpdateWithChildren(queriedrec);
                                text = txt;
                            }
                            List <string> choices = Form.FetchFormChoicesForDropdown(formField.Id);
                            textField.ItemsSource = choices;
                            textField.ValueId     = text.Id;
                            textField.TypeId      = formField.Id;
                            textField.Title       = formField.description;
                            textField.IsEnabled   = !ReadOnly;
                            textField.Mandatory   = formField.mandatory;
                            if (formField.mandatory)
                            {
                                Validation.Add((int)textField.ValueId, textField.SelectedItem != null || (text.value != null && text.value != String.Empty));
                            }
                            if (ReadOnly)
                            {
                                textField.SetAppThemeColor(Label.BackgroundColorProperty, Color.FromRgb(0.95, 0.95, 0.95), Color.FromRgb(0.2, 0.2, 0.2));
                            }
                            textField.SelectedIndexChanged += DidSelectFromChoices;

                            if (text.fieldChoiceId != null)
                            {
                                textField.SelectedIndex = choices.FindIndex(a => a.Contains(text.value));
                                if (textField.SelectedIndex == -1 && (text.value != null && text.value != String.Empty))
                                {
                                    textField.Title = text.value;
                                }
                                textField.SelectedItem = text.value;
                            }
                            else if (text.value != null && text.value != String.Empty)
                            {
                                textField.Title = text.value;
                            }
                            textField.Margin = new Thickness(0, 0, 0, 10);

                            Assets.Add(textField);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Could not create field" + e);
                        }
                    }
                    else if (formField.typeId == 21)
                    {
                        try
                        {
                            var num       = conn.Table <NumericData>().Select(n => n).Where(NumericData => NumericData.record_fk == RecId).Where(NumericData => NumericData.formFieldId == formField.fieldId).Take(1).FirstOrDefault();
                            var textField = new CustomEntry();
                            if (num == null)
                            {
                                //CreateNew
                                var nm = new NumericData {
                                    numericId = Guid.NewGuid().ToString(), title = String.Empty, value = null, formFieldId = formField.fieldId, record_fk = recId
                                };
                                conn.Insert(nm);
                                nums.Add(nm);
                                queriedrec.texts = txts;
                                conn.UpdateWithChildren(queriedrec);
                                num = nm;
                            }

                            textField = new CustomEntry {
                                Text = ((double)num.value).ToString("F", CultureInfo.CreateSpecificCulture("de-CH"))
                            };
                            textField.Keyboard = Keyboard.Numeric;
                            textField.ClearButtonVisibility = ClearButtonVisibility.WhileEditing;
                            textField.ReturnType            = ReturnType.Done;
                            textField.Margin    = new Thickness(0, 0, 0, 10);
                            textField.ValueId   = num.Id;
                            textField.TypeId    = formField.typeId;
                            textField.IsEnabled = !ReadOnly;
                            textField.Mandatory = formField.mandatory;
                            var empty = String.IsNullOrEmpty(textField.Text);
                            if (formField.mandatory)
                            {
                                Validation.Add((int)textField.ValueId, !empty);
                            }
                            if (ReadOnly)
                            {
                                textField.SetAppThemeColor(Label.BackgroundColorProperty, Color.FromRgb(0.95, 0.95, 0.95), Color.FromRgb(0.2, 0.2, 0.2));
                            }
                            textField.TextChanged += NumericFieldChanged;
                            Assets.Add(textField);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Could not create field" + e);
                        }
                    }
                    else if (formField.typeId == 31)
                    {
                        try
                        {
                            var boolValue = conn.Table <BooleanData>().Select(n => n).Where(BooleanData => BooleanData.record_fk == RecId).Where(BooleanData => BooleanData.formFieldId == formField.fieldId).Take(1).FirstOrDefault();
                            var checkBox  = new CustomCheckBox();
                            if (boolValue == null)
                            {
                                //CreateNew
                                boolValue = new BooleanData {
                                    booleanId = Guid.NewGuid().ToString(), title = String.Empty, value = false, formFieldId = formField.fieldId, record_fk = recId
                                };
                                conn.Insert(boolValue);
                                bools.Add(boolValue);
                                queriedrec.booleans = bools;
                                conn.UpdateWithChildren(queriedrec);
                            }
                            if (boolValue != null)
                            {
                                checkBox.IsChecked = (bool)boolValue.value;
                            }
                            checkBox.Margin    = new Thickness(0, 0, 0, 0);
                            checkBox.ValueId   = boolValue.Id;
                            checkBox.TypeId    = formField.typeId;
                            checkBox.IsEnabled = !ReadOnly;
                            if (ReadOnly)
                            {
                                checkBox.Color = Color.LightGray;
                            }
                            checkBox.CheckedChanged    += BooleanFieldChanged;
                            checkBox.VerticalOptions    = LayoutOptions.Fill;
                            checkBox.HorizontalOptions  = LayoutOptions.Start;
                            label.VerticalOptions       = LayoutOptions.Fill;
                            label.VerticalTextAlignment = TextAlignment.Center;
                            label.Margin = new Thickness(0, 0, 0, 0);
                            var stack = new CustomStackLayout()
                            {
                                Orientation       = StackOrientation.Horizontal,
                                HorizontalOptions = LayoutOptions.Start,
                                VerticalOptions   = LayoutOptions.Fill,
                                Children          =
                                {
                                    checkBox, label
                                }
                            };
                            stack.Margin = new Thickness(0, 0, 0, 10);
                            Assets.Add(stack);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Could not create field" + e);
                        }
                    }
                }

                var geomlabel = new Label();
                geomlabel.Text           = "Zugeordnete Geometrie";
                geomlabel.FontAttributes = FontAttributes.Bold;
                geomlabel.Margin         = new Thickness(0, 10, 0, 0);
                Assets.Add(geomlabel);

                AssociatedGeometry = new CustomPicker();
                Geoms = ReferenceGeometry.GetAllGeometries().Where(g => g.status < 3).OrderBy(g => g.geometryName).ToList();
                foreach (var gm in Geoms)
                {
                    if (gm.geometryName == null)
                    {
                        gm.geometryName = String.Empty; //Avoid a crash on android from null strings
                    }
                }
                var general = new ReferenceGeometry()
                {
                    geometryName = "Allgemeine Beobachtung"
                };
                AssociatedGeometry.ItemsSource = Geoms;
                AssociatedGeometry.ItemsSource.Insert(0, general);
                AssociatedGeometry.ItemDisplayBinding = new Binding("geometryName");
                AssociatedGeometry.TypeId             = -999;

                if (queriedrec.geometry_fk != null)
                {
                    var geom = ReferenceGeometry.GetGeometry((int)queriedrec.geometry_fk);
                    var selectedGeomIndex = Geoms.FindIndex(a => a.Id == geom.Id);
                    AssociatedGeometry.SelectedIndex = selectedGeomIndex++;
                }
                else
                {
                    AssociatedGeometry.SelectedIndex = 0;
                }
                AssociatedGeometry.Margin    = new Thickness(0, 0, 0, 10);
                AssociatedGeometry.IsEnabled = !ReadOnly;
                if (ReadOnly)
                {
                    AssociatedGeometry.SetAppThemeColor(Label.BackgroundColorProperty, Color.FromRgb(0.95, 0.95, 0.95), Color.FromRgb(0.2, 0.2, 0.2));
                }
                AssociatedGeometry.SelectedIndexChanged += DidSelectNewGeometry;

                Assets.Add(AssociatedGeometry);
            }

            var DeleteButton = new Button();

            DeleteCommand              = new Command(OnDelete, ValidateDelete);
            DeleteButton.ImageSource   = "delete.png";
            DeleteButton.Command       = DeleteCommand;
            DeleteButton.Style         = (Style)Xamarin.Forms.Application.Current.Resources["DangerButtonStyle"];
            DeleteButton.Margin        = new Thickness(0, 10);
            DeleteButton.CornerRadius  = 10;
            DeleteButton.TextTransform = TextTransform.Uppercase;
            DeleteButton.WidthRequest  = 50;
            var GUIDButton = new Button();

            GUIDCommand                  = new Command(CopyGUID);
            GUIDButton.Text              = "GUID";
            GUIDButton.BackgroundColor   = (Color)Xamarin.Forms.Application.Current.Resources["BioDivGreen"];
            GUIDButton.Command           = GUIDCommand;
            GUIDButton.HorizontalOptions = LayoutOptions.FillAndExpand;
            GUIDButton.TextColor         = Color.White;
            GUIDButton.Margin            = new Thickness(0, 10);
            GUIDButton.CornerRadius      = 10;
            GUIDButton.TextTransform     = TextTransform.Uppercase;
            GUIDButton.WidthRequest      = 250;
            var buttonLayout = new FlexLayout
            {
                Children =
                {
                    DeleteButton, GUIDButton
                }
            };

            buttonLayout.Direction         = FlexDirection.Row;
            buttonLayout.JustifyContent    = FlexJustify.SpaceAround;
            buttonLayout.HorizontalOptions = LayoutOptions.FillAndExpand;
            buttonLayout.AlignContent      = FlexAlignContent.SpaceAround;

            Assets.Add(buttonLayout);

            SaveCommand           = new Command(OnSave, ValidateSave);
            CancelCommand         = new Command(OnCancel);
            this.PropertyChanged +=
                (_, __) => SaveCommand.ChangeCanExecute();
        }
 void SetTextColor(CustomTimePicker timePicker)
 {
     this.Control.TextColor = timePicker.TextColor.ToUIColor();
 }
Exemple #23
0
 void SetTextColor(CustomTimePicker timePicker)
 {
     this.Control.SetTextColor(timePicker.TextColor.ToAndroid());
 }
Exemple #24
0
 void SetPlaceholder(CustomTimePicker timePicker)
 {
     this.Control.Text = timePicker.PlaceHolder;
 }