Inheritance: DateTimeElement
        public override void ViewDidLoad()
        {

            base.ViewDidLoad();
            
            // Perform any additional setup after loading the view
            var info = new RootElement("Info") {
                new Section() {
                    { eventname = new EntryElement("Event Name", "Enter the Name", null) },
                    { recipients = new EntryElement("Recipients' Names", "Enter the Recipients", null) },
                    { location = new EntryElement("Enter Location", "Enter the Location", null) }
                },

                new Section()
                {
                    { date = new DateElement("Pick the Date", DateTime.Now) },
                    { timeelement = new TimeElement("Pick the Time", DateTime.Now) },
                    { description = new EntryElement("Description", "Enter a Description", null) }
                },

                new Section()
                {
                    new RootElement("Type", category = new RadioGroup("Type of Event", 0)) {
                        new Section() {
                            new RadioElement ("Meeting", "Type of Event"),
                            new RadioElement ("Company Event", "Type of Event"),
                            new RadioElement ("Machine Maintenance", "Type of Event"),
                            new RadioElement ("Emergency", "Type of Event")
                        }
                    },
                    
                    new RootElement("Priority", priority = new RadioGroup ("priority", 0))
                    {
                        new Section()
                        {
                            new RadioElement("Low", "priority"),
                            new RadioElement("Medium", "priority"), 
                            new RadioElement("High", "priority")
                        }
                    }
                },
            };

            Root.Add(info);

            UIButton createEventBtn = UIButton.FromType(UIButtonType.RoundedRect);
            createEventBtn.SetTitle("Add Event", UIControlState.Normal);
            createEventBtn.Frame = new Rectangle(0, 0, 320, 44);
            int y = (int)((View.Frame.Size.Height - createEventBtn.Frame.Size.Height)/1.15);
            int x = ((int)(View.Frame.Size.Width - createEventBtn.Frame.Size.Width)) / 2;
            createEventBtn.Frame = new Rectangle(x, y, (int)createEventBtn.Frame.Width, (int)createEventBtn.Frame.Height);
            View.AddSubview(createEventBtn);


            createEventBtn.TouchUpInside += async (object sender, EventArgs e) =>
            {
                await createEvent(info);
            };
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            var title = expense == null ? "New Expense" : "Edit Expense";
            this.Root = new RootElement(title)
              {
            new Section("Expense Details")
            {
              (name = new EntryElement("Name", "Expense Name", string.Empty)),
              (total = new EntryElement("Total", "1.00", string.Empty){KeyboardType = UIKeyboardType.DecimalPad}),
              (billable = new CheckboxElement("Billable", true)),
              new RootElement("Category", categories = new RadioGroup("category", 0))
              {
            new Section()
            {
              from category in viewModel.Categories
                select (Element) new RadioElement(category)
            }
              },
              (due = new DateElement("Due Date", DateTime.Now))
            },
            new Section("Notes")
            {
              (notes = new EntryElement(string.Empty, "Enter expense notes.", string.Empty))
            }

              };

            billable.Value = viewModel.Billable;
            name.Value = viewModel.Name;
            total.Value = viewModel.Total;
            notes.Caption = viewModel.Notes;
            categories.Selected = viewModel.Categories.IndexOf(viewModel.Category);
            due.DateValue = viewModel.Due;

            this.NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Save, async delegate
            {
                viewModel.Category = viewModel.Categories[categories.Selected];
                viewModel.Name = name.Value;
                viewModel.Billable = billable.Value;
                viewModel.Due = due.DateValue;
                viewModel.Notes = notes.Caption;
                viewModel.Total = total.Value;

                await viewModel.ExecuteSaveExpenseCommand();
                if (!viewModel.CanNavigate)
                    return;
                NavigationController.PopToRootViewController(true);

            });
        }
