/* ----------------- HELPER METHODS ------------------- */ /// <summary> /// adds user specified stat to game and to all team and player stat totals /// </summary> private void Add_Stat() { // set deafult qtr values int qtr = 1; // if qtr = OT replace with 5 if (QtrCB.Text.ToString() == "OT") { qtr = 5; } else { qtr = Int32.Parse(QtrCB.Text.ToString()); } // deafult player id int playerId; // parse player number from combobox int playerNum; // if player is opponent, dont parse player value if (PlayerCB.Text.ToString() == "Opponent") { statType = 'O'; playerNum = Int32.Parse(PlayerCB.Items[0].ToString()); } // if home team stat, parse player id from player number else { statType = Set_Stat_Type(); playerNum = Int32.Parse(PlayerCB.Text.ToString()); } // get player id from player number string selqry = string.Format(SELECT_PLAYER_ID_QRY, playerNum, myTeam.GetId()); DataTable dt = build.Execute_DataTable_Qry(selqry); playerId = Int32.Parse(dt.Rows[0]["id"].ToString()); // insert new game stat into game history and watch the magic happen string insqry = string.Format(INSERT_STAT_QRY, qtr, this.statType, playerId, myGame.GetId(), myTeam.GetId()); build.Execute_Query(insqry); // update all tables Set_Game_Stats(); Update_Tables(); AddStatPNL.Visibility = Visibility.Hidden; this.UpdateLayout(); }
/// <summary> /// takes user to delete window of selected team /// </summary> private void Delete_Team() { // disable foreign key checks build.Execute_Query(FOREIGN_KEY_DISABLE_QRY); // delete team from database string qry = string.Format(DELETE_TEAM_QRY, myTeam.GetId()); build.Execute_Query(qry); Load_Table_Data(); }
/// <summary> /// adds player to database player datatable /// </summary> private void Add_Player() { // parse player number string playerNumStr = NumberTB.Text.ToString(); int playerNum = 0; try { playerNum = Int32.Parse(playerNumStr); } catch (FormatException ex) { string formatError = string.Format(STRING_FORMAT_MSG, "Player Number"); MessageBox.Show(formatError); return; } // parse player name string playerName = NameTB.Text.ToString(); // parse player position into a char string playerPos = PositionCB.SelectedItem.ToString(); playerPos = playerPos.Substring(playerPos.IndexOf(":") + 2); // parse player year string playerYearStr = YearCB.SelectedItem.ToString(); playerYearStr = playerYearStr.Substring(playerYearStr.IndexOf(":") + 2); int playerYear = Int32.Parse(playerYearStr); // parse player weight and height to integers string playerHeightStr = HeightTB.Text.ToString(); string playerWeightStr = WeightTB.Text.ToString(); int playerHeight, playerWeight; try { playerHeight = Int32.Parse(playerHeightStr); playerWeight = Int32.Parse(playerWeightStr); } catch (FormatException ex) { string formatError = string.Format(STRING_FORMAT_MSG, "Player Weight/Height"); MessageBox.Show(formatError); return; } // insert player into player data table string qry = string.Format(INSERT_PLAYER_QRY, playerNum, playerName, playerPos, playerYear, playerHeight, playerWeight, myTeam.GetId()); build.Execute_Query(qry); }
/// <summary> /// Inserts team into the team database /// </summary> private void AddTeam(string teamName, string teamYear) { // add team to database string qry = string.Format(INSERT_TEAM_QRY, teamName, teamYear); build.Execute_Query(qry); }
private void Delete_Game() { // disable foregnkey contraints string setQry = FOREIGN_KEY_DISABLE_QRY; build.Execute_Query(setQry); // delete game from database string delQry = string.Format(DELETE_GAME_QRY, myGame.GetId()); build.Execute_Query(delQry); Load_Game_Table_Data(); Set_Team_Stats(); Set_Player_Attributes_Stats(); Set_Labels(); Load_Player_Table_Data(); myGame.Clear(); }
/// <summary> /// updates information in database /// </summary> private void Update_Game() { // get game info from window uesr input string oppTeam = OppNameTB.Text.ToString(); string gameType = GameTypeCB.Text.ToString(); string gameLoc = GameLocCB.Text.ToString(); string gameDate = string.Format(DATE_FMT, YearTB.Text.ToString(), MonthCB.Text.ToString(), DayCB.Text.ToString()); // insert new game into game datatable string insqry = string.Format(UPDATE_GAME_QRY, oppTeam, gameType, gameLoc, gameDate, myGame.GetId()); build.Execute_Query(insqry); // select inserted game from datatable myGame.init(); myGame.Set_Attributes(build.Execute_DataSet_Query(SELECT_GAME_QRY)); }
private void Update_Player_Attributes() { // get text from textboxes int playerNum = Int32.Parse(NumberTB.Text.ToString()); string playerName = NameTB.Text.ToString(); string playerPos = PosCB.Text.ToString(); int playerYear = Int32.Parse(YearCB.Text.ToString()); int playerHeight = Int32.Parse(HeightTB.Text.ToString()); int playerWeight = Int32.Parse(WeightTB.Text.ToString()); // update player info string updqry = string.Format(UPDATE_PLAYER_QRY, playerNum, playerName, playerPos, playerYear, playerHeight, playerWeight, myPlayer.GetId()); build.Execute_Query(updqry); // update myplayer data fields string selqry = string.Format(SELECT_PLAYER_QRY, myPlayer.GetId()); myPlayer.Set_Attributes(build.Execute_DataSet_Query(selqry)); }