예제 #1
0
        private void btnXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            btnXoa.Enabled = false;
            DataRow   red         = gridView1.GetFocusedDataRow();
            DSinhVien KHTrongBang = new DSinhVien
            {
                MaSV     = red["Mã sinh viên"].ToString(),
                Ho       = red["Họ"].ToString(),
                Ten      = red["Tên"].ToString(),
                NgaySinh = DateTime.Parse(red["Ngày sinh"].ToString()),
                DiaChi   = red["Địa chỉ"].ToString(),
                MaLop    = lop.Select(string.Format("tenlop ='{0}'", red["Tên lớp"].ToString()))[0][0].ToString()
            };

            int code = Execute("delete", KHTrongBang, null);

            if (code == 0)
            {
                //MessageBox.Show("Xoá sinh viên thành công");
                btnReload.PerformClick();
            }
            else
            {
                MessageBox.Show("Xoá sinh viên thất bại.");
            }
        }
예제 #2
0
        private int Execute(string _operator, DSinhVien _operand, DSinhVien oldstate)
        {
            Command command = new SinhVienCommand(_operator, _operand, oldstate);
            int     code    = command.Execute();

            _commands.Push(command);
            btnUndo.Enabled = true;
            return(code);
        }
        public int Operation(string _operator, DSinhVien _operand, DSinhVien oldstate)
        {
            int code = 0;

            switch (_operator)
            {
            case "insert":
                code = CreateSinhVien(_operand);
                break;

            case "update":
                code = UpdateSinhVien(_operand);
                break;

            case "delete":
                code = RemoveSinhVien(_operand);
                break;

            case "unupdate":
                code = UpdateSinhVien(oldstate);
                break;
            }
            return(code);
        }
 public int RemoveSinhVien(DSinhVien sv)
 {
     string[] name  = { "@masv" };
     object[] param = { sv.MaSV };
     return(DBAccess.ExecuteNonQuery("SP_XoaSinhVien", name, param, 1));
 }
 public int UpdateSinhVien(DSinhVien sv)
 {
     string[] name  = { "@masv", "@ho", "@ten", "@ngaysinh", "@diachi", "@malop" };
     object[] param = { sv.MaSV, sv.Ho, sv.Ten, String.Format("{0:yyyy-MM-dd}", sv.NgaySinh), sv.DiaChi, sv.MaLop };
     return(DBAccess.ExecuteNonQuery("SP_SuaSinhVien", name, param, 6));
 }
 public SinhVienCommand(string _operator, DSinhVien _operand, DSinhVien oldstate)
 {
     this._operator = _operator;
     this._operand  = _operand;
     this.oldstate  = oldstate;
 }
예제 #7
0
        private void btnLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            btnLuu.Enabled = false;
            int    noError = 0;
            string errors  = "Nội dung bạn nhập có 1 số lỗi sau. Vui lòng sửa trước khi lưu.";

            if (textBox1.Text.Trim() == "")
            {
                //MessageBox.Show("Mã sinh viên không được bỏ trống");
                errors += "\r\n+ Mã sinh viên bị bỏ trống";
                noError++;
            }
            if (textBox2.Text.Trim() == "")
            {
                //MessageBox.Show("Họ không được bỏ trống");
                errors += "\r\n+ Họ bị bỏ trống";
                noError++;
            }
            if (textBox3.Text.Trim() == "")
            {
                //MessageBox.Show("Tên không được bỏ trống");
                errors += "\r\n+ Tên bị bỏ trống";
                noError++;
            }
            if (comboBox2.Text.Trim() == "")
            {
                //MessageBox.Show("Tên lớp không được bỏ trống. Vui lòng nhập thêm lớp hoặc kiểm tra lại CSDL");
                errors += "\r\n+ Tên lớp không được bỏ trống.\r\nVui lòng nhập thêm lớp hoặc kiểm tra lại CSDL";
                noError++;
            }
            if (dateTimePicker1.Value.Date > DateTime.Today.AddYears(18))
            {
                ///MessageBox.Show("Chỉ được đăng ký lịch thi sau thời điểm hiện tại");
                errors += "\r\n+ Ngày sinh không hợp lệ";
                noError++;
            }
            if (noError > 0)
            {
                MessageBox.Show(errors);
                btnLuu.Enabled = true;
                return;
            }


            if (textBox1.Enabled)
            {
                DSinhVien KHTrongForm = new DSinhVien
                {
                    MaSV     = textBox1.Text.Trim().ToUpper(),
                    Ho       = textBox2.Text.Trim().ToUpper(),
                    Ten      = textBox3.Text.Trim().ToUpper(),
                    NgaySinh = dateTimePicker1.Value,
                    DiaChi   = textBox4.Text.Trim(),
                    MaLop    = lop.Select(string.Format("tenlop ='{0}'", comboBox2.Text.Trim()))[0][0].ToString()
                };

                int code = Execute("insert", KHTrongForm, null);
                if (code == 0)
                {
                    btnReload.PerformClick();
                    //MessageBox.Show("Tạo sinh viên thành công");
                }
                else
                {
                    MessageBox.Show("Tạo sinh viên thất bại");
                }
                textBox1.Enabled = false;
            }
            else
            {
                DataRow   red         = gridView1.GetFocusedDataRow();
                DSinhVien KHTrongBang = new DSinhVien
                {
                    MaSV     = red["Mã sinh viên"].ToString(),
                    Ho       = red["Họ"].ToString(),
                    Ten      = red["Tên"].ToString(),
                    NgaySinh = DateTime.Parse(red["Ngày sinh"].ToString()),
                    DiaChi   = red["Địa chỉ"].ToString(),
                    MaLop    = lop.Select(string.Format("tenlop ='{0}'", red["Tên lớp"].ToString()))[0][0].ToString()
                };
                DSinhVien KHTrongForm = new DSinhVien
                {
                    MaSV     = textBox1.Text.Trim().ToUpper(),
                    Ho       = textBox2.Text.Trim().ToUpper(),
                    Ten      = textBox3.Text.Trim().ToUpper(),
                    NgaySinh = dateTimePicker1.Value,
                    DiaChi   = textBox4.Text.Trim(),
                    MaLop    = lop.Select(string.Format("tenlop ='{0}'", comboBox2.Text.Trim()))[0][0].ToString()
                };

                int code = Execute("update", KHTrongForm, KHTrongBang);
                if (code == 0)
                {
                    btnReload.PerformClick();
                    //MessageBox.Show("Lưu sinh viên thành công");
                }
                else
                {
                    MessageBox.Show("Lưu sinh viên thất bại");
                }
            }
            btnLuu.Enabled = true;
        }