Exemple #3
0
		void Populate (object callbacks, object o, RootElement root)
		{
			MemberInfo last_radio_index = null;
			
			BindingFlags flags = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance;
			if (Attribute.GetCustomAttribute(o.GetType (), typeof(SkipNonPublicAttribute)) == null)
				flags |= BindingFlags.NonPublic;
			var members = o.GetType ().GetMembers (flags);

			Section section = null;
			
			foreach (var mi in members){
				Type mType = GetTypeForMember (mi);

				if (mType == null)
					continue;

				string caption = null;
				object [] attrs = mi.GetCustomAttributes (false);
				bool skip = false;
				foreach (var attr in attrs){
					if (attr is SkipAttribute)
						skip = true;
					if (attr is CaptionAttribute)
						caption = ((CaptionAttribute) attr).Caption;
					else if (attr is SectionAttribute){
						if (section != null)
							root.Add (section);
						var sa = attr as SectionAttribute;
						section = new Section (sa.Caption, sa.Footer);
					}
				}
				if (skip)
					continue;
				
				if (caption == null)
					caption = MakeCaption (mi.Name);
				
				if (section == null)
					section = new Section ();
				
				Element element = null;
				if (mType == typeof (string)){
					PasswordAttribute pa = null;
					AlignmentAttribute align = null;
					EntryAttribute ea = null;
					object html = null;
					NSAction invoke = null;
					bool multi = false;
					
					foreach (object attr in attrs){
						if (attr is PasswordAttribute)
							pa = attr as PasswordAttribute;
						else if (attr is EntryAttribute)
							ea = attr as EntryAttribute;
						else if (attr is MultilineAttribute)
							multi = true;
						else if (attr is HtmlAttribute)
							html = attr;
						else if (attr is AlignmentAttribute)
							align = attr as AlignmentAttribute;
						
						if (attr is OnTapAttribute){
							string mname = ((OnTapAttribute) attr).Method;
							
							if (callbacks == null){
								throw new Exception ("Your class contains [OnTap] attributes, but you passed a null object for `context' in the constructor");
							}
							
							var method = callbacks.GetType ().GetMethod (mname);
							if (method == null)
								throw new Exception ("Did not find method " + mname);
							invoke = delegate {
								method.Invoke (method.IsStatic ? null : callbacks, new object [0]);
							};
						}
					}
					
					string value = (string) GetValue (mi, o);
					if (pa != null)
						element = new EntryElement (caption, pa.Placeholder, value, true);
					else if (ea != null)
						element = new EntryElement (caption, ea.Placeholder, value) { KeyboardType = ea.KeyboardType };
					else if (multi)
						element = new MultilineElement (caption, value);
					else if (html != null)
						element = new HtmlElement (caption, value);
					else {
						var selement = new StringElement (caption, value);
						element = selement;
						
						if (align != null)
							selement.Alignment = align.Alignment;
					}
					
					if (invoke != null)
						((StringElement) element).Tapped += invoke;
				} else if (mType == typeof (float)){
					var floatElement = new FloatElement (null, null, (float) GetValue (mi, o));
					floatElement.Caption = caption;
					element = floatElement;
					
					foreach (object attr in attrs){
						if (attr is RangeAttribute){
							var ra = attr as RangeAttribute;
							floatElement.MinValue = ra.Low;
							floatElement.MaxValue = ra.High;
							floatElement.ShowCaption = ra.ShowCaption;
						}
					}
				} else if (mType == typeof (bool)){
					bool checkbox = false;
					foreach (object attr in attrs){
						if (attr is CheckboxAttribute)
							checkbox = true;
					}
					
					if (checkbox)
						element = new CheckboxElement (caption, (bool) GetValue (mi, o));
					else
						element = new BooleanElement (caption, (bool) GetValue (mi, o));
				} else if (mType == typeof (DateTime)){
					var dateTime = (DateTime) GetValue (mi, o);
					bool asDate = false, asTime = false;
					
					foreach (object attr in attrs){
						if (attr is DateAttribute)
							asDate = true;
						else if (attr is TimeAttribute)
							asTime = true;
					}
					
					if (asDate)
						element = new DateElement (caption, dateTime);
					else if (asTime)
						element = new TimeElement (caption, dateTime);
					else
						 element = new DateTimeElement (caption, dateTime);
				} else if (mType.IsEnum){
					var csection = new Section ();
					ulong evalue = Convert.ToUInt64 (GetValue (mi, o), null);
					int idx = 0;
					int selected = 0;
					
					foreach (var fi in mType.GetFields (BindingFlags.Public | BindingFlags.Static)){
						ulong v = Convert.ToUInt64 (GetValue (fi, null));
						
						if (v == evalue)
							selected = idx;
						
						csection.Add (new RadioElement (MakeCaption (fi.Name)));
						idx++;
					}
					
					element = new RootElement (caption, new RadioGroup (null, selected)) { csection };
				} else if (mType == typeof (UIImage)){
					element = new ImageElement ((UIImage) GetValue (mi, o));
				} else if (typeof (System.Collections.IEnumerable).IsAssignableFrom (mType)){
					var csection = new Section ();
					int count = 0;
					
					if (last_radio_index == null)
						throw new Exception ("IEnumerable found, but no previous int found");
					foreach (var e in (IEnumerable) GetValue (mi, o)){
						csection.Add (new RadioElement (e.ToString ()));
						count++;
					}
					int selected = (int) GetValue (last_radio_index, o);
					if (selected >= count || selected < 0)
						selected = 0;
					element = new RootElement (caption, new MemberRadioGroup (null, selected, last_radio_index)) { csection };
					last_radio_index = null;
				} else if (typeof (int) == mType){
					foreach (object attr in attrs){
						if (attr is RadioSelectionAttribute){
							last_radio_index = mi;
							break;
						}
					}
				} else {
					var nested = GetValue (mi, o);
					if (nested != null){
						var newRoot = new RootElement (caption);
						Populate (callbacks, nested, newRoot);
						element = newRoot;
					}
				}
				
				if (element == null)
					continue;
				section.Add (element);
				mappings [element] = new MemberAndInstance (mi, o);
			}
			root.Add (section);
		}
