Esempio n. 1
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            // kiểm tra thông tin không được để trống
            if (string.IsNullOrEmpty(txtMaLop.Text) || string.IsNullOrEmpty(txtTenLop.Text) ||
                string.IsNullOrEmpty(txtNienKhoa.Text) || string.IsNullOrEmpty(cmbGVCN.Text) || cmbGVCN.SelectedIndex == -1)
            {
                MessageBox.Show("Không được để trống thông tin");
                return;
            }
            // kiểm tra mã lớp đã tồn tại hay chưa?
            if (lopBus.Exist(txtMaLop.Text))
            {
                MessageBox.Show("Mã lớp đã tồn tại");
                return;
            }

            // Lấy thông tin trên form  vào lop
            Lop lop = new Lop();

            lop.MaLop            = txtMaLop.Text;
            lop.TenLop           = txtTenLop.Text;
            lop.NienKhoa         = txtNienKhoa.Text;
            lop.SiSo             = (int)numSiSo.Value;
            lop.GiaoVienChuNhiem = cmbGVCN.SelectedValue.ToString();
            // kiểm tra môn hk có thất bại hay ko?
            if (!lopBus.Insert(lop))
            {
                MessageBox.Show(" Thêm môn học thành công");
                return;
            }

            // Tải lại dữ liệu
            QuanLyLopGUI_Load(sender, e);
        }
Esempio n. 2
0
        private void btnThemLop_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtTenLop.Text == "")
                {
                    MessageBox.Show("Phải nhập tên lớp");
                    return;
                }
                if (countSelectedRow() == 0)
                {
                    MessageBox.Show("Phải chọn ít nhất 1 môn học");
                    return;
                }

                DialogResult result = MessageBox.Show("Bạn có chắc muốn thêm lớp này không?",
                                                      "Question",
                                                      MessageBoxButtons.YesNo,
                                                      MessageBoxIcon.Question,
                                                      MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Yes)
                {
                    lopDTO.TenLop = txtTenLop.Text;

                    if (txtSoLuongSinhVien.Text == "")
                    {
                        lopDTO.SoLuongSinhVien = 0;
                    }
                    else
                    {
                        lopDTO.SoLuongSinhVien = Int32.Parse(txtSoLuongSinhVien.Text);
                    }

                    if (txtSoLuongTrongNganSach.Text == "")
                    {
                        lopDTO.SoLuongTrongNganSach = 0;
                    }
                    else
                    {
                        lopDTO.SoLuongTrongNganSach = Int32.Parse(txtSoLuongTrongNganSach.Text);
                    }

                    if (txtSoLuongNgoaiNganSach.Text == "")
                    {
                        lopDTO.SoLuongNgoaiNganSach = 0;
                    }
                    else
                    {
                        lopDTO.SoLuongNgoaiNganSach = Int32.Parse(txtSoLuongNgoaiNganSach.Text);
                    }

                    //lopDTO.MaNamHoc = (cmbNamHoc.SelectedItem as NamHocDTO).MaNamHoc;
                    LopBUS.Insert(lopDTO);

                    foreach (DataGridViewRow row in dtgvDSMon.Rows)
                    {
                        if (row.Cells[0].Value != null)
                        {
                            LopMonDTO lopMonDTO = new LopMonDTO();
                            lopMonDTO.MaLop = lopDTO.MaLop;
                            lopMonDTO.MaMon = Int32.Parse(row.Cells["MaMon"].Value.ToString());
                            LopMonBUS.Insert(lopMonDTO);

                            ChiTietMonDTO chiTietMonDTO = new ChiTietMonDTO();
                            chiTietMonDTO.MaLopMon = lopMonDTO.MaLopMon;
                            ChiTietMonBUS.Insert(chiTietMonDTO);
                        }
                    }

                    MessageBox.Show("Thêm lớp thành công");

                    LayDanhSachChiTietMon();

                    btnCapNhatChiTietMon.Visible = true;
                    dtgvChiTietMon.Visible       = true;
                    btnThemLop.Enabled           = false;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }