private void gvDauSach_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e) { if (!them) { if (gvDauSach.FocusedRowHandle != gvDauSach.RowCount - 1) { } else { if (MessageBox.Show("Bạn có chắc muốn lưu không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { if (gvDauSach.GetFocusedRowCellValue(colTenDS).ToString() != "" && gvDauSach.GetFocusedRowCellValue(colTheLoai).ToString() != "") { //chuẩn hóa tên string maDS = gvDauSach.GetFocusedRowCellValue(colMaDS).ToString(); string tenDS = ChuanHoa(gvDauSach.GetFocusedRowCellValue(colTenDS).ToString().ToLower()); string tenTL = gvDauSach.GetFocusedRowCellValue(colTheLoai).ToString(); string maTL = TheLoai_BUS.MaTL(tenTL); string tenTG = ChuanHoa(gvDauSach.GetFocusedRowCellValue(colTacGia).ToString().ToLower()); string nxb = ChuanHoa(gvDauSach.GetFocusedRowCellValue(colNXB).ToString().ToLower()); string giaSach = ChuanHoa(gvDauSach.GetFocusedRowCellValue(colGiaSach).ToString().ToLower()); DauSach_BUS.themDS(maDS, tenDS, maTL, tenTG, nxb, giaSach, 0, 0); MessageBox.Show("Thêm thành công"); // this.SinhVienbindingSource.EndEdit(); //chuẩn hóa trực tiếp sinh viên vào gridview mà không load lại danh sách gvDauSach.SetFocusedRowCellValue(colTenDS, tenDS); gvDauSach.SetFocusedRowCellValue(colTacGia, tenTG); gvDauSach.SetFocusedRowCellValue(colNXB, nxb); gvDauSach.SetFocusedRowCellValue(colSL, " 0/ 0"); gvDauSach.SetFocusedRowCellValue(colGiaSach, giaSach); //load_DS(); //chuẩn hóa ở textbox tbTenDS.Text = tenDS; tbTacGia.Text = tenTG; cboTheLoai.Text = tenTL; tbNXB.Text = nxb; tbGiaSach.Text = giaSach; tbSoLuong.Text = " 0/ 0"; // them = true; } else { MessageBox.Show("Nhập tên tên đầu sách"); } } catch { MessageBox.Show("Lưu không thành công!"); } } else { them = true; DSbindingSource.RemoveAt(gvDauSach.RowCount - 1); } } } else if (daChuanhoa) { daChuanhoa = false; } else if (sua) { sua = false; } else { string maDS = gvDauSach.GetFocusedRowCellValue(colMaDS).ToString(); string tenDS = ChuanHoa(gvDauSach.GetFocusedRowCellValue(colTenDS).ToString().ToLower()); string tenTL = gvDauSach.GetFocusedRowCellValue(colTheLoai).ToString(); string maTL = TheLoai_BUS.MaTL(tenTL); string tenTG = ChuanHoa(gvDauSach.GetFocusedRowCellValue(colTacGia).ToString().ToLower()); string nxb = ChuanHoa(gvDauSach.GetFocusedRowCellValue(colNXB).ToString().ToLower()); string giaSach = ChuanHoa(gvDauSach.GetFocusedRowCellValue(colGiaSach).ToString().ToLower()); //khi vừa mới thêm xong if (tbTenDS.Text == tenDS && tbTacGia.Text == tenTG && cboTheLoai.Text == tenTL && tbNXB.Text == nxb && tbGiaSach.Text == giaSach) { } else { if (MessageBox.Show("Bạn có chắc muốn sửa không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { if (tenDS != tbTenDS.Text) { //TheLoai_BUS.suaTL(tbMaTL.Text.Trim(), tenTL); DauSach_BUS.suaDS_ten(maDS, tenDS); gvDauSach.SetFocusedRowCellValue(colTenDS, tenDS); tbTenDS.Text = tenDS; } else { gvDauSach.SetFocusedRowCellValue(colTenDS, tenDS); } if (tenTL != cboTheLoai.Text) { DauSach_BUS.suaDS_tl(maDS, maTL); cboTheLoai.Text = tenTL; } if (tenTG != tbTacGia.Text) { DauSach_BUS.suaDS_tg(maDS, tenTG); gvDauSach.SetFocusedRowCellValue(colTacGia, tenTG); tbTacGia.Text = tenTG; } else { gvDauSach.SetFocusedRowCellValue(colTacGia, tenTG); } if (nxb != tbNXB.Text) { DauSach_BUS.suaDS_nxb(maDS, nxb); gvDauSach.SetFocusedRowCellValue(colNXB, nxb); tbNXB.Text = nxb; } else { gvDauSach.SetFocusedRowCellValue(colNXB, nxb); } if (giaSach != tbGiaSach.Text) { DauSach_BUS.suaDS_giasach(maDS, giaSach); gvDauSach.SetFocusedRowCellValue(colGiaSach, giaSach); tbGiaSach.Text = giaSach; } else { gvDauSach.SetFocusedRowCellValue(colGiaSach, giaSach); } // string maLop = Lop_BUS.maLop(cboLop.Text); // sv = new SinhVien_DTO(tbHoSV.Text, tbTenSV.Text, cboGioiTinh.Text, dtpNgaySinh.Value, tbDiaChi.Text, tbNoiSinh.Text, maLop); // SinhVien_BUS.suaSV(sv); //TheLoai_BUS.suaTL(maTL, tenTL); //gvDauSach.SetFocusedRowCellValue(colTenTL, tenTL); //tbTenTL.Text = tenTL; MessageBox.Show("Sửa thành công!"); } catch { MessageBox.Show("Sửa không thành công!"); } } else { gvDauSach.SetFocusedRowCellValue(colTenDS, tbTenDS.Text); gvDauSach.SetFocusedRowCellValue(colTheLoai, cboTheLoai.Text); gvDauSach.SetFocusedRowCellValue(colTacGia, tbTacGia.Text); gvDauSach.SetFocusedRowCellValue(colNXB, tbNXB.Text); gvDauSach.SetFocusedRowCellValue(colGiaSach, tbGiaSach.Text); //gvDauSach.SetFocusedRowCellValue(colTenDS, tbTenDS.Text); } } } }
private void btnLuu_Click(object sender, EventArgs e) { try { if (!them && gvDauSach.FocusedRowHandle == gvDauSach.RowCount - 1) { if (tbTenDS.Text != "" && cboTheLoai.Text != "") { //chuẩn hóa tên string maDS = tbMaDS.Text; string tenDS = ChuanHoa(tbTenDS.Text.ToLower()); string maTL = TheLoai_BUS.MaTL(cboTheLoai.Text.Trim()); string tenTG = ChuanHoa(tbTacGia.Text.ToLower()); string nxb = ChuanHoa(tbNXB.Text.ToLower()); string giaSach = tbGiaSach.Text; DauSach_BUS.themDS(maDS, tenDS, maTL, tenTG, nxb, giaSach, 0, 0); // TheLoai_BUS.themTL(tbMaTL.Text, tenTL); MessageBox.Show("Thêm thành công"); // this.SinhVienbindingSource.EndEdit(); //thêm trực tiếp sinh viên vào gridview mà không load lại danh sách //gvDauSach.SetFocusedRowCellValue(colTenTL, tenTL); gvDauSach.SetFocusedRowCellValue(colMaDS, maDS); gvDauSach.SetFocusedRowCellValue(colTenDS, tenDS); gvDauSach.SetFocusedRowCellValue(colTheLoai, cboTheLoai.Text); gvDauSach.SetFocusedRowCellValue(colTacGia, tenTG); gvDauSach.SetFocusedRowCellValue(colNXB, nxb); gvDauSach.SetFocusedRowCellValue(colGiaSach, giaSach); gvDauSach.SetFocusedRowCellValue(colSL, " 0/ 0"); //load_DS(); //chuẩn hóa ở textbox //tbTenTL.Text = tenTL; tbTenDS.Text = tenDS; tbTacGia.Text = tenTG; tbNXB.Text = nxb; tbGiaSach.Text = giaSach.ToString(); tbSoLuong.Text = " 0/ 0"; // them = true; } else { MessageBox.Show("Nhập tên đầu sách"); } } else { if (MessageBox.Show("Bạn có chắc muốn sửa không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { string maDS = tbMaDS.Text.Trim(); string tenDS = ChuanHoa(tbTenDS.Text.Trim().ToLower()); string tenTL = cboTheLoai.Text; string maTL = TheLoai_BUS.MaTL(tenTL); string tenTG = ChuanHoa(tbTacGia.Text.ToLower()); string nxb = ChuanHoa(tbNXB.Text.ToLower()); string sl = tbSoLuong.Text; string giaSach = tbGiaSach.Text; if (tenDS != gvDauSach.GetFocusedRowCellValue(colTenDS).ToString().Trim()) { //TheLoai_BUS.suaTL(tbMaTL.Text.Trim(), tenTL); DauSach_BUS.suaDS_ten(maDS, tenDS); gvDauSach.SetFocusedRowCellValue(colTenDS, tenDS); tbTenDS.Text = tenDS; } else { tbTenDS.Text = tenDS; } if (tenTL != gvDauSach.GetFocusedRowCellValue(colTheLoai).ToString()) { DauSach_BUS.suaDS_tl(maDS, maTL); gvDauSach.SetFocusedRowCellValue(colTheLoai, tenTL); } if (tenTG != gvDauSach.GetFocusedRowCellValue(colTacGia).ToString()) { DauSach_BUS.suaDS_tg(maDS, tenTG); gvDauSach.SetFocusedRowCellValue(colTacGia, tenTG); tbTacGia.Text = tenTG; } else { tbTacGia.Text = tenTG; } if (nxb != gvDauSach.GetFocusedRowCellValue(colNXB).ToString()) { DauSach_BUS.suaDS_nxb(maDS, nxb); gvDauSach.SetFocusedRowCellValue(colNXB, nxb); tbNXB.Text = nxb; } else { tbNXB.Text = nxb; } if (sl != gvDauSach.GetFocusedRowCellValue(colSL).ToString()) { gvDauSach.SetFocusedRowCellValue(colSL, sl); tbSoLuong.Text = sl; } if (giaSach != gvDauSach.GetFocusedRowCellValue(colGiaSach).ToString()) { DauSach_BUS.suaDS_giasach(maDS, giaSach); gvDauSach.SetFocusedRowCellValue(colGiaSach, giaSach); tbGiaSach.Text = giaSach; } else { tbGiaSach.Text = giaSach; } MessageBox.Show("Sửa thành công!"); sua = true; } catch { MessageBox.Show("Sửa không thành công"); } } else { tbTenDS.Text = gvDauSach.GetFocusedRowCellValue(colTenDS).ToString(); cboTheLoai.Text = gvDauSach.GetFocusedRowCellValue(colTheLoai).ToString(); tbTacGia.Text = gvDauSach.GetFocusedRowCellValue(colTacGia).ToString(); tbNXB.Text = gvDauSach.GetFocusedRowCellValue(colNXB).ToString(); tbSoLuong.Text = gvDauSach.GetFocusedRowCellValue(colSL).ToString(); tbGiaSach.Text = gvDauSach.GetFocusedRowCellValue(colGiaSach).ToString(); } } } catch { MessageBox.Show("Lưu thất bại"); } }