Created
July 3, 2018 03:10
-
-
Save d630/41dbe2ace1ebaeb10716c4b8fd728f9a to your computer and use it in GitHub Desktop.
Windows Forms + System.Xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Windows.Forms; | |
| using System.Xml; | |
| namespace XmlExp | |
| { | |
| public partial class Form1 : Form | |
| { | |
| public const string XML_DATA = "http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml"; | |
| //public const string XML_DATA = "x.xml"; | |
| private List<Kurs> k = new List<Kurs>(); | |
| public Form1() | |
| { | |
| InitializeComponent(); | |
| parseXml(); | |
| } | |
| private void Form1_Load(object sender, EventArgs e) | |
| { | |
| fillListBox1(); | |
| } | |
| private void fillListBox1() | |
| { | |
| foreach (Kurs kk in k) | |
| listBox1.Items.Add($"{kk.Currency}\t{kk.Rate}"); | |
| } | |
| private void parseXml() | |
| { | |
| XmlReader xmlReader = XmlReader.Create(XML_DATA); | |
| k.Clear(); | |
| while (xmlReader.Read()) | |
| { | |
| if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name == "Cube") | |
| { | |
| if (xmlReader.HasAttributes) | |
| if (xmlReader.AttributeCount == 2) | |
| k.Add(new Kurs(xmlReader.GetAttribute("currency"), double.Parse(xmlReader.GetAttribute("rate").Replace(".", ",")))); | |
| } | |
| } | |
| } | |
| private void listBox1_SelectedIndexChanged(object sender, EventArgs e) | |
| { | |
| textBox1.Text = k[listBox1.SelectedIndex].Currency; | |
| textBox2.Text = k[listBox1.SelectedIndex].Rate.ToString(); | |
| } | |
| private void textBox3_Leave(object sender, EventArgs e) | |
| { | |
| if (textBox3.Text == "" || listBox1.SelectedIndex == -1) | |
| return; | |
| try | |
| { | |
| textBox4.Text = Math.Round(double.Parse(textBox3.Text) * k[listBox1.SelectedIndex].Rate, 2).ToString(); | |
| } | |
| catch (Exception ex) | |
| { | |
| MessageBox.Show(ex.Message); | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| namespace XmlExp | |
| { | |
| class Kurs | |
| { | |
| public Kurs(string currency, double rate) | |
| { | |
| this.Currency = currency; | |
| this.Rate = rate; | |
| } | |
| public string Currency { get; set; } | |
| public double Rate { get; set; } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment