using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Metotlar
{
class Program
{
static int seçim;
static string AdıSoyadı, Telefon, AdSoyad, Kayıt="Yok";
static void menü()
{
Console.BackgroundColor
= ConsoleColor.Yellow;
Console.ForegroundColor
= ConsoleColor.Blue;
Console.Clear();
Console.CursorTop
= 5;Console.CursorLeft = 35;
Console.Write("ANA MENÜ");
Console.CursorTop
= 7; Console.CursorLeft = 30;
Console.Write("1-KAYIT EKLEME");
Console.CursorTop
= 8; Console.CursorLeft = 30;
Console.Write("2-KAYIT LİSTELEME");
Console.CursorTop
= 9; Console.CursorLeft = 30;
Console.Write("3-KAYIT ARAMA");
Console.CursorTop
= 10; Console.CursorLeft = 30;
Console.Write("4-KAYIT SİLME");
Console.CursorTop
= 11; Console.CursorLeft = 30;
Console.Write("5-KAYIT DÜZELTME");
Console.CursorTop
= 12; Console.CursorLeft = 30;
Console.Write("6-ÇIKIŞ");
Console.CursorTop
= 14; Console.CursorLeft = 30;
Console.Write("SEÇİMİNİZ [1-6] = ");
seçim = Convert.ToInt16(Console.ReadLine());
}
static void
KayıtEkle()
{
string
DosyaYolu = @"C:\Rehber.TXT";
FileInfo
Dosyaadı = new FileInfo(DosyaYolu);
if
(Dosyaadı.Exists)
{
StreamWriter
DosyaYaz = Dosyaadı.AppendText();
Console.Clear();
Console.Write("Adı Soyadı = ");
AdıSoyadı = Console.ReadLine();
Console.Write("Telefon =
");
Telefon = Console.ReadLine();
DosyaYaz.WriteLine(AdıSoyadı);
DosyaYaz.WriteLine(Telefon);
DosyaYaz.Close();
Console.WriteLine("Bilgiler Dosyaya Kaydedildi");
}
else
{
StreamWriter
DosyaYaz = Dosyaadı.CreateText();
Console.Clear();
Console.Write("Adı Soyadı = ");
AdıSoyadı = Console.ReadLine();
Console.Write("Telefon =
");
Telefon = Console.ReadLine();
DosyaYaz.WriteLine(AdıSoyadı);
DosyaYaz.WriteLine(Telefon);
DosyaYaz.Close();
Console.WriteLine("Bilgiler Dosyaya Kaydedildi");
}
}
static void
KayıtListele()
{
string
DosyaYolu = @"D:\Rehber.TXT";
FileInfo
Dosyaadı = new FileInfo(DosyaYolu);
Console.Clear();
StreamReader
DosyaOku = Dosyaadı.OpenText();
AdıSoyadı = DosyaOku.ReadLine();
Telefon = DosyaOku.ReadLine();
while
(AdıSoyadı != null)
{
Console.Write(AdıSoyadı);
Console.CursorLeft
= 15;
Console.WriteLine(Telefon);
AdıSoyadı =
DosyaOku.ReadLine();
Telefon = DosyaOku.ReadLine();
}
DosyaOku.Close();
}
static void KayıtAra()
{
string
DosyaYolu = @"D:\Rehber.TXT";
FileInfo
Dosyaadı = new FileInfo(DosyaYolu);
Console.Clear();
StreamReader
DosyaOku = Dosyaadı.OpenText();
Console.Write("Aranılan Kişinin Adı Soyadı = ");
AdSoyad = Console.ReadLine();
AdıSoyadı = DosyaOku.ReadLine();
Telefon = DosyaOku.ReadLine();
while
(AdıSoyadı != null)
{
if
(AdSoyad == AdıSoyadı)
{
Console.WriteLine("Aranılan Telefon = " + Telefon);
Kayıt = "Var";
}
AdıSoyadı =
DosyaOku.ReadLine();
Telefon = DosyaOku.ReadLine();
}
DosyaOku.Close();
if
(Kayıt == "Yok") Console.WriteLine("Aranılan
Kayıt Yok");
}
static void KayıtSilme()
{
string
DosyaYolu = @"D:\Rehber.TXT";
string
DosyaYolu2 = @"D:\Yedek.TXT";
FileInfo
Dosyaadı = new FileInfo(DosyaYolu);
FileInfo
Dosyaadı2 = new FileInfo(DosyaYolu2);
StreamReader
DosyaOku = Dosyaadı.OpenText();
StreamWriter
DosyaYaz = Dosyaadı2.CreateText();
Console.Clear();
Console.Write("Silinecek Kişinin Adı Soyadı = ");
AdSoyad = Console.ReadLine();
AdıSoyadı = DosyaOku.ReadLine();
Telefon = DosyaOku.ReadLine();
while
(AdıSoyadı != null)
{
if
(AdıSoyadı == AdSoyad)
{
Kayıt = "Var";
}
else
{
DosyaYaz.WriteLine(AdıSoyadı);
DosyaYaz.WriteLine(Telefon);
}
AdıSoyadı =
DosyaOku.ReadLine();
Telefon = DosyaOku.ReadLine();
}
DosyaOku.Close();
DosyaYaz.Close();
Dosyaadı.Delete();
Dosyaadı2.MoveTo(@"D:\Rehber.TXT");
if
(Kayıt == "Yok") Console.WriteLine("Silinecek
Kayıt Yok");
}
static void
KayıtDüzeltme()
{
string
DosyaYolu = @"D:\Rehber.TXT";
string
DosyaYolu2 = @"D:\Yedek.TXT";
FileInfo
Dosyaadı = new FileInfo(DosyaYolu);
FileInfo
Dosyaadı2 = new FileInfo(DosyaYolu2);
StreamReader
DosyaOku = Dosyaadı.OpenText();
StreamWriter
DosyaYaz = Dosyaadı2.CreateText();
Console.Clear();
Console.Write("Düzeltilecek Kişinin Adı Soyadı = ");
AdSoyad = Console.ReadLine();
AdıSoyadı = DosyaOku.ReadLine();
Telefon = DosyaOku.ReadLine();
while
(AdıSoyadı != null)
{
if
(AdıSoyadı == AdSoyad)
{
Console.Write("Düzeltilecek Kişinin Telefonu = ");
Telefon = Console.ReadLine();
Kayıt = "Var";
}
DosyaYaz.WriteLine(AdıSoyadı);
DosyaYaz.WriteLine(Telefon);
AdıSoyadı =
DosyaOku.ReadLine();
Telefon = DosyaOku.ReadLine();
}
DosyaOku.Close();
DosyaYaz.Close();
Dosyaadı.Delete();
Dosyaadı2.MoveTo(@"D:\Rehber.TXT");
if
(Kayıt == "Yok") Console.WriteLine("Silinecek
Kayıt Yok");
}
static void Main(string[]
args)
{
start:
menü();
if
(seçim == 6) Environment.Exit(0);
if
(seçim == 1) KayıtEkle();
if
(seçim == 2) KayıtListele();
Console.Write("Ana Menüye Dönmek İçin Bir Tuşa Basınız");
Console.ReadKey();
goto
start;
}
}
}