コード例 #1
0
 private void btnXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     if (MessageBox.Show("Bạn có chắc muốn xóa không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         TheLoai_BUS.xoaTL(gvTheLoai.GetFocusedRowCellValue(colMaTL).ToString());
         TLbindingSource.RemoveAt(gvTheLoai.FocusedRowHandle);
         MessageBox.Show("Xóa thành công!");
     }
 }
コード例 #2
0
 private void btnHuy_Click(object sender, EventArgs e)
 {
     //hủy khi không muốn thêm thể loại
     // MessageBox.Show(gvSinhVien.FocusedRowHandle+" "+gvSinhVien.RowCount);
     if (!them && gvTheLoai.FocusedRowHandle == gvTheLoai.RowCount - 1)
     {
         them = true;
         TLbindingSource.RemoveAt(gvTheLoai.RowCount - 1);
     }
     //hủy khi sửa
     else
     {
         tbTenTL.Text = gvTheLoai.GetFocusedRowCellValue(colTenTL).ToString();
     }
 }
コード例 #3
0
 private void btnThem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     if (them)
     {
         tbTenTL.Clear();
         //mã thể loại tự tăng
         string maTL = nextMa(TheLoai_BUS.LastMaTL());
         them = false;
         TLbindingSource.AddNew();
         //GÁN vào textbox và gridview
         gvTheLoai.SetFocusedRowCellValue(colMaTL, maTL);
         tbMaTL.Text = maTL;
         //trỏ tới dòng cuối cùng trong gridview
         gvTheLoai.FocusedRowHandle = gvTheLoai.RowCount - 1;
         tbTenTL.Focus();
     }
     else
     {
         gvTheLoai.FocusedRowHandle = gvTheLoai.RowCount - 1;
         tbTenTL.Focus();
     }
 }
コード例 #4
0
 //khi sửa ở 1 dòng trên gridview và trỏ sang dòng khác thì có sự kiện
 private void gvTheLoai_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
 {
     if (!them)
     {
         if (gvTheLoai.FocusedRowHandle != gvTheLoai.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 (gvTheLoai.GetFocusedRowCellValue(colTenTL).ToString() != "")
                     {
                         //chuẩn hóa tên
                         string tenTL = ChuanHoa(gvTheLoai.GetFocusedRowCellValue(colTenTL).ToString().ToLower());
                         string maTL  = gvTheLoai.GetFocusedRowCellValue(colMaTL).ToString().Trim();
                         TheLoai_BUS.themTL(maTL, tenTL);
                         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
                         gvTheLoai.SetFocusedRowCellValue(colTenTL, tenTL);
                         //load_DS();
                         //chuẩn hóa ở textbox
                         tbTenTL.Text = tenTL;
                         //
                         them = true;
                     }
                     else
                     {
                         MessageBox.Show("Nhập tên thể loại");
                     }
                 }
                 catch
                 {
                     MessageBox.Show("Lưu không thành công!");
                 }
             }
             else
             {
                 them = true;
                 TLbindingSource.RemoveAt(gvTheLoai.RowCount - 1);
             }
         }
     }
     else if (daChuanhoa)
     {
         daChuanhoa = false;
     }
     else if (sua)
     {
         sua = false;
     }
     else
     {
         string tenTL = ChuanHoa(gvTheLoai.GetFocusedRowCellValue(colTenTL).ToString().ToLower());
         string maTL  = gvTheLoai.GetFocusedRowCellValue(colMaTL).ToString();
         //khi vừa mới thêm xong
         if (tbTenTL.Text == tenTL)
         {
         }
         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 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);
                     gvTheLoai.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
             {
                 gvTheLoai.SetFocusedRowCellValue(colTenTL, tbTenTL.Text);
             }
         }
     }
 }