Classe per il CheckDigit del codice Fiscale

public sealed class FiscalCode
 {
  private string _cf;

  
  private static Hashtable Odd;
  private static Hashtable Even;
  private static Hashtable LastChar;

  static FiscalCode()
  {
   Odd=new Hashtable(26);
   Even=new Hashtable(26);
   LastChar=new Hashtable(26);

   Odd.Add('A',1);
   Odd.Add('B',0);
   Odd.Add('C',5);
   Odd.Add('D',7);
   Odd.Add('E',9);
   Odd.Add('F',13);
   Odd.Add('G',15);
   Odd.Add('H',17);
   Odd.Add('I',19);
   Odd.Add('J',21);
   Odd.Add('K',2);
   Odd.Add('L',4);
   Odd.Add('M',18);
   Odd.Add('N',20);
   Odd.Add('O',11);
   Odd.Add('P',3);
   Odd.Add('Q',6);
   Odd.Add('R',8);
   Odd.Add('S',12);
   Odd.Add('T',14);
   Odd.Add('U',16);
   Odd.Add('V',10);
   Odd.Add('W',22);
   Odd.Add('X',25);
   Odd.Add('Y',24);
   Odd.Add('Z',23);
   Odd.Add('0',1);
   Odd.Add('1',0);
   Odd.Add('2',5);
   Odd.Add('3',7);
   Odd.Add('4',9);
   Odd.Add('5',13);
   Odd.Add('6',15);
   Odd.Add('7',17);
   Odd.Add('8',19);
   Odd.Add('9',21);

   Even.Add('A',0);
   Even.Add('B',1);
   Even.Add('C',2);
   Even.Add('D',3);
   Even.Add('E',4);
   Even.Add('F',5);
   Even.Add('G',6);
   Even.Add('H',7);
   Even.Add('I',8);
   Even.Add('J',9);
   Even.Add('K',10);
   Even.Add('L',11);
   Even.Add('M',12);
   Even.Add('N',13);
   Even.Add('O',14);
   Even.Add('P',15);
   Even.Add('Q',16);
   Even.Add('R',17);
   Even.Add('S',18);
   Even.Add('T',19);
   Even.Add('U',20);
   Even.Add('V',21);
   Even.Add('W',22);
   Even.Add('X',23);
   Even.Add('Y',24);
   Even.Add('Z',25);
   Even.Add('0',0);
   Even.Add('1',1);
   Even.Add('2',2);
   Even.Add('3',3);
   Even.Add('4',4);
   Even.Add('5',5);
   Even.Add('6',6);
   Even.Add('7',7);
   Even.Add('8',8);
   Even.Add('9',9);

   LastChar.Add(0,'A');
   LastChar.Add(1,'B');
   LastChar.Add(2,'C');
   LastChar.Add(3,'D');
   LastChar.Add(4,'E');
   LastChar.Add(5,'F');
   LastChar.Add(6,'G');
   LastChar.Add(7,'H');
   LastChar.Add(8,'I');
   LastChar.Add(9,'J');
   LastChar.Add(10,'K');
   LastChar.Add(11,'L');
   LastChar.Add(12,'M');
   LastChar.Add(13,'N');
   LastChar.Add(14,'O');
   LastChar.Add(15,'P');
   LastChar.Add(16,'Q');
   LastChar.Add(17,'R');
   LastChar.Add(18,'S');
   LastChar.Add(19,'T');
   LastChar.Add(20,'U');
   LastChar.Add(21,'V');
   LastChar.Add(22,'W');
   LastChar.Add(23,'X');
   LastChar.Add(24,'Y');
   LastChar.Add(25,'Z');
  }

  public FiscalCode(string CF)
  {
   _cf=CF;
  }

  public bool IsValid
  {
   get
   {
    if(_cf.Length!=16)
     return false;

    int sum=0;
    for(int i=0;i<15;i++)
    {
     if(i%2==0)
      sum+=(int)FiscalCode.Odd[_cf[i]];
     else
      sum+=(int)FiscalCode.Even[_cf[i]];
    }

    if((char)FiscalCode.LastChar[sum%26]==_cf[15])
     return true;
    else
     return false;
   }
  }
 }

powered by IMHO 1.2

 

posted @ venerdì 4 novembre 2005 14:20

Print

Comments on this entry:

# calvert hall baltimore

Gravatar
XwCJvt0 | &lt;a href=&quot;http://dr-o'keefe-calvert-md.hureokapci.selfip.info&quot; &gt;dr o'keefe calvert md&lt;/a&gt;

# Order wellbutrin.

Left by Order wellbutrin. at 25/05/2010 22:25
Gravatar
Order wellbutrin.

# Esomeprazole.

Left by Esomeprazole. at 18/02/2011 21:01
Gravatar
Esomeprazole.

# Plavix.

Left by Plavix. at 19/02/2011 10:23
Gravatar
Plavix.

# Meridia.

Left by Meridia. at 24/02/2011 05:52
Gravatar
Meridia.

# Synthroid.

Left by Synthroid. at 28/02/2011 00:30
Gravatar
Synthroid.

# Toddler overdose on synthroid.

Left by Is synthroid supposed to taste sweet. at 28/02/2011 02:20
Gravatar
Synthroid. Side effects of synthroid.

# re: Classe per il CheckDigit del codice Fiscale

Left by Nike free run at 07/06/2012 12:38
Gravatar
Sporting en sort læder øvre, skoen skifter tingene op med brugen af stramme strikke mesh for sidepanelerne.
Comments have been closed on this topic.
«aprile»
domlunmarmergiovensab
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011