Laporan Final Project Pemrograman Client Server
-
Upload
ananda-miftakhurrokhmat -
Category
Documents
-
view
140 -
download
24
Transcript of Laporan Final Project Pemrograman Client Server
FINAL PROJECT Mata Kuliah Pemrograman Client Server
(Retail Manager)
Disusun Oleh : Feriyadi Iskandar Miftakhurrokhmat
: :
09.11.3229 09.11.3207
Dosen : Bp.Kamarudin, S.Kom
Sekolah Tinggi Ilmu Manajemen dan Komputer Amikom
Yogyakarta 2012
Final Project Mata Kuliah Pemrograman Client Server 1
Screenshot dan Code Program
A. CODE PROGRAM SERVER
1. Code Program Db Conection using System; using System.Collections.Generic; using System.Text; using System.Data.SqlClient; namespace SmartRetailServer { public class DBConnection { public static SqlConnection GetConnection() { string sConn = "Data Source=(local);" + "Initial Catalog=db_retail_cs;" + "Integrated Security=SSPI"; SqlConnection conn = new SqlConnection(sConn); conn.Open(); return conn; } } }
2. Code Program BeliDao.cs using System; using System.Collections.Generic; using System.Text; using SmartRetailLib.iDao; using SmartRetailLib.Model; using System.Data.SqlClient; using System.Data; 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) {
Final Project Mata Kuliah Pemrograman Client Server 2
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()
Final Project Mata Kuliah Pemrograman Client Server 3
{ 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; }
Final Project Mata Kuliah Pemrograman Client Server 4
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 } }
Final Project Mata Kuliah Pemrograman Client Server 5
3. Code Progam CustomerDao.cs using System; using System.Collections.Generic; using System.Text; using SmartRetailLib.iDao; using SmartRetailLib.Model; using System.Data.SqlClient; using System.Data; 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(); } }
Final Project Mata Kuliah Pemrograman Client Server 6
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())
Final Project Mata Kuliah Pemrograman Client Server 7
{ 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 } }
4. Code Program ItemBeliDao.cs using System; using System.Collections.Generic; using System.Text; using SmartRetailLib.iDao; using SmartRetailLib.Model; using System.Data.SqlClient; namespace SmartRetailServer.Dao { public class ItemBeliDao : MarshalByRefObject, iItemBeliDao { private SqlConnection conn = null; private string ss = "";
Final Project Mata Kuliah Pemrograman Client Server 8
public ItemBeliDao() { this.conn = DBConnection.GetConnection(); } #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 } }
5. Code Program OperatorDao.cs using System; using System.Collections.Generic; using System.Text; using SmartRetailLib.iDao; using SmartRetailLib.Model; using System.Data.SqlClient; using System.Data; 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)
Final Project Mata Kuliah Pemrograman Client Server 9
{ 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)) {
Final Project Mata Kuliah Pemrograman Client Server 10
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");
Final Project Mata Kuliah Pemrograman Client Server 11
return ds; } #endregion } }
6. Code Program SupplierDao.cs using System; using System.Collections.Generic; using System.Text; using SmartRetailLib.iDao; using SmartRetailLib.Model; using System.Data.SqlClient; using System.Data; 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);
Final Project Mata Kuliah Pemrograman Client Server 12
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(); } } 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>();
Final Project Mata Kuliah Pemrograman Client Server 13
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 } }
Final Project Mata Kuliah Pemrograman Client Server 14
B. CODE PROGRAM LIBRARY
1. Code Program IbarangDao.cs
using System; using System.Collections.Generic; using System.Text; using SmartRetailLib.iDao; using SmartRetailLib.Model; using System.Data.SqlClient; using System.Data; 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();
Final Project Mata Kuliah Pemrograman Client Server 15
} } 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 + "%");
Final Project Mata Kuliah Pemrograman Client Server 16
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 } }
2. Code Program iBeliDao.cs using System; using System.Collections.Generic; using System.Text; using SmartRetailLib.Model; using System.Data; namespace SmartRetailLib.iDao { public interface iBeliDao { int Save(Beli beli); int Update(Beli beli);
Final Project Mata Kuliah Pemrograman Client Server 17
int Delete(string nota); List<Beli> GetAll(); Beli GetByNota(string nota); bool IsExistNota(string nota); DataSet GetReportPembelian(); } }
3. Code Program iCustomerDao.cs using System; using System.Collections.Generic; using System.Text; using SmartRetailLib.Model; using System.Data; 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(); } }
4. Code Program iItemBeliDao.cs using System;
using System.Collections.Generic;
using System.Text;
using SmartRetailLib.Model;
namespace SmartRetailLib.iDao
{
public interface iItemBeliDao
{
int Save(ItemBeli itemBeli);
int Update(ItemBeli itemBeli);
int Delete(int itemBeliID);
}
}
Final Project Mata Kuliah Pemrograman Client Server 18
5. Code Program iItemJualDao.cs using System;
using System.Collections.Generic;
using System.Text;
using SmartRetailLib.Model;
namespace SmartRetailLib.iDao
{
public interface iItemJualDao
{
int Save(ItemJual itemJual);
int Update(ItemJual itemJual);
int Delete(int itemJualID);
}
}
6. Code Program iJualDao.cs using System;
using System.Collections.Generic;
using System.Text;
using SmartRetailLib.Model;
using System.Data;
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();
}
Final Project Mata Kuliah Pemrograman Client Server 19
}
7. Code Program iOperatorDao.cs using System;
using System.Collections.Generic;
using System.Text;
using SmartRetailLib.Model;
using System.Data;
namespace SmartRetailLib.iDao
{
public interface iOperatorDao
{
int Save(Operator _operator);
int Update(Operator _operator);
int Delete(string username);
List<Operator> getAll();
bool isValidOperator(Operator _operator);
DataSet getReportOperator();
}
}
8. Code Program iSupplierDao.cs using System;
using System.Collections.Generic;
using System.Text;
using SmartRetailLib.Model;
using System.Data;
namespace SmartRetailLib.iDao
{
public interface iSupplierDao
{
int Save(Supplier supplier);
int Update(Supplier supplier);
int Delete(int supplierID);
Final Project Mata Kuliah Pemrograman Client Server 20
List<Supplier> getAll();
List<Supplier> getByName(string name);
DataSet getReportSupplier();
}
}
C. CODE dan SCEENSHOT PROGRAM CLIENT
1. Form Login
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;
namespace SmartRetailClient.views
{
public partial class FrmLogin : Form
Final Project Mata Kuliah Pemrograman Client Server 21
{
private iOperatorDao operatorDao = null;
private FrmMain formMain = null;
public FrmLogin()
{
InitializeComponent();
operatorDao =
(iOperatorDao)Activator.GetObject(typeof(iOperatorDao),
Functions.bukaKoneksi("RetailManagerServer.OperatorDao"));
}
private void btnKeluar_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnMasuk_Click(object sender, EventArgs e)
{
if (textUser.Text == "" || textPassword.Text == "")
{
MessageBox.Show("Pengguna/Sandi tidak boleh kosong.",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Operator op = new Operator();
op.UserName = textUser.Text;
op.Password = textPassword.Text;
if (operatorDao.isValidOperator(op))
{
this.Hide();
formMain = new FrmMain();
formMain.toolStripStatusLabel1.Text = textUser.Text;
formMain.Show();
this.Dispose(false);
Final Project Mata Kuliah Pemrograman Client Server 22
}
else
{
MessageBox.Show("Pengguna / Sandi yang Anda masukkan
salah.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
}
2. Form Utama
Kode:
Final Project Mata Kuliah Pemrograman Client Server 23
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;
public FrmMain()
{
InitializeComponent();
}
private void menuMasterBarang_Click(object sender, EventArgs e)
{
if (formBarang != null)
Final Project Mata Kuliah Pemrograman Client Server 24
{
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();
}
Final Project Mata Kuliah Pemrograman Client Server 25
}
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)
{
Final Project Mata Kuliah Pemrograman Client Server 26
formOperator = new FrmOperator();
formOperator.MdiParent = this;
formOperator.Show();
}
}
private void menuLaporanBarang_Click(object sender, EventArgs e)
{
new FrmBarang().showReportBarang(this);
}
private void menuLaporanCustomer_Click(object sender, EventArgs e)
{
new FrmCustomer().showReportCustomer(this);
}
private void menuLaporanSupplier_Click(object sender, EventArgs e)
{
new FrmSupplier().showReportSupplier(this);
}
private void logOutToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Hide();
FrmLogin formLogin = new FrmLogin();
Final Project Mata Kuliah Pemrograman Client Server 27
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 28
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;
Final Project Mata Kuliah Pemrograman Client Server 29
namespace SmartRetailClient
{
public partial class FrmBarang : Form
{
private iBarangDao barangDao = null;
private bool isTambahData = false;
public FrmBarang()
{
InitializeComponent();
barangDao =
(iBarangDao)Activator.GetObject(typeof(iBarangDao),
Functions.bukaKoneksi("RetailManagerServer.BarangDao"));
LockInput(true);
LoadDataBarang();
HideButton(false);
}
// 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;
// sembunyikan btnSimpan dan btnBatal
btnSimpan.Visible = false;
btnBatal.Visible = false;
}
// method untuk mengaktifkan/menonaktifkan input data
private void LockInput(bool status)
{
txtKodeBarang.Enabled = !status;
txtNamaBarang.Enabled = !status;
txtHargaBeli.Enabled = !status;
Final Project Mata Kuliah Pemrograman Client Server 30
txtHargaJual.Enabled = !status;
txtStok.Enabled = !status;
}
// 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;
btnSimpan.Visible = status;
btnBatal.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());
Final Project Mata Kuliah Pemrograman Client Server 31
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);
}
}
private void btnPerbaiki_Click(object sender, EventArgs e)
Final Project Mata Kuliah Pemrograman Client Server 32
{
// 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 ?";
Final Project Mata Kuliah Pemrograman Client Server 33
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);
}
Final Project Mata Kuliah Pemrograman Client Server 34
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);
}
private void btnCari_Click(object sender, EventArgs e)
{
LoadDataBarang(txtCari.Text);
}
private void btnTambah_Click(object sender, EventArgs e)
{
Final Project Mata Kuliah Pemrograman Client Server 35
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;
}
}
private void btnPreview_Click(object sender, EventArgs e)
{
showReportBarang(this.ParentForm);
}
public void showReportBarang(Form frm)
{
string header = "Laporan Data Barang";
ReportBarang rptBarang = new ReportBarang(header);
Final Project Mata Kuliah Pemrograman Client Server 36
rptBarang.DataSource = barangDao.getReportBarang();
rptBarang.DataMember = "barang";
rptBarang.Run();
FrmReport frmReport = new FrmReport(header,
rptBarang.Document);
frmReport.MdiParent = frm;
frmReport.Show();
}
}
}
4. Form Customer
Final Project Mata Kuliah Pemrograman Client Server 37
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; namespace SmartRetailClient.views { public partial class FrmCustomer : Form
Final Project Mata Kuliah Pemrograman Client Server 38
{ 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; }
Final Project Mata Kuliah Pemrograman Client Server 39
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) {
Final Project Mata Kuliah Pemrograman Client Server 40
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) {
Final Project Mata Kuliah Pemrograman Client Server 41
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
Final Project Mata Kuliah Pemrograman Client Server 42
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) {
Final Project Mata Kuliah Pemrograman Client Server 43
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
Final Project Mata Kuliah Pemrograman Client Server 44
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; namespace SmartRetailClient.views { public partial class FrmSupplier : Form { private iSupplierDao supplierDao = null; private bool isTambahData = false;
Final Project Mata Kuliah Pemrograman Client Server 45
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);
Final Project Mata Kuliah Pemrograman Client Server 46
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];
Final Project Mata Kuliah Pemrograman Client Server 47
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
Final Project Mata Kuliah Pemrograman Client Server 48
{ 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); }
Final Project Mata Kuliah Pemrograman Client Server 49
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();
Final Project Mata Kuliah Pemrograman Client Server 50
} }
} 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;
using SmartRetailLib.iDao;
using SmartRetailLib.Model;
Final Project Mata Kuliah Pemrograman Client Server 51
using SmartRetailClient.functions;
namespace SmartRetailClient.views
{
public partial class FrmOperator : Form
{
private iOperatorDao operatorDao = null;
private bool isTambahData = false;
public FrmOperator()
{
InitializeComponent();
operatorDao =
(iOperatorDao)Activator.GetObject(typeof(iOperatorDao),
Functions.bukaKoneksi("RetailManagerServer.OperatorDao"));
LockInput(true);
LoadDataOperator();
HideButton(false);
}
// 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 = "";
}
// method untuk menampilkan/menyembunyikan button
Final Project Mata Kuliah Pemrograman Client Server 52
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, 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)
{
Final Project Mata Kuliah Pemrograman Client Server 53
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;
textPengguna.Text = username;
textPassword.Text = password;
}
}
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 btnBatal_Click(object sender, EventArgs e)
Final Project Mata Kuliah Pemrograman Client Server 54
{
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);
}
}
}
Final Project Mata Kuliah Pemrograman Client Server 55
}
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);
Final Project Mata Kuliah Pemrograman Client Server 56
// 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 57
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;
private List<int> supplierId = new List<int>();
public FrmPembelian()
{
InitializeComponent();
// mendapatkan proxy untuk remote object
supplierDao =
(iSupplierDao)Activator.GetObject(typeof(iSupplierDao),
Functions.bukaKoneksi("RetailManagerServer.SupplierDao"));
beliDao = (iBeliDao)Activator.GetObject(typeof(iBeliDao),
Functions.bukaKoneksi("RetailManagerServer.BeliDao"));
// load supplier
LoadSupplier(cmbSupplier);
Final Project Mata Kuliah Pemrograman Client Server 58
}
private void LoadSupplier(ComboBox obj)
{
List<Supplier> daftarSupplier = supplierDao.getAll();
foreach (Supplier supplier in daftarSupplier)
{
supplierId.Add(supplier.SupplierID);
obj.Items.Add(supplier.Nama);
}
if (obj.Items.Count > 0) obj.SelectedIndex = 0;
}
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));
lvwBarang.Items.Add(item);
}
else
{
int row = lvwBarang.SelectedIndices[0];
ListViewItem itemRow = lvwBarang.Items[row];
itemRow.SubItems[2].Text = itemBeli.Barang.Nama;
Final Project Mata Kuliah Pemrograman Client Server 59
itemRow.SubItems[3].Text = itemBeli.Jumlah.ToString();
itemRow.SubItems[4].Text =
itemBeli.HargaBeli.ToString();
itemRow.SubItems[5].Text =
itemBeli.HargaJual.ToString();
itemRow.SubItems[6].Text =
Convert.ToString(itemBeli.Jumlah * itemBeli.HargaBeli);
}
// hitung total nota
int total = 0;
foreach (ListViewItem item in lvwBarang.Items)
{
total += int.Parse(item.SubItems[6].Text);
}
lblTotalNota.Text = string.Format("Total : {0:N0}", total);
}
private void ResetForm()
{
txtNota.Clear();
lvwBarang.Items.Clear();
lblTotalNota.Text = "Total : 0";
txtNota.Focus();
}
private void FrmPembelian_Load(object sender, EventArgs e)
{
dtpTanggal.Value = DateTime.Today;
}
#region IListener Members
public void Ok(bool addData, object data)
{
Final Project Mata Kuliah Pemrograman Client Server 60
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);
FrmItemPembelian frmItemBeli = new
FrmItemPembelian(false, itemBeli);
frmItemBeli.Listener = this;
frmItemBeli.ShowDialog();
}
else
{
Final Project Mata Kuliah Pemrograman Client Server 61
MessageBox.Show("Data barang belum dipilih", "Warning",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
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;
}
// persiapan menyimpan mulai dari sini
string msg = "Apakah proses penyimpanan ingin dilanjutkan
?";
Final Project Mata Kuliah Pemrograman Client Server 62
if (MessageBox.Show(msg, "Konfirmasi",
MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) ==
DialogResult.Yes)
{
// 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);
}
// hubungkan antara objek item beli dg objek beli
beli.ItemBeli = daftarItemBeli;
int result = beliDao.Save(beli);
if (result > 0)
{
MessageBox.Show("Data pembelian berhasil disimpan",
"Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
ResetForm();
Final Project Mata Kuliah Pemrograman Client Server 63
}
else
{
MessageBox.Show("Data pembelian gagal disimpan",
"Informasi", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void btnNotaBaru_Click(object sender, EventArgs e)
{
ResetForm();
}
private void btnDaftarNota_Click(object sender, EventArgs e)
{
showReportPembelian(this.ParentForm);
}
private void btnSelesai_Click(object sender, EventArgs e)
{
this.Dispose();
}
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
ListViewItem itemRow = lvwBarang.Items[row];
string namaBarang = itemRow.SubItems[2].Text;
Final Project Mata Kuliah Pemrograman Client Server 64
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; }
}
public void showReportPembelian(Form frm)
{
string header = "Laporan Pembelian Barang";
ARLapPembelian rptPembelian = new ARLapPembelian(header);
rptPembelian.DataSource = beliDao.GetReportPembelian();
rptPembelian.DataMember = "pembelian";
rptPembelian.Run(false);
FrmReport frmReport = new FrmReport(header,
rptPembelian.Document);
frmReport.MdiParent = frm;
frmReport.Show();
}
Final Project Mata Kuliah Pemrograman Client Server 65
}
}
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;
namespace SmartRetailClient.views
{
public partial class FrmReport : Form
Final Project Mata Kuliah Pemrograman Client Server 66
{
public FrmReport()
{
InitializeComponent();
}
public FrmReport(string header, Document document)
: this()
{
this.Text = header;
viewer1.Document = document;
}
}
}