Beispiel #1
0
        //Thêm cầu thủ
        private void btnAdd_Click(object sender, EventArgs e)
        {
            int soao;

            try
            {
                if (txtMaCT.Text == "")
                {
                    MessageBox.Show("Bạn chưa tạo mã cầu thủ!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtMaCT.Focus();
                }
                else if (txtTenCT.Text == "")
                {
                    MessageBox.Show("Bạn chưa nhập tên cầu thủ!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtTenCT.Focus();
                }
                else if (cbxDoiBong.SelectedIndex == -1)
                {
                    MessageBox.Show("Bạn chưa chọn đội bóng!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (cbxViTri.SelectedIndex == -1)
                {
                    MessageBox.Show("Bạn chưa chọn vị trí!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (txtSoAo.Text == "")
                {
                    MessageBox.Show("Bạn chưa nhập số áo!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtSoAo.Focus();
                }
                else if (int.TryParse(txtSoAo.Text, out soao) == false)
                {
                    MessageBox.Show("Số áo không hợp lệ!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtSoAo.Text = "";
                    txtSoAo.Focus();
                }
                else if (cbxQuocTich.SelectedIndex == -1)
                {
                    MessageBox.Show("Bạn chưa chọn quốc tịch!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (txtImageSource.Text == "")
                {
                    MessageBox.Show("Bạn chưa chọn ảnh!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    if (soao <= 0 || soao > 99)
                    {
                        MessageBox.Show("Số áo không hợp lệ!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txtSoAo.Text = "";
                        txtSoAo.Focus();
                        return;
                    }

                    string   maCT       = txtMaCT.Text;
                    string   maDoi      = cbxDoiBong.SelectedValue.ToString();
                    string   tenCT      = txtTenCT.Text;
                    string   viTri      = cbxViTri.SelectedValue.ToString();
                    DateTime ngaySinh   = dtpNgaySinh.Value;
                    string   soAo       = txtSoAo.Text;
                    string   soBanThang = txtSoBanThang.Text;
                    string   soTheVang  = txtSoTheVang.Text;
                    string   soTheDo    = txtSoTheDo.Text;
                    string   maQuocTich = cbxQuocTich.SelectedValue.ToString();
                    string   soLanRaSan = txtSoLanRaSan.Text;

                    soBanThang = soTheVang = soTheDo = soLanRaSan = "0";

                    //Khởi tạo 1 cầu thủ
                    CauThuDTO dto = new CauThuDTO(maCT,
                                                  maDoi,
                                                  tenCT,
                                                  viTri,
                                                  ngaySinh,
                                                  int.Parse(soAo),
                                                  int.Parse(soBanThang),
                                                  int.Parse(soTheVang),
                                                  int.Parse(soTheDo),
                                                  maQuocTich,
                                                  int.Parse(soLanRaSan),
                                                  convertImageToBytes());

                    //Insert xuống database
                    CauThuDAO.saveCauThu(dto, sys.INSERT);
                    MessageBox.Show("Thêm cầu thủ thành công.");

                    UC_CauThu_Load(sender, e);
                    reset();
                }
            }
            catch
            {
                MessageBox.Show("Lỗi dữ liệu!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Beispiel #2
0
        //Sửa cầu thủ
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (rowid >= 0 && rowid < dgvCauThu.Rows.Count - 1) //Nếu đã chọn cầu thủ để sửa
            {
                try
                {
                    if (txtMaCT.Text == "")
                    {
                        MessageBox.Show("Bạn chưa tạo mã cầu thủ!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txtMaCT.Focus();
                    }
                    else if (txtTenCT.Text == "")
                    {
                        MessageBox.Show("Bạn chưa nhập tên cầu thủ!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txtTenCT.Focus();
                    }
                    else if (cbxDoiBong.SelectedIndex == -1)
                    {
                        MessageBox.Show("Bạn chưa chọn đội bóng!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (cbxViTri.SelectedIndex == -1)
                    {
                        MessageBox.Show("Bạn chưa chọn vị trí!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (txtSoAo.Text == "")
                    {
                        MessageBox.Show("Bạn chưa nhập số áo!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txtSoAo.Focus();
                    }
                    else if (cbxQuocTich.SelectedIndex == -1)
                    {
                        MessageBox.Show("Bạn chưa chọn quốc tịch!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (txtImageSource.Text == "")
                    {
                        MessageBox.Show("Bạn chưa chọn ảnh!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        string   maCT       = txtMaCT.Text;
                        string   maDoi      = cbxDoiBong.SelectedValue.ToString();
                        string   tenCT      = txtTenCT.Text;
                        string   viTri      = cbxViTri.SelectedValue.ToString();
                        DateTime ngaySinh   = dtpNgaySinh.Value;
                        string   soAo       = txtSoAo.Text;
                        string   soBanThang = txtSoBanThang.Text;
                        string   soTheVang  = txtSoTheVang.Text;
                        string   soTheDo    = txtSoTheDo.Text;
                        string   maQuocTich = cbxQuocTich.SelectedValue.ToString();
                        string   soLanRaSan = txtSoLanRaSan.Text;

                        soBanThang = soTheVang = soTheDo = soLanRaSan = "0";
                        try
                        {
                            currentImg = convertImageToBytes();
                        }
                        catch
                        {
                            MessageBox.Show("Lỗi dữ liệu!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        CauThuDTO dto = new CauThuDTO(maCT,
                                                      maDoi,
                                                      tenCT,
                                                      viTri,
                                                      ngaySinh,
                                                      int.Parse(soAo),
                                                      int.Parse(soBanThang),
                                                      int.Parse(soTheVang),
                                                      int.Parse(soTheDo),
                                                      maQuocTich,
                                                      int.Parse(soLanRaSan),
                                                      currentImg);

                        CauThuDAO.saveCauThu(dto, sys.UPDATE);
                        MessageBox.Show("Sửa cầu thủ thành công!");

                        UC_CauThu_Load(sender, e);
                        reset();
                    }
                }
                catch
                {
                    MessageBox.Show("Lỗi dữ liệu!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show("Bạn phải chọn cầu thủ để sửa.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }