Ejemplo n.º 1
0
 private bool validatefield(FieldValuePair field)
 {
     if (field.Type == null)
     {
         return(true);
     }
     if (field.Type.ToLower() == "integer")
     {
         int v;
         if (!int.TryParse(field.Value, out v))
         {
             return(false);
         }
     }
     if (field.Type.ToLower().Contains("decimal"))
     {
         decimal v;
         var     culture = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator;
         field.Value = field.Value.Replace(".", culture);
         field.Value = field.Value.Replace(",", culture);
         if (!decimal.TryParse(field.Value, out v))
         {
             return(false);
         }
     }
     return(true);
 }
 /// <summary>
 /// Sets a value for the specified field
 /// </summary>
 /// <param name="Field">The column or field name</param>
 /// <param name="Value">The new value to update</param>
 /// <param name="Mode">Sets how the update value will be applied to the existing field value</param>
 public void SetField(string Field, object Value, ValueMode Mode)
 {
     if (Fields.ContainsKey(Field))
         Fields[Field] = new FieldValuePair(Field, Value, Mode);
     else
         Fields.Add(Field, new FieldValuePair(Field, Value, Mode));
 }
Ejemplo n.º 3
0
 public static string ValueAsString(this FieldValuePair pair)
 {
     if (pair.Value == null)
     {
         return(null);
     }
     return(pair.Value.ToString());
 }
Ejemplo n.º 4
0
        /// <summary>
        /// This event is fired AFTER the fieldValuePair is parsed.
        /// </summary>
        /// <param name="xmlNode"></param>
        /// <param name="fieldValuePair"></param>
        /// <returns>True if cancelled else false if not.</returns>
        public bool Parsed(XmlNode xmlNode, ref FieldValuePair fieldValuePair)
        {
            // initial value
            bool cancel = false;

            // Add any post processing code here. Set cancel to true to abort adding this object.

            // return value
            return(cancel);
        }
 /// <summary>
 /// Sets a value for the specified field
 /// </summary>
 /// <param name="Field">The column or field name</param>
 /// <param name="Value">The new value to update</param>
 /// <param name="Mode">Sets how the update value will be applied to the existing field value</param>
 public void SetField(string Field, object Value, ValueMode Mode)
 {
     if (Fields.ContainsKey(Field))
     {
         Fields[Field] = new FieldValuePair(Field, Value, Mode);
     }
     else
     {
         Fields.Add(Field, new FieldValuePair(Field, Value, Mode));
     }
 }
Ejemplo n.º 6
0
        private static FieldValuePair ToFieldPair(FieldValue fieldValue)
        {
            var pair = new FieldValuePair();

            pair.Value = ParseFieldValueValue(fieldValue.Value);
            var field = new FieldRef();

            field.Guids      = fieldValue.Guids?.ToList() ?? new List <Guid>();
            field.ArtifactId = fieldValue.ArtifactID;
            field.Name       = fieldValue.Name;
            pair.Field       = field;
            return(pair);
        }
Ejemplo n.º 7
0
        public void ValueAsSingleChoice_ValueIsNull_ReturnsNull()
        {
            //ARRANGE
            var pair = new FieldValuePair();

            pair.Value = null;

            //ACT
            var result = FieldValuePairExtensions.ValueAsSingleChoice(pair);

            //ASSERT
            Assert.Null(result);
        }
Ejemplo n.º 8
0
        public void ValueAsSingleChoice_ValueIsNotNull_ReturnsCorrectField()
        {
            //ARRANGE
            var pair = new FieldValuePair();

            pair.Value = Newtonsoft.Json.JsonConvert.SerializeObject(new ChoiceRef(123));

            //ACT
            var result = FieldValuePairExtensions.ValueAsSingleChoice(pair);

            //ASSERT
            Assert.NotNull(result);
            Assert.Equal(123, result.ArtifactId);
        }
Ejemplo n.º 9
0
        public static RelativityObject ValueAsSingleObject(this FieldValuePair pair)
        {
            if (pair.Value == null)
            {
                return(null);
            }
            if (pair.Value is RelativityObject)
            {
                return(pair.Value as RelativityObject);
            }
            var obj = Newtonsoft.Json.JsonConvert.DeserializeObject <RelativityObject>(pair.Value.ToString());

            return(obj);
        }
