//显示赛事的基本信息 public void showMatchData() { //先清除DataGridView中的数据 if (dataGridView_match.Rows.Count > 0) { dataGridView_match.Rows.Clear(); } //取出数据 List<SeasonMatch> list = ContentDAO.getMatchInfo(); //往dataGridView中添加数据 for (int i = 0; i < list.Count; i++) { match = list[i]; //取出线性表中的赛事的信息 dataGridView_match.Rows.Add(match.getID().ToString(), match.getName(), match.getDescription(), match.getSwitchNum().ToString(), match.getSerialNum().ToString()); } }
//添加一个比赛的记录, private void addNewMatchGameInfo(SeasonMatch match) { if (textBox_GameName.Text != "") //检查比赛名字 { //检查比赛名称是否合法 string gameName = textBox_GameName.Text; if (GameInfoDAO.checkGameNameExist(match.getID(), gameName)) { MessageBox.Show("比赛名字已经存在,请修改", "比赛名字重复", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } else { //检查比赛序号 if (textBox_gameNum.Text != "") { if (checkSwitchResult.checkStringSwitchInteger(textBox_gameNum.Text)) { int gameNum = Convert.ToInt32(textBox_gameNum.Text); //检查比赛序号是否存在 if (GameInfoDAO.checkGameNumExist(match.getID(), gameNum)) { MessageBox.Show("比赛序号已经存在,请修改", "比赛序号重复", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } else { //判断比赛序号是否合法,即是否超过该赛事所限制的比赛次数 if (gameNum <= match.getSerialNum()) { if (comboBox_homeTeam.Text != "") { if (comboBox_guestTeam.Text != "") { Game _game = new Game(); //声明一个比赛类,并且赋值 _game.setMatchID(match.getID()); _game.setGameName(gameName); _game.setMatchGameNum(gameNum); _game.setHomeTeam(comboBox_homeTeam.Text); _game.setGuestTeam(comboBox_guestTeam.Text); _game.setGameWinner(comboBox_winner.Text); _game.setGameResult(textBox_gameResult.Text); _game.setGameAddress(textBox_gameAddress.Text); _game.setGameDate(Convert.ToDateTime(dateTimePicker_gameDate.Text)); //执行更新操作 GameInfoDAO.addNewGameInfo(_game); //弹出对话框,提示是否继续添加 if (MessageBox.Show("添加比赛信息成功,是否继续添加?", "添加比赛成功", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { //清空其他 textBox_GameName.Text = ""; textBox_gameNum.Text = ""; textBox_gameResult.Text = ""; textBox_gameAddress.Text = ""; } else { this.Close(); } } else { MessageBox.Show("客队名字不能为空", "球队空", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } } else { MessageBox.Show("主队名字不能为空", "球队空", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } } else { MessageBox.Show("比赛序号超过赛事比赛总数", "比赛序号溢出", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } } } else { MessageBox.Show("比赛序号必须填数字", "序号非数字", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } } else { MessageBox.Show("比赛序号不能为空", "比赛序号空", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } } } else { MessageBox.Show("比赛名称不能为空", "比赛名称空", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } }
//初始显示窗体时,调用已经打开的赛事信息 private void showDataInfo(SeasonMatch match) { //读取赛事信息,并且在文本框中显示 textBox_matchName.Text = match.getName(); textBox_matchGameNum.Text = match.getSerialNum().ToString(); //获取已经存放的比赛的最大序号 int _maxGameNum = GameInfoDAO.getMatchMaxGameNum(match.getID()); textBox_gameNum.Text = (_maxGameNum + 1).ToString(); }
//显示数据方法 private void showData(SeasonMatch match) { textBox_name.Text = match.getName(); textBox_switchNum.Text = match.getSwitchNum().ToString(); textBox_serialNum.Text = match.getSerialNum().ToString(); richTextBox_description.Text = match.getDescription(); }
/// ///本类针对赛事信息的数据库处理 /// /* * 更新某一个赛事的信息 */ public static void updateMatchInfo(SeasonMatch match) { DBUtility dbutility = new DBUtility(); string sql = "update matchinfo set seasonName='"+match.getName()+"' ,description='"+match.getDescription(); sql = sql + "' ,switchNum=" + match.getSwitchNum() + " ,serialNum=" + match.getSerialNum(); sql = sql + " where ID=" + match.getID(); try { dbutility.openConnection(); dbutility.ExecuteUpdate(sql); } catch (MySqlException ex) { Console.WriteLine(ex.ToString()); } finally { dbutility.Close(); } }