Exemple #4
0
        void Populate(object callbacks, object o, RootElement root)
        {
            MemberInfo last_radio_index = null;
            var        members          = o.GetType().GetMembers(BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                                 BindingFlags.NonPublic | BindingFlags.Instance);

            Section section = null;

            foreach (var mi in members)
            {
                Type mType = GetTypeForMember(mi);

                if (mType == null)
                {
                    continue;
                }

                string    caption = null;
                object [] attrs   = mi.GetCustomAttributes(false);
                bool      skip    = false;
                foreach (var attr in attrs)
                {
                    if (attr is SkipAttribute || attr is System.Runtime.CompilerServices.CompilerGeneratedAttribute)
                    {
                        skip = true;
                    }
                    else if (attr is CaptionAttribute)
                    {
                        caption = ((CaptionAttribute)attr).Caption;
                    }
                    else if (attr is SectionAttribute)
                    {
                        if (section != null)
                        {
                            root.Add(section);
                        }
                        var sa = attr as SectionAttribute;
                        section = new Section(sa.Caption, sa.Footer);
                    }
                }
                if (skip)
                {
                    continue;
                }

                if (caption == null)
                {
                    caption = MakeCaption(mi.Name);
                }

                if (section == null)
                {
                    section = new Section();
                }

                Element element = null;
                if (mType == typeof(string))
                {
                    PasswordAttribute  pa     = null;
                    AlignmentAttribute align  = null;
                    EntryAttribute     ea     = null;
                    object             html   = null;
                    NSAction           invoke = null;
                    bool multi = false;

                    foreach (object attr in attrs)
                    {
                        if (attr is PasswordAttribute)
                        {
                            pa = attr as PasswordAttribute;
                        }
                        else if (attr is EntryAttribute)
                        {
                            ea = attr as EntryAttribute;
                        }
                        else if (attr is MultilineAttribute)
                        {
                            multi = true;
                        }
                        else if (attr is HtmlAttribute)
                        {
                            html = attr;
                        }
                        else if (attr is AlignmentAttribute)
                        {
                            align = attr as AlignmentAttribute;
                        }

                        if (attr is OnTapAttribute)
                        {
                            string mname = ((OnTapAttribute)attr).Method;

                            if (callbacks == null)
                            {
                                throw new Exception("Your class contains [OnTap] attributes, but you passed a null object for `context' in the constructor");
                            }

                            var method = callbacks.GetType().GetMethod(mname);
                            if (method == null)
                            {
                                throw new Exception("Did not find method " + mname);
                            }
                            invoke = delegate {
                                method.Invoke(method.IsStatic ? null : callbacks, new object [0]);
                            };
                        }
                    }

                    string value = (string)GetValue(mi, o);
                    if (pa != null)
                    {
                        element = new EntryElement(caption, pa.Placeholder, value, true);
                    }
                    else if (ea != null)
                    {
                        element = new EntryElement(caption, ea.Placeholder, value)
                        {
                            KeyboardType = ea.KeyboardType, AutocapitalizationType = ea.AutocapitalizationType, AutocorrectionType = ea.AutocorrectionType, ClearButtonMode = ea.ClearButtonMode
                        }
                    }
                    ;
                    else if (multi)
                    {
                        element = new MultilineElement(caption, value);
                    }
                    else if (html != null)
                    {
                        element = new HtmlElement(caption, value);
                    }
                    else
                    {
                        var selement = new StringElement(caption, value);
                        element = selement;

                        if (align != null)
                        {
                            selement.Alignment = align.Alignment;
                        }
                    }

                    if (invoke != null)
                    {
                        ((StringElement)element).Tapped += invoke;
                    }
                }
                else if (mType == typeof(float))
                {
                    var floatElement = new FloatElement(null, null, (float)GetValue(mi, o));
                    floatElement.Caption = caption;
                    element = floatElement;

                    foreach (object attr in attrs)
                    {
                        if (attr is RangeAttribute)
                        {
                            var ra = attr as RangeAttribute;
                            floatElement.MinValue    = ra.Low;
                            floatElement.MaxValue    = ra.High;
                            floatElement.ShowCaption = ra.ShowCaption;
                        }
                    }
                }
                else if (mType == typeof(bool))
                {
                    bool checkbox = false;
                    foreach (object attr in attrs)
                    {
                        if (attr is CheckboxAttribute)
                        {
                            checkbox = true;
                        }
                    }

                    if (checkbox)
                    {
                        element = new CheckboxElement(caption, (bool)GetValue(mi, o));
                    }
                    else
                    {
                        element = new BooleanElement(caption, (bool)GetValue(mi, o));
                    }
                }
                else if (mType == typeof(DateTime))
                {
                    var  dateTime = (DateTime)GetValue(mi, o);
                    bool asDate = false, asTime = false;

                    foreach (object attr in attrs)
                    {
                        if (attr is DateAttribute)
                        {
                            asDate = true;
                        }
                        else if (attr is TimeAttribute)
                        {
                            asTime = true;
                        }
                    }

                    if (asDate)
                    {
                        element = new DateElement(caption, dateTime);
                    }
                    else if (asTime)
                    {
                        element = new TimeElement(caption, dateTime);
                    }
                    else
                    {
                        element = new DateTimeElement(caption, dateTime);
                    }
                }
                else if (mType.IsEnum)
                {
                    var   csection = new Section();
                    ulong evalue   = Convert.ToUInt64(GetValue(mi, o), null);
                    int   idx      = 0;
                    int   selected = 0;

                    foreach (var fi in mType.GetFields(BindingFlags.Public | BindingFlags.Static))
                    {
                        ulong v = Convert.ToUInt64(GetValue(fi, null));

                        if (v == evalue)
                        {
                            selected = idx;
                        }

                        CaptionAttribute ca = Attribute.GetCustomAttribute(fi, typeof(CaptionAttribute)) as CaptionAttribute;
                        csection.Add(new RadioElement(ca != null ? ca.Caption : MakeCaption(fi.Name)));
                        idx++;
                    }

                    element = new RootElement(caption, new RadioGroup(null, selected))
                    {
                        csection
                    };
                }
                else if (mType == typeof(UIImage))
                {
                    element = new ImageElement((UIImage)GetValue(mi, o));
                }
                else if (typeof(System.Collections.IEnumerable).IsAssignableFrom(mType))
                {
                    var csection = new Section();
                    int count    = 0;

                    if (last_radio_index == null)
                    {
                        throw new Exception("IEnumerable found, but no previous int found");
                    }
                    foreach (var e in (IEnumerable)GetValue(mi, o))
                    {
                        csection.Add(new RadioElement(e.ToString()));
                        count++;
                    }
                    int selected = (int)GetValue(last_radio_index, o);
                    if (selected >= count || selected < 0)
                    {
                        selected = 0;
                    }
                    element = new RootElement(caption, new MemberRadioGroup(null, selected, last_radio_index))
                    {
                        csection
                    };
                    last_radio_index = null;
                }
                else if (typeof(int) == mType)
                {
                    foreach (object attr in attrs)
                    {
                        if (attr is RadioSelectionAttribute)
                        {
                            last_radio_index = mi;
                            break;
                        }
                    }
                }
                else
                {
                    var nested = GetValue(mi, o);
                    if (nested != null)
                    {
                        var newRoot = new RootElement(caption);
                        Populate(callbacks, nested, newRoot);
                        element = newRoot;
                    }
                }

                if (element == null)
                {
                    continue;
                }
                section.Add(element);
                mappings [element] = new MemberAndInstance(mi, o);
            }
            root.Add(section);
        }
