Facebook
From Burak Karaalp, 4 Years ago, written in C#.
Embed
Download Paste or View Raw
Hits: 137
  1. //************************************Main Form kodları
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using System.IO;
  12. using System.Collections;
  13.  
  14.  
  15.  
  16. namespace WindowsFormsApp2
  17. {
  18.     public partial class Form1 : Form
  19.     {
  20.        
  21.         public Form1()
  22.         {
  23.             InitializeComponent();
  24.            
  25.         }
  26.  
  27.         private void Form1_Load(object sender, EventArgs e)
  28.         {
  29.            dosyaislem ds = new dosyaislem();
  30.            ds.DosyaOlustur();
  31.             List<string> liste = new List<string>();
  32.             liste = ds.ListeOlusturEkle();
  33.             foreach (string item in liste)
  34.             {
  35.                 listBox1.Items.Add(item);
  36.             }
  37.         }
  38.  
  39.         private void button1_Click(object sender, EventArgs e)
  40.         {
  41.             dosyaislem ds = new dosyaislem();
  42.             ds.KisiYaz(textBox1.Text);
  43.             List<string> liste = new List<string>();
  44.             string sonsatir = ds.ListeUpdate();
  45.             listBox1.Items.Add(sonsatir);
  46.         }
  47.  
  48.         private void label1_Click(object sender, EventArgs e)
  49.         {
  50.  
  51.         }
  52.         //Alan buglu düzeltilecek ########################
  53.          private void button3_Click(object sender, EventArgs e)
  54.          {
  55.              dosyaislem ds = new dosyaislem();          
  56.              ds.ListeTemizle();
  57.             listBox1.Items.Clear();
  58.             listBox2.Items.Clear();
  59.          }
  60.  
  61.         private void button2_Click(object sender, EventArgs e)
  62.         {
  63.             dosyaislem ds = new dosyaislem();
  64.             List<string> liste = new List<string>();
  65.             List<string> updateListe = new List<string>();
  66.             List<string> liste2 = new List<string>();
  67.             int kisiSayi=1;
  68.             int kisiSayi2 = 0;
  69.             liste = ds.KisiCek(numericUpDown1.Value);
  70.             foreach (string item in liste)
  71.             {
  72.                 listBox2.Items.Add("Kişi "+kisiSayi+": "+item);
  73.                 kisiSayi++;
  74.             }
  75.             liste2 = ds.kisiHesaplaCagir();          
  76.             foreach (var item in liste2)
  77.             {
  78.                 kisiSayi2++;
  79.             }
  80.             if (kisiSayi == 1)
  81.             {
  82.                 MessageBox.Show("Çekmek İstediğiniz kişi sayısı 0 değerinde yada listede çekmek istediğiniz kadar kişi yok! Listedeki kişi sayısı: "+kisiSayi2);
  83.             }
  84.         }
  85.     }
  86. }
  87.  
  88.  
  89.  
  90. //************************************dosyaislem.cs kodlar
  91.  
  92. using System;
  93. using System.Collections.Generic;
  94. using System.Linq;
  95. using System.Text;
  96. using System.Threading.Tasks;
  97. using System.IO;
  98. using System.Collections;
  99.  
  100. namespace WindowsFormsApp2
  101. {
  102.     class dosyaislem
  103.     {
  104.       public void DosyaOlustur()
  105.         {
  106.             if(!File.Exists("kisi.txt"))
  107.             {
  108.                 FileStream fs = new FileStream("kisi.txt", FileMode.OpenOrCreate);
  109.                 StreamWriter sw = new StreamWriter(fs);
  110.                 sw.Close();
  111.                 fs.Close();
  112.             }
  113.            
  114.         }
  115.        
  116.         public List<string> ListeOlusturEkle()
  117.         {
  118.             DosyaOlustur();
  119.             StreamReader streamReader = new StreamReader("kisi.txt", Encoding.UTF8);          
  120.             List<string> liste = new List<string>();
  121.             while (!streamReader.EndOfStream)
  122.             {
  123.                 string deger = streamReader.ReadLine();
  124.                 liste.Add(deger);
  125.             }
  126.             streamReader.Close();
  127.             return liste;
  128.  
  129.         }
  130.         public string ListeUpdate()
  131.         {
  132.             DosyaOlustur();
  133.             StreamReader streamReader = new StreamReader("kisi.txt", Encoding.UTF8);
  134.             List<string> liste = new List<string>();
  135.             while (!streamReader.EndOfStream)
  136.             {
  137.                 string deger = streamReader.ReadLine();
  138.                 liste.Add(deger);
  139.             }
  140.             streamReader.Close();
  141.             string sonsatir = "null";
  142.             for (int i = 0; i < liste.Count; i++)
  143.             {
  144.                 if (i == liste.Count-1)
  145.                 {                  
  146.                     sonsatir = liste[i];
  147.                     liste.Clear();
  148.                 }
  149.             }
  150.             return sonsatir;
  151.         }
  152.         public void KisiYaz(string isim)
  153.         {
  154.             List<string> liste = new List<string>();
  155.             liste = ListeOlusturEkle();
  156.            
  157.             StreamWriter streamWriter = new StreamWriter("kisi.txt");
  158.             foreach (string item in liste)
  159.             {
  160.                 streamWriter.WriteLine(item);
  161.             }
  162.             streamWriter.WriteLine(isim);
  163.             streamWriter.Close();
  164.         }
  165.  
  166.  
  167.         //BU ALAN BUGLU DÜZELTİLECEK ##################################################################################################################
  168.         public void ListeTemizle()
  169.         {
  170.             if (File.Exists("kisi.txt"))
  171.             {
  172.                 File.Delete("kisi.txt");
  173.             }          
  174.         }
  175.  
  176.         public List<string> kisiHesaplaCagir()
  177.         {
  178.             StreamReader streamReader = new StreamReader("kisi.txt",Encoding.UTF8);
  179.             List<string> liste = new List<string>();        
  180.             while (!streamReader.EndOfStream)
  181.             {
  182.                 liste.Add(streamReader.ReadLine());            
  183.             }
  184.             streamReader.Close();
  185.             return liste;
  186.         }
  187.         public List<string>  KisiCek(decimal sayi)
  188.         {
  189.             StreamReader streamReader = new StreamReader("kisi.txt",Encoding.UTF8);
  190.             List<string> liste = new List<string>();
  191.             List<string> KisilerListe = new List<string>();
  192.             List<int> sayiLar = new List<int>();
  193.             Random rand = new Random();        
  194.             int satirsayi = 0;
  195.             int durumint=0;
  196.             Boolean anaDurum = false;
  197.             while (!streamReader.EndOfStream)
  198.             {
  199.                 satirsayi++;
  200.                 liste.Add(streamReader.ReadLine());
  201.             }          
  202.             streamReader.Close();
  203.             foreach (var item in liste)
  204.             {
  205.                 durumint++;
  206.             }
  207.             if(durumint < sayi)
  208.             {
  209.                 anaDurum = true;
  210.             }
  211.             if (!anaDurum)
  212.             {
  213.                 for (int i = 0; i < sayi; i++)
  214.                 {
  215.                     int randomSayi;
  216.                     int eklenen = 0;
  217.                     Boolean durum;
  218.                     randomSayi = rand.Next(0, liste.Count);
  219.                     foreach (var item in sayiLar)
  220.                     {
  221.                         if (randomSayi == item)
  222.                         {
  223.                             sayi--;
  224.                             durum = false;
  225.                         }
  226.                     }
  227.                     if (durum = true)
  228.                     {
  229.                         sayiLar.Add(randomSayi);
  230.                         durum = false;
  231.                     }
  232.                 }
  233.                 foreach (var item in sayiLar)
  234.                 {
  235.                     KisilerListe.Add(liste[item]);                  
  236.                 }              
  237.             }
  238.             List<string> sonListe = new List<string>();
  239.             int kisilerListeuzunluk=0;
  240.             sonListe = kisiHesaplaCagir();
  241.             foreach (var item in KisilerListe)
  242.             {
  243.                 kisilerListeuzunluk++;
  244.             }
  245.             for (int i = 0; i < sonListe.Count; i++)
  246.             {
  247.                 for (int z = 0; z < kisilerListeuzunluk; z++)
  248.                 {
  249.                    
  250.                     if (KisilerListe[z] == sonListe[i])
  251.                     {
  252.                         string deger;
  253.                         deger = sonListe[i];
  254.                         sonListe.Remove(deger);
  255.                     }
  256.                 }
  257.             }
  258.             ListeTemizle();
  259.             StreamWriter streamWriter = new StreamWriter("kisi.txt");        
  260.             foreach (string item in sonListe)
  261.             {
  262.                 streamWriter.WriteLine(item);
  263.             }
  264.             streamWriter.Close();
  265.             return KisilerListe;
  266.         }  
  267.     }
  268. }
  269.  
  270.