Ejemplo n.º 10
0
        public static IEnumerable <RelativityObject> ValueAsMultiObject(this FieldValuePair pair)
        {
            if (pair.Value == null)
            {
                return(null);
            }
            if (pair.Value.IsEnumerableOf <RelativityObject>())
            {
                return(pair.Value as IEnumerable <RelativityObject>);
            }
            var obj = Newtonsoft.Json.JsonConvert.DeserializeObject <IEnumerable <RelativityObject> >(pair.Value.ToString());

            return(obj);
        }
Ejemplo n.º 11
0
        public static IEnumerable <ChoiceRef> ValueAsMultiChoice(this FieldValuePair pair)
        {
            if (pair.Value == null)
            {
                return(null);
            }
            else if (pair.Value.IsEnumerableOf <ChoiceRef>())
            {
                return(pair.Value as IEnumerable <ChoiceRef>);
            }
            var choices = Newtonsoft.Json.JsonConvert.DeserializeObject <IEnumerable <ChoiceRef> >(pair.Value.ToString());

            return(choices);
        }
Ejemplo n.º 12
0
        public static ChoiceRef ValueAsSingleChoice(this FieldValuePair pair)
        {
            if (pair.Value == null)
            {
                return(null);
            }
            if (pair.Value is ChoiceRef)
            {
                return(pair.Value as ChoiceRef);
            }
            var choice = Newtonsoft.Json.JsonConvert.DeserializeObject <ChoiceRef>(pair.Value.ToString());

            return(choice);
        }
Ejemplo n.º 13
0
        private static FieldValue ToFieldValue(FieldValuePair pair)
        {
            var value = new FieldValue();

            if (pair.Field == null)
            {
                throw new NullReferenceException("No field loaded on fieldValuePair");
            }
            value.Guids      = pair.Field.Guids?.ToList() ?? new List <Guid>();
            value.ArtifactID = pair.Field.ArtifactId;
            value.Name       = pair.Field.Name;
            Enum.TryParse <kCura.Relativity.Client.FieldType>(pair.Field.FieldType, out var fieldType);
            value.Value = ParseValue(pair.Value, fieldType);

            value.FieldType = fieldType;
            return(value);
        }
        public void ValueAsSingleObject_FieldValueIsSingleObject_ReturnsValueAsRelativityObject()
        {
            //ARRANGE
            var pair = new FieldValuePair();

            pair.Value = new RelativityObject
            {
                ArtifactId = 123
            };

            //ACT
            var r = pair.ValueAsSingleObject();

            //ASSERT
            Assert.IsType <RelativityObject>(r);
            Assert.Equal(123, r.ArtifactId);
        }
        public void ValueAsSingleObject_FieldValueIsSingleObjectString_ReturnsValueAsRelativityObject()
        {
            //ARRANGE
            var pair = new FieldValuePair();

            pair.Value = @"{ 
                             ""ArtifactID"":123,
                             ""Guids"":[],
                             ""Name"":""Single 1""
                          }";

            //ACT
            var r = pair.ValueAsSingleObject();

            //ASSERT
            Assert.IsType <RelativityObject>(r);
            Assert.Equal(123, r.ArtifactId);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Hydrates a list of Resources from the results of a Bulk Find operation
        /// </summary>
        /// <param name="result">Rows of resources where the fields are seperated by pipes.</param>
        /// <returns></returns>
        public static List <Resource> HydrateBulkResources(String result)
        {
            List <Resource> resources = new List <Resource>();
            Resource        resource  = null;

            //Break result into string array - one item for each resource.
            char[]   delimiters      = new char[] { '\r', '\n' };
            string[] resourceStrings = result.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);


            //Only return the first resource in result set.
            //Row 0 is headers. Row 1 is field values.

            List <string> headerFields   = new List <string>();
            List <string> resourceFields = new List <string>();

            for (int n = 0; n < resourceStrings.Count(); n++)
            {
                if (n == 0)
                {
                    headerFields = HydrateFields(resourceStrings[n]);
                    continue;
                }

                resourceFields = HydrateFields(resourceStrings[n]);

                // build a Resource from second row
                FieldValuePair[] fvp = new FieldValuePair[headerFields.Count];
                for (int i = 0; i < headerFields.Count; i++)
                {
                    fvp[i]       = new FieldValuePair();
                    fvp[i].Id    = headerFields[i];
                    fvp[i].Value = resourceFields[i];
                }
                resource = new Resource {
                    Field = fvp
                };
                resources.Add(resource);
            }
            return(resources);
        }
