Beruflich Dokumente
Kultur Dokumente
#include "StdAfx.h"
#include "DATA_PENDUDUK.h"
namespace MID {
/// <summary>
/// Summary for DATA_PENDUDUK
/// </summary>
public ref class DATA_PENDUDUK : public System::Windows::Forms::Form
{
public:
DATA_PENDUDUK(void)
{
InitializeComponent();
Fillcombo();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~DATA_PENDUDUK()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button4;
protected:
private: System::Windows::Forms::Button^ button3;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::GroupBox^ groupBox1;
private: System::Windows::Forms::TextBox^ textBox5;
private: System::Windows::Forms::ComboBox^ comboBox1;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::TextBox^ textBox4;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^
e) {
String^ constring=L"datasource=localhost;port=3306;username=root;password=";
MySqlConnection^ conDataBase=gcnew MySqlConnection(constring);
MySqlCommand^ cmdDataBase=gcnew MySqlCommand ("insert into
db_penduduk.tabel_pendudk (NIK,NAMA,TTL,JENIS_KELAMIN,ALAMAT,RT_RW,PEKERJAAN) values
('"+this->textBox1->Text+"','"+this->textBox2->Text+"','"+this->dateTimePicker1-
>Text+"','"+this->textBox4->Text+"','"+this->textBox6->Text+"','"+this->textBox7-
>Text+"','"+this->textBox8->Text+"');",conDataBase);
MySqlDataReader^ myReader;
try{
conDataBase->Open();
myReader=cmdDataBase->ExecuteReader();
MessageBox::Show ("data berhasil di simpan");
while(myReader->Read()){
}
}catch (Exception^ex){
MessageBox::Show (ex->Message);
}
}
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
//Keluar
Application::Exit();
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
//tambah combo box
comboBox1->Items->Add(textBox5->Text);
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
//hapus combo box
comboBox1->Items->Remove(comboBox1->Text);
}
private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^
e) {
}
private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) {
String^
constring=L"datasource=localhost;port=3306;username=root;password=";
MySqlConnection^ conDataBase=gcnew MySqlConnection(constring);
MySqlCommand^ cmdDataBase=gcnew MySqlCommand ("Update db_penduduk.tabel_pendudk
set NIK='"+this->textBox1->Text+"',NAMA='"+this->textBox2->Text+"',TTL='"+this-
>dateTimePicker1->Text+"',JENIS_KELAMIN='"+this->textBox4->Text+"',ALAMAT='"+this-
>textBox6->Text+"',RT_RW='"+this->textBox7->Text+"' where PEKERJAAN='"+this->textBox8-
>Text+"' ;",conDataBase);
MySqlDataReader^ myReader;
try{
conDataBase->Open();
myReader=cmdDataBase->ExecuteReader();
MessageBox::Show ("data berhasil di ubah");
while(myReader->Read()){
}catch (Exception^ex){
MessageBox::Show (ex->Message);
}
}
private:void Fillcombo (void){
String^
constring=L"datasource=localhost;port=3306;username=root;password=";
MySqlConnection^ conDataBase=gcnew
MySqlConnection(constring);
MySqlCommand^ cmdDataBase=gcnew MySqlCommand ("select * from
db_penduduk.tabel_pendudk;",conDataBase);
MySqlDataReader^ myReader;
try{
conDataBase->Open();
myReader=cmdDataBase->ExecuteReader();
while(myReader->Read()){
String^ vNIK;
vNIK=myReader->GetString("NIK");
comboBox2->Items->Add(vNIK);
}
}catch (Exception^ex){
MessageBox::Show (ex->Message);
}
}
private: System::Void comboBox2_SelectedIndexChanged(System::Object^ sender,
System::EventArgs^ e) {
String^ comboval=comboBox2->Text;
String^
constring=L"datasource=localhost;port=3306;username=root;password=";
MySqlConnection^ conDataBase=gcnew
MySqlConnection(constring);
MySqlCommand^ cmdDataBase=gcnew MySqlCommand (" select * from db_penduduk.tabel_pendudk
where NIK='"+comboval+"';",conDataBase); MySqlDataReader^ myReader;
try{
conDataBase->Open();
myReader=cmdDataBase->ExecuteReader();
if (myReader->Read()){
String^ NIKVal=myReader->GetInt32("NIK").ToString();
textBox1->Text=NIKVal;
String^ NAMAVal=myReader->GetString("NAMA");
textBox2->Text=NAMAVal;
String^ TTLVal=myReader->GetString("TTL");
dateTimePicker1->Text=TTLVal;
String^ JENIS_KELAMINVal=myReader->GetString("JENIS_KELAMIN");
textBox4->Text=JENIS_KELAMINVal;
String^ ALAMATVal=myReader->GetString("ALAMAT");
textBox6->Text=ALAMATVal;
String^ RT_RWVal=myReader->GetString("RT_RW");
textBox7->Text=RT_RWVal;
String^ PEKERJAANVal=myReader->GetInt32("PEKERJAAN").ToString();
textBox8->Text=PEKERJAANVal;
}
}catch (Exception^ex){
MessageBox::Show (ex->Message);
}
};
}