Esempio n. 1
0
        /// <summary>
        /// CMDs the create new definition click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void CmdCreateNewDefinitionClick(object sender, EventArgs e)
        {
            var response = Microsoft.VisualBasic.Interaction.InputBox(
               "Name der Parameterdefinition", "Parameterdefinition anlegen");

            if (string.IsNullOrEmpty(response))
            {
                return;
            }

            var newDefinition = new ParameterDefinition() { Id = this.definitionList.Count + 1, Name = response, ParameterList = new List<Parameter>() };
            ParamUtil.AddDefaultParams(newDefinition);

            this.definitionList.Add(newDefinition);
            this.activeDefinition = newDefinition;

            this.LoadDefinitions();
            ViewUtil.LoadDefinitionParamGridAsync(this.gvParameterDefinition, this.activeDefinition);
        }
Esempio n. 2
0
        /// <summary>
        /// CMDs the delete definition click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void CmdDeleteDefinitionClick(object sender, EventArgs e)
        {
            var idx = this.listParamDefinitions.SelectedIndex;
            if (idx > 0)
            {
                this.definitionList.RemoveAt(idx);

                this.activeDefinition = this.definitionList.First();

                this.LoadDefinitions();
                ViewUtil.LoadDefinitionParamGridAsync(this.gvParameterDefinition, this.activeDefinition);
            }

            if (idx == 0)
            {
                MessageBox.Show("Löschen der Standardparametrierung nicht möglich.");
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Inits the data.
        /// </summary>
        private void InitData()
        {
            if (File.Exists(this.ParamDefFileName))
            {
                try
                {
                    this.definitionList = ParamUtil.LoadParameterDefinitionFromFile(this.ParamDefFileName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(
                       string.Format("Fehler beim Laden der Parameterdefinition aus Datei: {0}. Fehler: {1}.", this.ParamDefFileName, ex.Message));
                }
            }

            if (this.definitionList == null || this.definitionList.Count() == 0)
            {
                // Create default list.
                this.definitionList = new List<ParameterDefinition>
               {
                   new ParameterDefinition() { Id = 1, Name = "Standard", ParameterList = new List<Parameter>() } 
               };

                ParamUtil.AddDefaultParams(this.definitionList.First());
                try
                {
                    ParamUtil.SaveParameterDefinitionsToFile(this.ParamDefFileName, this.definitionList);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(
                       string.Format("Fehler beim Speichern der Parameterdefinition in Datei: {0}. \nFehler: {1}.", this.ParamDefFileName, ex.Message));
                }
            }

            this.activeDefinition = this.definitionList.First();
        }
Esempio n. 4
0
        /// <summary>
        /// Lists the param definitions selected index changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="Telerik.WinControls.UI.Data.PositionChangedEventArgs"/> instance containing the event data.</param>
        private void ListParamDefinitionsSelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
        {
            if (this.listParamDefinitions.SelectedItem == null)
            {
                return;
            }

            var defId = this.listParamDefinitions.SelectedItem.Value;
            var selectedDef = this.definitionList.Find(d => d.Id == (int)defId);
            if (selectedDef != null)
            {
                this.activeDefinition = selectedDef;
            }

            ViewUtil.LoadDefinitionParamGridAsync(this.gvParameterDefinition, this.activeDefinition);
        }
        public static void ValidateCellInput(CellValidatingEventArgs e, ParameterDefinition activeDefinition, RadGridView paramDefinitionGrid)
        {
            var col = e.Column as GridViewDataColumn;
            if (!(e.Row is GridViewDataRowInfo) || col == null)
            {
                return;
            }

            var param = e.Row.DataBoundItem as Parameter;
            if (param == null || param.IsReadOnly)
            {
                return;
            }

            if (col.Name != "Sollwert")
            {
                return;
            }

            e.Row.ErrorText = string.Empty;

            try
            {
                var stringValue = e.Value as string;

                if (string.IsNullOrEmpty(stringValue) || stringValue.Trim() == string.Empty)
                {
                    e.Cancel = true;
                    e.Row.ErrorText = "Validierung fehlgeschlagen, kein Wert angegeben!";
                    throw new ApplicationException(e.Row.ErrorText);
                }

                stringValue = stringValue.Trim();

                if (param.Type == ParameterType.Boolean)
                {
                    if (stringValue == "AN" == false && stringValue == "AUS" == false)
                    {
                        e.Cancel = true;
                        e.Row.ErrorText = "Validierung fehlgeschlagen, nur 'AN' oder 'AUS' können angegeben werden!";
                        throw new ApplicationException(e.Row.ErrorText);
                    }
                }

                // find and set param value (override databinding)
                var listParam = activeDefinition.ParameterList.Find(p => p.Id == param.Id);
                if (listParam != null)
                {
                    if (param.Id == ParameterId.ServerId)
                    {
                        var bytes = Utils.ByteArray.FromHexString(stringValue.Replace("-", string.Empty));
                        if (bytes.Length != 10)
                        {
                            e.Cancel = true;
                            e.Row.ErrorText = "Validierung fehlgeschlagen, als ServerId sind exakt 10 Bytes anzugeben.";
                            throw new ApplicationException(e.Row.ErrorText);
                        }

                        listParam.TargetValue = BitConverter.ToString(bytes);
                    }
                    else
                    {
                        listParam.TargetValue = stringValue;
                    }

                    if (e.ActiveEditor != null)
                    {
                        e.ActiveEditor.Value = listParam.TargetValue;
                    }

                    LoadDefinitionParamGridAsync(paramDefinitionGrid, activeDefinition);
                }
            }
            catch (ApplicationException ex)
            {
                e.Cancel = true;
                MessageBox.Show(ex.Message);
            }
        }
 /// <summary>
 /// Loads the definition params.
 /// </summary>
 /// <param name="gridView">The grid view.</param>
 /// <param name="activeDefinition">The active definition.</param>
 public static void LoadDefinitionParamGridAsync(RadGridView gridView, ParameterDefinition activeDefinition)
 {
     gridView.InvokeEx(gv =>
        {
            gv.DataSource = null;
            gv.DataSource = activeDefinition.ParameterList;
            gv.ResetBindings();
            gv.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
        });
 }