Ejemplo n.º 17
0
        protected viewValidations getDataForView(int viewId)
        {
            //we get all the relevant fields for this view
            var viewFields = GetFieldsForView(viewId);

            //we find the date fields
            var dataFields = (from field in viewFields
                              where
                              field.dataType == Constants.TIMEPICKER ||
                              field.dataType == Constants.DATEPICKER ||
                              field.dataType == Constants.EDITTEXT ||
                              field.dataType == Constants.CHECKBOX ||
                              field.dataType == Constants.RADIOBUTTON
                              select field).ToList();
            var context          = this;
            var valueFields      = new List <FieldValuePair>();
            var validationIssues = new List <DataValidationIssue>();

            foreach (var field in dataFields)
            {
                var resultObject = new FieldValuePair()
                {
                    Field = field, Value = string.Empty
                };
                var fieldView = new ValidationObject()
                {
                    isRequired = field.IsRequired,
                    label      = field.Label,
                    //value = view.Text,
                    //viewId = view.Id,
                    validation = field.validation
                };
                switch (field.dataType)
                {
                case Constants.TIMEPICKER:
                case Constants.DATEPICKER:
                {
                    var view = field.GetDataView <EditText>(this);
                    fieldView.value      = view.Text;
                    fieldView.viewId     = view.Id;
                    fieldView.viewObject = view;

                    var validationResult = DateValidator.validates(fieldView);
                    clearError(view);

                    if (validationResult != null)
                    {
                        validationIssues.Add(validationResult);
                    }

                    if (string.IsNullOrWhiteSpace(view.Text))
                    {
                        continue;
                    }

                    resultObject.Value = view.Text;
                    break;
                }

                case Constants.EDITTEXT:
                {
                    var view = field.GetDataView <EditText>(this);
                    fieldView.value      = view.Text;
                    fieldView.viewId     = view.Id;
                    fieldView.viewObject = view;
                    clearError(view);
                    var validationResult = TextValidator.validates(fieldView);
                    if (validationResult != null)
                    {
                        validationIssues.Add(validationResult);
                    }

                    if (string.IsNullOrWhiteSpace(view.Text))
                    {
                        continue;
                    }

                    resultObject.Value = view.Text;
                    break;
                }

                case Constants.CHECKBOX:
                {
                    var view = field.GetDataView <CheckBox>(this);
                    if (!view.Checked)
                    {
                        continue;
                    }
                    resultObject.Value = Constants.DEFAULT_CHECKED;
                    break;
                }

                case Constants.RADIOBUTTON:
                {
                    var view = field.GetDataView <RadioButton>(this);
                    if (view == null)
                    {
                        view = field.GetDataView <RadioButton>(this);
                    }

                    if (!view.Checked)
                    {
                        continue;
                    }
                    resultObject.Value = Constants.DEFAULT_CHECKED;
                    break;
                }

                default:
                {
                    throw new ArgumentNullException("Could not find view for field " + field.name);
                }
                }

                if (string.IsNullOrWhiteSpace(resultObject.Value))
                {
                    throw new ArgumentNullException("Could not find view for field " + field.name);
                }
                valueFields.Add(resultObject);
            }

            return(new viewValidations()
            {
                TemporalViewData = valueFields, Validations = validationIssues
            });
        }
