Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
09.11.3229 09.11.3207
namespace SmartRetailServer.Dao { public class BarangDao : MarshalByRefObject, iBarangDao { private SqlConnection conn = null; private string ss = String.Empty; public BarangDao() { this.conn = DBConnection.GetConnection(); } // constructor public BarangDao(SqlConnection conn) {
this.conn = conn; } #region iBarangDao Members public int Delete(string barangId) { Console.WriteLine("Method Delete diakses secara remote.\n"); ss = "delete from barang where id = @1"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { cmd.Parameters.AddWithValue("@1", barangId); return cmd.ExecuteNonQuery(); } } public int Save(Barang barang) { Console.WriteLine("Method Save diakses secara remote.\n"); ss = "insert into barang (id, nama, harga_beli, harga_jual, stok) values (@1, @2, @3, @4, @5)"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { cmd.Parameters.AddWithValue("@1", barang.BarangID); cmd.Parameters.AddWithValue("@2", barang.Nama); cmd.Parameters.AddWithValue("@3", barang.HargaBeli); cmd.Parameters.AddWithValue("@4", barang.HargaJual); cmd.Parameters.AddWithValue("@5", barang.Stok); return cmd.ExecuteNonQuery(); } } public int Update(Barang barang) { Console.WriteLine("Method Update diakses secara remote.\n"); ss = "update barang set nama=@1, harga_beli=@2, harga_jual=@3, stok=@4 where id=@5"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { cmd.Parameters.AddWithValue("@1", barang.Nama); cmd.Parameters.AddWithValue("@2", barang.HargaBeli); cmd.Parameters.AddWithValue("@3", barang.HargaJual); cmd.Parameters.AddWithValue("@4", barang.Stok); cmd.Parameters.AddWithValue("@5", barang.BarangID); return cmd.ExecuteNonQuery(); } } public List<Barang> getAll()
{ Console.WriteLine("Method GetAll diakses secara remote.\n"); List<Barang> listBarang = new List<Barang>(); ss = "select id, nama, harga_beli, harga_jual, stok from barang order by nama"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { using (SqlDataReader dtr = cmd.ExecuteReader()) { while (dtr.Read()) { Barang barang = new Barang(); barang.BarangID = dtr.GetString(0); barang.Nama = dtr.GetString(1); barang.HargaBeli = dtr.GetInt32(2); barang.HargaJual = dtr.GetInt32(3); barang.Stok = dtr.GetInt32(4); listBarang.Add(barang); } } } return listBarang; } public Barang getById(string barangID) { Console.WriteLine("Method GetById diakses secara remote.\n"); Barang barang = null; ss = "select id, nama, harga_beli, harga_jual, stok from barang where id=@1"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { cmd.Parameters.AddWithValue("@1", barangID); using (SqlDataReader dtr = cmd.ExecuteReader()) { if (dtr.Read()) { barang = new Barang(); barang.BarangID = dtr.GetString(0); barang.Nama = dtr.GetString(1); barang.HargaBeli = dtr.GetInt32(2); barang.HargaJual = dtr.GetInt32(3); barang.Stok = dtr.GetInt32(4); } } } return barang; }
public List<Barang> getByName(string name) { Console.WriteLine("Method GetByName diakses secara remote.\n"); List<Barang> listBarang = new List<Barang>(); ss = "select id, nama, harga_beli, harga_jual, stok from barang " + "where nama like @1 " + "order by nama"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { cmd.Parameters.AddWithValue("@1", "%" + name + "%"); using (SqlDataReader dtr = cmd.ExecuteReader()) { while (dtr.Read()) { Barang barang = new Barang(); barang.BarangID = dtr.GetString(0); barang.Nama = dtr.GetString(1); barang.HargaBeli = dtr.GetInt32(2); barang.HargaJual = dtr.GetInt32(3); barang.Stok = dtr.GetInt32(4); listBarang.Add(barang); } } } return listBarang; } #endregion #region iBarangDao Members
public System.Data.DataSet getReportBarang() { Console.WriteLine("Method getReportBarang diakses"); ss = "select id, nama, harga_beli, harga_jual, stok from barang order by nama"; SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = new SqlCommand(ss, conn); DataSet ds = new DataSet(); da.Fill(ds, "barang"); return ds; } #endregion } }
namespace SmartRetailServer.Dao { class CustomerDao : MarshalByRefObject, iCustomerDao { private SqlConnection conn = null; private string ss = String.Empty; public CustomerDao() { this.conn = DBConnection.GetConnection(); } // constructor public CustomerDao(SqlConnection conn) { this.conn = conn; } #region iCustomerDao Members public int Delete(int customerID) { ss = "delete from customer where id = @1"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { cmd.Parameters.AddWithValue("@1", customerID); return cmd.ExecuteNonQuery(); } } public int Save(Customer customer) { ss = "insert into customer (nama, alamat, kota, kontak, telepon) values (@2, @3, @4, @5, @6)"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { cmd.Parameters.AddWithValue("@2", customer.Nama); cmd.Parameters.AddWithValue("@3", customer.Alamat); cmd.Parameters.AddWithValue("@4", customer.Kota); cmd.Parameters.AddWithValue("@5", customer.Kontak); cmd.Parameters.AddWithValue("@6", customer.Telepon); return cmd.ExecuteNonQuery(); } }
public int Update(Customer customer) { ss = "update customer set nama=@1, alamat=@2, kota=@3, kontak=@4, telepon=@5 where id=@6"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { cmd.Parameters.AddWithValue("@6", customer.CustomerID); cmd.Parameters.AddWithValue("@1", customer.Nama); cmd.Parameters.AddWithValue("@2", customer.Alamat); cmd.Parameters.AddWithValue("@3", customer.Kota); cmd.Parameters.AddWithValue("@4", customer.Kontak); cmd.Parameters.AddWithValue("@5", customer.Telepon); return cmd.ExecuteNonQuery(); } } public List<Customer> getAll() { List<Customer> listCustomer = new List<Customer>(); ss = "select id, nama, alamat, kota, kontak, telepon from customer order by id"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { using (SqlDataReader dtr = cmd.ExecuteReader()) { while (dtr.Read()) { Customer cs = new Customer(); cs.CustomerID = dtr.GetInt32(0); cs.Nama = dtr.GetString(1); cs.Alamat = dtr.GetString(2); cs.Kota = dtr.GetString(3); cs.Kontak = dtr.GetString(4); cs.Telepon = dtr.GetString(5); listCustomer.Add(cs); } } } return listCustomer; } public List<Customer> getByName(string name) { List<Customer> listCustomer = new List<Customer>(); ss = "select id, nama, alamat, kota, kontak, telepon from customer " + "where nama like @1 " + "order by id"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { cmd.Parameters.AddWithValue("@1", "%" + name + "%"); using (SqlDataReader dtr = cmd.ExecuteReader()) { while (dtr.Read())
{ Customer cs = new Customer(); cs.CustomerID = dtr.GetInt32(0); cs.Nama = dtr.GetString(1); cs.Alamat = dtr.GetString(2); cs.Kota = dtr.GetString(3); cs.Kontak = dtr.GetString(4); cs.Telepon = dtr.GetString(5); listCustomer.Add(cs); } } } return listCustomer; } #endregion #region iCustomerDao Members
public System.Data.DataSet getReportCustomer() { Console.WriteLine("Method getReportCustomer diakses"); ss = "select id, nama, alamat, kota, kontak, telepon from customer order by id"; SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = new SqlCommand(ss, conn); DataSet ds = new DataSet(); da.Fill(ds, "customer"); return ds; } #endregion } }
namespace SmartRetailServer.Dao { public class ItemBeliDao : MarshalByRefObject, iItemBeliDao { private SqlConnection conn = null; private string ss = "";
#region iItemBeliDao Members public int Delete(int itemBeliID) { throw new Exception("The method or operation is not implemented."); } public int Save(ItemBeli itemBeli) { throw new Exception("The method or operation is not implemented."); } public int Update(ItemBeli itemBeli) { throw new Exception("The method or operation is not implemented."); } #endregion } }
namespace SmartRetailServer.Dao { class OperatorDao : MarshalByRefObject, iOperatorDao { private SqlConnection conn = null; private string ss = String.Empty; public OperatorDao() { this.conn = DBConnection.GetConnection(); } // constructor public OperatorDao(SqlConnection conn)
{ this.conn = conn; } #region iOperatorDao Members public int Delete(string username) { Console.WriteLine("User "+username+" dihapus.\n"); ss = "delete from operator where user_name = @1"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { cmd.Parameters.AddWithValue("@1", username); return cmd.ExecuteNonQuery(); } } public int Save(Operator _operator) { Console.WriteLine("User " + _operator.UserName + " ditambahkan.\n"); ss = "insert into operator (user_name, password) values (@1, @2)"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { cmd.Parameters.AddWithValue("@1", _operator.UserName); cmd.Parameters.AddWithValue("@2", _operator.Password); return cmd.ExecuteNonQuery(); } } public int Update(Operator _operator) { Console.WriteLine("User " + _operator.UserName + " diubah.\n"); ss = "update operator set password=@1 where user_name=@2"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { cmd.Parameters.AddWithValue("@2", _operator.UserName); cmd.Parameters.AddWithValue("@1", _operator.Password); return cmd.ExecuteNonQuery(); } } public List<Operator> getAll() { List<Operator> listOperator = new List<Operator>(); ss = "select user_name, password from operator order by user_name"; using (SqlCommand cmd = new SqlCommand(ss, conn)) {
using (SqlDataReader dtr = cmd.ExecuteReader()) { while (dtr.Read()) { Operator op = new Operator(); op.UserName = dtr.GetString(0); op.Password = dtr.GetString(1); listOperator.Add(op); } } } return listOperator; } public bool isValidOperator(Operator _operator) { bool result = false; ss = "select user_name, password from operator where user_name=@1 and password=@2"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { cmd.Parameters.AddWithValue("@1", _operator.UserName); cmd.Parameters.AddWithValue("@2", _operator.Password); using (SqlDataReader dtr = cmd.ExecuteReader()) { if(dtr.Read()) { result = true; Console.WriteLine("User " + _operator.UserName + " login ke sistem.\n"); } } } return result; } #endregion #region iOperatorDao Members
public System.Data.DataSet getReportOperator() { Console.WriteLine("Method getReportOperator diakses"); ss = "select user_name, password from operator order by user_name"; SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = new SqlCommand(ss, conn); DataSet ds = new DataSet(); da.Fill(ds, "operator");
10
namespace SmartRetailServer.Dao { class SupplierDao : MarshalByRefObject, iSupplierDao { private SqlConnection conn = null; private string ss = String.Empty; public SupplierDao() { this.conn = DBConnection.GetConnection(); }
// constructor public SupplierDao(SqlConnection conn) { this.conn = conn; } #region iSupplierDao Members public int Delete(int supplierID) { ss = "delete from supplier where id = @1"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { cmd.Parameters.AddWithValue("@1", supplierID); return cmd.ExecuteNonQuery(); } } public int Save(Supplier supplier) { ss = "insert into supplier (id, nama, alamat, kota, kontak, telepon) values (@1, @2, @3, @4, @5, @6)"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { cmd.Parameters.AddWithValue("@1", supplier.SupplierID);
11
public int Update(Supplier supplier) { ss = "update supplier set nama=@1, alamat=@2, kota=@3, kontak=@4, telepon=@5 where id=@6"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { cmd.Parameters.AddWithValue("@6", supplier.SupplierID); cmd.Parameters.AddWithValue("@1", supplier.Nama); cmd.Parameters.AddWithValue("@2", supplier.Alamat); cmd.Parameters.AddWithValue("@3", supplier.Kota); cmd.Parameters.AddWithValue("@4", supplier.Kontak); cmd.Parameters.AddWithValue("@5", supplier.Telepon); return cmd.ExecuteNonQuery(); } } public List<Supplier> getAll() { List<Supplier> listSupplier = new List<Supplier>(); ss = "select id, nama, alamat, kota, kontak, telepon from supplier order by nama"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { using (SqlDataReader dtr = cmd.ExecuteReader()) { while (dtr.Read()) { Supplier sp = new Supplier(); sp.SupplierID = dtr.GetInt32(0); sp.Nama = dtr.GetString(1); sp.Alamat = dtr.GetString(2); sp.Kota = dtr.GetString(3); sp.Kontak = dtr.GetString(4); sp.Telepon = dtr.GetString(5); listSupplier.Add(sp); } } } return listSupplier; } public List<Supplier> getByName(string name) { List<Supplier> listSupplier = new List<Supplier>();
12
ss = "select id, nama, alamat, kota, kontak, telepon from supplier " + "where nama like @1 " + "order by nama"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { cmd.Parameters.AddWithValue("@1", "%" + name + "%"); using (SqlDataReader dtr = cmd.ExecuteReader()) { while (dtr.Read()) { Supplier sp = new Supplier(); sp.SupplierID = dtr.GetInt32(0); sp.Nama = dtr.GetString(1); sp.Alamat = dtr.GetString(2); sp.Kota = dtr.GetString(3); sp.Kontak = dtr.GetString(4); sp.Telepon = dtr.GetString(5); listSupplier.Add(sp); } } } return listSupplier; } #endregion #region iSupplierDao Members
public System.Data.DataSet getReportSupplier() { Console.WriteLine("Method getReportSupplier diakses"); ss = "select id, nama, alamat, kota, kontak, telepon from supplier order by nama"; SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = new SqlCommand(ss, conn); DataSet ds = new DataSet(); da.Fill(ds, "supplier"); return ds; } #endregion } }
13
namespace SmartRetailServer.Dao { class SupplierDao : MarshalByRefObject, iSupplierDao { private SqlConnection conn = null; private string ss = String.Empty; public SupplierDao() { this.conn = DBConnection.GetConnection(); }
// constructor public SupplierDao(SqlConnection conn) { this.conn = conn; } #region iSupplierDao Members public int Delete(int supplierID) { ss = "delete from supplier where id = @1"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { cmd.Parameters.AddWithValue("@1", supplierID); return cmd.ExecuteNonQuery(); } } public int Save(Supplier supplier) { ss = "insert into supplier (id, nama, alamat, kota, kontak, telepon) values (@1, @2, @3, @4, @5, @6)"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { cmd.Parameters.AddWithValue("@1", supplier.SupplierID); cmd.Parameters.AddWithValue("@2", supplier.Nama); cmd.Parameters.AddWithValue("@3", supplier.Alamat); cmd.Parameters.AddWithValue("@4", supplier.Kota); cmd.Parameters.AddWithValue("@5", supplier.Kontak); cmd.Parameters.AddWithValue("@6", supplier.Telepon); return cmd.ExecuteNonQuery();
14
} } public int Update(Supplier supplier) { ss = "update supplier set nama=@1, alamat=@2, kota=@3, kontak=@4, telepon=@5 where id=@6"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { cmd.Parameters.AddWithValue("@6", supplier.SupplierID); cmd.Parameters.AddWithValue("@1", supplier.Nama); cmd.Parameters.AddWithValue("@2", supplier.Alamat); cmd.Parameters.AddWithValue("@3", supplier.Kota); cmd.Parameters.AddWithValue("@4", supplier.Kontak); cmd.Parameters.AddWithValue("@5", supplier.Telepon); return cmd.ExecuteNonQuery(); } } public List<Supplier> getAll() { List<Supplier> listSupplier = new List<Supplier>(); ss = "select id, nama, alamat, kota, kontak, telepon from supplier order by nama"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { using (SqlDataReader dtr = cmd.ExecuteReader()) { while (dtr.Read()) { Supplier sp = new Supplier(); sp.SupplierID = dtr.GetInt32(0); sp.Nama = dtr.GetString(1); sp.Alamat = dtr.GetString(2); sp.Kota = dtr.GetString(3); sp.Kontak = dtr.GetString(4); sp.Telepon = dtr.GetString(5); listSupplier.Add(sp); } } } return listSupplier; } public List<Supplier> getByName(string name) { List<Supplier> listSupplier = new List<Supplier>(); ss = "select id, nama, alamat, kota, kontak, telepon from supplier " + "where nama like @1 " + "order by nama"; using (SqlCommand cmd = new SqlCommand(ss, conn)) { cmd.Parameters.AddWithValue("@1", "%" + name + "%");
15
using (SqlDataReader dtr = cmd.ExecuteReader()) { while (dtr.Read()) { Supplier sp = new Supplier(); sp.SupplierID = dtr.GetInt32(0); sp.Nama = dtr.GetString(1); sp.Alamat = dtr.GetString(2); sp.Kota = dtr.GetString(3); sp.Kontak = dtr.GetString(4); sp.Telepon = dtr.GetString(5); listSupplier.Add(sp); } } } return listSupplier; } #endregion #region iSupplierDao Members
public System.Data.DataSet getReportSupplier() { Console.WriteLine("Method getReportSupplier diakses"); ss = "select id, nama, alamat, kota, kontak, telepon from supplier order by nama"; SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = new SqlCommand(ss, conn); DataSet ds = new DataSet(); da.Fill(ds, "supplier"); return ds; } #endregion } }
namespace SmartRetailLib.iDao { public interface iBeliDao { int Save(Beli beli); int Update(Beli beli);
16
int Delete(string nota); List<Beli> GetAll(); Beli GetByNota(string nota); bool IsExistNota(string nota); DataSet GetReportPembelian(); } }
namespace SmartRetailLib.iDao { public interface iCustomerDao { int Save(Customer customer); int Update(Customer customer); int Delete(int customerID); List<Customer> getAll(); List<Customer> getByName(string name); DataSet getReportCustomer(); } }
namespace SmartRetailLib.iDao { public interface iItemBeliDao { int Save(ItemBeli itemBeli); int Update(ItemBeli itemBeli); int Delete(int itemBeliID); } }
17
namespace SmartRetailLib.iDao { public interface iItemJualDao { int Save(ItemJual itemJual); int Update(ItemJual itemJual); int Delete(int itemJualID); } }
namespace SmartRetailLib.iDao { public interface iJualDao { int Save(Jual jual); int Update(Jual jual); int Delete(string nota);
List<Jual> GetAll(); Beli GetByNota(string nota); bool IsExistNota(string nota); DataSet GetReportPenjualan();
18
namespace SmartRetailLib.iDao { public interface iOperatorDao { int Save(Operator _operator); int Update(Operator _operator); int Delete(string username);
DataSet getReportOperator(); } }
namespace SmartRetailLib.iDao { public interface iSupplierDao { int Save(Supplier supplier); int Update(Supplier supplier); int Delete(int supplierID);
19
DataSet getReportSupplier();
} }
Kode:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;
20
{ private iOperatorDao operatorDao = null; private FrmMain formMain = null; public FrmLogin() { InitializeComponent();
if (textUser.Text == "" || textPassword.Text == "") { MessageBox.Show("Pengguna/Sandi tidak boleh kosong.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
21
} else { MessageBox.Show("Pengguna / Sandi yang Anda masukkan salah.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } }
2. Form Utama
Kode:
22
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;
namespace SmartRetailClient.views { public partial class FrmMain : Form { private FrmBarang formBarang = null; private FrmCustomer formCustomer = null; private FrmSupplier formSupplier = null; private FrmOperator formOperator = null; private FrmPembelian formPembelian = null;
23
{ formBarang.Dispose(); formBarang = null; } if (formBarang == null) { formBarang = new FrmBarang(); formBarang.MdiParent = this; formBarang.Show(); }
private void menuMasterCustomer_Click(object sender, EventArgs e) { if (formCustomer != null) { formCustomer.Dispose(); formCustomer = null; } if (formCustomer == null) { formCustomer = new FrmCustomer(); formCustomer.MdiParent = this; formCustomer.Show(); }
24
private void menuMasterSupplier_Click(object sender, EventArgs e) { if (formSupplier != null) { formSupplier.Dispose(); formSupplier = null; } if (formSupplier == null) { formSupplier = new FrmSupplier(); formSupplier.MdiParent = this; formSupplier.Show(); } }
private void menuUtilityOperator_Click(object sender, EventArgs e) { if (formOperator != null) { formOperator.Dispose(); formOperator = null; } if (formOperator == null) {
25
private void logOutToolStripMenuItem_Click(object sender, EventArgs e) { this.Hide(); FrmLogin formLogin = new FrmLogin();
26
formLogin.ShowDialog();
this.Close(); }
private void menuTransaksiPembelian_Click(object sender, EventArgs e) { if (formPembelian != null) { formPembelian.Dispose(); formPembelian = null; } if (formPembelian == null) { formPembelian = new FrmPembelian(); formPembelian.Operator = toolStripStatusLabel1.Text; formPembelian.MdiParent = this; formPembelian.Show(); } } } }
3. Form Barang
Final Project Mata Kuliah Pemrograman Client Server 27
Kode:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;
using SmartRetailLib.iDao; using SmartRetailLib.Model; using SmartRetailClient.functions; using SmartRetailClient.reports; using SmartRetailClient.views;
28
namespace SmartRetailClient { public partial class FrmBarang : Form { private iBarangDao barangDao = null; private bool isTambahData = false; public FrmBarang() { InitializeComponent();
// event FrmBarang_Load dipanggil setelah constructor private void FrmBarang_Load(object sender, EventArgs e) { // set posisi awal btnSimpan dan btnBatal btnSimpan.Location = btnTambah.Location; btnBatal.Location = btnPerbaiki.Location;
// method untuk mengaktifkan/menonaktifkan input data private void LockInput(bool status) { txtKodeBarang.Enabled = !status; txtNamaBarang.Enabled = !status; txtHargaBeli.Enabled = !status;
29
// method untuk mengosongkan inputan data private void ResetInput() { txtKodeBarang.Clear(); txtNamaBarang.Clear(); txtHargaBeli.Text = "0"; txtHargaJual.Text = "0"; txtStok.Text = "0"; }
// method untuk menampilkan/menyembunyikan button private void HideButton(bool status) { btnTambah.Visible = !status; btnPerbaiki.Visible = !status; btnHapus.Visible = !status;
// method untuk menampilkan data barang ke listview private void FillToListView(bool isTambahData, Barang barang) { if (isTambahData) { int noUrut = lvwBarang.Items.Count + 1; ListViewItem item = new ListViewItem(noUrut.ToString()); item.SubItems.Add(barang.BarangID); item.SubItems.Add(barang.Nama); item.SubItems.Add(barang.HargaBeli.ToString()); item.SubItems.Add(barang.HargaJual.ToString()); item.SubItems.Add(barang.Stok.ToString());
30
lvwBarang.Items.Add(item); } else { int row = lvwBarang.SelectedIndices[0]; ListViewItem itemRow = lvwBarang.Items[row]; itemRow.SubItems[2].Text = barang.Nama; itemRow.SubItems[3].Text = barang.HargaBeli.ToString(); itemRow.SubItems[4].Text = barang.HargaJual.ToString(); itemRow.SubItems[5].Text = barang.Stok.ToString(); } }
// method untuk menampilkan semua data barang private void LoadDataBarang() { lvwBarang.Items.Clear(); List<Barang> daftarBarang = barangDao.getAll(); foreach (Barang barang in daftarBarang) { FillToListView(true, barang); } }
// method untuk menampilkan data barang berdasarkan nama barang // dipanggil pada saat pencarian private void LoadDataBarang(string namaBarang) { lvwBarang.Items.Clear(); List<Barang> daftarBarang = barangDao.getByName(namaBarang); foreach (Barang barang in daftarBarang) { FillToListView(true, barang); } }
31
{ // cek apakah barang sudah dipilih if (lvwBarang.SelectedItems.Count > 0) { // ambil baris barang yang diperbaiki int row = lvwBarang.SelectedIndices[0]; ListViewItem itemRow = lvwBarang.Items[row]; txtKodeBarang.Text = itemRow.SubItems[1].Text; txtNamaBarang.Text = itemRow.SubItems[2].Text; txtHargaBeli.Text = itemRow.SubItems[3].Text; txtHargaJual.Text = itemRow.SubItems[4].Text; txtStok.Text = itemRow.SubItems[5].Text; LockInput(false); // aktifkan input data HideButton(true); // sembunyikan tombol tambah, perbaiki dan hapus isTambahData = false; } else { MessageBox.Show("Data barang belum dipilih", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void btnHapus_Click(object sender, EventArgs e) { // cek apakah barang sudah dipilih if (lvwBarang.SelectedItems.Count > 0) { // ambil baris barang yang dihapus int row = lvwBarang.SelectedIndices[0]; ListViewItem itemRow = lvwBarang.Items[row]; string kodeBarang = itemRow.SubItems[1].Text; string namaBarang = itemRow.SubItems[2].Text; string msg = "Apakah data barang '" + namaBarang + "' ingin dihapus ?";
32
if (MessageBox.Show(msg, "Konfirmasi", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { int result = barangDao.Delete(kodeBarang); if (result > 0) // data barang berhasil dihapus { MessageBox.Show("Data barang berhasil dihapus", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadDataBarang();// refresh data barang } else { MessageBox.Show("Data barang gagal dihapus", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } else { MessageBox.Show("Data barang belum dipilih", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void btnSimpan_Click(object sender, EventArgs e) { int result = 0; Barang barang = new Barang(); barang.BarangID = txtKodeBarang.Text; barang.Nama = txtNamaBarang.Text; barang.HargaBeli = int.Parse(txtHargaBeli.Text); barang.HargaJual = int.Parse(txtHargaJual.Text); barang.Stok = int.Parse(txtStok.Text); if (isTambahData) { result = barangDao.Save(barang); }
33
else { result = barangDao.Update(barang); } if (result > 0) { MessageBox.Show("Data barang berhasil disimpan", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); // refresh data barang yang ditampilkan FillToListView(isTambahData, barang); LockInput(true); // nonaktifkan input data ResetInput(); // kosongkan input data HideButton(false); // tampilkan tombol tambah, perbaiki dan hapus } else { MessageBox.Show("Data barang gagal disimpan", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnBatal_Click(object sender, EventArgs e) { LockInput(true); // nonaktifkan input data ResetInput(); // kosongkan input data HideButton(false); // tampilkan tombol tambah, perbaiki dan hapus lvwBarang_SelectedIndexChanged(this, e); }
34
LockInput(false); // aktifkan input data ResetInput(); // kosongkan input data HideButton(true); // sembunyikan tombol tambah, perbaiki dan hapus isTambahData = true; }
private void lvwBarang_SelectedIndexChanged(object sender, EventArgs e) { if (lvwBarang.SelectedItems.Count > 0) { // ambil baris barang yang dihapus int row = lvwBarang.SelectedIndices[0]; ListViewItem itemRow = lvwBarang.Items[row]; string kodeBarang = itemRow.SubItems[1].Text; string namaBarang = itemRow.SubItems[2].Text; string hargaBeli = itemRow.SubItems[3].Text; string hargaJual = itemRow.SubItems[4].Text; string stok = itemRow.SubItems[5].Text;
txtHargaBeli.Text = hargaBeli; txtHargaJual.Text = hargaJual; txtKodeBarang.Text = kodeBarang; txtNamaBarang.Text = namaBarang; txtStok.Text = stok; } }
public void showReportBarang(Form frm) { string header = "Laporan Data Barang"; ReportBarang rptBarang = new ReportBarang(header);
35
} }
4. Form Customer
36
Kode:
using using using using using using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Text; System.Windows.Forms;
37
{ private iCustomerDao customerDao = null; private bool isTambahData = false; private int customerID = 0; public FrmCustomer() { InitializeComponent(); customerDao = (iCustomerDao)Activator.GetObject(typeof(iCustomerDao), Functions.bukaKoneksi("RetailManagerServer.CustomerDao")); LockInput(true); LoadDataCustomer(); HideButton(false); } // method untuk mengaktifkan/menonaktifkan input data private void LockInput(bool status) { textNamaCustomer.Enabled = !status; textKotaCustomer.Enabled = !status; textAlamatCustomer.Enabled = !status; textKontak.Enabled = !status; textTelepon.Enabled = !status; } // method untuk mengosongkan inputan data private void ResetInput() { textNamaCustomer.Text = ""; textAlamatCustomer.Text = ""; textKotaCustomer.Text = ""; textKontak.Text = ""; textTelepon.Text = ""; } // method untuk menampilkan/menyembunyikan button private void HideButton(bool status) { btnTambah.Visible = !status; btnPerbaiki.Visible = !status; btnHapus.Visible = !status; btnSimpan.Visible = status; btnBatal.Visible = status; }
38
private void FrmCustomer_Load(object sender, EventArgs e) { // sembunyikan btnSimpan dan btnBatal btnSimpan.Visible = false; btnBatal.Visible = false; } // method untuk menampilkan data barang ke listview private void FillToListView(bool isTambahData, Customer customer) { if (isTambahData) { int noUrut = lvwCustomer.Items.Count + 1; ListViewItem item = new ListViewItem(noUrut.ToString()); item.SubItems.Add(customer.CustomerID.ToString()); item.SubItems.Add(customer.Nama); item.SubItems.Add(customer.Alamat); item.SubItems.Add(customer.Kota); item.SubItems.Add(customer.Kontak); item.SubItems.Add(customer.Telepon); lvwCustomer.Items.Add(item); } else { int row = lvwCustomer.SelectedIndices[0]; ListViewItem itemRow = lvwCustomer.Items[row]; itemRow.SubItems[2].Text = customer.Nama; itemRow.SubItems[3].Text = customer.Alamat; itemRow.SubItems[4].Text = customer.Kota; itemRow.SubItems[4].Text = customer.Kontak; itemRow.SubItems[4].Text = customer.Telepon; } } // method untuk menampilkan semua data barang private void LoadDataCustomer() { lvwCustomer.Items.Clear(); List<Customer> daftarCustomer = customerDao.getAll(); foreach (Customer customer in daftarCustomer) { FillToListView(true, customer); } } // method untuk menampilkan data barang berdasarkan nama barang // dipanggil pada saat pencarian private void LoadDataCustomer(string namaBarang) {
39
lvwCustomer.Items.Clear(); List<Customer> daftarCustomer = customerDao.getByName(namaBarang); foreach (Customer customer in daftarCustomer) { FillToListView(true, customer); } } private void lvwCustomer_SelectedIndexChanged(object sender, EventArgs e) { if (lvwCustomer.SelectedItems.Count > 0) { // ambil baris barang yang dihapus int row = lvwCustomer.SelectedIndices[0]; ListViewItem itemRow = lvwCustomer.Items[row]; customerID = Int32.Parse(itemRow.SubItems[1].Text); string namaCustomer = itemRow.SubItems[2].Text; string alamat = itemRow.SubItems[3].Text; string kota = itemRow.SubItems[4].Text; string kontak = itemRow.SubItems[5].Text; string telpon = itemRow.SubItems[6].Text; textNamaCustomer.Text = namaCustomer; textAlamatCustomer.Text = alamat; textKotaCustomer.Text = kota; textKontak.Text = kontak; textTelepon.Text = telpon; } } private void btnTambah_Click(object sender, EventArgs e) { LockInput(false); // aktifkan input data ResetInput(); // kosongkan input data HideButton(true); // sembunyikan tombol tambah, perbaiki dan hapus isTambahData = true; } private void btnCari_Click(object sender, EventArgs e) { LoadDataCustomer(txtCari.Text); } private void btnBatal_Click(object sender, EventArgs e) {
40
LockInput(true); // nonaktifkan input data ResetInput(); // kosongkan input data HideButton(false); // tampilkan tombol tambah, perbaiki dan hapus lvwCustomer_SelectedIndexChanged(this, e); } private void btnHapus_Click(object sender, EventArgs e) { // cek apakah barang sudah dipilih if (lvwCustomer.SelectedItems.Count > 0) { // ambil baris barang yang dihapus int row = lvwCustomer.SelectedIndices[0]; ListViewItem itemRow = lvwCustomer.Items[row]; customerID = Int32.Parse(itemRow.SubItems[1].Text); string namaCustomer = itemRow.SubItems[2].Text; string msg = "Apakah data customer dengan nama '" + namaCustomer + "' ingin dihapus ?"; if (MessageBox.Show(msg, "Konfirmasi", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { int result = customerDao.Delete(customerID); if (result > 0) // data barang berhasil dihapus { MessageBox.Show("Data Customer berhasil dihapus", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadDataCustomer();// refresh data barang } else { MessageBox.Show("Data Customer gagal dihapus", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } } private void btnPerbaiki_Click(object sender, EventArgs e) { // cek apakah barang sudah dipilih if (lvwCustomer.SelectedItems.Count > 0) { // ambil baris barang yang diperbaiki int row = lvwCustomer.SelectedIndices[0]; ListViewItem itemRow = lvwCustomer.Items[row]; customerID = Int32.Parse(itemRow.SubItems[1].Text); LockInput(false); // aktifkan input data
41
HideButton(true); // sembunyikan tombol tambah, perbaiki dan hapus isTambahData = false; } else { MessageBox.Show("Data customer belum dipilih", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } private void btnSimpan_Click(object sender, EventArgs e) { int result = 0; Customer customer = new Customer(); customer.CustomerID = customerID; customer.Nama = textNamaCustomer.Text; customer.Alamat = textAlamatCustomer.Text; customer.Kota = textKotaCustomer.Text; customer.Kontak = textKontak.Text; customer.Telepon = textTelepon.Text; if (isTambahData) { result = customerDao.Save(customer); } else { result = customerDao.Update(customer); } if (result > 0) { MessageBox.Show("Data customer berhasil disimpan", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); // refresh data barang yang ditampilkan LoadDataCustomer(); LockInput(true); // nonaktifkan input data ResetInput(); // kosongkan input data HideButton(false); // tampilkan tombol tambah, perbaiki dan hapus } else { MessageBox.Show("Data customer gagal disimpan", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void btnPreview_Click(object sender, EventArgs e) {
42
this.showReportCustomer(this.ParentForm); } public void showReportCustomer(Form frm) { string header = "Laporan Data Customer"; ReportCustomer rptCustomer = new ReportCustomer(header); rptCustomer.DataSource = customerDao.getReportCustomer(); rptCustomer.DataMember = "customer"; rptCustomer.Run(); FrmReport frmReport = new FrmReport(header, rptCustomer.Document); frmReport.MdiParent = frm; frmReport.Show(); } } }
5. Form Supplier
43
Kode:
using using using using using using using using using using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Text; System.Windows.Forms; SmartRetailLib.iDao; SmartRetailLib.Model; SmartRetailClient.functions; SmartRetailClient.reports;
namespace SmartRetailClient.views { public partial class FrmSupplier : Form { private iSupplierDao supplierDao = null; private bool isTambahData = false;
44
private int supplierID = 0; public FrmSupplier() { InitializeComponent(); supplierDao = (iSupplierDao)Activator.GetObject(typeof(iSupplierDao), Functions.bukaKoneksi("RetailManagerServer.SupplierDao")); LockInput(true); LoadDataSupplier(); HideButton(false); } // method untuk mengaktifkan/menonaktifkan input data private void LockInput(bool status) { textNamaSupplier.Enabled = !status; textKotaSupplier.Enabled = !status; textAlamatSupplier.Enabled = !status; textKontak.Enabled = !status; textTelepon.Enabled = !status; } // method untuk mengosongkan inputan data private void ResetInput() { textNamaSupplier.Text = ""; textAlamatSupplier.Text = ""; textKotaSupplier.Text = ""; textKontak.Text = ""; textTelepon.Text = ""; } // method untuk menampilkan/menyembunyikan button private void HideButton(bool status) { btnTambah.Visible = !status; btnPerbaiki.Visible = !status; btnHapus.Visible = !status; btnSimpan.Visible = status; btnBatal.Visible = status; } // method untuk menampilkan data barang ke listview private void FillToListView(bool isTambahData, Supplier supplier) { if (isTambahData) { int noUrut = lvwSupplier.Items.Count + 1; ListViewItem item = new ListViewItem(noUrut.ToString()); item.SubItems.Add(supplier.SupplierID.ToString()); item.SubItems.Add(supplier.Nama);
45
item.SubItems.Add(supplier.Alamat); item.SubItems.Add(supplier.Kota); item.SubItems.Add(supplier.Kontak); item.SubItems.Add(supplier.Telepon); lvwSupplier.Items.Add(item); } else { int row = lvwSupplier.SelectedIndices[0]; ListViewItem itemRow = lvwSupplier.Items[row]; itemRow.SubItems[2].Text = supplier.Nama; itemRow.SubItems[3].Text = supplier.Alamat; itemRow.SubItems[4].Text = supplier.Kota; itemRow.SubItems[4].Text = supplier.Kontak; itemRow.SubItems[4].Text = supplier.Telepon; } } // method untuk menampilkan semua data barang private void LoadDataSupplier() { lvwSupplier.Items.Clear(); List<Supplier> daftarSupplier = supplierDao.getAll(); foreach (Supplier supplier in daftarSupplier) { FillToListView(true, supplier); } } // method untuk menampilkan data barang berdasarkan nama barang // dipanggil pada saat pencarian private void LoadDataSupplier(string namaSupplier) { lvwSupplier.Items.Clear(); List<Supplier> daftarSupplier = supplierDao.getByName(namaSupplier); foreach (Supplier supplier in daftarSupplier) { FillToListView(true, supplier); } } private void FrmSupplier_Load(object sender, EventArgs e) { // sembunyikan btnSimpan dan btnBatal btnSimpan.Visible = false; btnBatal.Visible = false; } private void lvwSupplier_SelectedIndexChanged(object sender, EventArgs e) { if (lvwSupplier.SelectedItems.Count > 0) { // ambil baris barang yang dihapus int row = lvwSupplier.SelectedIndices[0]; ListViewItem itemRow = lvwSupplier.Items[row];
46
supplierID = Int32.Parse(itemRow.SubItems[1].Text); string namaSupplier = itemRow.SubItems[2].Text; string alamat = itemRow.SubItems[3].Text; string kota = itemRow.SubItems[4].Text; string kontak = itemRow.SubItems[5].Text; string telpon = itemRow.SubItems[6].Text; textNamaSupplier.Text = namaSupplier; textAlamatSupplier.Text = alamat; textKotaSupplier.Text = kota; textKontak.Text = kontak; textTelepon.Text = telpon; } } private void btnTambah_Click(object sender, EventArgs e) { LockInput(false); // aktifkan input data ResetInput(); // kosongkan input data HideButton(true); // sembunyikan tombol tambah, perbaiki dan hapus isTambahData = true; } private void btnCari_Click(object sender, EventArgs e) { LoadDataSupplier(txtCari.Text); } private void btnBatal_Click(object sender, EventArgs e) { LockInput(true); // nonaktifkan input data ResetInput(); // kosongkan input data HideButton(false); // tampilkan tombol tambah, perbaiki dan hapus lvwSupplier_SelectedIndexChanged(this, e); } private void btnHapus_Click(object sender, EventArgs e) { // cek apakah barang sudah dipilih if (lvwSupplier.SelectedItems.Count > 0) { // ambil baris barang yang dihapus int row = lvwSupplier.SelectedIndices[0]; ListViewItem itemRow = lvwSupplier.Items[row]; supplierID = Int32.Parse(itemRow.SubItems[1].Text); string namaCustomer = itemRow.SubItems[2].Text; string msg = "Apakah data supplier dengan nama '" + namaCustomer + "' ingin dihapus ?"; if (MessageBox.Show(msg, "Konfirmasi", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { int result = supplierDao.Delete(supplierID); if (result > 0) // data barang berhasil dihapus
47
{ MessageBox.Show("Data supplier berhasil dihapus", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadDataSupplier();// refresh data barang } else { MessageBox.Show("Data supplier gagal dihapus", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } } private void btnPerbaiki_Click(object sender, EventArgs e) { // cek apakah barang sudah dipilih if (lvwSupplier.SelectedItems.Count > 0) { // ambil baris barang yang diperbaiki int row = lvwSupplier.SelectedIndices[0]; ListViewItem itemRow = lvwSupplier.Items[row]; supplierID = Int32.Parse(itemRow.SubItems[1].Text); LockInput(false); // aktifkan input data HideButton(true); // sembunyikan tombol tambah, perbaiki dan hapus isTambahData = false; } else { MessageBox.Show("Data supplier belum dipilih", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } private void btnSimpan_Click(object sender, EventArgs e) { if (!isValid()) { MessageBox.Show("Data tidak boleh kosong"); textNamaSupplier.Focus(); return; } int result = 0; Supplier supplier = new Supplier(); supplier.SupplierID = supplierID; supplier.Nama = textNamaSupplier.Text; supplier.Alamat = textAlamatSupplier.Text; supplier.Kota = textKotaSupplier.Text; supplier.Kontak = textKontak.Text; supplier.Telepon = textTelepon.Text; if (isTambahData) { result = supplierDao.Save(supplier); }
48
else { result = supplierDao.Update(supplier); } if (result > 0) { MessageBox.Show("Data supplier berhasil disimpan", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); // refresh data barang yang ditampilkan LoadDataSupplier(); LockInput(true); // nonaktifkan input data ResetInput(); // kosongkan input data HideButton(false); // tampilkan tombol tambah, perbaiki dan hapus } else { MessageBox.Show("Data supplier gagal disimpan", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private bool isValid() { if (textKotaSupplier.Text == "" || textNamaSupplier.Text == "" || textKontak.Text == "" || textTelepon.Text == "" || textAlamatSupplier.Text == "") { return false; } else { return true; } } private void btnPreview_Click(object sender, EventArgs e) { this.showReportSupplier(this.ParentForm); } public void showReportSupplier(Form frm) { string header = "Laporan Data Supplier"; ReportCustomer rptSupplier = new ReportCustomer(header); rptSupplier.DataSource = supplierDao.getReportSupplier(); rptSupplier.DataMember = "supplier"; rptSupplier.Run(); FrmReport frmReport = new FrmReport(header, rptSupplier.Document); frmReport.MdiParent = frm; frmReport.Show();
49
} } }
6. Form Operator
Kode:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;
50
using SmartRetailClient.functions;
// method untuk mengaktifkan/menonaktifkan input data private void LockInput(bool status) { textPengguna.Enabled = !status; textPassword.Enabled = !status; }
// method untuk mengosongkan inputan data private void ResetInput() { textPengguna.Text = ""; textPassword.Text = ""; }
51
private void HideButton(bool status) { btnTambah.Visible = !status; btnPerbaiki.Visible = !status; btnHapus.Visible = !status;
// method untuk menampilkan data barang ke listview private void FillToListView(bool isTambahData, Operator op) { if (isTambahData) { int noUrut = lvwOperator.Items.Count + 1; ListViewItem item = new ListViewItem(noUrut.ToString()); item.SubItems.Add(op.UserName); item.SubItems.Add(op.Password); lvwOperator.Items.Add(item); } else { int row = lvwOperator.SelectedIndices[0]; ListViewItem itemRow = lvwOperator.Items[row]; itemRow.SubItems[2].Text = op.UserName; itemRow.SubItems[2].Text = op.Password; } }
// method untuk menampilkan semua data barang private void LoadDataOperator() { lvwOperator.Items.Clear(); List<Operator> daftarOperator = operatorDao.getAll(); foreach (Operator op in daftarOperator) {
52
FillToListView(true, op); } }
private void FrmOperator_Load(object sender, EventArgs e) { // sembunyikan btnSimpan dan btnBatal btnSimpan.Visible = false; btnBatal.Visible = false; }
private void lvwOperator_SelectedIndexChanged(object sender, EventArgs e) { if (lvwOperator.SelectedItems.Count > 0) { // ambil baris barang yang dihapus int row = lvwOperator.SelectedIndices[0]; ListViewItem itemRow = lvwOperator.Items[row]; string username = itemRow.SubItems[1].Text; string password = itemRow.SubItems[2].Text;
} }
private void btnTambah_Click(object sender, EventArgs e) { LockInput(false); // aktifkan input data ResetInput(); // kosongkan input data HideButton(true); // sembunyikan tombol tambah, perbaiki dan hapus isTambahData = true; }
53
{ LockInput(true); // nonaktifkan input data ResetInput(); // kosongkan input data HideButton(false); // tampilkan tombol tambah, perbaiki dan hapus lvwOperator_SelectedIndexChanged(this, e); }
private void btnHapus_Click(object sender, EventArgs e) { // cek apakah barang sudah dipilih if (lvwOperator.SelectedItems.Count > 0) { // ambil baris barang yang dihapus int row = lvwOperator.SelectedIndices[0]; ListViewItem itemRow = lvwOperator.Items[row]; string namaPengguna = itemRow.SubItems[1].Text; string msg = "Apakah data operator dengan nama '" + namaPengguna + "' ingin dihapus ?"; if (MessageBox.Show(msg, "Konfirmasi", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { int result = operatorDao.Delete(namaPengguna); if (result > 0) // data barang berhasil dihapus { MessageBox.Show("Data pengguna berhasil dihapus", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadDataOperator();// refresh data barang } else { MessageBox.Show("Data pengguna gagal dihapus", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
54
private void btnPerbaiki_Click(object sender, EventArgs e) { // cek apakah barang sudah dipilih if (lvwOperator.SelectedItems.Count > 0) { LockInput(false); // aktifkan input data HideButton(true); // sembunyikan tombol tambah, perbaiki dan hapus isTambahData = false; } else { MessageBox.Show("Data operator belum dipilih", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void btnSimpan_Click(object sender, EventArgs e) { int result = 0; Operator op = new Operator(); op.UserName = textPengguna.Text; op.Password = textPassword.Text;
if (isTambahData) { result = operatorDao.Save(op); } else { result = operatorDao.Update(op); } if (result > 0) { MessageBox.Show("Data operator berhasil disimpan", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
55
// refresh data barang yang ditampilkan LoadDataOperator(); LockInput(true); // nonaktifkan input data ResetInput(); // kosongkan input data HideButton(false); // tampilkan tombol tambah, perbaiki dan hapus } else { MessageBox.Show("Data operator gagal disimpan", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
} }
7. Form Pembelian
Kode:
Final Project Mata Kuliah Pemrograman Client Server 56
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;
using SmartRetailLib.Model; using SmartRetailClient.reports; using SmartRetailLib.iDao; using SmartRetailClient.listener; using SmartRetailClient.functions; using RetailManagerKlien.Report;
namespace SmartRetailClient.views { public partial class FrmPembelian : Form, IListener { private iSupplierDao supplierDao = null; private iBeliDao beliDao = null;
57
private void LoadSupplier(ComboBox obj) { List<Supplier> daftarSupplier = supplierDao.getAll(); foreach (Supplier supplier in daftarSupplier) { supplierId.Add(supplier.SupplierID); obj.Items.Add(supplier.Nama); }
private void FillToListView(bool addData, ItemBeli itemBeli) { if (addData) { int noUrut = lvwBarang.Items.Count + 1;
ListViewItem item = new ListViewItem(noUrut.ToString()); item.SubItems.Add(itemBeli.Barang.BarangID); item.SubItems.Add(itemBeli.Barang.Nama); item.SubItems.Add(itemBeli.Jumlah.ToString()); item.SubItems.Add(itemBeli.HargaBeli.ToString()); item.SubItems.Add(itemBeli.HargaJual.ToString()); item.SubItems.Add(Convert.ToString(itemBeli.Jumlah * itemBeli.HargaBeli));
58
total += int.Parse(item.SubItems[6].Text); }
txtNota.Focus(); }
59
FillToListView(addData, (ItemBeli)data); }
#endregion
private void btnTambah_Click(object sender, EventArgs e) { FrmItemPembelian frmItemBeli = new FrmItemPembelian(true); frmItemBeli.Listener = this; frmItemBeli.ShowDialog(); }
private void btnPerbaiki_Click(object sender, EventArgs e) { // cek apakah barang sudah dipilih if (lvwBarang.SelectedItems.Count > 0) { // ambil baris barang yang diperbaiki int row = lvwBarang.SelectedIndices[0]; ListViewItem itemRow = lvwBarang.Items[row];
ItemBeli itemBeli = new ItemBeli(); itemBeli.Barang.BarangID = itemRow.SubItems[1].Text; itemBeli.Barang.Nama = itemRow.SubItems[2].Text; itemBeli.Jumlah = int.Parse(itemRow.SubItems[3].Text); itemBeli.HargaBeli = int.Parse(itemRow.SubItems[4].Text); itemBeli.HargaJual = int.Parse(itemRow.SubItems[5].Text);
} else {
60
private void btnSimpanNota_Click(object sender, EventArgs e) { // cek nota sudah diinputkan if (txtNota.Text.Length == 0) { MessageBox.Show("Nota harus diisi", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtNota.Focus(); return; }
// cek nota sudah pernah digunakan bool isExistNota = beliDao.IsExistNota(txtNota.Text); if (isExistNota) { MessageBox.Show("Nota sudah pernah digunakan", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtNota.Focus(); return; }
// cek item nota sudah diinputkan if (lvwBarang.Items.Count == 0) { MessageBox.Show("Rincian pembelian belum diinputkan", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; }
61
// beli Beli beli = new Beli(); beli.Nota = txtNota.Text; beli.Tanggal = dtpTanggal.Value; beli.Supplier.SupplierID = this.supplierId[cmbSupplier.SelectedIndex]; beli.Operator = this.Operator;
// item beli bisa lebih dari satu, jadi menggunakan class collection List<ItemBeli> daftarItemBeli = new List<ItemBeli>(); foreach (ListViewItem item in lvwBarang.Items) { ItemBeli itemBeli = new ItemBeli(); itemBeli.Barang.BarangID = item.SubItems[1].Text; itemBeli.Jumlah = int.Parse(item.SubItems[3].Text); itemBeli.HargaBeli = int.Parse(item.SubItems[4].Text); itemBeli.HargaJual = int.Parse(item.SubItems[5].Text);
daftarItemBeli.Add(itemBeli); }
int result = beliDao.Save(beli); if (result > 0) { MessageBox.Show("Data pembelian berhasil disimpan", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); ResetForm();
62
} }
private void btnHapus_Click(object sender, EventArgs e) { // cek apakah barang sudah dipilih if (lvwBarang.SelectedItems.Count > 0) { int row = lvwBarang.SelectedIndices[0]; // ambil baris barang yang dihapus
63
string msg = "Apakah data barang '" + namaBarang + "' ingin dihapus ?"; if (MessageBox.Show(msg, "Konfirmasi", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { lvwBarang.Items.RemoveAt(row); } } else { MessageBox.Show("Data barang belum dipilih", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private string _operator; public string Operator{ get { return _operator; } set { _operator = value; } }
64
} }
8. Form Report
Kode:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;
using DataDynamics.ActiveReports.Document;
65
public FrmReport(string header, Document document) : this() { this.Text = header; viewer1.Document = document; }
} }
66