Exemple #5
0
        private void BuildElementPropertyMap()
        {
            _ElementPropertyMap = new Dictionary <Type, Func <MemberInfo, string, object, List <Binding>, Element> >();
            _ElementPropertyMap.Add(typeof(MethodInfo), (member, caption, dataContext, bindings) =>
            {
                Element element = null;

                var buttonAttribute = member.GetCustomAttribute <ButtonAttribute>();
                if (buttonAttribute != null)
                {
                    element = new ButtonElement(caption)
                    {
                        BackgroundColor = buttonAttribute.BackgroundColor,
                        TextColor       = buttonAttribute.TextColor,
                        Command         = GetCommandForMember(dataContext, member)
                    };
                }

                return(element);
            });

            _ElementPropertyMap.Add(typeof(CLLocationCoordinate2D), (member, caption, dataContext, bindings) =>
            {
                Element element = null;

                var mapAttribute = member.GetCustomAttribute <MapAttribute>();
                var location     = (CLLocationCoordinate2D)GetValue(member, dataContext);
                if (mapAttribute != null)
                {
                    element = new MapElement(mapAttribute.Caption, mapAttribute.Value, location);
                }

                return(element);
            });

            _ElementPropertyMap.Add(typeof(string), (member, caption, dataContext, bindings) =>
            {
                Element element = null;

                var passwordAttribute  = member.GetCustomAttribute <PasswordAttribute>();
                var entryAttribute     = member.GetCustomAttribute <EntryAttribute>();
                var multilineAttribute = member.GetCustomAttribute <MultilineAttribute>();
                var htmlAttribute      = member.GetCustomAttribute <HtmlAttribute>();
                var alignmentAttribute = member.GetCustomAttribute <AlignmentAttribute>();

                if (passwordAttribute != null)
                {
                    element = new EntryElement(caption, passwordAttribute.Placeholder, true);
                }
                else if (entryAttribute != null)
                {
                    element = new EntryElement(caption, entryAttribute.Placeholder)
                    {
                        KeyboardType = entryAttribute.KeyboardType
                    }
                }
                ;
                else if (multilineAttribute != null)
                {
                    element = new MultilineElement(caption);
                }
                else if (htmlAttribute != null)
                {
                    SetDefaultConverter(member, "Value", new UriConverter(), bindings);
                    element = new HtmlElement(caption);
                }
                else
                {
                    var selement = new StringElement(caption, (string)GetValue(member, dataContext));

                    if (alignmentAttribute != null)
                    {
                        selement.Alignment = alignmentAttribute.Alignment;
                    }

                    element = selement;
                }

                var tappable = element as ITappable;
                if (tappable != null)
                {
                    ((ITappable)element).Command = GetCommandForMember(dataContext, member);
                }

                return(element);
            });

            _ElementPropertyMap.Add(typeof(float), (member, caption, dataContext, bindings) =>
            {
                Element element    = null;
                var rangeAttribute = member.GetCustomAttribute <RangeAttribute>();
                if (rangeAttribute != null)
                {
                    var floatElement = new FloatElement()
                    {
                    };
                    floatElement.Caption = caption;
                    element = floatElement;

                    floatElement.MinValue    = rangeAttribute.Low;
                    floatElement.MaxValue    = rangeAttribute.High;
                    floatElement.ShowCaption = rangeAttribute.ShowCaption;
                }
                else
                {
                    var entryAttribute = member.GetCustomAttribute <EntryAttribute>();
                    var placeholder    = "";
                    var keyboardType   = UIKeyboardType.NumberPad;

                    if (entryAttribute != null)
                    {
                        placeholder = entryAttribute.Placeholder;
                        if (entryAttribute.KeyboardType != UIKeyboardType.Default)
                        {
                            keyboardType = entryAttribute.KeyboardType;
                        }
                    }

                    element = new EntryElement(caption, placeholder, "")
                    {
                        KeyboardType = keyboardType
                    };
                }

                return(element);
            });

            _ElementPropertyMap.Add(typeof(Uri), (member, caption, dataContext, bindings) =>
            {
                return(new HtmlElement(caption, (Uri)GetValue(member, dataContext)));
            });

            _ElementPropertyMap.Add(typeof(bool), (member, caption, dataContext, bindings) =>
            {
                Element element = null;

                var checkboxAttribute = member.GetCustomAttribute <CheckboxAttribute>();
                if (checkboxAttribute != null)
                {
                    element = new CheckboxElement(caption)
                    {
                    }
                }
                ;
                else
                {
                    element = new BooleanElement(caption)
                    {
                    }
                };

                return(element);
            });

            _ElementPropertyMap.Add(typeof(DateTime), (member, caption, dataContext, bindings) =>
            {
                Element element = null;

                var dateAttribute = member.GetCustomAttribute <DateAttribute>();
                var timeAttribute = member.GetCustomAttribute <TimeAttribute>();

                if (dateAttribute != null)
                {
                    element = new DateElement(caption);
                }
                else if (timeAttribute != null)
                {
                    element = new TimeElement(caption);
                }
                else
                {
                    element = new DateTimeElement(caption);
                }

                return(element);
            });

            _ElementPropertyMap.Add(typeof(UIImage), (member, caption, dataContext, bindings) =>
            {
                return(new ImageElement());
            });

            _ElementPropertyMap.Add(typeof(int), (member, caption, dataContext, bindings) =>
            {
                return(new StringElement(caption)
                {
                    Value = GetValue(member, dataContext).ToString()
                });
            });
        }
		private void BuildElementPropertyMap()
		{
			_ElementPropertyMap = new Dictionary<Type, Func<MemberInfo, string, object, List<Binding>, Element>>();
			_ElementPropertyMap.Add(typeof(MethodInfo), (member, caption, dataContext, bindings)=>
			{
				Element element = null;
	
				var buttonAttribute = member.GetCustomAttribute<ButtonAttribute>();
				if (buttonAttribute != null)
				{	
					element = new ButtonElement(caption)
					{
						BackgroundColor = buttonAttribute.BackgroundColor,
						TextColor = buttonAttribute.TextColor,
						Command = GetCommandForMember(dataContext, member)
					};
				}

				return element;
			});

			_ElementPropertyMap.Add(typeof(CLLocationCoordinate2D), (member, caption, dataContext, bindings)=>
			{
				Element element = null;
		
				var mapAttribute = member.GetCustomAttribute<MapAttribute>();
				var location = (CLLocationCoordinate2D)GetValue(member, dataContext);
				if (mapAttribute != null)
					element = new MapElement(mapAttribute.Caption, mapAttribute.Value, location);

				return element;
			});

			_ElementPropertyMap.Add(typeof(string), (member, caption, dataContext, bindings)=>
			{
				Element element = null;
	
				var passwordAttribute = member.GetCustomAttribute<PasswordAttribute>();
				var entryAttribute = member.GetCustomAttribute<EntryAttribute>();
				var multilineAttribute = member.GetCustomAttribute<MultilineAttribute>();
				var htmlAttribute = member.GetCustomAttribute<HtmlAttribute>();
				var alignmentAttribute = member.GetCustomAttribute<AlignmentAttribute>();
		
				if (passwordAttribute != null)
					element = new EntryElement(caption, passwordAttribute.Placeholder, true);
				else if (entryAttribute != null)
					element = new EntryElement(caption, entryAttribute.Placeholder) { KeyboardType = entryAttribute.KeyboardType };
				else if (multilineAttribute != null)
					element = new MultilineElement(caption);
				else if (htmlAttribute != null)
				{
					SetDefaultConverter(member, "Value", new UriConverter(), bindings);
					element = new HtmlElement(caption);
				}
				else
				{
					var selement = new StringElement(caption, (string)GetValue(member, dataContext));
					
					if (alignmentAttribute != null)
						selement.Alignment = alignmentAttribute.Alignment;
					
					element = selement;
				}

				var tappable = element as ITappable;
				if (tappable != null)
					((ITappable)element).Command = GetCommandForMember(dataContext, member);
				
				return element;
			});

			_ElementPropertyMap.Add(typeof(float), (member, caption, dataContext, bindings)=>
			{
				Element element = null;
				var rangeAttribute = member.GetCustomAttribute<RangeAttribute>();
				if (rangeAttribute != null)
				{
					var floatElement = new FloatElement() {  };
					floatElement.Caption = caption;
					element = floatElement;
					
					floatElement.MinValue = rangeAttribute.Low;
					floatElement.MaxValue = rangeAttribute.High;
					floatElement.ShowCaption = rangeAttribute.ShowCaption;
				}
				else 
				{		
					var entryAttribute = member.GetCustomAttribute<EntryAttribute>();
					var placeholder = "";
					var keyboardType = UIKeyboardType.NumberPad;

					if(entryAttribute != null)
					{
						placeholder = entryAttribute.Placeholder;
						if(entryAttribute.KeyboardType != UIKeyboardType.Default)
							keyboardType = entryAttribute.KeyboardType;
					}

					element = new EntryElement(caption, placeholder, "") { KeyboardType = keyboardType };
				}

				return element;
			});
			
			_ElementPropertyMap.Add(typeof(Uri), (member, caption, dataContext, bindings)=>
			{
				return new HtmlElement(caption, (Uri)GetValue(member, dataContext));  
			});

			_ElementPropertyMap.Add(typeof(bool), (member, caption, dataContext, bindings)=>
			{
				Element element = null;

				var checkboxAttribute = member.GetCustomAttribute<CheckboxAttribute>();
				if (checkboxAttribute != null)
				    element = new CheckboxElement(caption) {  };
				else
					element = new BooleanElement(caption) {  };

				return element;
			});

			_ElementPropertyMap.Add(typeof(DateTime), (member, caption, dataContext, bindings)=>
			{
				Element element = null;

				var dateAttribute = member.GetCustomAttribute<DateAttribute>();
				var timeAttribute = member.GetCustomAttribute<TimeAttribute>();

				if(dateAttribute != null)
					element = new DateElement(caption);
				else if (timeAttribute != null)
					element = new TimeElement(caption);
				else
					element = new DateTimeElement(caption);
				
				return element;
			});

			_ElementPropertyMap.Add(typeof(UIImage),(member, caption, dataContext, bindings)=>
			{
				return new ImageElement();
			});

			_ElementPropertyMap.Add(typeof(int), (member, caption, dataContext, bindings)=>
			{
				return new StringElement(caption) { Value = GetValue(member, dataContext).ToString() };
			});
		}
