Ejemplo n.º 1
0
            public override IDeepCopyable CopyTo(IDeepCopyable other)
            {
                var dest = other as DiagnosticOrderEventComponent;

                if (dest != null)
                {
                    base.CopyTo(dest);
                    if (StatusElement != null)
                    {
                        dest.StatusElement = (Code <Hl7.Fhir.Model.DiagnosticOrder.DiagnosticOrderStatus>)StatusElement.DeepCopy();
                    }
                    if (Description != null)
                    {
                        dest.Description = (Hl7.Fhir.Model.CodeableConcept)Description.DeepCopy();
                    }
                    if (DateTimeElement != null)
                    {
                        dest.DateTimeElement = (Hl7.Fhir.Model.FhirDateTime)DateTimeElement.DeepCopy();
                    }
                    if (Actor != null)
                    {
                        dest.Actor = (Hl7.Fhir.Model.ResourceReference)Actor.DeepCopy();
                    }
                    return(dest);
                }
                else
                {
                    throw new ArgumentException("Can only copy to an object of the same type", "other");
                }
            }
Ejemplo n.º 2
0
        public static IBinding BindDate <TModel>(
            this DateTimeElement view,
            TModel model,
            Expression <Func <TModel, DateTime> > getVal)
            where TModel : INotifyPropertyChanged
        {
            var binding = BindingCore.CreateBinding(
                view,
                model,
                getVal,
                (v, value) => Apply(v,
                                    () =>
            {
                if (v.DateValue != value)
                {
                    v.DateValue = value;
                    return(true);
                }
                return(false);
            }));

            var prop = (PropertyInfo)((MemberExpression)getVal.Body).Member;

            Action <DateTimeElement> viewOnValueChanged = element =>
            {
                if (!Equals(element.DateValue, prop.GetValue(model)))
                {
                    prop.SetValue(model, element.DateValue);
                }
            };

            view.DateSelected += viewOnValueChanged;

            return(binding.With(() => view.DateSelected -= viewOnValueChanged));
        }
Ejemplo n.º 3
0
        public void SetDateTime(DateTimeElement element, uint value)
        {
            UsbCommand cmd;

            if (element == DateTimeElement.EEPROM_WRITE_REQUEST)
            {
                cmd = new UsbCommand((byte)element);
            }
            else
            {
                cmd = new UsbCommand((byte)element, UintToBcd(value));
            }
            PendingCommands.Add(cmd);
        }
        public void TestDateTime()
        {
            // Create the object.
            var xmlObject = new DateTimeElement();

            xmlObject.TestAttribute = new DateTime(2020, 4, 23);
            xmlObject.TestElement   = new DateTime(2020, 11, 4);;

            // Assert the element is generated correctly.
            Assert.AreEqual(xmlObject.Serialize(new XMLVersion()), "<TestXMLElement testAttribute=\"2020-04-23\"><testElement>2020-11-04</testElement></TestXMLElement>");

            // Create a new object with the attribute and element missing.
            xmlObject = new DateTimeElement();

            // Assert the element is generated correctly.
            Assert.AreEqual(xmlObject.Serialize(new XMLVersion()), "<TestXMLElement></TestXMLElement>");
        }
Ejemplo n.º 5
0
        private 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;
                    Action             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]); };
                        }
                    }

                    var 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)
                    {
                        (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;
                        }

                        var 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++;
                    }
                    var 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)
                {
                    if (attrs.OfType <RadioSelectionAttribute>().Any())
                    {
                        last_radio_index = mi;
                    }
                }
                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);
        }
Ejemplo n.º 6
0
        private 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;
                    Action 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]); };
                        }
                    }

                    var 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)
                        (element).Tapped += invoke;
                }
                else if (mType == typeof(float))
                {
                    var floatElement = new FloatElement(null, null, (float)GetValue(mi, o)) { 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;

                        var 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++;
                    }
                    var 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)
                {
                    if (attrs.OfType<RadioSelectionAttribute>().Any())
                    {
                        last_radio_index = mi;
                    }
                }
                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);
        }
