private void tampilData(int id, string nama) { MySqlConnection con = Koneksi.koneksi(); MySqlCommand cmd = new MySqlCommand("SELECT nama_user, jabatan, password FROM data_user WHERE id = '" + id + "' AND nama_user = BINARY '" + nama + "'", con); MySqlDataReader read = cmd.ExecuteReader(); read.Read(); tNamaUser.Text = read["nama_user"].ToString(); cbJabatan.SelectedItem = read["jabatan"].ToString(); tPassword.Text = read["password"].ToString(); con.Close(); edit = true; }
private void tampilData() { MySqlConnection con = Koneksi.koneksi(); MySqlCommand cmd = new MySqlCommand("SELECT id, nama_user, jabatan FROM data_user", con); MySqlDataReader read = cmd.ExecuteReader(); dataGridView1.Rows.Clear(); while (read.Read()) { dataGridView1.Rows.Add(new object[] { read["id"].ToString(), read["nama_user"].ToString(), read["jabatan"].ToString() }); } con.Close(); }
private void tampilData() { MySqlConnection con = Koneksi.koneksi(); MySqlCommand cmd = new MySqlCommand("SELECT * FROM data_produk", con); MySqlDataReader read = cmd.ExecuteReader(); dataGridView1.Rows.Clear(); while (read.Read()) { dataGridView1.Rows.Add(new object[] { read["kode_produk"].ToString(), read["nama_produk"].ToString(), String.Format(idID, "{0:#,##0}", Convert.ToInt64(read["harga_produk"].ToString())) }); } con.Close(); }
private void tampilData() { try { MySqlConnection con = Koneksi.koneksi(); MySqlCommand cmd = new MySqlCommand("SELECT * FROM data_pembelian", con); MySqlDataReader read = cmd.ExecuteReader(); dataGridView1.Rows.Clear(); while (read.Read()) { dataGridView1.Rows.Add(new object[] { read["invoice"], Convert.ToDateTime(read["tanggal_transaksi"]).ToString("dd/MM/yyyy"), read["nama_kasir"], String.Format(idID, "{0:#,##0}", Convert.ToInt64(read["total_harga"])) }); } } catch {} }
private void bHapus_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("Apakah Anda Yakin Ingin Menghapus Data Ini?", "Konfirmasi", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr.Equals(DialogResult.Yes)) { MySqlConnection con = Koneksi.koneksi(); MySqlCommand cmd = new MySqlCommand("DELETE FROM data_produk WHERE kode_produk = BINARY '" + tKodeProduk.Text + "'", con); cmd.ExecuteNonQuery(); tKodeProduk.Text = ""; tNamaProduk.Text = ""; tHargaProduk.Text = ""; tKodeProduk.Enabled = true; bHapus.Visible = false; tampilData(); con.Close(); } }
private void ambilData() { try { MySqlConnection con = Koneksi.koneksi(); MySqlCommand cmd = new MySqlCommand("SELECT kode_produk, nama_produk FROM data_produk", con); MySqlDataReader read = cmd.ExecuteReader(); while (read.Read()) { testProduk.Add(read["nama_produk"], read["kode_produk"]); } cbProduk.DataSource = new BindingSource(testProduk, null); cbProduk.DisplayMember = "Key"; cbProduk.ValueMember = "Value"; } catch { MessageBox.Show("Tidak Ada Produk Yang Terdaftar Dalam Sistem!", "Tidak Ada Data"); this.Close(); } }
private void button1_Click(object sender, EventArgs e) { if (!tUsername.Text.Equals("") && !tPassword.Text.Equals("")) { MySqlConnection con = Koneksi.koneksi(); MySqlCommand cmd = new MySqlCommand("SELECT nama_user, jabatan FROM data_user WHERE nama_user = BINARY '" + tUsername.Text + "'AND password = BINARY '" + tPassword.Text + "'", con); MySqlDataReader read = cmd.ExecuteReader(); if (read.HasRows) { read.Read(); Koneksi.Session_Username = read["nama_user"].ToString(); switch (read["jabatan"]) { case "admin": mn.openChildForm(new Admin(mn)); break; case "user": mn.openChildForm(new Kasir(mn)); break; } con.Close(); } else { MessageBox.Show("Username atau Password anda salah!", "Gagal Login"); tUsername.Focus(); } } else { MessageBox.Show("Masukan Username Dan Password Anda!", "Data Tidak Lengkap"); tUsername.Focus(); } }
private void button1_Click(object sender, EventArgs e) { if (!tNamaUser.Text.Equals("") || !tPassword.Text.Equals("")) { try { MySqlConnection con = Koneksi.koneksi(); if (!edit) { MySqlCommand cmd = new MySqlCommand("INSERT INTO data_user(nama_user, jabatan, password)" + " VALUES(@nama, @jabatan, @password)", con); cmd.Parameters.AddWithValue("@nama", tNamaUser.Text); cmd.Parameters.AddWithValue("@jabatan", cbJabatan.SelectedItem.ToString()); cmd.Parameters.AddWithValue("@password", tPassword.Text); cmd.ExecuteNonQuery(); tNamaUser.Text = ""; cbJabatan.SelectedItem = "user"; tPassword.Text = ""; tampilData(); } else { try { MySqlCommand cmd = new MySqlCommand("UPDATE data_user SET nama_user = @nama, jabatan = @jabatan, password = @password" + " WHERE id = '" + id + "'", con); cmd.Parameters.AddWithValue("@nama", tNamaUser.Text); cmd.Parameters.AddWithValue("@jabatan", cbJabatan.SelectedItem.ToString()); cmd.Parameters.AddWithValue("@password", tPassword.Text); cmd.ExecuteNonQuery(); } catch (Exception msg) { MessageBox.Show(msg.ToString()); } tNamaUser.Text = ""; cbJabatan.SelectedItem = "user"; tPassword.Text = ""; tampilData(); id = 0; edit = false; bHapus.Visible = false; } con.Close(); } catch { } } else { MessageBox.Show("Lengkapi Data Anda Terlebih Dahulu!!", "Data Tidak Lengkap", MessageBoxButtons.OK, MessageBoxIcon.Warning); if (tNamaUser.Text.Equals("")) { tNamaUser.Focus(); } else { tPassword.Focus(); } } }
public void simpanData() { /** * Memuat invoice, nama kasir, diskon pembelian, dan total harga ke dalam tabel data_pembelian */ MySqlConnection con = Koneksi.koneksi(); MySqlCommand cmd = new MySqlCommand("SELECT COUNT(*) AS ROW FROM data_pembelian WHERE invoice LIKE 'Invoice" + DateTime.Now.ToString("y''MM''dd") + "%'", con); MySqlDataReader read = cmd.ExecuteReader(); read.Read(); string invoice = "Invoice" + DateTime.Now.ToString("y''MM''dd") + String.Format(idID, "{0:0000}", Convert.ToInt32(read["ROW"]) + 1); string namaKasir = Koneksi.Session_Username; int totalHarga = 0; for (int i = 0; i < detailProduk.Count; i++) { totalHarga += Convert.ToInt32(detailProduk[i][5]); } read.Close(); cmd = new MySqlCommand("INSERT INTO data_pembelian(invoice, tanggal_transaksi, nama_kasir, total_harga) " + "VALUES(@invoice, @tanggal, @nama, @total)", con); cmd.Parameters.AddWithValue("@invoice", invoice); cmd.Parameters.AddWithValue("@tanggal", DateTime.Now.ToString("yyyy-MM-dd")); cmd.Parameters.AddWithValue("@nama", namaKasir); cmd.Parameters.AddWithValue("@total", totalHarga); cmd.ExecuteNonQuery(); /** * Loop semua data di detailPembelian sambil dimasukan ke dalam tabel detail_pembelian(invoice, kode barang, * harga barang, jumlah barang, diskon barang) */ for (int i = 0; i < detailProduk.Count; i++) { cmd = new MySqlCommand("INSERT INTO detail_pembelian(invoice, kode_barang, nama_barang, harga_barang," + " jumlah_barang, diskon_barang) VALUES(@invoice, @kode, @nama, @harga, @jumlah, @diskon)", con); cmd.Parameters.AddWithValue("@invoice", invoice); cmd.Parameters.AddWithValue("@kode", detailProduk[i][0]); cmd.Parameters.AddWithValue("@nama", detailProduk[i][1]); cmd.Parameters.AddWithValue("@harga", detailProduk[i][2]); cmd.Parameters.AddWithValue("@jumlah", detailProduk[i][3]); cmd.Parameters.AddWithValue("@diskon", detailProduk[i][4]); cmd.ExecuteNonQuery(); } /* * Mempersiapkan form untuk pembelian berikutnya */ detailProduk.Clear(); dataGridView1.Rows.Clear(); lTotal.Text = "0"; tKode.Focus(); con.Close(); }
private void button3_Click(object sender, EventArgs e) { if (!tKode.Text.Equals("")) { //Cek kode produk MySqlConnection con = Koneksi.koneksi(); MySqlCommand cmd = new MySqlCommand("SELECT nama_produk, harga_produk FROM data_produk WHERE kode_produk = '" + tKode.Text + "'", con); MySqlDataReader read = cmd.ExecuteReader(); if (!read.HasRows) { MessageBox.Show("Kode Produk Yang Anda Masukan Salah!!", "Error"); tKode.Focus(); } else { //Masukin dalam list detailProduk[i][kode_produk, nama_produk, harga_produk, Qty, Diskon, Total] read.Read(); string namaProduk = read["nama_produk"].ToString(); int hargaProduk = Convert.ToInt32(read["harga_produk"].ToString()); int qty = Convert.ToInt32(nudQty.Value); int diskon = Convert.ToInt32(nudDiskon.Value); int total = hargaProduk * qty - hargaProduk * qty * diskon / 100; detailProduk.Add(new List <string>()); detailProduk[detailProduk.Count - 1].Add(tKode.Text); detailProduk[detailProduk.Count - 1].Add(namaProduk); detailProduk[detailProduk.Count - 1].Add(hargaProduk.ToString()); detailProduk[detailProduk.Count - 1].Add(qty.ToString()); detailProduk[detailProduk.Count - 1].Add(diskon.ToString()); detailProduk[detailProduk.Count - 1].Add(total.ToString()); dataGridView1.Rows.Add(new object[] { tKode.Text, namaProduk, String.Format(idID, "{0:#,##0}", hargaProduk), qty, diskon, String.Format(idID, "{0:#,##0}", total) }); //Memperlihatkan total di label lTotal for (int i = 0; i < detailProduk.Count; i++) { ltotal += Convert.ToInt32(detailProduk[i][5]); } string test = String.Format(idID, "{0:#,##0}", ltotal); lTotal.Text = test; tKode.Text = ""; tKode.Focus(); nudQty.Value = 1; nudDiskon.Value = 0; } con.Close(); } else { MessageBox.Show("Masukan Kode Produk Anda!", "Masukan Data", MessageBoxButtons.OK, MessageBoxIcon.Warning); tKode.Focus(); } }