0
Laporan dan Aplikasi rental menggunakan C sharp/ C# (6)
Posted by jujur
on
3:28 PM
Psoude-Code
Form pelanggan
==================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace index
{
public partial class FPelanggan : Form
{
private string sql;
private kon koneksi = new kon();
private DataTable tpelanggan = new DataTable();
private TampilPelanggan TampilPlg;
private CPelanggan plg = new CPelanggan();
private bool isTambah;
private void id_otomatis()
{
int naik;
string kode_baru;
sql = "select*from pelanggan order by idplg desc";
tpelanggan = koneksi.tampil_data(sql);
if (tpelanggan.Rows.Count == 0)
{
txtkode.Text = "plg-0000001";
}
else
{
txtkode.Text = tpelanggan.Rows[0].ItemArray.GetValue(0).ToString();
naik = int.Parse(txtkode.Text.Substring(4, 7));
naik++;
if (naik < 10)
{
kode_baru = "plg-000000" + naik;
}
else if (naik < 100)
{
kode_baru = "plg-00000" + naik;
}
else if (naik < 1000)
{
kode_baru = "plg-0000" + naik;
}
else if (naik < 10000)
{
kode_baru = "plg-000" + naik;
}
else if (naik < 100000)
{
kode_baru = "plg-00" + naik;
}
else if (naik < 1000000)
{
kode_baru = "plg-0" + naik;
}
else
{
kode_baru = "plg-" + naik;
}
txtkode.Text = kode_baru;
}
txtkode.Enabled = false;
}
public FPelanggan(string mode, string id)
{
InitializeComponent();
if (mode == "tambah")
{
isTambah = true;
header.Text = "Tambah Pelanggan";
id_otomatis();
}
else
{
isTambah = false;
header.Text="Update Pelanggan";
this.Text += "[Edit]";
txtkode.Text = id;
txtkode.Enabled = false;
sql = "select*from pelanggan where idplg='" + id + "'";
tpelanggan = koneksi.tampil_data(sql);
txtnama.Text = tpelanggan.Rows[0].ItemArray.GetValue(1).ToString();
if (tpelanggan.Rows[0].ItemArray.GetValue(2).ToString() == "Pria")
{
txtpria.Checked = true;
}
else
{
txtwanita.Checked = true;
}
txtalamat.Text = tpelanggan.Rows[0].ItemArray.GetValue(3).ToString();
txtphone.Text = tpelanggan.Rows[0].ItemArray.GetValue(4).ToString();
txtidcad.SelectedItem = tpelanggan.Rows[0].ItemArray.GetValue(5).ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
if(txtkode.Text=="")
{
MessageBox.Show("Silahkan mengisi textbox Id terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (txtnama.Text == "")
{
MessageBox.Show("Silahkan mengisi textbox nama terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (txtalamat.Text == "")
{
MessageBox.Show("Silahkan mengisi textbox alamat terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (txtphone.Text == "")
{
MessageBox.Show("Silahkan mengisi Id terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
try
{
if(!isTambah)
{
plg.id = txtkode.Text;
plg.nama = txtnama.Text;
plg.alamat = txtalamat.Text;
plg.phone = txtphone.Text;
plg.jenisID = txtidcad.Text;
if (txtpria.Checked == true)
{
plg.Jk = txtpria.Text;
}
else
{
plg.Jk = txtwanita.Text;
}
sql = "Update pelanggan set nama='" + plg.nama + "', jenis_kelamin='" + plg.Jk + "', alamat='" + plg.alamat + "', phone='" + plg.phone + "', jenis_identitas='" + plg.jenisID + "' where idplg='" + plg.id + "'";
koneksi.dml(sql);
tampilplg.updatedatagrid();
MessageBox.Show("Data telah di update");
this.Close();
}else{
plg.id = txtkode.Text;
plg.nama = txtnama.Text;
plg.alamat = txtalamat.Text;
plg.phone = txtphone.Text;
plg.jenisID = txtidcad.Text;
if (txtpria.Checked == true)
{
plg.Jk = txtpria.Text;
}
else
{
plg.Jk = txtwanita.Text;
}
sql = ("insert into pelanggan (idplg,nama,jenis_kelamin,alamat,phone,jenis_identitas)" + "values('" + plg.id + "','" + plg.nama + "','" + plg.Jk + "','" + plg.alamat + "','" + plg.phone + "','" + plg.jenisID + "')");
koneksi.dml(sql);
tampilplg.updatedatagrid();
MessageBox.Show("Data telah ditambahkan");
this.Close();
}
}
catch(Exception)
{
}
}
}//end button ok
public TampilPelanggan tampilplg
{
get{ return TampilPlg;}
set{TampilPlg = value;}
}
}
}
Form TampilPelanggan
========================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace index
{
public partial class TampilPelanggan : Form
{
private kon koneksi = new kon();
private string sql;
private DataTable tbpelanggan = new DataTable();
private FPelanggan kelolaPelanggan;
private DataSet dataset = new DataSet();
private string temp = "";
public TampilPelanggan()
{
InitializeComponent();
}
private void lihatdata()
{
sql = "select * from pelanggan order by idplg asc ";
tbpelanggan = koneksi.tampil_data(sql);
dgpelanggan.DataSource = tbpelanggan;
dgpelanggan.Columns[0].HeaderText = "Id";
dgpelanggan.Columns[1].HeaderText = "Nama";
dgpelanggan.Columns[2].HeaderText = "Jenis Kelamin";
dgpelanggan.Columns[3].HeaderText = "Alamat";
dgpelanggan.Columns[4].HeaderText = "Telepon";
dgpelanggan.Columns[5].HeaderText = "ID Card";
}
private void TampilPelanggan_Load(object sender, EventArgs e)
{
lihatdata();
}
private void button1_Click(object sender, EventArgs e)
{
kelolaPelanggan = new FPelanggan("tambah", null);
kelolaPelanggan.tampilplg = this;
kelolaPelanggan.ShowDialog();
}
public void updatedatagrid()
{
sql = "select * from pelanggan order by idplg asc ";
tbpelanggan = koneksi.tampil_data(sql);
dgpelanggan.DataSource = tbpelanggan;
}
private void dgpelanggan_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
kelolaPelanggan = new FPelanggan("xxx", dgpelanggan.SelectedCells[0].Value.ToString());
kelolaPelanggan.tampilplg = this;
kelolaPelanggan.ShowDialog();
}
private void dgpelanggan_CellClick(object sender, DataGridViewCellEventArgs e)
{
temp = dgpelanggan.SelectedCells[0].Value.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
if (temp == "")
{
MessageBox.Show("Anda belum memilih Data untuk di edit");
}
else
{
kelolaPelanggan = new FPelanggan("xxx", temp);
kelolaPelanggan.tampilplg = this;
kelolaPelanggan.ShowDialog();
}
}
private void button3_Click(object sender, EventArgs e)
{
if (temp.Length == 0)
{
MessageBox.Show("Anda belum memilih data yang ingin di hapus");
}
else
{
sql = "delete from pelanggan where idplg='" + temp + "'";
koneksi.dml(sql);
MessageBox.Show("Data dengan id= " + temp + " telah berhasil di hapus", "Informasi", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
updatedatagrid();
}
}
private void txtcari_KeyUp(object sender, KeyEventArgs e)
{
if (txtcari.Text == "")
{
sql = "select*from pelanggan order by idplg asc";
tbpelanggan = koneksi.tampil_data(sql);
dgpelanggan.DataSource = tbpelanggan;
}
else
{
sql = "select*from pelanggan where idplg like '%" + txtcari.Text + "%'";
tbpelanggan = koneksi.tampil_data(sql);
if (tbpelanggan.Rows.Count == 0)
{
sql = "select*from pelanggan where nama like '%" + txtcari.Text + "%'";
tbpelanggan = koneksi.tampil_data(sql);
if (tbpelanggan.Rows.Count == 0)
{
sql = "select*from pelanggan where jenis_kelamin like '%" + txtcari.Text + "%'";
tbpelanggan = koneksi.tampil_data(sql);
if (tbpelanggan.Rows.Count == 0)
{
sql = "select*from pelanggan where alamat like '%" + txtcari.Text + "%'";
tbpelanggan = koneksi.tampil_data(sql);
if (tbpelanggan.Rows.Count == 0)
{
sql = "select*from pelanggan where phone like '%" + txtcari.Text + "%'";
tbpelanggan = koneksi.tampil_data(sql);
if (tbpelanggan.Rows.Count == 0)
{
sql = "select*from pelanggan where jenis_identitas '%" + txtcari.Text + "%'";
tbpelanggan = koneksi.tampil_data(sql);
if (tbpelanggan.Rows.Count == 0)
{
MessageBox.Show("Pencarian tidak di temukan", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtcari.Text = "";
}
else
{
dgpelanggan.DataSource = tbpelanggan;
}
}
else
{
dgpelanggan.DataSource = tbpelanggan;
}
}
else
{
dgpelanggan.DataSource = tbpelanggan;
}
}
else
{
dgpelanggan.DataSource = tbpelanggan;
}
}
else
{
dgpelanggan.DataSource = tbpelanggan;
}
}
else
{
dgpelanggan.DataSource = tbpelanggan;
}
}
}
}
}
Form Sopir
==============
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace index
{
public partial class fsopir : Form
{
private tampil_sopir F1;
private DataTable tsopir = new DataTable();
private kon koneksi = new kon();
private string sql = null;
private string stat = null;
private void inisialisasi()
{
txtid.Text = "";
txtnama.Text = "";
txtalamat.Text = "";
txtnotelp.Text = "";
}
public tampil_sopir f1
{
get { return F1; }
set { F1 = value; }
}
public fsopir(string x, string y)
{
if (x == "tambah")
{
InitializeComponent();
inisialisasi();
id_auto();
stat = x;
}
else
{
InitializeComponent();
inisialisasi();
stat = x;
txtid.Text = y;
sql = "select*from sopir where id='" + y + "'";
tsopir = koneksi.tampil_data(sql);
txtid.Enabled = false;
txtnama.Text = tsopir.Rows[0].ItemArray.GetValue(1).ToString();
txtalamat.Text = tsopir.Rows[0].ItemArray.GetValue(2).ToString();
txtnotelp.Text = tsopir.Rows[0].ItemArray.GetValue(3).ToString();
cbstatus.Text = tsopir.Rows[0].ItemArray.GetValue(4).ToString();
this.Text = "Update Sopir";
button2.Text = "Update";
}
}
private void id_auto()
{
string kode;
int temp;
sql = "select*from sopir order by id desc";
tsopir = koneksi.tampil_data(sql);
if (tsopir.Rows.Count == 0)
{
kode = "spr-0000001";
}
else
{
kode = tsopir.Rows[0].ItemArray.GetValue(0).ToString();
temp = int.Parse(kode.Substring(4, 7));
temp++;
if (temp < 10)
{
kode = "spr-000000" + temp;
}
else if (temp < 100)
{
kode = "spr-00000" + temp;
}
else if (temp < 1000)
{
kode = "spr-0000" + temp;
}
else if (temp < 10000)
{
kode = "spr-000" + temp;
}
else if (temp < 100000)
{
kode = "spr-00" + temp;
}
else if (temp < 1000000)
{
kode = "spr-0" + temp;
}
else
{
kode = "spr-" + temp;
}
}
txtid.Text = kode;
txtid.Enabled=false;
}
private void button3_Click(object sender, EventArgs e)
{
Close();
}
private void button2_Click(object sender, EventArgs e)
{
sopir s = new sopir();
if (txtid.Text == "")
{
MessageBox.Show("Anda belum mengisi ID sopir", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtid.Focus();
}
else if (txtnama.Text == "")
{
MessageBox.Show("Anda belum menginputkan nama sopir", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtnama.Focus();
}
else if (txtnotelp.Text == "")
{
MessageBox.Show("Anda belum menginputkan nomor telephone sopir", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtnotelp.Focus();
}
else if (cbstatus.Text == "")
{
MessageBox.Show("Anda belum menemilih status sopir", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
if (stat == "tambah")
{
s.Id = txtid.Text;
s.Nama = txtnama.Text;
s.Notelp = txtnotelp.Text;
s.Alamat = txtalamat.Text;
s.Status = cbstatus.Text;
sql = "insert into sopir (id,nama,alamat,telepon,status)values('" + s.Id + "','" + s.Nama + "','" + s.Notelp + "','" + s.Alamat + "','" + s.Status + "')";
koneksi.dml(sql);
MessageBox.Show("Data telah berhasil di tambahkan", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
f1.Form1_Load(sender, e);
inisialisasi();
this.Close();
}
else
{
s.Id = txtid.Text;
s.Nama = txtnama.Text;
s.Notelp = txtnotelp.Text;
s.Alamat = txtalamat.Text;
s.Status = cbstatus.Text;
sql = "update sopir set nama='" + s.Nama + "', alamat='" + s.Alamat + "', telepon='" + s.Notelp + "', status='" + s.Status + "' where id='" + s.Id + "'";
koneksi.dml(sql);
MessageBox.Show("Data telah berhasil di Update", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
f1.Form1_Load(sender, e);
inisialisasi();
this.Close();
}
}
}
private void fsopir_Load(object sender, EventArgs e)
{
}
}
}
Form tampil_sopir
=====================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace index
{
public partial class tampil_sopir : Form
{
public tampil_sopir()
{
InitializeComponent();
}
private string sql = null;
private kon koneksi = new kon();
private DataTable tsopir = new DataTable();
private string id = null;
public void lihatSemuaData()
{
sql = "select*from sopir order by id asc";
tsopir = koneksi.tampil_data(sql);
dataGridView1.DataSource = tsopir;
dataGridView1.Columns[0].Width = 100;
dataGridView1.Columns[1].Width = 100;
dataGridView1.Columns[2].Width = 148;
dataGridView1.Columns[3].Width = 100;
dataGridView1.Columns[4].Width = 100;
}
private void button2_Click(object sender, EventArgs e)
{
fsopir f2 = new fsopir("tambah","");
f2.f1 = this;
f2.ShowDialog();
}
public void Form1_Load(object sender, EventArgs e)
{
lihatSemuaData();
button2.Visible = true;
edit.Enabled = false;
hapus.Enabled = false;
cancel.Visible = false;
}
public void updatedatagrid()
{
sql = "select * from sopir order by id asc ";
tsopir = koneksi.tampil_data(sql);
dataGridView1.DataSource = tsopir;
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
id = dataGridView1.SelectedCells[0].Value.ToString();
edit.Enabled = true;
hapus.Enabled = true;
button2.Visible = false;
cancel.Visible = true;
}
private void txtpencarian_KeyUp(object sender, KeyEventArgs e)
{
if (txtpencarian.Text == "")
{
sql = "select*from sopir order by id asc";
tsopir = koneksi.tampil_data(sql);
dataGridView1.DataSource = tsopir;
}
else
{
sql = "select*from sopir where id like '%" + txtpencarian.Text + "%'";
tsopir = koneksi.tampil_data(sql);
if (tsopir.Rows.Count == 0)
{
sql = "select*from sopir where nama like '%" + txtpencarian.Text + "%'";
tsopir = koneksi.tampil_data(sql);
if (tsopir.Rows.Count == 0)
{
sql = "select*from sopir where status like '%" + txtpencarian.Text + "%'";
tsopir = koneksi.tampil_data(sql);
if (tsopir.Rows.Count == 0)
{
sql = "select*from sopir where alamat like '%" + txtpencarian.Text + "%'";
tsopir = koneksi.tampil_data(sql);
if (tsopir.Rows.Count == 0)
{
sql = "select*from pelanggan where telepon like '%" + txtpencarian.Text + "%'";
tsopir = koneksi.tampil_data(sql);
if (tsopir.Rows.Count == 0)
{
MessageBox.Show("Pencarian tidak di temukan", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtpencarian.Text = "";
lihatSemuaData();
}
else
{
dataGridView1.DataSource = tsopir;
}
}
else
{
dataGridView1.DataSource = tsopir;
}
}
else
{
dataGridView1.DataSource = tsopir;
}
}
else
{
dataGridView1.DataSource = tsopir;
}
}
else
{
dataGridView1.DataSource = tsopir;
}
}
}
private void cancel_Click(object sender, EventArgs e)
{
Form1_Load(sender, e);
}
private void hapus_Click(object sender, EventArgs e)
{
sql = "delete from sopir where id='" + id + "'";
koneksi.dml(sql);
MessageBox.Show("Data dengan id "+id+" telah berhasil di hapus","Informasi",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
private void edit_Click(object sender, EventArgs e)
{
fsopir fs = new fsopir("edit", id);
fs.f1 = this;
fs.ShowDialog();
}
}
}
Form user
=============
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace index
{
public partial class Fuser : Form
{
private kon koneksi = new kon();
public string id;
string sql;
public string searchkey;
Fusertambah tambah;
Fuseredit edit = new Fuseredit();
user User;
int rowindex;
int colindex;
int rowlength;
string[] arrayid;
public Fuser()
{
InitializeComponent();
}
void lihatSemuaData()
{
sql = "SELECT * FROM operator";
DataTable data = koneksi.tampil_data(sql);
dataGridView1.DataSource = data;
}
private void Fuser_Load(object sender, EventArgs e)
{
lihatSemuaData();
first_edit();
}
private void btn_close_Click(object sender, EventArgs e)
{
this.Close();
}
private void _CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex > -1)
{
User = new user();
User.Id = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
User.nama = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
User.Alamat = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
User.Telp = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
User.password = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
User.Hak_akses = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
rowindex = e.RowIndex;
colindex = e.ColumnIndex;
id = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
}
}
private void btn_delete_Click(object sender, EventArgs e)
{
sql = "DELETE FROM operator WHERE id='" + id + "'";
koneksi.dml(sql);
lihatSemuaData();
}
private void textBox7_TextChanged(object sender, EventArgs e)
{
if (textBox7.Text == "")
lihatSemuaData();
else
{
searchkey = textBox7.Text;
sql = "SELECT * FROM operator WHERE id LIKE '%" + searchkey + "%' or nama LIKE '%" + searchkey + "%' or alamat LIKE '%" + searchkey + "%' or no_telp LIKE '%" + searchkey + "%' or hak_akses LIKE '%" + searchkey + "%'";
DataTable data = koneksi.tampil_data(sql);
dataGridView1.DataSource = data;
}
}
private void btn_insert_Click(object sender, EventArgs e)
{
rowlength = dataGridView1.RowCount;
arrayid = new string[rowlength];
for (int i = 0; i < rowlength; i++)
{
arrayid[i] = dataGridView1.Rows[i].Cells[0].Value.ToString();
}
tambah = new Fusertambah(rowlength, arrayid);
tambah.Closed += tambah_closed;
tambah.ShowDialog();
}
public void tambah_closed(object sender, EventArgs e)
{
lihatSemuaData();
this.dataGridView1.CurrentCell = this.dataGridView1.Rows[rowindex].Cells[colindex];
}
public void edit_closed(object sender, EventArgs e)
{
lihatSemuaData();
this.dataGridView1.CurrentCell = this.dataGridView1.Rows[rowindex].Cells[colindex];
}
public void first_edit()
{
User = new user();
User.Id = dataGridView1.Rows[0].Cells[0].Value.ToString();
User.nama = dataGridView1.Rows[0].Cells[1].Value.ToString();
User.Alamat = dataGridView1.Rows[0].Cells[2].Value.ToString();
User.Telp = dataGridView1.Rows[0].Cells[3].Value.ToString();
User.password = dataGridView1.Rows[0].Cells[4].Value.ToString();
User.Hak_akses = dataGridView1.Rows[0].Cells[5].Value.ToString();
rowindex = 0;
colindex = 0;
id = dataGridView1.Rows[0].Cells[0].Value.ToString();
}
private void btn_edit_Click(object sender, EventArgs e)
{
edit.Closed += edit_closed;
edit.textBox1.Text = User.Id;
edit.textBox2.Text = User.nama;
edit.textBox3.Text = User.Alamat;
edit.textBox4.Text = User.Telp;
edit.textBox5.Text = "";
edit.comboBox1.Text = User.Hak_akses;
edit.id = id;
edit.ShowDialog();
}
}
}
Form useredit
=================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace index
{
public partial class Fuseredit : Form
{
private bool errorinput;
private kon koneksi = new kon();
private string sql;
private kripto encript = new kripto();
public string id;
public Fuseredit()
{
InitializeComponent();
}
private void btn_cancel_Click(object sender, EventArgs e)
{
this.Close();
}
private bool validate_input()
{
if (textBox1.Text == "")
{
MessageBox.Show(" ID Belum Terisi ", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox1.Focus();
errorinput = true;
}
else if (textBox2.Text == "")
{
MessageBox.Show(" Nama Belum Terisi ", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox2.Focus();
errorinput = true;
}
else if (textBox3.Text == "")
{
MessageBox.Show(" Alamat Belum Terisi ", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox3.Focus();
errorinput = true;
}
else if (textBox4.Text == "")
{
MessageBox.Show(" Telp Belum Terisi ", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox4.Focus();
errorinput = true;
}
else if (textBox5.Text == "")
{
MessageBox.Show(" Password Belum Terisi ", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox5.Focus();
errorinput = true;
}
else if (comboBox1.Text == "")
{
MessageBox.Show(" Golongan Belum Dipilih ", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
comboBox1.Focus();
errorinput = true;
}
else
errorinput = false;
return errorinput;
}
private void btn_save_Click(object sender, EventArgs e)
{
if (validate_input())
{ }
else
{
user User = new user();
User.Id = textBox1.Text;
User.nama = textBox2.Text;
User.Alamat = textBox3.Text;
User.Telp = textBox4.Text;
User.password = textBox5.Text;
User.Hak_akses = comboBox1.Text;
sql = "UPDATE operator SET id='" +User.Id+ "', nama='" +User.nama+ "',alamat='" +User.Alamat+ "',no_telp='" +User.Telp+ "',password='" +encript.enkripsi(User.password)+ "',hak_akses='" + User.Hak_akses + "' WHERE id='" + id + "'";
koneksi.dml(sql);
this.Close();
}
}
}
}
Form usertambah
===================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace index
{
public partial class Fusertambah : Form
{
private bool errorinput, errorId;
string sql;
private kon koneksi = new kon();
user User = new user();
Fuser formuser = new Fuser();
kripto enkrip = new kripto();
int columnlength;
string[] array;
public Fusertambah(int collength, string[] arrayid)
{
columnlength = collength;
array = new string[columnlength];
array = arrayid;
InitializeComponent();
}
private void btn_cancel_Click(object sender, EventArgs e)
{
this.Close();
}
private bool validate_input()
{
if (textBox1.Text == "")
{
MessageBox.Show(" Username Belum Terisi ", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox1.Focus();
errorinput = true;
}
else if (textBox2.Text == "")
{
MessageBox.Show(" Nama Belum Terisi ", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox2.Focus();
errorinput = true;
}
else if (textBox3.Text == "")
{
MessageBox.Show(" Alamat Belum Terisi ", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox3.Focus();
errorinput = true;
}
else if (textBox4.Text == "")
{
MessageBox.Show(" Telp Belum Terisi ", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox4.Focus();
errorinput = true;
}
else if (textBox5.Text == "")
{
MessageBox.Show(" Password Belum Terisi ", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox5.Focus();
errorinput = true;
}
else if (comboBox1.Text == "")
{
MessageBox.Show(" Golongan Belum Dipilih ", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
comboBox1.Focus();
errorinput = true;
}
else
errorinput = false;
return errorinput;
}
private bool validate_id()
{
for (int i = 0; i < columnlength; i++)
{
if (textBox1.Text == array[i])
{
MessageBox.Show("Username telah terpakai", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox1.Focus();
errorId = true;
break;
}
else
errorId = false;
}
return errorId;
}
private void btn_save_Click(object sender, EventArgs e)
{
if (validate_input())
{ }
else
{
if (validate_id())
{ }
else
{
user User = new user();
User.Id = textBox1.Text;
User.nama = textBox2.Text;
User.Alamat = textBox3.Text;
User.Telp = textBox4.Text;
User.password = textBox5.Text;
User.Hak_akses = comboBox1.Text;
sql = "INSERT INTO operator VALUES ('" + User.Id + "','" + User.nama + "','" + User.Alamat + "','" + User.Telp + "','" + enkrip.enkripsi(User.password) + "','" + User.Hak_akses + "')";
koneksi.dml(sql);
this.Close();
}
}
}
}
}
Form harga
===============
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace index
{
public partial class harga : Form
{
private kon koneksi = new kon();
private string sql = null;
private DataTable tharga = new DataTable();
private hargasewa ko = new hargasewa();
public harga()
{
InitializeComponent();
bacadb();
}
void bacadb()
{
dgv_hargasewa.Refresh();
DataTable data = ko.bacasemua();
dgv_hargasewa.DataSource = data;
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
editTabsControl.SelectedIndex = 1;
}
private void button4_Click(object sender, EventArgs e)
{
editTabsControl.SelectedIndex = 2;
}
private void Form1_Load(object sender, EventArgs e)
{
comboIDKEY("edit");
comboIDKEY("hapus");
}
private void button2_Click(object sender, EventArgs e)
{
editTabsControl.SelectedIndex = 0;
}
private void button2_Click_1(object sender, EventArgs e)
{
editTabsControl.SelectedIndex = 0;
}
private void button7_Click(object sender, EventArgs e)
{
editTabsControl.SelectedIndex = 0;
this.idKeyHapus.Items.Clear();
}
private void button6_Click(object sender, EventArgs e)
{
editTabsControl.SelectedIndex = 0;
this.idKeyEdit.Items.Clear();
}
private void button5_Click(object sender, EventArgs e)
{
editTabsControl.SelectedIndex = 3;
}
private void button1_Click(object sender, EventArgs e)
{
fields fl = new fields();
fl.Id = int.Parse(id_txt.Text);
fl.Golongan = golongan_txt.Text;
fl.Harga = int.Parse(harga_txt.Text);
if (ko.insert(fl))
{
MessageBox.Show("Data Tersimpan", "a", MessageBoxButtons.OK, MessageBoxIcon.Information);
bacadb();
}
else
{
MessageBox.Show("Gagal Mengisi data");
}
}
public void comboIDKEY( string x)
{
int counter;
sql = "SELECT * FROM harga_sewa order by id asc";
tharga = koneksi.tampil_data(sql);
counter = tharga.Rows.Count;
for(int i=0;i<counter;i++){
string sID = tharga.Rows[i].ItemArray.GetValue(0).ToString();
if((editTabsControl.SelectedIndex == 2)||(x == "hapus")){
idKeyEdit.Items.Add(sID);
}else{
idKeyHapus.Items.Add(sID);
}
}
}
private void button9_Click(object sender, EventArgs e)
{
if (EDIT_golongan.Text != "" && EDIT_harga.Text != "")
{
String sql = "UPDATE harga_sewa SET golongan = '" + EDIT_golongan.Text + "', harga='" + int.Parse(EDIT_harga.Text) + "' WHERE id='" + idKeyEdit.Text + "'";
koneksi.dml(sql);
bacadb();
}
else
{
MessageBox.Show("anda belum mengisi kotak inputan... silahkan di ulangi!", "Update Failed");
}
bacadb();
}
private void button8_Click(object sender, EventArgs e)
{
String kode = "delete from harga_sewa where id='" + idKeyHapus.Text + "'";
koneksi.dml(sql);
bacadb();
}
private void tab_edit_Click(object sender, EventArgs e)
{
}
private void refreshDataToolStripMenuItem_Click(object sender, EventArgs e)
{
bacadb();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Close();
}
private void idKeyEdit_TextChanged(object sender, EventArgs e)
{
sql="select*from harga_sewa where id='"+idKeyEdit.Text+"'";
tharga = koneksi.tampil_data(sql);
EDIT_golongan.Text = tharga.Rows[0].ItemArray.GetValue(1).ToString();
EDIT_harga.Text = tharga.Rows[0].ItemArray.GetValue(2).ToString();
}
}
}