Example #1
0
        private void btnSuaDSHS_Click(object sender, EventArgs e)
        {
            //Ma, Ten, Gioitinh, Ngaysinh , Email, Doituong, Sodienthoai, Lopma
            HocSinh hs = new HocSinh();

            hs.Ma  = dtgDanhSachHS.Rows[dtgDanhSachHS.CurrentRow.Index].Cells[0].Value.ToString();
            hs.Ten = dtgDanhSachHS.Rows[dtgDanhSachHS.CurrentRow.Index].Cells[1].Value.ToString();
            int gioitinh = int.Parse(dtgDanhSachHS.Rows[dtgDanhSachHS.CurrentRow.Index].Cells[2].Value.ToString());

            DateTime ns = DateTime.Now;

            if (DateTime.TryParse(dtgDanhSachHS.Rows[dtgDanhSachHS.CurrentRow.Index].Cells[3].Value.ToString(), out ns))
            {
                hs.NgaySinh = ns;
            }
            hs.NgaySinh = ns;
            hs.Email    = dtgDanhSachHS.Rows[dtgDanhSachHS.CurrentRow.Index].Cells[4].Value.ToString();
            hs.DanToc   = dtgDanhSachHS.Rows[dtgDanhSachHS.CurrentRow.Index].Cells[5].Value.ToString();

            hs.DienThoai = dtgDanhSachHS.Rows[dtgDanhSachHS.CurrentRow.Index].Cells[6].Value.ToString();
            hs.LopMa     = dtgDanhSachHS.Rows[dtgDanhSachHS.CurrentRow.Index].Cells[7].Value.ToString();
            hs.DiaChi    = dtgDanhSachHS.Rows[dtgDanhSachHS.CurrentRow.Index].Cells[8].Value.ToString();
            frmSua       = new frmSua(hs, this);
            frmSua.ShowDialog();
            dtgDanhSachHS.DataSource = _control.getListHocSinh();
        }
Example #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (checkAdd())
            {
                HocSinh hs = new HocSinh();
                hs.Ten      = txtHoTenHS.Text.ToString().Trim();
                hs.LopMa    = cbbLop.Text.ToString().Trim();
                hs.NgaySinh = DateTime.Parse(dtpNgaySinh.Value.ToShortDateString());
                if (rdbnam.Checked)
                {
                    hs.GioiTinh = 1;
                }
                else
                {
                    hs.GioiTinh = 0;
                }
                hs.DanToc    = txtDanToc.Text.ToString().Trim();
                hs.DiaChi    = txtDiaChi.Text.ToString().Trim();
                hs.Email     = txtEmail.Text.ToString().Trim();
                hs.DienThoai = txtSDT.Text.ToString().Trim();

                //    ma, ten, gioitinh, ngaysinh , Email,anh , luong , nhiemvu, Vaitro, Bomonma , trangthai
                (new Controllers()).ThemHS(hs);
                DialogResult result = MessageBox.Show("Thành công", "Chỉnh sửa", MessageBoxButtons.OK);

                if (result == DialogResult.OK)
                {
                    btnThoat_Click(sender, e);
                    form1 = new Form1();
                }
            }
        }
Example #3
0
        public void ThemHocSinhADO(HocSinh hocSinh)
        {
            if (connection.State != ConnectionState.Open)
            {
                connection.Open();
            }

            SqlCommand command = new SqlCommand("ThemHocSinh", connection);

            command.CommandType = CommandType.StoredProcedure;

            //command.Parameters.Add(new SqlParameter("@MaHS", hocSinh.MaHS));
            command.Parameters.AddWithValue("@HoTen", hocSinh.HoTen);
            command.Parameters.AddWithValue("@GioiTinh", hocSinh.GioiTinh);
            command.Parameters.AddWithValue("@NgaySinh", hocSinh.NgaySinh);
            command.Parameters.AddWithValue("@DiaChi", hocSinh.DiaChi);
            command.Parameters.AddWithValue("@SoDT", hocSinh.SoDT);
            if (hocSinh.MaLop == "")
            {
                command.Parameters.AddWithValue("@MaLop", DBNull.Value);
            }
            else
            {
                command.Parameters.AddWithValue("@MaLop", hocSinh.MaLop);
            }

            command.ExecuteNonQuery();
            connection.Close();
        }
Example #4
0
        public void ThemHocSinhBUS(HocSinh hocSinh)
        {
            // Kiểm tra dữ liệu hợp lệ
            if (hocSinh.GioiTinh != "Nam" && hocSinh.GioiTinh != "Nữ")
            {
                throw new Exception("Giới tính không hợp lệ");
            }
            if (hocSinh.SoDT != "" && !Int32.TryParse(hocSinh.SoDT, out int check))
            {
                throw new Exception("Số điện thoại không hợp lệ");
            }
            if (hocSinh.MaLop != "" && !lopObject.KiemTraLopHopLeADO(hocSinh.MaLop))
            {
                throw new Exception("Lớp không hợp lệ");
            }

            // Quy định tuổi
            Tuple <int, int> quyDinhTuoi = hocSinhObject.LayQuyDinhTuoiADO();
            DateTime         ngaySinh    = DateTime.ParseExact(hocSinh.NgaySinh, "dd/MM/yyyy",
                                                               System.Globalization.CultureInfo.InvariantCulture);

            hocSinh.NgaySinh = ngaySinh.ToString();
            int tuoi = DateTime.Today.Year - ngaySinh.Year;

            if (tuoi < quyDinhTuoi.Item1 || tuoi > quyDinhTuoi.Item2)
            {
                throw new Exception("Tuổi sai quy định");
            }

            // Quy định sĩ số tối đa
            if (hocSinh.MaLop != "")
            {
                int siSoLop   = Convert.ToInt32(lopObject.LayDuLieuMotLopADO(Convert.ToInt32(hocSinh.MaLop))["SiSo"]);
                int siSoToiDa = lopObject.LayQuyDinhSiSoToiDaADO();
                if (siSoLop >= siSoToiDa)
                {
                    throw new Exception("Lớp này đã đầy");
                }
            }

            hocSinhObject.ThemHocSinhADO(hocSinh);
        }
