763
Підписники
+324 години
+77 днів
+6030 днів
Архів дописів
using System;
using System.Drawing;
using System.Net.Http;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json.Linq;
namespace CurrencyProject1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private async Task<string> GetDataFromWeb(string url)
{
using (HttpClient client = new HttpClient())
{
HttpResponseMessage response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStringAsync();
}
}
decimal rate;
private async void btnConvert_Click(object sender, EventArgs e)
{
// Get selected currencies
if (cmbAmount.SelectedIndex == -1 || CmbConvAmount.SelectedIndex == -1)
{
MessageBox.Show(
"Please select both currencies", // النص
"Selection Required", // العنوان
MessageBoxButtons.OK, // الأزرار
MessageBoxIcon.Warning // الأيقونة
);
return;
}
if (cmbAmount.Text == CmbConvAmount.Text)
{
MessageBox.Show(
"You can't choose the same currency", // النص
"Invalid Selection", // العنوان
MessageBoxButtons.OK, // الأزرار
MessageBoxIcon.Warning // الأيقونة
);
return;
}
string selectedCurrency = cmbAmount.SelectedItem.ToString();
string selectedTOCurrency = CmbConvAmount.SelectedItem.ToString();
try
{
// Get amount from txtUsdAmount
decimal amount = decimal.Parse(txtUsdAmount.Text);
// Build API request URL
string url = "http://apilayer.net/api/live" +
"?access_key=2c9f482cf9f5607a111abdbbb62e0865" +
"&source=" + selectedCurrency +
"¤cies=" + selectedTOCurrency +
"&format=1";
// Call API
string json = await GetDataFromWeb(url);
// Parse JSON
JObject result = JObject.Parse(json);
// Example: if source=GBP and target=LYD, then key is "GBPLYD"
string key = selectedCurrency + selectedTOCurrency;
rate = (decimal)result["quotes"][key];
// Convert amount
decimal convertedAmount = amount * rate;
// Show result in txtConvertedAmount
txtConvertedAmount.Text = convertedAmount.ToString("0.00");
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
private void Form1_Load(object sender, EventArgs e)
{
// Add currencies to ComboBox
string[] currencies = { "USD", "EUR", "GBP", "JPY", "CAD", "AUD", "CHF", "TRY", "CNY", "EGP", "TND", "RUB", "LYD" };
cmbAmount.Items.AddRange(currencies);
CmbConvAmount.Items.AddRange(currencies);
}
private Image GetCurrencyImage(string currencyCode)
{
switch (currencyCode)
{
case "USD": return Properties.Resources.USD; // صورة الدولار
case "EUR": return Properties.Resources.EUR; // صورة اليورو
case "GBP": return Properties.Resources.GBP; // صورة الجنيه
case "JPY": return Properties.Resources.JPY; // صورة الين
case "CAD": return Properties.Resources.CAD; // صورة الدولار الكندي
case "AUD": return Properties.Resources.AUD; // صورة الدولار الأسترالي
case "CHF": return
في الجملة السابقة، إعراب (أبوك) هو:
A) مفعولٌ به منصوب B) فاعلٌ مرفوع C) بدل كلٍّ من كلّ مرفوع D) مضافٌ إليه مجرور
المفعول به هو:
A) اسم مرفوع يدل على الفاعل B) اسم منصوب يدل على من وقع عليه الفعل C) فعل يدل على الحدث D) ظرف زمان
Which hormone is both endocrine and exocrine in function?
A) Pancreas B) Thyroid C) Adrenal D) Pituitary
Which hormone is released in response to high blood glucose?
A) Insulin B) Glucagon C) Cortisol D) ADH
