Beispiel #1
0
    private void UpdateCountryTop(Country c)
    {
      try
      {
        StreamReader sr = new StreamReader(Application.StartupPath + Helper.GetCountryListFileName());
        List<string> lines = new List<string>();
        while (sr.EndOfStream == false)
        {
          string line = sr.ReadLine();
          if (line.Contains(c.CountryId + "|" + c.CountryName))
          {
            line = line.Substring(0, line.LastIndexOf("|")) + "|" + c.Top;
          }
          lines.Add(line);
        }
        sr.Close();

        StreamWriter sw = new StreamWriter(Application.StartupPath + Helper.GetCountryListFileName());
        foreach (string s in lines)
          sw.WriteLine(s);
        sw.Close();
      }
      catch (Exception ex)
      {
        Logger.Exception(ex);
        MessageBox.Show(ex.Message);
      }
    }
Beispiel #2
0
    private async Task LoadCompetitionsAsync()
    {
      try
      {
        this.pbLoadingCompetitions.Visible = true;
        this._selectedCountry = (Country)this.lbCountries.SelectedItem;
        this.lbTeams.DataSource = null;
        this.lbCompetition.DataSource = null;
        this.lbCompetition.DisplayMember = "CompetitionName";
        this.lbCompetition.ValueMember = "CompetitionId";
        this.lbTeams.DataSource = null;
        this.lbTeams.SelectedIndex = -1;
        this.cbCountries.Text = "";
        lbCountries.Enabled = false;

        List<Competition> list = (
          from cc in this._cachedCompetitions
          where cc.CompetitionCountryId == this._selectedCountry.CountryId
          select cc).ToList<Competition>();

        if (list.Count == 0)
        {
          //KLUPSKA TAKMICENJA
          if (_selectedCountry.CountryId == -2)
            this._selectedCountry.Competitions =
              await DataLoader.LoadCupCompetitionsAsync();

          //MEDJUNARODNA TAKMICENJA
          else if (_selectedCountry.CountryId == -3)
            this._selectedCountry.Competitions =
              await DataLoader.LoadInternationalCupCompetitionsAsync();

          //OSTALO
          else
            this._selectedCountry.Competitions =
              await DataLoader.LoadCompetitionsAsync(this._selectedCountry.CountryId);

          DirectoryInfo directoryInfo = new DirectoryInfo("cache");
          if (!directoryInfo.Exists)
          {
            directoryInfo.Create();
          }
          StreamWriter streamWriter = new StreamWriter(Application.StartupPath + Helper.GetCompetitionListFileName(), true);
          foreach (Competition c in _selectedCountry.Competitions)
          {

            if (c.CompetitionName.Equals("NATIONAL"))
            {
              StreamWriter sw = new StreamWriter(Application.StartupPath + Helper.GetTeamListFileName(), true);
              foreach (Team t in c.Teams)
              {
                t.CompetitionName = c.CompetitionName;
                if ((
                  from cc in this._cachedTeams
                  where cc.CompetitionId == t.CompetitionId && cc.TeamId == t.TeamId
                  select cc).ToList<Team>().Count == 0)
                {
                  this._cachedTeams.Add(t);
                  sw.WriteLine(t.CompetitionId.ToString() + "|" + t.CompetitionName + "|" + t.TeamId.ToString() + "|" + t.TeamName + "|" + t.UrlName);
                }
              }
              sw.Close();
            }

            if ((
              from cc in this._cachedCompetitions
              where cc.CompetitionId == c.CompetitionId
              select cc).ToList<Competition>().Count == 0)
            {
              list.Add(c);
              this._cachedCompetitions.Add(c);
              streamWriter.WriteLine(_selectedCountry.CountryId.ToString() + "|" + _selectedCountry.CountryName + "|" + c.CompetitionId.ToString() + "|" + c.CompetitionName);
            }
          }
          streamWriter.Close();
        }

        this._selectedCountry.Competitions = list;

        this.pbLoadingCompetitions.Visible = false;
        this.lbCompetition.DataSource = this._selectedCountry.Competitions;
        this.lbCompetition.Select();
        lbCountries.Enabled = true;


        if (_generatingInProgress == false)
        {
          btnAzurirajArhivu.Enabled = true;
        }
      }
      catch (Exception ex)
      {
        Logger.Exception(ex);
        MessageBox.Show(ex.Message);
      }
    }