示例#1
0
        /**
         * <summary>
         * This event handler deletes a game from the db using EF
         * </summary>
         *
         * @method gdTeams_RowDeleting
         * @param {object} sender
         * @param {GridViewDeleteEventArgs} e
         * @returns {void}
         */
        protected void gdTeams_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            // store which row was clicked
            int selectRow = e.RowIndex;

            //GET TID From selected row
            int TID = Convert.ToInt32(gdTeams.DataKeys[selectRow].Values["TID"]);

            // use EF to find the selected team in the DB and remove it
            using (DefaultConnectionGM db = new DefaultConnectionGM())
            {
                // create object of the team class and store the query string inside of it
                Models.Team deletedTeam = (from teamRecords in db.Teams
                                           where teamRecords.TID == TID
                                           select teamRecords).FirstOrDefault();

                // remove the selected game from the db
                db.Teams.Remove(deletedTeam);

                // save my changes back to the database
                db.SaveChanges();
                Session["TeamMsg"] = "Your Record Deleted Succeessfully.";
                // refresh the grid
                this.GetTeams();
                getMessage();
            }
        }
示例#2
0
        /**
         * <summary>
         * This event handler deletes a game from the db using EF
         * </summary>
         *
         * @method gdGames_RowDeleting
         * @param {object} sender
         * @param {GridViewDeleteEventArgs} e
         * @returns {void}
         */
        protected void gdGames_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            // store which row was clicked
            int selectedRow = e.RowIndex;

            // get the selected GID using the Grid's DataKey collection
            int GID = Convert.ToInt32(gdGames.DataKeys[selectedRow].Values["GID"]);

            // use EF to find the selected game in the DB and remove it
            using (DefaultConnectionGM db = new DefaultConnectionGM())
            {
                // create object of the Game class and store the query string inside of it
                Models.Game deletedGame = (from gameRecords in db.Games
                                           where gameRecords.GID == GID
                                           select gameRecords).FirstOrDefault();

                // remove the selected game from the db
                db.Games.Remove(deletedGame);

                // save my changes back to the database
                db.SaveChanges();
                Session["GameMsg"] = "Your Record Deleted Succeessfully.";
                // refresh the grid
                this.GetGames();
                getMessage();
            }
        }
        private void GetTeam()
        {
            try
            {
                //populate form with existing data
                int TID = Convert.ToInt32(Request.QueryString["TeamID"].ToString());

                //connect to EF DB
                using (DefaultConnectionGM db = new DefaultConnectionGM())
                {
                    // populate a team object instance with the TID from the URL Parameter
                    var Team = (from team in db.Teams
                                where team.TID == TID
                                select team).FirstOrDefault();
                    // map the team properties to the form controls
                    if (Team != null)
                    {
                        txtTeamName.Text          = Team.Name;
                        txtshortdesc.Text         = Team.Description;
                        ddlGameName.SelectedValue = Team.Gid.ToString();
                        btnsubmit.Text            = "Update";
                    }
                }
            }
            catch (Exception e)
            {
            }
        }
        private void GetGame()
        {
            try
            {
                // populate teh form with existing data from the database
                int GID = Convert.ToInt32(Request.QueryString["GID"]);

                // connect to the EF DB
                using (DefaultConnectionGM db = new DefaultConnectionGM())
                {
                    // populate a game object instance with the GID from the URL Parameter
                    Models.Game updatedStudent = (from game in db.Games
                                                  where game.GID == GID
                                                  select game).FirstOrDefault();

                    // map the student properties to the form controls
                    if (updatedStudent != null)
                    {
                        txtGameName.Text  = updatedStudent.Name;
                        txtshortdesc.Text = updatedStudent.Description;
                        btnsubmit.Text    = "Update";
                    }
                }
            }
            catch (Exception e)
            {
            }
        }
