private void SetUnsaved(object sender, NotifyCollectionChangedEventArgs e) { if (e != null && e.IsAddOrRemove() && ReferenceEquals(sender, AllData)) { if (e.NewItems != null) { foreach (object item in e.NewItems) { BaseDataClass obj = (BaseDataClass)item; int errs = obj.GetErrorCount(ErrorType.Error); NumErrors += errs; if (errs > 0) { NotifyErrorStateChanged(new ErrorStateChangedEventArgs(obj)); } errs = obj.GetErrorCount(ErrorType.Warning); NumWarnings += errs; if (errs > 0) { NotifyErrorStateChanged(new ErrorStateChangedEventArgs(obj)); } obj.ErrorStateChanged += ObjectErrorStateChanged; } } if (e.OldItems != null) { foreach (object item in e.OldItems) { BaseDataClass obj = (BaseDataClass)item; int errs = obj.GetErrorCount(ErrorType.Error); NumErrors -= errs; if (errs > 0) { NotifyErrorStateChanged(new ErrorStateChangedEventArgs(obj)); } errs = obj.GetErrorCount(ErrorType.Warning); NumWarnings -= errs; if (errs > 0) { NotifyErrorStateChanged(new ErrorStateChangedEventArgs(obj)); } obj.ErrorStateChanged -= ObjectErrorStateChanged; } } } if (!Unsaved) { Unsaved = true; SaveStateChanged?.Invoke(); Timer?.Start(); FileHelpers.SetWindowHeaders(); } }
public static void GenerateAllDataTypes(int number) { foreach (Type type in DataHelpers.UserTypes) { for (int i = 0; i < number; i++) { BaseDataClass obj = (BaseDataClass)Activator.CreateInstance(type); obj.Name = $"{type.Name}-{i}"; obj.Shorthand = $"{type.Name.Substring(0, 2).ToUpperInvariant()}{i}"; obj.Commit(); } } }
public ErrorWindow() { InitializeComponent(); headerStyle = (Style)Resources["HeaderStyle"]; tbStyle = (Style)Resources["tbStyle"]; foreach (Type type in DataHelpers.UserTypes) { TextBlock header = new TextBlock() { Style = headerStyle, Text = type.Name.Pluralize() }; header.SetResourceReference(TextBlock.BackgroundProperty, "PrimaryBrush"); Headers.Add(header); spMain.Children.Add(header); Filtering <BaseDataClass> list = ((INotifyCollectionChanged)App.Data.FromType(type)).Casting <BaseDataClass>().Filtering( o => o.Visible && o.ErrorValidations.Any(e => e.IsErroredState) ); Console.WriteLine(list.Count); for (int i = 0; i < list.Count; i++) { BaseDataClass item = list[i]; if (!item.Visible) { continue; } TextBlock tbItem = new TextBlock() { Text = item.ToString(), Style = tbStyle }; Console.WriteLine(item); Border border = new Border() { Child = tbItem, BorderBrush = GenericResources.BLACK }; if (i != 0) { border.BorderThickness = new Thickness(0, 1, 0, 0); } spMain.Children.Add(border); } } }
public static Predicate <object> GenerateDefaultNameFilter(string nameFilter, string shorthand) { return(new Predicate <object>(o => { BaseDataClass obj = (BaseDataClass)o; string name = obj.Name.RemoveWhitespace().ToUpperInvariant(); string sh = obj.Shorthand.RemoveWhitespace().ToUpperInvariant(); bool contains = name.Contains(nameFilter); if (nameFilter.Length < name.Length) { name = name.Substring(0, nameFilter.Length); } if (shorthand.Length < sh.Length) { sh = sh.Substring(0, shorthand.Length); } if (nameFilter.Length == 0 && shorthand.Length == 0) { return true; } if (contains && name.Length != 0) { return true; } bool nameCheck = name.Length != 0 && GenericHelpers.DamerauLevenshteinDistance(name, nameFilter, (nameFilter.Length + 1) / 2) != int.MaxValue; if (nameCheck) { return true; } bool shCheck = sh.Length != 0 && GenericHelpers.DamerauLevenshteinDistance(sh, shorthand, (sh.Length - 1) / 2) != int.MaxValue; if (shCheck) { return true; } return false; ; })); }
public void AddFromBDC(BaseDataClass dataClass) { if (dataClass is Teacher teacher) { Teachers.Add(teacher); } if (dataClass is Form form) { Forms.Add(form); } if (dataClass is Subject subject) { Subjects.Add(subject); } if (dataClass is Lesson lesson) { Lessons.Add(lesson); } if (dataClass is Group group) { Groups.Add(group); } }
private void Populate(BaseDataClass item) { StackPanel GenerateTextPanel(string label, FrameworkElement data) { StackPanel sp = new StackPanel() { Orientation = Orientation.Horizontal }; sp.Children.Add(new TextBlock() { Text = label, FontWeight = FontWeights.Bold, Margin = new Thickness(0, 0, 3, 0) }); data.Margin = new Thickness(0, 0, 10, 0); sp.Children.Add(data); return(sp); } StackPanel GenerateListPanel(string label, IList data) { StackPanel sp = new StackPanel() { Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Center }; sp.Children.Add(new TextBlock() { Text = label, FontWeight = FontWeights.Bold, Margin = new Thickness(0, 0, 3, 0) }); sp.Children.Add( new ScrollViewer() { HorizontalScrollBarVisibility = ScrollBarVisibility.Auto, VerticalScrollBarVisibility = ScrollBarVisibility.Auto, Content = new ItemsControl() { ItemsPanel = new ItemsPanelTemplate(new FrameworkElementFactory(typeof(WrapPanel))), ItemsSource = data, BorderThickness = new Thickness(0) } }); return(sp); } wpTop.Children.Add(GenerateTextPanel("Name:", new TextBlock() { Text = item.Name })); foreach (CustomPropertyInfo prop in BaseDataClass.ExposedProperties[item.GetType()]) { if (prop.Type.IsInterface <IList>()) { if (prop.Type != typeof(ObservableCollectionExtended <TimetableSlot>)) { IList data = (IList)prop.PropertyInfo.GetValue(item); StackPanel sp; if (data.Count == 0) { sp = GenerateTextPanel(prop.Alias + ":", new TextBlock() { Text = "None" }); } else { sp = GenerateListPanel(prop.Alias + ":", data); } sp.HorizontalAlignment = HorizontalAlignment.Center; gdBottom.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); Grid.SetColumn(sp, gdBottom.ColumnDefinitions.Count - 1); gdBottom.Children.Add(sp); } } else { wpTop.Children.Add(GenerateTextPanel(prop.Alias + ":", new TextBlock() { Text = prop.Display(prop.PropertyInfo.GetValue(item)) })); } } }
public InformationWindow(BaseDataClass item) { InitializeComponent(); Populate(item); Title = $"Information for {item.GetType().Name} '{item.Name}'"; }