Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
1.00/5 (1 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
C#
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


C#
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
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900