Quantcast
Channel: C#nedir?com Forum
Viewing all articles
Browse latest Browse all 613

C# : TC No Doğrulama

$
0
0
Author: maytas
Subject: TC No Doğrulama
Posted: 09 Eylül 2017 at 22:26

Merhaba.
Aşağıda TC No doğrulaması yapan yeni hazırladığım kodları paylaşıyorum.
Belki ihtiyacı olan istifade eder.

        private void tcNoDogrula_Click(object sender, EventArgs e)
        {
            char ilkRakam = maskedTextBox1.Text[0];
            char sonRakam = maskedTextBox1.Text[10];
            if (ilkRakam == '0' | sonRakam % 2 != 0)
            {
                MessageBox.Show("TC No hatalıdır");
            }
            else
            {
                string ilk9Karakter = maskedTextBox1.Text.Substring(0, 9);
                string rakam10 = maskedTextBox1.Text.Substring(9, 1);
                string rakam11 = maskedTextBox1.Text.Substring(10, 1);

                int toplam1 = 0;
                for (int i = 0; i < ilk9Karakter.Length; i += 2)
                {
                    toplam1 += Convert.ToByte(maskedTextBox1.Text.ToString());
                }

                int toplam2 = 0;
                for (int i = 1; i < ilk9Karakter.Length; i += 2)
                {
                    toplam2 += Convert.ToByte(maskedTextBox1.Text.ToString());
                }

                int sayi10 = ((toplam1 * 7) - toplam2) % 10;
                int sayi11 = (toplam1 + toplam2 + sayi10) % 10;
                if (rakam10 != sayi10.ToString() | rakam11 != sayi11.ToString())
                {
                    MessageBox.Show("TC No hatalıdır.");
                }
                else
                {
                    MessageBox.Show("TC No Doğrulandı.");
                }
            }
        }

Viewing all articles
Browse latest Browse all 613

Trending Articles