private void btnThem_Click(object sender, EventArgs e) { try { if (txtMaDoi.Text == "") { MessageBox.Show("Bạn chưa nhập mã đội bóng!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); txtMaDoi.Focus(); } else if (txtTenDoi.Text == "") { MessageBox.Show("Bạn chưa nhập tên đội bóng!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); txtTenDoi.Focus(); } else if (cbxMaTinh.SelectedIndex == -1) { MessageBox.Show("Bạn chưa chọn mã tỉnh!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (cbxMaSan.SelectedIndex == -1) { MessageBox.Show("Bạn chưa chọn mã sân bóng!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (txtHLV.Text == "") { MessageBox.Show("Bạn chưa nhập tên huấn luyện viên!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); txtHLV.Focus(); } else if (txtImageSource.Text == "") { MessageBox.Show("Bạn chưa chọn ảnh!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (checkMa() == false) { MessageBox.Show("Mã đội bóng đã tồn tại!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); txtMaDoi.Focus(); } else { string maDoi = txtMaDoi.Text; string tenDoi = txtTenDoi.Text; string maSan = cbxMaSan.SelectedValue.ToString(); string hlv = txtHLV.Text; string matinh = cbxMaTinh.SelectedValue.ToString(); string diem = txtDiem.Text; string sobanthang = "0"; string sobanthua = "0"; string socauthu = "0"; //sobanthang = sobanthua = socauthu = "0"; try { currentImg = convertImageToBytes(); } catch { } DoiBongDTO dto = new DoiBongDTO(maDoi, tenDoi, maSan, hlv, matinh, currentImg, int.Parse(diem), int.Parse(sobanthang), int.Parse(sobanthua), int.Parse(socauthu) ); DoiBongDAO.saveDoiBong(dto, sys.UPDATE); MessageBox.Show("Thêm Thành Công!"); UC_DoiBong_Load(sender, e); reset(); } } catch { MessageBox.Show("Lỗi dữ liệu!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
//Sửa thuộc tính đội bóng private void btnEdit_Click(object sender, EventArgs e) { if (rowid >= 0 && rowid < dgvDoiBong.Rows.Count - 1) { try { if (txtTenDoi.Text == "") { MessageBox.Show("Bạn chưa nhập tên đội bóng!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); txtTenDoi.Focus(); } else if (cbxMaTinh.SelectedIndex == -1) { MessageBox.Show("Bạn chưa chọn mã tỉnh!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (cbxMaSan.SelectedIndex == -1) { MessageBox.Show("Bạn chưa chọn mã sân bóng!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (txtHLV.Text == "") { MessageBox.Show("Bạn chưa nhập tên huấn luyện viên!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); txtHLV.Focus(); } else if (txtImageSource.Text == "") { MessageBox.Show("Bạn chưa chọn ảnh!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { string maDoi = txtMaDoi.Text; string tenDoi = txtTenDoi.Text; string maSan = cbxMaSan.SelectedValue.ToString(); string hlv = txtHLV.Text; string matinh = cbxMaTinh.SelectedValue.ToString(); string diem = txtDiem.Text; string sobanthang = txtSoBanThang.Text; string sobanthua = txtSoBanThua.Text; string socauthu = txtSoCauThu.Text; //sobanthang = sobanthua = socauthu = "0"; try { currentImg = convertImageToBytes(); } catch { } DoiBongDTO dto = new DoiBongDTO(maDoi, tenDoi, maSan, hlv, matinh, currentImg, int.Parse(diem), int.Parse(sobanthang), int.Parse(sobanthua), int.Parse(socauthu) ); DoiBongDAO.saveDoiBong(dto, sys.UPDATE); MessageBox.Show("Sửa Thành Công!"); UC_DoiBong_Load(sender, e); } } catch { MessageBox.Show("Lỗi dữ liệu!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Bạn phải chọn đội bóng để sửa.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } }