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
|
--une classe pour charger mes parametres,
public static class Utils_Load_Parametrage
{
static string strChaine = string.Empty;
public static DataSet Load_Parametre(int param)
{
DataSet ds = new DataSet();
switch (param)
{
case 1:
strChaine = "TypeTitre";
break;
case 2:
strChaine = "Categorie";
break;
case 3:
strChaine = "Nationalite";
break;
case 4:
strChaine = "PosteID";
break;
}
ds = ExecuteRequeteParam.ACTIONExecuteRequeteRetourneDataSetText( strChaine );
strChaine = string.Empty;
return ds;
}
public static bool Create_Dossier(string DOS_ID, string PID_CODE, string TIT_CODE, string NAT_CODE, string DOS_NOBR, string DOS_NODE, decimal DOS_VERSEMENT, string DOS_TYDE, string DOS_NOPREC, string DOS_NOM, string DOS_PRENOM, System.DateTime DOS_DDN, string DOS_SEX, string DOS_LNAIS, string DOS_CONTACT, string DOS_NPERE, string DOS_NMERE, string DOS_PROF, int DOS_TAILLE, string DOS_LRED, System.DateTime DOS_DTEN, string CAT_CODE)
{
strChaine = "INSERT INTO CSR_DOSSIER ( DOS_ID," + "PID_CODE," + "TIT_CODE," + "NAT_CODE," + "DOS_NOBR," + "DOS_NODE," + "DOS_VERSEMENT," + "DOS_TYDE," + "DOS_NOPREC," + "DOS_NOM," + "DOS_PRENOM," + "DOS_DDN," + "DOS_SEX," + "DOS_LNAIS," + "DOS_CONTACT," + "DOS_NPERE," + "DOS_NMERE," + "DOS_PROF," + "DOS_TAILLE," + "DOS_LRED," + "DOS_DTEN," + "CAT_CODE)" + "VALUES(@DOS_ID, @PID_CODE," + "@TIT_CODE," + "@NAT_CODE," + "@DOS_NOBR," + "@DOS_NODE," + "@DOS_VERSEMENT," + "@DOS_TYDE," + "@DOS_NOPREC," + "@DOS_NOM," + "@DOS_PRENOM," + "@DOS_DDN," + "@DOS_SEX," + "@DOS_LNAIS," + "@DOS_CONTACT," + "@DOS_NPERE," + "@DOS_NMERE," + "@DOS_PROF," + "@DOS_TAILLE," + "@DOS_LRED," + "@DOS_DTEN," + "@CAT_CODE)";
ExecuteRequeteParam.ACTIONExecuteRequeteSansRetourText(strChaine);
strChaine = string.Empty;
return true;
}
}
}
2- une classe qui execute les requetes
public static class ExecuteRequeteParam
{ //initialisation de la connexion à la base de données SQL Server
private static SqlConnection m_Connexion;
//déclaration de l'objet command
private static SqlCommand m_commande;
/// Instancier et initialiser les objets de connecxion
public static void InitConnexionMobileText()
{
try
{
//instancier l'objet de connexion
m_Connexion = new SqlConnection(Prj_RECLACSR.Properties.Settings .Default .cnStr );
//Ouvrir la connexion à la bd
m_Connexion.Open();
//creer la commande et indiquer le type de commande
m_commande = m_Connexion.CreateCommand();
m_commande.CommandType = CommandType.Text;
}
catch (Exception ex)
{
//lever une exception et l'ecrire dans le journal d'événement windows
EventLog.GetEventLogs(ex.Message );
}
}
/// Ferme la connexion à la base de données et libere les ressources
public static void Dispose()
{
m_commande.Dispose();
m_Connexion.Close();
m_commande = null;
m_Connexion = null;
}
#region "Fonctions d'aide - Requetes dynamiques mode texte"
public static void ACTIONExecuteRequeteSansRetourText(string chaineSql)
{
InitConnexionMobileText();
m_commande.CommandText = chaineSql;
try
{
m_commande.ExecuteNonQuery();
}
catch (Exception ex)
{
// ReSharper disable PossibleIntendedRethrow
throw ex;
// ReSharper restore PossibleIntendedRethrow
}
finally
{
Dispose();
}
}
/// Exécute une requete sql dynamique et retroune un dataset
public static DataSet ACTIONExecuteRequeteRetourneDataSetText(string chaineSql)
{
InitConnexionMobileText();
m_commande.CommandText = chaineSql;
try
{
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(m_commande);
da.Fill(ds);
return ds;
}
catch (Exception ex)
{
throw ex;
}
finally
{
Dispose();
}
}
#endregion
}
3- une classe qui gere diverses fonction
"la j ai creer une nouvelle instance de formulaire afin d avoir accces au controle a renseigner, mais lors de l appel effectivement ceci ne se voit pas"
public static class Utils_Proc_Func
{
public static void Call_Parametres()
{
using (F_Main unForm = new F_Main())
{
//Les titres
DataSet dsTitre = new DataSet();
dsTitre = Utils_Load_Parametrage.Load_Parametre(1);
for (int i = 0; i <= dsTitre.Tables[0].Rows.Count - 1; i++)
{
unForm.cbTITRE.Items.Add(dsTitre.Tables[0].Rows[i][1].ToString());
}
//Les categories
// ReSharper disable RedundantAssignment
DataSet dsCategorie = new DataSet();
// ReSharper restore RedundantAssignment
dsCategorie = Utils_Load_Parametrage.Load_Parametre(2);
for (int j = 0; j <= dsCategorie.Tables[0].Rows.Count - 1; j++)
{
unForm.cbCat.Items.Add(dsCategorie.Tables[0].Rows[j][0].ToString());
}
//Les nationalites
DataSet dsNationalite = new DataSet();
dsNationalite = Utils_Load_Parametrage.Load_Parametre(3);
for (int k = 0; k <= dsNationalite.Tables[0].Rows.Count - 1; k++)
{
unForm.cbNat.Items.Add(dsNationalite.Tables[0].Rows[k][1].ToString());
}
//Les Postes d'identification
DataSet dsPosteId = new DataSet();
dsPosteId = Utils_Load_Parametrage.Load_Parametre(4);
for (int l = 0; l <= dsPosteId.Tables[0].Rows.Count - 1; l++)
{
unForm.cbPI.Items.Add(dsPosteId.Tables[0].Rows[l][0].ToString());
}
}
}
public static void DisplayLibellePI (string paramPI)
// ReSharper restore InconsistentNaming
{
DataRow drPiParam = null;
drPiParam = Find_PI(paramPI);
unForm.Label_PI.Text = drPiParam[1].ToString(); "ici j ai deja une erreur"
}
}
4- l appel de la fonction dans le formulaire F_main
private void F_Main_Load(object sender, EventArgs e)
{
Utils_Proc_Func.Call_Parametres();
} |
Partager