Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Java Programming > Java GUI สอน Java GUI เขียนโปรแกรม GUI ด้วย Java(Swing/AWT/JFC) > iReport Create Design Report Wizard and Preview Report (Step by Step)



Clound SSD Virtual Server

iReport Create Design Report Wizard and Preview Report (Step by Step)

iReport Create Design Report Wizard and Preview Report (Step by Step) หลังจากที่เราได้ทำการสร้าง Database , Table และ Data สำหรับการทดสอบ รวมทั้งการสร้างชุดของ Connection บน iReport เรียบร้อยแล้ว ขั้นตอนนี้เราจะมาเริ่มต้นจริงกับการสร้าง Report ด้วย iReport แบบง่าย ๆ เช่น การเลือก Template การเลือก Table เขียน Query เลือกข้อมูลที่จะมาแสดงบน Report และสุดท้ายคือการ Preview Report ซึ่งในตัวอย่างนี้จะเลือกใช้ Database ของ MySQL ขอทบทวนโครงสร้างใหม่ดังนี้

ในตัวอย่างนี้จะเลือกใช้ Database ของ MySQL แต่ในกรณีที่จะใช้ร่วมกับ Database อื่น ๆ ก็สามารถทำได้ง่าย ๆ เพียงแค่เปลี่ยน Connector และ Connection String เท่านั้น สามารถอ่านเพิ่มเติมได้ที่บทความนี้

Java Connect to MySQL Database (JDBC)


โครงสร้างของ MySQL และ Table

Java GUI JComboBox from Database

CREATE TABLE `customer` (
  `CustomerID` varchar(4) NOT NULL,
  `Name` varchar(50) NOT NULL,
  `Email` varchar(50) NOT NULL,
  `CountryCode` varchar(2) NOT NULL,
  `Budget` double NOT NULL,
  `Used` double NOT NULL,
  PRIMARY KEY  (`CustomerID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- 
-- dump ตาราง `customer`
-- 

INSERT INTO `customer` VALUES ('C001', 'Win Weerachai', '[email protected]', 'TH', 1000000, 600000);
INSERT INTO `customer` VALUES ('C002', 'John  Smith', '[email protected]', 'UK', 2000000, 800000);
INSERT INTO `customer` VALUES ('C003', 'Jame Born', '[email protected]', 'US', 3000000, 600000);
INSERT INTO `customer` VALUES ('C004', 'Chalee Angel', '[email protected]', 'US', 4000000, 100000);

คำสั่งของ SQL ที่สามารถนำไปรันบน Query เพื่อสร้าง Table และ Rows ได้ทันที


ก่อนอื่นอย่าลืม : Create iReport JasperReports and Database Connection


Step 2 : Create a new report เป็นขั้นตอนการสร้าง Report ใหม่ ซึ่งทุก ๆ Report จะสร้างได้จากเเมนูนี้

iReport Create Design Report Wizard and Preview Report

เลือก Create a new report

iReport Create Design Report Wizard and Preview Report

จะเห็นว่าในหน้าจอนี้จะเป็น Template ต่าง ๆ ของ Report มีมาให้

iReport Create Design Report Wizard and Preview Report

ในครั้งแรกให้เลือก Coffee เพราะเป็นตัวอย่าง Report ที่แสดงข้อมูลในรูปแบบของ Column และ Rows จากนั้นให้เลือก Launch Report Wizard

iReport Create Design Report Wizard and Preview Report

ตั้งชื่อ Report และเลือก Path เดียวกับ Path ของโปรแกรม Java จากนั้นเลือก Next

iReport Create Design Report Wizard and Preview Report

ขั้นตอนนี้จะเป็นการเลือก Connection ซึ่งจะได้จากที่เราได้สร้างไว้ก่อนหน้านี้ จากนั้นให้คลิกที่ Design Query หรือถ้าคล่อง Query ก็สามารถเขียน Query จากหน้าจอนี้ได้ทันที

iReport Create Design Report Wizard and Preview Report

เลือก Table หรือตารางที่ต้องการ หรือในกรณีที่เขียนเป็นพวก View / Store Procedure ก็สามารถเลือกได้เช่นเดียวกัน จากนั้นเลือก OK

iReport Create Design Report Wizard and Preview Report

ปรับแต่งพวก Query ต่าง ๆ ให้ถูกต้อง








iReport Create Design Report Wizard and Preview Report

ขั้นตอนนี้ให้เลือก Column ทั้งหมด

iReport Create Design Report Wizard and Preview Report

ได้ Column ของข้อมูลไว้สำหรับแสดง Report เรียบร้อยแล้ว

iReport Create Design Report Wizard and Preview Report

ขั้นตอนนี้ให้เลือก Next ไปได้เลย เพราะเราจะต้องการสร้างแบบ Basic ง่าย ๆ

iReport Create Design Report Wizard and Preview Report

เลือก Finish

iReport Create Design Report Wizard and Preview Report

จากนั้น Report ก็จะถูกสร้างเรียบร้อยแล้ว ซึ่งจะเป็นรูปแบตาม Template ที่เราได้เลือกไว้ และเราสามารถที่จะ Preview ตัว Report ได้ทันที

iReport Create Design Report Wizard and Preview Report

แสดง Report แล้ว ง่ายมาก ๆ ยังไม่ได้เขียน Code หรือทำอะไรเพิ่มเติมเลย ก็ได้ Report ออกมาง่าย ๆ และในกรณีที่ต้องการเปลี่ยนพวก Title หรือปรับแต่งพวก Report ก็สามารถสลับไปยังโหมดลอง Desiner ได้ทันที

การแสดงเครื่องมือของ iReport

iReport Create Design Report Wizard and Preview Report

เลือกเมนู Window -> Palette

iReport Create Design Report Wizard and Preview Report

จะเห็นว่าตอนนี้มีเครื่องมือของ iReport ที่ใช้สำหรับการตบแต่ง Report คล้าย ๆ ของ Crystal Report

สรุป ขั้นตอนการสร้าง iReport แบบ Wizard แบบเลือก Template เป็นการช่วยสร้าง Report แบบพื้นฐานง่าย ๆ ซึ่งใน iReport เองก็มีตัวอย่างให้อยู่หลายตัว และเมื่อได้ Report จาก Template แล้ว เราสามารถที่จะปรับแต่งพวก Text / Font หรือตบแต่งด้วยเครื่องมืออื่น ๆ ตามที่ต้องการ และการสร้าง iReport ก็มีเพียงขั้นตอนง่าย ๆ เท่านี้ และในบทความถัดไปเราจะนำ Report นี้ไปใช้กับ Java GUI

iReport Create Design Report Wizard and Preview Report

และเราจะใช้แค่ไฟล์ .jrxml เท่านั้น ซึ่งเป็นไฟล์ที่ได้จากขั้นตอนการสร้าง iReport








บทความถัดไปที่แนะนำให้อ่าน


กรณีที่ใช้ร่วมกับ Database อื่น ๆ สามารถดูวิธีการใช้ Connector และ Connection String ได้ที่นี่


   
Share

Property & Method (Others Related)

iReport คืออะไร วิธีติดตั้ง iReport Designer for JasperReports (Step by Step)
Create iReport JasperReports and Database Connection
Java GUI : Connect and Viewer/Preview iReport (JasperReport)
Java GUI : Viewer/Preview iReport on JFrame/JPanel
Java GUI : iReport Create Parameters and Pass Variable

ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2013-09-12 11:42:33 / 2017-03-27 21:39:39
  Download : No files
 Sponsored Links / Related

 
iReport คืออะไร วิธีติดตั้ง iReport Designer for JasperReports (Step by Step)
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่