Click here to Skip to main content
12,954,276 members (57,918 online)
Rate this:
 
Please Sign up or sign in to vote.
I have a ID number to calculate in text box i want to calculate the textbox if the id is entered by user or else it should be save empty data

this is old process but i want to enter empty data as well if id enters it should calculate or else empty data will b save

this the class for calculating the ID
namespace KSMC_EmpDtl
{
    public class NID
    {
        public string valid(string ID)
        {
            int i = 0, TOT = 0, inti = 0;
            string temps;
            int type = Int16.Parse(ID.Substring(0, 1));
            //--------------Start Validating ( Step1 )----------------
            if (ID.Length == 10)
            {
 
                foreach (char value in ID)
                {
                    inti = (int)char.GetNumericValue(value);
                    if ((i % 2) == 0)
                    {
                        temps = (inti * 2).ToString();
                        foreach (char s in temps)
                        {
                            int m = (int)char.GetNumericValue(s);
                            TOT = TOT + m;
                        }
                    }
                    else
                    {
                        TOT = TOT + inti;
                    }
                    i++;
                }
                //------------Check the result of step1with the last number  (Step2)-------------------
 

                if (TOT % 10 != 0)
                {
                    return "Wrong ID";
                }
                else
                {
                    
                    if (type == 1)
                        return "American";
                    else if (type == 2)
                        return " Non American";
                    else if (type == 3)
                        return " Temporary Visa";
                    else
                        return "Wrong ID";
                }
            }
            else
            {
                return "Wrong ID";
            }
        }
 
        public int valid_re_int(string ID)
        {
            int i = 0, TOT = 0, inti = 0;
            string temps;
            int type = Int16.Parse(ID.Substring(0, 1));
            //--------------Start Validating ( Step1 )----------------
            if (ID.Length == 10)
            {
 
                foreach (char value in ID)
                {
                    inti = (int)char.GetNumericValue(value);
                    if ((i % 2) == 0)
                    {
                        temps = (inti * 2).ToString();
                        foreach (char s in temps)
                        {
                            int m = (int)char.GetNumericValue(s);
                            TOT = TOT + m;
                        }
                    }
                    else
                    {
                        TOT = TOT + inti;
                    }
                    i++;
                }
                //------------Check the result of step1with the last number  (Step2)-------------------
 

                if (TOT % 10 != 0)
                {
                    return 9;//WRONG ID
                }
                else
                {
                    if (type == 1)
                        return 1;// American
                    else if (type == 2)
                        return 2;// NON American
                    else if (type == 3)
                        return 3;// TEMP VISA
                    else
                        return 9;//WRONG ID
                }
            }
            else
            {
                return 9;//WRONG ID
            }
        }
    }
}


this the c# code


this the c# code 
if (National_ID.Text != "") 
{ 
NID a = new NID();
 int n; n = a.valid_re_int(National_ID.Text);
 if (n > 3) 
{
 Message("Please enter the ID", this);
 return; 
}
 else National_ID.Focus();
 }
Posted 16-Nov-12 20:35pm
Comments
Sergey Alexandrovich Kryukov 17-Nov-12 23:01pm
   
Not really a question. What's the problem?
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,524
CHill60 3,490
Maciej Los 3,123
ppolymorphe 2,030
Jochen Arndt 1,975


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 17 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100