示例#5
0
        /**
         * <summary>
         * This method check if record already have in table.
         * </summary>
         *
         * @method checkAlready
         * @returns {int}
         */
        private int checkAlready(Models.GameRecord newGameRecord)
        {
            int rowCount = 0;

            try {
                using (DefaultConnectionGM db = new DefaultConnectionGM())
                {
                    //write query
                    var recordAlready = (from record in db.GameRecords
                                         where record.Date == newGameRecord.Date &&
                                         record.Gid == newGameRecord.Gid &&
                                         record.Team1 == newGameRecord.Team1 &&
                                         record.Team2 == newGameRecord.Team2 &&
                                         record.WTeam == newGameRecord.WTeam
                                         select record).First();
                    if (recordAlready != null)
                    {
                        rowCount = 1;
                    }
                }
            }
            catch (Exception e)
            { }
            return(rowCount);
        }
示例#6
0
        /**
         * <summary>
         * This method gets teams from DB and bind to dropdown
         * </summary>
         *
         * @method ddlTeamData
         * @parameters {GID}
         * @returns {void}
         */
        private void ddlTeamData(int GID)
        {
            try {
                //connect to database
                using (DefaultConnectionGM db = new DefaultConnectionGM()) {
                    //write query
                    var TeamRecords = (from records in db.Teams
                                       where records.Gid == GID
                                       select new { records.Name, records.TID }).ToList();

                    //bind data in team1 drop down
                    ddlTeamName1.DataTextField  = "Name";
                    ddlTeamName1.DataValueField = "TID";
                    ddlTeamName1.DataSource     = TeamRecords;
                    ddlTeamName1.DataBind();
                    ddlTeamName1.Enabled = true;
                    //first item
                    ddlTeamName1.Items.Insert(0, new ListItem("Select Team", "0"));

                    //bind data in team2 drop down
                    ddlTeamName2.DataTextField  = "Name";
                    ddlTeamName2.DataValueField = "TID";
                    ddlTeamName2.DataSource     = TeamRecords;
                    ddlTeamName2.DataBind();


                    //first item
                    ddlTeamName2.Items.Insert(0, new ListItem("Select Team", "0"));
                }
            }
            catch (Exception e) { }
        }
示例#7
0
        /**
         * <summary>
         * This method gets the games data from the DB
         * </summary>
         *
         * @method GetGames
         * @returns {void}
         */
        protected void GetGames()
        {
            // connect to EF
            using (DefaultConnectionGM db = new DefaultConnectionGM())
            {
                string SortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                // query the Games Table using EF and LINQ
                var Games = (from allGames in db.Games
                             select allGames);

                // bind the result to the GridView
                gdGames.DataSource = Games.AsQueryable().OrderBy(SortString).ToList();

                gdGames.DataBind();
            }
        }
示例#8
0
        /**
         * <summary>
         * This event handler Shows pop-up box with game name and description
         * </summary>
         *
         * @method lbGame_Click
         * @param {object} sender
         * @param {EventArgs} e
         * @returns {void}
         */
        protected void lbGame_Click(object sender, EventArgs e)
        {
            // find link button and createe object
            LinkButton lnkBtnTags = (LinkButton)sender;

            //Connect to EF DB
            using (DefaultConnectionGM db = new DefaultConnectionGM())
            {
                var recordGame = (from record in db.Games
                                  where record.Name == lnkBtnTags.Text.Trim()
                                  select record).FirstOrDefault();

                //bind data to model pop up
                lblTitle.Text = recordGame.Name;
                lblbody.Text  = recordGame.Description;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
            }
        }
示例#9
0
        /**
         * <summary>
         * This method gets the teams data from the DB
         * </summary>
         *
         * @method GetTeams
         * @returns {void}
         */
        private void GetTeams()
        {
            // connect to EF
            using (DefaultConnectionGM db = new DefaultConnectionGM())
            {
                string SortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                // query the Teams Table using EF and LINQ
                var Teams = (from allTeams in db.Teams
                             join allGames in db.Games
                             on allTeams.Gid equals allGames.GID
                             select new { allTeams.Name, allTeams.Description, GName = allGames.Name, allTeams.TID, allTeams.Gid, allGames.GID });

                // bind the result to the GridView
                gdTeams.DataSource = Teams.AsQueryable().OrderBy(SortString).ToList();

                gdTeams.DataBind();
            }
        }
