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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
| using System;
using System.Collections;
using System.Data;
using System.Data.Common;
using System.Data.OleDb;
using System.Windows.Forms;
using Spigraph.SpiLib;
using Spigraph.Click2Data;
// Ne pas changer le nom de la classe ainsi que celui de la méthode statique principale
class SpiScript {
const string PATH_EXCEL_DATABASE = @"C:\Documents and Settings\Administrateur\Bureau\base-indexation-V2-02.mdb";
public int Main(ScriptsInterface c2d)
{
try{
//SpiLog.LogMessage(SpiMessages.InfoScript, "DEBUT OnClick("+c2d.FieldName+")" , "Script_externe C#", "SpiScript.Main()"); //AVIRER
MessageBox.Show("Here Main 1");
DataControl dc = null;
switch( c2d.FieldName )
{
case "PB_Search" :
Search(c2d) ;
break;
case "LW_Result" :
OnSelect(c2d);
break;
case "PB_MODIF_DATE_BULLETIN":
//Permettre le changement de la date : débloquer le Controle
c2d.ControlSetReadOnly("DATE_BULLETIN", false);
//blocage du PB
dc = c2d.GetDataControl("PB_MODIF_DATE_BULLETIN");
dc.ControlWinForms.Enabled = false;
break;
case "PB_MODIF_MOIS" :
//Permettre le changement de la date : débloquer le Controle
c2d.ControlSetReadOnly("MOIS", false);
//blocage du PB
dc = c2d.GetDataControl("PB_MODIF_MOIS");
dc.ControlWinForms.Enabled = false;
break;
case "PB_AJOUT_BDD" :
InsertInDataBase(c2d);
break;
MessageBox.Show("Here Main 2");
}//switch()
return 0; //OK
}
catch(Exception ex)
{
System.Diagnostics.EventLog.WriteEntry( "CLICK2DATA", "Script OnClick - Exception : "+ex.Message, System.Diagnostics.EventLogEntryType.Error);
return -1;
MessageBox.Show("Here Main Exception");
}
}//Main()
/// <summary>
/// Recherche multi-critere dans la BDD Excel en fonction des valeurs du formulaire
/// </summary>
private void Search(ScriptsInterface c2d)
{
//SpiLog.LogMessage(SpiMessages.InfoScript, "DEBUT Search()" , "Script_externe C#", "SpiScript.Main()"); //AVIRER
DataControl lw = c2d.GetDataControl("LW_Result");
lw.DeleteRows(); //RAZ
//Acquisition des critères de recherche à partir des champs du formullaire
String sNom = c2d.ControlGetValue("Nom" );
String sPrenom = c2d.ControlGetValue("PRENOM" );
String sNumSS = c2d.ControlGetValue("NUMSS" );
String sMatricule = c2d.ControlGetValue("Matricule" );
//String sCivilite = c2d.ControlGetValue("CIVILITE" );
MessageBox.Show("Here Search Acquisition");
//SpiLog.LogMessage(SpiMessages.InfoScript, "Search() Nom"+sNom+", Prenom="+sPrenom+", NumSS="+sNumSS+", Matricule="+sMatricule+", "Script_externe C#", "SpiScript.Main()"); //AVIRER
//Recherche dans la Feuille ACCESS
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" +PATH_EXCEL_DATABASE;
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
int iNbr = 0;
using (DbConnection connection = factory.CreateConnection())
{
connection.ConnectionString = connectionString;
using (DbCommand command = connection.CreateCommand())
{
command.CommandText = "SELECT NumeroSS, Matricule, Civilite, Nommarital, Prenom, Nompatronymique FROM [BASE-SG-COMPLET-Avec matricule]";
MessageBox.Show("Here Search Selection");
string sWhere = "";
if( !String.IsNullOrEmpty(sNom) )
{
if( !String.IsNullOrEmpty(sWhere) ) sWhere += " AND ";
sWhere += " ( [BASE-SG-COMPLET-Avec matricule].Nompatronymique = '" + sNom + "' OR [BASE-SG-COMPLET-Avec matricule].Nommarital = '" + sNom + "' )";
MessageBox.Show("Here sWhereNom"+sWhere);
}
if( !String.IsNullOrEmpty(sPrenom) )
{
if( !String.IsNullOrEmpty(sWhere) ) sWhere += " AND ";
sWhere += " [BASE-SG-COMPLET-Avec matricule].Prenom LIKE '%"+sPrenom+"%' ";
MessageBox.Show("Here sWherePre"+sWhere);
}
if( !String.IsNullOrEmpty(sNumSS) )
{
if( !String.IsNullOrEmpty(sWhere) ) sWhere += " AND ";
sWhere += " [BASE-SG-COMPLET-Avec matricule].NumeroSS LIKE '"+sNumSS+"%' ";
MessageBox.Show("Here sWhereNum"+sWhere);
}
if( !String.IsNullOrEmpty(sMatricule) )
{
if( !String.IsNullOrEmpty(sWhere) ) sWhere += " AND ";
sWhere += " [BASE-SG-COMPLET-Avec matricule].Matricule LIKE '%"+sMatricule+"' ";
MessageBox.Show("Here sWhereMat"+sWhere);
}
//ExecuteSQLFetch{Xls}(" SELECT * From [Feuil1$] WHERE [Feuil1$].NOM LIKE '%DUPONT%' ")
if( !String.IsNullOrEmpty(sWhere) )
command.CommandText += " WHERE " + sWhere ;
c2d.ShowInfoMessage(String.Format("REQUETE" + sNom + ","+ sPrenom + ","+ sNumSS + ","+ sMatricule));
connection.Open();
MessageBox.Show("Here Search Connection");
using (DbDataReader dr = command.ExecuteReader())
{
while (dr.Read())
{ //Ajoute les éléments trouvés dans la ListView
string[] arRows = { dr["Civilite"].ToString(), dr["Nompatronymique"].ToString(), dr["Prenom"].ToString(), FormatNumSS( dr["NumeroSS"].ToString() ), dr["Matricule"].ToString() } ;
lw.AddRow( dr["Matricule"].ToString(), arRows );
iNbr++;
MessageBox.Show("Here Search Ajout");
}
}
}
}
if( iNbr < 1 )
{ //Rien trouvé
SpiMisc.PlaySound(@"C:\windows\media\Ding.wav");
}
}//Search()
private string FormatNumSS( string a_numSS )
{
if( String.IsNullOrEmpty(a_numSS) )
return "" ;
string sTmp = a_numSS.Replace(" ", ""); //suppression d'éventuel espace
if (sTmp.Length < 13)
return sTmp;
//Passage du format 011335577700033 à 1 99 88 77 666 555 44
String sNumSS = sTmp.Substring(0, 1) + " " + sTmp.Substring(1, 2) + " " + sTmp.Substring(3, 2) + " " + sTmp.Substring(5, 2) + " " + sTmp.Substring(7, 3) + " " + sTmp.Substring(10, 3);
if (sTmp.Length < 15)
return sNumSS;
sNumSS = sNumSS + " " + sTmp.Substring(13, 2);
return sNumSS;
}
/// <summary>
/// Actions réalisées sur la sélection d'une ligne de la ListView
/// </summary>
private void OnSelect(ScriptsInterface c2d)
{
DataControl lw = c2d.GetDataControl("LW_Result");
int iNbrRows = lw.GetRowCount();
int iRowSelected = lw.GetRowSelected();
String sTag = (String) lw.GetRowTag( iRowSelected >=0 ? iRowSelected : iNbrRows-1 );
//c2d.ControlSetValue("EF_IDCLIENT", sTag);
//c2d.ShowInfoMessage( String.Format( "La ListView contient {0} lignes. La ligne {1} est sélectionnée. Son Tag a la valeur '{2}'", iNbrRows, iRowSelected, sTag ) ); //DEBUG
MessageBox.Show("Here Select");
//Acquisition des autres champs
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())
{
command.CommandText = "SELECT NumeroSS, Matricule, Civilite, Nommarital, Prenom, Nompatronymique FROM [BASE-SG-COMPLET-Avec matricule] WHERE [BASE-SG-COMPLET-Avec matricule].Matricule = '"+sTag +"' " ;
//c2d.ShowInfoMessage( String.Format( "REQUETE SQL : {0}.", command.CommandText ) ); //AVIRER POUR DEBUG
connection.Open();
MessageBox.Show("Here Select Connection");
using (DbDataReader dr = command.ExecuteReader())
{
if( dr.Read() )
{
c2d.ControlSetValue("Nom", dr["Nompatronymique"].ToString());
c2d.ControlSetValue("PRENOM", dr["Prenom"].ToString());
c2d.ControlSetValue("NUMSS", dr["NumeroSS"].ToString());
c2d.ControlSetValue("Matricule", dr["Matricule"].ToString());
//c2d.ControlSetValue("CIVILITE", dr["Civilite"].ToString());
MessageBox.Show("Here Select Acquisition");
}
}
}
}
c2d.ControlSetFocus("GUICHET");//SetFocus sur le champ suivant
}//OnSelect()
/// <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
{
MessageBox.Show("Here Ajout 1");
if(sNumSS.Length!=15)
{
MessageBox.Show("Numéro SS ERRONE, veuillez mettre 15 chiffres justes, bande de boulets!!!");
}
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()))
{
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=v1-(v5*10);
int v9=v1-(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;
return cle;
}
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+"' ) ;";
connection.Open();
int nbrLgnAffected = command.ExecuteNonQuery();
//c2d.ShowInfoMessage(String.Format("REQUETE NBR=" + nbrLgnAffected.ToString() + " pour SQL : {0}.", command.CommandText)); //AVIRER POUR DEBUG //ligne 260
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");
}//SS
}//Length
}//Equals
}//command
}//connection
}//InsertInDataBase()
}//Class |
Partager