Commit 7c588f6d authored by chalulu's avatar chalulu
Browse files

.

parent 3c49cf47
No related merge requests found
Showing with 508 additions and 0 deletions
+508 -0
{
"CurrentProjectSetting": null
}
\ No newline at end of file
{
"ExpandedNodes": [
""
],
"PreviewInSolutionExplorer": false
}
\ No newline at end of file
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
namespace SportsApi
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
lblTeam = new Label();
label4 = new Label();
lblName = new Label();
label2 = new Label();
lbOutput = new ListBox();
lblError = new Label();
btnSearch = new Button();
txtInput = new TextBox();
label1 = new Label();
pctImage = new PictureBox();
((System.ComponentModel.ISupportInitialize)pctImage).BeginInit();
SuspendLayout();
//
// lblTeam
//
lblTeam.AutoSize = true;
lblTeam.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
lblTeam.Location = new Point(401, 187);
lblTeam.Name = "lblTeam";
lblTeam.Size = new Size(31, 21);
lblTeam.TabIndex = 19;
lblTeam.Text = "xxx";
//
// label4
//
label4.AutoSize = true;
label4.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
label4.Location = new Point(306, 187);
label4.Name = "label4";
label4.Size = new Size(49, 21);
label4.TabIndex = 18;
label4.Text = "Team:";
//
// lblName
//
lblName.AutoSize = true;
lblName.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
lblName.Location = new Point(401, 150);
lblName.Name = "lblName";
lblName.Size = new Size(31, 21);
lblName.TabIndex = 17;
lblName.Text = "xxx";
//
// label2
//
label2.AutoSize = true;
label2.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
label2.Location = new Point(306, 150);
label2.Name = "label2";
label2.Size = new Size(55, 21);
label2.TabIndex = 16;
label2.Text = "Name:";
//
// lbOutput
//
lbOutput.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
lbOutput.FormattingEnabled = true;
lbOutput.ItemHeight = 21;
lbOutput.Location = new Point(12, 401);
lbOutput.Name = "lbOutput";
lbOutput.Size = new Size(585, 382);
lbOutput.TabIndex = 15;
//
// lblError
//
lblError.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
lblError.ForeColor = Color.Red;
lblError.Location = new Point(16, 50);
lblError.Name = "lblError";
lblError.Size = new Size(581, 30);
lblError.TabIndex = 14;
lblError.Text = "Error";
//
// btnSearch
//
btnSearch.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
btnSearch.Location = new Point(506, 9);
btnSearch.Name = "btnSearch";
btnSearch.Size = new Size(91, 33);
btnSearch.TabIndex = 13;
btnSearch.Text = "Search";
btnSearch.UseVisualStyleBackColor = true;
btnSearch.Click += btnSearch_Click;
//
// txtInput
//
txtInput.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
txtInput.Location = new Point(73, 12);
txtInput.Name = "txtInput";
txtInput.Size = new Size(418, 29);
txtInput.TabIndex = 12;
//
// label1
//
label1.AutoSize = true;
label1.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
label1.Location = new Point(12, 15);
label1.Name = "label1";
label1.Size = new Size(55, 21);
label1.TabIndex = 11;
label1.Text = "Name:";
//
// pctImage
//
pctImage.BackColor = SystemColors.ControlLight;
pctImage.Location = new Point(16, 129);
pctImage.Name = "pctImage";
pctImage.Size = new Size(246, 248);
pctImage.SizeMode = PictureBoxSizeMode.StretchImage;
pctImage.TabIndex = 10;
pctImage.TabStop = false;
//
// Form1
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(610, 807);
Controls.Add(lblTeam);
Controls.Add(label4);
Controls.Add(lblName);
Controls.Add(label2);
Controls.Add(lbOutput);
Controls.Add(lblError);
Controls.Add(btnSearch);
Controls.Add(txtInput);
Controls.Add(label1);
Controls.Add(pctImage);
Name = "Form1";
Text = "SportsApp";
((System.ComponentModel.ISupportInitialize)pctImage).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label lblTeam;
private Label label4;
private Label lblName;
private Label label2;
private ListBox lbOutput;
private Label lblError;
private Button btnSearch;
private TextBox txtInput;
private Label label1;
private PictureBox pctImage;
}
}
using System.Net.Http.Json;
namespace SportsApi;
public partial class Form1 : Form
{
private const string _baseUrl = "https://www.thesportsdb.com/api/v1/json/3/searchplayers.php?p=";
private const string _formerurl = "https://www.thesportsdb.com/api/v1/json/3/lookupformerteams.php?id=";
private static readonly HttpClient _httpClient = new();
public Form1()
{
InitializeComponent();
// Prepare components
lblError.Text = "";
lblName.Text = "";
lblTeam.Text = "";
lbOutput.DisplayMember = "ToString";
}
private async void btnSearch_Click(object sender, EventArgs e)
{
await showPlayer();
}
private async Task showPlayer()
{
HttpResponseMessage response = new();
string Pname = "";
lbOutput.Items.Clear();
try
{
Pname = txtInput.Text.Split(" ")[0] + "_" + txtInput.Text.Split(" ")[1];
}
catch (Exception)
{
MessageBox.Show("wrong name");
return;
}
try
{
response = await _httpClient.GetAsync(_baseUrl + Pname);
}
catch (Exception)
{
MessageBox.Show("Error");
return;
}
if (!response.IsSuccessStatusCode)
{
lblError.Text = "Player not found";
MessageBox.Show("Player not found");
}
players pl = new players();
try
{
pl = await response.Content.ReadFromJsonAsync<players>();
}
catch(Exception ex)
{
MessageBox.Show("chyba" + ex);
return;
}
if(pl.player.Count == 0)
{
MessageBox.Show("chyba");
return;
}
Player foot = pl.player[0];
lblName.Text = foot.strPlayer;
lblTeam.Text = foot.strTeam;
Stream imageStream;
try
{
imageStream = await _httpClient.GetStreamAsync(foot.strThumb);
}
catch (Exception)
{
MessageBox.Show("Failed to download image from the server.");
return;
}
Image img = Image.FromStream(imageStream);
pctImage.Image = img;
//
try
{
response = await _httpClient.GetAsync(_formerurl + foot.idPlayer);
}
catch (Exception)
{
MessageBox.Show("Error");
return;
}
formerteamsC teams = new();
try
{
teams = await response.Content.ReadFromJsonAsync<formerteamsC>();
}
catch (Exception ex)
{
MessageBox.Show("chyba" + ex);
return;
}
foreach (FormerT team in teams.formerteams)
{
lbOutput.Items.Add(team);
}
}
}
public class players
{
public List<Player> player { get; set; }
}
public class formerteamsC
{
public List<FormerT> formerteams { get; set; }
}
public class FormerT
{
public string strJoined { get; set; }
public string strDeparted { get; set; }
public string strFormerTeam { get; set; }
public override string ToString()
{
return "[" + strJoined + " - " + strDeparted + "]" + " " + strFormerTeam;
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
using System.Text.Json.Serialization;
namespace SportsApi;
public class Player
{
public string strPlayer { get; set; }
public string strTeam { get; set; }
public string strThumb { get; set; }
public string idPlayer { get; set; }
}
namespace SportsApi
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment