Exemplo n.º 1
0
        /// <summary>
        /// Creates a telecontrol command.
        /// </summary>
        private bool CreateCommand(out TeleCommand cmd)
        {
            TeleCommand InitCmd()
            {
                return(new TeleCommand
                {
                    DeviceNum = deviceConfig.DeviceNum,
                    CmdNum = Convert.ToInt32(numCmdNum.Value),
                    CmdCode = txtCmdCode.Text
                });
            }

            if (rbNumVal.Checked)
            {
                if (ScadaUtils.TryParseDouble(txtCmdVal.Text, out double cmdVal))
                {
                    cmd        = InitCmd();
                    cmd.CmdVal = cmdVal;
                    return(true);
                }
                else
                {
                    ScadaUiUtils.ShowError(CommonPhrases.RealRequired);
                }
            }
            else if (rbStrData.Checked)
            {
                cmd         = InitCmd();
                cmd.CmdData = TeleCommand.StringToCmdData(txtCmdData.Text);
                return(true);
            }
            else if (rbHexData.Checked)
            {
                if (ScadaUtils.HexToBytes(txtCmdData.Text, out byte[] cmdData, true))
Exemplo n.º 2
0
        /// <summary>
        /// Validates the form controls.
        /// </summary>
        private bool ValidateControls()
        {
            StringBuilder sbError = new();

            if (string.IsNullOrWhiteSpace(txtName.Text))
            {
                sbError.AppendError(lblName, CommonPhrases.NonemptyRequired);
            }

            if (txtLoLo.Text != "" && !ScadaUtils.TryParseDouble(txtLoLo.Text, out _))
            {
                sbError.AppendError(lblLoLo, CommonPhrases.RealRequired);
            }

            if (txtLow.Text != "" && !ScadaUtils.TryParseDouble(txtLow.Text, out _))
            {
                sbError.AppendError(lblLow, CommonPhrases.RealRequired);
            }

            if (txtHigh.Text != "" && !ScadaUtils.TryParseDouble(txtHigh.Text, out _))
            {
                sbError.AppendError(lblHigh, CommonPhrases.RealRequired);
            }

            if (txtHiHi.Text != "" && !ScadaUtils.TryParseDouble(txtHiHi.Text, out _))
            {
                sbError.AppendError(lblHiHi, CommonPhrases.RealRequired);
            }

            if (txtDeadband.Text != "" && !ScadaUtils.TryParseDouble(txtDeadband.Text, out _))
            {
                sbError.AppendError(lblDeadband, CommonPhrases.RealRequired);
            }

            if (sbError.Length > 0)
            {
                ScadaUiUtils.ShowError(CommonPhrases.CorrectErrors + Environment.NewLine + sbError);
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 3
0
 protected void btnSubmit_Click(object sender, EventArgs e)
 {
     if (cmdEnabled && CheckPassword())
     {
         if (pnlRealValue.Visible)
         {
             // отправка стандартной команды для вещественных значений
             double cmdVal;
             if (ScadaUtils.TryParseDouble(txtCmdVal.Text, out cmdVal))
             {
                 SendStandardCmd(cmdVal);
             }
             else
             {
                 pnlErrMsg.ShowAlert(lblIncorrectCmdVal);
             }
         }
         else if (pnlData.Visible)
         {
             // отправка бинарной команды
             byte[] cmdData;
             if (TryParseCmdData(out cmdData))
             {
                 SendBinaryCmd(cmdData);
             }
             else
             {
                 pnlErrMsg.ShowAlert(lblIncorrectCmdData);
             }
         }
         else
         {
             // отправка команды опроса КП
             int kpNum = (int)ViewState["KPNum"];
             SendRequestCmd(kpNum);
         }
     }
 }