public List <Khoi> getKhoi() { try { var khoi = khoibus.getKhoi(); var k1 = khoibus.GetTatCaKhoi(); var k = k1.Select(x => x.MaKhoi).ToList(); khoi.Select(x => x.MaKhoi).ToList().ForEach(x => { if (k.Contains(x)) { k.Remove(x); } }); if (k.Count > 0) { k.ForEach(x => { khoi.Add(new Khoi() { MaKhoi = x, TenKhoi = k1.First(i => i.MaKhoi == x).TenKhoi, SoLop = 0, NamHoc = 0 }); }); } return(khoi); } catch (Exception ex) { MessageBox.Show(ex.Message); return(null); } }
public void InitKhoi() { KhoiBUS khoiBUS = new KhoiBUS(); khoi = khoiBUS.GetTatCaKhoi(); var cbk = khoi.Select(x => new { Id = x.MaKhoi, Ten = x.TenKhoi }).ToList(); cbk.Insert(0, new { Id = 0, Ten = "Chọn khối" }); cbKhoi.DataSource = cbk; cbKhoi.ValueMember = "Id"; cbKhoi.DisplayMember = "Ten"; }