Ejemplo n.º 18
0
        private void Calculate()
        {
            var Context = new TempoDataBaseContext();
            var cp      = this.DataContext as SaldoItem;

            if (cp != null && (cp.Relookup != 0 || cp.RCODELOOKUP != 0))
            {
                string search = Entrence.ConfigFirmaToLookup.GetField(ConfigTempoSinglenton.GetInstance().CurrentFirma.Id,
                                                                      cp.Relookup);
                List <FieldValuePair> current = new List <FieldValuePair>();
                LookupModel           lookup  = null;
                if (cp.Relookup > 0)
                {
                    lookup = cp.SysLookup ? Context.GetSysLookup(cp.Relookup):Context.GetLookup(cp.Relookup);
                }
                else
                {
                    lookup = cp.SysLookup ? Context.GetSysLookup(cp.Relookup) : Context.GetLookup(cp.Relookup);
                }
                int i = 0;
                foreach (var item in lookup.Fields)
                {
                    if (cp.SysLookup && i == 0)
                    {
                        i++;
                        continue;
                    }
                    var nf = new FieldValuePair
                    {
                        Name       = item.Name,
                        Length     = item.Length,
                        Value      = i == 1 && string.IsNullOrWhiteSpace(search)?searcher.Text:"",
                        ReadOnly   = item.NameEng != "Id",
                        IsRequared = item.IsRequared,
                        IsUnique   = item.IsUnique,
                        RTABLENAME = item.RTABLENAME,
                        FieldName  = item.NameEng
                    };

                    if (item.NameEng == search)
                    {
                        nf.Value = searcher.Text;
                    }
                    current.Add(nf);
                }

                LookupsEdidViewModels vmm = new LookupsEdidViewModels(current, lookup.LookUpMetaData.Tablename, true);
                EditInsertLookups     ds  = new EditInsertLookups(vmm);
                ds.ShowDialog();
                if (ds.DialogResult.HasValue && ds.DialogResult.Value)
                {
                    //nov red
                    if (!cp.SysLookup)
                    {
                        lookup.Fields.Add(new TableField
                        {
                            DbField    = "integer",
                            GROUP      = 4,
                            Id         = 4,
                            Length     = 4,
                            IsRequared = false,
                            NameEng    = "FIRMAID",
                            Name       = "Фирма Номер"
                        });
                    }
                    bool sys = cp.SysLookup?!Context.SaveRow(ds.GetNewFields(), lookup):!Context.SaveRow(ds.GetNewFields(), lookup, ConfigTempoSinglenton.GetInstance().CurrentFirma.Id);
                    if (sys)
                    {
                        MessageBoxWrapper.Show(
                            "Получвава се дублиране на елемент от номенклатура! Номенклатурата не е записана!");
                    }
                    else
                    {
                        var dc  = DataContext as SaldoItem;
                        var dat = ds.GetNewFields();
                        if (dat != null)
                        {
                            dc.Value     = dat[1];
                            dc.Lookupval = dat[2];
                        }
                        if (dat != null && dat.Count > 5)
                        {
                            dc.Bulstad = dat[3];
                            dc.Vat     = dat[4];
                        }
                        dc.LiD = 0;
                        OnRefreshExecuted(new FastLookupEventArgs(dc));
                    }
                }
                //cp.LookUp.Add(new SaldoItem { Value = ds.GetNewFields()[2], Key = ds.GetNewFields()[1] });
            }
        }
Ejemplo n.º 19
0
 public static int ValueAsWholeNumber(this FieldValuePair pair)
 {
     return(Convert.ToInt32(pair.Value));
 }
Ejemplo n.º 20
0
        /// <summary>
        /// This method is used to parse a list of 'FieldValuePair' objects.
        /// </summary>
        /// <param name="XmlNode">The XmlNode to be parsed.</param>
        /// <returns>A list of 'FieldValuePair' objects.</returns>
        public List <FieldValuePair> ParseFieldValuePairs(XmlNode xmlNode, List <FieldValuePair> fieldValuePairs = null)
        {
            // locals
            FieldValuePair fieldValuePair = null;
            bool           cancel         = false;

            // if the xmlNode exists
            if (xmlNode != null)
            {
                // get the full name for this node
                string fullName = xmlNode.GetFullName();

                // if this is the new collection line
                if (fullName == "Mirror.Fields")
                {
                    // Raise event Parsing is starting.
                    cancel = Parsing(xmlNode);

                    // If not cancelled
                    if (!cancel)
                    {
                        // create the return collection
                        fieldValuePairs = new List <FieldValuePair>();
                    }
                }
                // if this is the new object line and the return collection exists
                else if ((fullName == "Mirror.Fields.FieldValuePair") && (fieldValuePairs != null))
                {
                    // Create a new object
                    fieldValuePair = new FieldValuePair();

                    // Perform pre parse operations
                    cancel = Parsing(xmlNode, ref fieldValuePair);

                    // If not cancelled
                    if (!cancel)
                    {
                        // parse this object
                        fieldValuePair = ParseFieldValuePair(ref fieldValuePair, xmlNode);
                    }

                    // Perform post parse operations
                    cancel = Parsed(xmlNode, ref fieldValuePair);

                    // If not cancelled
                    if (!cancel)
                    {
                        // Add this object to the return value
                        fieldValuePairs.Add(fieldValuePair);
                    }
                }

                // if there are ChildNodes
                if (xmlNode.HasChildNodes)
                {
                    // iterate the child nodes
                    foreach (XmlNode childNode in xmlNode.ChildNodes)
                    {
                        // self call this method for each childNode
                        fieldValuePairs = ParseFieldValuePairs(childNode, fieldValuePairs);
                    }
                }
            }

            // return value
            return(fieldValuePairs);
        }
