public string GetToString(Societe societe, DeclarationCnss declaration, Exercice exercice)
        {
            if (societe == null || declaration == null || exercice == null)
            {
                return(string.Empty);
            }
            string result = string.Empty;

            result += societe.NumeroEmployeur.PadLeft(8, '0');
            result += societe.CleEmployeur.PadLeft(2, '0');
            result += CodeExploitation.PadLeft(4, '0');
            result += declaration.Trimestre.ToString().PadLeft(1);
            result += exercice.Annee.PadLeft(4, '0');
            result += Page.ToString().PadLeft(3, '0');
            result += Ligne.ToString().PadLeft(2, '0');
            result += NumeroCnss.PadLeft(8, '0');
            result += CleCnss.PadLeft(2, '0');
            string identite = (Prenom.Trim() + " " + AutresNom.Trim() + " " + Nom.Trim() + " " + NomJeuneFille.Trim());

            result += Helper.StrTr(identite.PadRight(60)).ToUpper();
            result += Cin.PadLeft(8, '0');
            decimal total = Brut1 + Brut2 + Brut3;

            result += ((double)(total * 1000)).ToString("0").PadLeft(10, '0');
            result += string.Empty.PadLeft(10, '0');

            if (result.Length != 122)
            {
                throw new InvalidOperationException(
                          "Le nombre de caractère est invalide! Année [" + exercice + "] Trimestre " +
                          declaration.Trimestre);
            }

            return(result);
        }
