habe es wieder getan und ein Projekt erstellt zum Thema Wechselkurse
habe mir eine Währungsrechner gebastelt und möchte hier nachfragen was eure Meinung dazu ist, ich weiß die gibt es haufenweise im Netz, aber trotzdem wie würdet ihr das aufbauen? damit es auch zuverlässig funktioniert!
Design naja ...
es funktioniert halt.......
erbitte Kommentare dazu.
gerne auch Verbesserungsvorschläge Danke euch
hier mein Code dazu
Private jetzt As Date = Now.ToShortDateString
Private MyECB As New ECBExchanges
' Internet-Adresse
Public ECPXMLAddress As String = _
"http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml"
Private Sub Waehrungsliste_Enter()
Try
'ohne diese prozedur funktioniert es garnicht
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 Or _
SecurityProtocolType.Tls12 Or SecurityProtocolType.Tls11 Or _
SecurityProtocolType.Tls
'fill Data from XML
filldata_totable()
'zum Beispiel USD (Dollar)
find_corecct_Waehrung()
'Berechnen to EUR
berechne_to()
'Berechnen from Währung
berechne_from()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Public Sub filldata_totable()
Dim dt As New DataTable
dt.Columns.Add("currenct", GetType(String))
dt.Columns.Add("rate", GetType(Decimal))
Dim doc As XDocument = XDocument.Load(ECPXMLAddress)
Dim ns As XNamespace = doc.Root.GetDefaultNamespace()
For Each cube As XElement In doc.Descendants(ns + "Cube").Where( _
Function(x) Not x.Attribute("currency") Is Nothing)
Dim currency As String = CType(cube.Attribute("currency"), String)
Dim rate As Decimal = CType(cube.Attribute("rate"), Decimal)
dt.Rows.Add(New Object() {currency, rate})
Next
dgv_currency.DataSource = dt
End Sub
Private Sub find_corecct_Waehrung()
Dim code As String = "USD"
For Each row As DataGridViewRow In dgv_currency.Rows()
If row.Cells(0).Value.ToString().Equals(code) Then
row.Selected = True
lbl_datenabruf.Text = String.Concat("Datenabruf: " & jetzt & _
vbCrLf & "1 EUR = " & Math.Round(row.Cells(1).Value, 3) & " ~" & _
"" & row.Cells(0).Value)
'Wert übernehmen
Dim factorto As Double = row.Cells(1).Value
Dim factorfrom As Double = 1 / row.Cells(1).Value
'Textbox Format erstellen
tb_kurs_to.Text = Format(CDbl(factorto), "#,##0.000")
tb_kurs_from.Text = Format(CDbl(factorfrom), "#,##0.00000")
'groupbox Bezeichnungen erstellen
grb_wechselkurs_eur.Text = String.Concat("1 EUR TO " & _
row.Cells(0).Value).ToString
grb_wechselkurs_waehrung.Text = String.Concat("1 " & row.Cells( _
0).Value).ToString & " TO EUR"
'in Label Währung anzeigen
Label193.Text = row.Cells(0).Value
dgv_currency.CurrentCell = row.Cells(0)
Exit For
End If
Next
End Sub weiterer Code
Private Sub berechne_to()
'EUR = Euro
Dim EUR As Double = nud_Factor1.Value
Dim sum As Double = Format(CDbl(converto(EUR)), "#,##0.00")
'call function below
tb_to_ergebnis.Text = Format(CDbl(nud_Saldo_from.Value + sum), _
"#,##0.00")
End Sub
Private Sub berechne_from()
'FW = Fremdwährung
Dim FW As Double = nud_Factor2.Value
'call function below
tb_from_ergebnis.Text = Format(CDbl(convertfrom(FW)), "#,##0.0000")
End Sub
Function converto(ByVal Currency As Double) As Double
Return Currency * Math.Round(CDbl(tb_kurs_to.Text), 4)
End Function
Function convertfrom(ByVal Currency As Double) As Double
Return Currency * Math.Round(CDbl(tb_kurs_from.Text), 4)
End Function |