Ejemplo n.º 21
0
        private static uint ReadFieldValuePair(ref ReadOnlySequence <byte> data, out object value)
        {
            value = null;
            uint size = ReadShortString(ref data, out ShortString name);

            byte fieldType = ReadOctet(ref data);

            size += sizeof(byte);

            switch (fieldType)
            {
            case (byte)'t':
                size += sizeof(byte);
                value = new FieldValuePair <Primitives.Boolean>(name, ReadBoolean(ref data));
                break;

            case (byte)'b':
                size += sizeof(byte);
                value = new FieldValuePair <ShortShortInt>(name, ReadShortShortInt(ref data));
                break;

            case (byte)'B':
                size += sizeof(byte);
                value = new FieldValuePair <ShortShortUInt>(name, ReadShortShortUInt(ref data));
                break;

            case (byte)'U':
                size += sizeof(Int16);
                value = new FieldValuePair <ShortInt>(name, ReadShortInt(ref data));
                break;

            case (byte)'u':
                size += sizeof(UInt16);
                value = new FieldValuePair <ShortUInt>(name, ReadShortUInt(ref data));
                break;

            case (byte)'I':
                size += sizeof(Int32);
                value = new FieldValuePair <LongInt>(name, ReadLongInt(ref data));
                break;

            case (byte)'i':
                size += sizeof(Int32);
                value = new FieldValuePair <LongUInt>(name, ReadLongUInt(ref data));
                break;

            case (byte)'L':
                size += sizeof(Int64);
                value = new FieldValuePair <LongLongInt>(name, ReadLongLongInt(ref data));
                break;

            case (byte)'l':
                size += sizeof(UInt64);
                value = new FieldValuePair <LongLongUInt>(name, ReadLongLongUInt(ref data));
                break;

            case (byte)'f':
                size += sizeof(float);
                value = new FieldValuePair <Primitives.Float>(name, ReadFloat(ref data));
                break;

            case (byte)'d':
                size += sizeof(double);
                value = new FieldValuePair <Primitives.Double>(name, ReadDouble(ref data));
                break;

            case (byte)'D':
                size += sizeof(byte) + 4;
                value = new FieldValuePair <Primitives.Decimal>(name, ReadDecimal(ref data));
                break;

            case (byte)'s':
                size += ReadShortString(ref data, out var shortString);
                value = new FieldValuePair <ShortString>(name, shortString);
                break;

            case (byte)'S':
                size += ReadLongString(ref data, out var longString);
                value = new FieldValuePair <LongString>(name, longString);
                break;

            case (byte)'A':
                size += ReadFieldArray(ref data, out FieldArray <object> fieldArray);
                value = new FieldValuePair <FieldArray <object> >(name, fieldArray);
                break;

            case (byte)'T':
                size += 8;
                value = new FieldValuePair <Timestamp>(name, new FieldValue <Timestamp>(ReadTimestamp(ref data)));
                break;

            case (byte)'F':
                size += ReadTable(ref data, out Table table);
                value = new FieldValuePair <Table>(name, table);
                break;

            case (byte)'V':
                size += 0;
                value = null;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(fieldType));
            }

            return(size);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// This method is used to parse FieldValuePair objects.
        /// </summary>
        public FieldValuePair ParseFieldValuePair(ref FieldValuePair fieldValuePair, XmlNode xmlNode)
        {
            // if the fieldValuePair object exists and the xmlNode exists
            if ((fieldValuePair != null) && (xmlNode != null))
            {
                // get the full name of this node
                string fullName = xmlNode.GetFullName();

                // Check the name of this node to see if it is mapped to a property
                switch (fullName)
                {
                case "Mirror.Fields.FieldValuePair.EnumDataTypeName":

                    // Set the value for fieldValuePair.EnumDataTypeName
                    fieldValuePair.EnumDataTypeName = xmlNode.FormattedNodeValue;

                    // required
                    break;

                case "Mirror.Fields.FieldValuePair.FieldDataType":

                    // Set the value for fieldValuePair.FieldDataType
                    // Select the default value of this enum fieldValuePair.FieldDataType = EnumHelper.GetEnumValue<XmlMirror.Runtime.Enumerations.DataTypeEnum>(xmlNode.FormattedNodeValue, XmlMirror.Runtime.Enumerations.DataTypeEnum);

                    // required
                    break;

                case "Mirror.Fields.FieldValuePair.FieldDataTypeString":

                    // Set the value for fieldValuePair.FieldDataTypeString
                    fieldValuePair.FieldDataTypeString = xmlNode.FormattedNodeValue;

                    // required
                    break;

                case "Mirror.Fields.FieldValuePair.FieldName":

                    // Set the value for fieldValuePair.FieldName
                    fieldValuePair.FieldName = xmlNode.FormattedNodeValue;

                    // required
                    break;

                case "Mirror.Fields.FieldValuePair.FieldValue":

                    // Set the value for fieldValuePair.FieldValue
                    // fieldValuePair.FieldValue = // this field must be parsed manually.

                    // required
                    break;

                case "Mirror.Fields.FieldValuePair.IsEnumeration":

                    // Set the value for fieldValuePair.IsEnumeration
                    fieldValuePair.IsEnumeration = BooleanHelper.ParseBoolean(xmlNode.FormattedNodeValue, false, false);

                    // required
                    break;

                case "Mirror.Fields.FieldValuePair.Skip":

                    // Set the value for fieldValuePair.Skip
                    fieldValuePair.Skip = BooleanHelper.ParseBoolean(xmlNode.FormattedNodeValue, false, false);

                    // required
                    break;
                }

                // if there are ChildNodes
                if (xmlNode.HasChildNodes)
                {
                    // iterate the child nodes
                    foreach (XmlNode childNode in xmlNode.ChildNodes)
                    {
                        // append to this FieldValuePair
                        fieldValuePair = ParseFieldValuePair(ref fieldValuePair, childNode);
                    }
                }
            }

            // return value
            return(fieldValuePair);
        }