示例#10
0
        /**
         * <summary>
         * This method gets gamesrecords from DB and bind to form
         * </summary>
         *
         * @method GetGameRecord
         * @returns {void}
         */
        private void GetGameRecord()
        {
            try
            {
                int GRID = Convert.ToInt32(Request.QueryString["GRID"]);
                if (GRID > 0)
                {
                    //connect to EF DB
                    using (DefaultConnectionGM db = new DefaultConnectionGM())
                    {
                        var gameRecords = (from records in db.GameRecords
                                           where records.GRID == GRID
                                           select records).FirstOrDefault();

                        //bind data to form
                        txtGameDate.Text          = gameRecords.Date.ToString("yyyy-MM-dd");
                        txtWinTeamScore.Text      = gameRecords.T1WinScore.ToString();
                        txtLoseTeamScore.Text     = gameRecords.T2WinScore.ToString();
                        txtSpectators.Text        = gameRecords.Sepectators.ToString();
                        ddlGameName.SelectedValue = gameRecords.Gid.ToString();
                        //fill team drop down
                        ddlTeamData(gameRecords.Gid);
                        //set selected value to team dropdowns
                        ddlTeamName1.SelectedValue = gameRecords.Team1.ToString();
                        ddlTeamName2.SelectedValue = gameRecords.Team2.ToString();
                        ddlTeamName2.Enabled       = true;
                        //bind value to win dropdown
                        ddlWinTeam.Items.Clear();
                        ddlWinTeam.Items.Insert(0, new ListItem("Select Winning Team", "0"));
                        ddlWinTeam.Items.Insert(1, new ListItem(ddlTeamName1.SelectedItem.Text.ToString(), ddlTeamName1.SelectedValue));
                        ddlWinTeam.Items.Insert(2, new ListItem(ddlTeamName2.SelectedItem.Text.ToString(), ddlTeamName2.SelectedValue));
                        ddlWinTeam.SelectedValue = gameRecords.WTeam.ToString();
                        ddlWinTeam.Enabled       = true;

                        btnsubmit.Text = "Update";
                    }
                }
            }
            catch (Exception e)
            {
            }
        }
示例#11
0
        /**
         * <summary>
         * This method gets the student data from the DB
         * </summary>
         *
         * @method GetGameRecords
         * @returns {void}
         */
        private void GetGameRecords()
        {
            try {
                //geberate sorting
                string SortString = Session["SortColumn"] + " " + Session["SortDirection"];
                //Connect to EF DB
                using (DefaultConnectionGM db = new DefaultConnectionGM()) {
                    var GameRecords = (from GR in db.GameRecords
                                       join G in db.Games on GR.Gid equals G.GID
                                       join T in db.Teams on GR.Team1 equals T.TID
                                       join T1 in db.Teams on GR.Team2 equals T1.TID
                                       join W in db.Teams on GR.WTeam equals W.TID
                                       select new  { GR.GRID, GR.Sepectators, GR.T1WinScore, GR.T2WinScore, GR.Date, GR.Team2, GR.Team1, GR.WTeam, GName = G.Name, TeamN1 = T.Name, TeamN2 = T1.Name, WTeamN = W.Name });

                    //bind result to grid view
                    gdGameRecord.DataSource = GameRecords.AsQueryable().OrderBy(SortString).ToList();
                    gdGameRecord.DataBind();
                }
            } catch (Exception e) { }
        }