Ejemplo n.º 7
0
 private void DEle_DateSelected(DateTimeElement obj)
 {
     throw new NotImplementedException();
 }
			public VisitDetailsView(VisitDetailsViewController parent)
			{
				Parent = parent;
				BackgroundColor = UIColor.FromRGB(239,239,244);

				addVisitor = new UIButton
				{
					Frame = new RectangleF(0, 0, 150, 150),
					TintColor = UIColor.White,
					Layer =
					{
						CornerRadius = 75,
						MasksToBounds = true,
					}
				};
				addVisitor.SetTitle("Add a visitor", UIControlState.Normal);
				addVisitor.ImageView.ContentMode = UIViewContentMode.ScaleAspectFill;;
				addVisitor.SetImage(Theme.UserImageDefaultLight.Value,UIControlState.Normal);
				addVisitor.TouchUpInside += (sender, args) => { if (Parent.PickVisitor != null) Parent.PickVisitor(); };
				AddSubview(addVisitor);

				addEmployee = new UIButton
				{
					Frame = new RectangleF(0, 0, 150, 150),
					TintColor = UIColor.White,
					Layer =
					{
						CornerRadius = 75,
						MasksToBounds = true,
					}
				};
				addEmployee.SetTitle("Add an employee", UIControlState.Normal);
				addEmployee.ImageView.ContentMode = UIViewContentMode.ScaleAspectFill; ;
				addEmployee.SetImage(Theme.UserImageDefaultLight.Value, UIControlState.Normal);
				addEmployee.TouchUpInside += (sender, args) => { if (Parent.PickEmployee != null) Parent.PickEmployee(); };
				AddSubview(addEmployee);

				editButton = new UIButton(new RectangleF(0,0,40,40));
				editButton.SetBackgroundImage(UIImage.FromBundle("edit"),UIControlState.Normal );
				editButton.TouchUpInside += (sender, args) =>
				{
					var vc = new EditVisitorViewController
					{
						Visitor = new VMVisitor{Visitor = visit.Visitor}
					};
					this.Parent.NavigationController.PushViewController(vc,true);
				};

				visitorLabel = new UILabel { Text = "Visitor", Font = UIFont.FromName(font2, 30), TextAlignment = UITextAlignment.Center, AdjustsFontSizeToFitWidth = true,};

				visitorLabel.SizeToFit();
				AddSubview(visitorLabel);

				employeeLabel = new UILabel { Text = "Employee", Font = UIFont.FromName(font2, 30), TextAlignment = UITextAlignment.Center, AdjustsFontSizeToFitWidth = true,};
				employeeLabel.SizeToFit();
				AddSubview(employeeLabel);

				date = new DateTimeElement("Date", DateTime.Now);
				comment = new EntryElement("Reason: ", "Reason", "");
				comment.Changed += (sender, args) =>
				{
					Console.WriteLine("Comment");
				};
				vehicle = new BooleanElement("Vehicle",false);
				licensePlate = new EntryElement("Lic Plate: ", "License Plate", "");
				licensePlate.Changed += (sender, args) =>
				{
					Console.WriteLine("licensePlate");
				};
				vehicle.ValueChanged += (sender, args) =>
				{
					if (vehicle.Value)
					{
						if (!section.Elements.Contains(licensePlate))
							section.Add(licensePlate);
						datadvc.ReloadData();
					}
					else
					{
						licensePlate.FetchValue();
						section.Remove(licensePlate);
					}
				};


				datadvc = new DialogViewController(new RootElement("visit")
				{
					(section = new Section
					{
						date,
						comment,
						vehicle,
						licensePlate
					})
				});
				datadvc.TableView.SectionHeaderHeight = 0;
				datadvc.TableView.TableHeaderView = null;
				datadvc.View.BackgroundColor = UIColor.White;
				datadvc.View.Layer.CornerRadius = 5f;
				var height = Enumerable.Range(0, datadvc.TableView.Source.RowsInSection(datadvc.TableView,0)).Sum(x => datadvc.TableView.Source.GetHeightForRow(datadvc.TableView, NSIndexPath.FromRowSection(x, 0)));
				datadvc.View.Frame = new RectangleF(0,0,100,height);
				AddSubview(datadvc.View);
				this.Parent.AddChildViewController(datadvc);


			}
Ejemplo n.º 9
0
 public static double Extract(DateTimeElement element, DateTime src)
 {
     throw new InvalitContextException(nameof(Extract));
 }
