private void OpenFile(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); openFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"; toolStrip.Items["txtDosyaYolu"].Text = GlobalClass.FilePath;//FileName; /* if (openFileDialog.ShowDialog(this) == DialogResult.OK) * { * string FileName = openFileDialog.FileName; * GlobalClass.FilePath = FileName; * * toolStrip.Items["txtDosyaYolu"].Text = FileName; * } */RecordList frm = new RecordList(); frm.MdiParent = this; frm.Show(); }
public void button2_Click(object sender, EventArgs e) { if (ÖğrNo_textBox5.Text == "" || newString(Ad_textBox6.Text) == "" || newString(Soyad_textBox4.Text) == "") { MessageBox.Show("Lütfen gecerlı bır kayıt gırınız.."); } else { GlobalMethods objMethods = new GlobalMethods(); List <Ogrenci> OgrenciListesi = new List <Ogrenci>(); OgrenciListesi = objMethods.OgrenciListesi(); if (Kaydet.Text == "Güncelle") { if (!control) { MessageBox.Show("listede olmayan bir kişiyi güncellemeye çalışıyorsunuz ,lütfen listeden güncellemek istediğiniz bir kişi seçiniz.."); textboxClear(ÖğrNo_textBox5, Ad_textBox6, Soyad_textBox4); control = false; } else { Ogrenci _ogrenci = OgrenciListesi.Where(x => (x.Id == Convert.ToInt32(Id1)) && x.silindi == 1).FirstOrDefault(); string dosya_yolu = GlobalClass.FilePath; if (_ogrenci != null && (Convert.ToInt32(ÖğrNo_textBox5.Text) == id || !dosyadan_bulD(ÖğrNo_textBox5.Text))) { _ogrenci.Id = Convert.ToInt32(ÖğrNo_textBox5.Text); _ogrenci.name = Ad_textBox6.Text; _ogrenci.surName = Soyad_textBox4.Text; string yazdirilacakText = ""; for (int i = 0; i < OgrenciListesi.Count; i++) { yazdirilacakText += OgrenciListesi[i].Id.ToString().Trim() + "~" + newString(OgrenciListesi[i].name).Trim().ToTitleCase() + "~" + newString(OgrenciListesi[i].surName).Trim().ToTitleCase() + "~" + OgrenciListesi[i].silindi.ToString().Trim() + "\r"; } File.WriteAllText(dosya_yolu, yazdirilacakText); dosyadanOku(); DialogResult xxx = MessageBox.Show("Kişi Güncellenmiştir.."); textboxClear(ÖğrNo_textBox5, Ad_textBox6, Soyad_textBox4); if (xxx == DialogResult.OK) { //RecordList fromundaki dataGridViev deki kayıtların yenlenmesini sağlıyor.. RecordList f1 = (RecordList)Application.OpenForms["RecordList"]; f1.dosyadanOku(); } Kaydet.Text = "Kaydet"; } else { MessageBox.Show("The same Id can not be used twice.."); ÖğrNo_textBox5.Text = id.ToString(); } //control = false; } } else//kaydet alanı buradan başlıyor.. { string yazdırılacakText = " "; if (dosyadan_bul(ÖğrNo_textBox5.Text) == null) { string kayitSatiri = ÖğrNo_textBox5.Text.Trim() + "~" + newString(Ad_textBox6.Text).Trim().ToTitleCase() + "~" + newString(Soyad_textBox4.Text).Trim().ToTitleCase() + "~" + 1; Boolean flag = false; FileStream fs = File.Create(GlobalClass.TempPath); // bir metin dosyası oluşturur. StreamWriter yaz = new StreamWriter(fs); StreamReader oku = new StreamReader(GlobalClass.FilePath); string _text = oku.ReadLine(); if (_text != null) //alfabetik sıraya göre sıralama yapılıyor.. { while (_text != null) { if (flag == false) { if (string.Compare((kayitSatiri.Split('~')[1] + kayitSatiri.Split('~')[2]), (_text.Split('~')[1] + _text.Split('~')[2])) <= 0) { yaz.WriteLine(kayitSatiri); flag = true; } yaz.WriteLine(_text); } else { yaz.WriteLine(_text); } _text = oku.ReadLine(); } if (flag == false) { yaz.WriteLine(kayitSatiri); } } else { yaz.WriteLine(kayitSatiri); } yaz.Close(); oku.Close(); File.Delete(GlobalClass.FilePath); FileInfo fi = new FileInfo(GlobalClass.TempPath); fi.MoveTo(GlobalClass.FilePath); //dosya isimlerini değiştiriyoruz.. fs.Close(); MessageBox.Show("Record successful"); dosyadanOku(); textboxClear(ÖğrNo_textBox5, Ad_textBox6, Soyad_textBox4); } else { MessageBox.Show("The same Id can not be used twice.."); ÖğrNo_textBox5.Clear(); } } } }