Example #1
0
        private int Execute(string _operator, DKhoa _operand, DKhoa oldstate)
        {
            Command command = new KhoaCommand(_operator, _operand, oldstate);
            int     code    = command.Execute();

            _commands.Push(command);
            btnUndo.Enabled = true;
            return(code);
        }
Example #2
0
        private void btnXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            btnXoa.Enabled = false;
            DataRow red         = gridView1.GetFocusedDataRow();
            DKhoa   KHTrongBang = new DKhoa
            {
                MaKhoa  = red["Mã khoa"].ToString(),
                TenKhoa = red["Tên khoa"].ToString(),
                MaCS    = DBAccess.donVi
            };

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

            if (code == 0)
            {
                //MessageBox.Show("Xoá khoa thành công");
                btnReload.PerformClick();
            }
            else
            {
                MessageBox.Show("Xoá khoa thất bại.");
            }
        }
        public int Operation(string _operator, DKhoa _operand, DKhoa oldstate)
        {
            int code = 0;

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

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

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

            case "unupdate":
                code = UpdateKhoa(oldstate);
                break;
            }
            return(code);
        }
 public int RemoveKhoa(DKhoa khoa)
 {
     string[] name  = { "@makh" };
     object[] param = { khoa.MaKhoa };
     return(DBAccess.ExecuteNonQuery("SP_XoaKhoa", name, param, 1));
 }
 public int UpdateKhoa(DKhoa khoa)
 {
     string[] name  = { "@makh", "@tenkh", "@macs" };
     object[] param = { khoa.MaKhoa, khoa.TenKhoa, khoa.MaCS };
     return(DBAccess.ExecuteNonQuery("SP_SuaKhoa", name, param, 3));
 }
 public KhoaCommand(string _operator, DKhoa _operand, DKhoa oldstate)
 {
     this._operator = _operator;
     this._operand  = _operand;
     this.oldstate  = oldstate;
 }
Example #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ã khoa không được bỏ trống");
                errors += "\r\n+ Mã khoa bị bỏ trống";
                noError++;
            }
            if (textBox2.Text.Trim() == "")
            {
                //MessageBox.Show("Tên khoa không được bỏ trống");
                errors += "\r\n+ Tên khoa bị bỏ trống";
                noError++;
            }
            if (noError > 0)
            {
                MessageBox.Show(errors);
                btnLuu.Enabled = true;
                return;
            }

            if (textBox1.Enabled)
            {
                DKhoa KHTrongForm = new DKhoa
                {
                    MaKhoa  = textBox1.Text.Trim().ToUpper(),
                    TenKhoa = textBox2.Text.Trim(),
                    MaCS    = DBAccess.donVi
                };

                int code = Execute("insert", KHTrongForm, null);
                if (code == 0)
                {
                    btnReload.PerformClick();
                    //MessageBox.Show("Tạo khoa thành công");
                }
                else
                {
                    MessageBox.Show("Tạo khoa thất bại");
                }
                textBox1.Enabled = false;
            }
            else
            {
                DataRow red         = gridView1.GetFocusedDataRow();
                DKhoa   KHTrongBang = new DKhoa
                {
                    MaKhoa  = red["Mã khoa"].ToString(),
                    TenKhoa = red["Tên khoa"].ToString(),
                    MaCS    = DBAccess.donVi
                };
                DKhoa KHTrongForm = new DKhoa
                {
                    MaKhoa  = textBox1.Text.Trim().ToUpper(),
                    TenKhoa = textBox2.Text.Trim(),
                    MaCS    = DBAccess.donVi
                };


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