Ejemplo n.º 10
0
        public override IDeepCopyable CopyTo(IDeepCopyable other)
        {
            var dest = other as Media;

            if (dest != null)
            {
                base.CopyTo(dest);
                if (TypeElement != null)
                {
                    dest.TypeElement = (Code <Hl7.Fhir.Model.Media.MediaType>)TypeElement.DeepCopy();
                }
                if (Subtype != null)
                {
                    dest.Subtype = (Hl7.Fhir.Model.CodeableConcept)Subtype.DeepCopy();
                }
                if (Identifier != null)
                {
                    dest.Identifier = new List <Hl7.Fhir.Model.Identifier>(Identifier.DeepCopy());
                }
                if (DateTimeElement != null)
                {
                    dest.DateTimeElement = (Hl7.Fhir.Model.FhirDateTime)DateTimeElement.DeepCopy();
                }
                if (Subject != null)
                {
                    dest.Subject = (Hl7.Fhir.Model.ResourceReference)Subject.DeepCopy();
                }
                if (Operator != null)
                {
                    dest.Operator = (Hl7.Fhir.Model.ResourceReference)Operator.DeepCopy();
                }
                if (View != null)
                {
                    dest.View = (Hl7.Fhir.Model.CodeableConcept)View.DeepCopy();
                }
                if (DeviceNameElement != null)
                {
                    dest.DeviceNameElement = (Hl7.Fhir.Model.FhirString)DeviceNameElement.DeepCopy();
                }
                if (HeightElement != null)
                {
                    dest.HeightElement = (Hl7.Fhir.Model.Integer)HeightElement.DeepCopy();
                }
                if (WidthElement != null)
                {
                    dest.WidthElement = (Hl7.Fhir.Model.Integer)WidthElement.DeepCopy();
                }
                if (FramesElement != null)
                {
                    dest.FramesElement = (Hl7.Fhir.Model.Integer)FramesElement.DeepCopy();
                }
                if (LengthElement != null)
                {
                    dest.LengthElement = (Hl7.Fhir.Model.Integer)LengthElement.DeepCopy();
                }
                if (Content != null)
                {
                    dest.Content = (Hl7.Fhir.Model.Attachment)Content.DeepCopy();
                }
                return(dest);
            }
            else
            {
                throw new ArgumentException("Can only copy to an object of the same type", "other");
            }
        }
Ejemplo n.º 11
0
        private Element ConvertXElementToElement(XElement element)
        {
            var elementValues = new List <string>();

            if (!element.Elements().Any())
            {
                var tElem = _oldRoot.Descendants(element.Name).Where(x => GetParentsAsString(x, -1) == GetParentsAsString(element, -1) && !x.Elements().Any()).Select(e => e.Value);
                elementValues.AddRange(tElem);
            }

            var xElementList = _oldRoot.Descendants(element.Name).GroupBy(el => el.Parent).Select(g => new { g.Key, Count = g.Count() }).Where(x => x.Count > 1);

            Element returnElement;
            var     elementName = element.Name.LocalName;
            var     elementType = DataType.GetDataTypeFromList(elementValues, _dateFormat, _dateTimeFormat);

            switch (elementType.type)
            {
            case DataType.Type.Date:
                returnElement = new DateTimeElement(elementName, _dateFormat);
                break;

            case DataType.Type.DateTime:
                returnElement = new DateTimeElement(elementName, _dateTimeFormat);
                break;

            case DataType.Type.Bool:
                returnElement = new BoolElement(elementName, "True", "False");
                break;

            case DataType.Type.@bool:
                returnElement = new BoolElement(elementName, "true", "false");
                break;

            case DataType.Type.@int:
                returnElement = new IntElement(elementName);
                break;

            case DataType.Type.@decimal:
                returnElement = new DecimalElement(elementName);
                break;

            case DataType.Type.@string:
                returnElement = new StringElement(elementName);
                break;

            default:
                returnElement = new Element(elementName);
                break;
            }
            returnElement.Enumerable      = xElementList.Any();
            returnElement.Type            = elementType;
            returnElement.OriginalElement = element;

            foreach (var xElement in element.Elements())
            {
                returnElement.Elements.Add(ConvertXElementToElement(xElement));
            }

            foreach (var xAttribute in element.Attributes())
            {
                var tElements = _oldRoot.DescendantsAndSelf(element.Name).Where(x => GetParentsAsString(x, -1) == GetParentsAsString(element, -1)).ToList();

                var xAttr           = xAttribute;
                var attributeValues = tElements.Select(tElement => tElement.Attribute(xAttr.Name)).Select(attribute => attribute != null ? attribute.Value : "").ToList();

                Attribute thisAttribute;
                var       attributeName = xAttribute.Name.LocalName;

                if (xAttribute.IsNamespaceDeclaration)
                {
                    returnElement.NamespaceAttributes.Add(xAttribute);
                    continue;
                }

                if (attributeName == "schemaLocation")
                {
                    thisAttribute = new SchemaLocationAttribute(attributeName, xAttribute.Value);
                    returnElement.Attributes.Add(thisAttribute);
                    continue;
                }

                var attributeType = DataType.GetDataTypeFromList(attributeValues, _dateFormat, _dateTimeFormat);
                switch (attributeType.type)
                {
                case DataType.Type.Date:
                    thisAttribute = new DateTimeAttribute(attributeName, _dateFormat);
                    break;

                case DataType.Type.DateTime:
                    thisAttribute = new DateTimeAttribute(attributeName, _dateTimeFormat);
                    break;

                case DataType.Type.Bool:
                    thisAttribute = new BoolAttribute(attributeName, "True", "False");
                    break;

                case DataType.Type.@bool:
                    thisAttribute = new BoolAttribute(attributeName, "true", "false");
                    break;

                case DataType.Type.@int:
                    thisAttribute = new IntAttribute(attributeName);
                    break;

                case DataType.Type.@decimal:
                    thisAttribute = new DecimalAttribute(attributeName);
                    break;

                case DataType.Type.@string:
                    thisAttribute = new StringAttribute(attributeName);
                    break;

                default:
                    thisAttribute = new Attribute(attributeName);
                    break;
                }
                thisAttribute.Type = attributeType;

                returnElement.Attributes.Add(thisAttribute);
            }

            return(returnElement);
        }
