示例#1
0
        static void Main(string[] args)
        {
            Blocknote bloknote = new Blocknote();

            bloknote.Add(new Record("Amy", "75585555887"));
            bloknote.Add(new Record("Kurt", "75495620557"));
            bloknote.Add(new Record("Janis", "78159529822"));
            bloknote.Add(new Record("Armin", "098000000"));
            bloknote.Add(new Record("Adam", "87952879218"));
            bloknote.Add(new Record("Semy", "98151158754"));
            bloknote.Add(new Record("Gary", "75495620557"));
            bloknote.Remove(new Record("Armen", "098000000"));
            string filePath = @"E:\Blocknote\block.txt";

            bloknote.WriteInFile(filePath);
            // bloknote.LoadRecordsFromFile(filePath);
            //bloknote.ShowOnConsole();

            //Console.WriteLine(bloknote.Contains(new Record("Semy", "98151158754")));
            //Console.WriteLine("Index OF");
            //Console.WriteLine(bloknote.IndexOf(new Record("Semy", "98151158754")));
            //Console.WriteLine("Remove item");
            //bloknote.Remove(new Record("Armen", "098000000"));
            //bloknote.ShowOnConsole();
            //Console.WriteLine("insert item");
            //bloknote.Insert(3,new Record("InsertItem", "98151158754"));
            //bloknote.ShowOnConsole();
            //bloknote.Remove(new Record("InsertItem", "98151158754"));
            //bloknote.ShowOnConsole();
            //bloknote.ReturnRecordsByCondition(NameStartsWithG).ShowBlock(Console.WriteLine);
            //bloknote.FindRecord(FindByPhone, "098000000").ShowBlock(Console.WriteLine);
            //bloknote.FindRecord(PhonStartsWith, "055").ShowBlock(Console.WriteLine);
            //bloknote.FindRecord(FindByName, "Hakob").ShowBlock(Console.WriteLine);
            Console.ReadKey();
        }
 public static void LoadRecordsFromFile(this Blocknote blocknote, string filePath)
 {
     try
     {
         using (StreamReader sr = File.OpenText(filePath))
         {
             while (!sr.EndOfStream)
             {
                 blocknote.Add(sr.ReadLine().CreateRecord());
             }
         }
     }
     catch (FileNotFoundException e)
     {
         Console.WriteLine(e.Message);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
 public static void WriteInFile(this Blocknote blocknote, string filePath)
 {
     try
     {
         using (StreamWriter sw = File.AppendText(filePath))
         {
             foreach (Record record in blocknote)
             {
                 sw.WriteLine(record.WritingStyle());
             }
         }
     }
     catch (FileNotFoundException e)
     {
         Console.WriteLine(e.Message);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }