1
Code C#.Net : Connexion. 2021/2022 Formateur : L.KARIM.
{
sw = 1;
}
}
if (sw == 0)
{
if (ID.Text != "" && NOM.Text != "" && PRENOM.Text != "")
{
BD.NewLigne = BD.dtset.Tables["TADH"].NewRow();
BD.NewLigne[0] = ID.Text;
BD.NewLigne[1] = NOM.Text;
BD.NewLigne[2] = PRENOM.Text;
BD.dtset.Tables["TADH"].Rows.Add(BD.NewLigne);
BD.CmdBuild = new SqlCommandBuilder(BD.dtadapter);
BD.dtadapter.InsertCommand = BD.CmdBuild.GetInsertCommand();
BD.dtadapter.Update(BD.dtset, "TADH");
MessageBox.Show("Ajout Avec Succes");
// BD.DECONNECTER();
}
else
{
MessageBox.Show("Vous Devez Remplir Tous Les Champs SVP");
}
}
else
{
MessageBox.Show("Référence Existe Déjà");
}
}
Recherche Unique (Quatre Méthodes)
Codes Recherché (Consultation)
L’application et la base de données
Méthode 1 : Contrôle TextBox (Bouton Evénement Click)
int sw = 0;
if (ID.Text != "")
{
for (int s = 0; s <= this.G1.RowCount - 2; s++)
{
if (ID.Text == this.G1.Rows[s].Cells[0].Value.ToString())
{
ID.Text = this.G1.Rows[s].Cells[0].Value.ToString();
NOM.Text = this.G1.Rows[s].Cells[1].Value.ToString();
PRENOM.Text = this.G1.Rows[s].Cells[2].Value.ToString();
MemoryStream ms = new MemoryStream((byte[])this.G1.Rows[s].Cells[3].Value);
pictureBox1.Image = Image.FromStream(ms);
sw = 1;
}
}
if (sw == 0)
{
MessageBox.Show("ID Introuvable");
}
}
else
{
MessageBox.Show("Vous Devez Remplir ID");
}
string a;
a = Interaction.InputBox("entrer l'id a rechercher");
2
Code C#.Net : Connexion. 2021/2022 Formateur : L.KARIM.
for (int s = 0; s <= this.G1.RowCount - 2; s++)
{
if (a == this.G1.Rows[s].Cells[0].Value.ToString())
{
ID.Text = this.G1.Rows[s].Cells[0].Value.ToString();
NOM.Text = this.G1.Rows[s].Cells[1].Value.ToString();
PRENOM.Text = this.G1.Rows[s].Cells[2].Value.ToString();
MemoryStream ms = new MemoryStream((byte[])this.G1.Rows[s].Cells[3].Value);
pictureBox1.Image = Image.FromStream(ms);
sw = 1;
}
}
if (sw == 0)
{
MessageBox.Show("ID Introuvable");
}
bool SW = false;
3
Code C#.Net : Connexion. 2021/2022 Formateur : L.KARIM.
BD.dtset.Tables["TADH"].Rows[i][3] = imageToByteArray(this.pictureBox1.Image);
Random rnd;
int number;
rnd = new Random();
number = rnd.Next(999, 10000);
BD.dtset.Tables["TADH"].Rows[i][4] = number.ToString();
BD.CmdBuild = new SqlCommandBuilder(BD.dtadapter);
BD.dtadapter.UpdateCommand= BD.CmdBuild.GetUpdateCommand();
BD.dtadapter.Update(BD.dtset, "TADH");
MessageBox.Show("Employé Modifié Avec Succès");
break;
}
}
if (SW == false)
{
MessageBox.Show("ID NON VALIDE");
}
Codes Suppression (Bouton Suppression)
L’application et la base de données
if (ID.Text == "")
{
MessageBox.Show("Merci de Saisir ID");
return;
}
bool SW = false;
4
Code C#.Net : Connexion. 2021/2022 Formateur : L.KARIM.
msg.Body = "un Simple Test";
client.Send(msg);
MessageBox.Show("Mail Envoyé");
Exploitation Photo Dans une Table & Interface
AJOUT & MODIFICATION
Phase 1
Insérer un Champ Dans la Table Avec Type Varbinary(Max)
Phase 2 Code à Insérer au début de la Page de Codes.
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
Phase 3Code à InsérerForm_Load
N.B. :Avant d’insérer ce bloc de codes veuillez spécifier au niveau propriètés une image de BackgroundImage au
contrôle PictureBox1
pictureBox1.Image = pictureBox1.BackgroundImage;
pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
Phase 4 Code à Insérer Bouton Enregistrer (Ajout + Modification)
BD.NewLigne[N° Champ] = imageToByteArray(this.pictureBox1.Image);
N.B. : imageToByteArray est une Fonction que vous devez la créer (Phase 5)
Phase 5 Fonction imageToByteArray
public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
return ms.ToArray();
}
Phase 6 Création de Bouton Parcourir
1. Insérer le Contrôle OpenFileDialog
2. Inserer le Bloc de Code Suivant (Bouton Parcourir)
this.openFileDialog1.FileName = "";
this.openFileDialog1.ShowDialog();
if (this.openFileDialog1.FileName !="")
this.pictureBox1.ImageLocation = this.openFileDialog1.FileName;
Exploitation Photo Dans une Table & Interface
RECHERCHE
MemoryStream ms = new MemoryStream((byte[])this.G1.Rows[N° Ligne].Cells[N° Champ].Value);
pictureBox1.Image = Image.FromStream(ms);
5
Code C#.Net : Connexion. 2021/2022 Formateur : L.KARIM.
}
}
Phase Classe
Création de la calsse de connexion (Exemple : CN_MID.CS)
Zone Importation
using MySql.Data.MySqlClient;
using System.Data