private void init_input() { txtID.Text = ""; txtTieude.Text = ""; txtNoidung.Text = ""; txtTieude.Focus(); txtThutu.Text = MyFunction.Get_MaxId().ToString(); }
private void btnLuu_Click(object sender, EventArgs e) { ////foreach (BaiHoc bh in MyFunction.danhsachBaihoc) ////{ //// //bh.Id = int.Parse(bh.tieude.Replace("Bài ", "").Replace("Bai", "").Replace(" ", "").Trim()); //// bh.tieude = bh.tieude.Replace("Bài ", "").Replace("Bai", "").Replace(" ", "").Trim(); ////} ////MyFunction.ToXml_NoiCau(); ////return; 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 = int.Parse(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 = int.Parse(txtTieude.Text.Trim()); bh.baihoc = baihoc; bh.thutu = int.Parse(txtThutu.Text); MyFunction.danhsachBaihoc.Add(bh); } MyFunction.ToXml_NoiCau(); load_listBaihoc(); init_input(); }