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
| #pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
namespace Stage_entreprise_C {
/// <summary>
/// Description résumée de FSaisie
///
/// AVERTISSEMENT*: si vous modifiez le nom de cette classe, vous devrez modifier la
/// propriété 'Nom du fichier de ressources' de l'outil de compilation de ressource managée
/// pour tous les fichiers .resx dont dépend cette classe. Dans le cas contraire,
/// les concepteurs ne pourront pas interagir correctement avec les ressources
/// localisées associées à ce formulaire.
/// </summary>
public ref class FSaisie : public System::Windows::Forms::Form
{
public:
FSaisie(void)
{
InitializeComponent();
//
//TODO*: ajoutez ici le code du constructeur
//
}
protected:
/// <summary>
//Déclaration des objets utilisés pour l'exemple avec le connecteur/NET
MySql::Data::MySqlClient::MySqlDataAdapter ^monAdaptateur;
//MySql::Data::MySqlClient::MySqlDataAdapter ^monAdaptateurDS;
MySql::Data::MySqlClient::MySqlCommand ^cmd;
MySql::Data::MySqlClient::MySqlConnection ^conn;
MySql::Data::MySqlClient::MySqlDataReader ^monReader;
System::Data::DataSet ^monDataSet;
private: System::Windows::Forms::Button^ b_envoyer;
private: System::Data::DataSet^ dS_entreprise;
protected:
System::Data::DataTable ^MaTable;
/// </summary>
~FSaisie()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::DataGridView^ dgw_saisiestage;
private: System::Windows::Forms::BindingSource^ bS_saisisentreprise;
private: System::ComponentModel::IContainer^ components;
protected:
private:
/// <summary>
/// Variable nécessaire au concepteur.
/// </summary>
#pragma region Windows Form Designer generated code
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
System::Windows::Forms::DataGridViewCellStyle^ dataGridViewCellStyle1 = (gcnew System::Windows::Forms::DataGridViewCellStyle());
System::Windows::Forms::DataGridViewCellStyle^ dataGridViewCellStyle2 = (gcnew System::Windows::Forms::DataGridViewCellStyle());
System::Windows::Forms::DataGridViewCellStyle^ dataGridViewCellStyle3 = (gcnew System::Windows::Forms::DataGridViewCellStyle());
this->dgw_saisiestage = (gcnew System::Windows::Forms::DataGridView());
this->bS_saisisentreprise = (gcnew System::Windows::Forms::BindingSource(this->components));
this->b_envoyer = (gcnew System::Windows::Forms::Button());
this->dS_entreprise = (gcnew System::Data::DataSet());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->dgw_saisiestage))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->bS_saisisentreprise))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->dS_entreprise))->BeginInit();
this->SuspendLayout();
//
// dgw_saisiestage
//
dataGridViewCellStyle1->Alignment = System::Windows::Forms::DataGridViewContentAlignment::MiddleLeft;
dataGridViewCellStyle1->BackColor = System::Drawing::SystemColors::Control;
dataGridViewCellStyle1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
dataGridViewCellStyle1->ForeColor = System::Drawing::SystemColors::WindowText;
dataGridViewCellStyle1->SelectionBackColor = System::Drawing::SystemColors::Highlight;
dataGridViewCellStyle1->SelectionForeColor = System::Drawing::SystemColors::HighlightText;
dataGridViewCellStyle1->WrapMode = System::Windows::Forms::DataGridViewTriState::True;
this->dgw_saisiestage->ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
this->dgw_saisiestage->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
dataGridViewCellStyle2->Alignment = System::Windows::Forms::DataGridViewContentAlignment::MiddleLeft;
dataGridViewCellStyle2->BackColor = System::Drawing::SystemColors::Window;
dataGridViewCellStyle2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
dataGridViewCellStyle2->ForeColor = System::Drawing::SystemColors::ControlText;
dataGridViewCellStyle2->SelectionBackColor = System::Drawing::SystemColors::Highlight;
dataGridViewCellStyle2->SelectionForeColor = System::Drawing::SystemColors::HighlightText;
dataGridViewCellStyle2->WrapMode = System::Windows::Forms::DataGridViewTriState::False;
this->dgw_saisiestage->DefaultCellStyle = dataGridViewCellStyle2;
this->dgw_saisiestage->Location = System::Drawing::Point(12, 24);
this->dgw_saisiestage->Name = L"dgw_saisiestage";
dataGridViewCellStyle3->Alignment = System::Windows::Forms::DataGridViewContentAlignment::MiddleLeft;
dataGridViewCellStyle3->BackColor = System::Drawing::SystemColors::Control;
dataGridViewCellStyle3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
dataGridViewCellStyle3->ForeColor = System::Drawing::SystemColors::WindowText;
dataGridViewCellStyle3->SelectionBackColor = System::Drawing::SystemColors::Highlight;
dataGridViewCellStyle3->SelectionForeColor = System::Drawing::SystemColors::HighlightText;
dataGridViewCellStyle3->WrapMode = System::Windows::Forms::DataGridViewTriState::True;
this->dgw_saisiestage->RowHeadersDefaultCellStyle = dataGridViewCellStyle3;
this->dgw_saisiestage->Size = System::Drawing::Size(560, 190);
this->dgw_saisiestage->TabIndex = 0;
this->dgw_saisiestage->CellContentClick += gcnew System::Windows::Forms::DataGridViewCellEventHandler(this, &FSaisie::dgw_saisiestage_CellContentClick);
//
// bS_saisisentreprise
//
this->bS_saisisentreprise->CurrentChanged += gcnew System::EventHandler(this, &FSaisie::bS_saisisentreprise_CurrentChanged);
//
// b_envoyer
//
this->b_envoyer->Location = System::Drawing::Point(229, 246);
this->b_envoyer->Name = L"b_envoyer";
this->b_envoyer->Size = System::Drawing::Size(75, 23);
this->b_envoyer->TabIndex = 1;
this->b_envoyer->Text = L"Envoyer";
this->b_envoyer->UseVisualStyleBackColor = true;
this->b_envoyer->Click += gcnew System::EventHandler(this, &FSaisie::b_envoyer_Click);
//
// dS_entreprise
//
this->dS_entreprise->DataSetName = L"monDataSet";
//
// FSaisie
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(806, 548);
this->Controls->Add(this->b_envoyer);
this->Controls->Add(this->dgw_saisiestage);
this->Name = L"FSaisie";
this->Text = L"Saisie adresse et entreprise";
this->Load += gcnew System::EventHandler(this, &FSaisie::FSaisie_Load);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->dgw_saisiestage))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->bS_saisisentreprise))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->dS_entreprise))->EndInit();
this->ResumeLayout(false);
}
#pragma endregion
void getdata()
{
// initialisation de connectString avec la chaine de connexion
System::String ^connectString =/*"server=192.168.100.142;uid=root;pwd=root;database=stage_entreprise_dylan";*/"server=localhost;uid=root;database=stage_entreprise_dylan";
//Création du bindingSource qui permet de relier la source de données à la datagrid
bS_saisisentreprise = gcnew System::Windows::Forms::BindingSource();
//Création du DataAdaptateur qui récupère les données de la source de donnée
monAdaptateur = gcnew MySql::Data::MySqlClient::MySqlDataAdapter();
//Paramétrage de la connexion
conn = gcnew MySql::Data::MySqlClient::MySqlConnection(connectString);
//Ouverture de la connexion
try{
conn->Open();
}
catch(MySql::Data::MySqlClient::MySqlException ^Ex)
{
MessageBox::Show("Erreur de connexion à la base de données : " +Ex->Message);
}
//Création de la commande
cmd = gcnew MySql::Data::MySqlClient::MySqlCommand();
cmd->Connection= conn;
cmd->CommandText = "Select * from adresse;";
monAdaptateur->SelectCommand = cmd;
//Remplissage de données d'un datagridview en provenance d'une bindingsource
//--------------------------------------------------------------------------
//rempli à partir d'une table
MaTable = gcnew System::Data::DataTable();
MaTable->Locale = System::Globalization::CultureInfo::InvariantCulture;
//Ajout des données du DataAdater dans le DataTable
monAdaptateur->Fill(MaTable);
bS_saisisentreprise->DataSource = MaTable;
//Ajout des données dans le DataGrigView
dgw_saisiestage->DataSource = bS_saisisentreprise;
//Attention au s
dgw_saisiestage->AutoResizeColumns(DataGridViewAutoSizeColumnsMode::AllCellsExceptHeader);
//Mode connecté
//-------------
//Récupération des données avec un reader
//Elle me permet de faire facilement tous les DataGridView du programme
//identiques
try{
monReader = cmd->ExecuteReader();
}
catch(Exception ^Ex)
{
MessageBox::Show("Erreur de récupération des données : " +Ex->Message);
}
//On en a terminé avec le MySqlDataReader, donc on ferme
monReader->Close();
}
private: System::Void dgw_saisiestage_CellContentClick(System::Object^ sender, System::Windows::Forms::DataGridViewCellEventArgs^ e) {
}
private: System::Void FSaisie_Load(System::Object^ sender, System::EventArgs^ e) {
getdata2();
}
private: System::Void bS_saisisentreprise_CurrentChanged(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void b_envoyer_Click(System::Object^ sender, System::EventArgs^ e) {
/*getdata2();
int ^numerorue=12;
int ^Codepostal;
String ^Nomrue;
String ^Ville;
String ^Numerotel;
String ^Email;
String ^Pays;
String ^rqInserProduit = "INSERT INTO adresse (idAdresse, Numerorue, Nomrue, Codepostal, Ville, Numerotel, Email, Pays) VALUES (null, " + numerorue + ", '" + Nomrue + "', " + Codepostal + ", '" + Ville + "', '" + Numerotel + "', '" + Email + "', '" + Pays + "')";
cmd->CommandText = rqInserProduit;
cmd->ExecuteNonQuery(); */
}
};
} |
Partager