public void Save(object param = null) { var control = param as FrameworkElement; if (control != null) { var bindings = CosmeticDataRepositoryVM.FindBindingGroups(control); for (int i = 0; i < bindings.Count; i++) { bindings[i].CommitEdit(); } } foreach (var attr in Attributes) { var layerMV = _attributeVM.Source.MapViewer.getLayer(_table.NameMap); if (layerMV == null) { continue; } var objMV = layerMV.getObject(_attributeVM.TableObject.Id); if (objMV == null) { continue; } objMV.SetAttribute(attr.Field.Name, (string)attr.Value); if (_attributeVM.TableObject != null) { _attributeVM.TableObject.SetAttribute(attr.Field.Name, attr.Value); } } // Создание события на обновление атрибута //var source = (CosmeticDataRepositoryVM)Table.Source; //source.SetEventAttribute(Table, PkAttribute.Value, ...); Reload(); }
public CosmeticAttributesVM(AbsM.ITableBaseM table, int?obj, bool isReadOnly = false, string wkt = null, bool isDebug = false) { _table = table as CosM.CosmeticTableBaseM; if (_table == null) { throw new ArgumentNullException(Rekod.Properties.Resources.CosAttributes_TableIsNull); } else if (_table.PrimaryKeyField == null) { throw new ArgumentNullException(Rekod.Properties.Resources.CosAttributes_TableWithoutPK); } if (obj == null) { throw new ArgumentNullException(Rekod.Properties.Resources.CosAttributes_MvObjectIsNull); } _isDebug = isDebug; _source = _table.Source as CosVM.CosmeticDataRepositoryVM; _tableObject = GetOrCreateTableObject(obj); _attributesListVM = new CosmeticAttributesListVM(this); if (_table.Type == AbsM.ETableType.MapLayer || _table.Type == AbsM.ETableType.View) { string curWKT = string.Empty; if (string.IsNullOrWhiteSpace(wkt)) { var layerMV = Source.MapViewer.getLayer(_table.NameMap); if (layerMV != null) { var objMV = layerMV.getObject(_tableObject.Id); if (objMV != null) { curWKT = objMV.getWKT(); } } } else { curWKT = wkt; } _pgGeometryVM = new PgVM.PgAttributes.PgAttributesGeomVM(_attributesListVM, curWKT, (int?)_attributesListVM.PkAttribute.Value); } _styleVM = GetStyle(); Title = String.Format("{0}: [id: {3}]; {1}: \"{4}\"; {2}: \"{5}\"", Rekod.Properties.Resources.CosAttributes_Object, Rekod.Properties.Resources.CosAttributes_Table, Rekod.Properties.Resources.CosAttributes_Type, _tableObject != null ? _tableObject.Id.ToString() : "null", _table.Text, _table.Source.Type); }
/// <summary> /// Отменить введенные значения /// </summary> public void CancelValidation(object parameter = null) { var control = parameter as FrameworkElement; if (control != null) { var bindings = CosmeticDataRepositoryVM.FindBindingGroups(control); foreach (var binding in bindings) { binding.CancelEdit(); binding.BeginEdit(); } } }
/// <summary> /// Начало валидации /// </summary> public void BeginValidation(object parameter = null) { if (parameter is Rekod.Behaviors.CommandEventParameter) { Rekod.Behaviors.CommandEventParameter commEventPar = parameter as Rekod.Behaviors.CommandEventParameter; var control = commEventPar.CommandParameter as FrameworkElement; if (control != null) { var bindings = CosmeticDataRepositoryVM.FindBindingGroups(control); foreach (var binding in bindings) { binding.BeginEdit(); } } } }
public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo) { BindingGroup bindingGroup = (BindingGroup)value; if (bindingGroup.Items.Count > 0) { CosmeticTableBaseM cosmLayer = (CosmeticTableBaseM)bindingGroup.Items[0]; SourcePostgres.Model.PgStyleLayerM layerStyle = (SourcePostgres.Model.PgStyleLayerM)bindingGroup.Items[1]; CosmeticDataRepositoryVM cosmRepo = cosmLayer.Source as CosmeticDataRepositoryVM; String cosmName = (String)bindingGroup.GetValue(cosmLayer, "Text"); if (String.IsNullOrWhiteSpace(cosmName)) { return(new ValidationResult(false, "Не задано название косметического слоя")); } bool cosmNameExists = (from TableBaseM cosmTable in cosmRepo.Tables where (cosmTable.Text == cosmName && cosmLayer != cosmTable) select cosmTable).Count() > 0; if (cosmNameExists) { return(new ValidationResult(false, "Слой с таким названием уже существует")); } BooleanYesNoConverter boolYesNo = new BooleanYesNoConverter(); bool useBounds = Convert.ToBoolean(boolYesNo.ConvertBack(bindingGroup.GetValue(layerStyle, "UseBounds"), null, null, null)); object minScaleObj = bindingGroup.GetValue(layerStyle, "MinScale"); object maxScaleObj = bindingGroup.GetValue(layerStyle, "MaxScale"); int minScale = -1; int maxScale = -1; try { minScale = Convert.ToInt32(minScaleObj); } catch (Exception ex) { String mes = "Ошибка в значении нижней границы масштаба: \n" + ex.Message; return(new ValidationResult(false, mes)); } try { maxScale = Convert.ToInt32(maxScaleObj); } catch (Exception ex) { String mes = "Ошибка в значении верхней границы масштаба: \n" + ex.Message; return(new ValidationResult(false, mes)); } if (useBounds) { if (minScale < 0) { return(new ValidationResult(false, "Минимальное значение не может быть отрицательным числом")); } if (maxScale < 0) { return(new ValidationResult(false, "Максимальное значение не может быть отрицательным числом")); } if (minScale > maxScale) { return(new ValidationResult(false, "Минимальное значение не может быть больше максимального")); } } return(ValidationResult.ValidResult); } else { return(new ValidationResult(false, "Не выбран объект для отображения")); } }