private void btnThemNhom_Click(object sender, EventArgs e) { if (btnThemNhom.Text == "Thêm") { HideTextNhom(true); txtMaNhom.Focus(); btnThemNhom.Text = "Lưu"; txtMaNhom.Text = ""; txtTenNhom.Text = ""; } else { try { NhomObj nhom = new NhomObj(int.Parse(txtMaNhom.Text), txtTenNhom.Text); if (nhomMon.AddNhom(nhom)) { loadTree(); HideTextNhom(false); btnThemNhom.Text = "Thêm"; } else { MessageBox.Show("Không thêm được!"); txtMaNhom.Focus(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public List <NhomObj> GetNhomMon() { db = new DataClasses_QLMADataContext(); List <NhomObj> lst = new List <NhomObj>(); List <NhomMonAn> templst = db.NhomMonAns.ToList(); if (templst.Count > 0) { foreach (var item in templst) { NhomObj tempnhomObj = new NhomObj(); tempnhomObj.MaNhom = item.maNhom; tempnhomObj.TenNhom = item.tenNhom; lst.Add(tempnhomObj); } } return(lst); }
public bool AddNhom(NhomObj nhomObj) { db = new DataClasses_QLMADataContext(); NhomMonAn nhomMon = db.NhomMonAns.Where(x => x.maNhom == nhomObj.MaNhom).FirstOrDefault(); if (nhomMon != null) { throw new Exception("Nhom da co"); } else { NhomMonAn tempnhomMon = new NhomMonAn(); tempnhomMon.maNhom = nhomObj.MaNhom; tempnhomMon.tenNhom = nhomObj.TenNhom; db.NhomMonAns.InsertOnSubmit(tempnhomMon); db.SubmitChanges(); return(true); } }