示例#12
0
        /**
         * <summary>
         * This method gets the games data from the DB
         * </summary>
         *
         * @method bindGames
         * @returns {void}
         */
        private void bindGames()
        {
            //Connect to EF DB
            using (DefaultConnectionGM db = new DefaultConnectionGM())
            {
                if (Week == 0)
                {
                    //get current week
                    CultureInfo ciCurr = CultureInfo.CurrentCulture;
                    Week = Convert.ToInt32(ciCurr.Calendar.GetWeekOfYear(DateTime.Now, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday).ToString());
                }
                lbprevious.CommandArgument = (Week - 1).ToString();
                lbnext.CommandArgument     = (Week + 1).ToString();

                //write query
                var GameRecords = (from GR in db.GameRecords
                                   join G in db.Games on GR.Gid equals G.GID
                                   join T in db.Teams on GR.Team1 equals T.TID
                                   join T1 in db.Teams on GR.Team2 equals T1.TID
                                   join W in db.Teams on GR.WTeam equals W.TID
                                   where GR.Week == Week
                                   select new { GR.GRID, GR.Sepectators, GR.T1WinScore, GR.T2WinScore, GR.Date, GR.Team2, GR.Team1, GR.WTeam, GName = G.Name, TeamN1 = T.Name, TeamN2 = T1.Name, WTeamN = W.Name, TotalScore = GR.T1WinScore + GR.T2WinScore, GR.Week });

                if (GameRecords.Count() > 0)
                {
                    //bind result to grid view
                    rptGame.DataSource = GameRecords.ToList();
                    rptGame.DataBind();
                    Jumbotron3.Visible = false;
                    rptGame.Visible    = true;
                }
                else
                {
                    rptGame.DataSource = null;
                    rptGame.DataBind();
                    Jumbotron3.Visible = true;
                    rptGame.Visible    = true;
                }
            }
        }
        /* <summary>
         * This method check if record already have in table.
         * </summary>
         *
         * @method checkAlready
         * @returns {int }
         */
        private int checkAlready(Models.Game newGame)
        {
            int rowCount = 0;

            try
            {
                using (DefaultConnectionGM db = new DefaultConnectionGM())
                {
                    //write query
                    var recordAlready = (from record in db.Games
                                         where record.Name == newGame.Name
                                         select record).First();
                    if (recordAlready != null)
                    {
                        rowCount = 1;
                    }
                }
            }
            catch (Exception e)
            { }
            return(rowCount);
        }
示例#14
0
        /**
         * <summary>
         * This method gets total number of records from each table.
         * </summary>
         *
         * @method GetData
         * @returns {void}
         */
        private void GetData()
        {
            using (DefaultConnectionGM db = new DefaultConnectionGM())
            {
                //games count
                var countGame = (from count in db.Games
                                 select count).Count();

                //teams count
                var countTeam = (from count in db.Teams
                                 select count).Count();

                //games records
                var countGRecords = (from count in db.GameRecords
                                     select count).Count();

                //bind data
                lblGames.Text   = countGame.ToString();
                lblTeams.Text   = countTeam.ToString();
                lblGRecord.Text = countGRecords.ToString();
            }
        }
示例#15
0
        /**
         * <summary>
         * This method gets games from DB and bind to dropdown
         * </summary>
         *
         * @method ddlBindGameData
         * @returns {void}
         */
        private void ddlBindGameData()
        {
            try
            {
                using (DefaultConnectionGM db = new DefaultConnectionGM())
                {
                    //Write query
                    ddlGameName.DataSource = (from allGames in db.Games
                                              orderby allGames.Name
                                              select new { allGames.GID, allGames.Name }).ToList();

                    //bind data to dropdown
                    ddlGameName.DataTextField  = "Name";
                    ddlGameName.DataValueField = "GID";
                    //ddlGameName.DataSource = Games;
                    ddlGameName.DataBind();

                    //first item
                    ddlGameName.Items.Insert(0, new ListItem("Select Game", "0"));
                }
            }
            catch (Exception e) { }
        }
