/*public static GraduateStudent Generator(int n) * { * GraduateStudent graduate = new GraduateStudent() { Name = "Index № " + n.ToString() + " " }; * if (people.Contains(graduate)) * { * people.Add(graduate as Person); * vs.Add(graduate.ToString()); * pairs.Add(graduate as Person, graduate); * keys.Add(graduate.ToString(), graduate); * } * return graduate; * }*/ public static GraduateStudent Generator(int n) { GraduateStudent graduate = new GraduateStudent(); graduate.Name = n.ToString(); return(graduate); }
public bool Replace(GraduateStudent gsold, GraduateStudent gnew) { if (_studentDictionary.ContainsValue(gsold)) { foreach (var stud in _studentDictionary.ToArray()) { if (stud.Value == gsold) { _studentDictionary[stud.Key] = gnew; gsold.PropertyChanged -= _studentHandler; if (GraduateStudentChanged != null) { GraduateStudentChanged(this, new GraduateStudentsChangedEventArgs <TKey>(NameOfCollection, Revision.Replace, "", gnew.Year)); } gnew.PropertyChanged += _studentHandler; } } return(true); } else { return(false); } }
public void _studentHandler(object sender, PropertyChangedEventArgs e) { GraduateStudent graduate = (GraduateStudent)sender; GraduateStudentChanged?.Invoke(this, new GraduateStudentsChangedEventArgs <TKey>(NameOfCollection, Revision.Property, e.PropertyName, graduate.Year)); // Console.WriteLine("Name Of Collection: {0} \nRevision Info: {1} \nProperty: {2}\n", NameOfCollection, Revision.Property, e.PropertyName); }
public TestCollections(int elements) { for (int i = 0; i < elements; i++) { GraduateStudent graduate = Generator(i); people.Add(graduate.Person); vs.Add(graduate.ToString()); pairs.Add(graduate.Person, graduate); keys.Add(graduate.ToString(), graduate); } }
public void AddGraduateStudents(TKey key, GraduateStudent GrLists) { /*if (GrLists == null) * { GrLists = new GraduateStudent[0]; }*/ /* for (int i = 0; i < GrLists.Length; i++) * {*/ GrLists.PropertyChanged += _studentHandler; _studentDictionary.Add(key, GrLists); //GraduateStudentInserted?.Invoke(this, new GraduateStudentListHandlerEventArgs(NameOfCollection, "Был добавлен новый элемент", i+1)); /*}*/ }
/*public TestCollections(int elements) * { * people = new List<Person>(elements); * vs = new List<string>(elements); * pairs = new Dictionary<Person, GraduateStudent>(elements); * keys = new Dictionary<string, GraduateStudent>(elements); * for (int i = 0; i < elements; i++) * { * GraduateStudent grs1 = Generator(i); * } * }*/ public string Search(int index) { string result = ""; bool cont; GraduateStudent graduate = new GraduateStudent(); graduate.Name = index.ToString(); Person p = (Person)graduate; //graduate.Name += string.Format(" #{0}", index); // graduate = Generator(index); //Person p = (Person)graduate; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); cont = people.Contains(graduate.Person); Console.WriteLine(cont); stopwatch.Stop(); result = result + String.Format("Время поиска в списке List<Person> составило: {0}\n", stopwatch.Elapsed); stopwatch.Restart(); cont = vs.Contains(graduate.ToString()); Console.WriteLine(cont); stopwatch.Stop(); result = result + String.Format("Время поиска в списке List<string> составило: {0}\n", stopwatch.Elapsed); stopwatch.Restart(); cont = pairs.ContainsKey(graduate.Person); Console.WriteLine(cont); stopwatch.Stop(); result = result + String.Format("Время поиска в словаре Dictionary<Person, GraduateStudent> по ключу составило: {0}\n", stopwatch.Elapsed); stopwatch.Restart(); cont = pairs.ContainsValue(graduate); Console.WriteLine(cont); stopwatch.Stop(); result = result + String.Format("Время поиска в словаре Dictionary<Person, GraduateStudent> по значению составило: {0}\n", stopwatch.Elapsed); stopwatch.Restart(); cont = keys.ContainsKey(graduate.ToString()); Console.WriteLine(cont); stopwatch.Stop(); result = result + String.Format("Время поиска в словаре Dictionary<string, GraduateStudent> по ключу составило: {0}\n", stopwatch.Elapsed); stopwatch.Restart(); cont = keys.ContainsValue(graduate); Console.WriteLine(cont); stopwatch.Stop(); result = result + String.Format("Время поиска в словаре Dictionary<string, GraduateStudent> по значению составило: {0}\n", stopwatch.Elapsed); return(result); }
public void InsertAt(int j, GraduateStudent gs) { if (j >= grlist.Count) { gs.AddArticles(); GraduateStundentAdded?.Invoke(this, new GraduateStudentListHandlerEventArgs(NameOfCollection, "Вставлен в конец", j)); } else { grlist.Insert(j - 1, gs); GraduateStudentInserted?.Invoke(this, new GraduateStudentListHandlerEventArgs(NameOfCollection, "Вставлен перед элементом", j)); } }
public void AddDefaults(TKey key) { if (_studentDictionary == null) { _studentDictionary = new Dictionary <TKey, GraduateStudent>(); } GraduateStudent graduateStudent = new GraduateStudent(new Person("Alex", "Papirnyk", new DateTime(1999, 10, 01)), "PZ-17-1", "Student", Tuition.FullTime, 2018); _studentDictionary.Add(key, graduateStudent); graduateStudent.PropertyChanged += _studentHandler; /* int j = _studentDictionary.LastIndexOf(graduateStudent); * var arg = new GraduateStudentListHandlerEventArgs(NameOfCollection, "Был добавлен дефолтный элемент",j); * GraduateStudentInserted?.Invoke(this, arg);*/ }
public bool Remove(GraduateStudent rt) { if (_studentDictionary.ContainsValue(rt)) { TKey tkey = _studentDictionary.FirstOrDefault(grst => grst.Value.Equals(rt)).Key; rt.PropertyChanged -= _studentHandler; _studentDictionary.Remove(tkey); if (GraduateStudentChanged != null) { GraduateStudentChanged(this, new GraduateStudentsChangedEventArgs <TKey>(NameOfCollection, Revision.Remove, "", rt.Year)); } return(true); } else { return(false); } }
static void Main(string[] args) { GraduateStudent gStudent = new GraduateStudent(new Person("Alex", "Papr", new DateTime(1999, 10, 1)), "PZ-17", "Student", Tuition.FullTime, 2017); gStudent.AddArticles(new Article("Проблемы обработки данных", "Солнышко", new DateTime(2012, 10, 1))); GraduateStudent lecturer1 = gStudent.DeepCopy(); Console.WriteLine(gStudent.ToString() + "\n"); Console.WriteLine(lecturer1.ToString() + "\n"); link: Console.WriteLine("Введи имя файла: "); string filename = Console.ReadLine(); if (!File.Exists($"{filename}.dat")) { Console.WriteLine("Файла не существует, файл создан"); File.Create($"{filename}.dat").Close(); goto link; } else { gStudent.Load(filename); Console.WriteLine("\n" + gStudent.ToString() + "\n"); } gStudent.AddFromConsole(); gStudent.Save(filename); Console.WriteLine("\n" + gStudent.ToString() + "\n"); GraduateStudent.Load(filename, gStudent); gStudent.AddFromConsole(); GraduateStudent.Save(filename, gStudent); Console.WriteLine("Окончательный результат #1"); Console.WriteLine("\n" + gStudent.ToString() + "\n"); Console.ReadLine(); }