Exemple #7
0
        public Cultivation(int num, SQLiteConnection s)
            : base(UITableViewStyle.Grouped, null)
        {
            sql = s;
            sql.CreateTable<CultivationData> ();

            fieldID = num;

            date = new DateElement (null, DateTime.Today);
            implement = new EntryElement (null, "Which implement was used?", null);
            depth = new FloatElementEx (0);

            notes = new SimpleMultilineEntryElement (null, null);

            depth.UseCaptionForValueDisplay = true;
            depth.ShowCaption = true;
            depth.MinValue = 0;
            depth.MaxValue = 2;

            implement.ShouldReturn += delegate {
                implement.ResignFirstResponder (true);
                return true;
            };

            notes.Editable = true;

            this.Title = "Cultivation";
            this.Pushing = true;
            this.NavigationItem.SetRightBarButtonItem (
                new UIBarButtonItem (UIBarButtonSystemItem.Save, (sender,args) => {
                // button was clicked

                var cultivationData = new CultivationData {
                    DbField = fieldID,
                    DbDate = date.DateValue,
                    DbImplement = implement.Value,
                    DbDepth = depth.Value,
                    DbNotes = notes.Value
                };

                //insert to database
                sql.Insert (cultivationData);

                UIAlertView alert = new UIAlertView ();
                alert.Title = "Success";
                alert.Message = "Your Data Has Been Saved";
                alert.AddButton("OK");

                alert.Clicked += delegate {
                    this.NavigationController.PopViewControllerAnimated(true);
                } ;
                alert.Show();
            })
                , true);

            Root = new RootElement (null) {
                new Section ("Date"){
                    date,
                },
                new Section ("Implement Used"){
                    implement,
                },
                new Section("Depth (in)"){
                    depth,
                },
                new Section ("Notes"){
                    notes,
                },
            };
        }
        private UINavigationController NewRMEntry(double prevBest)
        {
            CustomRootElement root = new CustomRootElement(" ");

            CustomDialogViewController dvc = new CustomDialogViewController(root, false);
            UINavigationController nav = new UINavigationController(dvc);

            dvc.BackgroundImage = "images/white_carbon";
            dvc.NavigationBarColor = UIColor.FromRGB(39, 113, 205);
            dvc.NavigationBarImage = UIImage.FromBundle("images/navBar");

            UIColor buttonColor = UIColor.FromRGB(39, 113, 205);
            UIBarButtonItem cancelButton = new UIBarButtonItem(UIBarButtonSystemItem.Cancel);
            cancelButton.TintColor = buttonColor;
            cancelButton.Clicked += delegate {
                dvc.NavigationController.DismissViewController(true, null);
            };
            UIBarButtonItem saveButton = new UIBarButtonItem(UIBarButtonSystemItem.Save);
            saveButton.TintColor = buttonColor;
            dvc.NavigationItem.LeftBarButtonItem = cancelButton;
            dvc.NavigationItem.RightBarButtonItem = saveButton;

            Section newRMSection = new Section("Record Details") {};

            string strPrevBest = String.Format("{0:000.0}", prevBest);

            if(prevBest == 0)
                strPrevBest = "100.0";

            ResponsiveCounterElement newRMCounter = new ResponsiveCounterElement("New RM", strPrevBest); // TODO: grab the previous best and use that
            newRMCounter.SetCustomBackButton(UIImage.FromBundle("images/backbutton"), RectangleF.FromLTRB (0, 20, 50, 20));

            DateElement newRMDate = new DateElement("Date", DateTime.Today);

            newRMSection.Add(newRMCounter);
            newRMSection.Add(newRMDate);

            root.Add(newRMSection);

            saveButton.Clicked += delegate {
                RmLog newEntry = new RmLog {
                    DateLogged = newRMDate.DateValue,
                    Weight = Convert.ToDouble(newRMCounter.Value),
                    ExerciseID = this._exercise.ID
                };

                dvc.NavigationController.DismissViewController(true, null);

                db.Insert(newEntry);
                this._rms.Add(newEntry);

                // refresh view
                this.RefreshRecords();

            };

            return nav;
        }
		public CalloutViewCtrl () : base(null)
		{
			this.CentersCheck = new CheckboxElement[Centers.Length];
			for (int i = 0; i < Centers.Length; i++) {
				var tmp = new CheckboxElement (Centers[i]);
				this.CentersCheck [i] = tmp;
			}

			this.FirstName = new EntryElement ("First Name", "Rocky", KeyStore.Get ("FirstName")) {
				TextAlignment = UITextAlignment.Right
			};

			this.LastName = new EntryElement ("Last Name", "D. Bull", KeyStore.Get ("LastName")) {
				TextAlignment = UITextAlignment.Right
			};

			this.Email = new EntryElement ("E-Mail", "*****@*****.**", KeyStore.Get ("Email")) {
				TextAlignment = UITextAlignment.Right,
				KeyboardType = UIKeyboardType.EmailAddress
			};

			OptionGroup = new RadioGroup ("type", 0);
			Callout = new RadioElement ("Call-Out", "type");
			Inlate = new RadioElement ("In Late", "type");

			StartDate = new DateElement ("Out On", DateTime.Today) {
				Alignment = UITextAlignment.Right
			};

			MultipleDays = new BooleanElement ("Out Multiple Days", false);
			EndDate = new DateElement ("Back On", DateTime.Today.AddDays (1)) { Alignment = UITextAlignment.Right };

			WhenInDate = new DateTimeElement ("Will Be In", DateTime.Today.AddHours (12)) { Alignment = UITextAlignment.Right };

			Explaination = new EntryElement ("Explaination", "reasons.", null) { TextAlignment = UITextAlignment.Right };

			Section Name = new Section () { FirstName, LastName, Email };
			Section Options = new Section () { Callout, Inlate };

			Section CalloutDates = new Section () { StartDate, MultipleDays };
			MultipleDays.ValueChanged += (sender, e) => {
				if (MultipleDays.Value) {
					CalloutDates.Add(EndDate);
				} else {
					CalloutDates.Remove(EndDate);
				}
			};

			Section LateDay = new Section () { WhenInDate };
			Callout.Tapped += delegate {
				this.Root.RemoveAt(2);
				this.Root.Insert(2, CalloutDates);
			};

			Inlate.Tapped += delegate {
				this.Root.RemoveAt(2);
				this.Root.Insert(2, LateDay);
			};

			this.Submit = new StringElement ("Submit") { Alignment = UITextAlignment.Center };
			this.Root = new RootElement ("Call-Out", OptionGroup) { 
				Name,
				Options,
				CalloutDates,
				new Section("Centers") {
					this.CentersCheck
				},
				new Section() { Explaination },
				new Section() { Submit }
			};


			this.Submit.Tapped += Submit_Tapped;

			this.NavigationItem.LeftBarButtonItem = new UIBarButtonItem (UIBarButtonSystemItem.Cancel, delegate {
				this.NavigationController.PopViewController(true);	
			});
		}
		void Populate (object callbacks, object o, RootElement root)
		{
			var members = o.GetType ().GetMembers (BindingFlags.DeclaredOnly | BindingFlags.Public |
							       BindingFlags.NonPublic | BindingFlags.Instance);

			Section section = null;
			
			foreach (var mi in members){
				Type mType = GetTypeForMember (mi);

				if (mType == null)
					continue;

				string caption = null;
				object [] attrs = mi.GetCustomAttributes (false);
				foreach (var attr in attrs){
					if (attr is CaptionAttribute)
						caption = ((CaptionAttribute) attr).Caption;
					else if (attr is SectionAttribute){
						if (section != null)
							Root.Add (section);
						var sa = attr as SectionAttribute;
						section = new Section (sa.Caption, sa.Footer);
					}
				}
				if (caption == null)
					caption = MakeCaption (mi.Name);
				
				if (section == null)
					section = new Section ();
				
				Element element = null;
				if (mType == typeof (string)){
					PasswordAttribute pa = null;
					EntryAttribute ea = null;
					NSAction invoke = null;
					bool multi = false;
					
					foreach (object attr in attrs){
						if (attr is PasswordAttribute)
							pa = attr as PasswordAttribute;
						else if (attr is EntryAttribute)
							ea = attr as EntryAttribute;
						else if (attr is MultilineAttribute)
							multi = true;
						
						if (attr is OnTapAttribute){
							string mname = ((OnTapAttribute) attr).Method;
							
							if (callbacks == null){
								throw new Exception ("Your class contains [OnTap] attributes, but you passed a null object for `context' in the constructor");
							}
							
							var method = callbacks.GetType ().GetMethod (mname);
							if (method == null)
								throw new Exception ("Did not find method " + mname);
							invoke = delegate {
								method.Invoke (method.IsStatic ? null : callbacks, new object [0]);
							};
						}
					}
					
					string value = (string) GetValue (mi, o);
					if (pa != null)
						element = new EntryElement (caption, pa.Placeholder, value, true);
					else if (ea != null)
						element = new EntryElement (caption, ea.Placeholder, value);
					else if (multi)
						element = new MultilineElement (caption, value);
					else
						element = new StringElement (caption, value);
					
					if (invoke != null)
						((StringElement) element).Tapped += invoke;
				} else if (mType == typeof (float)){
					var floatElement = new FloatElement (null, null, (float) GetValue (mi, o));
					element = floatElement;
					
					foreach (object attr in attrs){
						if (attr is RangeAttribute){
							var ra = attr as RangeAttribute;
							floatElement.MinValue = ra.Low;
							floatElement.MaxValue = ra.High;
						}
					}
				} else if (mType == typeof (bool)){
					bool checkbox = false;
					foreach (object attr in attrs){
						if (attr is CheckboxAttribute)
							checkbox = true;
					}
					
					if (checkbox)
						element = new CheckboxElement (caption, (bool) GetValue (mi, o));
					else
						element = new BooleanElement (caption, (bool) GetValue (mi, o));
				} else if (mType == typeof (DateTime)){
					var dateTime = (DateTime) GetValue (mi, o);
					bool asDate = false, asTime = false;
					
					foreach (object attr in attrs){
						if (attr is DateAttribute)
							asDate = true;
						else if (attr is TimeAttribute)
							asTime = true;
					}
					
					if (asDate)
						element = new DateElement (caption, dateTime);
					else if (asTime)
						element = new TimeElement (caption, dateTime);
					else
						 element = new DateTimeElement (caption, dateTime);
				} else if (mType.IsEnum){
					var csection = new Section ();
					ulong evalue = Convert.ToUInt64 (GetValue (mi, o), null);
					int idx = 0;
					int selected = 0;
					
					foreach (var fi in mType.GetFields (BindingFlags.Public | BindingFlags.Static)){
						ulong v = Convert.ToUInt64 (GetValue (fi, null));
						
						if (v == evalue)
							selected = idx;
						
						csection.Add (new RadioElement (MakeCaption (fi.Name)));
						idx++;
					}
					
					element = new RootElement (caption, new RadioGroup (null, selected)) { csection };
				} else if (mType == typeof (UIImage)){
					element = new ImageElement ((UIImage) GetValue (mi, o));
				} else {
					var nested = GetValue (mi, o);
					if (nested != null){
						var newRoot = new RootElement (caption);
						Populate (callbacks, nested, newRoot);
						element = newRoot;
					}
				}
				
				if (element == null)
					continue;
				section.Add (element);
				mappings [element] = new MemberAndInstance (mi, o);
			}
			root.Add (section);
		}