Exemplo n.º 2
0
        public void GetPropertyError(string propertyName, ErrorInfo info)
        {
            var         regNumber        = new Regex(@"^\d+$");
            var         regName          = new Regex(@"^[\ a-zA-Z\'\.]+$");
            CultureInfo culture          = Thread.CurrentThread.CurrentCulture;
            string      decimalSeparator = culture.NumberFormat.NumberDecimalSeparator;

            //******* Verify Nom ***********
            if (propertyName == "Nom")
            {
                if (string.IsNullOrEmpty(Nom.Trim()))
                {
                    info.ErrorText = "Le champs [Nom] est obligatoire!";
                    info.ErrorType = ErrorType.Critical;
                }
                else
                {
                    if (!regName.IsMatch(Nom.Trim()))
                    {
                        info.ErrorText = "Le champs [Nom] est invalide!";
                        info.ErrorType = ErrorType.Critical;
                    }
                }
            }
            //******* Verify Prenom ***********
            if (propertyName == "Prenom")
            {
                if (string.IsNullOrEmpty(Prenom.Trim()))
                {
                    info.ErrorText = "Le champs [Prenom] est obligatoire!";
                    info.ErrorType = ErrorType.Critical;
                }
                else
                {
                    if (!regName.IsMatch(Prenom.Trim()))
                    {
                        info.ErrorText = "Le champs [Prénom] est invalide!";
                        info.ErrorType = ErrorType.Critical;
                    }
                }
            }
            //******* Verify CIN ***********
            if (propertyName == "Cin")
            {
                if (string.IsNullOrEmpty(Cin.Trim()))
                {
                    info.ErrorText = "Le champs [Cin] est obligatoire!";
                    info.ErrorType = ErrorType.Critical;
                }
                else
                {
                    if (Cin.Length > 8)
                    {
                        info.ErrorText = "Le champs [Cin] est invalide!";
                        info.ErrorType = ErrorType.Critical;
                    }
                    else
                    {
                        if (Cin.Length < 8)
                        {
                            Cin = Cin.Trim().PadLeft(8, '0');
                        }
                        var rgxCin = new Regex(@"[0-9]{8}");
                        if (!rgxCin.IsMatch(Cin))
                        {
                            info.ErrorText = "Le champs [Cin] est invalide!";
                            info.ErrorType = ErrorType.Critical;
                        }
                    }
                }
            }
            //******** Verify Civilite **********
            if (propertyName == "Civilite" && (CiviliteNo < 0 || CiviliteNo > 2))
            {
                info.ErrorText = "Le champs [Civilité] est invalide!";
                info.ErrorType = ErrorType.Critical;
            }

            //******* Verify Autres nom ********
            if (propertyName == "AutresNom" &&
                !regName.IsMatch(AutresNom.Trim()) &&
                AutresNom.Trim() != string.Empty)
            {
                info.ErrorText = "Le champs [Autres nom] est invalide!";
                info.ErrorType = ErrorType.Critical;
            }

            //******* Verify NomJeuneFille ********
            if (propertyName == "NomJeuneFille")
            {
                if (!string.IsNullOrEmpty(NomJeuneFille.Trim()) && !regName.IsMatch(NomJeuneFille.Trim()))
                {
                    info.ErrorText = "Le champs [Nom de jeune fille] est invalide!";
                    info.ErrorType = ErrorType.Critical;
                }
            }

            //******* Verify BrutA ********
            if (propertyName == "BrutA")
            {
                if (BrutA < 0)
                {
                    info.ErrorText = "BrutA invalide! ";
                    info.ErrorType = ErrorType.Critical;
                }
            }

            //******* Verify BrutB ********
            if (propertyName == "BrutB")
            {
                if (BrutB < 0)
                {
                    info.ErrorText = "BrutB invalide! ";
                    info.ErrorType = ErrorType.Critical;
                }
            }

            //******* Verify BrutC ********
            if (propertyName == "BrutC")
            {
                if (BrutC < 0)
                {
                    info.ErrorText = "BrutC invalide! ";
                    info.ErrorType = ErrorType.Critical;
                }
            }
            //******* Verify Matricule ********
            if (propertyName == "NumeroCnss")
            {
                if (string.IsNullOrEmpty(NumeroCnss.Trim()) ||
                    NumeroCnss.Length > 8 ||
                    !regNumber.IsMatch(NumeroCnss.Trim()))
                {
                    info.ErrorText = "Numéro Cnss invalide! ";
                    info.ErrorType = ErrorType.Critical;
                }
                else
                {
                    NumeroCnss = NumeroCnss.PadLeft(8, '0');
                }
            }
            //******* Verify Cle ********
            if (propertyName == "CleCnss")
            {
                if (string.IsNullOrEmpty(CleCnss.Trim()) ||
                    CleCnss.Length > 2 ||
                    !regNumber.IsMatch(CleCnss.Trim()))
                {
                    info.ErrorText = "Clé Cnss invalide! ";
                    info.ErrorType = ErrorType.Critical;
                }
                else
                {
                    CleCnss = CleCnss.PadLeft(2, '0');
                }
            }
            //******* Verify matricule interne ********
            if (propertyName == "Matricule")
            {
                if (string.IsNullOrEmpty(Matricule.Trim()) ||
                    Matricule.Trim().Length > 10 ||
                    !regNumber.IsMatch(Matricule.Trim()))
                {
                    info.ErrorText = "Matricule interne invalide! ";
                    info.ErrorType = ErrorType.Critical;
                }
            }
            //******* Verify Type cnss  ********
            if (propertyName == "TypeCnss")
            {
                if (TypeCnss > 19 || TypeCnss < 0)
                {
                    info.ErrorText = "Type cnss invalide! ";
                    info.ErrorType = ErrorType.Critical;
                }
            }
            //******* Situation familiale  ********
            if (propertyName == "SituationFamille")
            {
                if (SituationFamilleNo > 8 || SituationFamilleNo < 0)
                {
                    info.ErrorText = "Situation familiale invalide! ";
                    info.ErrorType = ErrorType.Critical;
                }
            }
        }
