Bu örneğimizde C# WPF Form ile TC Kimlik Numarası sorgulaması yapacağız. Örneğimizde WPF Formumuza 1 adet textBox ve 1 adet Button kontrolü ekleyerek girilen TC Kimlik numarasının doğruluğunu kontrol edeceğiz.
xaml Kodları:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<Window x:Class="tckimlik.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:tckimlik" mc:Ignorable="d" Title="www.yazilimkodlama.com" Height="350" Width="525"> <Grid> <TextBox x:Name="txtTc" HorizontalAlignment="Left" Height="36" Margin="146,71,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="224"/> <Button x:Name="button" Content="DOĞRULA" HorizontalAlignment="Left" VerticalAlignment="Top" Width="224" Margin="146,112,0,0" Height="48" Click="button_Click"/> <TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="146,185,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Height="37" Width="224"/> </Grid> </Window> |
Form Tasarımı:
C# Kodları:
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 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace tckimlik { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void button_Click(object sender, RoutedEventArgs e) { string tcKimlikNo = txtTc.Text; bool returnvalue = false; if (tcKimlikNo.Length == 11) { Int64 ATCNO, BTCNO, TcNo; long C1, C2, C3, C4, C5, C6, C7, C8, C9, Q1, Q2; TcNo = Int64.Parse(tcKimlikNo); ATCNO = TcNo / 100; BTCNO = TcNo / 100; C1 = ATCNO % 10; ATCNO = ATCNO / 10; C2 = ATCNO % 10; ATCNO = ATCNO / 10; C3 = ATCNO % 10; ATCNO = ATCNO / 10; C4 = ATCNO % 10; ATCNO = ATCNO / 10; C5 = ATCNO % 10; ATCNO = ATCNO / 10; C6 = ATCNO % 10; ATCNO = ATCNO / 10; C7 = ATCNO % 10; ATCNO = ATCNO / 10; C8 = ATCNO % 10; ATCNO = ATCNO / 10; C9 = ATCNO % 10; ATCNO = ATCNO / 10; Q1 = ((10 - ((((C1 + C3 + C5 + C7 + C9) * 3) + (C2 + C4 + C6 + C8)) % 10)) % 10); Q2 = ((10 - (((((C2 + C4 + C6 + C8) + Q1) * 3) + (C1 + C3 + C5 + C7 + C9)) % 10)) % 10); returnvalue = ((BTCNO * 100) + (Q1 * 10) + Q2 == TcNo); } if (returnvalue) textBlock.Text = "TC Kimlik Numarası Geçerli"; else textBlock.Text = "TC Kimlik Numarası Geçersiz"; } } } |
Ekran Çıktısı: