// Thêm vào cuối danh sách public void addTail(SACH x) { Node p = new Node(x, null); if (this.Head == null) { this.Head = this.Tail = p; } else { this.Tail.Next = p; this.Tail = p; } }
public void SearchNode(LinkedList myList, string x) { Node p = myList.Head; while (p != null) { SACH temp = new SACH(); //Biến nhớ kiểu sinh viên để đưa vào list if ((x == p.info.MaSach) || (x == p.info.TenSach) || (x == p.info.LoaiSach) || (x == p.info.DonGia.ToString())) { temp.Nhap(p.info.MaSach, p.info.TenSach, p.info.LoaiSach, p.info.DonGia); found.Add(temp); } p = p.Next; } }
// Tạo Node chứa dữ liệu public Node CreateNode(SACH x) { Node p = new Node(); p.info = new SACH(); p.info.MaSach = x.MaSach; p.info.TenSach = x.TenSach; p.info.LoaiSach = x.LoaiSach; p.info.DonGia = x.DonGia; p.info.NgayMua = x.NgayMua; p.info.TacGia = x.TacGia; p.info.NXB = x.NXB; p.info.ThongKe = x.ThongKe; if (p.info == null) { return(null); } return(p); }
private void Doc_Click(object sender, EventArgs e) { try { myList.clear(myList); //Xóa hết dữ liệu đã tồn tại trong danh sách liên kết StreamReader rd = new StreamReader("LoaiSach.txt", Encoding.UTF8); //Đọc file text if (rd == null) { MessageBox.Show("Đọc file không thành công.", "THÔNG BÁO:"); } string x = rd.ReadLine(); /// doc so cuon sach soloaisach = Convert.ToInt32(x); /// rd.ReadLine(); /// doc text for (int i = 0; i < soloaisach; i++) { string x1 = rd.ReadLine(); dsChuoi.Add(x1); } for (int j = 0; j < soloaisach; j++) { SACH x2 = new SACH(); string[] thongtin = dsChuoi[j].Split('/'); x2.Nhap2(thongtin[1], thongtin[2], thongtin[3]); myList.addHead(x2); } //myList.Sort(); /// loi if (rd != null) { MessageBox.Show("Lấy dữ liệu thành công.", "THÔNG BÁO:"); } rd.Close(); } catch (Exception ee) { MessageBox.Show(ee.Message); } }
private void Them_Click(object sender, EventArgs e) { Them6 them = new Them6(); them.ShowDialog(); Node p = new Node(); SACH Sthem = new SACH(); Sthem = them.temp; p = myList.Head; float kt = 0; if (them.ktThem == 1) { MessageBox.Show("Thông tin thêm vào không hợp lệ hoặc đang trống.", "THÔNG BÁO:"); } else { while (p != null) { /*if (them.temp.MaSach == p.info.MaSach) * { * kt = 1; //Nếu MaSach bị trùng thì thay đổi biến kt để không thêm vào danh sách liên kết. * MessageBox.Show("Đã có trong danh sách"); * }*/ p = p.Next; } if (kt == 0 && them.temp.MaSach != null) { them.temp.TongTien = them.temp.SoLuongMua * them.temp.DonGia; if (them.temp.TongTien > 500000 && them.temp.TongTien < 2000000) { them.temp.GiamGia = 0.2F; } else if (them.temp.TongTien > 200000 && them.temp.TongTien < 500000) { them.temp.GiamGia = 0.1F; } else if ((them.temp.TongTien > 2000000) || (them.temp.SoLuongMua > 100)) { them.temp.GiamGia = 0.3F; } else { them.temp.GiamGia = 0F; } them.temp.ThanhTien = them.temp.TongTien - (them.temp.GiamGia * them.temp.TongTien); myList.addHead(them.temp); MessageBox.Show("Thêm sách thành công.", "THÔNG BÁO:"); string secondLine; using (var reader = new StreamReader("6.txt")) { reader.ReadLine(); // skip secondLine = reader.ReadLine(); } secondLine = string.Format("{0,-4}/{1,-40}/{2,-1}/{3,-7}/{4,-12}/{5,-3}/{6,-8}/{7,-2}/{8,-9}/", them.temp.MaSach, them.temp.TenSach, them.temp.LoaiSach, them.temp.DonGia, them.temp.NgayMua, them.temp.SoLuongMua, them.temp.TongTien, them.temp.GiamGia, them.temp.ThanhTien); string filename = "10.txt"; //File.AppendAllText(filename, Environment.NewLine); File.AppendAllText(filename, secondLine + Environment.NewLine); //File.AppendAllText(filename, Environment.NewLine); } } }
public Node(SACH x, Node next) { this.info = x; this.Next = next; }