private void frmFootball_Load_1(object sender, EventArgs e) { Data_Organiser data = new Data_Organiser(); Team team = new Team(); //data.GetCountryLink(); //data.GetCompetitionData(); //team.GeneratePoints(); //data.GetHomeFormsData(); // double homeWins, awayWins; // string date = "12/24/2018"; // double minPercent = 70; // double maxPercent = 80; // using (IDbConnection conn = data.Connection()) // { // List<Fixture> retval = conn.Query<Fixture>(@"SELECT * FROM [dbo].[FIXTURES] // WHERE [dateOfmatch] = @Date // ORDER BY [timeOfMatch] DESC", // new // { // Date = Convert.ToDateTime(date) // }).ToList(); // foreach (Fixture fixItem in retval) // { // try // { // homeWins = conn.Query<double>("[dbo].[sp_GetSeasonPerformance]", // new // { // TeamName = fixItem.homeTeam, // Country = fixItem.country, // Competition = fixItem.competition // },commandType: CommandType.StoredProcedure).FirstOrDefault(); // awayWins = conn.Query<double>("[dbo].[sp_GetSeasonPerformance]", // new // { // TeamName = fixItem.awayTeam, // Country = fixItem.country, // Competition = fixItem.competition // }, commandType: CommandType.StoredProcedure).FirstOrDefault(); // } // catch (Exception ex) // { // continue; // } // Debug.WriteLineIf((homeWins >= minPercent && homeWins < maxPercent) || (awayWins >= minPercent && homeWins >= maxPercent), // "\n" + fixItem.homeTeam + "---> " + homeWins + " VS " + awayWins + // " <---" + fixItem.awayTeam + " ===" + fixItem.timeOfMatch + "==="); // Debug.WriteLineIf((homeWins >= minPercent && homeWins < maxPercent) || (awayWins >= minPercent && homeWins >= maxPercent), // fixItem.competition); // Debug.WriteLineIf((homeWins >= minPercent && homeWins < maxPercent) || (awayWins >= minPercent && homeWins >= maxPercent), // fixItem.country); // } // } }
//private int groupLoop = 5; //public int GroupLoop //{ // get // { // return groupLoop; // } // set // { // groupLoop = value; // } //} //public enum ResultState { Draw, HomeWin, AwayWin, Posponed } #endregion #region Methods public void InsertResults(string pHomeTeam, string pAwayTeam, DateTime pDate, string pCountry, string pCOMPETITION, string pHomeScore, string pAwayScore, string state) { Data_Organiser data = new Data_Organiser(); using (IDbConnection conn = data.Connection()) { var value = conn.Query <bool>("sp_InsertResults", new { Country = pCountry, Competition = pCOMPETITION, DateOfmatch = pDate, HomeTeam = pHomeTeam, AwayTeam = pAwayTeam, HomeTeamScore = pHomeScore, AwayTeamScore = pAwayScore, MatchState = state }, commandType: CommandType.StoredProcedure).ToList(); Debug.WriteLine("Match RESULTS at " + DateTime.Now + " Result: " + value[0].ToString().ToUpper()); } //using (SampleDataDataContext DbData = new SampleDataDataContext()) //{ // RESULT result = DbData.RESULTs.SingleOrDefault(x => (x.homeTeam == pHomeTeam) && (x.awayTeam == pAwayTeam) // && (x.dateOfmatch == pDate)); // if (result == null) // { // try // { // RESULT newResult = new RESULT() // { // country = pCountry, // competition = pCOMPETITION, // dateOfmatch = pDate, // timeOfMatch = "unavailable", // homeTeam = pHomeTeam, // awayTeam = pAwayTeam, // homeTeamScore = pHomeScore, // awayTeamScore = pAwayScore, // matchState = state // }; // DbData.RESULTs.InsertOnSubmit(newResult); // DbData.SubmitChanges(); // } // catch (Exception sql) // { // MessageBox.Show("An error occurred while inserting results..\n" + sql.Message); // } // } //} }
public void InsertFixture(string pCountry, string pCompetition, string pHomeTeam, string pAwayTeam, DateTime pDate, string pTime) { Data_Organiser data = new Data_Organiser(); using (IDbConnection conn = data.Connection()) { var value = conn.Query <bool>("sp_InsertFixture", new { Country = pCountry, Competition = pCompetition, HomeTeam = pHomeTeam, AwayTeam = pAwayTeam, DateOfmatch = pDate, TimeOfMatch = pTime, FixtureState = "NORMAL FIXTURE" }, commandType: CommandType.StoredProcedure).ToList(); Debug.WriteLine("Match FIXTURE at " + DateTime.Now + " Result: " + value[0].ToString().ToUpper()); } //using (SampleDataDataContext DbData = new SampleDataDataContext()) //{ // FIXTURE fixture = DbData.FIXTUREs.SingleOrDefault(x => (x.homeTeam == pHomeTeam) && (x.awayTeam == pAwayTeam) && (x.dateOfmatch == pDate)); // if (fixture == null) // { // try // { // FIXTURE newFixture = new FIXTURE() // { // country = pCountry, // competition = pCompetition, // homeTeam = pHomeTeam, // awayTeam = pAwayTeam, // dateOfmatch = pDate, // timeOfMatch = pTime, // fixtureState = "NORMAL FIXTURE" // }; // DbData.FIXTUREs.InsertOnSubmit(newFixture); // DbData.SubmitChanges(); // } // catch (Exception sql) // { // MessageBox.Show("An error occurred while inserting fixture...\n" + sql.Message); // } // } //} }
private void btnQuickUpdate_Click_1(object sender, EventArgs e) { Results results = new Results(); Data_Organiser dataOrganiser = new Data_Organiser(); //int value = pbShowProgress.Value; //pbShowProgress.Value = value + 10; dataOrganiser.GetCountryLink(); //pbShowProgress.Value = value + 25; dataOrganiser.GetCompetitionData(); //pbShowProgress.Value = value + 25; dataOrganiser.GetHomeFormsData(); //pbShowProgress.Value = value + 40; //pbShowProgress.Value = 100; }
//protected int NumberOfTeams { get; set; } #endregion #region Methods public void InsertCompetition(string pCompetition, string pCountry, string pLink) { Data_Organiser data = new Data_Organiser(); using (IDbConnection conn = data.Connection()) { var retval = conn.Query <bool>("[dbo].[sp_InsertCompetition]", new { Competition = pCompetition, Country = pCountry, Link = pLink }, commandType: CommandType.StoredProcedure); Debug.WriteLine("COMPETITION at " + DateTime.Now + " Result: " + retval.ToString().ToUpper()); } //using (SampleDataDataContext DbData = new SampleDataDataContext()) //{ // COMPETITION league = DbData.COMPETITIONs.SingleOrDefault(x => (x.titleOfCompetition == pCompetition)); // if (league == null) // { // try // { // COMPETITION newCompetition = new COMPETITION() // { // titleOfCompetition = pCompetition, // country = pCountry, // link = pLink // }; // DbData.COMPETITIONs.InsertOnSubmit(newCompetition); // DbData.SubmitChanges(); // } // catch (Exception sql) // { // MessageBox.Show("An error occurred while inserting league..\n" + sql.Message); // } // } //} }
private void btnUpdate_Click(object sender, EventArgs e) { Results results = new Results(); Data_Organiser dataOrganiser = new Data_Organiser(); int value = 0; //pbShowProgress.Value = value + 5; ///dataOrganiser.GetCountryLink(); //pbShowProgress.Value = value + 5; ///dataOrganiser.GetCompetitionData(); //pbShowProgress.Value = value + 5; //dataOrganiser.GetHomeFormsData(); //pbShowProgress.Value = value + 5; //results.FullUpdateOfResults(); //pbShowProgress.Value = 100; //File_Organiser objFile = new File_Organiser(); Fixture fixture = new Fixture(); //objFile.GetFilesFromFolder(results.FileName, results.NumOfRowsToSkip, results.GroupLoop, "Results"); //objFile.GetFilesFromFolder(fixture.FileName, fixture.NumOfRowsToSkip, fixture.GroupLoop, "Fixture"); Team team = new Team(); team.GeneratePoints(); }
public void InsertTeamsForm(string pCountry, string pCompetition, string teamName, string pLink , char num1, char num2, char num3, char num4, char num5) { Data_Organiser data = new Data_Organiser(); using (IDbConnection conn = data.Connection()) { var retval = conn.Query <bool>("sp_InsertTeamsForm", new { nameOfTeam = teamName, country = pCountry, competition = pCompetition, competitionLink = pLink, _1 = num1, _2 = num2, _3 = num3, _4 = num4, _5 = num5 }, commandType: CommandType.StoredProcedure).ToList(); Debug.WriteLine("TEAMS FORM at " + DateTime.Now + " Result: " + retval[0].ToString().ToUpper()); //TEAMSFORM team = DbData.TEAMSFORMs.SingleOrDefault(t => (t.country.Equals(pCountry) && (t.competition.Equals(pCompetition) // && (t.nameOfTeam.Equals(teamName))))); //if (team == null) //{ // try // { // TEAMSFORM teamsForm = new TEAMSFORM() // { // nameOfTeam = teamName, // country = pCountry, // competition = pCompetition, // competitionLink = pLink, // _1 = num1, // _2 = num2, // _3 = num3, // _4 = num4, // _5 = num5 // }; // DbData.TEAMSFORMs.InsertOnSubmit(teamsForm); // DbData.SubmitChanges(); // } // catch (Exception ex) // { // MessageBox.Show("An error occurred while inserting teams form..." + ex.Message); // } //} //else //{ // try // { // team._1 = num1; // team._2 = num2; // team._3 = num3; // team._4 = num4; // team._5 = num5; // DbData.SubmitChanges(); // } // catch (Exception ex) // { // MessageBox.Show("An error occurred while updating teams form..." + ex.Message); // } //} } }
//Data_Organiser data = new Data_Organiser(); public void InsertRecalledMatch(string pCountry, string pCompetition, DateTime pDate, string pHomeTeam, string pAwayTeam, string pMatchState) { Data_Organiser data = new Data_Organiser(); using (IDbConnection conn = data.Connection()) { var value = conn.Query <bool>("sp_InsertRecalledMatch", new { Country = pCountry, Competition = pCompetition, DateOfmatch = pDate, HomeTeam = pHomeTeam, AwayTeam = pAwayTeam, MatchState = pMatchState }, commandType: CommandType.StoredProcedure); Debug.WriteLine("Match RECALLED at " + DateTime.Now + " Result: " + value.ToString().ToUpper()); } //using (SampleDataDataContext DbData = new SampleDataDataContext()) //{ // RECALLEDMATCH match = DbData.RECALLEDMATCHes.SingleOrDefault(x => (x.homeTeam.Equals(pHomeTeam)) && (x.awayTeam.Equals(pAwayTeam)) // && (x.dateOfmatch.Equals(pDate)) && (x.country.Equals(pCountry)) // && (x.competition.Equals(pCompetition))); // RECALLEDMATCH newRematch = new RECALLEDMATCH() // { // country = pCountry, // competition = pCompetition, // dateOfmatch = pDate, // homeTeam = pHomeTeam, // awayTeam = pAwayTeam // }; // if (match == null) // { // try // { // RECALLEDMATCH recalledMatch = new RECALLEDMATCH() // { // country = pCountry, // competition = pCompetition, // dateOfmatch = pDate, // homeTeam = pHomeTeam, // awayTeam = pAwayTeam, // matchState = pMatchState // }; // DbData.RECALLEDMATCHes.InsertOnSubmit(recalledMatch); // DbData.SubmitChanges(); // } // catch (Exception ex) // { // MessageBox.Show("An error occurred while inserting into RecalledMatch...\n" + ex); // } // } // else // { // string continueString = ""; // } //} }
public async void FullUpdateOfResults() { int countTimeout = 0; RecalledMatch reviewedMatch = new RecalledMatch(); Data_Organiser dor = new Data_Organiser(); Fixture fixture = new Fixture(); using (IDbConnection conn = dor.Connection()) { try { var links = conn.Query <Team>(" SELECT * FROM [Football].[dbo].[TEAM]"); foreach (Team linksItem in links) { HttpClient httpClient = new HttpClient(); String html = await httpClient.GetStringAsync(constantUrl + linksItem.link); HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument(); htmlDocument.LoadHtml(html); List <HtmlNode> MatchHtml = htmlDocument.DocumentNode.Descendants("tr") .Where(node => (node.GetAttributeValue("id", "") .Contains("page_team_1_block_team_matches"))).ToList(); foreach (HtmlNode MatchListItem in MatchHtml) { string date = GetMatchData(MatchListItem).Item1; DateTime evaluatedDate = Convert.ToDateTime(date); string homeTeam = GetMatchData(MatchListItem).Item2; string awayTeam = GetMatchData(MatchListItem).Item3; string score = GetMatchData(MatchListItem).Item4; string homeScore = ""; string awayScore = ""; ResultState state = ResultState.UNDEFINED; OptionState optionState = OptionState.Result; string time = ""; if (dor.IsSubstringable(score, ref homeScore, ref awayScore) && score.Contains(':')) { optionState = OptionState.Fixture; time = score; //dor.SlicingData(linksItem.country, linksItem.currentCompetition, evaluatedDate, homeTeam, awayTeam, // homeScore, awayScore, OptionState.Fixture.ToString(), score); fixture.InsertFixture(linksItem.country, linksItem.currentCompetition, homeTeam, awayTeam, evaluatedDate, score); } else if (dor.IsSubstringable(score, ref homeScore, ref awayScore) && score.Contains('P') || score.Contains('E') || score.Contains("PSTP")) { state = ResultState.POSTPONED; reviewedMatch.InsertRecalledMatch(linksItem.country, linksItem.currentCompetition, evaluatedDate, homeTeam, awayTeam, state.ToString()); continue; } else if (dor.IsSubstringable(score, ref homeScore, ref awayScore) && score == "CANC") { state = ResultState.CANCELLED; reviewedMatch.InsertRecalledMatch(linksItem.country, linksItem.currentCompetition, evaluatedDate, homeTeam, awayTeam, state.ToString()); continue; } else if (dor.IsSubstringable(score, ref homeScore, ref awayScore) && dor.IsNumber(homeScore, awayScore)) { optionState = OptionState.Result; dor.SlicingData(linksItem.country, linksItem.currentCompetition, evaluatedDate, homeTeam, awayTeam, homeScore, awayScore, OptionState.Result.ToString(), time); } else { state = ResultState.UNDEFINED; reviewedMatch.InsertRecalledMatch(linksItem.country, linksItem.currentCompetition, evaluatedDate, homeTeam, awayTeam, state.ToString()); continue; } } } } catch (TaskCanceledException tex) { Debug.WriteLine("\n" + tex.Message + " " + DateTime.Now + "\n"); FullUpdateOfResults(); //countTimeout++; //if (countTimeout >= 5) //{ //} } catch (Exception ex) { Debug.WriteLine("\n" + ex.Message + " " + DateTime.Now + "\n"); //FullUpdateOfResults(); //reviewedMatch.InsertRecalledMatch("COUNTRY", "COMPETITION", DateTime.Now, // "HOME", "AWAY", "UNDEFINED"); } } }