1.1 --- a/Client/Client.cs Tue Dec 16 16:35:55 2014 +0100
1.2 +++ b/Client/Client.cs Tue Dec 16 18:05:55 2014 +0100
1.3 @@ -171,7 +171,7 @@
1.4 }
1.5
1.6 SetLayout(Layout);
1.7 - SetFields(Fields);
1.8 + iClient.SetFields(Fields);
1.9 }
1.10 finally
1.11 {
1.12 @@ -196,34 +196,85 @@
1.13 iClient.SetLayout(aLayout);
1.14 }
1.15
1.16 -
1.17 - public void SetField(DataField aField)
1.18 + /// <summary>
1.19 + /// Set the specified field.
1.20 + /// </summary>
1.21 + /// <param name="aField"></param>
1.22 + /// <returns>True if the specified field was set client side. False means you need to redefine all your fields using CreateFields.</returns>
1.23 + public bool SetField(DataField aField)
1.24 {
1.25 - //TODO: Create fields if not present
1.26 int i = 0;
1.27 + bool fieldFound = false;
1.28 foreach (DataField field in Fields)
1.29 {
1.30 if (field.Index == aField.Index)
1.31 {
1.32 //Update our field then
1.33 Fields[i] = aField;
1.34 + fieldFound = true;
1.35 break;
1.36 }
1.37 i++;
1.38 }
1.39
1.40 + if (!fieldFound)
1.41 + {
1.42 + //Field not found, make to use SetFields with all your fields at least once after setting your layout.
1.43 + return false;
1.44 + }
1.45 +
1.46 CheckConnection();
1.47 iClient.SetField(aField);
1.48 + return true;
1.49 }
1.50
1.51 - public void SetFields(System.Collections.Generic.IList<DataField> aFields)
1.52 + /// <summary>
1.53 + /// Use this function when updating existing fields.
1.54 + /// </summary>
1.55 + /// <param name="aFields"></param>
1.56 + public bool SetFields(System.Collections.Generic.IList<DataField> aFields)
1.57 + {
1.58 + int fieldFoundCount = 0;
1.59 + foreach (DataField fieldUpdate in aFields)
1.60 + {
1.61 + int i = 0;
1.62 + foreach (DataField existingField in Fields)
1.63 + {
1.64 + if (existingField.Index == fieldUpdate.Index)
1.65 + {
1.66 + //Update our field then
1.67 + Fields[i] = fieldUpdate;
1.68 + fieldFoundCount++;
1.69 + //Move on to the next field
1.70 + break;
1.71 + }
1.72 + i++;
1.73 + }
1.74 + }
1.75 +
1.76 + //
1.77 + if (fieldFoundCount!=aFields.Count)
1.78 + {
1.79 + //Field not found, make sure to use SetFields with all your fields at least once after setting your layout.
1.80 + return false;
1.81 + }
1.82 +
1.83 + CheckConnection();
1.84 + iClient.SetFields(aFields);
1.85 + return true;
1.86 + }
1.87 +
1.88 + /// <summary>
1.89 + /// Use this function when creating your fields.
1.90 + /// </summary>
1.91 + /// <param name="aFields"></param>
1.92 + public void CreateFields(System.Collections.Generic.IList<DataField> aFields)
1.93 {
1.94 Fields = aFields;
1.95 CheckConnection();
1.96 iClient.SetFields(aFields);
1.97 }
1.98
1.99 -
1.100 public int ClientCount()
1.101 {
1.102 CheckConnection();