Ejemplo n.º 23
0
        // <Summary>
        // This method is used to export a FieldValuePair object to xml.
        // </Summary>
        public string ExportFieldValuePair(FieldValuePair fieldValuePair, int indent = 0)
        {
            // initial value
            string fieldValuePairXml = "";

            // locals
            string indentString  = TextHelper.Indent(indent);
            string indentString2 = TextHelper.Indent(indent + 2);

            // If the fieldValuePair object exists
            if (NullHelper.Exists(fieldValuePair))
            {
                // Create a StringBuilder
                StringBuilder sb = new StringBuilder();

                // Append the indentString
                sb.Append(indentString);

                // Write the open fieldValuePair node
                sb.Append("<FieldValuePair>" + Environment.NewLine);

                // Write out each property

                // Write out the value for EnumDataTypeName

                sb.Append(indentString2);
                sb.Append("<EnumDataTypeName>" + fieldValuePair.EnumDataTypeName + "</EnumDataTypeName>" + Environment.NewLine);

                // Write out the value for FieldDataType

                sb.Append(indentString2);
                sb.Append("<FieldDataType>" + fieldValuePair.FieldDataType + "</FieldDataType>" + Environment.NewLine);

                // Write out the value for FieldDataTypeString

                sb.Append(indentString2);
                sb.Append("<FieldDataTypeString>" + fieldValuePair.FieldDataTypeString + "</FieldDataTypeString>" + Environment.NewLine);

                // Write out the value for FieldName

                sb.Append(indentString2);
                sb.Append("<FieldName>" + fieldValuePair.FieldName + "</FieldName>" + Environment.NewLine);

                // Write out the value for FieldValue

                sb.Append(indentString2);
                sb.Append("<FieldValue>" + fieldValuePair.FieldValue + "</FieldValue>" + Environment.NewLine);

                // Write out the value for IsEnumeration

                sb.Append(indentString2);
                sb.Append("<IsEnumeration>" + fieldValuePair.IsEnumeration + "</IsEnumeration>" + Environment.NewLine);

                // Write out the value for Skip

                sb.Append(indentString2);
                sb.Append("<Skip>" + fieldValuePair.Skip + "</Skip>" + Environment.NewLine);

                // Append the indentString
                sb.Append(indentString);

                // Write out the close fieldValuePair node
                sb.Append("</FieldValuePair>" + Environment.NewLine);

                // set the return value
                fieldValuePairXml = sb.ToString();
            }
            // return value
            return(fieldValuePairXml);
        }