Exemple #11
0
        public void initializeUserInterface()
        {
            // 0. Chemical Template

            chemicalTemplateDict = new Dictionary<string, ChemicalTemplate> ();
            chemicalTemplateDict = LocalStorage.getLocalStorageManager ().loadChemicalTemplate();

            Section chemicalTemplateS = new Section ("Chemical Template");
            chemicalTemplate = new RadioGroup (0);

            Section stSection = new Section ();
            foreach(var templateName in chemicalTemplateDict){
                var t = new myRadioElement(templateName.Value.templateName);
                t.OnSelected += delegate(object sender, EventArgs e) {

                    InvokeOnMainThread(()=>{
                        loadValueFromTemplate(t.Caption);
                    });
                };
                stSection .Add(t);
            }
            RootElement stRoot = new RootElement ("Chemical Template", chemicalTemplate) { };
            stRoot.Add(stSection);
            chemicalTemplateS.Add (stRoot);

            // 1. Chemical Date
            Section chemicalDateS = new Section ("Chemical Date");
            chemicalDate = new DateElement ("", DateTime.Now);
            chemicalDateS.Add (this.chemicalDate);

            // 2. Implemented Used
            Section implementedUsedS = new Section ("Implemented Used");
            tools = new EntryElement (" ","Tools","");
            tools.ShouldReturn += delegate {
                tools.ResignFirstResponder(true);
                return true;
            };
            tools.ReturnKeyType = UIReturnKeyType.Done;
            implementedUsedS.Add (tools);

            // 3. Seed Type
            Section chemicalTypeS = new Section ("Chemical Types");

            chemicalTypes = new EntryElement (" ", "Chemical Types", "");
            chemicalTypes.ShouldReturn += delegate {
                chemicalTypes.ResignFirstResponder(true);
                return true;
            };
            chemicalTypes.ReturnKeyType = UIReturnKeyType.Done;
            chemicalTypeS.Add (chemicalTypes);

            // 4. chemical Rate
            Section chemicalRateS = new Section ("Chemical Rate (L/ac)");
            chemicalRate = new EntryElement (" ", "Chemical Rates", "");
            chemicalRate.ShouldReturn += delegate {
                chemicalRate.ResignFirstResponder(true);
                return true;
            };
            chemicalRate.ReturnKeyType = UIReturnKeyType.Done;
            chemicalRateS.Add (chemicalRate);

            // 5. Note
            Section noteS = new Section ("Notes");
            note = new SimpleMultilineEntryElement ("", " ") { Editable = true };
            noteS.Add (note);

            Root.Add (chemicalTemplateS);
            Root.Add (chemicalDateS);
            Root.Add (implementedUsedS);
            Root.Add (chemicalTypeS);
            Root.Add (chemicalRateS);
            Root.Add (noteS);
        }
		public BindingContext (object o, string title)
		{
			mappings = new Dictionary<Element,MemberAndInstance> ();
			var members = o.GetType ().GetMembers (BindingFlags.DeclaredOnly | BindingFlags.Public |
							       BindingFlags.NonPublic | BindingFlags.Instance);

			Root = new RootElement (title);
			Section section = null;
			
			foreach (var mi in members){
				Type mType = GetTypeForMember (mi);

				if (mType == null)
					continue;

				string caption = null;
				object [] attrs = mi.GetCustomAttributes (false);
				foreach (var attr in attrs){
					if (attr is CaptionAttribute)
						caption = ((CaptionAttribute) attr).Caption;
					else if (attr is SectionAttribute){
						if (section != null)
							Root.Add (section);
						var sa = attr as SectionAttribute;
						section = new Section (sa.Caption, sa.Footer);
					}
				}
				if (caption == null)
					caption = MakeCaption (mi.Name);
				
				if (section == null)
					section = new Section ();
				
				Element element = null;
				if (mType == typeof (string)){
					PasswordAttribute pa = null;
					EntryAttribute ea = null;
					
					foreach (object attr in attrs){
						if (attr is PasswordAttribute)
							pa = attr as PasswordAttribute;
						else if (attr is EntryAttribute)
							ea = attr as EntryAttribute;
					}
					
					if (pa != null)
						element = new EntryElement (caption, pa.Placeholder, (string) GetValue (mi, o), true);
					else if (ea != null)
						element = new EntryElement (caption, ea.Placeholder, (string) GetValue (mi, o));
					else
						element = new StringElement (caption, (string) GetValue (mi, o));
				} else if (mType == typeof (float)){
					element = new FloatElement (null, null, (float) GetValue (mi, o));
				} else if (mType == typeof (bool)){
					element = new BooleanElement (caption, (bool) GetValue (mi, o));
				} else if (mType == typeof (DateTime)){
					var dateTime = (DateTime) GetValue (mi, o);
					bool asDate = false, asTime = false;
					
					foreach (object attr in attrs){
						if (attr is DateAttribute)
							asDate = true;
						else if (attr is TimeAttribute)
							asTime = true;
					}
					
					if (asDate)
						element = new DateElement (caption, dateTime);
					else if (asTime)
						element = new TimeElement (caption, dateTime);
					else
						 element = new DateTimeElement (caption, dateTime);
				} else if (mType.IsEnum){
					var csection = new Section ();
					ulong evalue = Convert.ToUInt64 (GetValue (mi, o), null);
					int idx = 0;
					int selected = 0;
					
					foreach (var fi in mType.GetFields (BindingFlags.Public | BindingFlags.Static)){
						ulong v = Convert.ToUInt64 (GetValue (fi, null));
						
						if (v == evalue)
							selected = idx;
						
						csection.Add (new RadioElement (fi.Name));
						idx++;
					}
					
					element = new RootElement (caption, new RadioGroup (null, selected)) { csection };
				}
				
				if (element == null)
					continue;
				section.Add (element);
				mappings [element] = new MemberAndInstance (mi, o);
			}
			Root.Add (section);
		}
