Esempio n. 1
0
 //添加方法
 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);
             }
         }
     }
 }
Esempio n. 2
0
        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;
            }
        }