Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Threading;
  7. using static System.Console;
  8. using System.IO;
  9.  
  10.  
  11. namespace Projektopgave
  12. {
  13.     class Program
  14.     {
  15.         static void Main(string[] args)
  16.         {
  17.             CursorVisible = false;
  18.  
  19.             BackgroundColor = ConsoleColor.White;
  20.             ForegroundColor = ConsoleColor.DarkBlue;
  21.  
  22.             Clear();
  23.  
  24.  
  25.             string Bar1 = "Information System";
  26.             var title1 = "";
  27.  
  28.  
  29.  
  30.             while (true)
  31.             {
  32.                 for (int K = 0; K < Bar1.Length; K++)
  33.                 {
  34.                     title1 += Bar1[K];
  35.                     Title = title1;
  36.                     Thread.Sleep(25);
  37.  
  38.                 }
  39.                 title1 = "";
  40.                 break;
  41.             }
  42.  
  43.  
  44.  
  45.             string title = @"
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.                           _____                                 _______                      
  55.                          |  __ \                               |__   __|                    
  56.                          | |  | | _ __  ___   __ _  _ __ ___      | |  ___   __ _  _ __ ___  
  57.                          | |  | || '__|/ _ \ / _` || '_ ` _ \     | | / _ \ / _` || '_ ` _ \
  58.                          | |__| || |  |  __/| (_| || | | | | |    | ||  __/| (_| || | | | | |
  59.                          |_____/ |_|   \___| \__,_||_| |_| |_|    |_| \___| \__,_||_| |_| |_|
  60.                                                                                              
  61.  
  62.                                      
  63.                                                                                          
  64.  
  65.                                                                 ";
  66.  
  67.             WriteLine(title);
  68.             Thread.Sleep(3500);
  69.             Clear();
  70.  
  71.             Main_Projekt();
  72.         }
  73.  
  74.         private static void Main_Projekt()
  75.         {
  76.             CursorVisible = true;
  77.  
  78.             BackgroundColor = ConsoleColor.White;
  79.             ForegroundColor = ConsoleColor.Black;
  80.  
  81.  
  82.             Clear();
  83.  
  84.             ConsoleKeyInfo Tast = new ConsoleKeyInfo();
  85.  
  86.  
  87.             do
  88.             {
  89.                 //Overskift
  90.                 Write("                          <<<  Dream Team's information Systems - Gæste-registrering >>>");
  91.  
  92.                 //Laver Enters
  93.                 WriteLine();
  94.                 WriteLine();
  95.  
  96.                 //Udskriver
  97.                 WriteLine("Telefon nr : ");
  98.                 WriteLine("Navn       : ");
  99.                 WriteLine("Adresse    : ");
  100.                 WriteLine("Postnr     : ");
  101.                 WriteLine("By         : ");
  102.                 WriteLine("E-Mail     : ");
  103.  
  104.                 //Laver linje skift
  105.                 WriteLine();
  106.                 WriteLine();
  107.                 WriteLine();
  108.                 WriteLine();
  109.  
  110.                 //Udskriver
  111.                 WriteLine("[O] Opret  [F] Find  [V] Vis alle  [X] Slet Fil  [Q] Afslut");
  112.  
  113.                 //Laver linje skift
  114.                 WriteLine();
  115.                 WriteLine();
  116.  
  117.                 //
  118.                 Write("Vælg funktion  : ");
  119.  
  120.                 Tast = ReadKey(true);
  121.  
  122.                 switch (Tast.Key)
  123.                 {
  124.                     case ConsoleKey.O: OpretB(); break;
  125.                     case ConsoleKey.F: Find(); break;
  126.                     case ConsoleKey.V: VisAlle(); break;
  127.                     case ConsoleKey.X: Delete(); break;
  128.                     case ConsoleKey.Q: Exit(); break;
  129.  
  130.                 }
  131.  
  132.                 Clear();
  133.  
  134.             } while (Tast.Key != ConsoleKey.Escape);
  135.  
  136.  
  137.         }
  138.  
  139.         private static void OpretB()
  140.         {
  141.             using (StreamWriter file = new StreamWriter(@"C:\Users\Bruger\Desktop\Projekt_C#\Data.txt", true))
  142.             {
  143.  
  144.  
  145.                 file.Dispose();
  146.                 string tlf;
  147.                 SetCursorPosition(13, 2);
  148.                 tlf = ReadLine();
  149.  
  150.                 string[] tlftxt = File.ReadAllLines(@"C:\Users\Bruger\Desktop\Projekt_C#\Data.txt");
  151.  
  152.                 bool findes = false;
  153.  
  154.                 for (int x = 0; x < tlftxt.Length; x++)
  155.                     if (tlf == tlftxt[x])
  156.                     {
  157.                         SetCursorPosition(13, 2);
  158.                         Write("Telefon nummeret eksitere allerede i systemet");
  159.                         findes = true;
  160.                         Thread.Sleep(2000);
  161.  
  162.                         Main_Projekt();
  163.  
  164.  
  165.  
  166.                     }
  167.  
  168.                 if (!findes)
  169.                 {
  170.  
  171.                     SetCursorPosition(25, 2);
  172.                     Write("Kan oprettes");
  173.  
  174.                 }
  175.  
  176.                 string Navn, adresse, postnr, by, email;
  177.  
  178.                 SetCursorPosition(13, 3);
  179.                 Navn = ReadLine();
  180.                 SetCursorPosition(13, 4);
  181.                 adresse = ReadLine();
  182.                 SetCursorPosition(13, 5);
  183.                 postnr = ReadLine();
  184.                 SetCursorPosition(13, 6);
  185.                 by = ReadLine();
  186.                 SetCursorPosition(13, 7);
  187.                 email = ReadLine();
  188.                 string[] info = {tlf, Navn, adresse, postnr, by, email + Environment.NewLine};
  189.  
  190.                 File.AppendAllLines(@"C:\Users\Bruger\Desktop\Projekt_C#\Data.txt", info);
  191.  
  192.                 WriteLine("Oplysninger gemmes . . . . ");
  193.  
  194.                 Clear();
  195.  
  196.                 file.Close();
  197.  
  198.                 Main_Projekt();
  199.  
  200.  
  201.             }
  202.  
  203.  
  204.         }
  205.  
  206.         public static void Find()
  207.         {
  208.             Clear();
  209.  
  210.             if (System.IO.File.Exists(@"C:\Users\Bruger\Desktop\Projekt_C#\Data.txt"))
  211.             {
  212.                 // Array som finder text fra data filen som skal bruges senere i koden
  213.  
  214.                 Clear();
  215.  
  216.                 Write("Søg efter personer med telefon nr: \n\ntlf nr : ");
  217.  
  218.                 string lookup;
  219.  
  220.                 lookup = ReadLine();
  221.  
  222.                 string[] text = File.ReadAllLines(@"C:\Users\Bruger\Desktop\Projekt_C#\Data.txt");
  223.  
  224.                 //laver et array med all teksten i vores fil
  225.                 for (int x = 0; x < text.Length; x++)
  226.                 {
  227.                     if (text[x].Contains(lookup))    //kigger om vores string findes i vores fil
  228.                     {
  229.                         Write("\nFundet!");
  230.                         Write("\n" + text[x] + "\n" + text[x + 1] + "\n" + text[x + 2] + "\n" + text[x + 3] + "\n" + text[x + 4] + "\n" + text[x + 5]);
  231.                     }
  232.  
  233.                 }
  234.  
  235.  
  236.                 Thread.Sleep(1500);
  237.  
  238.                 WriteLine();
  239.  
  240.                 WriteLine("Tryk enter for at gå tilbage");
  241.  
  242.                 ReadLine();
  243.  
  244.                 Clear();
  245.  
  246.                 Main_Projekt();
  247.  
  248.             }
  249.             else Write("Filen er tom");
  250.  
  251.             Thread.Sleep(1500);
  252.  
  253.             Clear();
  254.  
  255.             Main_Projekt();
  256.  
  257.  
  258.  
  259.         }
  260.  
  261.         private static void VisAlle()
  262.         {
  263.             if (System.IO.File.Exists(@"C:\Users\Bruger\Desktop\Projekt_C#\Data.txt"))
  264.             {
  265.                 Clear();
  266.                 WriteLine("Indhold af databasen");
  267.  
  268.                 WriteLine();
  269.                 WriteLine();
  270.  
  271.                 string alle = File.ReadAllText(@"C:\Users\Bruger\Desktop\Projekt_C#\Data.txt");
  272.                 WriteLine(alle);
  273.  
  274.                 Thread.Sleep(1500);
  275.  
  276.                 WriteLine("Tryk enter for at gå tilbage");
  277.  
  278.                 ReadLine();
  279.  
  280.                 Clear();
  281.  
  282.                 Main_Projekt();
  283.  
  284.             }
  285.  
  286.             else
  287.  
  288.                 Clear();
  289.  
  290.             Write("Filen er tom");
  291.  
  292.             Thread.Sleep(2500);
  293.  
  294.             Main_Projekt();
  295.         }
  296.  
  297.         private static void Delete()
  298.         {
  299.             ConsoleKeyInfo Tast = new ConsoleKeyInfo();
  300.  
  301.  
  302.             Clear();
  303.             if (System.IO.File.Exists(@"C:\Users\Bruger\Desktop\Projekt_C#\Data.txt"))
  304.             {
  305.                 WriteLine("Er du sikker du vil slette Data?");
  306.  
  307.                 WriteLine();
  308.  
  309.                 WriteLine("J = Ja N = Nej");
  310.  
  311.                 Write("Valg: ");
  312.  
  313.                 Tast = ReadKey(true);
  314.  
  315.  
  316.                 switch (Tast.Key)
  317.                 {
  318.                     case ConsoleKey.J:
  319.  
  320.                         Clear();
  321.  
  322.                         System.IO.File.Delete(@"C:\Users\Bruger\Desktop\Projekt_C#\Data.txt");
  323.  
  324.                         Write("Filen blev slettet");
  325.  
  326.                         Thread.Sleep(2500);
  327.  
  328.                         Main_Projekt();
  329.  
  330.                         break;
  331.  
  332.                     case ConsoleKey.N:
  333.  
  334.                         Clear();
  335.  
  336.                         Write("Filen blev ikke slettet");
  337.  
  338.                         Thread.Sleep(2500);
  339.  
  340.                         Main_Projekt();
  341.  
  342.                         break;
  343.  
  344.  
  345.                 }
  346.  
  347.  
  348.  
  349.             }
  350.             else WriteLine("Filen findes ikke");
  351.  
  352.             Thread.Sleep(2500);
  353.  
  354.             Main_Projekt();
  355.  
  356.        
  357.  
  358.  
  359.         }
  360.  
  361.         private static void Exit()
  362.         {
  363.  
  364.             Clear();
  365.  
  366.             WriteLine("Programmet bliver lukket ned, Vent Venligst");
  367.             Thread.Sleep(2000);
  368.             Environment.Exit(0);
  369.  
  370.  
  371.         }
  372.     }
  373. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement