private int TongTien(DanhSachHangHoa a) { int max = int.MinValue; foreach (var item in a.dshh) { if (!dsten.Contains(item.TenHang)) { dsten.Add(item.TenHang); } } foreach (var item in dsten) { int Tong = 0; foreach (var i in a.dshh) { if (item.CompareTo(i.TenHang) == 0) { Tong += i.ThanhTien(); } } if (Tong > max) { max = Tong; } } return(max); }
public DanhSachHangHoa TimDSMatHangX(DanhSachHangHoa a, string ten) { DanhSachHangHoa kq = new DanhSachHangHoa(); kq.dshh = a.dshh.FindAll(x => x.TenHang == ten).ToList(); return(kq); }
public DanhSachHangHoa InDSHHSLMuoi(DanhSachHangHoa a) { DanhSachHangHoa kq = new DanhSachHangHoa(); kq.dshh = a.dshh.Where(x => x.SoLuong >= 10).ToList(); return(kq); }
public DanhSachHangHoa TimDSTaiNghe(DanhSachHangHoa a) { DanhSachHangHoa kq = new DanhSachHangHoa(); kq.dshh = a.dshh.Where(x => x.TenHang == "TAI NGHE").ToList(); return(kq); }
public DanhSachHangHoa TimMatHangThanhTienMax(DanhSachHangHoa a) { DanhSachHangHoa kq = new DanhSachHangHoa(); int max = a.dshh.Max(x => x.ThanhTien()); kq.dshh = a.dshh.Where(x => x.ThanhTien() == max).ToList(); return(kq); }
public void XoaHangHoaX(DanhSachHangHoa a, string ten) { DanhSachHangHoa ds = new DanhSachHangHoa(); ds.dshh = a.dshh.FindAll(x => x.MoTa == ten).ToList(); foreach (var item in ds.dshh) { a.Xoa(item); } }
public DanhSachHangHoa TimSoTienMaxMHX(DanhSachHangHoa a, string ten) { DanhSachHangHoa ds = new DanhSachHangHoa(); ds = TimDSMatHangX(a, ten); int max = ds.dshh.Max(x => x.ThanhTien()); DanhSachHangHoa kq = new DanhSachHangHoa(); kq.dshh = a.dshh.Where(x => x.ThanhTien() == max).ToList(); return(kq); }
public void TimMHTongTienMax(DanhSachHangHoa a) { int max = TongTien(a); DanhSachHangHoa kq = new DanhSachHangHoa(); foreach (var item in dsten) { int Tong = 0; foreach (var i in a.dshh) { if (item.CompareTo(i.TenHang) == 0) { Tong += i.ThanhTien(); } } if (Tong == max) { Console.WriteLine("Mat hang co tong so tien nhieu nhat la : " + item + " voi tong so tien la: $" + Tong); } } }
static void Main(string[] args) { DanhSachHangHoa DSHH = new DanhSachHangHoa(); QuanLyHangHoa ql = new QuanLyHangHoa(); while (true) { Console.Clear(); Console.WriteLine("====================== DANH SACH CHUC NANG ======================"); Console.WriteLine("Nhap {0} de Thoat", (int)Menu.Thoat); Console.WriteLine("Nhap {0} de Nhap du lieu tu file", (int)Menu.NhapTuFile); Console.WriteLine("Nhap {0} de Xuat file du lieu", (int)Menu.Xuat); Console.WriteLine("Nhap {0} de In danh sach mat hang co so luong tren 10", (int)Menu.InDSMHSLTren10); Console.WriteLine("Nhap {0} de In danh sach mat hang co ten la TAI NGHE", (int)Menu.XuatDSTaiNghe); Console.WriteLine("Nhap {0} de Tim mat hang co tong so tien cao nhat", (int)Menu.TimMatHangCoTongTienCaoNhat); Console.WriteLine("Nhap {0} de Mat Hang co Thanh Tien cao nhat", (int)Menu.MatHangThanhTienMax); Console.WriteLine("Nhap {0} de Tim gia lon nhat cua mat hang X", (int)Menu.TimMaxMatHangX); Console.WriteLine("Nhap {0} de Sap xep", (int)Menu.SapXep); Console.WriteLine("Nhap {0} de xoa hang hoa co mo ta X", (int)Menu.XoaHangHoaMoTaX); Menu nhap = (Menu)int.Parse(Console.ReadLine()); switch (nhap) { case Menu.Thoat: return; case Menu.NhapTuFile: { Console.Clear(); DSHH.NhapThuFile(); DSHH.Xuat(); } break; case Menu.Xuat: { Console.Clear(); DSHH.Xuat(); } break; case Menu.InDSMHSLTren10: { Console.Clear(); ql.InDSHHSLMuoi(DSHH).Xuat(); } break; case Menu.XuatDSTaiNghe: { Console.Clear(); ql.TimDSTaiNghe(DSHH).Xuat(); } break; case Menu.TimMatHangCoTongTienCaoNhat: { Console.Clear(); ql.TimMHTongTienMax(DSHH); } break; case Menu.MatHangThanhTienMax: { Console.Clear(); ql.TimMatHangThanhTienMax(DSHH).Xuat(); } break; case Menu.TimMaxMatHangX: { Console.Clear(); while (true) { Console.WriteLine("Xin moi nhap ten hang hoa gom (MAY TINH, QUAN AO, GIAY, TAI NGHE)"); string ten = Console.ReadLine(); try { ql.TimDSMatHangX(DSHH, ten).Xuat(); Console.WriteLine("Hang hoa Thanh tien cao nhat mat hang {0} la: ", ten + "\n"); ql.TimSoTienMaxMHX(DSHH, ten).Xuat(); break; } catch { Console.WriteLine("Mat hang vua nhap khong ton tai, xin moi nhap lai!!"); } } } break; case Menu.SapXep: { Console.Clear(); Console.WriteLine("Nhap {0} de Sap xep tang theo thanh tien!", (int)sort.TangTheoTien); Console.WriteLine("Nhap {0} de Sap xep giam theo thanh tien!", (int)sort.GianTheoTien); Console.WriteLine("Nhap {0} de Sap xep tang theo so luong", (int)sort.TangSL); Console.WriteLine("Nhap {0} de sap xep tang theo ten", (int)sort.SapXepTangTen); Console.WriteLine("Nhap {0} de Sap xep tang theo chieu dai ten", (int)sort.SapXepTangTheoChieuDaiTen); sort n = (sort)int.Parse(Console.ReadLine()); switch (n) { case sort.TangTheoTien: { Console.Clear(); ql.SapXep(DSHH).Xuat(); } break; case sort.GianTheoTien: { Console.Clear(); ql.SapXepGiam(DSHH).Xuat(); } break; case sort.TangSL: { Console.Clear(); ql.SapXepTangSL(DSHH).Xuat(); } break; case sort.SapXepTangTen: { Console.Clear(); ql.SapXepTheoTen(DSHH).Xuat(); } break; case sort.SapXepTangTheoChieuDaiTen: { Console.Clear(); ql.SapXepTangChieuDaiTen(DSHH).Xuat(); } break; default: break; } } break; case Menu.XoaHangHoaMoTaX: { Console.Clear(); DSHH.Xuat(); string ten; Console.WriteLine("Xin moi nhap ten hang hoa: "); ten = Console.ReadLine(); ql.XoaHangHoaX(DSHH, ten); DSHH.Xuat(); } break; default: break; } Console.ReadLine(); } Console.ReadLine(); }
public DanhSachHangHoa SapXepTangChieuDaiTen(DanhSachHangHoa a) { a.dshh.Sort((x, y) => x.MoTa.Length.CompareTo(y.MoTa.Length)); return(a); }
public DanhSachHangHoa SapXepTheoTen(DanhSachHangHoa a) { a.dshh.Sort((x, y) => x.MoTa.CompareTo(y.MoTa)); return(a); }
public DanhSachHangHoa SapXepTangSL(DanhSachHangHoa a) { a.dshh.Sort((x, y) => x.SoLuong.CompareTo(y.SoLuong)); return(a); }
public DanhSachHangHoa SapXepGiam(DanhSachHangHoa a) { a.dshh.Sort((x, y) => y.ThanhTien().CompareTo(x.ThanhTien())); return(a); }