private void lblLoadMatchDate_Click(object sender, EventArgs e) { //Create match and the databse string path = ""; saveFileDialog1.FileName = txtMatchName.Text + ".sdf"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { path = saveFileDialog1.FileName; } else { return; } if (!rbTeam1FirstBatting.Checked && !rbTeam2FirstBatting.Checked) { clsMessages.showMessage(clsMessages.msgType.exclamation, "Please select the first batting team to continue."); return; } //show infor txtInfo.Text = "Save path: " + path + "\n\n"; //Import data //Get the two team names. string team1Name = "", team2Name = ""; OleDbCommand comAc = new OleDbCommand("SELECT Teams.CountryID, Countries.Name, Teams.ID FROM Countries INNER JOIN Teams ON Countries.ID = Teams.CountryID", conACCESS); OleDbDataAdapter adACC = new OleDbDataAdapter(comAc); DataSet dsAC = new DataSet("countries"); adACC.Fill(dsAC, "countries"); team1Name = dsAC.Tables["countries"].Rows[0][1].ToString(); team2Name = dsAC.Tables["countries"].Rows[1][1].ToString(); int team1RefID = Convert.ToInt32(dsAC.Tables["countries"].Rows[0][2].ToString()); int team2RefID = Convert.ToInt32(dsAC.Tables["countries"].Rows[1][2].ToString()); //Indormation for creating a match int matchId = clsMatch.getNextMatchId(); string matchName = txtMatchName.Text; DateTime matchDate = dateTimePicker1.Value; clsMatchTypes matchType = new clsMatchTypes(clsMatchTypes.getMatchTypeID(cmbMatchType.SelectedItem.ToString()), cmbMatchType.SelectedItem.ToString()); comAc = new OleDbCommand("SELECT Countries.Name FROM Countries INNER JOIN Venues ON Countries.ID = Venues.CountryID", conACCESS); string countryNamePlayed = ""; try { countryNamePlayed = comAc.ExecuteScalar().ToString(); } catch (Exception ex) { clsMessages.showMessage(clsMessages.msgType.error, ex.Message); } clsCountry countryPlayed = new clsCountry(clsCountry.getCountryCode(countryNamePlayed), countryNamePlayed); comAc = new OleDbCommand("SELECT [Name] FROM Venues", conACCESS); string venueName = comAc.ExecuteScalar().ToString(); //Check if venue is in database if (clsGround.getGroundCode(venueName) <= 0) { int venueCode = clsGround.getNextGroundCode(); int endId = clsEnds.getNextEndID(); clsGround.addGround(new clsGround(venueCode, venueName, 30000, countryPlayed.countryId, new clsEnds(endId, "Scoreboard End", venueCode), new clsEnds(endId + 1, "Pavillion End", venueCode))); } clsGround groundPlayed = clsGround.getGround(venueName); //Show info txtInfo.Text += "Ground played in: " + groundPlayed.stadiumName + "\n\n"; txtInfo.Text += "Venue played: " + venueName + "\n\n"; txtInfo.Text += "Match name: " + matchName + "\n\n"; txtInfo.Text += "Team 1: " + team1Name + "\n\n"; txtInfo.Text += "Team 1: " + team2Name + "\n\n"; txtInfo.Text += "-----------------------\n\n"; //Get team 1 and 2 string playerFName = "", platerLName = ""; List <clsPlayer> team1 = new List <clsPlayer>(); List <clsPlayer> team2 = new List <clsPlayer>(); comAc = new OleDbCommand("SELECT CurrentTeamID, FirstName, LastName FROM Players", conACCESS); adACC = new OleDbDataAdapter(comAc); dsAC = new DataSet("Players"); adACC.Fill(dsAC, "Players"); //Show info txtInfo.Text += "Players added..." + "\n\n"; foreach (DataRow rAC in dsAC.Tables["Players"].Rows) { int currentTeamID = Convert.ToInt32(rAC[0].ToString()); string currentTeam = ""; OleDbCommand comCurrentTeam = new OleDbCommand("SELECT [Name] FROM Teams WHERE ID=@p1", conACCESS); comCurrentTeam.Parameters.AddWithValue("@p1", currentTeamID); currentTeam = comCurrentTeam.ExecuteScalar().ToString(); playerFName = rAC[1].ToString(); platerLName = rAC[2].ToString(); if (currentTeam == team1Name) { team1.Add(clsPlayer.getPlayer(clsPlayer.getPlayerId(playerFName, platerLName, clsCountry.getCountryCode(team1Name)))); } else { team2.Add(clsPlayer.getPlayer(clsPlayer.getPlayerId(playerFName, platerLName, clsCountry.getCountryCode(team2Name)))); } //Display the data added. txtInfo.Text += playerFName + " " + platerLName + "\n\n"; } OleDbCommand comCaptain1 = new OleDbCommand("SELECT CaptainID FROM MatchTeams WHERE TeamID=@p1", conACCESS); comCaptain1.Parameters.AddWithValue("@p1", team1RefID); OleDbCommand comCaptain2 = new OleDbCommand("SELECT CaptainID FROM MatchTeams WHERE TeamID=@p1", conACCESS); comCaptain2.Parameters.AddWithValue("@p1", team2RefID); int captain1Id = 0; int captain2Id = 0; try { captain1Id = clsImportBallbyBall.mapPlayer(Convert.ToInt32(comCaptain1.ExecuteScalar().ToString()), conACCESS); captain2Id = clsImportBallbyBall.mapPlayer(Convert.ToInt32(comCaptain2.ExecuteScalar().ToString()), conACCESS); } catch (Exception ex) { clsMessages.showMessage(clsMessages.msgType.error, "Error retrieving team capain IDs\n\n" + ex.Message); } List <clsTeams> squard = new List <clsTeams>(); squard.Add(new clsTeams(clsCountry.getCountry(team1Name), team1, captain1Id, 0, 0)); squard.Add(new clsTeams(clsCountry.getCountry(team2Name), team2, captain2Id, 0, 0)); string firstBatting = ""; if (rbTeam1FirstBatting.Checked) { firstBatting = cmbTeam1.SelectedItem.ToString(); } else if (rbTeam2FirstBatting.Checked) { firstBatting = cmbTema2.SelectedItem.ToString(); } new clsMatch(matchId, matchName, matchType, matchDate, path, countryPlayed, groundPlayed, squard, cmbTeam1.SelectedItem.ToString(), firstBatting); SqlCeConnection conSQL = connection.creatDatabase(path, true); //Create tables in the match database clsCreateTables.createTables(conSQL); //connection.CON_WORKING = conSQL; //Creates the match in the main database clsMatch.creatMatch(); if (chkMatchWon.Checked) { clsMatch.setWinningTeam(matchId, squard[0].country.countryId, ""); } else { clsMatch.setWinningTeam(matchId, squard[1].country.countryId, ""); } clsCreateTables.AddTeam(clsMatch.currentMatch.team1.players, clsMatch.currentMatch.matchID); clsCreateTables.AddTeam(clsMatch.currentMatch.team2.players, clsMatch.currentMatch.matchID); lblLoadMatchDate.Enabled = false; btnBallByBall.Enabled = true; clsMessages.showMessage(clsMessages.msgType.information, "Match data was Imported successfully"); }
private void btnCreateMatch_Click(object sender, EventArgs e) { if (dataValidated()) { new frmToss(cmbCountry1.SelectedItem.ToString(), cmbCountry2.SelectedItem.ToString()).ShowDialog(); saveFileDialog1.FileName = txtMatchName.Text; if (saveFileDialog1.ShowDialog() == DialogResult.Cancel) { return; } string fileName = saveFileDialog1.FileName; List <clsTeams> teams = new List <clsTeams>(); List <clsPlayer> squad1 = new List <clsPlayer>(); List <clsPlayer> squad2 = new List <clsPlayer>(); int captain = 0, viceCaptain = 0, wicketKeeper = 0; string fName, lName = ""; //Adding the squad for the team 1 int countryId = clsCountry.getCountryCode(cmbCountry1.SelectedItem.ToString()); foreach (string player in lstCountry1Squard.Items) { //Splits the name in to two fName = extractPlayerFName(player); lName = extractPlayerLName(player); squad1.Add(clsPlayer.getPlayer(clsPlayer.getPlayerId(fName, lName, countryId))); } captain = clsPlayer.getPlayerId(extractPlayerFName(cmbSquad1Capt.SelectedItem.ToString()), extractPlayerLName(cmbSquad1Capt.SelectedItem.ToString()), countryId); viceCaptain = clsPlayer.getPlayerId(extractPlayerFName(cmbSquad1VCapt.SelectedItem.ToString()), extractPlayerLName(cmbSquad1VCapt.SelectedItem.ToString()), countryId); wicketKeeper = clsPlayer.getPlayerId(extractPlayerFName(cmbSquad1WC.SelectedItem.ToString()), extractPlayerLName(cmbSquad1WC.SelectedItem.ToString()), countryId); teams.Add(new clsTeams(clsCountry.getCountry(cmbCountry1.SelectedItem.ToString()), squad1, captain, viceCaptain, wicketKeeper)); //Adding the squad for the team 2 countryId = clsCountry.getCountryCode(cmbCountry2.SelectedItem.ToString()); foreach (string player in lstCountry2Squard.Items) { //Splits the name in to two fName = extractPlayerFName(player); lName = extractPlayerLName(player); squad2.Add(clsPlayer.getPlayer(clsPlayer.getPlayerId(fName.Trim(), lName.Trim(), countryId))); } captain = clsPlayer.getPlayerId(extractPlayerFName(cmbSquad2Capt.SelectedItem.ToString()), extractPlayerLName(cmbSquad2Capt.SelectedItem.ToString()), countryId); viceCaptain = clsPlayer.getPlayerId(extractPlayerFName(cmbSquad2VCapt.SelectedItem.ToString()), extractPlayerLName(cmbSquad2VCapt.SelectedItem.ToString()), countryId); wicketKeeper = clsPlayer.getPlayerId(extractPlayerFName(cmbSquad2WC.SelectedItem.ToString()), extractPlayerLName(cmbSquad2WC.SelectedItem.ToString()), countryId); teams.Add(new clsTeams(clsCountry.getCountry(cmbCountry2.SelectedItem.ToString()), squad2, captain, viceCaptain, wicketKeeper)); clsMatchTypes matchType = new clsMatchTypes(clsMatchTypes.getMatchTypeID(cmbMatchType.SelectedItem.ToString()), cmbMatchType.SelectedItem.ToString()); int matchId = clsMatch.getNextMatchId(); //Creates the main math object new clsMatch(matchId, txtMatchName.Text, matchType, dateTimePicker1.Value, fileName, clsCountry.getCountry(cmbCountry.SelectedItem.ToString()), clsGround.getGround(cmbVenue.SelectedItem.ToString()), teams, tossWonby, firstBattinh); //Set the isBatting flag if (firstBattinh == clsMatch.currentMatch.team1.country.countryName) { clsMatch.currentMatch.team1.isBatting = true; clsMatch.currentMatch.team2.isBatting = false; } else { clsMatch.currentMatch.team1.isBatting = false; clsMatch.currentMatch.team2.isBatting = true; } //Writes data to the databse clsMatch.creatMatch(); clsFormCreater.openForm(new frmCaptureVideo()); //Close(); } }