예제 #1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            // validation of entered data
            var    errors = new StringBuilder();
            string errMsg;

            if (!AppUtils.ValidateInt(txtCnlNum.Text, 1, ushort.MaxValue, out errMsg))
            {
                errors.AppendLine(AppPhrases.IncorrectInCnlNum).AppendLine(errMsg);
            }
            if (txtName.Text == "")
            {
                errors.AppendLine(AppPhrases.IncorrectInCnlName).AppendLine(CommonPhrases.NonemptyRequired);
            }
            if (cbCnlType.SelectedValue == null)
            {
                errors.AppendLine(AppPhrases.IncorrectCnlType).AppendLine(CommonPhrases.NonemptyRequired);
            }
            if (txtSignal.Text != "" && !AppUtils.ValidateInt(txtSignal.Text, 1, int.MaxValue, out errMsg))
            {
                errors.AppendLine(AppPhrases.IncorrectSignal).AppendLine(errMsg);
            }
            string ctrlCnlNum = txtCtrlCnlNum.Text;

            if (ctrlCnlNum != "")
            {
                if (AppUtils.ValidateInt(ctrlCnlNum, 1, ushort.MaxValue, out errMsg))
                {
                    if (Tables.GetCtrlCnlName(int.Parse(ctrlCnlNum)) == "")
                    {
                        errors.AppendLine(AppPhrases.IncorrectCtrlCnlNum)
                        .AppendLine(string.Format(AppPhrases.CtrlCnlNotExists, ctrlCnlNum));
                    }
                }
                else
                {
                    errors.AppendLine(AppPhrases.IncorrectCtrlCnlNum).AppendLine(errMsg);
                }
            }

            if (txtLimLowCrash.Text != "" && !AppUtils.ValidateDouble(txtLimLowCrash.Text, out errMsg))
            {
                errors.AppendLine(AppPhrases.IncorrectLimLowCrash).AppendLine(errMsg);
            }
            if (txtLimLow.Text != "" && !AppUtils.ValidateDouble(txtLimLow.Text, out errMsg))
            {
                errors.AppendLine(AppPhrases.IncorrectLimLow).AppendLine(errMsg);
            }
            if (txtLimHigh.Text != "" && !AppUtils.ValidateDouble(txtLimHigh.Text, out errMsg))
            {
                errors.AppendLine(AppPhrases.IncorrectLimHigh).AppendLine(errMsg);
            }
            if (txtLimHighCrash.Text != "" && !AppUtils.ValidateDouble(txtLimHighCrash.Text, out errMsg))
            {
                errors.AppendLine(AppPhrases.IncorrectLimHighCrash).AppendLine(errMsg);
            }

            errMsg = errors.ToString().TrimEnd();

            if (errMsg == "")
            {
                // passing input channel properties to an editable table
                try {
                    var dataRow = frmTable.Table.DefaultView[row.Index];
                    dataRow["Active"]       = chkActive.Checked;
                    dataRow["CnlNum"]       = txtCnlNum.Text;
                    dataRow["Name"]         = txtName.Text;
                    dataRow["CnlTypeID"]    = cbCnlType.SelectedValue;
                    dataRow["ModifiedDT"]   = DateTime.Now;
                    dataRow["ObjNum"]       = cbObj.SelectedValue;
                    dataRow["KPNum"]        = cbKP.SelectedValue;
                    dataRow["Signal"]       = txtSignal.Text == "" ? DBNull.Value : (object)txtSignal.Text;
                    dataRow["FormulaUsed"]  = chkFormulaUsed.Checked;
                    dataRow["Formula"]      = txtFormula.Text == "" ? DBNull.Value : (object)txtFormula.Text;
                    dataRow["Averaging"]    = chkAveraging.Checked;
                    dataRow["ParamID"]      = cbParam.SelectedValue;
                    dataRow["FormatID"]     = cbFormat.SelectedValue;
                    dataRow["UnitID"]       = cbUnit.SelectedValue;
                    dataRow["CtrlCnlNum"]   = txtCtrlCnlNum.Text == "" ? DBNull.Value : (object)txtCtrlCnlNum.Text;
                    dataRow["EvEnabled"]    = chkEvEnabled.Checked;
                    dataRow["EvSound"]      = chkEvSound.Checked;
                    dataRow["EvOnChange"]   = chkEvOnChange.Checked;
                    dataRow["EvOnUndef"]    = chkEvOnUndef.Checked;
                    dataRow["LimLowCrash"]  = txtLimLowCrash.Text == "" ? DBNull.Value : (object)txtLimLowCrash.Text;
                    dataRow["LimLow"]       = txtLimLow.Text == "" ? DBNull.Value : (object)txtLimLow.Text;
                    dataRow["LimHigh"]      = txtLimHigh.Text == "" ? DBNull.Value : (object)txtLimHigh.Text;
                    dataRow["LimHighCrash"] = txtLimHighCrash.Text == "" ? DBNull.Value : (object)txtLimHighCrash.Text;
                    DialogResult            = DialogResult.OK;
                } catch (Exception ex) {
                    AppUtils.ProcError(AppPhrases.WriteInCnlPropsError + ":\r\n" + ex.Message);
                    DialogResult = DialogResult.Cancel;
                }
            }
            else
            {
                ScadaUiUtils.ShowError(errMsg);
            }
        }