You are on page 1of 19

TUGAS

BESAR

VNET

DISUSUN OLEH

Nama : Juan Pierre Zelot Karodo (192548)

Kelas : Teknik Informatika P

UNIVERSITAS DIPA MAKASSAR


2021
- Koneksi

/*
* Created by SharpDevelop.
* User: YPR
* Date: 7/16/2021
* Time: 2:37 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using MySql.Data.MySqlClient;

namespace perhotelan
{
/// <summary>
/// Description of Koneksi.
/// </summary>
public class Koneksi
{
string pegawai = "server=localhost; database=perhotelan; uid=root; pwd=";
public MySqlConnection conn;

public void buka()


{
conn= new MySqlConnection(pegawai);
conn.Open();
}

public void tutup()


{
conn= new MySqlConnection(pegawai);
conn.Close();
}
}
}

- Koneksi Pengunjung

/*
* Created by SharpDevelop.
* User: YPR
* Date: 7/16/2021
* Time: 3:26 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using MySql.Data.MySqlClient;

namespace perhotelan
{
/// <summary>
/// Description of KoneksiPengunjung.
/// </summary>
public class KoneksiPengunjung
{
string pengunjung = "server=localhost; database=perhotelan; uid=root; pwd=";
public MySqlConnection conn;

public void buka()


{
conn= new MySqlConnection(pengunjung);
conn.Open();
}

public void tutup()


{
conn= new MySqlConnection(pengunjung);
conn.Close();
}
}
}

- Main form

/*
* Created by SharpDevelop.
* User: YPR
* Date: 7/16/2021
* Time: 2:05 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.Data;

namespace perhotelan
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
Koneksi sambung;
DialogResult result;

public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();

//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
void DataKaryawanToolStripMenuItemClick(object sender, EventArgs e)
{
Pegawai pegawai = new Pegawai();
pegawai.Show();
}
void TesKoneksiToolStripMenuItemClick(object sender, EventArgs e)
{
sambung = new Koneksi();
try{
sambung.buka();
MessageBox.Show("Berhasil Koneksi Ke Database","informasi");

}catch(MySqlException ex)
{
switch(ex.Number){
case 0 : {MessageBox.Show("Koneksi Gagal ","Konfirmasi");
}break;
case 1045 : { MessageBox.Show("Username Atau Password Salah","Konfirmasi");
}break;
}
}
}
void PengunToolStripMenuItemClick(object sender, EventArgs e)
{
Pengunjung pengunjung = new Pengunjung();
pengunjung.Show();
}

}
}

- Pegawai

/*
* Created by SharpDevelop.
* User: YPR
* Date: 7/16/2021
* Time: 2:49 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using MySql.Data.MySqlClient;

namespace perhotelan
{
/// <summary>
/// Description of Pegawai.
/// </summary>
public partial class Pegawai : Form
{
MySqlCommand query;
Koneksi sambung;
MySqlDataAdapter adapter;
string sql;
DataTable tabel;
public Pegawai()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();

//
// TODO: Add constructor code after the InitializeComponent() call.
//
}

void TampilDalamTabel()
{
ViewData tampilkan = new ViewData();
DataTable tabel = new DataTable();

tabel = tampilkan.bacasemua();
dataGridView1.DataSource = tabel;
}

public void simpan()


{
sambung = new Koneksi();
sql = "INSERT INTO pegawai(id,nik,nama,umur,jenis_kelamin,alamat,jabatan) VALUES
('"+textBox1.Text+"','"+textBox2.Text+"','"+textBox3.Text+"','"+textBox4.Text+"','"+textBox5.Text+"','"+t
extBox6.Text+"','"+textBox7.Text+"')";
tabel = new DataTable();
try{
sambung.buka();
query = new MySqlCommand(sql,sambung.conn);
adapter = new MySqlDataAdapter(query);
query.ExecuteNonQuery();
MessageBox.Show("Data Berhasil Tersimpan !!!","information");
}catch (Exception er)
{
MessageBox.Show(er.Message);
}
sambung.tutup();
}

public void editdata()


{
sambung= new Koneksi();
sql = "UPDATE pegawai SET
nik='"+textBox2.Text+"',nama='"+textBox3.Text+"',umur='"+textBox4.Text+"',jenis_kelamin='"+textBox5
.Text+"',alamat='"+textBox6.Text+"',jabatan='"+textBox7.Text+"' WHERE ID= '"+textBox1.Text+"'";
tabel = new DataTable();
try{
sambung.buka();
query = new MySqlCommand(sql, sambung.conn);
adapter = new MySqlDataAdapter(query);
query.ExecuteNonQuery();
MessageBox.Show("Data Berhasil Diubah !!!","information");
dataGridView1.Refresh();
TampilDalamTabel();
bersih();
}
catch (Exception er)
{
MessageBox.Show(er.Message);
}
sambung.tutup();
}

public void hapus()


{
sambung= new Koneksi();
sql = "DELETE from pegawai where ID='"+textBox1.Text+"'";
tabel = new DataTable();
try{
sambung.buka();
query = new MySqlCommand(sql, sambung.conn);
adapter = new MySqlDataAdapter(query);
query.ExecuteNonQuery();
MessageBox.Show("Data Berhasil Dihapus !!!","information");
TampilDalamTabel();
bersih();
}
catch (Exception er)
{
MessageBox.Show(er.Message);
}
sambung.tutup();
}

public void bersih(){


textBox1.Text="";
textBox2.Text="";
textBox3.Text="";
textBox1.Focus();
}

void Button1Click(object sender, EventArgs e)


{
TampilDalamTabel();
}
void Button2Click(object sender, EventArgs e)
{
simpan();
TampilDalamTabel();
}
void Button3Click(object sender, EventArgs e)
{
hapus();
TampilDalamTabel();
}
void Button4Click(object sender, EventArgs e)
{
editdata();
TampilDalamTabel();
}
void DataGridView1CellContentClick(object sender, DataGridViewCellEventArgs e)
{
DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
textBox1.Text = row.Cells["id"].Value.ToString();
textBox2.Text = row.Cells["nik"].Value.ToString();
textBox3.Text = row.Cells["nama"].Value.ToString();
textBox4.Text = row.Cells["umur"].Value.ToString();
textBox5.Text = row.Cells["jenis_kelamin"].Value.ToString();
textBox6.Text = row.Cells["alamat"].Value.ToString();
textBox7.Text = row.Cells["jabatan"].Value.ToString();
}
void Button5Click(object sender, EventArgs e)
{
string nama=textBox8.Text;
ViewCari cari = new ViewCari();
DataTable tabel = new DataTable();
tabel = cari.tampilkanpencarian(nama);
dataGridView1.DataSource = tabel;
}

}
}

- Pengunjung

/*
* Created by SharpDevelop.
* User: YPR
* Date: 7/16/2021
* Time: 3:26 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using MySql.Data.MySqlClient;

namespace perhotelan
{
/// <summary>
/// Description of Pengunjung.
/// </summary>
public partial class Pengunjung : Form
{
MySqlCommand query;
Koneksi sambung;
MySqlDataAdapter adapter;
string sql;
DataTable tabel;

public Pengunjung()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();

//
// TODO: Add constructor code after the InitializeComponent() call.
//
}

void TampilDalamTabel()
{
ViewDataPengunjung tampilkan = new ViewDataPengunjung();
DataTable tabel = new DataTable();

tabel = tampilkan.bacasemua();
dataGridView1.DataSource = tabel;
}

public void simpan()


{
sambung = new Koneksi();
sql = "INSERT INTO pengunjung(id,nama,umur,jenis_kelamin,alamat,no_kamar) VALUES
('"+textBox1.Text+"','"+textBox2.Text+"','"+textBox3.Text+"','"+textBox4.Text+"','"+textBox5.Text+"','"+t
extBox6.Text+"')";
tabel = new DataTable();
try{
sambung.buka();
query = new MySqlCommand(sql,sambung.conn);
adapter = new MySqlDataAdapter(query);
query.ExecuteNonQuery();
MessageBox.Show("Data Berhasil Tersimpan !!!","information");
}catch (Exception er)
{
MessageBox.Show(er.Message);
}
sambung.tutup();
}

public void editdata()


{
sambung= new Koneksi();
sql = "UPDATE pengunjung SET
nama='"+textBox2.Text+"',umur='"+textBox3.Text+"',jenis_kelamin='"+textBox4.Text+"',alamat='"+textB
ox5.Text+"',no_kamar='"+textBox6.Text+"' WHERE ID= '"+textBox1.Text+"'";
tabel = new DataTable();
try{
sambung.buka();
query = new MySqlCommand(sql, sambung.conn);
adapter = new MySqlDataAdapter(query);
query.ExecuteNonQuery();
MessageBox.Show("Data Berhasil Diubah !!!","information");
dataGridView1.Refresh();
TampilDalamTabel();
bersih();
}
catch (Exception er)
{
MessageBox.Show(er.Message);
}
sambung.tutup();
}

public void hapus()


{
sambung= new Koneksi();
sql = "DELETE from pengunjung where ID='"+textBox1.Text+"'";
tabel = new DataTable();
try{
sambung.buka();
query = new MySqlCommand(sql, sambung.conn);
adapter = new MySqlDataAdapter(query);
query.ExecuteNonQuery();
MessageBox.Show("Data Berhasil Dihapus !!!","information");
TampilDalamTabel();
bersih();
}
catch (Exception er)
{
MessageBox.Show(er.Message);
}
sambung.tutup();
}

public void bersih(){


textBox1.Text="";
textBox2.Text="";
textBox3.Text="";
textBox1.Focus();
}
void Label3Click(object sender, EventArgs e)
{

}
void Button1Click(object sender, EventArgs e)
{
TampilDalamTabel();
}
void Button2Click(object sender, EventArgs e)
{
simpan();
TampilDalamTabel();
}
void Button3Click(object sender, EventArgs e)
{
hapus();
TampilDalamTabel();
}
void Button4Click(object sender, EventArgs e)
{
editdata();
TampilDalamTabel();
}
void DataGridView1CellContentClick(object sender, DataGridViewCellEventArgs e)
{
DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
textBox1.Text = row.Cells["id"].Value.ToString();
textBox2.Text = row.Cells["nama"].Value.ToString();
textBox3.Text = row.Cells["umur"].Value.ToString();
textBox4.Text = row.Cells["jenis_kelamin"].Value.ToString();
textBox5.Text = row.Cells["alamat"].Value.ToString();
textBox6.Text = row.Cells["no_kamar"].Value.ToString();
}
void Button5Click(object sender, EventArgs e)
{
string nama=textBox8.Text;
ViewCariPengunjung cari = new ViewCariPengunjung();
DataTable tabel = new DataTable();
tabel = cari.tampilkanpencarian(nama);
dataGridView1.DataSource = tabel;
}

}
}
- View cari

/*
* Created by SharpDevelop.
* User: YPR
* Date: 7/16/2021
* Time: 3:17 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Drawing;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.Data;

namespace perhotelan
{
/// <summary>
/// Description of ViewCari.
/// </summary>
public class ViewCari
{
MySqlCommand query;
Koneksi sambung;
MySqlDataAdapter adapter;
string sql;
DataTable tabel;

public DataTable tampilkanpencarian(string x)


{
sambung = new Koneksi();
sql = "SELECT * FROM pegawai where Nama LIKE '%"+x+"%' ";
tabel = new DataTable();
try{
sambung.buka();
query = new MySqlCommand(sql,sambung.conn);
adapter = new MySqlDataAdapter(query);
query.ExecuteNonQuery();
adapter.Fill(tabel);
}catch (Exception er)
{
MessageBox.Show(er.Message);
}
sambung.tutup();
return tabel;
}
}
}

- View cari pengunjung

/*
* Created by SharpDevelop.
* User: YPR
* Date: 7/16/2021
* Time: 3:34 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Drawing;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.Data;

namespace perhotelan
{
/// <summary>
/// Description of ViewCariPengunjung.
/// </summary>
public class ViewCariPengunjung
{
MySqlCommand query;
Koneksi sambung;
MySqlDataAdapter adapter;
string sql;
DataTable tabel;

public DataTable tampilkanpencarian(string x)


{
sambung = new Koneksi();
sql = "SELECT * FROM pengunjung where Nama LIKE '%"+x+"%' ";
tabel = new DataTable();
try{
sambung.buka();
query = new MySqlCommand(sql,sambung.conn);
adapter = new MySqlDataAdapter(query);
query.ExecuteNonQuery();
adapter.Fill(tabel);
}catch (Exception er)
{
MessageBox.Show(er.Message);
}
sambung.tutup();
return tabel;
}
}
}

- View data

/*
* Created by SharpDevelop.
* User: YPR
* Date: 7/16/2021
* Time: 2:55 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Drawing;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.Data;

namespace perhotelan
{
/// <summary>
/// Description of ViewData.
/// </summary>
public partial class ViewData : Form
{
MySqlCommand query;
Koneksi sambung;
MySqlDataAdapter adapter;
string sql;
DataTable tabel;

public DataTable bacasemua()


{

sambung = new Koneksi();


sql = "SELECT * FROM pegawai";
tabel = new DataTable();
try{
sambung.buka();
query = new MySqlCommand(sql,sambung.conn);
adapter = new MySqlDataAdapter(query);
query.ExecuteNonQuery();
adapter.Fill(tabel);
}catch (Exception er)
{
MessageBox.Show(er.Message);
}
sambung.tutup();
return tabel;
}
}
}

- View data pengunjung

/*
* Created by SharpDevelop.
* User: YPR
* Date: 7/16/2021
* Time: 3:28 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Drawing;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.Data;

namespace perhotelan
{
/// <summary>
/// Description of ViewDataPengunjung.
/// </summary>
public class ViewDataPengunjung
{
MySqlCommand query;
Koneksi sambung;
MySqlDataAdapter adapter;
string sql;
DataTable tabel;

public DataTable bacasemua()


{

sambung = new Koneksi();


sql = "SELECT * FROM pengunjung";
tabel = new DataTable();
try{
sambung.buka();
query = new MySqlCommand(sql,sambung.conn);
adapter = new MySqlDataAdapter(query);
query.ExecuteNonQuery();
adapter.Fill(tabel);
}catch (Exception er)
{
MessageBox.Show(er.Message);
}
sambung.tutup();
return tabel;
}
}
}

- Output

You might also like