//双击表格行 private void dataGridView_playerManage_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex >= 0) { try { int playerID = Convert.ToInt32(dataGridView_playerManage.Rows[e.RowIndex].Cells["Player_ID"].Value); player = ContentDAO.getPlayerInfo(playerID); if (SystemParam.getAddPlayerCardRecordsForm() != null) //当该窗体已经打开时 { //刷新添加球员罚牌记录页面 SystemParam.getAddPlayerCardRecordsForm().flushPlayerName(player.getName()); } //关闭本页面 this.Close(); } catch (NullReferenceException ex) { Console.WriteLine(ex.ToString()); } } } catch { } }
public void loadDataOfDatagridView() { //先清除dataGridView中的数据 if (this.dataGridView_playerManage.Rows.Count > 0) { dataGridView_playerManage.Rows.Clear(); } //取出数据 List<FootballPlayer> list = ContentDAO.getPlayerInfoOfCertainTeam(selectedTeamName); for (int i = 0; i < list.Count;i++ ) { player = list[i]; dataGridView_playerManage.Rows.Add(player.getID(),player.getName(),player.getNumber(),player.getNumber().ToString(),player.getPostion(),player.getBelongTeam(),player.getIDnum()); } }
//往数据库中添加球员,返回是否添加成功的信息 public static bool addNewPlayer(FootballPlayer player) { DBUtility dbutility = new DBUtility(); string SQL = "insert into player(playerName,postion,teamName,number,playerIDnum) values('"; SQL = SQL + player.getName() + "','" + player.getPostion() + "','" + player.getBelongTeam() + "'," + player.getNumber() + ",'" +player.getIDnum() + "')"; try { dbutility.openConnection(); dbutility.ExecuteUpdate(SQL); return true; } catch (MySqlException ex) { Console.WriteLine(ex.ToString()); return false; } finally { dbutility.Close(); } }
private void alterPlayerInfo() { if (comboBox_teamName.Text == "") { MessageBox.Show("球队名称不能是空", "球队名称空", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } else { if (checkSwitchResult.checkStringSwitchInteger(textBox_teamLeader.Text)) //球员号码是数字 { FootballPlayer player = new FootballPlayer(); player = _player; //先给Player附一个初值 // player.setPlayerName(textBox_teamName.Text); player.setPlayNumber(Convert.ToInt32(textBox_teamLeader.Text)); player.setPostion(textBox_teamManager.Text); player.setBelongTeam(comboBox_teamName.Text); //执行更新操作 if (PlayerInfoDAO.updatePlayerInfo(player)) { MessageBox.Show("修改球员信息成功", "修改成功", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); //刷新管理球队界面数据信息 SystemParam.getPlayerManageForm().showCertainTeamPlayerData(); //关闭本页面 this.Close(); } else { MessageBox.Show("修改球员信息失败", "修改失败", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } } else { MessageBox.Show("球员号码必须是数字", "号码错误", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } } }
//显示赛事的基本信息 private void showPlayerData(SeasonMatch match) { //先清除DataGridView中的数据 if (dataGridView_playerManage.Rows.Count > 0) { dataGridView_playerManage.Rows.Clear(); } //取出数据 List<FootballPlayer> list = MatchPlayerInfoDAO.getAssignedPlayerInfo(match.getID()); //往dataGridView中添加数据 for (int i = 0; i < list.Count; i++) { player = list[i]; //取出线性表中的赛事的信息 dataGridView_playerManage.Rows.Add(player.getID().ToString(), player.getName(), player.getNumber().ToString(), player.getPostion(), player.getBelongTeam()); } }
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(); } } }
//依据球员的姓名,返回球员信息 public static FootballPlayer getPlayerInfo(string playerName) { FootballPlayer player = new FootballPlayer(); //执行查询数据库操作 DBUtility dbutility = new DBUtility(); string SQL = "select ID,playerName,number,postion,teamName from player where playerName='" + playerName+"'"; try { dbutility.openConnection(); MySqlDataReader rd = dbutility.ExecuteQuery(SQL); while (rd.Read()) { player.setPlayerID(Convert.ToInt32(rd[0])); player.setPlayerName(Convert.ToString(rd[1])); player.setPlayNumber(Convert.ToInt32(rd[2])); player.setPostion(Convert.ToString(rd[3])); player.setBelongTeam(Convert.ToString(rd[4])); } } catch (MySqlException ex) { Console.WriteLine(ex.ToString()); } finally { dbutility.Close(); } return player; }
//判断添加条件 private void addNewPlayerRecord() { if (textBox_teamName.Text == "") { MessageBox.Show("球员姓名不能是空", "球员姓名空", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } else { //检查球队名字是否已经存在 if (PlayerInfoDAO.checkPlayerNameExist(textBox_teamName.Text)) { MessageBox.Show("球员姓名已经存在,请修改", "球员姓名重复", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } else { if (comboBox_teamName.Text == "") { MessageBox.Show("球队名称不能是空", "球队名称空", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } else { if (textBox_IDnum.Text == "") { MessageBox.Show("身份证号不能是空", "身份证号码为空", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } else { if (checkSwitchResult.checkStringSwitchInteger(textBox_teamLeader.Text)) //球员号码是数字 { FootballPlayer _player = new FootballPlayer(); _player.setPlayerName(textBox_teamName.Text); _player.setPlayNumber(Convert.ToInt32(textBox_teamLeader.Text)); _player.setPostion(textBox_teamManager.Text); _player.setBelongTeam(comboBox_teamName.Text); _player.setIDnum(textBox_IDnum.Text); //执行更新操作 if (PlayerInfoDAO.addNewPlayer(_player)) { if (MessageBox.Show("添加新球员成功,是否继续添加", "继续添加提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { //刷新管理球队界面数据信息 SystemParam.getPlayerManageForm().showCertainTeamPlayerData(); //清空文本框 this.clearTextBox(); } else { //刷新管理球队界面数据信息 SystemParam.getPlayerManageForm().showCertainTeamPlayerData(); this.Close(); //添加成功后自动关闭本页面 } } else { MessageBox.Show("添加新球员失败", "添加失败", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } } else { MessageBox.Show("球员号码必须是数字", "号码错误", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } } } } } }
/* * 更新某一个赛事的信息 */ public static bool updatePlayerInfo(FootballPlayer player) { DBUtility dbutility = new DBUtility(); string sql = "update player set playerName='" + player.getName() + "',postion='" + player.getPostion()+ "' ,number=" + player.getNumber() +" ,teamName='" + player.getBelongTeam()+"' where ID =" + player.getID(); try { dbutility.openConnection(); dbutility.ExecuteUpdate(sql); return true; } catch (MySqlException ex) { Console.WriteLine(ex.ToString()); return false; } finally { dbutility.Close(); } }
private FootballPlayer _player; //用来记录被修改的球员信息 #endregion Fields #region Constructors public AlterPlayer(FootballPlayer player) { InitializeComponent(); this._player = player; }
private void showAlterPlayerInfo(FootballPlayer player) { textBox_teamName.Text = player.getName(); textBox_teamLeader.Text = player.getNumber().ToString(); textBox_teamManager.Text = player.getPostion(); comboBox_teamName.Text = player.getBelongTeam(); }
private void button_savePlayerInfo_Click(object sender, EventArgs e) { DialogResult RSS = MessageBox.Show(this, "确定要保存表单球员信息吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); switch (RSS) { case DialogResult.Yes: { int rowNum = this.dataGridView_ExcelImport.Rows.Count - 1; //得到总列数,其中要除去新行 int cellNum = this.dataGridView_ExcelImport.Columns.Count;//得到总列数 int flag = 0;//验证表格是否有空值 List<FootballPlayer> playerlList = new List<FootballPlayer>(); for (int i = 0; i < rowNum; i++) { for (int j = 0; j < cellNum; j++) { if (this.dataGridView_ExcelImport.Rows[i].Cells[j].Value == null) flag = 1; } } if (flag == 1) MessageBox.Show("当前表格有未填写的空格,请确认!"); else { for (int k = 0; k < rowNum; k++) { FootballPlayer player = new FootballPlayer(); //实例化一条赛程记录,存放到list中 for (int l = 0; l < cellNum; l++) { switch (l) { case 0: player.setPlayerName(this.dataGridView_ExcelImport.Rows[k].Cells[l].Value.ToString()); break; case 1: player.setPlayNumber(Convert.ToInt32(this.dataGridView_ExcelImport.Rows[k].Cells[l].Value.ToString())); break; case 2: player.setPostion(this.dataGridView_ExcelImport.Rows[k].Cells[l].Value.ToString()); break; case 3: player.setBelongTeam(this.dataGridView_ExcelImport.Rows[k].Cells[l].Value.ToString()); break; case 4: player.setIDnum(this.dataGridView_ExcelImport.Rows[k].Cells[l].Value.ToString()); break; default: break; } } playerlList.Add(player); } PlayerInfoDAO.addPlayerList(playerlList); MessageBox.Show("插入数据成功!"); SystemParam.getPlayerManageForm().loadDataOfDatagridView(); //清除已经提交的数据,如果设定的是数据源则源设置为空,不是用clear()方法清除 if (this.dataGridView_ExcelImport.DataSource != null) { this.dataGridView_ExcelImport.DataSource = null; this.textBox_fileName.Text = ""; } else { this.dataGridView_ExcelImport.Rows.Clear(); this.textBox_fileName.Text = ""; } }//else表格不为空的 } break; case DialogResult.No: break; } }
//显示未分配球队信息 private void showNotAssignedPlayer() { if (dataGridView_notAssignedPlayer.Rows.Count > 0) //若已经有记录,先清除记录 { dataGridView_notAssignedPlayer.Rows.Clear(); } //取出数据 List<FootballPlayer> list = MatchPlayerInfoDAO.getNotAssignedPlayerInfo(SystemParam.getMatch().getID()); //声明实例 FootballPlayer player = new FootballPlayer(); //往dataGridView中添加数据 for (int i = 0; i < list.Count; i++) { player = list[i]; //取出线性表中的赛事的信息 dataGridView_notAssignedPlayer.Rows.Add(player.getID().ToString(), player.getName(), player.getNumber().ToString(), player.getPostion(), player.getBelongTeam()); } }