示例#16
0
        /**
         * <summary>
         * This event handler deletes a game record from the db using EF
         * </summary>
         *
         * @method gdGameRecord_RowDeleting
         * @param {object} sender
         * @param {GridViewDeleteEventArgs} e
         * @returns {void}
         */
        protected void gdGameRecord_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            // store which row was clicked
            int selectRow = e.RowIndex;

            //get id form selected row
            int GRID = Convert.ToInt32(gdGameRecord.DataKeys[selectRow].Values["GRID"]);

            //Connect to EF DB
            using (DefaultConnectionGM db = new DefaultConnectionGM())
            {
                var deleteRecord = (from record in db.GameRecords
                                    where record.GRID == GRID
                                    select record).FirstOrDefault();

                db.GameRecords.Remove(deleteRecord);

                db.SaveChanges();
                //refresh grid
                GetGameRecords();
                Session["GRMsg"] = "Your Record Delete Succeessfully.";
                getMessage();
            }
        }
        /**
         * <summary>
         * This event handler allows to add or update records to DB
         * </summary>
         *
         * @method btnsubmit_Click
         * @param {object} sender
         * @param {EventArgs} e
         * @returns {void}
         */
        protected void btnsubmit_Click(object sender, EventArgs e)
        {
            int rowCount;

            // Use EF to connect to the server
            using (DefaultConnectionGM db = new DefaultConnectionGM())
            {
                // use the Games model to create a new game object and
                // save a new record
                Models.Game newGame = new Models.Game();

                int GID = 0;

                if (Request.QueryString.Count > 0) // our URL has a StudentID in it
                {
                    // get the id from the URL
                    GID = Convert.ToInt32(Request.QueryString["GID"]);

                    // get the current student from EF DB
                    newGame = (from game in db.Games
                               where game.GID == GID
                               select game).FirstOrDefault();

                    Session["GameMsg"] = "Your Record Updated Succeessfully.";
                }

                // add form data to the new game record
                newGame.Name        = txtGameName.Text;
                newGame.Description = txtshortdesc.Text;


                // use LINQ to ADO.NET to add / insert new student into the database

                if (GID == 0)
                {
                    //check record is already in DB
                    rowCount = checkAlready(newGame);
                    if (rowCount == 0)
                    {
                        db.Games.Add(newGame);

                        Session["GameMsg"] = "Your Record Added Succeessfully.";
                        // save our changes - also updates and inserts
                        db.SaveChanges();

                        // Redirect back to the updated games page
                        Response.Redirect("~/AdminPanel/Game.aspx");
                    }
                    else
                    {
                        lblMsg.Text      = "Record has been already added.";
                        alertMsg.Visible = true;
                    }
                }
                else
                {
                    // save our changes - also updates and inserts
                    db.SaveChanges();

                    // Redirect back to the updated games page
                    Response.Redirect("~/AdminPanel/Game.aspx");
                }
            }
        }
        /**
         * <summary>
         * This event handler update or add record to DB
         * </summary>
         *
         * @method btnsubmit_Click
         * @param {object} sender
         * @param {EventArgs} e
         * @returns {void}
         */
        protected void btnsubmit_Click(object sender, EventArgs e)
        {
            int rowCount;

            // Use EF to connect to the server
            using (DefaultConnectionGM db = new DefaultConnectionGM())
            {
                // use the Teams model to create a new team object and
                // save a new record
                Models.Team newTeam = new Models.Team();

                int TID = 0;

                if (Request.QueryString.Count > 0)
                {
                    TID = Convert.ToInt32(Request.QueryString["TeamID"]);
                    //write query
                    newTeam = (from teamRecord in db.Teams
                               where teamRecord.TID == TID
                               select teamRecord).FirstOrDefault();

                    Session["TeamMsg"] = "Your Record Updated Succeessfully.";
                }

                //add data to DB
                newTeam.Name        = txtTeamName.Text.ToString().Trim();
                newTeam.Description = txtshortdesc.Text.ToString().Trim();
                newTeam.Gid         = Convert.ToInt32(ddlGameName.SelectedValue);

                //check operation insert or update
                if (TID == 0)
                {
                    //check record is already in DB
                    rowCount = checkAlready(newTeam);
                    if (rowCount == 0)
                    {
                        db.Teams.Add(newTeam);

                        Session["TeamMsg"] = "Your Record Added Succeessfully.";
                        //save our change
                        db.SaveChanges();

                        // Redirect back to the updated games page
                        Response.Redirect("~/AdminPanel/Team.aspx");
                    }
                    else
                    {
                        lblMsg.Text      = "Record has been already added.";
                        alertMsg.Visible = true;
                    }
                }
                else
                {
                    //save our change
                    db.SaveChanges();

                    // Redirect back to the updated games page
                    Response.Redirect("~/AdminPanel/Team.aspx");
                }
            }
        }
