示例#1
0
 //依据球员的姓名,返回球员信息
 public static FootballPlayer getPlayerInfo(string playerName)
 {
     FootballPlayer player = new FootballPlayer();
     //执行查询数据库操作
     DBUtility dbutility = new DBUtility();
     string SQL = "select ID,playerName,number,postion,teamName,playerIDnum 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]));
             player.setIDnum(Convert.ToString(rd[5]));
         }
     }
     catch (MySqlException ex)
     {
         Console.WriteLine(ex.ToString());
     }
     finally
     {
         dbutility.Close();
     }
     return player;
 }
示例#2
0
        //判断添加条件
        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);
                        }
                    } }
                }
            }
        }
        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;
            }
        }