Exemple #13
0
        public void initializeUserInterface()
        {
            // 0. Seed Templates
            seedTemplateDict = new Dictionary<string, SeedTemplate> ();
            seedTemplateDict = LocalStorage.getLocalStorageManager ().loadSeedTemplate ();

            Section seedTemplateS = new Section ("Seed Template");
            seedTemplate = new RadioGroup (0);

            Section stSection = new Section ();
            foreach(var templateName in seedTemplateDict){
                var t = new myRadioElement(templateName.Value.templateName);
                t.OnSelected += delegate(object sender, EventArgs e) {

                    InvokeOnMainThread(()=>{
                        loadValueFromTemplate(t.Caption);
                    });
            };
                stSection .Add(t);
            }
            RootElement stRoot = new RootElement ("Seed Template", seedTemplate) { };
            stRoot.Add(stSection);

            seedTemplateS.Add (stRoot);

            // 1. Seed Date
            Section seedDateS = new Section ("Seed Date");
            this.seedDate = new DateElement ("", DateTime.Now);
            seedDateS.Add (this.seedDate);

            // 2. Seed Type
            Section seedTypeS = new Section ("Seed Types");

            seedTypes = new EntryElement (" ", "Seed Types", "");
            seedTypes.ShouldReturn += delegate {
                seedTypes.ResignFirstResponder(true);
                return true;
            };
            seedTypes.ReturnKeyType = UIReturnKeyType.Done;
            seedTypeS.Add (seedTypes);

            // 3. Seeding Depth
            Section seedDepthS = new Section ("Seeding Depth (in)");
            //			seedDepth = new FloatElementEx (0, lockable: false) {
            //				ShowCaption = true,
            //				UseCaptionForValueDisplay = true,
            //				MaxValue = 2,
            //			};
            seedDepth = new EntryElement(" ","Seed Depth", "");
            seedDepth.ShouldReturn += delegate {
                seedDepth.ResignFirstResponder(true);
                return true;
            };
            seedDepth.ReturnKeyType = UIReturnKeyType.Done;
            seedDepthS.Add(seedDepth);

            // 4. Implemented Used
            Section implementedUsedS = new Section ("Implemented Used");
            tools = new EntryElement (" ","Tools","");
            tools.ShouldReturn += delegate {
                tools.ResignFirstResponder(true);
                return true;
            };
            tools.ReturnKeyType = UIReturnKeyType.Done;
            implementedUsedS.Add (tools);

            // 5. Variety Name
            Section varietyNameS = new Section ("Variety Name");
            varietyName = new EntryElement (" ","Enter Variety Name","");
            varietyName.ReturnKeyType = UIReturnKeyType.Done;
            varietyName.ShouldReturn += delegate {

                varietyName.ResignFirstResponder(true);
                return true;
            };
            varietyNameS.Add (varietyName);

            // 6. Seed Rate
            Section seedRateS = new Section ("Seed Rate (lb/ac)");
            seedRate = new FloatElementEx (0, lockable: false) {
                ShowCaption = true,
                UseCaptionForValueDisplay = true,
                MaxValue = 300,
            };
            seedRateS.Add(seedRate);

            // 7. Seed Treatment
            Section seedTreatmentS = new Section ("Seed Treatment");
            seedTreatment = new  EntryElement (" ","Enter Seed Treatment","");
            seedTreatment.ReturnKeyType = UIReturnKeyType.Done;

            seedTreatmentS.Add (seedTreatment);

            // 8. NH3
            Section NH3S = new Section ("NH3 (lb/ac)");
            NH3 = new FloatElementEx (0, lockable: false) {
                ShowCaption = true,
                UseCaptionForValueDisplay = true,
                MaxValue = 120,
            };
            NH3S.Add (NH3);

            // 9. 11-52-20
            Section _11S = new Section ("11-52-20 (lb/ac)");
            _11 = new FloatElementEx (0, lockable: false) {
                ShowCaption = true,
                UseCaptionForValueDisplay = true,
                MaxValue = 100,
            };
            _11S.Add(_11);

            // 10. Note
            Section noteS = new Section ("Notes");

            note = new SimpleMultilineEntryElement ("", " ") { Editable = true };
            noteS.Add (note);

            Root.Add (seedTemplateS);
            Root.Add (seedDateS);
            Root.Add (seedTypeS);
            Root.Add (implementedUsedS);
            Root.Add (seedDepthS);
            Root.Add (varietyNameS);
            Root.Add (seedRateS);
            Root.Add (seedTreatmentS);
            Root.Add (NH3S);
            Root.Add (_11S);
            Root.Add (noteS);
        }
