示例#1
0
        private void buttonOk_Click(object sender, System.EventArgs e)
        {
            bool numericFormatOk = true;

            IEnumerator en = this.panelCenter.Controls.GetEnumerator();

            while (en.MoveNext())
            {
                Control ctrl = (Control)en.Current;
                if (ctrl is RecommProcVarElementControl)
                {
                    RecommProcVarElementControl pveCtrl = ctrl as RecommProcVarElementControl;
                    if (!pveCtrl.IsNewValueValid)
                    {
                        numericFormatOk = false;
                        break;
                    }
                }
            }

            if (numericFormatOk)
            {
                // build the hashtable with procVars and values
                Hashtable hashtable = new Hashtable();
                if (initialProcVar is ProcessVarDouble)
                {
                    double val = UnitSystemService.GetInstance().ConvertToSIValue(this.initialProcVar.Type, (double)initialVarNewValue);
                    hashtable.Add(this.initialProcVar, val);
                }
                else
                {
                    hashtable.Add(this.initialProcVar, (int)initialVarNewValue);
                }

                IEnumerator en2 = this.panelCenter.Controls.GetEnumerator();
                while (en2.MoveNext())
                {
                    Control ctrl = (Control)en2.Current;
                    if (ctrl is RecommProcVarElementControl)
                    {
                        RecommProcVarElementControl pveCtrl = ctrl as RecommProcVarElementControl;
                        hashtable.Add(pveCtrl.Variable, pveCtrl.NewValue);
                    }
                }

                ErrorMessage error = this.initialProcVar.Owner.Specify(hashtable);
                if (error != null)
                {
                    UI.ShowError(error);
                }
                this.Close();
            }
            else
            {
                string message = "Please enter numeric values!";
                MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
示例#2
0
        public ProcVarsInappropriateForm(INumericFormat iNumericFormat, ProcessVar var, object varNewValue, ErrorMessage error)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            this.Text = error.Title;

            this.initialProcVar     = var;
            this.initialVarNewValue = varNewValue;
            this.varsAndValues      = error.ProcessVarsAndValues;

            // display the message
            this.labelMessage.Text = error.Message;

            // dispaly the initial variable
            this.labelProcVarName.InitializeVariable(var);
            this.labelProcVarName.BorderStyle = BorderStyle.None;
            this.textBoxProcVarExistingValue.InitializeVariable(iNumericFormat, var);

            // note: the new value is already converted to the current unit system,
            //       it needs only to be formated
            if (var is ProcessVarDouble)
            {
                double val = (double)varNewValue;
                if (val == Constants.NO_VALUE)
                {
                    this.textBoxProcVarNewValue.Text = "";
                }
                else
                {
                    this.textBoxProcVarNewValue.Text = val.ToString(iNumericFormat.NumericFormatString);
                }
            }
            else if (var is ProcessVarInt)
            {
                int val = (int)varNewValue;
                if (val == Constants.NO_VALUE_INT)
                {
                    this.textBoxProcVarNewValue.Text = "";
                }
                else
                {
                    this.textBoxProcVarNewValue.Text = val.ToString(UI.DECIMAL);
                }
            }
            this.textBoxProcVarExistingValue.BackColor = Color.Gainsboro;
            this.textBoxProcVarNewValue.BackColor      = Color.Gainsboro;

            IEnumerator en = varsAndValues.ProcessVarList.GetEnumerator();

            while (en.MoveNext())
            {
                ProcessVar pv                    = (ProcessVar)en.Current;
                object     recommVal             = varsAndValues.GetRecommendedValue(pv);
                RecommProcVarElementControl ctrl = new RecommProcVarElementControl(iNumericFormat, pv, recommVal);
                ctrl.Dock = DockStyle.Top;
                this.panelCenter.Controls.Add(ctrl);
                ctrl.BringToFront();
            }
        }