SlideShare una empresa de Scribd logo
1 de 27
Riza Muhammad Nurman 4SC
Click to edit Master title style
LAST
SESSIONon
4SC Q7
LAST
SESSIONon
4SC Q7
FACULTYFACULTY
Riza Muhammad NurmanRiza Muhammad Nurman
Enhanced AppsEnhanced Apps
Facebook : https://facebook.com/rizamanFacebook : https://facebook.com/rizaman
Twitter : https://twitter.com/rhyzoneTwitter : https://twitter.com/rhyzone
SlideShare : https://slideshare.net/rizamanSlideShare : https://slideshare.net/rizaman
Riza Muhammad Nurman 4SC
Click to edit Master title styleContent
• Bekerja Dengan Gambar
• Membuat Form Transaksi
*Source Code : Twitter RMN 4SC_Q7M1_8
Riza Muhammad Nurman 4SC
Click to edit Master title styleCara Kerja
Riza Muhammad Nurman 4SC
Click to edit Master title styleDatabase & Class Faculty
public class Faculty {
private String fac_code, fac_name, fac_email, fac_phone, fac_photo;
private Koneksi obj_koneksi = new Koneksi();
….
public String getFac_photo() {
return fac_photo;
}
public void setFac_photo(String fac_photo) {
this.fac_photo = fac_photo;
}
Riza Muhammad Nurman 4SC
Click to edit Master title styleClass Faculty – doInsert()
public int doInsert() {
int i = 0;
try
{
obj_koneksi.bukaKoneksi();
File file = new File(fac_photo.trim());
FileInputStream fis = new FileInputStream(file);
int len = (int)file.length();
String str = "INSERT INTO faculty(fac_code, fac_name, fac_email, fac_phone, fac_photo) VALUES(?,?,?,?,?)";
PreparedStatement pr = obj_koneksi.con.prepareStatement(str);
pr.setString(1,fac_code.trim());
pr.setString(2,fac_name.trim());
pr.setString(3,fac_email.trim());
pr.setString(4,fac_phone.trim());
pr.setBinaryStream(5, fis, len);
i = pr.executeUpdate();
}
catch(FileNotFoundException | SQLException ex){
System.out.println(ex.getMessage());
}
return i;
}
Riza Muhammad Nurman 4SC
Click to edit Master title styleClass Faculty – doUpdate()
public int doUpdate() {
int i = 0; PreparedStatement pr = null;
try
{
obj_koneksi.bukaKoneksi();
if(fac_photo.trim().equals(""))
{
…..
}
else
{
File file = new File(fac_photo.trim());
FileInputStream fis = new FileInputStream(file);
int len = (int)file.length();
String str = "UPDATE faculty SET fac_name = ?," +
"fac_email = ?," +
"fac_phone = ?, " +
"fac_photo = ? " +
"WHERE fac_code = ?";
pr = obj_koneksi.con.prepareStatement(str);
pr.setString(1,fac_name);
pr.setString(2,fac_email);
pr.setString(3,fac_phone);
pr.setBinaryStream(4, fis, len);
pr.setString(5,fac_code);
}
i = pr.executeUpdate();
}
catch(FileNotFoundException | SQLException ex){ System.out.println(ex.getMessage()); }
return i;
}
Riza Muhammad Nurman 4SC
Click to edit Master title styleClass Faculty – getRecord()
public ArrayList getRecord() {
ArrayList data = new ArrayList();
byte[] fileBytes;
try
{
obj_koneksi.bukaKoneksi();
String str = "SELECT * FROM faculty WHERE fac_code = ?";
PreparedStatement pr = obj_koneksi.con.prepareStatement(str);
pr.setString(1,fac_code);
ResultSet rs = pr.executeQuery();
while(rs.next()) {
this.setFac_code(rs.getString(1));
this.setFac_name(rs.getString(2));
this.setFac_email(rs.getString(3));
this.setFac_phone(rs.getString(4));
fileBytes = rs.getBytes(5);
String file = "photo.jpg";
try (OutputStream targetFile = new FileOutputStream(file)) {
targetFile.write(fileBytes);
}
this.setFac_photo(file);
data.add(this.getFac_code()); data.add(this.getFac_name()); data.add(this.getFac_email()); data.add(this.getFac_phone());
data.add(this.getFac_photo());
}
}
catch(IOException | SQLException ex){ System.out.println(ex.getMessage()); }
return data;
}
Riza Muhammad Nurman 4SC
Click to edit Master title styleMerancang Faculty Form
PalettePalette
Tambahkan:
•Label bertuliskan photo
•Tombol btn_photo
bertuliskan Get Photo untuk
mengambil gambar
•Label lbl_photo untuk
menampilkan gambar
•TextField txt_photo untuk
menampilkan nama foto
yang diambil
Tambahkan:
•Label bertuliskan photo
•Tombol btn_photo
bertuliskan Get Photo untuk
mengambil gambar
•Label lbl_photo untuk
menampilkan gambar
•TextField txt_photo untuk
menampilkan nama foto
yang diambil
Panel NavigatorPanel Navigator
Riza Muhammad Nurman 4SC
Click to edit Master title styleFaculty Form
private void add() {
try {
obj.setFac_code(txt_code.getText());
obj.setFac_name(txt_name.getText());
obj.setFac_email(txt_email.getText());
obj.setFac_phone(txt_phone.getText());
obj.setFac_photo(txt_photo.getText());
int i = obj.doInsert();
if(i > 0) {
JOptionPane.showMessageDialog(null, "SUKSES! Data Berhasil Disimpan");
this.clear();
}
else {
JOptionPane.showMessageDialog(null, "PERINGATAN! Harap Memasukkan Data Yang Sesuai");
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"Error: " + e);
}
}
Riza Muhammad Nurman 4SC
Click to edit Master title styleFaculty Form - 2
private void update() {
try {
obj.setFac_code(txt_code.getText().trim());
obj.setFac_name(txt_name.getText().trim());
obj.setFac_email(txt_email.getText().trim());
obj.setFac_phone(txt_phone.getText().trim());
if(!txt_photo.getText().trim().equals("")) {
obj.setFac_photo(txt_photo.getText());
}
int i = obj.doUpdate();
if(i > 0) {
JOptionPane.showMessageDialog(null, "SUKSES! Data Berhasil Diubah");
this.clear();
}
else {
JOptionPane.showMessageDialog(null, "PERINGATAN! Harap Memasukkan Data Yang Sesuai");
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"Error: " + e);
}
}
Riza Muhammad Nurman 4SC
Click to edit Master title styleFaculty Form - 3
private void getPhoto() {
int returnVal = fileChooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
lbl_photo.setIcon(new javax.swing.ImageIcon(file.getAbsolutePath()));
txt_photo.setText(file.getAbsolutePath());
} else {
System.out.println("File access cancelled by user.");
}
}
…
private void btn_photoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.getPhoto();
}
Riza Muhammad Nurman 4SC
Click to edit Master title styleFaculty Form - 3
Riza Muhammad Nurman 4SC
Click to edit Master title styleFaculty Form - 4
private void getRecord(String id)
{
try{
obj.setFac_code(id);
ArrayList data = obj.getRecord();
txt_code.setText((String)data.get(0));
txt_name.setText((String)data.get(1));
txt_email.setText((String)data.get(2));
txt_phone.setText((String)data.get(3));
txt_photo.setText((String)data.get(4));
lbl_photo.setText("");
BufferedImage bufImg=ImageIO.read(new File((String)data.get(4)));
lbl_photo.setIcon(new javax.swing.ImageIcon(bufImg));
}
catch(Exception ex) {
JOptionPane.showMessageDialog(null, "Data Gagal Ditampilkan");
}
}
Riza Muhammad Nurman 4SC
Click to edit Master title styleMembuat Form Transaksi
ADD ITEM : Untuk menambahkan
item ke dalam tabel penjualan
TOTAL :
Perhitungan
total otomatis
dengan
menjumlahkan
Sub Total dari
tabel penjualan
TOTAL :
Perhitungan
total otomatis
dengan
menjumlahkan
Sub Total dari
tabel penjualan
CHANGE : Hasil
pengurangan
PAYMENT -
TOTAL
CHANGE : Hasil
pengurangan
PAYMENT -
TOTAL
Tekan Tombol
OK untuk
memproses
Transaksi
Riza Muhammad Nurman 4SC
Click to edit Master title styleHasil Setelah Eksekusi Program
Riza Muhammad Nurman 4SC
Click to edit Master title styleForm Transaksi - Tabel
1. create table employee
2. (
3. emp_code char(10) not null primary key,
4. emp_name varchar(30) not null,
5. emp_position varchar(30) not null
6. )
7. create table item
8. (
9. item_code char(10) not null primary key,
10. item_name varchar(30) not null,
11. item_price money not null,
12. item_stock int not null
13. )
14. create table transactions
15. (
16. trans_code char(10) not null primary key,
17. trans_date datetime not null,
18. emp_code char(10) not null references employee(emp_code),
19. total money not null
20. )
21. create table transactions_detail
22. (
23. id int identity(1,1) primary key,
24. trans_code char(10) not null references transactions(trans_code),
25. item_code char(10) not null references item(item_code),
26. quantity int not null,
27. sub_total money not null
28. )
Riza Muhammad Nurman 4SC
Click to edit Master title styleForm Transaksi – Trigger Stok
1. alter trigger trgUpdateStock
2. on transactions_detail
3. for insert
4. as
5. declare @qty as int
6. declare @item_code as char(10)
7. declare @trans_code as char(10)
8. declare @subtotal as money
9. declare @stock as int
10. declare @check as int
11. set @trans_code = (select trans_code from inserted)
12. set @item_code = (select item_code from inserted)
13. set @qty = (select quantity from inserted)
14. set @subtotal = (select sub_total from inserted)
15. begin
16. update item
17. set item_stock = item_stock - @qty
18. where item_code = @item_code
19. update transactions
20. set total = total + @subtotal
21. where trans_code = @trans_code
22. end
Riza Muhammad Nurman 4SC
Click to edit Master title styleTransaction Class
public class Transaction {
private String trans_code, trans_date, emp_code, item_code;
private int total, quantity, sub_total;
private Koneksi obj_koneksi = new Koneksi();
….
// Getter & Setter Code
Riza Muhammad Nurman 4SC
Click to edit Master title styleTransaction Class - 2
public int doTransaction() {
int i = 0;
try
{
obj_koneksi.bukaKoneksi();
String str = "INSERT INTO transactions(trans_code, trans_date, emp_code, total)
VALUES(?,getdate(),?,?)";
PreparedStatement pr = obj_koneksi.con.prepareStatement(str);
pr.setString(1,trans_code.trim());
pr.setString(2,emp_code.trim());
pr.setInt(3,total);
i = pr.executeUpdate();
}
catch(SQLException ex){
System.out.println(ex.getMessage());
}
return i;
}
Riza Muhammad Nurman 4SC
Click to edit Master title styleTransaction Class - 3
public int setDetailTransaction() {
int i = 0;
try
{
obj_koneksi.bukaKoneksi();
String str = "INSERT INTO transactions_detail(trans_code, item_code, quantity, sub_total)
VALUES(?,?,?,?)";
PreparedStatement pr = obj_koneksi.con.prepareStatement(str);
pr.setString(1,trans_code.trim());
pr.setString(2,item_code.trim());
pr.setInt(3,quantity);
pr.setInt(4,sub_total);
i = pr.executeUpdate();
}
catch(SQLException ex){
System.out.println(ex.getMessage());
}
return i;
}
Riza Muhammad Nurman 4SC
Click to edit Master title styleVTransaction
public class VTransaction extends javax.swing.JFrame {
Transaction obj_trans = new Transaction();
Item obj_item = new Item();
DefaultTableModel model;
int total;
public VTransaction() {
initComponents();
lbl_date.setText(new java.util.Date().toString());
}
private void clear() {
txt_code.setText("");
txt_quantity.setText("0");
txt_change.setText("");
txt_payment.setText("");
txt_total.setText("");
total = 0;
}
Riza Muhammad Nurman 4SC
Click to edit Master title styleVTransaction - 2
private void doTransactions() {
try {
obj_trans.setTrans_code(txt_trans.getText());
obj_trans.setEmp_code(lbl_empcode.getText());
obj_trans.setTotal(0);
int i = obj_trans.doTransaction();
if(i > 0) {
JOptionPane.showMessageDialog(null, "SUKSES! Data Berhasil Disimpan");
}
else {
JOptionPane.showMessageDialog(null, "PERINGATAN! Harap Memasukkan Data Yang
Sesuai");
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"Error: " + e);
}
}
Riza Muhammad Nurman 4SC
Click to edit Master title styleVTransaction - 3
private void doTransactionDetails() {
model = (DefaultTableModel) table_item.getModel();
int row_count = table_item.getRowCount();
int count = 0;
try {
while(count < row_count) {
String code = model.getValueAt(count,0).toString();
int qty = Integer.parseInt(model.getValueAt(count,3).toString());
int subtotal = Integer.parseInt(model.getValueAt(count,4).toString());
obj_trans.setItem_code(code);
obj_trans.setQuantity(qty);
obj_trans.setSub_total(subtotal);
int i = obj_trans.setDetailTransaction();
count++;
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"Error Details: " + e);
}
}
Riza Muhammad Nurman 4SC
Click to edit Master title styleVTransaction - 4
private void addItem() {
try{
int quantity = Integer.parseInt(txt_quantity.getText());
obj_item.setItem_code(txt_code.getText());
ArrayList data = obj_item.getRecord();
for(int i = 0;i < data.size()-1;i+=4)
{
String item_code = (String)data.get(i);
String item_name = (String)data.get(i+1);
int item_price = (Integer)data.get(i+2);
int subtotal = item_price * quantity;
String[] data_field =
{item_code.trim(),item_name.trim(),String.valueOf(item_price),String.valueOf(quantity), String.valueOf(subtotal) };
model = (DefaultTableModel)table_item.getModel();
model.addRow(data_field);
total = total + subtotal;
obj_trans.setTotal(total);
txt_total.setText(String.valueOf(obj_trans.getTotal()));
}
}
catch(Exception ex) {
JOptionPane.showMessageDialog(null, "Data Gagal Ditampilkan" + ex.getMessage());
}
}
Riza Muhammad Nurman 4SC
Click to edit Master title styleVTransaction - 5
private void clearTable() {
model = (DefaultTableModel) table_item.getModel();
int baris = model.getRowCount();
for (int i = 0; i< baris; i++) {
model.removeRow(0);
}
}
Riza Muhammad Nurman 4SC
Click to edit Master title styleVTransaction - Event
private void btn_itemActionPerformed(java.awt.event.ActionEvent evt) {
this.addItem();
}
private void txt_changeMouseClicked(java.awt.event.MouseEvent evt) {
int payment = Integer.parseInt(txt_payment.getText());
int change = payment - total;
txt_change.setText(String.valueOf(change));
}
private void btn_clearActionPerformed(java.awt.event.ActionEvent evt) {
this.clearTable();
this.clear();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
this.doTransactions();
this.doTransactionDetails();
txt_trans.setText("TRANS NUMBER");
this.clearTable();
this.clear();
}
Riza Muhammad Nurman 4SC
Click to edit Master title style

Más contenido relacionado

Similar a 4SCQ7M1 Last session

Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeletonIram Ramrajkar
 
Stored procedures by thanveer danish melayi
Stored procedures by thanveer danish melayiStored procedures by thanveer danish melayi
Stored procedures by thanveer danish melayiMuhammed Thanveer M
 
Applying Real-time SQL Changes in your Hazelcast Data Grid
Applying Real-time SQL Changes in your Hazelcast Data GridApplying Real-time SQL Changes in your Hazelcast Data Grid
Applying Real-time SQL Changes in your Hazelcast Data GridHazelcast
 
Keep getting a null pointer exception for some odd reasonim creati.pdf
Keep getting a null pointer exception for some odd reasonim creati.pdfKeep getting a null pointer exception for some odd reasonim creati.pdf
Keep getting a null pointer exception for some odd reasonim creati.pdfAroraRajinder1
 
First Failure Data Capture for your enterprise application with WebSphere App...
First Failure Data Capture for your enterprise application with WebSphere App...First Failure Data Capture for your enterprise application with WebSphere App...
First Failure Data Capture for your enterprise application with WebSphere App...Rohit Kelapure
 
Sql storeprocedure
Sql storeprocedureSql storeprocedure
Sql storeprocedureftz 420
 
Best of build 2021 - C# 10 & .NET 6
Best of build 2021 -  C# 10 & .NET 6Best of build 2021 -  C# 10 & .NET 6
Best of build 2021 - C# 10 & .NET 6Moaid Hathot
 
Custom web application development with Django for startups and Django-CRM intro
Custom web application development with Django for startups and Django-CRM introCustom web application development with Django for startups and Django-CRM intro
Custom web application development with Django for startups and Django-CRM introMicroPyramid .
 
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)James Titcumb
 
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)James Titcumb
 
High Performance Core Data
High Performance Core DataHigh Performance Core Data
High Performance Core DataMatthew Morey
 
Instruction1. Please read the two articles. (Kincheloe part 1 &.docx
Instruction1. Please read the two articles. (Kincheloe part 1 &.docxInstruction1. Please read the two articles. (Kincheloe part 1 &.docx
Instruction1. Please read the two articles. (Kincheloe part 1 &.docxcarliotwaycave
 

Similar a 4SCQ7M1 Last session (20)

Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
 
Stored procedures by thanveer danish melayi
Stored procedures by thanveer danish melayiStored procedures by thanveer danish melayi
Stored procedures by thanveer danish melayi
 
Applying Real-time SQL Changes in your Hazelcast Data Grid
Applying Real-time SQL Changes in your Hazelcast Data GridApplying Real-time SQL Changes in your Hazelcast Data Grid
Applying Real-time SQL Changes in your Hazelcast Data Grid
 
Keep getting a null pointer exception for some odd reasonim creati.pdf
Keep getting a null pointer exception for some odd reasonim creati.pdfKeep getting a null pointer exception for some odd reasonim creati.pdf
Keep getting a null pointer exception for some odd reasonim creati.pdf
 
First Failure Data Capture for your enterprise application with WebSphere App...
First Failure Data Capture for your enterprise application with WebSphere App...First Failure Data Capture for your enterprise application with WebSphere App...
First Failure Data Capture for your enterprise application with WebSphere App...
 
Sql storeprocedure
Sql storeprocedureSql storeprocedure
Sql storeprocedure
 
Django
DjangoDjango
Django
 
Xml & Java
Xml & JavaXml & Java
Xml & Java
 
Best of build 2021 - C# 10 & .NET 6
Best of build 2021 -  C# 10 & .NET 6Best of build 2021 -  C# 10 & .NET 6
Best of build 2021 - C# 10 & .NET 6
 
Custom web application development with Django for startups and Django-CRM intro
Custom web application development with Django for startups and Django-CRM introCustom web application development with Django for startups and Django-CRM intro
Custom web application development with Django for startups and Django-CRM intro
 
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
 
Crawler 2
Crawler 2Crawler 2
Crawler 2
 
FMDB - SLC-Cocoaheads
FMDB - SLC-CocoaheadsFMDB - SLC-Cocoaheads
FMDB - SLC-Cocoaheads
 
Code
CodeCode
Code
 
Objective-c Runtime
Objective-c RuntimeObjective-c Runtime
Objective-c Runtime
 
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
 
High Performance Core Data
High Performance Core DataHigh Performance Core Data
High Performance Core Data
 
Web based development
Web based developmentWeb based development
Web based development
 
Instruction1. Please read the two articles. (Kincheloe part 1 &.docx
Instruction1. Please read the two articles. (Kincheloe part 1 &.docxInstruction1. Please read the two articles. (Kincheloe part 1 &.docx
Instruction1. Please read the two articles. (Kincheloe part 1 &.docx
 
Clean code slide
Clean code slideClean code slide
Clean code slide
 

Más de Riza Nurman

SE - Chapter 9 Pemeliharaan Perangkat Lunak
SE - Chapter 9 Pemeliharaan Perangkat LunakSE - Chapter 9 Pemeliharaan Perangkat Lunak
SE - Chapter 9 Pemeliharaan Perangkat LunakRiza Nurman
 
SE - Chapter 8 Strategi Pengujian Perangkat Lunak
SE - Chapter 8 Strategi Pengujian Perangkat LunakSE - Chapter 8 Strategi Pengujian Perangkat Lunak
SE - Chapter 8 Strategi Pengujian Perangkat LunakRiza Nurman
 
SE - Chapter 7 Teknik Pengujian Perangkat Lunak
SE - Chapter 7 Teknik Pengujian Perangkat LunakSE - Chapter 7 Teknik Pengujian Perangkat Lunak
SE - Chapter 7 Teknik Pengujian Perangkat LunakRiza Nurman
 
SE - Chapter 6 Tim dan Kualitas Perangkat Lunak
SE - Chapter 6 Tim dan Kualitas Perangkat LunakSE - Chapter 6 Tim dan Kualitas Perangkat Lunak
SE - Chapter 6 Tim dan Kualitas Perangkat LunakRiza Nurman
 
XML - Chapter 8 WEB SERVICES
XML - Chapter 8 WEB SERVICESXML - Chapter 8 WEB SERVICES
XML - Chapter 8 WEB SERVICESRiza Nurman
 
XML - Chapter 7 XML DAN DATABASE
XML - Chapter 7 XML DAN DATABASEXML - Chapter 7 XML DAN DATABASE
XML - Chapter 7 XML DAN DATABASERiza Nurman
 
XML - Chapter 6 SIMPLE API FOR XML (SAX)
XML - Chapter 6 SIMPLE API FOR XML (SAX)XML - Chapter 6 SIMPLE API FOR XML (SAX)
XML - Chapter 6 SIMPLE API FOR XML (SAX)Riza Nurman
 
XML - Chapter 5 XML DOM
XML - Chapter 5 XML DOMXML - Chapter 5 XML DOM
XML - Chapter 5 XML DOMRiza Nurman
 
DBA BAB 5 - Keamanan Database
DBA BAB 5 - Keamanan DatabaseDBA BAB 5 - Keamanan Database
DBA BAB 5 - Keamanan DatabaseRiza Nurman
 
DBA BAB 4 - Recovery Data
DBA BAB 4 - Recovery DataDBA BAB 4 - Recovery Data
DBA BAB 4 - Recovery DataRiza Nurman
 
DBA BAB 3 - Manage Database
DBA BAB 3 - Manage DatabaseDBA BAB 3 - Manage Database
DBA BAB 3 - Manage DatabaseRiza Nurman
 
DBA BAB 2 - INSTALASI DAN UPGRADE SQL SERVER 2005
DBA BAB 2 - INSTALASI DAN UPGRADE SQL SERVER 2005DBA BAB 2 - INSTALASI DAN UPGRADE SQL SERVER 2005
DBA BAB 2 - INSTALASI DAN UPGRADE SQL SERVER 2005Riza Nurman
 
DBA BAB 1 - Pengenalan Database Administrator
DBA BAB 1 - Pengenalan Database AdministratorDBA BAB 1 - Pengenalan Database Administrator
DBA BAB 1 - Pengenalan Database AdministratorRiza Nurman
 
RMN - XML Source Code
RMN -  XML Source CodeRMN -  XML Source Code
RMN - XML Source CodeRiza Nurman
 
ADP - Chapter 5 Exploring JavaServer Pages Technology
ADP - Chapter 5 Exploring JavaServer Pages TechnologyADP - Chapter 5 Exploring JavaServer Pages Technology
ADP - Chapter 5 Exploring JavaServer Pages TechnologyRiza Nurman
 

Más de Riza Nurman (20)

TOT PHP DAY 1
TOT PHP DAY 1TOT PHP DAY 1
TOT PHP DAY 1
 
SE - Chapter 9 Pemeliharaan Perangkat Lunak
SE - Chapter 9 Pemeliharaan Perangkat LunakSE - Chapter 9 Pemeliharaan Perangkat Lunak
SE - Chapter 9 Pemeliharaan Perangkat Lunak
 
SE - Chapter 8 Strategi Pengujian Perangkat Lunak
SE - Chapter 8 Strategi Pengujian Perangkat LunakSE - Chapter 8 Strategi Pengujian Perangkat Lunak
SE - Chapter 8 Strategi Pengujian Perangkat Lunak
 
SE - Chapter 7 Teknik Pengujian Perangkat Lunak
SE - Chapter 7 Teknik Pengujian Perangkat LunakSE - Chapter 7 Teknik Pengujian Perangkat Lunak
SE - Chapter 7 Teknik Pengujian Perangkat Lunak
 
SE - Chapter 6 Tim dan Kualitas Perangkat Lunak
SE - Chapter 6 Tim dan Kualitas Perangkat LunakSE - Chapter 6 Tim dan Kualitas Perangkat Lunak
SE - Chapter 6 Tim dan Kualitas Perangkat Lunak
 
XML - Chapter 8 WEB SERVICES
XML - Chapter 8 WEB SERVICESXML - Chapter 8 WEB SERVICES
XML - Chapter 8 WEB SERVICES
 
XML - Chapter 7 XML DAN DATABASE
XML - Chapter 7 XML DAN DATABASEXML - Chapter 7 XML DAN DATABASE
XML - Chapter 7 XML DAN DATABASE
 
XML - Chapter 6 SIMPLE API FOR XML (SAX)
XML - Chapter 6 SIMPLE API FOR XML (SAX)XML - Chapter 6 SIMPLE API FOR XML (SAX)
XML - Chapter 6 SIMPLE API FOR XML (SAX)
 
XML - Chapter 5 XML DOM
XML - Chapter 5 XML DOMXML - Chapter 5 XML DOM
XML - Chapter 5 XML DOM
 
DBA BAB 5 - Keamanan Database
DBA BAB 5 - Keamanan DatabaseDBA BAB 5 - Keamanan Database
DBA BAB 5 - Keamanan Database
 
DBA BAB 4 - Recovery Data
DBA BAB 4 - Recovery DataDBA BAB 4 - Recovery Data
DBA BAB 4 - Recovery Data
 
DBA BAB 3 - Manage Database
DBA BAB 3 - Manage DatabaseDBA BAB 3 - Manage Database
DBA BAB 3 - Manage Database
 
DBA BAB 2 - INSTALASI DAN UPGRADE SQL SERVER 2005
DBA BAB 2 - INSTALASI DAN UPGRADE SQL SERVER 2005DBA BAB 2 - INSTALASI DAN UPGRADE SQL SERVER 2005
DBA BAB 2 - INSTALASI DAN UPGRADE SQL SERVER 2005
 
DBA BAB 1 - Pengenalan Database Administrator
DBA BAB 1 - Pengenalan Database AdministratorDBA BAB 1 - Pengenalan Database Administrator
DBA BAB 1 - Pengenalan Database Administrator
 
RMN - XML Source Code
RMN -  XML Source CodeRMN -  XML Source Code
RMN - XML Source Code
 
XML - Chapter 4
XML - Chapter 4XML - Chapter 4
XML - Chapter 4
 
XML - Chapter 3
XML - Chapter 3XML - Chapter 3
XML - Chapter 3
 
XML - Chapter 2
XML - Chapter 2XML - Chapter 2
XML - Chapter 2
 
XML - Chapter 1
XML - Chapter 1XML - Chapter 1
XML - Chapter 1
 
ADP - Chapter 5 Exploring JavaServer Pages Technology
ADP - Chapter 5 Exploring JavaServer Pages TechnologyADP - Chapter 5 Exploring JavaServer Pages Technology
ADP - Chapter 5 Exploring JavaServer Pages Technology
 

Último

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 

Último (20)

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 

4SCQ7M1 Last session

  • 1. Riza Muhammad Nurman 4SC Click to edit Master title style LAST SESSIONon 4SC Q7 LAST SESSIONon 4SC Q7 FACULTYFACULTY Riza Muhammad NurmanRiza Muhammad Nurman Enhanced AppsEnhanced Apps Facebook : https://facebook.com/rizamanFacebook : https://facebook.com/rizaman Twitter : https://twitter.com/rhyzoneTwitter : https://twitter.com/rhyzone SlideShare : https://slideshare.net/rizamanSlideShare : https://slideshare.net/rizaman
  • 2. Riza Muhammad Nurman 4SC Click to edit Master title styleContent • Bekerja Dengan Gambar • Membuat Form Transaksi *Source Code : Twitter RMN 4SC_Q7M1_8
  • 3. Riza Muhammad Nurman 4SC Click to edit Master title styleCara Kerja
  • 4. Riza Muhammad Nurman 4SC Click to edit Master title styleDatabase & Class Faculty public class Faculty { private String fac_code, fac_name, fac_email, fac_phone, fac_photo; private Koneksi obj_koneksi = new Koneksi(); …. public String getFac_photo() { return fac_photo; } public void setFac_photo(String fac_photo) { this.fac_photo = fac_photo; }
  • 5. Riza Muhammad Nurman 4SC Click to edit Master title styleClass Faculty – doInsert() public int doInsert() { int i = 0; try { obj_koneksi.bukaKoneksi(); File file = new File(fac_photo.trim()); FileInputStream fis = new FileInputStream(file); int len = (int)file.length(); String str = "INSERT INTO faculty(fac_code, fac_name, fac_email, fac_phone, fac_photo) VALUES(?,?,?,?,?)"; PreparedStatement pr = obj_koneksi.con.prepareStatement(str); pr.setString(1,fac_code.trim()); pr.setString(2,fac_name.trim()); pr.setString(3,fac_email.trim()); pr.setString(4,fac_phone.trim()); pr.setBinaryStream(5, fis, len); i = pr.executeUpdate(); } catch(FileNotFoundException | SQLException ex){ System.out.println(ex.getMessage()); } return i; }
  • 6. Riza Muhammad Nurman 4SC Click to edit Master title styleClass Faculty – doUpdate() public int doUpdate() { int i = 0; PreparedStatement pr = null; try { obj_koneksi.bukaKoneksi(); if(fac_photo.trim().equals("")) { ….. } else { File file = new File(fac_photo.trim()); FileInputStream fis = new FileInputStream(file); int len = (int)file.length(); String str = "UPDATE faculty SET fac_name = ?," + "fac_email = ?," + "fac_phone = ?, " + "fac_photo = ? " + "WHERE fac_code = ?"; pr = obj_koneksi.con.prepareStatement(str); pr.setString(1,fac_name); pr.setString(2,fac_email); pr.setString(3,fac_phone); pr.setBinaryStream(4, fis, len); pr.setString(5,fac_code); } i = pr.executeUpdate(); } catch(FileNotFoundException | SQLException ex){ System.out.println(ex.getMessage()); } return i; }
  • 7. Riza Muhammad Nurman 4SC Click to edit Master title styleClass Faculty – getRecord() public ArrayList getRecord() { ArrayList data = new ArrayList(); byte[] fileBytes; try { obj_koneksi.bukaKoneksi(); String str = "SELECT * FROM faculty WHERE fac_code = ?"; PreparedStatement pr = obj_koneksi.con.prepareStatement(str); pr.setString(1,fac_code); ResultSet rs = pr.executeQuery(); while(rs.next()) { this.setFac_code(rs.getString(1)); this.setFac_name(rs.getString(2)); this.setFac_email(rs.getString(3)); this.setFac_phone(rs.getString(4)); fileBytes = rs.getBytes(5); String file = "photo.jpg"; try (OutputStream targetFile = new FileOutputStream(file)) { targetFile.write(fileBytes); } this.setFac_photo(file); data.add(this.getFac_code()); data.add(this.getFac_name()); data.add(this.getFac_email()); data.add(this.getFac_phone()); data.add(this.getFac_photo()); } } catch(IOException | SQLException ex){ System.out.println(ex.getMessage()); } return data; }
  • 8. Riza Muhammad Nurman 4SC Click to edit Master title styleMerancang Faculty Form PalettePalette Tambahkan: •Label bertuliskan photo •Tombol btn_photo bertuliskan Get Photo untuk mengambil gambar •Label lbl_photo untuk menampilkan gambar •TextField txt_photo untuk menampilkan nama foto yang diambil Tambahkan: •Label bertuliskan photo •Tombol btn_photo bertuliskan Get Photo untuk mengambil gambar •Label lbl_photo untuk menampilkan gambar •TextField txt_photo untuk menampilkan nama foto yang diambil Panel NavigatorPanel Navigator
  • 9. Riza Muhammad Nurman 4SC Click to edit Master title styleFaculty Form private void add() { try { obj.setFac_code(txt_code.getText()); obj.setFac_name(txt_name.getText()); obj.setFac_email(txt_email.getText()); obj.setFac_phone(txt_phone.getText()); obj.setFac_photo(txt_photo.getText()); int i = obj.doInsert(); if(i > 0) { JOptionPane.showMessageDialog(null, "SUKSES! Data Berhasil Disimpan"); this.clear(); } else { JOptionPane.showMessageDialog(null, "PERINGATAN! Harap Memasukkan Data Yang Sesuai"); } } catch(Exception e) { JOptionPane.showMessageDialog(null,"Error: " + e); } }
  • 10. Riza Muhammad Nurman 4SC Click to edit Master title styleFaculty Form - 2 private void update() { try { obj.setFac_code(txt_code.getText().trim()); obj.setFac_name(txt_name.getText().trim()); obj.setFac_email(txt_email.getText().trim()); obj.setFac_phone(txt_phone.getText().trim()); if(!txt_photo.getText().trim().equals("")) { obj.setFac_photo(txt_photo.getText()); } int i = obj.doUpdate(); if(i > 0) { JOptionPane.showMessageDialog(null, "SUKSES! Data Berhasil Diubah"); this.clear(); } else { JOptionPane.showMessageDialog(null, "PERINGATAN! Harap Memasukkan Data Yang Sesuai"); } } catch(Exception e) { JOptionPane.showMessageDialog(null,"Error: " + e); } }
  • 11. Riza Muhammad Nurman 4SC Click to edit Master title styleFaculty Form - 3 private void getPhoto() { int returnVal = fileChooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); lbl_photo.setIcon(new javax.swing.ImageIcon(file.getAbsolutePath())); txt_photo.setText(file.getAbsolutePath()); } else { System.out.println("File access cancelled by user."); } } … private void btn_photoActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: this.getPhoto(); }
  • 12. Riza Muhammad Nurman 4SC Click to edit Master title styleFaculty Form - 3
  • 13. Riza Muhammad Nurman 4SC Click to edit Master title styleFaculty Form - 4 private void getRecord(String id) { try{ obj.setFac_code(id); ArrayList data = obj.getRecord(); txt_code.setText((String)data.get(0)); txt_name.setText((String)data.get(1)); txt_email.setText((String)data.get(2)); txt_phone.setText((String)data.get(3)); txt_photo.setText((String)data.get(4)); lbl_photo.setText(""); BufferedImage bufImg=ImageIO.read(new File((String)data.get(4))); lbl_photo.setIcon(new javax.swing.ImageIcon(bufImg)); } catch(Exception ex) { JOptionPane.showMessageDialog(null, "Data Gagal Ditampilkan"); } }
  • 14. Riza Muhammad Nurman 4SC Click to edit Master title styleMembuat Form Transaksi ADD ITEM : Untuk menambahkan item ke dalam tabel penjualan TOTAL : Perhitungan total otomatis dengan menjumlahkan Sub Total dari tabel penjualan TOTAL : Perhitungan total otomatis dengan menjumlahkan Sub Total dari tabel penjualan CHANGE : Hasil pengurangan PAYMENT - TOTAL CHANGE : Hasil pengurangan PAYMENT - TOTAL Tekan Tombol OK untuk memproses Transaksi
  • 15. Riza Muhammad Nurman 4SC Click to edit Master title styleHasil Setelah Eksekusi Program
  • 16. Riza Muhammad Nurman 4SC Click to edit Master title styleForm Transaksi - Tabel 1. create table employee 2. ( 3. emp_code char(10) not null primary key, 4. emp_name varchar(30) not null, 5. emp_position varchar(30) not null 6. ) 7. create table item 8. ( 9. item_code char(10) not null primary key, 10. item_name varchar(30) not null, 11. item_price money not null, 12. item_stock int not null 13. ) 14. create table transactions 15. ( 16. trans_code char(10) not null primary key, 17. trans_date datetime not null, 18. emp_code char(10) not null references employee(emp_code), 19. total money not null 20. ) 21. create table transactions_detail 22. ( 23. id int identity(1,1) primary key, 24. trans_code char(10) not null references transactions(trans_code), 25. item_code char(10) not null references item(item_code), 26. quantity int not null, 27. sub_total money not null 28. )
  • 17. Riza Muhammad Nurman 4SC Click to edit Master title styleForm Transaksi – Trigger Stok 1. alter trigger trgUpdateStock 2. on transactions_detail 3. for insert 4. as 5. declare @qty as int 6. declare @item_code as char(10) 7. declare @trans_code as char(10) 8. declare @subtotal as money 9. declare @stock as int 10. declare @check as int 11. set @trans_code = (select trans_code from inserted) 12. set @item_code = (select item_code from inserted) 13. set @qty = (select quantity from inserted) 14. set @subtotal = (select sub_total from inserted) 15. begin 16. update item 17. set item_stock = item_stock - @qty 18. where item_code = @item_code 19. update transactions 20. set total = total + @subtotal 21. where trans_code = @trans_code 22. end
  • 18. Riza Muhammad Nurman 4SC Click to edit Master title styleTransaction Class public class Transaction { private String trans_code, trans_date, emp_code, item_code; private int total, quantity, sub_total; private Koneksi obj_koneksi = new Koneksi(); …. // Getter & Setter Code
  • 19. Riza Muhammad Nurman 4SC Click to edit Master title styleTransaction Class - 2 public int doTransaction() { int i = 0; try { obj_koneksi.bukaKoneksi(); String str = "INSERT INTO transactions(trans_code, trans_date, emp_code, total) VALUES(?,getdate(),?,?)"; PreparedStatement pr = obj_koneksi.con.prepareStatement(str); pr.setString(1,trans_code.trim()); pr.setString(2,emp_code.trim()); pr.setInt(3,total); i = pr.executeUpdate(); } catch(SQLException ex){ System.out.println(ex.getMessage()); } return i; }
  • 20. Riza Muhammad Nurman 4SC Click to edit Master title styleTransaction Class - 3 public int setDetailTransaction() { int i = 0; try { obj_koneksi.bukaKoneksi(); String str = "INSERT INTO transactions_detail(trans_code, item_code, quantity, sub_total) VALUES(?,?,?,?)"; PreparedStatement pr = obj_koneksi.con.prepareStatement(str); pr.setString(1,trans_code.trim()); pr.setString(2,item_code.trim()); pr.setInt(3,quantity); pr.setInt(4,sub_total); i = pr.executeUpdate(); } catch(SQLException ex){ System.out.println(ex.getMessage()); } return i; }
  • 21. Riza Muhammad Nurman 4SC Click to edit Master title styleVTransaction public class VTransaction extends javax.swing.JFrame { Transaction obj_trans = new Transaction(); Item obj_item = new Item(); DefaultTableModel model; int total; public VTransaction() { initComponents(); lbl_date.setText(new java.util.Date().toString()); } private void clear() { txt_code.setText(""); txt_quantity.setText("0"); txt_change.setText(""); txt_payment.setText(""); txt_total.setText(""); total = 0; }
  • 22. Riza Muhammad Nurman 4SC Click to edit Master title styleVTransaction - 2 private void doTransactions() { try { obj_trans.setTrans_code(txt_trans.getText()); obj_trans.setEmp_code(lbl_empcode.getText()); obj_trans.setTotal(0); int i = obj_trans.doTransaction(); if(i > 0) { JOptionPane.showMessageDialog(null, "SUKSES! Data Berhasil Disimpan"); } else { JOptionPane.showMessageDialog(null, "PERINGATAN! Harap Memasukkan Data Yang Sesuai"); } } catch(Exception e) { JOptionPane.showMessageDialog(null,"Error: " + e); } }
  • 23. Riza Muhammad Nurman 4SC Click to edit Master title styleVTransaction - 3 private void doTransactionDetails() { model = (DefaultTableModel) table_item.getModel(); int row_count = table_item.getRowCount(); int count = 0; try { while(count < row_count) { String code = model.getValueAt(count,0).toString(); int qty = Integer.parseInt(model.getValueAt(count,3).toString()); int subtotal = Integer.parseInt(model.getValueAt(count,4).toString()); obj_trans.setItem_code(code); obj_trans.setQuantity(qty); obj_trans.setSub_total(subtotal); int i = obj_trans.setDetailTransaction(); count++; } } catch(Exception e) { JOptionPane.showMessageDialog(null,"Error Details: " + e); } }
  • 24. Riza Muhammad Nurman 4SC Click to edit Master title styleVTransaction - 4 private void addItem() { try{ int quantity = Integer.parseInt(txt_quantity.getText()); obj_item.setItem_code(txt_code.getText()); ArrayList data = obj_item.getRecord(); for(int i = 0;i < data.size()-1;i+=4) { String item_code = (String)data.get(i); String item_name = (String)data.get(i+1); int item_price = (Integer)data.get(i+2); int subtotal = item_price * quantity; String[] data_field = {item_code.trim(),item_name.trim(),String.valueOf(item_price),String.valueOf(quantity), String.valueOf(subtotal) }; model = (DefaultTableModel)table_item.getModel(); model.addRow(data_field); total = total + subtotal; obj_trans.setTotal(total); txt_total.setText(String.valueOf(obj_trans.getTotal())); } } catch(Exception ex) { JOptionPane.showMessageDialog(null, "Data Gagal Ditampilkan" + ex.getMessage()); } }
  • 25. Riza Muhammad Nurman 4SC Click to edit Master title styleVTransaction - 5 private void clearTable() { model = (DefaultTableModel) table_item.getModel(); int baris = model.getRowCount(); for (int i = 0; i< baris; i++) { model.removeRow(0); } }
  • 26. Riza Muhammad Nurman 4SC Click to edit Master title styleVTransaction - Event private void btn_itemActionPerformed(java.awt.event.ActionEvent evt) { this.addItem(); } private void txt_changeMouseClicked(java.awt.event.MouseEvent evt) { int payment = Integer.parseInt(txt_payment.getText()); int change = payment - total; txt_change.setText(String.valueOf(change)); } private void btn_clearActionPerformed(java.awt.event.ActionEvent evt) { this.clearTable(); this.clear(); } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { this.doTransactions(); this.doTransactionDetails(); txt_trans.setText("TRANS NUMBER"); this.clearTable(); this.clear(); }
  • 27. Riza Muhammad Nurman 4SC Click to edit Master title style