示例#1
0
        private void simpleButtonGhiDuLieu_Click(object sender, EventArgs e)
        {
            _currentRowEdit = _isAddButton ? gridViewDSHocSinh.FocusedRowHandle : 0;

            var hocSinhDTO = new HocSinhDTO
            {
                NgaySinh   = Convert.ToDateTime(dateEditNgaySinh.EditValue),
                MaHocSinh  = textEditmaHocSinh.Text,
                TenHocSinh = textEditTenHocSinh.Text.Replace("'", "''"),
                GioiTinh   = radioGroupGioiTinh.SelectedIndex,
                NoiSinh    = textEditNoiSinh.Text.Replace("'", "''"),
                DiaChi     = textEditDiaChi.Text.Replace("'", "''"),
                Email      = textEditEmail.Text
            };

            string maLop = null;

            // neu co phan lop
            if (!checkEditChuaPhanLop.Checked)
            {
                hocSinhDTO.STT = Convert.ToInt32(spinEditSTTSoDiem.Value);
                maLop          = CboUtil.GetValueItem(comboBoxEditLop);
            }
            if (hocSinhDTO.TenHocSinh.Length < 3 || !hocSinhDTO.TenHocSinh.Contains(" "))
            {
                MsgboxUtil.Error("Họ tên học sinh không hợp lệ (không chứa khoảng trắng) hoặc nhỏ hơn 3 ký tự!");
                textEditTenHocSinh.Focus();
                return;
            }
            if (hocSinhDTO.NoiSinh.Length < 3)
            {
                MsgboxUtil.Error("Nơi sinh không hợp lệ (nhỏ hơn 3 ký tự)!");
                textEditNoiSinh.Focus();
                return;
            }
            if (hocSinhDTO.DiaChi.Length < 3)
            {
                MsgboxUtil.Error("Địa chỉ không hợp lệ (nhỏ hơn 3 ký tự)!");
                textEditDiaChi.Focus();
                return;
            }
            try
            {
                _hocSinhBUS.LuuHoSo_HocSinh(hocSinhDTO, maLop);
                MsgboxUtil.Success("Lưu hồ sơ học sinh " + hocSinhDTO.TenHocSinh + " thành công!");
            }
            catch (Exception ex)
            {
                MsgboxUtil.Error(ex);
                return;
            }
            LoadLai_GridControl_HocSinh(checkEditChuaPhanLop.Checked);
            _Diable_Control(isAdding: false);
        }