示例#19
0
        /**
         * <summary>
         * This event handler allows to save or update data
         * </summary>
         *
         * @method btnsubmit_Click
         * @param {object} sender
         * @param {EventArgs} e
         * @returns {void}
         */
        protected void btnsubmit_Click(object sender, EventArgs e)
        {
            int rowCount;

            //connect to EF DB
            using (DefaultConnectionGM db = new DefaultConnectionGM())
            {
                if (Convert.ToInt32(txtWinTeamScore.Text) > Convert.ToInt32(txtLoseTeamScore.Text))
                {
                    if ((ddlTeamName1.SelectedValue != ddlTeamName2.SelectedValue))
                    {
                        int GRID = 0;
                        //define onject of Game record model
                        Models.GameRecord newGameRecord = new Models.GameRecord();

                        if (Request.QueryString.Count > 0)
                        {
                            GRID          = Convert.ToInt32(Request.QueryString["GRID"]);
                            newGameRecord = (from record in db.GameRecords
                                             where record.GRID == GRID
                                             select record).FirstOrDefault();

                            Session["GRMsg"] = "Your Record Updated Succeessfully.";
                        }

                        newGameRecord.Date        = Convert.ToDateTime(txtGameDate.Text.ToString());
                        newGameRecord.Gid         = Convert.ToInt32(ddlGameName.SelectedValue);
                        newGameRecord.Team1       = Convert.ToInt32(ddlTeamName1.SelectedValue);
                        newGameRecord.Team2       = Convert.ToInt32(ddlTeamName2.SelectedValue);
                        newGameRecord.WTeam       = Convert.ToInt32(ddlWinTeam.SelectedValue);
                        newGameRecord.Sepectators = Convert.ToInt32(txtSpectators.Text.ToString().Trim());
                        newGameRecord.T1WinScore  = Convert.ToInt32(txtWinTeamScore.Text.ToString().Trim());
                        newGameRecord.T2WinScore  = Convert.ToInt32(txtLoseTeamScore.Text.ToString().Trim());
                        newGameRecord.T1LoseScore = Convert.ToInt32(txtLoseTeamScore.Text.ToString().Trim());
                        newGameRecord.T2LoseScore = Convert.ToInt32(txtWinTeamScore.Text.ToString().Trim());
                        newGameRecord.TotalScore  = Convert.ToInt32(txtWinTeamScore.Text.ToString().Trim()) + Convert.ToInt32(txtLoseTeamScore.Text.ToString().Trim());
                        CultureInfo ciCurr = CultureInfo.CurrentCulture;
                        newGameRecord.Week = Convert.ToInt32(ciCurr.Calendar.GetWeekOfYear(Convert.ToDateTime(txtGameDate.Text.ToString()), CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday).ToString());

                        //check insert of update operation
                        if (GRID == 0)
                        {
                            //check record is already in DB
                            rowCount = checkAlready(newGameRecord);
                            if (rowCount == 0)
                            {
                                db.GameRecords.Add(newGameRecord);
                                Session["GRMsg"] = "Your Record Added Succeessfully.";
                                //save our change
                                db.SaveChanges();

                                // Redirect back to the updated games page
                                Response.Redirect("~/AdminPanel/GameRecord.aspx");
                            }
                            else
                            {
                                lblMsg.Text      = "Record has been already added.";
                                alertMsg.Visible = true;
                            }
                        }
                        else
                        {
                            //save our change
                            db.SaveChanges();

                            // Redirect back to the updated games page
                            Response.Redirect("~/AdminPanel/GameRecord.aspx");
                        }
                    }
                    else
                    {
                        lblMsg.Text = "Team1 and Team2 have different value.";
                        ddlTeamName1.Focus();
                        alertMsg.Visible = true;
                    }
                }
                else
                {
                    lblMsg.Text = "Winning team has always higher score.";
                    txtWinTeamScore.Focus();
                    alertMsg.Visible = true;
                }
            }
        }