Beispiel #1
0
 ////////获取当前赛事的球队信息
 /*
 * 查询数据库中的球队的基本信息,并且返回到一个线性表中
 */
 public static List<Schedule> getScheduleInfo(SeasonOfMatch season)
 {
     //声明实例
     List<Schedule> list = new List<Schedule>();
     //执行查询数据库操作
     DBUtility dbutility = new DBUtility();
     string SQL = "select seasonId,matchId,turn,gameDate,homeTeamName,guestTeamName from schedule where seasonId= " + season.getNumOfSeason();
     try
     {
         dbutility.openConnection();
         MySqlDataReader rd = dbutility.ExecuteQuery(SQL);
         while (rd.Read())
         {
             Schedule s = new Schedule();
             s.setSeasonId(Convert.ToInt32(rd[0]));
             s.setMatchId(Convert.ToInt32(rd[1]));
             s.setTurn(Convert.ToInt32(rd[2]));
             s.setGameDate(Convert.ToString(rd[3]));
             s.setHomeTeam(Convert.ToString(rd[4]));
             s.setGuestTeam(Convert.ToString(rd[5]));
             list.Add(s);
         }
     }
     catch (MySqlException ex)
     {
         Console.WriteLine(ex.ToString());
     }
     finally
     {
         dbutility.Close();
     }
     return list;
 }
Beispiel #2
0
        //保存提交的数据到数据库并清空该表
        private void button_saveSchedule_Click(object sender, EventArgs e)
        {
            DialogResult RSS = MessageBox.Show(this, "确定要保存表单赛程吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            switch (RSS)
            {
                case DialogResult.Yes:
                    {
                        int rowNum = this.dataGridView1.Rows.Count-1;  //得到总列数,其中要除去新行
                        int cellNum = this.dataGridView1.Columns.Count;//得到总列数
                        int flag = 0;//验证表格是否有空值
                        List<Schedule> scheduleList = new List<Schedule>();
                        for (int i = 0; i < rowNum; i++)
                        {

                            for (int j = 0; j < cellNum; j++) {

                                if (this.dataGridView1.Rows[i].Cells[j].Value==null)
                                    flag = 1;
                            }
                         }
                        if (flag == 1)
                            MessageBox.Show("当前表格有未填写的空格,请确认!");
                        else {

                           for(int k=0;k<rowNum;k++ ){

                               Schedule s = new Schedule();  //实例化一条赛程记录,存放到list中
                               s.setMatchId(SystemParam.getMatch().getID());
                               s.setSeasonId(SystemParam.getCurrentSelectedSeason().getId());
                               for (int l = 0; l < cellNum;l++ ) {
                                   switch (l)
                                   {
                                       case 0:
                                           s.setTurn(Convert.ToInt32(this.dataGridView1.Rows[k].Cells[l].Value.ToString()));
                                           break;
                                       case 1:
                                           s.setGameDate(this.dataGridView1.Rows[k].Cells[l].Value.ToString());
                                           break;
                                       case 2:
                                         s.setHomeTeam(this.dataGridView1.Rows[k].Cells[l].Value.ToString()) ;
                                          break;
                                       case 3:
                                            s.setGuestTeam(this.dataGridView1.Rows[k].Cells[l].Value.ToString());
                                           break;
                                       default:
                                           break;
                                   }
                               }
                             scheduleList.Add(s);
                           }
                            ScheduleDAO.addSchedule(scheduleList);
                           MessageBox.Show("插入数据成功!");
                            //清楚已经提交的数据
                           this.dataGridView1.Rows.Clear();

                        }//else表格不为空的
                    }
                    break;
                case DialogResult.No:
                    break;
            }
        }
        private void button_saveSchedule_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 isTheTeam = 0;//验证表格中特定的两列是否是存在的球队,默认0是
                        int isHomeEqualsGuest = 0;  //验证表格中是否存在主队和客队一样的球队,默认0不等
                        List<Schedule> scheduleList = new List<Schedule>();
                        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()==this.dataGridView_ExcelImport.Rows[i].Cells[3].Value.ToString()){
                                     isHomeEqualsGuest=1;
                                 }
                                 if (checkIsTheTeam(this.dataGridView_ExcelImport.Rows[i].Cells[2].Value.ToString())||checkIsTheTeam(this.dataGridView_ExcelImport.Rows[i].Cells[3].Value.ToString()))
                                 { isTheTeam = 1; }
                        }
                        if (flag == 1)
                            MessageBox.Show("当前表格有未填写的空格,请确认!");
                        else
                        {
                            if (isTheTeam == 1) { MessageBox.Show("表格中球队存在不是该赛事的球队,请确认!"); }

                            else
                            {
                                if (isHomeEqualsGuest == 1) { MessageBox.Show("表格中球队存在主客队为同一球队,请确认!"); }

                                else
                                  {
                                for (int k = 0; k < rowNum; k++)
                                {

                                    Schedule s = new Schedule();  //实例化一条赛程记录,存放到list中
                                    s.setMatchId(8);
                                    s.setSeasonId(1);
                                    for (int l = 0; l < cellNum; l++)
                                    {
                                        switch (l)
                                        {
                                            case 0:
                                                s.setTurn(Convert.ToInt32(this.dataGridView_ExcelImport.Rows[k].Cells[l].Value.ToString()));
                                                break;
                                            case 1:
                                                s.setGameDate(this.dataGridView_ExcelImport.Rows[k].Cells[l].Value.ToString());
                                                break;
                                            case 2:
                                                s.setHomeTeam(this.dataGridView_ExcelImport.Rows[k].Cells[l].Value.ToString());
                                                break;
                                            case 3:
                                                s.setGuestTeam(this.dataGridView_ExcelImport.Rows[k].Cells[l].Value.ToString());
                                                break;
                                            default:
                                                break;
                                        }
                                    }
                                    scheduleList.Add(s);
                                }

                                ScheduleDAO.addSchedule(scheduleList);
                                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 = "";
                                }

                            } //表格中球队存在主客队为同一球队
                            }//球队存在不是该赛事的球队
                        }//else表格不为空的
                    }
                    break;
                case DialogResult.No:
                    break;
            }
        }