I have a WinForms App that the user can use to input values. This is then serialized into a XML.
Here is a bit of code (XML and C#) to hopefully give you guys a idea.
Design View
The WinForm Zone Tab
The Combobox in the top right edited in paint by me. The idea is the user can toggle between English, French & Russian. The static data will translate to the language change to. For user inputted data maybe the Data can be selected, edited and saved under the new language.
e.g If there was only English Data inputed and French is selected the static fields would change to their French names.
As there is no French inputed data (Look at Zone Names), the English Data will populate the Grid however the user will have to edit the value to French, so Bathroom > Salle de Bains and Salle de Bains would be saved under French. If the user then toggled to English, Bathroom would be displayed again.
C# Code View [The FCMZone Class]
public class FCMZone
{
public string id { get; set; }
public string name { get; set; }
public int icon { get; set; }
public string group { get; set; }
public string listIndex { get; set; }
public string excludedSources { get; set; }
public CheckState avEnable { get; set; }
public CheckState audioOnly { get; set; }
public MyCheckBoxItem chkBoxAVEnable;
public MyCheckBoxItem chkBoxAudioOnly;
public List<FCMOption> fusionZoneOptions;
public List<FCMSource> sourceExclusion;
public List<FCMLightingFixture> lightingFixtures;
public List<FCMWindowFixture> windowFixtures;
public List<FCMLightingScene> lightingScenes;
public List<FALutronKeypad> lightingKeypadIDs;
public List<FALutronKeypad> windowKeypadIDs;
public FCMZone(string zId, string nm, Icon icn, string grp, CheckBox avEn, CheckBox aOnly, string lstIndx)
{
id = zId;
name = nm;
icon = icn.IconId;
group = grp;
avEnable = avEn.CheckState;
audioOnly = aOnly.CheckState;
chkBoxAVEnable = new MyCheckBoxItem(false);
chkBoxAudioOnly = new MyCheckBoxItem(false);
fusionZoneOptions = new List<FCMOption>();
sourceExclusion = new List<FCMSource>();
listIndex = lstIndx;
excludedSources = "All Available";
updateCheckbox();
}
public FCMZone(FCMZone fZone)
{
id = fZone.id;
name = fZone.name;
icon = fZone.icon;
group = fZone.group;
avEnable = fZone.avEnable;
audioOnly = fZone.audioOnly;
listIndex = fZone.listIndex;
chkBoxAVEnable = new MyCheckBoxItem(false);
chkBoxAudioOnly = new MyCheckBoxItem(false);
fusionZoneOptions = new List<FCMOption>();
sourceExclusion = new List<FCMSource>();
updateCheckbox();
}
public FCMZone(FusionZone zn, ZoneProps znProps)
{
id = zn.Id;
name = zn.Name;
icon = zn.IconID;
var myValue = zn.Group;
int parsedValue;
if (Int32.TryParse(myValue, out parsedValue))
{
// zn.Group is a ID number
var fcmZoneGroup = znProps.systemZoneGroupList.Find(zg => zg.id == parsedValue.ToString());
group = fcmZoneGroup.name;
}
else
{
// zn.Group is a word.
group = myValue;
}
listIndex = zn.ListIndex;
excludedSources = zn.ExcludedSources;
if (zn.AVEnable == "1")
avEnable = CheckState.Checked;
else
avEnable = CheckState.Unchecked;
if (zn.AudioOnly == "1")
audioOnly = CheckState.Checked;
else
audioOnly = CheckState.Unchecked;
chkBoxAVEnable = new MyCheckBoxItem(false);
chkBoxAudioOnly = new MyCheckBoxItem(false);
fusionZoneOptions = new List<FCMOption>();
sourceExclusion = new List<FCMSource>();
updateCheckbox();
}
}
How it builds from a FCMZone to XML [The FusionSystem that contains all the lists]
public class FusionSystem
{
// All list items that will be serialised to the fusion system.
public List<FusionOption> optionList = new List<FusionOption>();
public List<FusionSource> sourceList = new List<FusionSource>();
public List<FusionZoneGroup> zoneGroupList = new List<FusionZoneGroup>();
public List<FusionZone> zoneList = new List<FusionZone>();
public List<FusionUser> userList = new List<FusionUser>();
public List<FusionSipGroup> sipGroupList;
public List<FusionSip> sipList;
public List<FusionCamGroup> camGroupList;
public List<FusionCam> camList;
public FusionLightingProperties lightingProperties;
public FusionWindowProperties windowProperties;
}
XML Snippet [ The XML, I've left the Bathroom Zone and removed the others for ease]
<?xml version="1.0" encoding="utf-8"?>
<FusionSystem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<optionList>
<sourceList>
</sourceList>
<zoneGroupList>
<FusionZoneGroup>
<Id>1</Id>
<Name>Fusion</Name>
<Icon>24</Icon>
<Ident />
<ListIndex>0</ListIndex>
</FusionZoneGroup>
<FusionZoneGroup>
<Id>2</Id>
<Name>Demo</Name>
<Icon>23</Icon>
<Ident>Demo</Ident>
<ListIndex>1</ListIndex>
</FusionZoneGroup>
</zoneGroupList>
<zoneList>
<FusionZone>
</FusionZone>
<FusionZone>
</FusionZone>
<FusionZone>
</FusionZone>
<FusionZone>
</FusionZone>
<FusionZone>
<ZoneOptionList>
<FusionZoneOption>
<Id>1</Id>
<Name>Lighting</Name>
<Icon>1</Icon>
<Enabled>0</Enabled>
<ListIndex>0</ListIndex>
</FusionZoneOption>
<FusionZoneOption>
<Id>2</Id>
<Name>Window Treatments</Name>
<Icon>2</Icon>
<Enabled>0</Enabled>
<ListIndex>0</ListIndex>
</FusionZoneOption>
<FusionZoneOption>
<Id>3</Id>
<Name>Climate</Name>
<Icon>3</Icon>
<Enabled>0</Enabled>
<ListIndex>0</ListIndex>
</FusionZoneOption>
<FusionZoneOption>
<Id>4</Id>
<Name>Display</Name>
<Icon>4</Icon>
<Enabled>0</Enabled>
<ListIndex>0</ListIndex>
</FusionZoneOption>
</ZoneOptionList>
<LightingFixtureList />
<LightingSceneList />
<WindowFixtureList />
<LightingKeypadIDs />
<WindowKeypadIDs />
<Id>5</Id>
<Name>Bathroom</Name>
<IconName>Bathroom(M)</IconName>
<IconID>8</IconID>
<ListIndex>2</ListIndex>
<Group>1</Group>
<AVEnable>0</AVEnable>
<AudioOnly>1</AudioOnly>
<ExcludedSources>All Available</ExcludedSources>
</FusionZone>
My guess is using Globalization and Resources, but I have never used either before and if I could be directed to a relevant guide I'd be grateful.
Sorry if I added a bit too much info.
XmlSerializer
private void OpenFile(string filePath)
{
projProps.fileName = filePath;
try
{
bool proceed = CheckLegacyTypes();
if (!proceed)
{
return;
}
XmlSerializer xmlData = new XmlSerializer(typeof(FusionSystem));
using (StreamReader streamRead = new StreamReader(projProps.fileName))
{
fusionSystem = (FusionSystem) xmlData.Deserialize(streamRead);
}
openFusionSystem();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
.