コード例 #1
0
        private void DisplaysTabRadioButton_Click(object sender, RoutedEventArgs e)
        {
            if (!(sender is Button))
            {
                return;
            }

            Button           button       = (Button)sender;
            string           operatorName = (string)button.Tag;
            DisplaySelection content      = (DisplaySelection)displayDataGrid.CurrentItem;
            bool             allOperator  = (string.Compare(operatorName, "All") == 0);
            RadioButtonType  newValue     = RadioButtonType.Off;
            RadioButtonType  currentValue = RadioButtonType.Off;
            bool             isOperator   = operatorName.Contains("Operator");
            int operatorIndex             = 0;

            if (string.Compare("All", operatorName) == 0)
            {
                currentValue = content.All;
            }
            else if (isOperator)
            {
                operatorIndex = int.Parse(operatorName.Replace("Operator", "")) - 1;
                currentValue  = content[operatorIndex];
            }
            else
            {
                return;
            }

            if ((currentValue == RadioButtonType.Off) || (currentValue == RadioButtonType.Partial))
            {
                newValue = RadioButtonType.On;
            }
            else
            {
                newValue = RadioButtonType.Off;
            }

            if (allOperator)
            {
                content.All = newValue;

                for (int i = 0; i < displayDataModel.NumOperators; i++)
                {
                    content[i] = newValue;
                }
            }
            else if (isOperator)
            {
                content[operatorIndex] = newValue;
            }

            // Recalculate all rollups
            displayDataModel.RefreshAllCol();
        }
        //-------------------------------------------------------------------------------------------------//
        public bool SetDisplaySelection(DisplaySelection displaySelection)
        {
            const String methodName = "SetDisplaySelection";
            Logfile.WriteCalled(logLevel, STR_ClassName, methodName,
                String.Format(STRLOG_DisplaySelection_arg, Enum.GetName(typeof(DisplaySelection), displaySelection)));

            bool success = false;

            try
            {
                while (true)
                {
                    /*
                     * Get the current display selection
                     */
                    byte[] readData = WriteReadData(new byte[] { CMD_ReadDisplaySelection }, 1, DATALEN_CMD_Read);
                    if (readData == null || readData.Length != DATALEN_CMD_Read || readData[0] != CMD_ReadDisplaySelection)
                    {
                        throw new ApplicationException(STRERR_FailedToSetDisplaySelection);
                    }
                    DisplaySelection currentDisplaySelection = (DisplaySelection)readData[DATALEN_CMD_Read - 1];

                    /*
                     * Check if this is the desired display selection
                     */
                    if (currentDisplaySelection == displaySelection)
                    {
                        break;
                    }

                    /*
                     * Move the display selection down by one
                     */
                    readData = WriteReadData(new byte[] { CMD_PushDisplaySelectSwitch }, 1, DATALEN_CMD_Push);
                    if (readData == null || readData.Length != DATALEN_CMD_Push || readData[0] != CMD_PushDisplaySelectSwitch)
                    {
                        throw new ApplicationException(STRERR_FailedToPushDisplaySelectSwitch);
                    }
                }

                success = true;
            }
            catch (Exception ex)
            {
                this.lastError = ex.Message;
            }

            Logfile.WriteCompleted(logLevel, STR_ClassName, methodName,
                    String.Format(STRLOG_Success_arg, success));

            return success;
        }