public static void updatePhatThe(PHATTHE phatthe)
        {
            SqlConnection conn        = DatabaseManager.Instance.getConnection();
            string        ThoiDiem    = phatthe.ThoiDiem.ToString("c");
            string        queryString = "UPDATE PHATTHE SET MaCauThu = @MaCauThu, MaLoaiThe = @MaLoaiThe, ThoiDiem = @ThoiDiem, MaTranDau = @MaTranDau WHERE MaPhatThe = @MaPhatThe";
            SqlCommand    command     = new SqlCommand(queryString);

            try
            {
                command.Parameters.AddWithValue("@MaCauThu", phatthe.MaCauThu);
                command.Parameters.AddWithValue("@MaLoaiThe", phatthe.MaLoaiThe);
                command.Parameters.AddWithValue("@ThoiDiem", ThoiDiem);
                command.Parameters.AddWithValue("@MaTranDau", phatthe.MaTranDau);
                command.Parameters.AddWithValue("@MaPhatThe", phatthe.MaPhatThe);
                command.Connection = conn;
                int res = command.ExecuteNonQuery();
                if (res == 0)
                {
                    throw new Exception();
                }
            }
            catch (SqlException SQLex)
            {
                throw SQLex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static void createPhatThe(PHATTHE phatthe)
        {
            string        ThoiDiem = phatthe.ThoiDiem.ToString("c");
            SqlConnection conn     = DatabaseManager.Instance.getConnection();

            string     queryString = "INSERT INTO PHATTHE Values (NEWID(), @MaCauThu, @MaLoaiThe, @ThoiDiem, @MaTranDau)";
            SqlCommand command     = new SqlCommand(queryString);

            try
            {
                command.Parameters.AddWithValue("@MaCauThu", phatthe.MaCauThu);
                command.Parameters.AddWithValue("@MaLoaiThe", phatthe.MaLoaiThe);
                command.Parameters.AddWithValue("@ThoiDiem", ThoiDiem);
                command.Parameters.AddWithValue("@MaTranDau", phatthe.MaTranDau);
                command.Connection = conn;
                int res = command.ExecuteNonQuery();
                if (res == 0)
                {
                    throw new Exception();
                }
            }
            catch (SqlException SQLex)
            {
                throw SQLex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static void selectPhatThe(string MaPhatThe, out PHATTHE phatthe)
        {
            SqlConnection conn        = DatabaseManager.Instance.getConnection();
            string        queryString = "SELECT * FROM PHATTHE WHERE MaPhatThe = @MaPhatThe";
            SqlCommand    command     = new SqlCommand(queryString);

            phatthe = new PHATTHE()
            {
                MaCauThu  = "",
                MaLoaiThe = "",
                ThoiDiem  = new TimeSpan(0),
            };
            try
            {
                command.Parameters.AddWithValue("@MaPhatThe", MaPhatThe);
                command.Connection = conn;
                SqlDataReader reader = command.ExecuteReader();
                if (reader.Read())
                {
                    phatthe.MaCauThu  = reader.GetString(1);
                    phatthe.MaLoaiThe = reader.GetString(2);
                    phatthe.ThoiDiem  = reader.GetTimeSpan(3);
                }
                reader.Close();
            }
            catch (SqlException SQLex)
            {
                throw SQLex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void suaThePhat_Click(object sender, EventArgs e)
        {
            if (suaThePhat.Text.Equals("Sửa"))
            {
                if (danhSachPhamLoiData.SelectedCells.Count == 0 || danhSachPhamLoiData.SelectedCells[0].RowIndex < 0)
                {
                    MessageBox.Show("Xin hãy chọn thông tin 1 thẻ phạt trong bảng để chỉnh sửa", "Thông báo");
                    return;
                }
                else
                {
                    selectedFoulId = danhSachPhamLoiData.SelectedCells[0].OwningRow.Cells[0].Value.ToString();
                    try
                    {
                        PHATTHE phatthe;
                        Database.PhatThe_DAO.selectPhatThe(selectedFoulId, out phatthe);
                        cauThuPhamLoiComboBox.SelectedValue = phatthe.MaCauThu;
                        loaiThePhatComboBox.SelectedValue   = phatthe.MaLoaiThe;
                        phutPhamLoi.Value = phatthe.ThoiDiem.Hours * 60 + phatthe.ThoiDiem.Minutes;
                        giayPhamLoi.Value = phatthe.ThoiDiem.Seconds;

                        xoaThePhat.Text     = "Hủy";
                        suaThePhat.Text     = "Lưu";
                        themThePhat.Enabled = false;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Lỗi xảy ra");
                    }
                }
            }
            else if (suaThePhat.Text.Equals("Lưu"))
            {
                //update foul info

                try
                {
                    PHATTHE phatthe = new PHATTHE()
                    {
                        MaPhatThe = selectedFoulId,
                        MaCauThu  = cauThuPhamLoiComboBox.SelectedValue.ToString(),
                        MaLoaiThe = loaiThePhatComboBox.SelectedValue.ToString(),
                        ThoiDiem  = new TimeSpan(0, Int16.Parse(phutPhamLoi.Value.ToString()), Int16.Parse(giayPhamLoi.Value.ToString())),
                        MaTranDau = GlobalState.selectedMatchId,
                    };
                    Database.PhatThe_DAO.updatePhatThe(phatthe);
                    MessageBox.Show("Cập nhật thành công", "Thông báo");
                    thePhatExtTableAdapter.Fill(quanLyGiaiVoDichDataSet.ThePhatExt);
                    selectedFoulId      = "";
                    xoaThePhat.Text     = "Xóa";
                    suaThePhat.Text     = "Sửa";
                    themThePhat.Enabled = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Lỗi xảy ra");
                }
            }
        }
        private void themThePhat_Click(object sender, EventArgs e)
        {
            int      minutes = Int16.Parse(phutPhamLoi.Value.ToString());
            int      second  = Int16.Parse(giayPhamLoi.Value.ToString());
            TimeSpan time    = new TimeSpan(0, minutes, second);

            string timeString = time.ToString();

            bool checkComboBox  = (doiPhamLoiComboBox.Text == "");
            bool checkTimeEvent = checkTime(timeString, danhSachPhamLoiData, 4);

            if (checkComboBox && checkTimeEvent)
            {
                MessageBox.Show("Hãy chọn đội bóng!");
            }
            else
            if ((!checkTimeEvent && checkComboBox) || (!checkComboBox && !checkTimeEvent))
            {
                MessageBox.Show("Thời điểm đã trùng");
            }
            else
            {
                try
                {
                    PHATTHE phatthe = new PHATTHE()
                    {
                        MaTranDau = GlobalState.selectedMatchId,
                        MaCauThu  = cauThuPhamLoiComboBox.SelectedValue.ToString(),
                        MaLoaiThe = loaiThePhatComboBox.SelectedValue.ToString(),
                        ThoiDiem  = new TimeSpan(0, Int16.Parse(phutPhamLoi.Value.ToString()), Int16.Parse(giayPhamLoi.Value.ToString())),
                        MaPhatThe = GlobalState.selectedMatchId,
                    };
                    Database.PhatThe_DAO.createPhatThe(phatthe);
                    this.thePhatExtTableAdapter.Fill(this.quanLyGiaiVoDichDataSet.ThePhatExt);
                    MessageBox.Show("Thêm thành công", "Thông báo");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Lỗi xảy ra");
                }
            }
        }