示例#1
0
        private void btnthemhp_Click(object sender, EventArgs e)
        {
            if (!DuLieuHopLe())
            {
                return;
            }

            string  mahp   = txtmahp.Text;
            string  tenhp  = txttenhp.Text;
            int     stc    = string.IsNullOrEmpty(txtstchp.Text) ? 0 : int.Parse(txtstchp.Text);
            string  loaihp = cbbLoaiHocPhan.Text;
            decimal tsdqt  = decimal.Parse(txtTrongSoDQT.Text);
            decimal tsdt   = decimal.Parse(txtTrongSoDThi.Text);

            MonHoc monhoc = new MonHoc(mahp, tenhp, stc, loaihp, tsdqt, tsdt);

            if (monhocBUS.Them(monhoc))
            {
                MessageBox.Show("Thành công !");

                bs.DataSource = monhocBUS.DanhSach();
            }
            else
            {
                MessageBox.Show("Lỗi !", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            txtmahp.Focus();
        }
        private void btnLuu_Click(object sender, EventArgs e)
        {
            try
            {
                MonHoc mh = new MonHoc();
                if (!string.IsNullOrEmpty(txtMaMH.Text))
                {
                    mh.MaMH = txtMaMH.Text.Trim();
                }
                else
                {
                    MsgboxUtil.Exclamation("Mã môn học không được để trống");
                    txtMaMH.Focus();
                    return;
                }
                if (!string.IsNullOrEmpty(txtTenMH.Text))
                {
                    mh.TenMH = txtTenMH.Text.Trim();
                }
                else
                {
                    MsgboxUtil.Exclamation("Tên môn học không được để trống");
                    txtTenMH.Focus();
                    return;
                }
                if (numSTC.Value > 0)
                {
                    mh.STC = (byte)numSTC.Value;
                }
                else
                {
                    MsgboxUtil.Exclamation("Số tín chỉ không thể nhỏ hơn 0");
                    numSTC.Focus();
                    return;
                }

                if (numLyThuyet.Value > 0)
                {
                    mh.LyThuyet = (byte)numLyThuyet.Value;
                }
                else
                {
                    MsgboxUtil.Exclamation("Số tiết lý thuyết không thể nhỏ hơn 0");
                    numLyThuyet.Focus();
                    return;
                }

                if (numThucHanh.Value >= 0)
                {
                    mh.ThucHanh = (byte)numThucHanh.Value;
                }
                else
                {
                    MsgboxUtil.Exclamation("Số tiết thực hành không thể nhỏ hơn 0");
                    numThucHanh.Focus();
                    return;
                }
                MonHocBUS.Them(mh);
                StaticClass.LuuThayDoi();
                log.GhiFile("Thêm mới môn học: " + mh.MaMH);
                MsgboxUtil.Success("Thành công");
                btnHuy_Click(null, null);
            }
            catch (Exception ex)
            {
                ExceptionUtil.ThrowMsgBox(ex.Message);
            }
        }