Ejemplo n.º 12
0
        private void ConsolidateElements(Element newElement, Element currentElement)
        {
            // compare current element elements with new element elements and add unique missing to new element
            foreach (var cElement in currentElement.Elements)
            {
                var tempElement = newElement.Elements.FirstOrDefault(e => e.Name == cElement.Name);

                if (tempElement == null)                 // element missing, add it
                {
                    var elementName = cElement.Name;
                    switch (cElement.Type.type)
                    {
                    case DataType.Type.Date:
                        tempElement = new DateTimeElement(elementName, _dateFormat);
                        break;

                    case DataType.Type.DateTime:
                        tempElement = new DateTimeElement(elementName, _dateTimeFormat);
                        break;

                    case DataType.Type.Bool:
                        tempElement = new BoolElement(elementName, "True", "False");
                        break;

                    case DataType.Type.@bool:
                        tempElement = new BoolElement(elementName, "true", "false");
                        break;

                    case DataType.Type.@int:
                        tempElement = new IntElement(elementName);
                        break;

                    case DataType.Type.@decimal:
                        tempElement = new DecimalElement(elementName);
                        break;

                    case DataType.Type.@string:
                        tempElement = new StringElement(elementName);
                        break;

                    default:
                        tempElement = new Element(elementName);
                        break;
                    }

                    tempElement.Enumerable          = cElement.Enumerable;
                    tempElement.Type                = cElement.Type;
                    tempElement.OriginalElement     = cElement.OriginalElement;
                    tempElement.NamespaceAttributes = cElement.NamespaceAttributes;

                    newElement.Elements.Add(tempElement);
                }

                foreach (var attribute in cElement.Attributes)
                {
                    // Check Attribute Exists
                    if (tempElement.Attributes.Any(a => a.Name == attribute.Name))
                    {
                        continue;
                    }

                    var sameAttributes = cElement.Attributes.Where(a => a.Name == attribute.Name).ToList();
                    var dataType       = sameAttributes.Aggregate <Attribute, DataType>(null, (current, sameAttribute) => current == null ? sameAttribute.Type : DataType.GetBestType(current, sameAttribute.Type));
                    attribute.Type = dataType;
                    tempElement.Attributes.Add(attribute);
                }

                ConsolidateElements(tempElement, cElement);
            }
        }
Ejemplo n.º 13
0
        public override ErrorList Validate()
        {
            var result = new ErrorList();

            result.AddRange(base.Validate());

            if (TypeElement != null)
            {
                result.AddRange(TypeElement.Validate());
            }
            if (Subtype != null)
            {
                result.AddRange(Subtype.Validate());
            }
            if (Identifier != null)
            {
                Identifier.ForEach(elem => result.AddRange(elem.Validate()));
            }
            if (DateTimeElement != null)
            {
                result.AddRange(DateTimeElement.Validate());
            }
            if (Subject != null)
            {
                result.AddRange(Subject.Validate());
            }
            if (Requester != null)
            {
                result.AddRange(Requester.Validate());
            }
            if (Operator != null)
            {
                result.AddRange(Operator.Validate());
            }
            if (View != null)
            {
                result.AddRange(View.Validate());
            }
            if (DeviceNameElement != null)
            {
                result.AddRange(DeviceNameElement.Validate());
            }
            if (HeightElement != null)
            {
                result.AddRange(HeightElement.Validate());
            }
            if (WidthElement != null)
            {
                result.AddRange(WidthElement.Validate());
            }
            if (FramesElement != null)
            {
                result.AddRange(FramesElement.Validate());
            }
            if (LengthElement != null)
            {
                result.AddRange(LengthElement.Validate());
            }
            if (Content != null)
            {
                result.AddRange(Content.Validate());
            }

            return(result);
        }
