Exemplo n.º 1
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (txtMaHS.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập học sinh! ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (txtTenHS.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập tên học sinh! ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (cbMaLop.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập lớp học sinh! ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (radNam.Checked == false && radNu.Checked == false)
            {
                MessageBox.Show("Bạn chưa chọn giới tính cho học sinh! ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (txtDanToc.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập dân tộc học sinh! ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (txtTonGiao.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập tôn giáo học sinh! ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (txtDiaChi.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập địa chỉ học sinh! ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                txtMaHS.Enabled = false;
                // xử lý
                obj.MaHS     = txtMaHS.Text;
                obj.TenHS    = txtTenHS.Text;
                obj.MaLop    = cbMaLop.SelectedValue.ToString();
                obj.TonGiao  = txtTonGiao.Text;
                obj.DanToc   = txtDanToc.Text;
                obj.NgaySinh = dtNgaySinh.Value;
                obj.DiaChi   = txtDiaChi.Text;

                string gt;
                if (radNam.Checked)
                {
                    gt = "Nam";
                }
                else
                {
                    gt = "Nữ";
                }

                obj.GioiTinh = gt;

                if (fluu == 0)
                {
                    try
                    {
                        Bus.InsertData(obj);
                        MessageBox.Show("Thêm thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        HienThi();
                        clearData();
                        DisEnl(false);
                        fluu = 1;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Lỗi!" + ex.Message);
                    }
                }
                else if (fluu != 0)
                {
                    try
                    {
                        Bus.UpdateData(obj);
                        MessageBox.Show("Sửa Thành Công ! ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        HienThi();
                        clearData();
                        DisEnl(false);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Lỗi sửa" + ex.Message);
                    }
                }
            }
        }