public EditAdequacyCriterionForm(AdequacyCriterion criterion) { InitializeComponent(); this.FillAdequacyCriterionTypesList(); AdequacyCriterionType type; if (criterion != null) { this.Text = "Редактировать критерий адекватности"; this.criterion = criterion; this.txtCriterionName.Text = criterion.Name; this.txtCriterionVariableIdentifier.Text = criterion.VariableIdentifier; type = criterion.AdequacyType; } else { this.Text = "Новый критерий адекватности"; //taking value of previous criterion if possible if (model.Criteria.Count != 0) { type = model.Criteria[model.Criteria.Count - 1].AdequacyType; } else { //defaulf value type = AdequacyCriterionType.DifferenceInSquare; } } this.cmbAdequacyCriterionType.SelectedItem = AdequacyCriterionTypeManager.GetFriendlyName(type); this.pbAdequacyCriterionFunction.Image = AdequacyCriterionTypeManager.GetImage(type); }
private void btnOK_Click(object sender, EventArgs e) { string critName = this.txtCriterionName.Text.Trim(); string critVariableIdentifier = this.txtCriterionVariableIdentifier.Text.Trim(); AdequacyCriterionType critType = AdequacyCriterionTypeManager.ParseName(this.cmbAdequacyCriterionType.Text); if (string.IsNullOrEmpty(critName)) { MessageBoxHelper.ShowExclamation("Введите имя критерия оптимальности"); return; } if (!string.IsNullOrEmpty(critVariableIdentifier)) { if (!VariableIdentifierChecker.RegExCheck(critVariableIdentifier)) { MessageBoxHelper.ShowExclamation("Идентификатор переменной должен начинаться только с заглавной или строчной буквы \nлатинского алфавита и содержать заглавные и строчные буквы латинского алфавита,\n цифры и символ подчеркивания"); return; } if (criterion == null || criterion.VariableIdentifier != critVariableIdentifier) { if (model.CheckCriterionVariableIdentifier(critVariableIdentifier)) { MessageBoxHelper.ShowExclamation("Параметр с таким идентификатором переменной уже существует в модели"); return; } } } if (criterion == null) { TId criterionId = model.Criteria.GetFreeConsequentId(); criterion = new AdequacyCriterion( criterionId, critName, critVariableIdentifier, critType); model.Criteria.Add(criterion); } else { criterion.Name = critName; criterion.VariableIdentifier = critVariableIdentifier; criterion.AdequacyType = critType; } this.DialogResult = DialogResult.OK; this.Close(); }
/// <summary> /// Reads a collection of <see cref="AdequacyCriterion"/> from XML /// </summary> /// <param name="criteriaCollection">A collection to be read from XML</param> /// <param name="criteriaCollectionElement"><see cref="XElement"/> to read a collection from</param> private static void ReadCriteria(NamedModelEntityCollection <AdequacyCriterion> criteriaCollection, XElement criteriaCollectionElement) { IEnumerable <XElement> criterionElements = criteriaCollectionElement.Descendants(Elements.Criterion); foreach (XElement criterionElement in criterionElements) { TId id = TId.Parse(criterionElement.Attribute(Attributes.Id).Value); string name = criterionElement.Attribute(Attributes.Name).Value; string variableIdentifier = criterionElement.Attribute(Attributes.VariableIdentifier).Value; AdequacyCriterionType criterionType = EnumEx.Parse <AdequacyCriterionType>(criterionElement.Attribute(Attributes.Type).Value); AdequacyCriterion criterion = new AdequacyCriterion(id, name, variableIdentifier, criterionType); ReadPropertyCollection(criterion.Properties, ReadCollectionElement(Elements.Properties, criterionElement, false)); criteriaCollection.Add(criterion); } }