Exemplo n.º 3
0
        public bool IsValide()
        {
            bool        isValid          = true;
            var         regNumber        = new Regex(@"^\d+$");
            var         regName          = new Regex(@"^[\ a-zA-Z\'\.]+$");
            CultureInfo culture          = Thread.CurrentThread.CurrentCulture;
            string      decimalSeparator = culture.NumberFormat.NumberDecimalSeparator;

            Matricule  = Matricule.Trim();
            CleCnss    = CleCnss.Trim();
            NumeroCnss = NumeroCnss.Trim();
            Nom        = Nom.Trim();
            Prenom     = Prenom.Trim();

            //******* Verify Nom ***********

            if (string.IsNullOrEmpty(Nom))
            {
                return(false);
            }
            if (!regName.IsMatch(Nom))
            {
                return(false);
            }

            //******* Verify Prenom ***********

            if (string.IsNullOrEmpty(Prenom))
            {
                return(false);
            }
            if (!regName.IsMatch(Prenom))
            {
                return(false);
            }

            //******* Verify CIN ***********

            if (string.IsNullOrEmpty(Cin))
            {
                return(false);
            }
            if (Cin.Length > 8)
            {
                return(false);
            }
            if (Cin.Length < 8)
            {
                Cin = Cin.Trim().PadLeft(8, '0');
            }
            var rgxCin = new Regex(@"[0-9]{8}");

            if (!rgxCin.IsMatch(Cin))
            {
                return(false);
            }

            //******** Verify Civilite **********
            if (CiviliteNo < 0 || CiviliteNo > 2)
            {
                return(false);
            }

            //******* Verify Autres nom ********
            if (!regName.IsMatch(AutresNom) && AutresNom.Trim() != string.Empty)
            {
                return(false);
            }

            //******* Verify NomJeuneFille ********

            if (!string.IsNullOrEmpty(NomJeuneFille) && !regName.IsMatch(NomJeuneFille.Trim()))
            {
                return(false);
            }

            //******* Verify BrutA ********

            string brutAtStr = BrutAStr
                               .Replace(",", decimalSeparator)
                               .Replace(".", decimalSeparator);
            decimal brutA;

            if (!decimal.TryParse(brutAtStr, out brutA))
            {
                return(false);
            }
            if (brutA < 0)
            {
                return(false);
            }

            //******* Verify BrutB ********

            string brutBtStr = BrutBStr
                               .Replace(",", decimalSeparator)
                               .Replace(".", decimalSeparator);
            decimal brutB;

            if (!decimal.TryParse(brutBtStr, out brutB))
            {
                return(false);
            }
            if (brutB < 0)
            {
                return(false);
            }

            //******* Verify BrutC ********

            string brutCtStr = BrutCStr
                               .Replace(",", decimalSeparator)
                               .Replace(".", decimalSeparator);
            decimal brutC;

            if (!decimal.TryParse(brutCtStr, out brutC))
            {
                return(false);
            }
            if (brutC < 0)
            {
                return(false);
            }

            //******* Verify Matricule ********
            if (NumeroCnss.Trim().Length < 8)
            {
                NumeroCnss = NumeroCnss.Trim().PadLeft(8, '0');
            }
            if (string.IsNullOrEmpty(NumeroCnss) ||
                NumeroCnss.Length > 8 ||
                !regNumber.IsMatch(NumeroCnss))
            {
                return(false);
            }

            //******* Verify Cle ********
            if (CleCnss.Trim().Length < 2)
            {
                CleCnss = CleCnss.Trim().PadLeft(2, '0');
            }
            if (string.IsNullOrEmpty(CleCnss) ||
                CleCnss.Length > 2 ||
                !regNumber.IsMatch(CleCnss))
            {
                return(false);
            }

            //******* Verify matricule interne ********

            if (string.IsNullOrEmpty(Matricule) ||
                Matricule.Length > 10 ||
                !regNumber.IsMatch(Matricule))
            {
                return(false);
            }

            //******* Verify Type cnss  ********

            if (TypeCnss > 19 || TypeCnss < 0)
            {
                return(false);
            }

            //******* Situation familiale  ********

            if (SituationFamilleNo > 8 || SituationFamilleNo < 0)
            {
                return(false);
            }
            return(true);
        }