Bu yazımızda ASP.NET ile İdeal Kilo Hesaplaması yaptırarak sonucu ekranda göstereceğiz. Örneğimizde Kullanıcıdan Kilo, Boy, Cinsiyet ve Doğum Yılı bilgisi istenerek gerekli hesaplama yapıldıktan sonra ekranda görüntülenmesini sağlayacağız.
WebForm tasarımımız aşağıdaki gibi olacaktır.
WebForm1.aspx kodlarımız:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <style type="text/css"> .auto-style1 { width: 100%; } .auto-style2 { width: 103px; } .auto-style3 { width: 103px; height: 27px; } .auto-style4 { height: 27px; } </style> </head> <body> <form id="form1" runat="server"> <div> <table class="auto-style1"> <tr> <td class="auto-style2">Kilo</td> <td> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </td> </tr> <tr> <td class="auto-style2">Boy (cm)</td> <td> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> </td> </tr> <tr> <td class="auto-style2">Doğum Yılı</td> <td> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> </td> </tr> <tr> <td class="auto-style3">Cinsiyet</td> <td class="auto-style4"> <asp:RadioButton ID="RadioButton1" runat="server" Text="Bay" GroupName="cins" /> <asp:RadioButton ID="RadioButton2" runat="server" Text="Bayan" GroupName="cins" /> </td> </tr> <tr> <td class="auto-style2"> </td> <td> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Hesapla" Width="126px" /> </td> </tr> <tr> <td class="auto-style2">İdeal Kilonuz</td> <td> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> </td> </tr> <tr> <td class="auto-style2">Açıklama</td> <td> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </td> </tr> </table> </div> </form> </body> </html> |
WebForm1.aspx.cs Button1_Click kodlarımız:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | protected void Button1_Click(object sender, EventArgs e) { // Formül: İdeal kilo = (Boy - 100 + Yaş / 10) * K // K katsayısı kadınlar için 0.8, erkekler için ise 0.9'dur. int boy = Convert.ToInt32(TextBox2.Text); int kilo = Convert.ToInt32(TextBox1.Text); int yas = DateTime.Now.Year - Convert.ToInt32(TextBox3.Text); double idealkilo=0; if(RadioButton1.Checked) { idealkilo = (boy - 100 + yas / 10) * 0.9; } else { idealkilo = (boy - 100 + yas / 10) * 0.8; } Label1.Text = idealkilo.ToString(); if (idealkilo==kilo) { Label2.Text = "İdeal Kilodasınız!"; } if (idealkilo>kilo) { Label2.Text = "Zayıfsınız. Kilo almalısınız!"; } if (idealkilo<kilo) { Label2.Text = "İdeal kilonuzun üzerindesiniz!"; } } |