/// <summary> /// Returns a clone of the current SignalFormatProperties object /// </summary> /// <returns>Clone of the current SignalFormatProperties object</returns> public SignalFormatProperties Get_Clone() { SignalFormatProperties oClone = new SignalFormatProperties(); oClone.FormatType = this.FormatType; oClone.Decimals = this.Decimals; oClone.Enums = new List <EnumerationValue>(); foreach (EnumerationValue sEnum in this.Enums) { oClone.Enums.Add(sEnum); } if (!(sControlProperties == null)) { SignalControlFormatProperties sCtrlProps = new SignalControlFormatProperties(); sCtrlProps.Text = sControlProperties.Value.Text; sCtrlProps.On_Value = sControlProperties.Value.On_Value; sCtrlProps.Off_Value = sControlProperties.Value.Off_Value; oClone.sControlProperties = sCtrlProps; } return(oClone); }
private void Cmd_OK_Click(object sender, EventArgs e) { SignalControlFormatProperties sCtrlProps = new SignalControlFormatProperties(); int Val = 0; sCtrlProps.Text = Txt_CtrlText.Text; if (!(Txt_CtrlOnValue.Text.Equals(""))) { if (int.TryParse(Txt_CtrlOnValue.Text, out Val)) { sCtrlProps.On_Value = Val; } else { MessageBox.Show("Field 'On value' should be a numerical value !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } else { MessageBox.Show("Field 'On value' is empty !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (!(Txt_CtrlOffValue.Text.Equals(""))) { if (int.TryParse(Txt_CtrlOffValue.Text, out Val)) { sCtrlProps.Off_Value = Val; } else { MessageBox.Show("Field 'Off value' should be a numerical value !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } else { MessageBox.Show("Field 'Off value' is empty !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } oRefFormat.sControlProperties = sCtrlProps; this.Close(); }
/// <summary> /// Read the SignalFormatProperties XML node and set the current object /// </summary> /// <param name="xSignalFormat">XML Node to read</param> /// <returns>Read error flag: True = No Error / False = Error</returns> public bool ReadSignalFormatXmlNode(XmlNode xSignalFormat) { XmlNode xFormatType = xSignalFormat.SelectSingleNode("FormatType"); if (!(xFormatType == null)) { SignalValueFormat eFormatType; if (Enum.TryParse(xFormatType.InnerText, out eFormatType)) { FormatType = eFormatType; } else { return(false); } } else { return(false); } XmlNode xFormatDec = xSignalFormat.SelectSingleNode("FormatDecimals"); if (!(xFormatDec == null)) { int nDec; if (int.TryParse(xFormatDec.InnerText, out nDec)) { Decimals = nDec; } else { return(false); } } else { return(false); } switch (FormatType) { case SignalValueFormat.Enum: { XmlNode xFormatEnums = xSignalFormat.SelectSingleNode("FormatEnums"); if (!(xFormatEnums == null)) { Enums = new List <EnumerationValue>(); foreach (XmlNode xEnum in xFormatEnums.ChildNodes) { EnumerationValue sEnum = new EnumerationValue(); XmlNode xEnumVal = xEnum.SelectSingleNode("EnumValue"); if (!(xEnumVal == null)) { int eVal; if (int.TryParse(xEnumVal.InnerText, out eVal)) { sEnum.Value = eVal; } else { return(false); } } else { return(false); } XmlNode xEnumText = xEnum.SelectSingleNode("EnumText"); if (!(xEnumText == null)) { sEnum.Text = xEnumText.InnerText; } else { return(false); } Enums.Add(sEnum); } } else { return(false); } } break; case SignalValueFormat.Checkbox: case SignalValueFormat.Button: { XmlNode xControlProps = xSignalFormat.SelectSingleNode("ControlProperties"); if (!(xControlProps == null)) { SignalControlFormatProperties sCtrlProps = new SignalControlFormatProperties(); XmlNode xCtrlText = xControlProps.SelectSingleNode("ControlText"); if (!(xCtrlText == null)) { sCtrlProps.Text = xCtrlText.InnerText; } else { return(false); } XmlNode xCtrlOnValue = xControlProps.SelectSingleNode("ControlOnValue"); if (!(xCtrlOnValue == null)) { int Val = 0; if (int.TryParse(xCtrlOnValue.InnerText, out Val)) { sCtrlProps.On_Value = Val; } else { return(false); } } else { return(false); } XmlNode xCtrlOffValue = xControlProps.SelectSingleNode("ControlOffValue"); if (!(xCtrlOffValue == null)) { int Val = 0; if (int.TryParse(xCtrlOffValue.InnerText, out Val)) { sCtrlProps.Off_Value = Val; } else { return(false); } } else { return(false); } sControlProperties = new SignalControlFormatProperties(); sControlProperties = sCtrlProps; } else { return(false); } } break; } return(true); }