public void Add() { Nhanvien t = new Nhanvien(); DSNhanvien n = new DSNhanvien(); n.Readfile(); n.Show(); do { Console.Write("\n\n\t\tNhập mã nhân viên muốn thêm: "); t.Manv1 = Console.ReadLine(); t.Manv1 = t.Manv1.ToUpper(); if (t.Manv1.Length == 0) { Console.WriteLine("Mời nhập lại: "); } } while (t.Manv1.Length == 0); if (n.KTMa(t.Manv1)) { Console.WriteLine("Mã nhân viên đã tồn tại! Mời nhập lại!"); } else { t.NhapThem(); n.ktADD(t.Manv1, t.Hoten1, t.Gioitinh1, t.NamSinh1, t.Chucvu1, t.Diachi1, t.Sodt1); Console.WriteLine("Add Successfully !!!"); } }
public void Readfile() { string filepath = "NhanVien.txt"; dsnhanvien = new List <Nhanvien>(); try { StreamReader sr = File.OpenText(filepath); string a; while ((a = sr.ReadLine()) != null) { Nhanvien b = new Nhanvien(); string[] c = a.Split('#'); b.Manv1 = c[0]; b.Hoten1 = c[1]; b.Gioitinh1 = c[2]; b.NamSinh1 = c[3]; b.Chucvu1 = c[4]; b.Diachi1 = c[5]; b.Sodt1 = c[6]; dsnhanvien.Add(b); } sr.Close(); } catch (IOException e) { Console.WriteLine(e.Message); } }