Ejemplo n.º 14
0
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            Root.Clear();

            Section section = new Section();

            StringElement idElement = new StringElement("Id: " + Order.Id);

            var mapTable = Database.Table <OrderPosition>();

            var positionIds = mapTable.Where(p => p.OrderId == Order.Id);

            Order.Positions.Clear();

            foreach (var position in positionIds)
            {
                Order.Positions.Add(position);
            }

            StringElement totalSumElement = new StringElement("Total sum: " + Order.GetTotalSum());

            DateTimeElement dateElement = new DateTimeElement("Date: ", Order.Date);

            dateElement.DateSelected += (obj) =>
            {
                Order.Date = dateElement.DateValue;
            };

            StringElement positionsElement = new StringElement("See positions");

            positionsElement.Tapped += () =>
            {
                NavigationController.PushViewController(new OrderPositionListViewController(Order.Id, Database), true);
            };

            StringElement deleteElement = new StringElement("Delete");

            deleteElement.Tapped += () =>
            {
                if (!confirming)
                {
                    confirming = true;

                    Section confirmSection = new Section();

                    StringElement confirmElement = new StringElement("Are you sure?");

                    confirmElement.Alignment = UIKit.UITextAlignment.Center;

                    confirmSection.Add(confirmElement);

                    StringElement yesButton = new StringElement("Yes");

                    yesButton.Alignment = UIKit.UITextAlignment.Center;

                    yesButton.Tapped += () =>
                    {
                        Database.Execute(@"delete from OrderPosition where OrderId==" + Order.Id);

                        Database.Delete(Order);

                        NavigationController.PopViewController(true);
                    };

                    confirmSection.Add(yesButton);

                    StringElement noButton = new StringElement("No");

                    noButton.Alignment = UIKit.UITextAlignment.Center;

                    noButton.Tapped += () =>
                    {
                        confirming = false;

                        Root.Remove(confirmSection);
                    };

                    confirmSection.Add(noButton);

                    Root.Add(confirmSection);
                }
            };

            section.Add(idElement);

            section.Add(totalSumElement);

            section.Add(dateElement);

            section.Add(positionsElement);

            section.Add(deleteElement);

            Root.Add(section);
        }
Ejemplo n.º 15
0
        public override ErrorList Validate()
        {
            var result = new ErrorList();

            result.AddRange(base.Validate());

            if (Subject != null)
            {
                result.AddRange(Subject.Validate());
            }
            if (DateTimeElement != null)
            {
                result.AddRange(DateTimeElement.Validate());
            }
            if (Operator != null)
            {
                result.AddRange(Operator.Validate());
            }
            if (Identifier != null)
            {
                result.AddRange(Identifier.Validate());
            }
            if (AccessionNo != null)
            {
                result.AddRange(AccessionNo.Validate());
            }
            if (StudyId != null)
            {
                result.AddRange(StudyId.Validate());
            }
            if (SeriesId != null)
            {
                result.AddRange(SeriesId.Validate());
            }
            if (Method != null)
            {
                result.AddRange(Method.Validate());
            }
            if (Requester != null)
            {
                result.AddRange(Requester.Validate());
            }
            if (ModalityElement != null)
            {
                result.AddRange(ModalityElement.Validate());
            }
            if (DeviceNameElement != null)
            {
                result.AddRange(DeviceNameElement.Validate());
            }
            if (HeightElement != null)
            {
                result.AddRange(HeightElement.Validate());
            }
            if (WidthElement != null)
            {
                result.AddRange(WidthElement.Validate());
            }
            if (BitsElement != null)
            {
                result.AddRange(BitsElement.Validate());
            }
            if (FramesElement != null)
            {
                result.AddRange(FramesElement.Validate());
            }
            if (FrameDelay != null)
            {
                result.AddRange(FrameDelay.Validate());
            }
            if (View != null)
            {
                result.AddRange(View.Validate());
            }
            if (Content != null)
            {
                result.AddRange(Content.Validate());
            }

            return(result);
        }