Welcome to Sign in | Help

Re: verificare cod fiscal

  •  01-23-2009, 7:13 AM

    Re: verificare cod fiscal

    validare CF
    -------------
    public string ValidareCIF(string CIF)
            {
               
                int[] c = new int[CIF.Length];
                int[] b =  new int[9] ;
                int produs = 0;
                b[0]=2;
                b[1]=3;
                b[2]=5;
                b[3]=7;
                b[4]=1;
                b[5]=2;
                bDevil=3;
                b[7]=5;
                bMusic=7;
               
                string cif_inversat = "", msg = "", cifra_control = "", cheie_testare = "753217532";
                if (CIF.Trim().Length > 10)
                    {
                    
                      msg = "invalid";
                    }
                if (msg != "invalid")
                {
                    for (int i = 0; i <= CIF.Length - 1; i++)
                    {
                        try
                        {
                       
                            cIdea = System.Convert.ToInt32(CIF.Substring(i, 1));
                            cifra_control = CIF.Substring(i, 1);
                        }
                        catch (Exception)
                        {
                            msg = "invalid";
                         
                        }
                    }

                    int j = 0;
                    for (int i = CIF.Length - 2; i>=0; i--)
                    {
                        cif_inversat = cif_inversat + Convert.ToString(cIdea);
                        produs = produs + b[j] * cIdea;
                        j += 1;
                    }
                    int t = produs*10;
                    int r = t % 11;
                    if (Convert.ToString( r) == cifra_control)
                    {
                        msg = "valid";
                    }
                 
                }
              
                return msg;
              
            }

    n-am avut cand sa-l optimizez
View Complete Thread
Powered by Community Server (Commercial Edition), by Telligent Systems