Ejemplo n.º 1
0
 //查询某一赛事的所有罚牌记录信息
 public static List<PlayerCardRecord> getMatchCardRecord(int matchID)
 {
     List<PlayerCardRecord> list = new List<PlayerCardRecord>();
     DBUtility dbutility = new DBUtility();
     string sql = "select playergetcardrecord.uniqueID,playergetcardrecord.matchID,matchinfo.seasonName,";
     sql = sql + "playergetcardrecord.playerID,player.playerName,playergetcardrecord.yellowCardNum,";
     sql = sql + "playergetcardrecord.redCardNum,playergetcardrecord.serialNum,playergetcardrecord.getDate,gameinfo.gameName from ";
     sql = sql + "playergetcardrecord,player,matchinfo,gameinfo where playergetcardrecord.matchID=matchinfo.ID and ";
     sql = sql + "gameinfo.matchID=playergetcardrecord.matchID and playergetcardrecord.serialNum=gameinfo.matchGameNum and ";
     sql = sql + "playergetcardrecord.playerID=player.ID and playergetcardrecord.matchID=" + matchID;
     sql = sql + " order by playergetcardrecord.serialNum";
     try
     {
         dbutility.openConnection();
         MySqlDataReader rd = dbutility.ExecuteQuery(sql);
         while (rd.Read())
         {
             PlayerCardRecord playerCardRecord = new PlayerCardRecord();
             playerCardRecord.setUniqueID(Convert.ToInt32(rd[0]));
             playerCardRecord.setMatchID(Convert.ToInt32(rd[1]));
             playerCardRecord.setMatchName(Convert.ToString(rd[2]));
             playerCardRecord.setPlayerID(Convert.ToInt32(rd[3]));
             playerCardRecord.setPlayerName(Convert.ToString(rd[4]));
             playerCardRecord.setYellowCardNum(Convert.ToInt32(rd[5]));
             playerCardRecord.setRedCardNum(Convert.ToInt32(rd[6]));
             playerCardRecord.setSerialNum(Convert.ToInt32(rd[7]));
             playerCardRecord.setDateTime(Convert.ToDateTime(rd[8]));
             playerCardRecord.setGameName(Convert.ToString(rd[9]));
             list.Add(playerCardRecord);
         }
     }
     catch (MySqlException ex)
     {
         Console.WriteLine(ex.ToString());
     }
     finally
     {
         dbutility.Close();
     }
     return list;
 }
Ejemplo n.º 2
0
 //添加球员罚牌记录信息
 public static void addNewPlayerCardNum(PlayerCardRecord _playerCardNum)
 {
     DBUtility dbutility = new DBUtility();
     string SQL = "insert into playerGetCardRecord(matchID,playerID,serialNum,yellowCardNum,redCardNum,";
     SQL = SQL + "getDate) values(" + _playerCardNum.getMatchID() + "," + _playerCardNum.getPlayerID() + ",";
     SQL = SQL + _playerCardNum.getSerialNum() + "," + _playerCardNum.getYellowCardNum() + ",";
     SQL = SQL + _playerCardNum.getRedCardNum() + ",'" + _playerCardNum.getDateTime() + "')";
     try
     {
         dbutility.openConnection();
         dbutility.ExecuteUpdate(SQL);
     }
     catch (MySqlException ex)
     {
         Console.WriteLine(ex.ToString());
     }
     finally
     {
         dbutility.Close();
     }
 }
        private void addPlayerRecord()
        {
            //记录各个变量
            int matchID;  //比赛ID
            int playerID;  //球员ID
            int matchSerial;  //赛事轮次
            int yellowCardNum;  //黄牌数量
            int redCardNum;  //红牌数量
            DateTime dateTime;  //记录添加罚牌记录的日期

            if (textBox_matchName.Text == "" || textBox_playerName.Text == "")  //赛事名称和用户名称不能为空
            {
                MessageBox.Show("赛事名称或球员姓名不能为空","不能为空",MessageBoxButtons.OKCancel,MessageBoxIcon.Information);
            }
            else
            {
                matchID = _match.getID();  //记录赛事的编号
                //查询并获取球员信息
                _player = ContentDAO.getPlayerInfo(textBox_playerName.Text);
                playerID = _player.getID();
                if (textBox_matchSerial.Text != "")  //当比赛场次不是空时
                {
                    //检查是否是数字
                    if (!checkSwitchResult.checkStringSwitchInteger(textBox_matchSerial.Text))
                    {
                        MessageBox.Show("赛事轮次必须是数字", "非数字", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                        return;
                    }
                    else //可以转换时
                    {
                        matchSerial = Convert.ToInt32(textBox_matchSerial.Text);
                    }
                }
                else  //比赛轮次是空时,记录其值为0
                {
                    matchSerial = 0;
                }
                if (textBox_yellowCardNum.Text != "")  //当黄牌数量不是空时
                {
                    //检查是否是数字
                    if (!checkSwitchResult.checkStringSwitchInteger(textBox_yellowCardNum.Text))
                    {
                        MessageBox.Show("黄牌数量必须是数字", "非数字", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                        return;
                    }
                    else //可以转换时
                    {
                        yellowCardNum = Convert.ToInt32(textBox_yellowCardNum.Text);
                    }
                }
                else
                {
                    yellowCardNum = 0;
                }
                if (textBox_redCardNum.Text != "")  //红牌数量不是空时
                {
                    //检查是否是数字
                    if (!checkSwitchResult.checkStringSwitchInteger(textBox_redCardNum.Text))
                    {
                        MessageBox.Show("红牌数量必须是数字", "非数字", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                        return;
                    }
                    else //可以转换时
                    {
                        redCardNum = Convert.ToInt32(textBox_redCardNum.Text);
                        if (yellowCardNum != 0 && yellowCardNum % SystemParam.getSwitchNum() == 0)
                        {
                            yellowCardNum = 0;
                        }
                    }
                }
                else
                {
                    redCardNum = 0;
                    if (yellowCardNum != 0 && yellowCardNum % SystemParam.getSwitchNum() == 0)  //若添加的黄牌数量可以转换成红牌时,直接将黄牌数变为0
                    {
                        yellowCardNum = 0;
                        redCardNum = 1;
                    }
                }
                //记录日期
                if (dateTimePicker_addCardRecord.Text != "")  //日期文本不是空时
                {
                    dateTime = dateTimePicker_addCardRecord.Value;
                }
                else  //日期文本是空时,直接设定当前日期为默认日期
                {
                    dateTime = DateTime.Today;
                }
                PlayerCardRecord _playerCardRecord = new PlayerCardRecord(matchID,playerID,matchSerial,yellowCardNum,redCardNum,dateTime);
                //往数据库中添加记录
                ContentDAO.addNewPlayerCardNum(_playerCardRecord);
                if (MessageBox.Show("添加罚牌信息成功,是否继续添加?", "添加罚牌成功", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    textBox_matchSerial.Text = "";
                    textBox_playerName.Text = "";
                    textBox_yellowCardNum.Text = "";
                    textBox_redCardNum.Text = "";
                }
                else
                {
                    this.Close();
                }
            }
        }