Esempio n. 1
0
    protected void cmdOverwrite_Click(object sender, EventArgs e)
    {
        panAlert.Visible         = true;
        panDatabaseAlert.Visible = false;

        DatabaseMgr dm        = new DatabaseMgr();
        bool        didDelete = dm.DeleteMeet(meetID);

        if (didDelete)
        {
            bool didAdd = dm.AddMeet(newMeet, Session["Username"].ToString());
            if (didAdd)
            {
                Session["ActiveMeet"] = newMeet;

                //Open MeetHub here
                Response.Redirect("MeetHub.aspx");
            }
            else
            {
                lblAlert.Text = "Meet deleted from database, but error adding new database entry";
            }
        }
        else
        {
            lblAlert.Text = "Error deleting existing meet from database";
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Performance myPerformance1 = new Performance("A", "AA", 1.1m);
        Performance myPerformance2 = new Performance("B", "BB", 2.2m);
        Performance myPerformance3 = new Performance("C", "CC", 3.3m);
        Performance myPerformance4 = new Performance("D", "AA", 4.1m);
        Performance myPerformance5 = new Performance("E", "BB", 5.2m);
        Performance myPerformance6 = new Performance("F", "CC", 6.3m);

        List <Performance> myPerformancesA = new List <Performance>();

        myPerformancesA.Add(myPerformance1);
        myPerformancesA.Add(myPerformance2);
        myPerformancesA.Add(myPerformance3);

        List <Performance> myPerformancesB = new List <Performance>();

        myPerformancesB.Add(myPerformance4);
        myPerformancesB.Add(myPerformance5);
        myPerformancesB.Add(myPerformance6);

        Dictionary <string, List <Performance> > myPerformances = new Dictionary <string, List <Performance> >();

        myPerformances.Add("Boy's 100", myPerformancesA);
        myPerformances.Add("Boy's 200", myPerformancesB);

        Dictionary <string, string> boysNames = new Dictionary <string, string>();

        boysNames.Add("BLN", "Baldwin");
        boysNames.Add("TJ", "Thomas Jefferson");
        boysNames.Add("WHS", "Washington HS");

        Dictionary <string, string> girlsNames = new Dictionary <string, string>();

        girlsNames.Add("PLM", "Plum");
        girlsNames.Add("GWY", "Gateway");
        girlsNames.Add("KCH", "Knoch");

        Teams teams = new Teams(boysNames, girlsNames);

        Meet myMeetNoEvents = new Meet(new DateTime(2017, 04, 13), "Baldwin HS", "Windy", teams, myPerformances);

        DatabaseMgr dbm = new DatabaseMgr();

        dbm.AddMeet(myMeetNoEvents, "NoUsername");

        /*TableRow meetRow = new TableRow();
         * tblMeets.Rows.Add(meetRow);
         *
         * TableCell idCell = new TableCell();
         * idCell.Text = "1";
         * meetRow.Cells.Add(idCell);
         *
         * TableCell dateOfMeetCell = new TableCell();
         * dateOfMeetCell.Text = myMeetNoEvents.dateOfMeet.ToString();
         * meetRow.Cells.Add(dateOfMeetCell);
         *
         * TableCell locationCell = new TableCell();
         * locationCell.Text = myMeetNoEvents.location;
         * meetRow.Cells.Add(locationCell);
         *
         * TableCell weatherCell = new TableCell();
         * weatherCell.Text = myMeetNoEvents.weatherConditions;
         * meetRow.Cells.Add(weatherCell);
         *
         * for (int i = 0; i < myMeetNoEvents.schoolNames.boySchoolNames.Count; i++)
         * {
         *  TableRow boysRow = new TableRow();
         *  tblBoysTeams.Rows.Add(boysRow);
         *
         *  TableCell boysId = new TableCell();
         *  boysId.Text = (i + 1).ToString();
         *  boysRow.Cells.Add(boysId);
         *
         *  TableCell abbrCell = new TableCell();
         *  abbrCell.Text = myMeetNoEvents.schoolNames.boySchoolNames.ElementAt(i).Key;
         *  boysRow.Cells.Add(abbrCell);
         *
         *  TableCell tNameCell = new TableCell();
         *  tNameCell.Text = myMeetNoEvents.schoolNames.boySchoolNames.ElementAt(i).Value;
         *  boysRow.Cells.Add(tNameCell);
         *
         *  TableCell meetKeyBoys = new TableCell();
         *  meetKeyBoys.Text = idCell.Text;
         *  boysRow.Cells.Add(meetKeyBoys);
         * }
         *
         * for (int i = 0; i < myMeetNoEvents.schoolNames.girlSchoolNames.Count; i++)
         * {
         *  TableRow girlsRow = new TableRow();
         *  tblGirlsTeams.Rows.Add(girlsRow);
         *
         *  TableCell girlsId = new TableCell();
         *  girlsId.Text = (i + 1).ToString();
         *  girlsRow.Cells.Add(girlsId);
         *
         *  TableCell abbrCell = new TableCell();
         *  abbrCell.Text = myMeetNoEvents.schoolNames.girlSchoolNames.ElementAt(i).Key;
         *  girlsRow.Cells.Add(abbrCell);
         *
         *  TableCell tNameCell = new TableCell();
         *  tNameCell.Text = myMeetNoEvents.schoolNames.girlSchoolNames.ElementAt(i).Value;
         *  girlsRow.Cells.Add(tNameCell);
         *
         *  TableCell meetKeygirls = new TableCell();
         *  meetKeygirls.Text = idCell.Text;
         *  girlsRow.Cells.Add(meetKeygirls);
         * }
         *
         * if (myMeetNoEvents != null && myMeetNoEvents.performances != null)
         * {
         *  foreach (string eventName in myMeetNoEvents.performances.Keys)
         *
         *  //for (int i = 0; i < myMeetNoEvents.performances.Keys; i++)
         *  {
         *      foreach (Performance perf in myMeetNoEvents.performances[eventName])
         *      {
         *          TableRow perfRow = new TableRow();
         *          tblPerformances.Rows.Add(perfRow);
         *
         *          TableCell perfId = new TableCell();
         *          perfId.Text = (100).ToString();
         *          perfRow.Cells.Add(perfId);
         *
         *          TableCell athleteCell = new TableCell();
         *          athleteCell.Text = perf.athleteName;
         *          perfRow.Cells.Add(athleteCell);
         *
         *          TableCell tNameCell = new TableCell();
         *          tNameCell.Text = perf.schoolName;
         *          perfRow.Cells.Add(tNameCell);
         *
         *          TableCell genderCell = new TableCell();
         *          if (eventName.ToUpper().Contains("BOY"))
         *          {
         *              genderCell.Text = "Boy's";
         *          }
         *          else if (eventName.ToUpper().Contains("GIRL"))
         *          {
         *              genderCell.Text = "Girl's";
         *          }
         *          else
         *          {
         *              genderCell.Text = "";
         *          }
         *          perfRow.Cells.Add(genderCell);
         *
         *          TableCell eventCell = new TableCell();
         *          eventCell.Text = eventName;
         *          perfRow.Cells.Add(eventCell);
         *
         *          TableCell heatCell = new TableCell();
         *          heatCell.Text = perf.heatNum.ToString();
         *          perfRow.Cells.Add(heatCell);
         *
         *          TableCell perfCell = new TableCell();
         *          perfCell.Text = perf.performance.ToString();
         *          perfRow.Cells.Add(perfCell);
         *
         *          TableCell meetKeyPerf = new TableCell();
         *          meetKeyPerf.Text = idCell.Text;
         *          perfRow.Cells.Add(meetKeyPerf);
         *
         *      }
         *  }
         * }*/
    }
Esempio n. 3
0
    protected void cmdCreate_Click(object sender, EventArgs e)
    {
        panAlert.Visible = true;
        if (txtLocation.Text == "")
        {
            lblAlert.Text = "Please enter a location";
        }
        else if (txtWeather.Text == "")
        {
            lblAlert.Text = "Please enter weather conditions";
        }
        else if (string.IsNullOrWhiteSpace(txtBoysTeam1.Text) || string.IsNullOrWhiteSpace(txtBoysAbbr1.Text))
        {
            lblAlert.Text = "Please enter team name information for boy's team #1";
        }
        else if ((string.IsNullOrWhiteSpace(txtBoysTeam2.Text) && !string.IsNullOrWhiteSpace(txtBoysAbbr2.Text)) || (!string.IsNullOrWhiteSpace(txtBoysTeam2.Text) && string.IsNullOrWhiteSpace(txtBoysAbbr2.Text)))
        {
            lblAlert.Text = "Invalid name information for boy's team #2";
        }
        else if ((string.IsNullOrWhiteSpace(txtBoysTeam3.Text) && !string.IsNullOrWhiteSpace(txtBoysAbbr3.Text)) || (!string.IsNullOrWhiteSpace(txtBoysTeam3.Text) && string.IsNullOrWhiteSpace(txtBoysAbbr3.Text)))
        {
            lblAlert.Text = "Invalid name information for boy's team #3";
        }
        else if ((string.IsNullOrWhiteSpace(txtBoysTeam4.Text) && !string.IsNullOrWhiteSpace(txtBoysAbbr4.Text)) || (!string.IsNullOrWhiteSpace(txtBoysTeam4.Text) && string.IsNullOrWhiteSpace(txtBoysAbbr4.Text)))
        {
            lblAlert.Text = "Invalid name information for boy's team #4";
        }
        else if ((string.IsNullOrWhiteSpace(txtBoysTeam5.Text) && !string.IsNullOrWhiteSpace(txtBoysAbbr5.Text)) || (!string.IsNullOrWhiteSpace(txtBoysTeam5.Text) && string.IsNullOrWhiteSpace(txtBoysAbbr5.Text)))
        {
            lblAlert.Text = "Invalid name information for boy's team #5";
        }
        else if ((string.IsNullOrWhiteSpace(txtBoysTeam6.Text) && !string.IsNullOrWhiteSpace(txtBoysAbbr6.Text)) || (!string.IsNullOrWhiteSpace(txtBoysTeam6.Text) && string.IsNullOrWhiteSpace(txtBoysAbbr6.Text)))
        {
            lblAlert.Text = "Invalid name information for boy's team #6";
        }
        else if (string.IsNullOrWhiteSpace(txtGirlsTeam1.Text) || string.IsNullOrWhiteSpace(txtGirlsAbbr1.Text))
        {
            lblAlert.Text = "Please enter team name information for girl's team #1";
        }
        else if ((string.IsNullOrWhiteSpace(txtGirlsTeam2.Text) && !string.IsNullOrWhiteSpace(txtGirlsAbbr2.Text)) || (!string.IsNullOrWhiteSpace(txtGirlsTeam2.Text) && string.IsNullOrWhiteSpace(txtGirlsAbbr2.Text)))
        {
            lblAlert.Text = "Invalid name information for girl's team #2";
        }
        else if ((string.IsNullOrWhiteSpace(txtGirlsTeam3.Text) && !string.IsNullOrWhiteSpace(txtGirlsAbbr3.Text)) || (!string.IsNullOrWhiteSpace(txtGirlsTeam3.Text) && string.IsNullOrWhiteSpace(txtGirlsAbbr3.Text)))
        {
            lblAlert.Text = "Invalid name information for girl's team #3";
        }
        else if ((string.IsNullOrWhiteSpace(txtGirlsTeam4.Text) && !string.IsNullOrWhiteSpace(txtGirlsAbbr4.Text)) || (!string.IsNullOrWhiteSpace(txtGirlsTeam4.Text) && string.IsNullOrWhiteSpace(txtGirlsAbbr4.Text)))
        {
            lblAlert.Text = "Invalid name information for girl's team #4";
        }
        else if ((string.IsNullOrWhiteSpace(txtGirlsTeam5.Text) && !string.IsNullOrWhiteSpace(txtGirlsAbbr5.Text)) || (!string.IsNullOrWhiteSpace(txtGirlsTeam5.Text) && string.IsNullOrWhiteSpace(txtGirlsAbbr5.Text)))
        {
            lblAlert.Text = "Invalid name information for girl's team #5";
        }
        else if ((string.IsNullOrWhiteSpace(txtGirlsTeam6.Text) && !string.IsNullOrWhiteSpace(txtGirlsAbbr6.Text)) || (!string.IsNullOrWhiteSpace(txtGirlsTeam6.Text) && string.IsNullOrWhiteSpace(txtGirlsAbbr6.Text)))
        {
            lblAlert.Text = "Invalid name information for girl's team #6";
        }
        else
        {
            string meetLocation = txtLocation.Text;

            int month = 1;
            if (ddlMonth.Text == "February")
            {
                month = 2;
            }
            else if (ddlMonth.Text == "March")
            {
                month = 3;
            }
            else if (ddlMonth.Text == "April")
            {
                month = 4;
            }
            else if (ddlMonth.Text == "May")
            {
                month = 5;
            }
            else if (ddlMonth.Text == "June")
            {
                month = 6;
            }
            else if (ddlMonth.Text == "July")
            {
                month = 7;
            }
            else if (ddlMonth.Text == "August")
            {
                month = 8;
            }
            else if (ddlMonth.Text == "September")
            {
                month = 9;
            }
            else if (ddlMonth.Text == "October")
            {
                month = 10;
            }
            else if (ddlMonth.Text == "November")
            {
                month = 11;
            }
            else if (ddlMonth.Text == "December")
            {
                month = 12;
            }

            DateTime meetDateTime   = new DateTime(Convert.ToInt32(ddlYear.Text), month, Convert.ToInt32(ddlDay.Text));
            string   meetWeather    = txtWeather.Text;
            string   boysTeam1Abbr  = txtBoysAbbr1.Text.Trim();
            string   boysTeam1Name  = txtBoysTeam1.Text.Trim();
            string   boysTeam2Abbr  = txtBoysAbbr2.Text.Trim();
            string   boysTeam2Name  = txtBoysTeam2.Text.Trim();
            string   boysTeam3Abbr  = txtBoysAbbr3.Text.Trim();
            string   boysTeam3Name  = txtBoysTeam3.Text.Trim();
            string   boysTeam4Abbr  = txtBoysAbbr4.Text.Trim();
            string   boysTeam4Name  = txtBoysTeam4.Text.Trim();
            string   boysTeam5Abbr  = txtBoysAbbr5.Text.Trim();
            string   boysTeam5Name  = txtBoysTeam5.Text.Trim();
            string   boysTeam6Abbr  = txtBoysAbbr6.Text.Trim();
            string   boysTeam6Name  = txtBoysTeam6.Text.Trim();
            string   girlsTeam1Abbr = txtGirlsAbbr1.Text.Trim();
            string   girlsTeam1Name = txtGirlsTeam1.Text.Trim();
            string   girlsTeam2Abbr = txtGirlsAbbr2.Text.Trim();
            string   girlsTeam2Name = txtGirlsTeam2.Text.Trim();
            string   girlsTeam3Abbr = txtGirlsAbbr3.Text.Trim();
            string   girlsTeam3Name = txtGirlsTeam3.Text.Trim();
            string   girlsTeam4Abbr = txtGirlsAbbr4.Text.Trim();
            string   girlsTeam4Name = txtGirlsTeam4.Text.Trim();
            string   girlsTeam5Abbr = txtGirlsAbbr5.Text.Trim();
            string   girlsTeam5Name = txtGirlsTeam5.Text.Trim();
            string   girlsTeam6Abbr = txtGirlsAbbr6.Text.Trim();
            string   girlsTeam6Name = txtGirlsTeam6.Text.Trim();

            List <string> boysNames = new List <string>();
            if (!string.IsNullOrWhiteSpace(boysTeam1Name))
            {
                boysNames.Add(boysTeam1Name);
            }
            if (!string.IsNullOrWhiteSpace(boysTeam2Name))
            {
                boysNames.Add(boysTeam2Name);
            }
            if (!string.IsNullOrWhiteSpace(boysTeam3Name))
            {
                boysNames.Add(boysTeam3Name);
            }
            if (!string.IsNullOrWhiteSpace(boysTeam4Name))
            {
                boysNames.Add(boysTeam4Name);
            }
            if (!string.IsNullOrWhiteSpace(boysTeam5Name))
            {
                boysNames.Add(boysTeam5Name);
            }
            if (!string.IsNullOrWhiteSpace(boysTeam6Name))
            {
                boysNames.Add(boysTeam6Name);
            }

            List <string> boysAbbrs = new List <string>();
            if (!string.IsNullOrWhiteSpace(boysTeam1Abbr))
            {
                boysAbbrs.Add(boysTeam1Abbr);
            }
            if (!string.IsNullOrWhiteSpace(boysTeam2Abbr))
            {
                boysAbbrs.Add(boysTeam2Abbr);
            }
            if (!string.IsNullOrWhiteSpace(boysTeam3Abbr))
            {
                boysAbbrs.Add(boysTeam3Abbr);
            }
            if (!string.IsNullOrWhiteSpace(boysTeam4Abbr))
            {
                boysAbbrs.Add(boysTeam4Abbr);
            }
            if (!string.IsNullOrWhiteSpace(boysTeam5Abbr))
            {
                boysAbbrs.Add(boysTeam5Abbr);
            }
            if (!string.IsNullOrWhiteSpace(boysTeam6Abbr))
            {
                boysAbbrs.Add(boysTeam6Abbr);
            }

            List <string> girlsNames = new List <string>();
            if (!string.IsNullOrWhiteSpace(girlsTeam1Name))
            {
                girlsNames.Add(girlsTeam1Name);
            }
            if (!string.IsNullOrWhiteSpace(girlsTeam2Name))
            {
                girlsNames.Add(girlsTeam2Name);
            }
            if (!string.IsNullOrWhiteSpace(girlsTeam3Name))
            {
                girlsNames.Add(girlsTeam3Name);
            }
            if (!string.IsNullOrWhiteSpace(girlsTeam4Name))
            {
                girlsNames.Add(girlsTeam4Name);
            }
            if (!string.IsNullOrWhiteSpace(girlsTeam5Name))
            {
                girlsNames.Add(girlsTeam5Name);
            }
            if (!string.IsNullOrWhiteSpace(girlsTeam6Name))
            {
                girlsNames.Add(girlsTeam6Name);
            }

            List <string> girlsAbbrs = new List <string>();
            if (!string.IsNullOrWhiteSpace(girlsTeam1Abbr))
            {
                girlsAbbrs.Add(girlsTeam1Abbr);
            }
            if (!string.IsNullOrWhiteSpace(girlsTeam2Abbr))
            {
                girlsAbbrs.Add(girlsTeam2Abbr);
            }
            if (!string.IsNullOrWhiteSpace(girlsTeam3Abbr))
            {
                girlsAbbrs.Add(girlsTeam3Abbr);
            }
            if (!string.IsNullOrWhiteSpace(girlsTeam4Abbr))
            {
                girlsAbbrs.Add(girlsTeam4Abbr);
            }
            if (!string.IsNullOrWhiteSpace(girlsTeam5Abbr))
            {
                girlsAbbrs.Add(girlsTeam5Abbr);
            }
            if (!string.IsNullOrWhiteSpace(girlsTeam6Abbr))
            {
                girlsAbbrs.Add(girlsTeam6Abbr);
            }

            if (boysNames.Distinct().Count() != boysNames.Count())
            {
                lblAlert.Text = "All Boy's names must be unique";
            }
            else if (boysAbbrs.Distinct().Count() != boysAbbrs.Count())
            {
                lblAlert.Text = "All Boy's abbrs must be unique";
            }
            else if (girlsNames.Distinct().Count() != girlsNames.Count())
            {
                lblAlert.Text = "All Girl's names must be unique";
            }
            else if (girlsAbbrs.Distinct().Count() != girlsAbbrs.Count())
            {
                lblAlert.Text = "All Girl's abbrs must be unique";
            }
            else
            {
                Dictionary <string, string> boysTeams = new Dictionary <string, string>();
                boysTeams.Add(boysTeam1Abbr, boysTeam1Name);
                if (!string.IsNullOrWhiteSpace(boysTeam2Abbr))
                {
                    boysTeams.Add(boysTeam2Abbr, boysTeam2Name);
                }
                if (!string.IsNullOrWhiteSpace(boysTeam3Abbr))
                {
                    boysTeams.Add(boysTeam3Abbr, boysTeam3Name);
                }
                if (!string.IsNullOrWhiteSpace(boysTeam4Abbr))
                {
                    boysTeams.Add(boysTeam4Abbr, boysTeam4Name);
                }
                if (!string.IsNullOrWhiteSpace(boysTeam5Abbr))
                {
                    boysTeams.Add(boysTeam5Abbr, boysTeam5Name);
                }
                if (!string.IsNullOrWhiteSpace(boysTeam6Abbr))
                {
                    boysTeams.Add(boysTeam6Abbr, boysTeam6Name);
                }

                Dictionary <string, string> girlsTeams = new Dictionary <string, string>();
                girlsTeams.Add(girlsTeam1Abbr, girlsTeam1Name);
                if (!string.IsNullOrWhiteSpace(girlsTeam2Abbr))
                {
                    girlsTeams.Add(girlsTeam2Abbr, girlsTeam2Name);
                }
                if (!string.IsNullOrWhiteSpace(girlsTeam3Abbr))
                {
                    girlsTeams.Add(girlsTeam3Abbr, girlsTeam3Name);
                }
                if (!string.IsNullOrWhiteSpace(girlsTeam4Abbr))
                {
                    girlsTeams.Add(girlsTeam4Abbr, girlsTeam4Name);
                }
                if (!string.IsNullOrWhiteSpace(girlsTeam5Abbr))
                {
                    girlsTeams.Add(girlsTeam5Abbr, girlsTeam5Name);
                }
                if (!string.IsNullOrWhiteSpace(girlsTeam6Abbr))
                {
                    girlsTeams.Add(girlsTeam6Abbr, girlsTeam6Name);
                }

                Teams newTeams = new Teams(boysTeams, girlsTeams);

                newMeet = new Meet(meetDateTime, meetLocation, meetWeather, newTeams);

                if (newMeet.validate())
                {
                    DatabaseMgr dm = new DatabaseMgr();
                    meetID = dm.FindMeetId(newMeet);

                    if (meetID < 0)
                    {
                        panAlert.GroupingText = "Problem loading meet database. Please try again later";
                    }
                    else
                    {
                        if (meetID == 0) //Meet does not exist in database
                        {
                            bool didAdd = dm.AddMeet(newMeet, Session["Username"].ToString());
                            if (didAdd)
                            {
                                Session["ActiveMeet"] = newMeet;

                                //Open MeetHub here
                                Response.Redirect("MeetHub.aspx");
                            }
                            else
                            {
                                lblAlert.Text = "Problem addign meet to database, please try again later";
                            }
                        }
                        else
                        {
                            panAlert.Visible         = false;
                            panDatabaseAlert.Visible = true;

                            lblDatabaseAlert.Text = "Meet already exists, do you wish to overwrite existing meet, or open existing meet?";
                            cmdCreate.Visible     = false;
                        }
                    }
                }
                else
                {
                    lblAlert.Text = "Unknown problem creating this meet. Data was invalid.";
                }
            }
        }
    }