Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#1.0 C#2.0 C#3.0 C++ C C# , +
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 at 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
0 OriginalGriff 210
1 Richard MacCutchan 100
2 kbrandwijk 90
3 ChauhanAjay 80
4 ProgramFOX 80
0 Sergey Alexandrovich Kryukov 9,050
1 OriginalGriff 8,151
2 CPallini 2,613
3 Richard MacCutchan 2,221
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 17 Nov 2012
Copyright © CodeProject, 1999-2014
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