Ejemplo n.º 24
0
        protected void getDataForView(int viewId)
        {
            //we get all the relevant fields for this view
            var viewFields = GetFieldsForView(viewId);

            //we find the date fields
            var dataFields = (from field in viewFields
                              where
                              field.dataType == Constants.TIMEPICKER ||
                              field.dataType == Constants.DATEPICKER ||
                              field.dataType == Constants.EDITTEXT ||
                              field.dataType == Constants.CHECKBOX ||
                              field.dataType == Constants.RADIOBUTTON
                              select field).ToList();
            var context     = this;
            var valueFields = new List <FieldValuePair>();

            foreach (var field in dataFields)
            {
                var resultObject = new FieldValuePair()
                {
                    Field = field, Value = string.Empty
                };
                switch (field.dataType)
                {
                case Constants.TIMEPICKER:
                case Constants.DATEPICKER:
                {
                    var view = field.GetDataView <EditText>(this);
                    if (string.IsNullOrWhiteSpace(view.Text))
                    {
                        continue;
                    }

                    resultObject.Value = view.Text;
                    break;
                }

                case Constants.EDITTEXT:
                {
                    var view = field.GetDataView <EditText>(this);
                    if (string.IsNullOrWhiteSpace(view.Text))
                    {
                        continue;
                    }

                    resultObject.Value = view.Text;
                    break;
                }

                case Constants.CHECKBOX:
                {
                    var view = field.GetDataView <CheckBox>(this);
                    if (!view.Checked)
                    {
                        continue;
                    }
                    resultObject.Value = Constants.DEFAULT_CHECKED;
                    break;
                }

                case Constants.RADIOBUTTON:
                {
                    var view = field.GetDataView <RadioButton>(this);
                    if (!view.Checked)
                    {
                        continue;
                    }
                    resultObject.Value = Constants.DEFAULT_CHECKED;
                    break;
                }

                default:
                {
                    throw new ArgumentNullException("Could not find view for field " + field.name);
                }
                }

                if (string.IsNullOrWhiteSpace(resultObject.Value))
                {
                    throw new ArgumentNullException("Could not find view for field " + field.name);
                }
                valueFields.Add(resultObject);
            }
            AppInstance.Instance.TemporalViewData[viewId] = valueFields;
        }
