Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Pemrograman Visual Net

Oleh :

Nama : Muhammad Issyar Mubarakh Opu


STB : 172387
Kelas : B-TI

UNIVERSITAS DIPA MAKASSAR


2021
Program.cs

/*
* Created by SharpDevelop.
* User: ASUS TUF
* Date: 26/08/2021
* Time: 2:19
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Windows.Forms;

namespace muhammad_issyar_mubarakh_opu
{
/// <summary>
/// Class with program entry point.
/// </summary>
internal sealed class Program
{
/// <summary>
/// Program entry point.
/// </summary>
[STAThread]
private static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}

}
}

MainForm.cs

/*
* Created by SharpDevelop.
* User: ASUS TUF
* Date: 26/08/2021
* Time: 2:19
*
* 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 System.Data;
using MySql.Data.MySqlClient;

namespace muhammad_issyar_mubarakh_opu
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();

//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
void Button1Click(object sender, EventArgs e)
{
string username = user.Text;
string password = pass.Text;
string koneksi =
"server=localhost;database=muhammad_issyar_mubarakh_opu;uid=root;pwd=root";
MySqlConnection con = new MySqlConnection(koneksi);
try {
con.Open();
MySqlDataAdapter da = new MySqlDataAdapter("select * from admin where
user='" + user.Text + "' && pass='" + pass.Text + "'", con);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count <= 0) {
MessageBox.Show("Your username or password wrong! H3H3");
} else {
Menu form1 = new Menu();
this.Hide();
form1.Show();
}
con.Close();
} catch {
MessageBox.Show("Koneksi Error");
}
}
}
}

Menu.cs

/*
* Created by SharpDevelop.
* User: ASUS TUF
* Date: 26/08/2021
* Time: 2:25
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Drawing;
using System.Windows.Forms;

namespace muhammad_issyar_mubarakh_opu
{
/// <summary>
/// Description of Menu.
/// </summary>
public partial class Menu : Form
{
public Menu()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();

//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
void Button1Click(object sender, EventArgs e)
{
Pegawai form1 = new Pegawai();
form1.Show();
this.Hide();
}
void Button2Click(object sender, EventArgs e)
{
Masuk form2 = new Masuk();
form2.Show();
this.Hide();
}
void Button3Click(object sender, EventArgs e)
{
Keluar form3 = new Keluar();
form3.Show();
this.Hide();
}
}
}
Pegawai.cs

/*
* Created by SharpDevelop.
* User: ASUS TUF
* Date: 26/08/2021
* Time: 3:31
*
* 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 muhammad_issyar_mubarakh_opu
{
/// <summary>
/// Description of Pegawai.
/// </summary>
public partial class Pegawai : Form
{
MySqlCommand query;
koneksi sambung;
MySqlDataAdapter adapter;
MySqlCommandBuilder cmdbl;
String sql;
DataTable tabel;
int selectedRowIndex;
public Pegawai()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
Tampildalamtabel();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
public class ViewData
{
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.Koneksi);
adapter = new MySqlDataAdapter(query);
query.ExecuteNonQuery();
adapter.Fill(tabel);
}
catch (Exception er)
{
MessageBox.Show(er.Message);
}
sambung.tutup();
return tabel;
}

}
void Tampildalamtabel()
{
ViewData tampilkan = new ViewData();
DataTable tabel = new DataTable();

tabel = tampilkan.bacasemua();
dataGridView1.DataSource = tabel;
}
public void simpan()
{
sambung = new koneksi();
sambung.buka();
string query = "insert into pegawai (id, no_pegawai, nama, bagian, kontak,
alamat)values(null,'"+textBox1.Text+"', '"+textBox2.Text+"', '"+textBox3.Text+"',
'"+textBox4.Text+"', '"+textBox5.Text+"')";
MySqlDataAdapter adapter = new MySqlDataAdapter (query,sambung.Koneksi);
adapter.SelectCommand.ExecuteNonQuery();

dataGridView1.Refresh();
sambung.tutup();
MessageBox.Show("Berhasil Di Tambah!");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
}
public void HapusData()
{sambung= new koneksi ();
sambung.buka();
string query = "DELETE FROM pegawai where no_pegawai= '"+textBox1.Text+"'";
MySqlDataAdapter adapter = new MySqlDataAdapter (query,sambung.Koneksi);
adapter.SelectCommand.ExecuteNonQuery();

dataGridView1.Refresh();
sambung.tutup();
MessageBox.Show("Berhasil Di Hapus!");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
}
public void EditData()
{
sambung= new koneksi ();

sambung.buka();
string query = "UPDATE pegawai SET nama='"+textBox2.Text+"',
bagian='"+textBox3.Text+"', kontak='"+textBox4.Text+"', alamat='"+textBox5.Text+"'
WHERE no_pegawai='"+textBox1.Text+"'";
MySqlDataAdapter adapter = new MySqlDataAdapter
(query,sambung.Koneksi);
adapter.SelectCommand.ExecuteNonQuery();

dataGridView1.Refresh();
sambung.tutup();
MessageBox.Show("Data tersimpan!");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
}
void Button1Click(object sender, EventArgs e)
{
simpan();
Tampildalamtabel();
}
void Button2Click(object sender, EventArgs e)
{
EditData();
Tampildalamtabel();
}
void Button3Click(object sender, EventArgs e)
{
HapusData();
Tampildalamtabel();
}
}
}
Masuk.cs

/*
* Created by SharpDevelop.
* User: ASUS TUF
* Date: 26/08/2021
* Time: 3:31
*
* 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 muhammad_issyar_mubarakh_opu
{
/// <summary>
/// Description of Masuk.
/// </summary>
public partial class Masuk : Form
{
MySqlCommand query;
koneksi sambung;
MySqlDataAdapter adapter;
MySqlCommandBuilder cmdbl;
String sql;
DataTable tabel;
int selectedRowIndex;
public Masuk()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
Tampildalamtabel();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
public class ViewData
{
MySqlCommand query;
koneksi sambung;
MySqlDataAdapter adapter;
string sql;
DataTable tabel;

public DataTable bacasemua()


{
sambung = new koneksi();
sql = "SELECT * FROM stock_masuk";
tabel = new DataTable();
try
{
sambung.buka();
query = new MySqlCommand(sql,sambung.Koneksi);
adapter = new MySqlDataAdapter(query);
query.ExecuteNonQuery();
adapter.Fill(tabel);
}
catch (Exception er)
{
MessageBox.Show(er.Message);
}
sambung.tutup();
return tabel;
}
}
void Tampildalamtabel()
{
ViewData tampilkan = new ViewData();
DataTable tabel = new DataTable();

tabel = tampilkan.bacasemua();
dataGridView1.DataSource = tabel;
}
public void simpan()
{
sambung = new koneksi();
sambung.buka();
string query = "insert into stock_masuk (id, kd_masuk, nama, konveksi, jumlah,
harga)values(null,'"+textBox1.Text+"', '"+textBox2.Text+"', '"+textBox3.Text+"',
'"+textBox4.Text+"', '"+textBox5.Text+"')";
MySqlDataAdapter adapter = new MySqlDataAdapter (query,sambung.Koneksi);
adapter.SelectCommand.ExecuteNonQuery();

dataGridView1.Refresh();
sambung.tutup();
MessageBox.Show("Berhasil Di Tambah!");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
}
public void HapusData()
{sambung= new koneksi ();
sambung.buka();
string query = "DELETE FROM stock_masuk where kd_masuk=
'"+textBox1.Text+"'";
MySqlDataAdapter adapter = new MySqlDataAdapter (query,sambung.Koneksi);
adapter.SelectCommand.ExecuteNonQuery();

dataGridView1.Refresh();
sambung.tutup();
MessageBox.Show("Berhasil Di Hapus!");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
}
public void EditData()
{
sambung= new koneksi ();

sambung.buka();
string query = "UPDATE stock_masuk SET nama='"+textBox2.Text+"',
konveksi='"+textBox3.Text+"', jumlah='"+textBox4.Text+"', harga='"+textBox5.Text+"'
WHERE kd_masuk='"+textBox1.Text+"'";
MySqlDataAdapter adapter = new MySqlDataAdapter
(query,sambung.Koneksi);
adapter.SelectCommand.ExecuteNonQuery();

dataGridView1.Refresh();
sambung.tutup();
MessageBox.Show("Data tersimpan!");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
}
void Button1Click(object sender, EventArgs e)
{
simpan();
Tampildalamtabel();
}
void Button2Click(object sender, EventArgs e)
{
EditData();
Tampildalamtabel();
}
void Button3Click(object sender, EventArgs e)
{
HapusData();
Tampildalamtabel();
}

}
}
Keluar.cs

/*
* Created by SharpDevelop.
* User: ASUS TUF
* Date: 26/08/2021
* Time: 3:31
*
* 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 muhammad_issyar_mubarakh_opu
{
/// <summary>
/// Description of Keluar.
/// </summary>
public partial class Keluar : Form
{
MySqlCommand query;
koneksi sambung;
MySqlDataAdapter adapter;
MySqlCommandBuilder cmdbl;
String sql;
DataTable tabel;
int selectedRowIndex;
public Keluar()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
Tampildalamtabel();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
public class ViewData
{
MySqlCommand query;
koneksi sambung;
MySqlDataAdapter adapter;
string sql;
DataTable tabel;

public DataTable bacasemua()


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

}
void Tampildalamtabel()
{
ViewData tampilkan = new ViewData();
DataTable tabel = new DataTable();

tabel = tampilkan.bacasemua();
dataGridView1.DataSource = tabel;
}
public void simpan()
{
sambung = new koneksi();
sambung.buka();
string query = "insert into stock_keluar (id, kd_keluar, warna, ukuran, jumlah,
harga)values(null,'"+textBox1.Text+"', '"+textBox2.Text+"', '"+textBox3.Text+"',
'"+textBox4.Text+"', '"+textBox5.Text+"')";
MySqlDataAdapter adapter = new MySqlDataAdapter (query,sambung.Koneksi);
adapter.SelectCommand.ExecuteNonQuery();

dataGridView1.Refresh();
sambung.tutup();
MessageBox.Show("Berhasil Di Tambah!");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
}
public void HapusData()
{sambung= new koneksi ();
sambung.buka();
string query = "DELETE FROM stock_keluar where kd_keluar=
'"+textBox1.Text+"'";
MySqlDataAdapter adapter = new MySqlDataAdapter (query,sambung.Koneksi);
adapter.SelectCommand.ExecuteNonQuery();

dataGridView1.Refresh();
sambung.tutup();
MessageBox.Show("Berhasil Di Hapus!");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
}
public void EditData()
{
sambung= new koneksi ();

sambung.buka();
string query = "UPDATE stock_keluar SET warna='"+textBox2.Text+"',
ukuran='"+textBox3.Text+"', jumlah='"+textBox4.Text+"', harga='"+textBox5.Text+"'
WHERE kd_keluar='"+textBox1.Text+"'";
MySqlDataAdapter adapter = new MySqlDataAdapter
(query,sambung.Koneksi);
adapter.SelectCommand.ExecuteNonQuery();

dataGridView1.Refresh();
sambung.tutup();
MessageBox.Show("Data tersimpan!");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
}
void Button1Click(object sender, EventArgs e)
{
simpan();
Tampildalamtabel();
}
void Button2Click(object sender, EventArgs e)
{
EditData();
Tampildalamtabel();
}
void Button3Click(object sender, EventArgs e)
{
HapusData();
Tampildalamtabel();
}
}
}

You might also like