예제 #1
0
 private void gvDSLop_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
 {
     if (!them)
     {
         if (gvDSLop.FocusedRowHandle != gvDSLop.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 (gvDSLop.GetFocusedRowCellValue(colTenLop).ToString() != "" &&
                         gvDSLop.GetFocusedRowCellValue(colTenKhoa).ToString() != "")
                     {
                         //chuẩn hóa tên
                         string maLop   = gvDSLop.GetFocusedRowCellValue(colMaLop).ToString();
                         string tenLop  = ChuanHoa(gvDSLop.GetFocusedRowCellValue(colTenLop).ToString().ToLower());
                         string tenKhoa = gvDSLop.GetFocusedRowCellValue(colTenKhoa).ToString();
                         Lop_BUS.themLop(maLop, tenLop, tenKhoa);
                         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
                         //  gvDSLop.SetFocusedRowCellValue(colHoSV, hoSV);
                         // gvDSLop.SetFocusedRowCellValue(colTenSV, tenSV);
                         ///  gvDSLop.SetFocusedRowCellValue(colDiaChi, diaChi);
                         //  gvDSLop.SetFocusedRowCellValue(colNoiSinh, noiSinh);
                         //load_DS();
                         //chuẩn hóa ở textbox
                         tbTenLop.Text   = tenLop;
                         cboTenKhoa.Text = tenKhoa;
                         //
                         them = true;
                     }
                     else
                     {
                         MessageBox.Show("Nhập đầy đủ thông tin cho Lớp");
                     }
                 }
                 catch
                 {
                     MessageBox.Show("Thêm không thành công!");
                 }
             }
             else
             {
                 them = true;
                 DSLopbindingSource.RemoveAt(gvDSLop.RowCount - 1);
             }
         }
     }
     else if (sua)
     {
         sua = false;
     }
     else
     {
         if (tbTenLop.Text.Trim() == gvDSLop.GetFocusedRowCellValue(colTenLop).ToString().Trim() &&
             cboTenKhoa.Text.Trim() == gvDSLop.GetFocusedRowCellValue(colTenKhoa).ToString().Trim())
         {
         }
         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 tenLop  = ChuanHoa(gvDSLop.GetFocusedRowCellValue(colTenLop).ToString().ToLower());
                     string tenKhoa = gvDSLop.GetFocusedRowCellValue(colTenKhoa).ToString();
                     if (tbTenLop.Text.Trim() != tenLop || cboTenKhoa.Text != tenKhoa)
                     {
                         Lop_BUS.suaLop(tbMaLop.Text, tenLop, cboTenKhoa.Text);
                         gvDSLop.SetFocusedRowCellValue(colTenLop, tenLop);
                         tbTenLop.Text   = tenLop;
                         cboTenKhoa.Text = tenKhoa;
                         MessageBox.Show("Sửa thành công!");
                     }
                     else
                     {
                         gvDSLop.SetFocusedRowCellValue(colTenLop, tenLop);
                     }
                 }
                 catch
                 {
                     MessageBox.Show("Sửa không thành công!");
                 }
             }
             else
             {
                 gvDSLop.SetFocusedRowCellValue(colTenLop, tbTenLop.Text);
                 gvDSLop.SetFocusedRowCellValue(colTenKhoa, cboTenKhoa.Text);
             }
         }
     }
 }
예제 #2
0
 private void btnLuu_Click(object sender, EventArgs e)
 {
     try
     {
         if (!them && gvDSLop.FocusedRowHandle == gvDSLop.RowCount - 1)
         {
             if (cboTenKhoa.Text != "" && tbTenLop.Text != "")
             {
                 string tenLop = ChuanHoa(tbTenLop.Text.ToLower());
                 Lop_BUS.themLop(tbMaLop.Text, tenLop, cboTenKhoa.Text);
                 //thêm trực tiếp lớp vào gridview mà không load lại danh sách
                 gvDSLop.SetFocusedRowCellValue(colMaLop, tbMaLop.Text);
                 gvDSLop.SetFocusedRowCellValue(colTenLop, tenLop);
                 gvDSLop.SetFocusedRowCellValue(colTenKhoa, cboTenKhoa.Text);
                 MessageBox.Show("Thêm thành công");
                 them = true;
             }
             else
             {
                 MessageBox.Show("Nhập đầy đủ thông tin cho Lớp");
             }
         }
         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 tenLop = ChuanHoa(tbTenLop.Text.Trim().ToLower());
                     if (tenLop != gvDSLop.GetFocusedRowCellValue(colTenLop).ToString() ||
                         cboTenKhoa.Text != gvDSLop.GetFocusedRowCellValue(colTenKhoa).ToString())
                     {
                         Lop_BUS.suaLop(tbMaLop.Text, tenLop, cboTenKhoa.Text);
                         gvDSLop.SetFocusedRowCellValue(colTenLop, tenLop);
                         gvDSLop.SetFocusedRowCellValue(colTenKhoa, cboTenKhoa.Text);
                         tbTenLop.Text = tenLop;
                         MessageBox.Show("Sửa thành công!");
                     }
                     else
                     {
                         tbTenLop.Text   = gvDSLop.GetFocusedRowCellValue(colTenLop).ToString();
                         cboTenKhoa.Text = gvDSLop.GetFocusedRowCellValue(colTenKhoa).ToString();
                     }
                     sua = true;
                 }
                 catch
                 {
                     MessageBox.Show("Sửa không thành công!");
                 }
             }
             else
             {
                 tbTenLop.Text   = gvDSLop.GetFocusedRowCellValue(colTenLop).ToString();
                 cboTenKhoa.Text = gvDSLop.GetFocusedRowCellValue(colTenKhoa).ToString();
             }
         }
     }
     catch
     {
         MessageBox.Show("Lưu thất bại");
     }
 }