1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
| /// <summary>
/// Création d'une ligne SALARIE dans la BDD Access à partir des infos du formulaire
/// </summary>
private void InsertInDataBase(ScriptsInterface c2d)
{
//SpiLog.LogMessage(SpiMessages.InfoScript, "DEBUT InsertInDataBase()" , "Script_externe C#", "SpiScript.Main()"); //AVIRER
//Acquisition des critères de recherche à partir des champs du formulaire
String sNumSS = c2d.ControlGetValue("NUMSS");
String sMatricule = c2d.ControlGetValue("Matricule");
String sNom = c2d.ControlGetValue("Nom");
String sPrenom = c2d.ControlGetValue("PRENOM");
//String sCivilite = c2d.ControlGetValue("CIVILITE");
//SpiLog.LogMessage(SpiMessages.InfoScript, "Search() Nom"+sNom+", Prenom="+sPrenom+", NumSS="+sNumSS+", Matricule="+sMatricule+", Civilite="+sCivilite+"." , "Script_externe C#", "SpiScript.Main()"); //AVIRER
//Controle zones obligatoires : NOM + PRENOM
if (String.IsNullOrEmpty(sNom.Trim()))
{
System.Windows.Forms.MessageBox.Show("La zone 'Nom' doit être renseignée", "Zone obligatoire", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
c2d.ControlSetFocus("NOM");//SetFocus sur le champ
return;
}
if (String.IsNullOrEmpty(sPrenom.Trim()))
{
System.Windows.Forms.MessageBox.Show("La zone 'Prénom' doit être renseignée", "Zone obligatoire", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
c2d.ControlSetFocus("PRENOM");//SetFocus sur le champ
return;
}
//Insert dans la Feuille ACCESS
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + PATH_EXCEL_DATABASE;
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
using (DbConnection connection = factory.CreateConnection())
{
connection.ConnectionString = connectionString;
using (DbCommand command = connection.CreateCommand())
{
if(sNom.Equals("") || sNumSS.Equals("") || sPrenom.Equals("") || sMatricule.Equals(""))
{
MessageBox.Show("Remplissez les champs vides");
}
else
{
if(!IsString(sNom)||!IsString(sPrenom)||!IsNumeric(sNumSS)||!IsNumeric(sMatricule))
{
MessageBox.Show("Vérifiez le formulaire, Lettre dans Numéro SS ou Matricule ou Chiffre dans le Nom ou le Prénom ");
}
else
{
//MessageBox.Show("Here Ajout 1");
if(sNumSS.Length!=15)
{
MessageBox.Show("Numéro SS ERRONE, veuillez mettre 15 chiffres justes!");
}
else
{
MessageBox.Show("Here Ajout 2");
String varcless = sNumSS.Substring(13, 2);
String CorpsSS = sNumSS.Substring(0, 13);
long CorpsSSInt=0;
try{
CorpsSSInt = Convert.ToInt64(CorpsSS);}catch(Exception e){MessageBox.Show("erreur:"+e);}
int varclecalc = 97 - (int)(CorpsSSInt % 97);
MessageBox.Show(varcless+";"+varclecalc.ToString());//ligne 261
//Vérifie si le numéro de sécurité sociale est juste
if (varcless.Equals(varclecalc.ToString()))
{
if(sMatricule.Length!=7)
{
MessageBox.Show("Numéro Matricule ERRONE, veuillez mettre 7 chiffres justes!");
}
else
{
String A = sMatricule.Substring(0, 1);//ligne 266
String B = sMatricule.Substring(1, 1);
String C = sMatricule.Substring(2, 1);
String D = sMatricule.Substring(3, 1);
String E = sMatricule.Substring(4, 1);
String F = sMatricule.Substring(5, 1);
int AM=0;
try{
AM = Convert.ToInt32(A);}catch(Exception e){MessageBox.Show("erreur:"+e);}
int BM=0;
try{
BM = Convert.ToInt32(B);}catch(Exception e){MessageBox.Show("erreur:"+e);}
int CM=0;
try{
CM = Convert.ToInt32(C);}catch(Exception e){MessageBox.Show("erreur:"+e);}
int DM=0;
try{
DM = Convert.ToInt32(D);}catch(Exception e){MessageBox.Show("erreur:"+e);}
int EM=0;
try{
EM = Convert.ToInt32(E);}catch(Exception e){MessageBox.Show("erreur:"+e);}
int FM=0;
try{
FM = Convert.ToInt32(F);}catch(Exception e){MessageBox.Show("erreur:"+e);}//ligne 290
int v1=2*BM;
int v2=2*DM;
int v3=2*FM;
int v4=(v1/10);
int v5=(v2/10);
int v6=(v3/10);
int v7=v1-(v4*10);
int v8=v2-(v5*10);
int v9=v3-(v6*10);
int somme=AM+CM+EM+v4+v5+v6+v7+v8+v9;
int cle=10-(somme-(somme/10)*10);
if(cle==10)
{
cle=0;
}
String Mat = sMatricule.Substring(6, 1);
int M=0;
try{
M = Convert.ToInt32(Mat);}catch(Exception e){MessageBox.Show("erreur:"+e);}//ligne 318
//Vérifie si le numéro de Matricule est juste
if(M==cle)
{
command.CommandText = "INSERT INTO [BASE-SG-COMPLET-Avec matricule] (NumeroSS, Matricule, Civilite, Nommarital, Nompatronymique, Prenom) VALUES('"+sNumSS +"','"+ sMatricule+"','x','"+sNom+"','"+sNom+"','"+sPrenom+"' ) ;";
int nbrLgnAffected=0;
try{connection.Open();
nbrLgnAffected = command.ExecuteNonQuery();}catch(Exception e){MessageBox.Show("erreur:"+e);}
//c2d.ShowInfoMessage(String.Format("REQUETE NBR=" + nbrLgnAffected.ToString() + " pour SQL : {0}.", command.CommandText)); //AVIRER POUR DEBUG
if (nbrLgnAffected != 1)
{
//TODO: Trace Event
System.Windows.Forms.MessageBox.Show("ERREUR SUR AJOUT DANS BDD (" + nbrLgnAffected.ToString() + ")", "Erreur BDD", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
MessageBox.Show("AJOUT DANS BDD REUSSI");
}
else
{
MessageBox.Show("Numéro de Matricule Erroné, veuillez saisir le vrai Numéro");
}//Matricule
}
}
else
{
MessageBox.Show("Numéro de Sécurité Sociale Erroné, veuillez saisir le vrai Numéro"); //ligne 342
}//SS
}//Length
}//IsString
}//Equals
}//command
}//connection
}//InsertInDataBase() |
Partager