private void btnLuu_Click(object sender, EventArgs e) { if (txtTieude.Text.Trim() == "" || txtNoidung.Text.Trim() == "") { MessageBox.Show("Chưa nhập đủ thông tin"); return; } List <string> txt = txtNoidung.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None).ToList(); int dong = 0; List <Noidung> baihoc = new List <Noidung>(); foreach (string str in txt) { if (str.Trim().Length > 0) { Noidung nd = new Noidung(); dong++; nd.dong = dong; nd.noidung = str.Trim(); baihoc.Add(nd); } } if (txtID.Text != "") { int idx = MyFunction.danhsachBaihoc.FindIndex(x => x.Id == int.Parse(txtID.Text)); MyFunction.danhsachBaihoc[idx].tieude = txtTieude.Text.Trim(); MyFunction.danhsachBaihoc[idx].baihoc = baihoc; MyFunction.danhsachBaihoc[idx].thutu = int.Parse(txtThutu.Text); } else { BaiHoc bh = new BaiHoc(); bh.Id = MyFunction.Get_MaxId() + 1; bh.tieude = txtTieude.Text.Trim(); bh.baihoc = baihoc; bh.thutu = int.Parse(txtThutu.Text); MyFunction.danhsachBaihoc.Add(bh); } MyFunction.ToXml(); load_listBaihoc(); init_input(); }
private void btnXoa_Click(object sender, EventArgs e) { if (txtID.Text != "") { BaiHoc bh = MyFunction.danhsachBaihoc.FirstOrDefault(x => x.Id == int.Parse(txtID.Text)); if (bh != null) { try { MyFunction.danhsachBaihoc.Remove(bh); MyFunction.ToXml(); load_listBaihoc(); } catch (Exception ex) { MessageBox.Show("Khong Xoa Duoc"); return; } } } init_input(); }