Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Te ndertohet nje web form ne ASP.

NET dhe C# qe konverton nga celcius ne Fahrenheit, sipas formulave


me poshte:

Nga Celsius ne Fahrenheit:

F = (C * 9) / 5 + 32;

Nga Fahrenheit ne Celsius:

C = (F – 32) * 5 / 9;

Forma duhet te permbaj:


1. RadioButton List per opsionet e konvertimit
2. TextBox per konvertim
3. Trajtuesit e gabimeve ne rast se perdoruesi nuk vendos vlera numerike por tekst
Kodi ne TemperatureConvertForm.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TemperatureConvertForm.aspx.cs"


Inherits="WebApplication2.TemperatureConvertForm" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>

</head>
<body style="background-color:burlywood; position:center">
<form id="form1" runat="server" style="align-items:center; margin-left: 25%;
margin-top: 15%; ">

<fieldset style="width: 270px; background-color: #FFCCFF; display: block;


list-style-type: disc;">
<legend style="background-color:aqua; color:deeppink">Zgjidh menyren e
konvertimit:</legend>

<asp:RadioButtonList ID="TempRadioButtonList" runat="server"


style="width: 270px" OnSelectedIndexChanged="TempRadioButtonList_SelectedIndexChanged"
AutoPostBack="true"> </asp:RadioButtonList>
</fieldset>
<br />
<fieldset style="width: 270px; background-color: #FFCCFF; position: absolute;
display: block; list-style-type: disc;">
<legend style="background-color:aqua; color:deeppink">Vlera per
konvertimit:</legend>
<table style="width: 270px" >
<tr>
<td style="color:red">Celcius</td>
<td style="color:blue">Fahrenheit</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtCelsious" runat="server"
OnTextChanged="txtCelsious_TextChanged" AutoPostBack="true" Width="90px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtFahrenheit" runat="server"
OnTextChanged="txtFahrenheit_TextChanged" Enabled="false" AutoPostBack="true"
Width="90px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="ResultLabel" runat="server" ForeColor="Red"
></asp:Label>
</td>
</tr>
</table>
</fieldset>

</form>
</body>
</html>

Kodi ne TemperatureConvertForm.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication2
{
public partial class TemperatureConvertForm : System.Web.UI.Page
{
#region Public methods
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
FillConvertionType();

}
}
#endregion
#region Private methods
private void FillConvertionType()
{
// mbushet lista me radio button me vlera
TempRadioButtonList.Items.Add(new ListItem("Celcius", "1"));
TempRadioButtonList.Items.Add(new ListItem("Fahrenheit", "2"));
// elementi i pare checkohet
TempRadioButtonList.Items[0].Selected = true;

}
#endregion

protected void txtCelsious_TextChanged(object sender, EventArgs e)


{
// deklarojme variablat qe do te perdoren per konvertim
decimal f = 0, c = 0;

if (TempRadioButtonList.SelectedValue == "1")
{
try
{
//Konvertohet nga celcus ne Fahrenheit
c = decimal.Parse(txtCelsious.Text);
//F = (C * 9) / 5 + 32;
f = (c * 9) / 5 + 32;
txtFahrenheit.Text = f.ToString();
txtCelsious.Style["Border-color"] = "black";
}
catch (Exception ex)
{
txtCelsious.Style["Border-color"] = "Red";
ResultLabel.Text = "Ju lutem rishikoni vleren e vendosur ne kutine
Celvius!";
}

}
}

protected void txtFahrenheit_TextChanged(object sender, EventArgs e)


{
// deklarojme variablat qe do te perdoren per konvertim
decimal f = 0, c = 0;

if (TempRadioButtonList.SelectedValue == "2")
{
try {
//Konvertohet nga celcus ne Fahrenheit
f= decimal.Parse(txtFahrenheit.Text);
//C = (F – 32) * 5 / 9;
c = (f-32)*5/9;
txtCelsious.Text = c.ToString();
txtFahrenheit.Style["Border-color"] = "black";
}
catch (Exception ex)
{
txtFahrenheit.Style["Border-color"] = "Red";
ResultLabel.Text = "Ju lutem rishikoni vleren e vendosur ne
kutine Celvius!";
}

protected void TempRadioButtonList_SelectedIndexChanged(object sender, EventArgs


e)
{
if (TempRadioButtonList.SelectedIndex == 0)
{
txtFahrenheit.Enabled = false;
txtCelsious.Enabled = true;
}
else
{
txtFahrenheit.Enabled = true;
txtCelsious.Enabled = false;
}
}
}
}

You might also like