Esempio n. 1
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            try
            {
                if (!them && gvTheLoai.FocusedRowHandle == gvTheLoai.RowCount - 1)
                {
                    if (tbTenTL.Text != "")
                    {
                        //chuẩn hóa tên
                        string tenTL = ChuanHoa(tbTenTL.Text.ToLower());
                        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
                        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");
                    }
                }
                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 (ChuanHoa(tbTenTL.Text.Trim().ToLower()) != gvTheLoai.GetFocusedRowCellValue(colTenTL).ToString().Trim())
                            {
                                string tenTL = ChuanHoa(tbTenTL.Text.ToLower());
                                TheLoai_BUS.suaTL(tbMaTL.Text.Trim(), tenTL);
                                gvTheLoai.SetFocusedRowCellValue(colTenTL, tenTL);
                                tbTenTL.Text = tenTL;
                            }

                            MessageBox.Show("Sửa thành công!");
                            sua = true;
                        }
                        catch
                        {
                            MessageBox.Show("Sửa không thành công");
                        }
                    }
                    else
                    {
                        tbTenTL.Text = gvTheLoai.GetFocusedRowCellValue(colTenTL).ToString();
                    }
                }
            }
            catch
            {
                MessageBox.Show("Lưu thất bại");
            }
        }
Esempio n. 2
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);
             }
         }
     }
 }