예제 #1
0
        /// <summary>
        /// Sets a switch to the specified state
        /// If the switch cannot be set then throws a MethodNotImplementedException.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="state"></param>
        public void SetSwitch(short id, bool state)
        {
            Validate("SetSwitch", id);
            LocalSwitch sw = switches[id];

            sw.SetValue(state ? sw.Maximum : sw.Minimum, "SetSwitch");
        }
예제 #2
0
        /// <summary>
        /// Return the state of switch n
        /// </summary>
        /// <param name="id">The switch number to return</param>
        /// <returns>
        /// True or false
        /// </returns>
        public bool GetSwitch(short id)
        {
            Validate("GetSwitch", id);
            LocalSwitch sw = switches[id];

            // returns true if the value is closer to the maximum than the minimum
            return(sw.Maximum - sw.Value <= sw.Value - sw.Minimum);
        }
        private void dataGridViewSwitches_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
        {
            var row = dataGridViewSwitches.Rows[e.RowIndex];

            if (row.IsNewRow)
            {
                return;
            }
            string reason;

            if (LocalSwitch.IsValid(row.Cells, out reason))
            {
                row.ErrorText = "";
            }
            else
            {
                row.ErrorText = "Switch parameters invalid: " + reason;
                e.Cancel      = true;
            }
        }
        private void cmdOK_Click(object sender, EventArgs e) // OK button event handler
        {
            // Place any validation constraint checks here

            Switch.traceState = chkTrace.Checked;
            Switch.switches.Clear();
            // update the switch list
            foreach (DataGridViewRow row in dataGridViewSwitches.Rows)
            {
                if (row.IsNewRow)
                {
                    continue;
                }
                string reason;
                if (LocalSwitch.IsValid(row.Cells, out reason))
                {
                    Switch.switches.Add(new LocalSwitch(row.Cells));
                }
                else
                {
                    row.ErrorText = "Invalid row contents: " + reason;
                }
            }
        }