Exemple #14
0
        public Harvest(int num, SQLiteConnection s)
            : base(UITableViewStyle.Grouped, null)
        {
            sql = s;
            //Create the db table for this viewcontroller.
            sql.CreateTable<HarvestData> ();
            //The field Id passed to this controller. Represents a unique field on a farm.
            fieldID = num;
            //The Elements with their variables
            date = new DateElement (null, DateTime.Today);
            implement = new EntryElement (null, "Which implement was used?", null);
            yield = new FloatElementEx (0);
            moisture = new FloatElementEx (0);
            bin = new EntryElement (null, "Enter Bin #", null);
            notes = new SimpleMultilineEntryElement (null, null);

            //Specify element details
            yield.UseCaptionForValueDisplay = true;
            yield.ShowCaption = true;
            yield.MinValue = 0;
            yield.MaxValue = 120;

            moisture.UseCaptionForValueDisplay = true;
            moisture.ShowCaption = true;
            moisture.MinValue = 0;
            moisture.MaxValue = 25;
            notes.Editable = true;

            implement.ShouldReturn += delegate {
                implement.ResignFirstResponder (true);
                return true;
            };
            bin.ShouldReturn += delegate {
                bin.ResignFirstResponder (true);
                return true;
            };

            this.Title = "Harvest";
            this.Pushing = true;

            //Create the save button
            this.NavigationItem.SetRightBarButtonItem (
                new UIBarButtonItem (UIBarButtonSystemItem.Save, (sender,args) => {

                //Create table row with data.
                var harvestData = new HarvestData {
                    DbField = fieldID,
                    DbDate = date.DateValue,
                    DbImplement = implement.Value,
                    DbYield = yield.Value,
                    DbMoisture = moisture.Value,
                    DbBin = bin.Value,
                    DbNotes = notes.Value
                };
                //insert to database
                sql.Insert (harvestData);

                UIAlertView alert = new UIAlertView ();
                alert.Title = "Success";
                alert.Message = "Your Data Has Been Saved";
                alert.AddButton("OK");

                alert.Clicked += delegate {
                    this.NavigationController.PopViewControllerAnimated(true);
                } ;
                alert.Show();
            })
                , true);

            //Create the GUI
            Root = new RootElement (null) {
                new Section ("Date"){
                    date,
                },
                new Section("Implement Used") {
                    implement,
                },
                new Section("Yield (bushel / acre)"){
                    yield,
                },
                new Section("Moisture (%)"){
                    moisture,
                },
                new Section ("Bin"){
                    bin,
                },
                new Section("Notes") {
                    notes,
                },
            };
        }