Ejemplo n.º 25
0
        /// <summary>
        /// This method returns the properties for an object type.
        /// This method will have null property values for each field value pair.
        /// </summary>
        /// <param name="sourceObject"></param>
        /// <returns></returns>
        public static List <FieldValuePair> GetPropertyAttributes(Type type, bool skipReadOnlyProperties = false)
        {
            // Initial Value
            List <FieldValuePair> properties = new List <FieldValuePair>();

            // Get the value of this object
            object propertyValue = null;

            // skip is set to true if skipReadOnlyProperties and the property does not have a Setter (GetSetMethod() returns null)
            bool skip = false;

            // if the type exists
            if (type != null)
            {
                // Get a propretyInfo Array from sourceObject
                PropertyInfo[] propertyTypes = type.GetProperties();

                // loop through each property
                foreach (PropertyInfo infoObject in propertyTypes)
                {
                    // reset the value for skip
                    skip = false;

                    // get property name
                    string propertyName = infoObject.Name;

                    // convert the dataType
                    string dataType = infoObject.PropertyType.ToString();

                    // If this is not a 'SystemProperty'.
                    if (!SystemProperty(propertyName))
                    {
                        // if skip read only properties is true
                        if (skipReadOnlyProperties)
                        {
                            // if the GetSetMethod() is null, then skip this property
                            skip = (infoObject.GetSetMethod() == null);
                        }

                        // if the field should not be skipped
                        if (!skip)
                        {
                            // Create new field value pair object
                            FieldValuePair property = new FieldValuePair(propertyName, propertyValue);

                            // if this Field is an Enumeration
                            if (infoObject.PropertyType.IsEnum)
                            {
                                // Set IsEnumeration to true
                                property.IsEnumeration = true;

                                // Get the type for this enum
                                Type enumType = infoObject.PropertyType;

                                // Set teh EnumDataTypeName
                                property.EnumDataTypeName = enumType.ToString();

                                // set the dataTypeString (which is parsed into the FieldDataType)
                                property.FieldDataTypeString = enumType.Name;
                            }
                            else
                            {
                                // set the dataTypeString (which is parsed into the FieldDataType)
                                property.FieldDataTypeString = dataType;
                            }

                            // Now add this property to properties collection.
                            properties.Add(property);
                        }
                    }
                }
            }

            // Return Value
            return(properties);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Performes the merge and saves the files with the given Format
        /// </summary>
        /// <param name="DestinationFolder"></param>
        /// <param name=""></param>
        public void Merge(string DestinationFolder, Microsoft.Office.Interop.Word.WdSaveFormat Format, string FileNameKey, bool CreateFolder = true)
        {
            Microsoft.Office.Interop.Word.Application wordApplication = null;
            Microsoft.Office.Interop.Word.Document    wordDocument    = null;

            bool FileNameKeyExists = false;

            foreach (Dictionary <string, string> FieldValuePair in MergeFields)
            {
                if (FieldValuePair.ContainsKey(FileNameKey))
                {
                    FileNameKeyExists = true;
                    break;
                }
            }
            if (!FileNameKeyExists)
            {
                throw new ArgumentException("The given key for FileName doesn't exist");
            }

            if (!Directory.Exists(DestinationFolder))
            {
                if (!CreateFolder)
                {
                    throw new IOException("Destination folder doesn't exist");
                }
                else
                {
                    Directory.CreateDirectory(DestinationFolder);
                }
            }
            try
            {
                wordApplication = new Microsoft.Office.Interop.Word.Application();
                foreach (Dictionary <string, string> FieldValuePair in MergeFields)
                {
                    Microsoft.Office.Interop.Word.Document MergeDocument  = wordApplication.Documents.Add(wordDocumentPath);
                    Microsoft.Office.Interop.Word.Fields   DocumentFields = MergeDocument.Fields;
                    //Search through fields and replace any Mergefield found
                    foreach (Microsoft.Office.Interop.Word.Field Field in DocumentFields)
                    {
                        string FieldText = Field.Code.Text;
                        if (FieldText.StartsWith(" MERGEFIELD"))
                        {
                            string FieldName = FieldText.Substring(11, FieldText.Length - 11).Trim();
                            foreach (KeyValuePair <string, string> Entry in FieldValuePair)
                            {
                                if (Entry.Key.Equals(FieldName, StringComparison.CurrentCultureIgnoreCase))
                                {
                                    Field.Select();
                                    wordApplication.Selection.TypeText(Entry.Value);
                                }
                            }
                        }
                    }
                    Marshal.ReleaseComObject(DocumentFields);

                    Microsoft.Office.Interop.Word.Sections DocumentSections = MergeDocument.Sections;
                    //Search through the headers and footers for Mergefields and replace it
                    foreach (Microsoft.Office.Interop.Word.Section Section in DocumentSections)
                    {
                        Microsoft.Office.Interop.Word.Fields HeaderFields = Section.Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Fields;
                        foreach (Microsoft.Office.Interop.Word.Field Field in HeaderFields)
                        {
                            string FieldText = Field.Code.Text;
                            if (FieldText.StartsWith(" MERGEFIELD"))
                            {
                                string FieldName = FieldText.Substring(11, FieldText.Length - 11).Trim();
                                foreach (KeyValuePair <string, string> Entry in FieldValuePair)
                                {
                                    if (Entry.Key.Equals(FieldName, StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        Field.Select();
                                        wordApplication.Selection.TypeText(Entry.Value);
                                    }
                                }
                            }
                        }
                        Marshal.ReleaseComObject(HeaderFields);
                    }
                    Marshal.ReleaseComObject(DocumentSections);
                    MergeDocument.SaveAs2(Path.Combine(DestinationFolder, FieldValuePair[FileNameKey]), Format);
                    MergeDocument.Close(false);
                    Marshal.ReleaseComObject(MergeDocument);
                }
            }
            ///TODO
            catch (Exception)
            {
                throw;
            }
            finally
            {
                wordApplication.Quit(false);
                Marshal.ReleaseComObject(wordApplication);
            }
        }