/// <summary>
        ///
        /// </summary>
        private void SegmentValue_Add(object sender, RoutedEventArgs e)
        {
            string valueText = _segmentValueTextbox.Text.Trim();

            if (valueText.Length < 1)
            {
                return;
            }

            if (_segmentValuesTable.Select(String.Format("{0} = '{1}'",
                                                         _segmentValuesTable.ValueColumn.ColumnName,
                                                         valueText.Replace("'", "''"))).Length > 0)
            {
                MessageBoxError("This value is already defined.", null);
                return;
            }

            ObservableCollection <DataRow> source = _segmentValuesListTable.ListView.ItemsSource as ObservableCollection <DataRow>;

            Oltp.SegmentValueRow segmentValueRow = _segmentValuesTable.NewSegmentValueRow();
            segmentValueRow.AccountID = Window.CurrentAccount.ID;
            segmentValueRow.SegmentID = (Segment_dialog.TargetContent as Oltp.SegmentRow).SegmentID;
            segmentValueRow.Value     = valueText;
            _segmentValuesTable.Rows.Add(segmentValueRow);

            source.Add(segmentValueRow);
            _segmentValuesListTable.ListView.SelectedItem = segmentValueRow;
            _segmentValuesListTable.ListView.ScrollIntoView(segmentValueRow);

            // Deselect whatever
            _segmentValueTextbox.Text = String.Empty;
            _segmentValueTextbox.Focus();
        }
Exemple #2
0
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            ValidationResult result = base.Validate(value, cultureInfo);

            if (!result.IsValid)
            {
                return(result);
            }

            var valueText = (string)value;

            if (valueText.Trim().Length != valueText.Length)
            {
                return(new ValidationResult(false, "Value cannot start or end with whitespace."));
            }

            var page = MainWindow.Current.CurrentPage as SegmentsPage;

            if (page == null)
            {
                return(new ValidationResult(true, null));
            }

            Oltp.SegmentValueDataTable values = page._segmentValuesTable;

            DataRow[] rows = values.Select(String.Format("{0} = '{1}'",
                                                         values.ValueColumn.ColumnName,
                                                         valueText.Trim().Replace("'", "''")));

            bool self = rows.Length == 1 && rows[0] == this.Row;

            if (!self && rows.Length > 0)
            {
                result = new ValidationResult(false, "This value is already defined.");
            }

            return(result);
        }