Пример #1
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public SignalFormatProperties()
 {
     FormatType         = SignalValueFormat.Auto;
     Decimals           = 2;
     Enums              = new List <EnumerationValue>();
     sControlProperties = null;
 }
        public Frm_ParamControlFormatProperties(SignalFormatProperties oFormat, SignalValueFormat SelectedFormat)
        {
            string DefaultText = "";

            InitializeComponent();

            switch (SelectedFormat)
            {
            case SignalValueFormat.Button:

                Lbl_CtrlOnValue.Text  = "Control ON Value (Pressed)";
                Lbl_CtrlOffValue.Text = "Control OFF Value (Released)";

                DefaultText = "Button";

                break;

            case SignalValueFormat.Checkbox:

                Lbl_CtrlOnValue.Text  = "Control ON Value (Checked)";
                Lbl_CtrlOffValue.Text = "Control OFF Value (Unchecked)";

                DefaultText = "Checkbox";

                break;

            default:

                Lbl_CtrlText.Enabled = false;
                Txt_CtrlText.Enabled = false;

                Lbl_CtrlOnValue.Enabled = false;
                Txt_CtrlOnValue.Enabled = false;

                Lbl_CtrlOffValue.Enabled = false;
                Txt_CtrlOffValue.Enabled = false;

                Cmd_OK.Enabled = false;

                break;
            }

            oRefFormat = oFormat;

            FrmClosing = false;

            if (oFormat.sControlProperties.HasValue)
            {
                Txt_CtrlText.Text     = oFormat.sControlProperties.Value.Text;
                Txt_CtrlOnValue.Text  = oFormat.sControlProperties.Value.On_Value.ToString();
                Txt_CtrlOffValue.Text = oFormat.sControlProperties.Value.Off_Value.ToString();
            }
            else
            {
                Txt_CtrlText.Text     = DefaultText;
                Txt_CtrlOnValue.Text  = "1";
                Txt_CtrlOffValue.Text = "0";
            }
        }
Пример #3
0
        /// <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);
        }