# HG changeset patch
# User sl
# Date 1418749555 -3600
# Node ID 408ef0501cb7a906093cab2474a60aa18318d710
# Parent 76564df23849ee9c760ab7e3ac797a80eb0decca
Client now enforcing field creations to guarantee client side fields always
in sync.
diff -r 76564df23849 -r 408ef0501cb7 Client/Client.cs
--- a/Client/Client.cs Tue Dec 16 16:35:55 2014 +0100
+++ b/Client/Client.cs Tue Dec 16 18:05:55 2014 +0100
@@ -171,7 +171,7 @@
}
SetLayout(Layout);
- SetFields(Fields);
+ iClient.SetFields(Fields);
}
finally
{
@@ -196,34 +196,85 @@
iClient.SetLayout(aLayout);
}
-
- public void SetField(DataField aField)
+ ///
+ /// Set the specified field.
+ ///
+ ///
+ /// True if the specified field was set client side. False means you need to redefine all your fields using CreateFields.
+ public bool SetField(DataField aField)
{
- //TODO: Create fields if not present
int i = 0;
+ bool fieldFound = false;
foreach (DataField field in Fields)
{
if (field.Index == aField.Index)
{
//Update our field then
Fields[i] = aField;
+ fieldFound = true;
break;
}
i++;
}
+ if (!fieldFound)
+ {
+ //Field not found, make to use SetFields with all your fields at least once after setting your layout.
+ return false;
+ }
+
CheckConnection();
iClient.SetField(aField);
+ return true;
}
- public void SetFields(System.Collections.Generic.IList aFields)
+ ///
+ /// Use this function when updating existing fields.
+ ///
+ ///
+ public bool SetFields(System.Collections.Generic.IList aFields)
+ {
+ int fieldFoundCount = 0;
+ foreach (DataField fieldUpdate in aFields)
+ {
+ int i = 0;
+ foreach (DataField existingField in Fields)
+ {
+ if (existingField.Index == fieldUpdate.Index)
+ {
+ //Update our field then
+ Fields[i] = fieldUpdate;
+ fieldFoundCount++;
+ //Move on to the next field
+ break;
+ }
+ i++;
+ }
+ }
+
+ //
+ if (fieldFoundCount!=aFields.Count)
+ {
+ //Field not found, make sure to use SetFields with all your fields at least once after setting your layout.
+ return false;
+ }
+
+ CheckConnection();
+ iClient.SetFields(aFields);
+ return true;
+ }
+
+ ///
+ /// Use this function when creating your fields.
+ ///
+ ///
+ public void CreateFields(System.Collections.Generic.IList aFields)
{
Fields = aFields;
CheckConnection();
iClient.SetFields(aFields);
}
-
public int ClientCount()
{
CheckConnection();
diff -r 76564df23849 -r 408ef0501cb7 Client/MainForm.Designer.cs
--- a/Client/MainForm.Designer.cs Tue Dec 16 16:35:55 2014 +0100
+++ b/Client/MainForm.Designer.cs Tue Dec 16 18:05:55 2014 +0100
@@ -39,6 +39,7 @@
this.buttonSetBitmap = new System.Windows.Forms.Button();
this.buttonBitmapLayout = new System.Windows.Forms.Button();
this.buttonIndicatorsLayout = new System.Windows.Forms.Button();
+ this.buttonUpdateTexts = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// buttonSetText
@@ -145,11 +146,22 @@
this.buttonIndicatorsLayout.UseVisualStyleBackColor = true;
this.buttonIndicatorsLayout.Click += new System.EventHandler(this.buttonIndicatorsLayout_Click);
//
+ // buttonUpdateTexts
+ //
+ this.buttonUpdateTexts.Location = new System.Drawing.Point(257, 189);
+ this.buttonUpdateTexts.Name = "buttonUpdateTexts";
+ this.buttonUpdateTexts.Size = new System.Drawing.Size(75, 35);
+ this.buttonUpdateTexts.TabIndex = 29;
+ this.buttonUpdateTexts.Text = "Update Texts";
+ this.buttonUpdateTexts.UseVisualStyleBackColor = true;
+ this.buttonUpdateTexts.Click += new System.EventHandler(this.buttonUpdateTexts_Click);
+ //
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(443, 252);
+ this.Controls.Add(this.buttonUpdateTexts);
this.Controls.Add(this.buttonIndicatorsLayout);
this.Controls.Add(this.buttonBitmapLayout);
this.Controls.Add(this.buttonSetBitmap);
@@ -183,6 +195,7 @@
private System.Windows.Forms.Button buttonSetBitmap;
private System.Windows.Forms.Button buttonBitmapLayout;
private System.Windows.Forms.Button buttonIndicatorsLayout;
+ private System.Windows.Forms.Button buttonUpdateTexts;
}
}
diff -r 76564df23849 -r 408ef0501cb7 Client/MainForm.cs
--- a/Client/MainForm.cs Tue Dec 16 16:35:55 2014 +0100
+++ b/Client/MainForm.cs Tue Dec 16 18:05:55 2014 +0100
@@ -139,16 +139,12 @@
private void buttonSetText_Click(object sender, EventArgs e)
{
- //iClient.SetText(0,"Top");
- //iClient.SetText(1, "Bottom");
- //TextField top = new TextField(0, textBoxTop.Text, ContentAlignment.MiddleLeft);
-
//Set one column two lines layout
TableLayout layout = new TableLayout(1, 2);
iClient.SetLayout(layout);
//Set our fields
- iClient.SetFields(new DataField[]
+ iClient.CreateFields(new DataField[]
{
new DataField(0, textBoxTop.Text, Alignment),
new DataField(1, textBoxBottom.Text, Alignment)
@@ -183,7 +179,7 @@
}
DataField field = new DataField(0, bitmap);
- field.ColumnSpan = 2;
+ //field.ColumnSpan = 2;
iClient.SetField(field);
}
@@ -228,7 +224,7 @@
field.RowSpan = 2;
//Set texts
- iClient.SetFields(new DataField[]
+ iClient.CreateFields(new DataField[]
{
field,
new DataField(1, textBoxTop.Text, Alignment),
@@ -282,7 +278,7 @@
//Set texts
- iClient.SetFields(new DataField[]
+ iClient.CreateFields(new DataField[]
{
textFieldTop,
indicator1,
@@ -293,5 +289,21 @@
});
}
+
+ private void buttonUpdateTexts_Click(object sender, EventArgs e)
+ {
+
+ bool res = iClient.SetFields(new DataField[]
+ {
+ new DataField(0, textBoxTop.Text, Alignment),
+ new DataField(1, textBoxBottom.Text, Alignment)
+ });
+
+ if (!res)
+ {
+ MessageBox.Show("Create you fields first", "Field update error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+
+ }
}
}