Example #5
0
        private void LuuButton_Click(object sender, EventArgs e)
        {
            try
            {
                HocSinh hocSinh = new HocSinh(maHocSinhTextBox.Text,
                                              hoTenTextBox.Text,
                                              gioiTinhComboBox.Text,
                                              ngaySinhDateTimePicker.Text,
                                              diaChiTextBox.Text,
                                              soDienThoaiTextBox.Text,
                                              lopComboBox.Text == "" ? "" : (lopComboBox.SelectedValue.ToString()));
                hocSinhObject.ThemHocSinhBUS(hocSinh);
                MessageBox.Show("Thêm học sinh thành công");

                TiepNhanHocSinh_Load(sender, e);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void Button_Sua_Click(object sender, EventArgs e)
        {
            if (!checkThongTin() || currentMaHS == "")
            {
                MessageBox.Show("Không thể cập nhật thông tin", "Đã xảy ra lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            HocSinh temp = new HocSinh();

            temp.MaHocSinh = long.Parse(currentMaHS);
            temp.HoTen     = TextBox_HoTen.Text;
            if (RadioButton_Nam.Checked)
            {
                temp.GioiTinh = 1;
            }
            else if (RadioButton_Nu.Checked)
            {
                temp.GioiTinh = 0;
            }
            temp.NgaySinh = DateTimePicker_NgaySinh.Value;
            temp.DiaChi   = TextBox_DiaChi.Text;
            temp.Email    = TextBox_Email.Text;
            int?result = hocsinh.Update_HocSinh(temp);

            if (result == 1)
            {
                MessageBox.Show("Dữ liệu đã được cập nhật", "Cập nhật thành công!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Không thể cập nhật thông tin", "Đã xảy ra lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            currentMaHS = "";
            LoadThongTin();
            GridView_DSHocSinh.ClearSelection();
            ClearTextBoxes();
        }
Example #7
0
 private void btOk_Click(object sender, EventArgs e)
 {
     if (type == "Them")
     {
         if (txtMaHS.Text != "" && txtTen.Text != "" && txtTenNguoiThan.Text != "" && txtDiaChi.Text != "")
         {
             string gioitinh = "";
             if (rbNam.Checked)
             {
                 gioitinh = "Nam";
             }
             else if (rbNu.Checked)
             {
                 gioitinh = "Nữ";
             }
             else
             {
                 gioitinh = "Khác";
             }
             HocSinh hs = new HocSinh(txtMaHS.Text.Trim().ToString(), txtTen.Text.Trim().ToString(), txtDiaChi.Text.Trim(), gioitinh, DateTime.Parse(dtNgaySinh.Text), txtTenNguoiThan.Text.Trim(), txtMaLH.Text.Trim());
             if (dal_hs.Them(hs) == true)
             {
                 FormatData();
                 ShowData();
                 EnableMethod(true);
                 MessageBox.Show("Thêm thành công");
             }
             else
             {
                 Exception ex = dal_hs.GetEx();
                 MessageBox.Show(ex.Message);
             }
         }
         else
         {
             MessageBox.Show("Bạn cần nhập đủ thông tin phòng ban");
         }
     }
     else if (type == "Sua")
     {
         if (txtTen.Text != "")
         {
             string gioitinh = "";
             if (rbNam.Checked)
             {
                 gioitinh = "Nam";
             }
             else if (rbNu.Checked)
             {
                 gioitinh = "Nữ";
             }
             else
             {
                 gioitinh = "Khác";
             }
             HocSinh hs = new HocSinh(txtMaHS.Text.Trim().ToString(), txtTen.Text.Trim().ToString(), txtDiaChi.Text.Trim(), gioitinh, DateTime.Parse(dtNgaySinh.Text), txtTenNguoiThan.Text.Trim(), txtMaLH.Text.Trim());
             if (dal_hs.Sua(hs) == true)
             {
                 FormatData();
                 ShowData();
                 MessageBox.Show("Sửa thành công");
                 EnableMethod(true);
             }
             else
             {
                 Exception ex = dal_hs.GetEx();
                 MessageBox.Show(ex.Message);
             }
         }
         else
         {
             MessageBox.Show("Bạn cần nhập đủ thông tin phòng ban");
         }
     }
     else if (type == "Xoa")
     {
         if (txtMaHS.Text != "" && txtTen.Text != "" && txtTenNguoiThan.Text != "" && txtDiaChi.Text != "")
         {
             DialogResult dr = MessageBox.Show("Bạn có muốn xóa khồng?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
             if (dr == DialogResult.OK)
             {
                 dal_hs.Xoa(txtMaHS.Text);
                 EnableMethod(true);
                 ShowData();
                 FormatData();
             }
             else
             {
                 EnabledData(false);
                 EnableMethod(true);
             }
         }
     }
 }