private void showAlterTeamInfo(Team team) { textBox_teamName.Text = team.getName(); textBox_teamLeader.Text = team.getLeader(); textBox_teamManager.Text = team.getManager(); textBox_teamCoach.Text = team.getCoach(); }
//添加方法 private void addNewTeamRecord() { if (textBox_teamName.Text == "") { MessageBox.Show("球队名字不能是空","球队名字空",MessageBoxButtons.OKCancel,MessageBoxIcon.Information); } else { //检查球队名字是否已经存在 if (TeamInfoDAO.checkTeamNameExist(textBox_teamName.Text)) { MessageBox.Show("球队名字已经存在,请修改", "球队名字重复", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } else { Team _team = new Team(); _team.setMatchName(textBox_matchNameOfTeam.Text); _team.setName(textBox_teamName.Text); _team.setTeamFullName(textBox_teamFullName.Text); _team.setBirthDate(dateTimePicker_birthDate.Text); _team.setLocation(textBox_location.Text); _team.setIntroduction(textBox_location.Text); _team.setLeader(textBox_teamLeader.Text); _team.setManager(textBox_teamManager.Text); _team.setCoach(textBox_teamCoach.Text); //执行更新操作 if (TeamInfoDAO.addNewTeam(_team)) { if (MessageBox.Show("添加新球队成功,是否继续添加", "继续添加提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { //刷新管理球队界面数据信息 SystemParam.getTeamManageForm().showTeamData(); //清空文本框 this.clearTextBox(); } else { //刷新管理球队界面数据信息 SystemParam.getTeamManageForm().showTeamData(); this.Close(); //添加成功后自动关闭本页面 } } else { MessageBox.Show("添加新球队失败", "添加失败", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } } } }
//显示赛事的基本信息 public void showTeamData() { //先清除DataGridView中的数据 if (dataGridView_teamManage.Rows.Count > 0) { dataGridView_teamManage.Rows.Clear(); } //取出数据 List<Team> list =TeamInfoDAO.getTeamInfoOfCertainMatch(SystemParam.getMatch()); //往dataGridView中添加数据 for (int i = 0; i < list.Count; i++) { team = list[i]; //取出线性表中的赛事的信息 dataGridView_teamManage.Rows.Add(team.getID().ToString(), team.getName(),team.getTeamFullName(),team.getMatchName(), team.getLocation(),team.getBirthDate().ToString(),team.getIntroduction(),team.getLeader(),team.getManager(),team.getCoach()); } }
//往数据库中添加球队,返回是否添加成功的信息 public static bool addNewTeam(Team team) { DBUtility dbutility = new DBUtility(); string SQL = "insert into team(teamName,teamLeader,teamManager,teamCoach,teamFullName,birthDate,matchName,location,introduction) values('"; SQL = SQL + team.getName() + "','" + team.getLeader() + "','" + team.getManager() + "','" + team.getCoach() + "','" + team.getTeamFullName() + "','" + team.getBirthDate() + "','" + team.getMatchName() + "','" + team.getLocation()+ "','" + team.getIntroduction() + "')"; try { dbutility.openConnection(); dbutility.ExecuteUpdate(SQL); return true; } catch (MySqlException ex) { Console.WriteLine(ex.ToString()); return false; } finally { dbutility.Close(); } }
//获取球队信息 public static Team getTeamInfo(string teamName) { Team team = new Team(); //执行查询数据库操作 DBUtility dbutility = new DBUtility(); string SQL = "select ID,teamName,teamLeader,teamManager,teamCoach from player where teamName='" + teamName+"'"; try { dbutility.openConnection(); MySqlDataReader rd = dbutility.ExecuteQuery(SQL); while (rd.Read()) { team.setID(Convert.ToInt32(rd[0])); team.setName(Convert.ToString(rd[1])); team.setLeader(Convert.ToString(rd[2])); team.setManager(Convert.ToString(rd[3])); team.setCoach(Convert.ToString(rd[4])); } } catch (MySqlException ex) { Console.WriteLine(ex.ToString()); } finally { dbutility.Close(); } return team; }
//为下拉框绑定数据 private void bindComboData() { if (comboBox_teamName.Items.Count > 0) { comboBox_teamName.Items.Clear(); } else { List<Team> _teamList = TeamInfoDAO.getTeamInfoOfCertainMatch(SystemParam.getMatch()); Team _team = new Team(); comboBox_teamName.Items.Add(""); //添加一个空白字符串 for (int i = 0; i < _teamList.Count; i++) { _team = _teamList[i]; comboBox_teamName.Items.Add(_team.getName()); } } }
//显示未分配球队信息 private void showNotAssignedTeam() { if (dataGridView_NotAssiagnedTeam.Rows.Count > 0) //若已经有记录,先清除记录 { dataGridView_NotAssiagnedTeam.Rows.Clear(); } //显示数据操作 Team team = new Team(); //查询未被分配的球队信息,并且返回到一个线性表中 List<Team> list = MatchTeamInfoDAO.getNotAssignedMatchTeamInfo(SystemParam.getMatch().getID()); for (int i = 0; i < list.Count; i++) { team = list[i]; //取出球队信息 dataGridView_NotAssiagnedTeam.Rows.Add(team.getID().ToString(), team.getName(), team.getLeader(), team.getManager(), team.getCoach()); } }
private void button_saveTeam_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;//验证表格是否有空值 int isTheMatch = 0; List<Team> teamList = new List<Team>(); 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 ((this.dataGridView_ExcelImport.Rows[i].Cells[2].Value.ToString())!= SystemParam.getMatch().getName()) isTheMatch = 1; } } if (flag == 1) MessageBox.Show("当前表格有未填写的空格,请确认!"); else { if (isTheMatch == 1) { MessageBox.Show("您导入的表格中存在或者不是当前联赛的球队,请确认所属联赛是否是当前赛事!"); } else { for (int k = 0; k < rowNum; k++) { Team t = new Team(); //实例化一条球队记录,存放到list中 // t.setMatchName(SystemParam.getMatch().getName()); 此处要用来验证导入的表格是否都是属于这个联赛的 for (int l = 0; l < cellNum; l++) { switch (l) { case 0: t.setName(this.dataGridView_ExcelImport.Rows[k].Cells[l].Value.ToString()); break; case 1: t.setTeamFullName(this.dataGridView_ExcelImport.Rows[k].Cells[l].Value.ToString()); break; case 2: t.setMatchName(this.dataGridView_ExcelImport.Rows[k].Cells[l].Value.ToString()); break; case 3: t.setLocation(this.dataGridView_ExcelImport.Rows[k].Cells[l].Value.ToString()); break; case 4: t.setBirthDate(this.dataGridView_ExcelImport.Rows[k].Cells[l].Value.ToString()); break; case 5: t.setIntroduction(this.dataGridView_ExcelImport.Rows[k].Cells[l].Value.ToString()); break; case 6: t.setLeader(this.dataGridView_ExcelImport.Rows[k].Cells[l].Value.ToString()); break; case 7: t.setManager(this.dataGridView_ExcelImport.Rows[k].Cells[l].Value.ToString()); break; case 8: t.setCoach(this.dataGridView_ExcelImport.Rows[k].Cells[l].Value.ToString()); break; default: break; } } teamList.Add(t); } TeamInfoDAO.addNewTeamList(teamList); MessageBox.Show("插入数据成功!"); //清除已经提交的数据,如果设定的是数据源则源设置为空,不是用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 = ""; } //刷新球队管理界面 SystemParam.getTeamManageForm().showTeamData(); }//else表格不为空的 } } break; case DialogResult.No: break; } }
/* * 更新某一个球队的信息 */ public static bool updateTeamInfo(Team team) { DBUtility dbutility = new DBUtility(); string sql = "update team set teamName='" + team.getName() + "' ,teamLeader='" + team.getLeader(); sql = sql + "' ,teamManager='" + team.getManager() + "' ,teamCoach='" + team.getCoach(); sql = sql + "' where ID=" + team.getID(); try { dbutility.openConnection(); dbutility.ExecuteUpdate(sql); return true; } catch (MySqlException ex) { Console.WriteLine(ex.ToString()); return false; } finally { dbutility.Close(); } }
//查询特定赛事所属的球队 public static List<Team> getTeamInfoOfCertainMatch(SeasonMatch match) { //声明实例 List<Team> list = new List<Team>(); //执行查询数据库操作 DBUtility dbutility = new DBUtility(); // string SQL = "select ID,teamName,teamLeader,teamManager,teamCoach from team order by ID"; string SQL = "select * from team where matchName= '"+match.getName()+"' order by ID"; try { dbutility.openConnection(); MySqlDataReader rd = dbutility.ExecuteQuery(SQL); while (rd.Read()) { Team team = new Team(Convert.ToInt32(rd[0]), Convert.ToString(rd[1]), Convert.ToString(rd[2]), Convert.ToString(rd[3]), Convert.ToString(rd[4]), Convert.ToString(rd[5]), Convert.ToString(rd[6]), Convert.ToString(rd[7]), Convert.ToString(rd[8]), Convert.ToString(rd[9])); list.Add(team); } } catch (MySqlException ex) { Console.WriteLine(ex.ToString()); } finally { dbutility.Close(); } return list; }
private Team _team; //用于内部记录的球队信息 #endregion Fields #region Constructors public AlterTeam(Team team) { InitializeComponent(); this._team = team; }