本專案為前幾天收費幫學妹做的一個專案,Java swing專案,在作業環境中基本使用不到,但是很多學校把這個當做編程入門的專案來做,故分享出本專案供初學者參考,
CSDN9.9贊助下載: https://download.csdn.net/download/weixin_44893902/20545860
白嫖: 加QQ68872185
一、效果演示
主要功能:
普通用戶:
- 用戶用水用電查詢(根據時間查詢、匯出Excel)
管理員用戶:
- 用戶資訊管理 >> 平臺用戶資訊查詢(修改資訊、新增用戶、洗掉用戶、根據編號查詢)
- 水電費管理 >> 用戶水電費查詢 (修改資訊、新增用戶、洗掉用戶、根據日期查詢、根據戶主編號查詢、匯出資料到Excel)
- 管理員賬戶管理 >> 管理后臺(管理員添加、洗掉、修改、編號賬戶查詢)
1、用戶登錄



2、“普通用戶” 主界面
2.1 用戶水電費查詢

3、“管理員用戶” 界面

3.1 用戶資訊管理




3.2 水電費管理

3.3 管理員賬戶管理



4、匯出功能



二、核心代碼
(1)資料庫【utilitiessys】:

① admin(管理員表)
-- ----------------------------
-- Table structure for admin
-- ----------------------------
DROP TABLE IF EXISTS `admin`;
CREATE TABLE `admin` (
`id` int(30) NOT NULL AUTO_INCREMENT COMMENT '編號',
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '姓名',
`account` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '賬戶',
`password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '密碼',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 11 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of admin
-- ----------------------------
INSERT INTO `admin` VALUES (1, '楊明金', 'ymj', '123456');
INSERT INTO `admin` VALUES (2, '肖波', 'xb', '123123');
② feeinfo(收費資訊表)
-- ----------------------------
-- Table structure for feeinfo
-- ----------------------------
DROP TABLE IF EXISTS `feeinfo`;
CREATE TABLE `feeinfo` (
`id` int(30) NOT NULL AUTO_INCREMENT COMMENT '訂單號',
`userid` int(30) NULL DEFAULT NULL COMMENT '戶主id',
`watertype` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用水型別',
`water` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '水費單價',
`watersum` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用水總量',
`monthwater` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '本月水費',
`electricitytype` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用電型別',
`electricity` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '電費單價',
`electricitysum` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用電總量',
`monthelectricity` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '本月電費',
`years` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '年份',
`month` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '月份',
`cost` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '總費用',
`costime` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '收費時間',
`adminid` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '操作員',
`note` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '備注',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 41 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of feeinfo
-- ----------------------------
INSERT INTO `feeinfo` VALUES (1, 1, '商業用電', '20', '50', '200', '商業用電', '30', '500', '200', '2021年', '3月', '300', '4000', '楊明金', '備注');
INSERT INTO `feeinfo` VALUES (2, 1, '家庭用電', '20', '50', '200', '家庭用電', '20', '20', '20', '2021年', '5月', '300', '2000', 'mj', '背后');
INSERT INTO `feeinfo` VALUES (3, 3, '居民家庭用水', '20', '50', '200', '一般工商業用電', '30', '500', '200', '2021年', '3月', '300', '4000', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (4, 4, '城市居民家庭用水', '20', '50', '200', '一般工商業用電', '20', '20', '20', '2021年', '5月', '300', '2000', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (5, 5, '農民家庭用水', '21', '51', '201', '家庭用電', '21', '21', '21', '2021年', '6月', '301', '2001', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (6, 6, '公共供水站用水', '22', '52', '202', '一般工商業用電', '22', '22', '22', '2019年', '7月', '302', '2002', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (7, 7, '公共服務用水', '23', '53', '203', '居民生活用電', '23', '23', '23', '2021年', '8月', '303', '2003', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (8, 8, '公共設施服務用水', '24', '54', '204', '大工業用電', '24', '24', '24', '2019年', '9月', '304', '2004', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (9, 9, '社會服務業用水', '25', '55', '205', '一般工商業用電', '25', '25', '25', '2021年', '10月', '305', '2005', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (10, 10, '批發和零售貿易業用水', '26', '56', '206', '一般工商業用電', '26', '26', '26', '2019年', '11月', '306', '2006', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (11, 11, '餐飲業、旅館業用水', '27', '57', '207', '居民生活用電', '27', '27', '27', '2019年', '12月', '307', '2007', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (12, 12, '衛生事業用水', '28', '58', '208', '大工業用電', '28', '28', '28', '2021年', '3月', '308', '2008', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (13, 13, '文娛體育事業、文藝廣電業用水', '29', '59', '209', '居民生活用電', '29', '29', '29', '2019年', '5月', '309', '2009', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (14, 14, '教育事業用水', '30', '60', '210', '大工業用電', '30', '30', '30', '2021年', '5月', '310', '2010', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (15, 15, '科學研究和綜合技術服務業用水', '31', '61', '211', '大工業用電', '31', '31', '31', '2021年', '6月', '311', '2011', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (16, 16, '社會福利保障業用水', '32', '62', '212', '大工業用電', '32', '32', '32', '2019年', '5月', '312', '2012', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (17, 17, '金融、保險、房地產業用水', '33', '63', '213', '商業用電', '33', '33', '33', '2021年', '8月', '313', '2013', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (18, 18, '機關、企事業管理機構和社會團體用水', '34', '64', '214', '居民生活用電', '34', '34', '34', '2021年', '9月', '314', '2014', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (19, 19, '其他公共服務用水', '35', '65', '215', '居民生活用電', '35', '35', '35', '2021年', '5月', '315', '2015', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (20, 20, '生產運營用水', '36', '66', '216', '商業用電', '36', '36', '36', '2019年', '2月', '316', '2016', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (21, 21, '農、林、牧、漁業用水', '37', '67', '217', '農業生產用電', '37', '37', '37', '2021年', '5月', '317', '2017', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (22, 22, '采掘業用水', '38', '68', '218', '農業生產用電', '38', '38', '38', '2021年', '12月', '318', '2018', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (23, 23, '家庭用電', '39', '69', '219', '農業生產用電', '39', '39', '39', '2021年', '12月', '319', '2019', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (24, 24, '家庭用電', '40', '70', '220', '居民生活用電', '40', '40', '40', '2021年', '5月', '320', '2020', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (25, 25, '家庭用電', '41', '71', '221', '農業生產用電', '41', '41', '41', '2021年', '1月', '321', '2021', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (26, 26, '家庭用電', '42', '72', '222', '農業生產用電', '42', '42', '42', '2021年', '2月', '322', '2022', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (27, 27, '家庭用電', '43', '73', '223', '居民生活用電', '43', '43', '43', '2021年', '5月', '323', '2023', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (28, 1, '居民家庭用水', '20', '50', '200', '一般工商業用電', '30', '500', '200', '2021年', '3月', '300', '4000', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (29, 1, '城市居民家庭用水', '20', '50', '200', '一般工商業用電', '20', '20', '20', '2021年', '5月', '300', '2000', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (30, 1, '農民家庭用水', '21', '51', '201', '家庭用電', '21', '21', '21', '2021年', '6月', '301', '2001', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (31, 1, '公共供水站用水', '22', '52', '202', '一般工商業用電', '22', '22', '22', '2019年', '7月', '302', '2002', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (32, 1, '公共服務用水', '23', '53', '203', '居民生活用電', '23', '23', '23', '2021年', '8月', '303', '2003', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (33, 1, '公共設施服務用水', '24', '54', '204', '大工業用電', '24', '24', '24', '2019年', '9月', '304', '2004', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (34, 1, '社會服務業用水', '25', '55', '205', '一般工商業用電', '25', '25', '25', '2021年', '10月', '305', '2005', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (35, 1, '批發和零售貿易業用水', '26', '56', '206', '一般工商業用電', '26', '26', '26', '2019年', '11月', '306', '2006', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (36, 1, '餐飲業、旅館業用水', '27', '57', '207', '居民生活用電', '27', '27', '27', '2019年', '12月', '307', '2007', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (37, 1, '衛生事業用水', '28', '58', '208', '大工業用電', '28', '28', '28', '2021年', '3月', '308', '2008', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (39, 1, '教育事業用水', '30', '60', '210', '大工業用電', '30', '30', '30', '2021年', '5月', '310', '2010', '楊明金', '已繳納');
INSERT INTO `feeinfo` VALUES (40, 1, '科學研究和綜合技術服務業用水', '31', '61', '211', '大工業用電', '31', '31', '31', '2021年', '6月', '311', '2011', '楊明金', '已繳納');
③ users(用戶表)
-- ----------------------------
-- Table structure for users
-- ----------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` int(30) NOT NULL AUTO_INCREMENT COMMENT 'ID',
`username` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '戶主姓名',
`account` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '賬戶',
`password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '密碼',
`sex` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '性別',
`idcard` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '身份證號碼',
`phone` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '電話號碼',
`address` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '居住地址',
`usertime` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '備注',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 28 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of users
-- ----------------------------
INSERT INTO `users` VALUES (1, '楊明金', 'ymj', '123456', '女', '5323456', '1886454551', '云南昆明22', '22');
INSERT INTO `users` VALUES (2, '李華', 'lh', '123123', '女', '5653464', '656564555', '河北', '200');
INSERT INTO `users` VALUES (3, '董志豪', 'dzh', '123456', '男', '532123200103060023', '18214211253', '云南省昆明市五華區茭菱路128號', '20210701');
INSERT INTO `users` VALUES (4, '曾躍', 'cy', '123456', '女', '532123200103060023', '18214211254', '云南省昆明市五華區茭菱路129號', '20210702');
INSERT INTO `users` VALUES (5, '崔任松', 'crs', '123456', '男', '532123200103060023', '18214211255', '云南省昆明市五華區茭菱路130號', '20210703');
INSERT INTO `users` VALUES (6, '趙馳', 'zc', '123456', '女', '532123200103060023', '18214211256', '云南省昆明市五華區茭菱路131號', '20210704');
INSERT INTO `users` VALUES (7, '余靖', 'yj', '123456', '男', '532123200103060023', '18214211257', '云南省昆明市五華區茭菱路132號', '20210705');
INSERT INTO `users` VALUES (8, '李銀嬌', 'lyj', '123456', '男', '532123200103060023', '18214211258', '云南省昆明市五華區茭菱路133號', '20210706');
INSERT INTO `users` VALUES (9, '楊志興', 'yzx', '123456', '男', '532123200103060023', '18214211259', '云南省昆明市五華區茭菱路134號', '20210707');
INSERT INTO `users` VALUES (10, '許應燁', 'xyy', '123456', '女', '532123200103060023', '18214211260', '云南省昆明市五華區茭菱路135號', '20210708');
INSERT INTO `users` VALUES (11, '何鴻廷', 'hht', '123456', '男', '532123200103060023', '18214211261', '云南省昆明市五華區茭菱路136號', '20210709');
INSERT INTO `users` VALUES (12, '郭超', 'gc', '123456', '男', '532123200103060023', '18214211262', '云南省昆明市五華區茭菱路137號', '20210710');
INSERT INTO `users` VALUES (13, '夏明方', 'xmf', '123456', '男', '532123200103060023', '18214211263', '云南省昆明市五華區茭菱路138號', '20210711');
INSERT INTO `users` VALUES (14, '杜順昌', 'dsc', '123456', '女', '532123200103060023', '18214211264', '云南省昆明市五華區茭菱路139號', '20210712');
INSERT INTO `users` VALUES (15, '楊雄美', 'yxm', '123456', '男', '532123200103060023', '18214211265', '云南省昆明市五華區茭菱路140號', '20210713');
INSERT INTO `users` VALUES (16, '楊金明', 'yjm', '123456', '男', '532123200103060023', '18214211266', '云南省昆明市五華區茭菱路141號', '20210714');
INSERT INTO `users` VALUES (17, '李驥', 'lj', '123456', '男', '532123200103060023', '18214211267', '云南省昆明市五華區茭菱路142號', '20210715');
INSERT INTO `users` VALUES (18, '嚴卓琳', 'yzl', '123456', '女', '532123200103060023', '18214211268', '云南省昆明市五華區茭菱路143號', '20210716');
INSERT INTO `users` VALUES (19, '宋廷虎', 'sth', '123456', '女', '532123200103060023', '18214211269', '云南省昆明市五華區茭菱路144號', '20210717');
INSERT INTO `users` VALUES (20, '馬士穎', 'msy', '123456', '男', '532123200103060023', '18214211270', '云南省昆明市五華區茭菱路145號', '20210718');
INSERT INTO `users` VALUES (21, '陸振黎', 'lzl', '123456', '女', '532123200103060023', '18214211271', '云南省昆明市五華區茭菱路146號', '20210719');
INSERT INTO `users` VALUES (22, '何忠禮', 'hzl', '123456', '男', '532123200103060023', '18214211272', '云南省昆明市五華區茭菱路147號', '20210720');
INSERT INTO `users` VALUES (23, '畢猛', 'bm', '123456', '女', '532123200103060023', '18214211273', '云南省昆明市五華區茭菱路148號', '20210721');
INSERT INTO `users` VALUES (24, '李映權', 'lyq', '123456', '女', '532123200103060023', '18214211274', '云南省昆明市五華區茭菱路149號', '20210722');
INSERT INTO `users` VALUES (25, '王明煒', 'wmw', '123456', '男', '532123200103060023', '18214211275', '云南省昆明市五華區茭菱路150號', '20210723');
INSERT INTO `users` VALUES (26, '周子龍', 'zzl', '123456', '女', '532123200103060023', '18214211276', '云南省昆明市五華區茭菱路151號', '20210724');
INSERT INTO `users` VALUES (27, '方晨曉', 'fcx', '123456', '男', '532123200103060023', '18214211277', '云南省昆明市五華區茭菱路152號', '20210725');
(2)JAVA:

1、Bean包【存放物體包】
① Admin(管理員類)
package com.ynavc.Bean;
import java.io.Serializable;
/**
* @description admin
* @author ymjin.blog.csdn.net/
* @date 2021-07-01
*/
public class Admin implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 編號
*/
private Integer id;
/**
* 姓名
*/
private String name;
/**
* 賬戶
*/
private String account;
/**
* 密碼
*/
private String password;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
public Admin() {}
public Admin(Integer id, String name, String account, String password) {
super();
this.id = id;
this.name = name;
this.account = account;
this.password = password;
}
@Override
public String toString() {
return "Admin [id=" + id + ", name=" + name + ", account=" + account + ", password=" + password + "]";
}
}
② Feeinfo(收費資訊類)
package com.ynavc.Bean;
import java.io.Serializable;
/**
* @description feeinfo
* @author ymjin.blog.csdn.net/
* @date 2021-07-01
*/
public class Feeinfo implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 訂單號
*/
private Integer id;
/**
* 戶主id
*/
private Integer userid;
/**
* 用水型別
*/
private String watertype;
/**
* 水費單價
*/
private String water;
/**
* 用水總量
*/
private String watersum;
/**
* 本月水費
*/
private String monthwater;
/**
* 用電型別
*/
private String electricitytype;
/**
* 電費單價
*/
private String electricity;
/**
* 用電總量
*/
private String electricitysum;
/**
* 本月電費
*/
private String monthelectricity;
/**
* 年份
*/
private String years;
/**
* 月份
*/
private String month;
/**
* 總費用
*/
private String cost;
/**
* 收費時間
*/
private String costime;
/**
* 操作員
*/
private String adminid;
/**
* 備注
*/
private String note;
public Feeinfo() {}
public Feeinfo(Integer id, Integer userid, String watertype, String water, String watersum, String monthwater,
String electricitytype, String electricity, String electricitysum, String monthelectricity, String years,
String month, String cost, String costime, String adminid, String note) {
super();
this.id = id;
this.userid = userid;
this.watertype = watertype;
this.water = water;
this.watersum = watersum;
this.monthwater = monthwater;
this.electricitytype = electricitytype;
this.electricity = electricity;
this.electricitysum = electricitysum;
this.monthelectricity = monthelectricity;
this.years = years;
this.month = month;
this.cost = cost;
this.costime = costime;
this.adminid = adminid;
this.note = note;
}
@Override
public String toString() {
return "Feeinfo [id=" + id + ", userid=" + userid + ", watertype=" + watertype + ", water=" + water
+ ", watersum=" + watersum + ", monthwater=" + monthwater + ", electricitytype=" + electricitytype
+ ", electricity=" + electricity + ", electricitysum=" + electricitysum + ", monthelectricity="
+ monthelectricity + ", years=" + years + ", month=" + month + ", cost=" + cost + ", costime=" + costime
+ ", adminid=" + adminid + ", note=" + note + "]";
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getUserid() {
return userid;
}
public void setUserid(Integer userid) {
this.userid = userid;
}
public String getWatertype() {
return watertype;
}
public void setWatertype(String watertype) {
this.watertype = watertype;
}
public String getWater() {
return water;
}
public void setWater(String water) {
this.water = water;
}
public String getWatersum() {
return watersum;
}
public void setWatersum(String watersum) {
this.watersum = watersum;
}
public String getMonthwater() {
return monthwater;
}
public void setMonthwater(String monthwater) {
this.monthwater = monthwater;
}
public String getElectricitytype() {
return electricitytype;
}
public void setElectricitytype(String electricitytype) {
this.electricitytype = electricitytype;
}
public String getElectricity() {
return electricity;
}
public void setElectricity(String electricity) {
this.electricity = electricity;
}
public String getElectricitysum() {
return electricitysum;
}
public void setElectricitysum(String electricitysum) {
this.electricitysum = electricitysum;
}
public String getMonthelectricity() {
return monthelectricity;
}
public void setMonthelectricity(String monthelectricity) {
this.monthelectricity = monthelectricity;
}
public String getYears() {
return years;
}
public void setYears(String years) {
this.years = years;
}
public String getMonth() {
return month;
}
public void setMonth(String month) {
this.month = month;
}
public String getCost() {
return cost;
}
public void setCost(String cost) {
this.cost = cost;
}
public String getCostime() {
return costime;
}
public void setCostime(String costime) {
this.costime = costime;
}
public String getAdminid() {
return adminid;
}
public void setAdminid(String adminid) {
this.adminid = adminid;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
}
③ Feeinfo(收費資訊實作類)
package com.ynavc.Bean;
import java.io.Serializable;
/**
* @description feeinfo
* @author ymjin.blog.csdn.net/
* @date 2021-07-01
*/
public class FeeinfoImp implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 訂單號
*/
private Integer id;
/**
* 戶主id
*/
private Integer userid;
/**
/**
* 戶主姓名
*/
private String userName;
/**
* 用水型別
*/
private String watertype;
/**
* 水費單價
*/
private String water;
/**
* 用水總量
*/
private String watersum;
/**
* 本月水費
*/
private String monthwater;
/**
* 用電型別
*/
private String electricitytype;
/**
* 電費單價
*/
private String electricity;
/**
* 用電總量
*/
private String electricitysum;
/**
* 本月電費
*/
private String monthelectricity;
/**
* 年份
*/
private String years;
/**
* 月份
*/
private String month;
/**
* 總費用
*/
private String cost;
/**
* 收費時間
*/
private String costime;
/**
* 操作員
*/
private String adminid;
/**
* 備注
*/
private String note;
@Override
public String toString() {
return "FeeinfoImp [id=" + id + ", userid=" + userid + ", userName=" + userName + ", watertype=" + watertype
+ ", water=" + water + ", watersum=" + watersum + ", monthwater=" + monthwater + ", electricitytype="
+ electricitytype + ", electricity=" + electricity + ", electricitysum=" + electricitysum
+ ", monthelectricity=" + monthelectricity + ", years=" + years + ", month=" + month + ", cost=" + cost
+ ", costime=" + costime + ", adminid=" + adminid + ", note=" + note + "]";
}
public FeeinfoImp() {
super();
}
public FeeinfoImp(Integer id, Integer userid, String usename, String watertype, String water, String watersum,
String monthwater, String electricitytype, String electricity, String electricitysum,
String monthelectricity, String years, String month, String cost, String costime, String adminid,
String note) {
super();
this.id = id;
this.userid = userid;
this.userName = usename;
this.watertype = watertype;
this.water = water;
this.watersum = watersum;
this.monthwater = monthwater;
this.electricitytype = electricitytype;
this.electricity = electricity;
this.electricitysum = electricitysum;
this.monthelectricity = monthelectricity;
this.years = years;
this.month = month;
this.cost = cost;
this.costime = costime;
this.adminid = adminid;
this.note = note;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getUserid() {
return userid;
}
public void setUserid(Integer userid) {
this.userid = userid;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getWatertype() {
return watertype;
}
public void setWatertype(String watertype) {
this.watertype = watertype;
}
public String getWater() {
return water;
}
public void setWater(String water) {
this.water = water;
}
public String getWatersum() {
return watersum;
}
public void setWatersum(String watersum) {
this.watersum = watersum;
}
public String getMonthwater() {
return monthwater;
}
public void setMonthwater(String monthwater) {
this.monthwater = monthwater;
}
public String getElectricitytype() {
return electricitytype;
}
public void setElectricitytype(String electricitytype) {
this.electricitytype = electricitytype;
}
public String getElectricity() {
return electricity;
}
public void setElectricity(String electricity) {
this.electricity = electricity;
}
public String getElectricitysum() {
return electricitysum;
}
public void setElectricitysum(String electricitysum) {
this.electricitysum = electricitysum;
}
public String getMonthelectricity() {
return monthelectricity;
}
public void setMonthelectricity(String monthelectricity) {
this.monthelectricity = monthelectricity;
}
public String getYears() {
return years;
}
public void setYears(String years) {
this.years = years;
}
public String getMonth() {
return month;
}
public void setMonth(String month) {
this.month = month;
}
public String getCost() {
return cost;
}
public void setCost(String cost) {
this.cost = cost;
}
public String getCostime() {
return costime;
}
public void setCostime(String costime) {
this.costime = costime;
}
public String getAdminid() {
return adminid;
}
public void setAdminid(String adminid) {
this.adminid = adminid;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
}
④ Users(用戶類)
package com.ynavc.Bean;
import java.io.Serializable;
/**
* @description users
* @author ymjin.blog.csdn.net/
* @date 2021-07-01
*/
public class Users implements Serializable {
private static final long serialVersionUID = 1L;
/**
* id
*/
private Integer id;
/**
* 戶主姓名
*/
private String username;
/**
* 賬戶
*/
private String account;
/**
* 密碼
*/
private String password;
/**
* 性別
*/
private String sex;
/**
* 身份證號碼
*/
private String idcard;
/**
* 電話號碼
*/
private String phone;
/**
* 居住地址
*/
private String address;
/**
* 備注
*/
private String usertime;
public Users() {}
public Users(Integer id, String username, String account, String password, String sex, String idcard, String phone,
String address, String usertime) {
super();
this.id = id;
this.username = username;
this.account = account;
this.password = password;
this.sex = sex;
this.idcard = idcard;
this.phone = phone;
this.address = address;
this.usertime = usertime;
}
@Override
public String toString() {
return "Users [id=" + id + ", username=" + username + ", account=" + account + ", password=" + password
+ ", sex=" + sex + ", idcard=" + idcard + ", phone=" + phone + ", address=" + address + ", usertime="
+ usertime + "]";
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getIdcard() {
return idcard;
}
public void setIdcard(String idcard) {
this.idcard = idcard;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getUsertime() {
return usertime;
}
public void setUsertime(String usertime) {
this.usertime = usertime;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}
2、Controller包【資料庫互動控制包】
① Select(查詢類)
package com.ynavc.Controller;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.mysql.jdbc.PreparedStatement;
import com.ynavc.Bean.Admin;
import com.ynavc.Bean.Feeinfo;
import com.ynavc.Bean.FeeinfoImp;
import com.ynavc.Bean.Users;
import com.ynavc.Dao.DbConnection;
public class Select {
// 查詢全部管理員用戶資訊
public Object[][] getAdminInfo() {
String sql = "SELECT * FROM admin";
Connection conn = DbConnection.getConnection();
PreparedStatement stmt = null;
;
ResultSet rs = null;
ArrayList<Admin> list = new ArrayList<Admin>();
try {
stmt = (PreparedStatement) conn.prepareStatement(sql);
rs = stmt.executeQuery();
while (rs.next()) {
Admin admin = new Admin();
admin.setId(rs.getInt(1));
admin.setName(rs.getString(2));
admin.setAccount(rs.getString(3));
admin.setPassword(rs.getString(4));
list.add(admin);
}
} catch (SQLException e1) {
e1.printStackTrace();
} finally {
try {
DbConnection.colse(rs, stmt, conn);
} catch (Exception e) {
e.printStackTrace();
}
}
Object[][] objects = new Object[list.size()][4];
for (int i = 0; i < list.size(); i++) {
objects[i][0] = list.get(i).getId();
objects[i][1] = list.get(i).getName();
objects[i][2] = list.get(i).getAccount();
objects[i][3] = list.get(i).getPassword();
}
return objects;
}
// 查詢全部管理員用戶資訊
public Object[][] getAdminInfoBykey(String name, String id) {
if (name.equals("") && !id.equals("")) {
name = "null";
} else if (id.equals("") && !name.equals("")) {
id = "null";
}
String sql = "SELECT * FROM admin WHERE account LIKE '%" + name + "%' OR id LIKE '%" + id + "%'";
Connection conn = DbConnection.getConnection();
PreparedStatement stmt = null;
;
ResultSet rs = null;
ArrayList<Admin> list = new ArrayList<Admin>();
try {
stmt = (PreparedStatement) conn.prepareStatement(sql);
rs = stmt.executeQuery();
while (rs.next()) {
Admin admin = new Admin();
admin.setId(rs.getInt(1));
admin.setName(rs.getString(2));
admin.setAccount(rs.getString(3));
admin.setPassword(rs.getString(4));
list.add(admin);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
DbConnection.colse(rs, stmt, conn);
} catch (Exception e) {
e.printStackTrace();
}
}
Object[][] objects = new Object[list.size()][4];
for (int i = 0; i < list.size(); i++) {
objects[i][0] = list.get(i).getId();
objects[i][1] = list.get(i).getName();
objects[i][2] = list.get(i).getAccount();
objects[i][3] = list.get(i).getPassword();
}
return objects;
}
// 查詢全部管理員用戶資訊
public Object[][] getUserInfo(String id) {
String sql = null;
if (id.equals("")) {
sql = "SELECT * FROM users";
} else {
sql = "SELECT * FROM users WHERE id='" + id + "'";
}
Connection conn = DbConnection.getConnection();
PreparedStatement stmt = null;
;
ResultSet rs = null;
ArrayList<Users> list = new ArrayList<Users>();
try {
stmt = (PreparedStatement) conn.prepareStatement(sql);
rs = stmt.executeQuery();
while (rs.next()) {
Users users = new Users();
users.setId(rs.getInt(1));
users.setUsername(rs.getString(2));
users.setAccount(rs.getString(3));
users.setPassword(rs.getString(4));
users.setSex(rs.getString(5));
users.setIdcard(rs.getString(6));
users.setPhone(rs.getString(7));
users.setAddress(rs.getString(8));
users.setUsertime(rs.getString(9));
list.add(users);
}
} catch (SQLException e1) {
e1.printStackTrace();
} finally {
try {
DbConnection.colse(rs, stmt, conn);
} catch (Exception e) {
e.printStackTrace();
}
}
Object[][] objects = new Object[list.size()][9];
for (int i = 0; i < list.size(); i++) {
objects[i][0] = list.get(i).getId();
objects[i][1] = list.get(i).getUsername();
objects[i][2] = list.get(i).getAccount();
objects[i][3] = list.get(i).getPassword();
objects[i][4] = list.get(i).getSex();
objects[i][5] = list.get(i).getIdcard();
objects[i][6] = list.get(i).getPhone();
objects[i][7] = list.get(i).getAddress();
objects[i][8] = list.get(i).getUsertime();
}
return objects;
}
// 管理員查詢收費資訊
public Object[][] getFeeInfo(String id) {
String sql = null;
if (id.equals("")) {
sql = "SELECT f.id,u.id,u.username,watertype,water,watersum,monthwater,electricity,electricitytype,electricitysum,monthelectricity,years,`month`,cost,costime,adminid,note FROM feeinfo f,users u WHERE f.userid=u.id";
} else {
sql = "SELECT f.id,u.id,u.username,watertype,water,watersum,monthwater,electricity,electricitytype,electricitysum,monthelectricity,years,`month`,cost,costime,adminid,note FROM feeinfo f,users u WHERE f.userid=u.id and u.id="
+ id;
}
Connection conn = DbConnection.getConnection();
PreparedStatement stmt = null;
;
ResultSet rs = null;
ArrayList<FeeinfoImp> list = new ArrayList<FeeinfoImp>();
try {
stmt = (PreparedStatement) conn.prepareStatement(sql);
rs = stmt.executeQuery();
while (rs.next()) {
FeeinfoImp feeinfoImp = new FeeinfoImp(rs.getInt(1), rs.getInt(2), rs.getString(3), rs.getString(4),
rs.getString(5), rs.getString(6), rs.getString(7), rs.getString(8), rs.getString(9),
rs.getString(10), rs.getString(11), rs.getString(12), rs.getString(13), rs.getString(14),
rs.getString(15), rs.getString(16), rs.getString(17));
list.add(feeinfoImp);
}
} catch (SQLException e1) {
e1.printStackTrace();
} finally {
try {
DbConnection.colse(rs, stmt, conn);
} catch (Exception e) {
e.printStackTrace();
}
}
Object[][] objects = new Object[list.size()][17];
for (int i = 0; i < list.size(); i++) {
objects[i][0] = list.get(i).getId();
objects[i][1] = list.get(i).getUserName();
objects[i][2] = list.get(i).getWatertype();
objects[i][3] = list.get(i).getWater();
objects[i][4] = list.get(i).getWatersum();
objects[i][5] = list.get(i).getMonthwater();
objects[i][6] = list.get(i).getElectricitytype();
objects[i][7] = list.get(i).getElectricity();
objects[i][8] = list.get(i).getElectricitysum();
objects[i][9] = list.get(i).getMonthelectricity();
objects[i][10] = list.get(i).getYears();
objects[i][11] = list.get(i).getMonth();
objects[i][12] = list.get(i).getCost();
objects[i][13] = list.get(i).getCostime();
objects[i][14] = list.get(i).getAdminid();
objects[i][15] = list.get(i).getNote();
objects[i][16] = list.get(i).getUserid();
}
return objects;
}
// 根據日期查詢收費資訊
public Object[][] getFeeInfoByMonth(String id, String years, String month) {
String sql = null;
if (years.equals("全部年份")||month.equals("全部月份")&&id.equals("")) {
sql = "SELECT f.id,u.id,u.username,watertype,water,watersum,monthwater,electricity,electricitytype,electricitysum,monthelectricity,years,`month`,cost,costime,adminid,note FROM feeinfo f,users u WHERE f.userid=u.id";
}else if (years.equals("全部年份")||month.equals("全部月份")&&!id.equals("")) {
sql = "SELECT f.id,u.id,u.username,watertype,water,watersum,monthwater,electricity,electricitytype,electricitysum,monthelectricity,years,`month`,cost,costime,adminid,note FROM feeinfo f,users u WHERE f.userid=u.id and u.id="+id;
}else if (!years.equals("")||!month.equals("")&&id.equals("")) {
sql = "SELECT f.id,u.id,u.username,watertype,water,watersum,monthwater,electricity,electricitytype,electricitysum,monthelectricity,years,`month`,cost,costime,adminid,note FROM feeinfo f,users u WHERE f.userid=u.id and years='" + years + "' and `month`='" + month + "'";
}else if (!years.equals("")&&!month.equals("")&&!id.equals("")) {
sql = "SELECT f.id,u.id,u.username,watertype,water,watersum,monthwater,electricity,electricitytype,electricitysum,monthelectricity,years,`month`,cost,costime,adminid,note FROM feeinfo f,users u WHERE f.userid=u.id and u.id="
+ id + " and years='" + years + "' and `month`='" + month + "'";
}else {
sql = "SELECT f.id,u.id,u.username,watertype,water,watersum,monthwater,electricity,electricitytype,electricitysum,monthelectricity,years,`month`,cost,costime,adminid,note FROM feeinfo f,users u WHERE f.userid=u.id";
}
Connection conn = DbConnection.getConnection();
PreparedStatement stmt = null;
;
ResultSet rs = null;
ArrayList<FeeinfoImp> list = new ArrayList<FeeinfoImp>();
try {
System.out.println(sql);
stmt = (PreparedStatement) conn.prepareStatement(sql);
rs = stmt.executeQuery();
while (rs.next()) {
FeeinfoImp feeinfoImp = new FeeinfoImp(rs.getInt(1), rs.getInt(2), rs.getString(3), rs.getString(4),
rs.getString(5), rs.getString(6), rs.getString(7), rs.getString(8), rs.getString(9),
rs.getString(10), rs.getString(11), rs.getString(12), rs.getString(13), rs.getString(14),
rs.getString(15), rs.getString(16), rs.getString(17));
list.add(feeinfoImp);
}
} catch (SQLException e1) {
e1.printStackTrace();
} finally {
try {
DbConnection.colse(rs, stmt, conn);
} catch (Exception e) {
e.printStackTrace();
}
}
Object[][] objects = new Object[list.size()][17];
for (int i = 0; i < list.size(); i++) {
objects[i][0] = list.get(i).getId();
objects[i][1] = list.get(i).getUserName();
objects[i][2] = list.get(i).getWatertype();
objects[i][3] = list.get(i).getWater();
objects[i][4] = list.get(i).getWatersum();
objects[i][5] = list.get(i).getMonthwater();
objects[i][6] = list.get(i).getElectricitytype();
objects[i][7] = list.get(i).getElectricity();
objects[i][8] = list.get(i).getElectricitysum();
objects[i][9] = list.get(i).getMonthelectricity();
objects[i][10] = list.get(i).getYears();
objects[i][11] = list.get(i).getMonth();
objects[i][12] = list.get(i).getCost();
objects[i][13] = list.get(i).getCostime();
objects[i][14] = list.get(i).getAdminid();
objects[i][15] = list.get(i).getNote();
objects[i][16] = list.get(i).getUserid();
}
return objects;
}
// 查詢執行行數
public int userloginSelect(String sql) {
// String sql="select * from users where password='"+password+"' and
// username='"+username+"'";
ResultSet resultSet = DbConnection.query(sql);
int a = 0;
try {
while (resultSet.next()) {
a = resultSet.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace();
}
return a;
}
// 查詢用戶ID
public int userloginSelectByid(String sql) {
ResultSet resultSet = DbConnection.query(sql);
int a = 0;
try {
while (resultSet.next()) {
a = resultSet.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace();
}
return a;
}
// 查詢用戶ID
public String getStr(String sql) {
ResultSet resultSet = DbConnection.query(sql);
String a = null;
try {
while (resultSet.next()) {
a = resultSet.getString(1);
}
} catch (SQLException e) {
e.printStackTrace();
}
return a;
}
}
② Updata(增刪改查類)
package com.ynavc.Controller;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import com.ynavc.Dao.DbConnection;
public class Updata {
// 添加資料
public int addData(String sql) {
Connection conn = DbConnection.getConnection();
// 獲取連接
PreparedStatement stmt = null;
ResultSet rs = null;
try {
System.out.println(sql);
stmt = conn.prepareStatement(sql);
int executeUpdate = stmt.executeUpdate();
return executeUpdate;
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "執行陳述句出錯\n" + e.toString());
e.printStackTrace();
}finally {
try {
DbConnection.colse(rs, stmt, conn);
} catch (Exception e) {
e.printStackTrace();
}
}
return 0;
}
}
3、Dao包【資料庫鏈接工具包】
① DbConnection(資料庫連接類)
package com.ynavc.Dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import com.mysql.jdbc.Statement;
public class DbConnection {
// 驅動類的類名
private static final String DRIVERNAME = "com.mysql.jdbc.Driver";
// 連接資料的URL路徑
private static final String URL = "jdbc:mysql://127.0.0.1:3306/utilitiessys?useUnicode=true&characterEncoding=UTF-8&useSSL=false";
// 資料庫登錄賬號
private static final String USER = "root";
// 資料庫登錄密碼
private static final String PASSWORD = "123456";
// 加載驅動
static {
try {
Class.forName(DRIVERNAME);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
// 獲取資料庫連接
public static Connection getConnection() {
try {
return DriverManager.getConnection(URL, USER, PASSWORD);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
// 查詢
public static ResultSet query(String sql) {
System.out.println(sql);
// 獲取連接
Connection connection = getConnection();
PreparedStatement psd;
try {
psd = connection.prepareStatement(sql);
return psd.executeQuery();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "執行陳述句出錯\n" + e.toString());
e.printStackTrace();
}
return null;
}
// 增、刪、改、查
public static int updataInfo(String sql) {
System.out.println(sql);
// 獲取連接
Connection connection = getConnection();
try {
PreparedStatement psd = connection.prepareStatement(sql);
return psd.executeUpdate();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "執行陳述句出錯\n" + e.toString());
e.printStackTrace();
}
return 0;
}
// 關閉連接
public static void colse(ResultSet rs, PreparedStatement stmt, Connection conn) throws Exception {
try {
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.cancel();
}
if (conn != null) {
conn.close();
}
} catch (Exception e) {
e.printStackTrace();
throw new Exception();
}
}
public static void main(String[] args) {
}
}
4、Test包【測驗包】
① Main(運行入口)
package com.ynavc.Test;
import com.ynavc.Vive.UserLogin;
public class Main {
public static void main(String[] args) {
new UserLogin().setVisible(true);
}
}
5、View包【視圖包】
① AdminFeeView(水電費管理系統>用戶水電費查詢)
package com.ynavc.Vive;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import com.ynavc.Bean.Admin;
import com.ynavc.Bean.FeeinfoImp;
import com.ynavc.Controller.Select;
import com.ynavc.Controller.Updata;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import java.awt.Color;
import java.awt.FileDialog;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JButton;
public class AdminFeeView extends JFrame {
JTable jtable;
Select select = new Select();
Updata updata = new Updata();
Object[] header = { "訂單號", "戶主", "用水分類", "水費單價", "水費總量", "本月水費", "用電型別", "電費單價", "電總量", "本月電費", "年份", "月份", "應繳納費用",
"收費時間", "開票人", "備注" };
Object[][] data = null;
DefaultTableModel df = null;
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
private JTextField textField;
public AdminFeeView() {
super("水電費管理系統--用戶水電費查詢");
Updata updata = new Updata();
this.setBounds(0, 0, 1235, 550);
this.setLocationRelativeTo(null);// 讓視窗在螢屏中間顯示
this.setResizable(false);
getContentPane().setLayout(null);
data = select.getFeeInfo("");
df = new DefaultTableModel(data, header);
jtable = new JTable(df);// 創建表格
jtable.getTableHeader().setFont(new Font(null, Font.BOLD, 14)); // 設定表頭名稱字體樣式
jtable.getTableHeader().setForeground(Color.black); // 設定表頭名稱字體顏色
// jTable.getTableHeader().setResizingAllowed(false); // 設定不允許手動改變列寬
jtable.getTableHeader().setReorderingAllowed(false);// 設定表頭不允許拖動
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;// 水平滾動條
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;// 垂直滾動條
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
new AdminView().setVisible(true);
// 加入動作
// GoodsManagement m = new GoodsManagement();
// m.setVisible(true);
}
});
JScrollPane jsp = new JScrollPane(jtable, v, h);
jsp.setBounds(26, 105, 1178, 331);
getContentPane().add(jsp);
JPanel panel = new JPanel();
panel.setBorder(new TitledBorder(null, "條件查詢", TitledBorder.LEADING, TitledBorder.TOP, null, null));
panel.setBounds(26, 13, 623, 78);
getContentPane().add(panel);
JLabel label = new JLabel("戶主編號:");
panel.add(label);
textField = new JTextField();
panel.add(textField);
textField.setColumns(10);
JLabel label_1 = new JLabel("年份:");
panel.add(label_1);
JComboBox comboBox = new JComboBox();
panel.add(comboBox);
comboBox.addItem("全部年份");
for (int i = 2016; i < 2026; i++) {
comboBox.addItem(i + "年");
}
JLabel label_2 = new JLabel("月份");
panel.add(label_2);
JComboBox comboBox_1 = new JComboBox();
panel.add(comboBox_1);
comboBox_1.addItem("全部月份");
for (int i = 1; i <= 12; i++) {
comboBox_1.addItem(i + "月");
}
comboBox.setSelectedItem("2021年");
comboBox_1.setSelectedItem("7月");
JButton button = new JButton("查詢");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String years = comboBox.getItemAt(comboBox.getSelectedIndex()).toString();
String mouth = comboBox_1.getItemAt(comboBox_1.getSelectedIndex()).toString();
Object[][] data = select.getFeeInfoByMonth(textField.getText(), years, mouth);
df.setDataVector(data, header);
}
});
panel.add(button);
JButton btnNewButton = new JButton("顯示全部");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Object[][] data = select.getFeeInfo("");
df.setDataVector(data, header);
}
});
btnNewButton.setBounds(797, 47, 113, 27);
getContentPane().add(btnNewButton);
JButton button_1 = new JButton("洗掉");
button_1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (jtable.getSelectedColumn() < 0) {
JOptionPane.showMessageDialog(null, "請選中要洗掉的資料!");
} else {
int userid = Integer.parseInt(jtable.getValueAt(jtable.getSelectedRow(), 0).toString());
String dsql = "delete from feeinfo where id=" + userid;
int result = updata.addData(dsql);
if (result > 0) {
JOptionPane.showMessageDialog(null, "洗掉成功!");
Object[][] data = select.getFeeInfo("");
df.setDataVector(data, header);
} else {
JOptionPane.showMessageDialog(null, "洗掉失敗!");
}
}
}
});
// // 創建表模型
// df = new DefaultTableModel(data, header) {
// // 設定表格內容不可被編輯
// public boolean isCellEditable(int row, int column) {
// return false;// 回傳true表示能編輯,false表示不能編輯
// }
// };
JButton btnexcel = new JButton("匯出資料導Excel");
btnexcel.setBounds(997, 47, 147, 27);
getContentPane().add(btnexcel);
btnexcel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButtonActionPerformed(e);
}
});
button_1.setBounds(797, 462, 113, 27);
getContentPane().add(button_1);
JButton button_2 = new JButton("修改");
button_2.setBounds(950, 462, 113, 27);
button_2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (jtable.getSelectedColumn() < 0) {
JOptionPane.showMessageDialog(null, "請選擇要修改的資料!");
} else {
FeeinfoImp feeinfoImp = new FeeinfoImp();
feeinfoImp.setId(Integer.parseInt(jtable.getValueAt(jtable.getSelectedRow(), 0).toString()));
feeinfoImp.setUserName(jtable.getValueAt(jtable.getSelectedRow(), 1).toString());
feeinfoImp.setWatertype(jtable.getValueAt(jtable.getSelectedRow(), 2).toString());
feeinfoImp.setWater(jtable.getValueAt(jtable.getSelectedRow(), 3).toString());
feeinfoImp.setWatersum(jtable.getValueAt(jtable.getSelectedRow(), 4).toString());
feeinfoImp.setMonthwater(jtable.getValueAt(jtable.getSelectedRow(), 5).toString());
feeinfoImp.setElectricitytype(jtable.getValueAt(jtable.getSelectedRow(), 6).toString());
feeinfoImp.setElectricity(jtable.getValueAt(jtable.getSelectedRow(), 7).toString());
feeinfoImp.setElectricitysum(jtable.getValueAt(jtable.getSelectedRow(), 8).toString());
feeinfoImp.setMonthelectricity(jtable.getValueAt(jtable.getSelectedRow(), 9).toString());
feeinfoImp.setYears(jtable.getValueAt(jtable.getSelectedRow(), 10).toString());
feeinfoImp.setMonth(jtable.getValueAt(jtable.getSelectedRow(), 11).toString());
feeinfoImp.setCost(jtable.getValueAt(jtable.getSelectedRow(), 12).toString());
feeinfoImp.setCostime(jtable.getValueAt(jtable.getSelectedRow(), 13).toString());
feeinfoImp.setAdminid(jtable.getValueAt(jtable.getSelectedRow(), 14).toString());
feeinfoImp.setNote(jtable.getValueAt(jtable.getSelectedRow(), 15).toString());
System.out.println(feeinfoImp);
new AdminFeeViewUpd(feeinfoImp).setVisible(true);;
}
}
});
getContentPane().add(button_2);
JButton button_2_1 = new JButton("增加");
button_2_1.setBounds(1091, 462, 113, 27);
getContentPane().add(button_2_1);
button_2_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new AdminFeeViewAdd().setVisible(true);
}
});
// 設定單元格內容居中顯示
DefaultTableCellRenderer r = new DefaultTableCellRenderer();
r.setHorizontalAlignment(JLabel.CENTER);
jtable.setDefaultRenderer(Object.class, r);
// Object[][] data = select.getAdminInfo();
df.setDataVector(data, header);
}
// 匯出
private void jButtonActionPerformed(java.awt.event.ActionEvent evt) {
FileDialog fd = new FileDialog(this, "將資料保存到", FileDialog.SAVE);
fd.setLocation(1100, 600);
fd.setVisible(true);
String stringfile = fd.getDirectory() + fd.getFile() + ".xlsx";
try {
this.exportTable(jtable, new File(stringfile));
} catch (IOException ex) {
ex.printStackTrace();
}
}
/** 匯出JTable到excel */
public void exportTable(JTable table, File file) throws IOException {
TableModel model = table.getModel();
BufferedWriter bWriter = new BufferedWriter(new FileWriter(file));
for (int i = 0; i < model.getColumnCount(); i++) {
bWriter.write(model.getColumnName(i));
bWriter.write("\t");
}
bWriter.newLine();
for (int i = 0; i < model.getRowCount(); i++) {
for (int j = 0; j < model.getColumnCount(); j++) {
bWriter.write(model.getValueAt(i, j).toString());
bWriter.write("\t");
}
bWriter.newLine();
}
bWriter.close();
}
public void refresh() {
Object[][] data = select.getFeeInfo("");
df.setDataVector(data, header);
}
//
// public static void main(String[] args) {
// new AdminFeeView().setVisible(true);
// }
}
② AdminFeeViewAdd(水電費管理系統>用戶水電費添加)
package com.ynavc.Vive;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.TitledBorder;
import com.ynavc.Controller.Updata;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.JComboBox;
import java.awt.Color;
public class AdminFeeViewAdd extends JFrame{
private JTextField userid;
private JTextField admin;
private JTextField watertype;
private JTextField watersum;
private JTextField water;
private JTextField monthwater;
private JTextField electricitytype;
private JTextField electricitysum;
private JTextField monthelectricity;
private JTextField electricity;
private JTextField cost;
private JTextField node;
public AdminFeeViewAdd() {
super("水電費管理系統--用戶水電費管理--收費資訊添加");
this.setBounds(0, 0, 900, 500);
this.setLocationRelativeTo(null);// 讓視窗在螢屏中間顯示
this.setResizable(false);// 讓視窗大小不可改變
getContentPane().setLayout(null);
Updata updata = new Updata();
JLabel label = new JLabel("戶主編號:");
label.setBounds(25, 123, 83, 18);
getContentPane().add(label);
userid = new JTextField();
userid.setBounds(117, 120, 196, 24);
getContentPane().add(userid);
userid.setColumns(10);
JLabel label_1 = new JLabel("開票人:");
label_1.setBounds(618, 120, 60, 18);
getContentPane().add(label_1);
admin = new JTextField();
admin.setColumns(10);
admin.setBounds(677, 117, 196, 24);
getContentPane().add(admin);
JLabel label_2 = new JLabel("水電費添加");
label_2.setFont(new Font("宋體", Font.BOLD, 20));
label_2.setBounds(363, 28, 123, 28);
getContentPane().add(label_2);
JButton addBtn = new JButton("確認添加");
addBtn.setBounds(389, 425, 113, 27);
addBtn.setIcon(new ImageIcon(AdminSysViewAdd.class.getResource("/images/add.png")));
getContentPane().add(addBtn);
JPanel panel = new JPanel();
panel.setBounds(17, 184, 419, 130);
panel.setBorder(new TitledBorder(null, "水費資訊", TitledBorder.LEADING, TitledBorder.TOP, null, null));
getContentPane().add(panel);
panel.setLayout(null);
JLabel label_3 = new JLabel("用水型別:");
label_3.setBounds(14, 47, 75, 18);
panel.add(label_3);
watertype = new JTextField();
watertype.setBounds(103, 44, 86, 24);
panel.add(watertype);
watertype.setColumns(10);
JLabel label_4 = new JLabel("用水量:");
label_4.setBounds(230, 47, 75, 18);
panel.add(label_4);
watersum = new JTextField();
watersum.setBounds(319, 44, 86, 24);
panel.add(watersum);
watersum.setColumns(10);
JLabel lblNewLabel = new JLabel("水費單價:");
lblNewLabel.setBounds(14, 91, 75, 18);
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
panel.add(lblNewLabel);
water = new JTextField();
water.setBounds(103, 88, 86, 24);
panel.add(water);
water.setColumns(10);
JLabel label_5 = new JLabel("本月水費:");
label_5.setBounds(230, 91, 75, 18);
panel.add(label_5);
monthwater = new JTextField();
monthwater.setBounds(319, 88, 86, 24);
panel.add(monthwater);
monthwater.setColumns(10);
JPanel panel_1 = new JPanel();
panel_1.setBorder(new TitledBorder(null, "電費資訊", TitledBorder.LEADING, TitledBorder.TOP, null, null));
panel_1.setBounds(454, 184, 419, 130);
getContentPane().add(panel_1);
panel_1.setLayout(null);
JLabel label_3_1 = new JLabel("用電型別:");
label_3_1.setBounds(14, 40, 75, 18);
panel_1.add(label_3_1);
electricitytype = new JTextField();
electricitytype.setColumns(10);
electricitytype.setBounds(103, 37, 86, 24);
panel_1.add(electricitytype);
JLabel label_4_1 = new JLabel("用電量:");
label_4_1.setBounds(230, 40, 75, 18);
panel_1.add(label_4_1);
electricitysum = new JTextField();
electricitysum.setColumns(10);
electricitysum.setBounds(319, 37, 86, 24);
panel_1.add(electricitysum);
monthelectricity = new JTextField();
monthelectricity.setColumns(10);
monthelectricity.setBounds(319, 81, 86, 24);
panel_1.add(monthelectricity);
JLabel label_5_1 = new JLabel("本月電費:");
label_5_1.setBounds(230, 84, 75, 18);
panel_1.add(label_5_1);
electricity = new JTextField();
electricity.setColumns(10);
electricity.setBounds(103, 81, 86, 24);
panel_1.add(electricity);
JLabel lblNewLabel_1 = new JLabel("電費單價:");
lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_1.setBounds(14, 84, 75, 18);
panel_1.add(lblNewLabel_1);
JLabel lblNewLabel_2 = new JLabel("年份:");
lblNewLabel_2.setBounds(25, 347, 52, 18);
getContentPane().add(lblNewLabel_2);
JComboBox years = new JComboBox();
years.setBounds(77, 344, 72, 24);
getContentPane().add(years);
for (int i = 2016; i < 2026; i++) {
years.addItem(i + "年");
}
JLabel lblNewLabel_2_1 = new JLabel("月份:");
lblNewLabel_2_1.setBounds(163, 346, 52, 18);
getContentPane().add(lblNewLabel_2_1);
JComboBox mouth = new JComboBox();
mouth.setBounds(215, 343, 72, 24);
getContentPane().add(mouth);
for (int i = 1; i <= 12; i++) {
mouth.addItem(i + "月");
}
years.setSelectedItem("2021年");
mouth.setSelectedItem("7月");
JLabel label_6 = new JLabel("本月總價:");
label_6.setFont(new Font("宋體", Font.PLAIN, 17));
label_6.setForeground(Color.RED);
label_6.setBounds(636, 350, 105, 18);
getContentPane().add(label_6);
cost = new JTextField();
cost.setBounds(755, 347, 105, 24);
getContentPane().add(cost);
cost.setColumns(10);
JLabel label_7 = new JLabel("備注:");
label_7.setBounds(314, 350, 72, 18);
getContentPane().add(label_7);
node = new JTextField();
node.setBounds(363, 347, 196, 24);
getContentPane().add(node);
node.setColumns(10);
addBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String uid = userid.getText();
String uwatertype = watertype.getText();
String uwater = water.getText();
String uwatersum = watersum.getText();
String umonthwater = monthwater.getText();
String uelectricitytype = electricitytype.getText();
String uelectricity = electricity.getText();
String uelectricitysum = electricitysum.getText();
String umonthelectricity = monthelectricity.getText();
String uyears = years.getItemAt(years.getSelectedIndex()).toString();
String umouth = mouth.getItemAt(mouth.getSelectedIndex()).toString();
String ucost = cost.getText();
String costTime = getTime();
String uadmin = admin.getText();
String unode = node.getText();
if (uid.equals("") && uadmin.equals("")) {
JOptionPane.showMessageDialog(null, "請填寫完整資訊!");
} else {
// String sql1= "INSERT INTO `feeinfo` VALUES (2, 1, '家庭用電', '20', '50', '200', '家庭用電', '20', '20', '20', '2021年', '5月', '300', '2000', 'mj', '背后')";
String sql = "INSERT INTO feeinfo VALUES(null,'" + uid + "','"+uwatertype+"','" + uwater + "','" + uwatersum + "','" + umonthwater + "','" + uelectricitytype + "','" + uelectricity + "','" + uelectricitysum + "','" + umonthelectricity + "','" + uyears + "','" + umouth + "','" + ucost + "','" + costTime + "','" + uadmin + "','" + unode + "')";
int reselt = updata.addData(sql);
if (reselt > 0) {
JOptionPane.showMessageDialog(null, "水電費資訊添加成功!");
AdminView.getAdminFeeView().refresh();
dispose();
} else {
JOptionPane.showMessageDialog(null, "添加失敗!");
}
}
}
});
}
private String getTime() {
Date d = new Date();
SimpleDateFormat sbf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String format = sbf.format(d);
System.out.println(sbf);
System.out.println(sbf.format(d));
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
return format;
}
// public static void main(String[] args) {
// new AdminFeeViewAdd().setVisible(true);
// }
}
③ AdminFeeViewUpd(水電費管理系統>用戶水電費修改)
package com.ynavc.Vive;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.TitledBorder;
import com.ynavc.Bean.FeeinfoImp;
import com.ynavc.Controller.Updata;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.JComboBox;
import java.awt.Color;
public class AdminFeeViewUpd extends JFrame{
private JTextField userid;
private JTextField admin;
private JTextField watertype;
private JTextField watersum;
private JTextField water;
private JTextField monthwater;
private JTextField electricitytype;
private JTextField electricitysum;
private JTextField monthelectricity;
private JTextField electricity;
private JTextField cost;
private JTextField node;
public AdminFeeViewUpd(FeeinfoImp f) {
super("水電費管理系統--用戶水電費管理--收費資訊添加");
this.setBounds(0, 0, 900, 500);
this.setLocationRelativeTo(null);// 讓視窗在螢屏中間顯示
this.setResizable(false);// 讓視窗大小不可改變
getContentPane().setLayout(null);
Updata updata = new Updata();
JLabel label = new JLabel("戶主編號:");
label.setBounds(25, 123, 83, 18);
getContentPane().add(label);
userid = new JTextField();
userid.setBounds(117, 120, 196, 24);
getContentPane().add(userid);
userid.setColumns(10);
JLabel label_1 = new JLabel("開票人:");
label_1.setBounds(618, 120, 60, 18);
getContentPane().add(label_1);
admin = new JTextField();
admin.setColumns(10);
admin.setBounds(677, 117, 196, 24);
getContentPane().add(admin);
JLabel label_2 = new JLabel("水電費資訊修改");
label_2.setFont(new Font("宋體", Font.BOLD, 20));
label_2.setBounds(363, 28, 196, 28);
getContentPane().add(label_2);
JButton addBtn = new JButton("確認修改");
addBtn.setBounds(389, 425, 113, 27);
addBtn.setIcon(new ImageIcon(AdminSysViewAdd.class.getResource("/images/modify.png")));
getContentPane().add(addBtn);
JPanel panel = new JPanel();
panel.setBounds(17, 184, 419, 130);
panel.setBorder(new TitledBorder(null, "水費資訊", TitledBorder.LEADING, TitledBorder.TOP, null, null));
getContentPane().add(panel);
panel.setLayout(null);
JLabel label_3 = new JLabel("用水型別:");
label_3.setBounds(14, 47, 75, 18);
panel.add(label_3);
watertype = new JTextField();
watertype.setBounds(103, 44, 86, 24);
panel.add(watertype);
watertype.setColumns(10);
JLabel label_4 = new JLabel("用水量:");
label_4.setBounds(230, 47, 75, 18);
panel.add(label_4);
watersum = new JTextField();
watersum.setBounds(319, 44, 86, 24);
panel.add(watersum);
watersum.setColumns(10);
JLabel lblNewLabel = new JLabel("水費單價:");
lblNewLabel.setBounds(14, 91, 75, 18);
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
panel.add(lblNewLabel);
water = new JTextField();
water.setBounds(103, 88, 86, 24);
panel.add(water);
water.setColumns(10);
JLabel label_5 = new JLabel("本月水費:");
label_5.setBounds(230, 91, 75, 18);
panel.add(label_5);
monthwater = new JTextField();
monthwater.setBounds(319, 88, 86, 24);
panel.add(monthwater);
monthwater.setColumns(10);
JPanel panel_1 = new JPanel();
panel_1.setBorder(new TitledBorder(null, "電費資訊", TitledBorder.LEADING, TitledBorder.TOP, null, null));
panel_1.setBounds(454, 184, 419, 130);
getContentPane().add(panel_1);
panel_1.setLayout(null);
JLabel label_3_1 = new JLabel("用電型別:");
label_3_1.setBounds(14, 40, 75, 18);
panel_1.add(label_3_1);
electricitytype = new JTextField();
electricitytype.setColumns(10);
electricitytype.setBounds(103, 37, 86, 24);
panel_1.add(electricitytype);
JLabel label_4_1 = new JLabel("用電量:");
label_4_1.setBounds(230, 40, 75, 18);
panel_1.add(label_4_1);
electricitysum = new JTextField();
electricitysum.setColumns(10);
electricitysum.setBounds(319, 37, 86, 24);
panel_1.add(electricitysum);
monthelectricity = new JTextField();
monthelectricity.setColumns(10);
monthelectricity.setBounds(319, 81, 86, 24);
panel_1.add(monthelectricity);
JLabel label_5_1 = new JLabel("本月電費:");
label_5_1.setBounds(230, 84, 75, 18);
panel_1.add(label_5_1);
electricity = new JTextField();
electricity.setColumns(10);
electricity.setBounds(103, 81, 86, 24);
panel_1.add(electricity);
JLabel lblNewLabel_1 = new JLabel("電費單價:");
lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_1.setBounds(14, 84, 75, 18);
panel_1.add(lblNewLabel_1);
JLabel lblNewLabel_2 = new JLabel("年份:");
lblNewLabel_2.setBounds(25, 347, 52, 18);
getContentPane().add(lblNewLabel_2);
JComboBox years = new JComboBox();
years.setBounds(77, 344, 74, 24);
getContentPane().add(years);
for (int i = 2016; i < 2026; i++) {
years.addItem(i + "年");
}
JLabel lblNewLabel_2_1 = new JLabel("月份:");
lblNewLabel_2_1.setBounds(165, 347, 52, 18);
getContentPane().add(lblNewLabel_2_1);
JComboBox mouth = new JComboBox();
mouth.setBounds(217, 344, 72, 24);
getContentPane().add(mouth);
for (int i = 1; i <= 12; i++) {
mouth.addItem(i + "月");
}
years.setSelectedItem("2021年");
mouth.setSelectedItem("7月");
JLabel label_6 = new JLabel("本月總價:");
label_6.setFont(new Font("宋體", Font.PLAIN, 17));
label_6.setForeground(Color.RED);
label_6.setBounds(636, 350, 105, 18);
getContentPane().add(label_6);
cost = new JTextField();
cost.setBounds(755, 347, 105, 24);
getContentPane().add(cost);
cost.setColumns(10);
JLabel label_7 = new JLabel("備注:");
label_7.setBounds(314, 350, 72, 18);
getContentPane().add(label_7);
node = new JTextField();
node.setBounds(363, 347, 196, 24);
getContentPane().add(node);
node.setColumns(10);
if (f!=null) {
userid.setText(f.getUserName().toString());
admin.setText(f.getAdminid());
water.setText(f.getWater());
watertype.setText(f.getWatertype());
watersum.setText(f.getWatersum());
monthwater.setText(f.getMonthwater());
electricity.setText(f.getElectricity());
electricitysum.setText(f.getElectricitysum());
electricitytype.setText(f.getElectricitytype());
monthelectricity.setText(f.getMonthelectricity());
node.setText(f.getNote());
cost.setText(f.getCost());
mouth.setSelectedItem(f.getMonth());
years.setSelectedItem(f.getYears());
}
addBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String uid = userid.getText();
String uwatertype = watertype.getText();
String uwater = water.getText();
String uwatersum = watersum.getText();
String umonthwater = monthwater.getText();
String uelectricitytype = electricitytype.getText();
String uelectricity = electricity.getText();
String uelectricitysum = electricitysum.getText();
String umonthelectricity = monthelectricity.getText();
String uyears = years.getItemAt(years.getSelectedIndex()).toString();
String umouth = mouth.getItemAt(mouth.getSelectedIndex()).toString();
String ucost = cost.getText();
String costTime = getTime();
String uadmin = admin.getText();
String unode = node.getText();
if (uid.equals("") && uadmin.equals("")) {
JOptionPane.showMessageDialog(null, "請填寫完整資訊!");
} else {
// String sql1= "INSERT INTO `feeinfo` VALUES (2, 1, '家庭用電', '20', '50', '200', '家庭用電', '20', '20', '20', '2021年', '5月', '300', '2000', 'mj', '背后')";
String sql = "INSERT INTO feeinfo VALUES(null,'" + uid + "','"+uwatertype+"','" + uwater + "','" + uwatersum + "','" + umonthwater + "','" + uelectricitytype + "','" + uelectricity + "','" + uelectricitysum + "','" + umonthelectricity + "','" + uyears + "','" + umouth + "','" + ucost + "','" + costTime + "','" + uadmin + "','" + unode + "')";
int reselt = updata.addData(sql);
if (reselt > 0) {
JOptionPane.showMessageDialog(null, "水電費資訊添加成功!");
AdminView.getAdminFeeView().refresh();
dispose();
} else {
JOptionPane.showMessageDialog(null, "添加失敗!");
}
}
}
});
}
private String getTime() {
Date d = new Date();
SimpleDateFormat sbf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String format = sbf.format(d);
System.out.println(sbf);
System.out.println(sbf.format(d));
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
return format;
}
// public static void main(String[] args) {
// new AdminFeeViewUpd().setVisible(true);
// }
}
④ AdminSysView(水電費管理系統>管理后臺>管理員賬戶管理)
package com.ynavc.Vive;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import com.ynavc.Bean.Admin;
import com.ynavc.Controller.Select;
import com.ynavc.Controller.Updata;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Font;
import java.awt.event.ActionEvent;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
public class AdminSysView extends JFrame {
private JTextField textField;
Select select = new Select();
Updata updata = new Updata();
Object[] header = { "管理員編號", "管理員姓名", "管理員賬戶", "管理員密碼" };
Object[][] data = select.getAdminInfo();
DefaultTableModel df = new DefaultTableModel(data, header);
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
private JTextField textField_1;
public AdminSysView() {
super("水電費管理系統--管理員后臺---管理員賬戶管理");
this.setBounds(0, 0, 748, 482);
this.setLocationRelativeTo(null);// 讓視窗在螢屏中間顯示
this.setResizable(false);// 讓視窗大小不可改變
getContentPane().setLayout(null);
JTable jTable = new JTable(df);
JScrollPane jsp = new JScrollPane(jTable, v, h);
jsp.setBounds(14, 114, 714, 320);
getContentPane().add(jsp);
JButton button_2 = new JButton("修改");
button_2.setBounds(627, 27, 90, 30);
button_2.setIcon(new ImageIcon(AdminSysViewAdd.class.getResource("/images/modify.png")));
getContentPane().add(button_2);
button_2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (jTable.getSelectedColumn() < 0) {
JOptionPane.showMessageDialog(null, "請選擇要修改的資料!");
} else {
Admin admin = new Admin();
admin.setId(Integer.parseInt(jTable.getValueAt(jTable.getSelectedRow(), 0).toString()));
admin.setName(jTable.getValueAt(jTable.getSelectedRow(), 1).toString());
admin.setAccount(jTable.getValueAt(jTable.getSelectedRow(), 2).toString());
admin.setPassword(jTable.getValueAt(jTable.getSelectedRow(), 3).toString());
System.out.println(admin);
AdminSysViewUpd adminSysViewUpd = new AdminSysViewUpd(admin);
adminSysViewUpd.setVisible(true);
}
}
});
JButton button_3 = new JButton("洗掉");
button_3.setBounds(522, 70, 90, 30);
button_3.setIcon(new ImageIcon(AdminSysViewAdd.class.getResource("/images/delete.png")));
getContentPane().add(button_3);
button_3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (jTable.getSelectedColumn() < 0) {
JOptionPane.showMessageDialog(null, "請選中要洗掉的資料!");
} else {
int userid = Integer.parseInt(jTable.getValueAt(jTable.getSelectedRow(), 0).toString());
String dsql = "delete from admin where id=" + userid;
int result = updata.addData(dsql);
if (result > 0) {
JOptionPane.showMessageDialog(null, "洗掉成功!");
Object[][] data = select.getAdminInfo();
df.setDataVector(data, header);
} else {
JOptionPane.showMessageDialog(null, "洗掉失敗!");
}
}
}
});
JButton button_4 = new JButton("添加");
button_4.setBounds(627, 70, 90, 30);
button_4.setIcon(new ImageIcon(AdminSysViewAdd.class.getResource("/images/add.png")));
getContentPane().add(button_4);
button_4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
new AdminSysViewAdd().setVisible(true);
}
});
JPanel panel = new JPanel();
panel.setBounds(14, 13, 483, 81);
panel.setBorder(new TitledBorder(null, "條件查詢", TitledBorder.LEADING, TitledBorder.TOP, null, null));
getContentPane().add(panel);
JLabel label_1 = new JLabel("編號:");
panel.add(label_1);
textField_1 = new JTextField();
textField_1.setColumns(10);
panel.add(textField_1);
JLabel label = new JLabel("賬戶:");
panel.add(label);
textField = new JTextField();
panel.add(textField);
textField.setColumns(10);
JButton button = new JButton("查詢");
button.setIcon(new ImageIcon(AdminSysViewAdd.class.getResource("/images/search.png")));
panel.add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String id = textField_1.getText();
String name = textField.getText();
Object[][] data = select.getAdminInfoBykey(name, id);
df.setDataVector(data, header);
}
});
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
new AdminView().setVisible(true);
// 加入動作
// GoodsManagement m = new GoodsManagement();
// m.setVisible(true);
}
});
}
public void refresh() {
Object[][] data = select.getAdminInfo();
df.setDataVector(data, header);
}
// public static void main(String[] args) {
// AdminSysView t = new AdminSysView();
// t.setVisible(true);
// }
}
⑤ AdminSysViewAdd(水電費管理系統>管理后臺>管理員賬戶添加)
package com.ynavc.Vive;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JTextField;
import javax.swing.UnsupportedLookAndFeelException;
import com.ynavc.Controller.Updata;
import javax.swing.ImageIcon;
import javax.swing.JButton;
public class AdminSysViewAdd extends JFrame{
private JTextField username;
private JTextField account;
private JTextField password;
public AdminSysViewAdd() {
super("管理員賬戶管理");
this.setBounds(0, 0, 450, 400);
this.setLocationRelativeTo(null);// 讓視窗在螢屏中間顯示
this.setResizable(false);// 讓視窗大小不可改變
getContentPane().setLayout(null);
Updata updata = new Updata();
JLabel label = new JLabel("姓名:");
label.setBounds(64, 95, 72, 18);
getContentPane().add(label);
username = new JTextField();
username.setBounds(113, 92, 243, 24);
getContentPane().add(username);
username.setColumns(10);
JLabel label_1 = new JLabel("賬戶:");
label_1.setBounds(64, 149, 72, 18);
getContentPane().add(label_1);
account = new JTextField();
account.setColumns(10);
account.setBounds(113, 146, 243, 24);
getContentPane().add(account);
JLabel label_1_1 = new JLabel("密碼:");
label_1_1.setBounds(64, 203, 72, 18);
getContentPane().add(label_1_1);
password = new JTextField();
password.setColumns(10);
password.setBounds(113, 200, 243, 24);
getContentPane().add(password);
JLabel label_2 = new JLabel("管理員賬戶添加");
label_2.setFont(new Font("宋體", Font.BOLD, 20));
label_2.setBounds(144, 24, 173, 28);
getContentPane().add(label_2);
JButton addBtn = new JButton("確認添加");
addBtn.setBounds(171, 288, 113, 27);
addBtn.setIcon(new ImageIcon(AdminSysViewAdd.class.getResource("/images/add.png")));
getContentPane().add(addBtn);
addBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String uname = username.getText();
String uaccount = account.getText();
String pwd = password.getText();
if (uname.equals("") && pwd.equals("") && uaccount.equals("")) {
JOptionPane.showMessageDialog(null, "請填寫完整資訊!");
} else {
String sql = "INSERT INTO admin (name,account,`password`) VALUES('" + uname + "','"+uaccount+"','" + pwd + "')";
int reselt = updata.addData(sql);
if (reselt > 0) {
JOptionPane.showMessageDialog(null, "添加管理員賬戶成功!");
AdminSysView adminSysView = AdminView.getAdminSysView();
adminSysView.refresh();
dispose();
} else {
JOptionPane.showMessageDialog(null, "添加失敗!");
}
}
}
});
}
// public static void main(String[] args) {
// new AdminSysViewAdd().setVisible(true);
// }
}
⑥ AdminSysViewUpd(水電費管理系統>管理后臺>管理員賬戶修改)
package com.ynavc.Vive;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JTextField;
import javax.swing.UnsupportedLookAndFeelException;
import com.ynavc.Bean.Admin;
import com.ynavc.Controller.Updata;
import javax.swing.ImageIcon;
import javax.swing.JButton;
public class AdminSysViewUpd extends JFrame{
private JTextField username;
private JTextField account;
private JTextField password;
private JTextField userid;
public AdminSysViewUpd(Admin admin) {
super("管理員賬戶管理");
this.setBounds(0, 0, 450, 400);
this.setLocationRelativeTo(null);// 讓視窗在螢屏中間顯示
this.setResizable(false);// 讓視窗大小不可改變
getContentPane().setLayout(null);
Updata updata = new Updata();
JLabel label_2 = new JLabel("管理員賬戶修改");
label_2.setFont(new Font("宋體", Font.BOLD, 20));
label_2.setBounds(144, 24, 173, 28);
getContentPane().add(label_2);
JLabel label_3 = new JLabel("編號:");
label_3.setBounds(65, 83, 72, 18);
getContentPane().add(label_3);
userid = new JTextField();
userid.setEnabled(false);
userid.setColumns(10);
userid.setBounds(114, 80, 243, 24);
getContentPane().add(userid);
JLabel label = new JLabel("姓名:");
label.setBounds(65, 132, 72, 18);
getContentPane().add(label);
username = new JTextField();
username.setBounds(114, 129, 243, 24);
getContentPane().add(username);
username.setColumns(10);
JLabel label_1 = new JLabel("賬戶:");
label_1.setBounds(65, 186, 72, 18);
getContentPane().add(label_1);
account = new JTextField();
account.setColumns(10);
account.setBounds(114, 183, 243, 24);
getContentPane().add(account);
JLabel label_1_1 = new JLabel("密碼:");
label_1_1.setBounds(65, 240, 72, 18);
getContentPane().add(label_1_1);
password = new JTextField();
password.setColumns(10);
password.setBounds(114, 237, 243, 24);
getContentPane().add(password);
if (admin!=null) {
userid.setText(admin.getId().toString());
username.setText(admin.getName());
account.setText(admin.getAccount());
password.setText(admin.getPassword());
}
JButton addBtn = new JButton("確認修改");
addBtn.setBounds(171, 288, 113, 27);
addBtn.setIcon(new ImageIcon(AdminSysViewUpd.class.getResource("/images/modify.png")));
getContentPane().add(addBtn);
addBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String uid = userid.getText();
String uname = username.getText();
String uaccount = account.getText();
String pwd = password.getText();
if (uname.equals("") && pwd.equals("") && uaccount.equals("")) {
JOptionPane.showMessageDialog(null, "請填寫完整資訊!");
} else {
String sql = "UPDATE admin SET `name`='"+uname+"',account='"+uaccount+"',`password`='"+pwd+"' WHERE id='"+admin.getId()+"'";
int reselt = updata.addData(sql);
if (reselt > 0) {
JOptionPane.showMessageDialog(null, "添加管理員賬戶成功!");
AdminSysView adminSysView = AdminView.getAdminSysView();
adminSysView.refresh();
dispose();
} else {
JOptionPane.showMessageDialog(null, "添加失敗!");
}
}
}
});
}
// public static void main(String[] args) {
// new AdminSysViewUpd(null).setVisible(true);
// }
}
⑦ AdminUserView(水電費管理系統>管理后臺>平臺用戶資訊管理)
package com.ynavc.Vive;
import javax.swing.JFrame;
import com.ynavc.Controller.Select;
import com.ynavc.Controller.Updata;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import javax.xml.ws.soap.AddressingFeature;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.Component;
import java.awt.Container;
import java.awt.event.ActionEvent;
import javax.swing.JTextArea;
import java.awt.FlowLayout;
import java.awt.BorderLayout;
public class AdminUserView extends JFrame{
Select select = new Select();
Updata updata = new Updata();
private JTable table;
DefaultTableModel df;
Object[][] data = select.getUserInfo("");
String[] header = new String[] { "戶主編號", "戶主姓名", "賬戶", "密碼", "性別", "身份證號", "電話", "地址", "備注"};
private JTextField userid;
private JTextField username;
private JTextField address;
private JTextField idcard;
private JTextField phone;
private JTextField account;
private JTextField password;
private JTextField searchid;
JTextArea usertime;
ButtonGroup sex;
JRadioButton male,female;
public AdminUserView() {
super("水電費管理系統--管理員后臺--平臺用戶資訊管理");
Updata updata = new Updata();
this.setBounds(0, 0, 935, 700);
this.setLocationRelativeTo(null);// 讓視窗在螢屏中間顯示
this.setResizable(false);
getContentPane().setLayout(null);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(27, 321, 876, 331);
getContentPane().add(scrollPane);
table = new JTable();
df = new DefaultTableModel(data,header);
table.setModel(df);
scrollPane.setViewportView(table);
table.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
// 處理滑鼠釋放
}
@Override
public void mousePressed(MouseEvent e) {
// 處理滑鼠按下
}
@Override
public void mouseExited(MouseEvent e) {
// 處理滑鼠離開
}
@Override
public void mouseEntered(MouseEvent e) {
// 處理滑鼠移入
}
public void mouseClicked(MouseEvent e) {
// 處理滑鼠點擊
userid.setText(table.getValueAt(table.getSelectedRow(), 0).toString());
username.setText(table.getValueAt(table.getSelectedRow(), 1).toString());
account.setText(table.getValueAt(table.getSelectedRow(), 2).toString());
password.setText(table.getValueAt(table.getSelectedRow(), 3).toString());
if ((table.getValueAt(table.getSelectedRow(), 4).toString()).equals("男")) {
male.setSelected(true);
}else{
female.setSelected(true);
}
idcard.setText(table.getValueAt(table.getSelectedRow(), 5).toString());
phone.setText(table.getValueAt(table.getSelectedRow(), 6).toString());
address.setText(table.getValueAt(table.getSelectedRow(), 7).toString());
usertime.setText(table.getValueAt(table.getSelectedRow(), 8).toString());
}
});
JPanel panel = new JPanel();
panel.setBorder(new TitledBorder(null, "用戶資訊", TitledBorder.LEADING, TitledBorder.TOP, null, null));
panel.setBounds(27, 27, 876, 200);
getContentPane().add(panel);
panel.setLayout(null);
JLabel label = new JLabel("戶主編號:");
label.setBounds(32, 30, 75, 18);
panel.add(label);
userid = new JTextField();
userid.setEditable(false);
userid.setBounds(112, 26, 119, 24);
panel.add(userid);
userid.setColumns(10);
JLabel label_1 = new JLabel("戶主姓名:");
label_1.setBounds(257, 30, 75, 18);
panel.add(label_1);
username = new JTextField();
username.setBounds(337, 26, 108, 24);
panel.add(username);
username.setColumns(10);
JLabel label_2 = new JLabel("地址:");
label_2.setBounds(505, 67, 54, 18);
panel.add(label_2);
address = new JTextField();
address.setBounds(550, 64, 175, 24);
panel.add(address);
address.setColumns(10);
JLabel label_3 = new JLabel("身份證號:");
label_3.setBounds(32, 65, 75, 18);
panel.add(label_3);
idcard = new JTextField();
idcard.setBounds(112, 61, 171, 24);
panel.add(idcard);
idcard.setColumns(10);
JLabel label_2_1 = new JLabel("電話:");
label_2_1.setBounds(308, 67, 45, 18);
panel.add(label_2_1);
phone = new JTextField();
phone.setColumns(10);
phone.setBounds(358, 63, 119, 24);
panel.add(phone);
JLabel label_1_1 = new JLabel("賬戶:");
label_1_1.setBounds(459, 30, 45, 18);
panel.add(label_1_1);
account = new JTextField();
account.setColumns(10);
account.setBounds(511, 26, 120, 24);
panel.add(account);
JLabel label_1_1_1 = new JLabel("密碼:");
label_1_1_1.setBounds(651, 30, 45, 18);
panel.add(label_1_1_1);
password = new JTextField();
password.setColumns(10);
password.setBounds(703, 26, 127, 24);
panel.add(password);
JLabel label_4 = new JLabel("備注:");
label_4.setBounds(35, 113, 72, 18);
panel.add(label_4);
usertime = new JTextArea();
usertime.setBounds(91, 111, 741, 76);
panel.add(usertime);
JPanel panel_2 = new JPanel();
panel_2.setBounds(739, 55, 91, 43);
panel.add(panel_2);
sex = new ButtonGroup ();
panel_2.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
male = new JRadioButton ("男", true);
female = new JRadioButton ("女", false);
sex.add(male);
sex.add(female);
JPanel ButtonPanel=new JPanel();
ButtonPanel.add(male);
ButtonPanel.add(female);
panel_2.add(ButtonPanel);
// panel_2.add(male,BorderLayout.WEST);
// panel_2.add(female,BorderLayout.EAST);
JPanel panel_1 = new JPanel();
panel_1.setBorder(new TitledBorder(null, "條件查詢", TitledBorder.LEADING, TitledBorder.TOP, null, null));
panel_1.setBounds(27, 240, 531, 68);
getContentPane().add(panel_1);
JLabel label_5 = new JLabel("編號:");
panel_1.add(label_5);
searchid = new JTextField();
panel_1.add(searchid);
searchid.setColumns(10);
JButton searchBuut = new JButton("查詢");
panel_1.add(searchBuut);
searchBuut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// 處理滑鼠點擊
userid.setText("");
username.setText("");
account.setText("");
password.setText("");
male.setSelected(true);
idcard.setText("");
phone.setText("");
address.setText("");
usertime.setText("");
String id = searchid.getText();
Object[][] data = select.getUserInfo(id);
df.setDataVector(data, header);
}
});
searchBuut.setIcon(new ImageIcon(AdminUserView.class.getResource("/images/search.png")));
JButton addButt = new JButton("新增用戶");
addButt.setBounds(790, 265, 113, 27);
getContentPane().add(addButt);
JButton updataButt = new JButton("修改資訊");
updataButt.setBounds(659, 265, 113, 27);
getContentPane().add(updataButt);
updataButt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String usex;
if (male.isSelected()) {
usex = "男";
} else {
usex = "女";
}
String sql = "UPDATE users SET username='"+username.getText()+"',account='"+account.getText()+"',`password`='"+password.getText()+"',sex='"+usex+"',idcard='"+idcard.getText()+"',phone='"+phone.getText()+"',address='"+address.getText()+"',usertime='"+usertime.getText()+"' WHERE id='"+userid.getText()+"'";
int addData = updata.addData(sql);
if (addData>0) {
JOptionPane.showMessageDialog(null, "修改成功!");
Object[][] data = select.getUserInfo("");
df.setDataVector(data, header);
} else {
JOptionPane.showMessageDialog(null, "修改失敗!");
}
}
});
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
new AdminView().setVisible(true);
}
});
}
// public static void main(String[] args) {
// new AdminUserView().setVisible(true);
// }
}
⑧ AdminUserViewAdd(水電費管理系統>管理后臺>平臺用戶資訊添加)
package com.ynavc.Vive;
import javax.swing.JFrame;
import com.ynavc.Controller.Updata;
public class AdminUserViewAdd extends JFrame{
public AdminUserViewAdd() {
super("管理員賬戶管理");
this.setBounds(0, 0, 450, 400);
this.setLocationRelativeTo(null);// 讓視窗在螢屏中間顯示
this.setResizable(false);// 讓視窗大小不可改變
getContentPane().setLayout(null);
Updata updata = new Updata();
}
public static void main(String[] args) {
}
}
⑨ AdminView(管理員后臺主界面)
package com.ynavc.Vive;
import javax.swing.JFrame;
import com.ynavc.Controller.Updata;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import java.awt.Color;
import javax.swing.SwingConstants;
public class AdminView extends JFrame{
static AdminUserView adminUserView = new AdminUserView();
static AdminSysView adminSysView = new AdminSysView();
static AdminFeeView adminFeeView = new AdminFeeView();
public AdminView() {
super("水電費管理系統--管理員后臺");
getContentPane().setFont(new Font("宋體", Font.PLAIN, 35));
Updata updata = new Updata();
this.setBounds(0, 0, 760, 400);
this.setLocationRelativeTo(null);// 讓視窗在螢屏中間顯示
this.setResizable(false);
getContentPane().setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 用戶單擊視窗的關閉按鈕時程式執行的操作
JLabel lblxxx = new JLabel("你好,管理員 ,歡迎使用水電費管理系統");
lblxxx.setFont(new Font("宋體", Font.PLAIN, 35));
lblxxx.setBounds(44, 35, 726, 91);
getContentPane().add(lblxxx);
JButton button = new JButton("用戶資訊管理");
button.setFont(new Font("宋體", Font.BOLD, 20));
button.setBounds(80, 192, 166, 59);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
adminUserView.setVisible(true);
dispose();
}
});
getContentPane().add(button);
JButton button_1 = new JButton("水電費管理");
button_1.setFont(new Font("宋體", Font.BOLD, 20));
button_1.setBounds(292, 192, 166, 59);
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
adminFeeView.setVisible(true);
dispose();
}
});
getContentPane().add(button_1);
JButton button_1_1 = new JButton("管理賬戶管理");
button_1_1.setFont(new Font("宋體", Font.BOLD, 20));
button_1_1.setBounds(515, 192, 166, 59);
button_1_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
adminSysView.setVisible(true);
dispose();
}
});
getContentPane().add(button_1_1);
// String username = "系統管理員";
// if (UserLogin.getUsername()!=null) {
// username = UserLogin.getUsername();
// }
System.out.println("41534"+username);
// if (!username.equals("")) {
// lblNewLabel.setText(username);
// }
}
public static AdminSysView getAdminSysView() {
return adminSysView;
}
public static AdminFeeView getAdminFeeView() {
return adminFeeView;
}
// public static void main(String[] args) {
// new AdminView().setVisible(true);
// }
}
⑩ Registered(用戶注冊界面)
package com.ynavc.Vive;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import com.ynavc.Controller.Updata;
public class Registered extends JFrame {
private JTextField username;
private JTextField password;
private JTextField textField;
public Registered() {
super("用戶注冊");
Updata updata = new Updata();
this.setBounds(0, 0, 600, 350);
this.setLocationRelativeTo(null);// 讓視窗在螢屏中間顯示
this.setResizable(false);// 讓視窗大小不可改變
getContentPane().setLayout(null);
JLabel usernameText = new JLabel("賬號:");
usernameText.setBounds(142, 36, 72, 18);
getContentPane().add(usernameText);
username = new JTextField();
username.setBounds(228, 33, 203, 24);
getContentPane().add(username);
username.setColumns(10);
JLabel passwordText = new JLabel("密碼:");
passwordText.setBounds(142, 96, 72, 18);
getContentPane().add(passwordText);
password = new JPasswordField();
password.setColumns(10);
password.setBounds(228, 93, 203, 24);
getContentPane().add(password);
JButton regButton = new JButton("確認注冊");
regButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String uname = username.getText();
String pwd = password.getText();
if (uname.equals("") && pwd.equals("")) {
JOptionPane.showMessageDialog(null, "賬戶名或密碼未填寫!");
} else {
if (pwd.equals(textField.getText())) {
String sql = "INSERT INTO users (username,`password`) VALUES('" + uname + "','" + pwd + "')";
int reselt = updata.addData(sql);
if (reselt > 0) {
JOptionPane.showMessageDialog(null, "注冊成功!請登錄!");
new UserLogin().setVisible(true);
dispose();
} else {
JOptionPane.showMessageDialog(null, "注冊失敗!");
}
} else {
JOptionPane.showMessageDialog(null, "兩次密碼不一致請重新輸入!");
}
}
}
});
regButton.setBounds(243, 222, 113, 27);
getContentPane().add(regButton);
ImageIcon icon = new ImageIcon("src/img/background.jpg");
JLabel passwordText_1 = new JLabel("確認密碼:");
passwordText_1.setBounds(119, 148, 95, 18);
getContentPane().add(passwordText_1);
textField = new JPasswordField();
textField.setColumns(10);
textField.setBounds(228, 145, 203, 24);
getContentPane().add(textField);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
// 加入動作
// UserLogin.getUserLoin().setVisible(true);
}
});
}
}
? UserFeeView(用戶收費資訊查詢界面)
package com.ynavc.Vive;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import com.ynavc.Controller.Select;
import com.ynavc.Controller.Updata;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import java.awt.Color;
import java.awt.FileDialog;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JButton;
public class UserFeeView extends JFrame {
JTable jtable;
Select select = new Select();
Updata updata = new Updata();
Object[] header = { "訂單號", "戶主", "用水分類", "水費單價", "水費總量", "本月水費", "用電型別", "電費單價", "電總量", "本月電費", "年份", "月份", "應繳納費用",
"收費時間", "開票人", "備注" };
Object[][] data = null;
DefaultTableModel df = null;
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
public UserFeeView(String id) {
super("水電費管理系統--用戶水電費查詢");
Updata updata = new Updata();
this.setBounds(0, 0, 1235, 500);
this.setLocationRelativeTo(null);// 讓視窗在螢屏中間顯示
this.setResizable(false);
getContentPane().setLayout(null);
data = select.getFeeInfoByMonth(id, "", "");
df = new DefaultTableModel(data, header);
jtable = new JTable(df);// 創建表格
jtable.getTableHeader().setFont(new Font(null, Font.BOLD, 14)); // 設定表頭名稱字體樣式
jtable.getTableHeader().setForeground(Color.black); // 設定表頭名稱字體顏色
// jTable.getTableHeader().setResizingAllowed(false); // 設定不允許手動改變列寬
jtable.getTableHeader().setReorderingAllowed(false);// 設定表頭不允許拖動
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;// 水平滾動條
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;// 垂直滾動條
JScrollPane jsp = new JScrollPane(jtable, v, h);
jsp.setBounds(26, 105, 1178, 331);
getContentPane().add(jsp);
JPanel panel = new JPanel();
panel.setBorder(new TitledBorder(null, "條件查詢", TitledBorder.LEADING, TitledBorder.TOP, null, null));
panel.setBounds(26, 13, 340, 78);
getContentPane().add(panel);
JLabel label_1 = new JLabel("年份:");
panel.add(label_1);
JComboBox comboBox = new JComboBox();
panel.add(comboBox);
for (int i = 2016; i < 2026; i++) {
comboBox.addItem(i + "年");
}
JLabel label_2 = new JLabel("月份");
panel.add(label_2);
JComboBox comboBox_1 = new JComboBox();
panel.add(comboBox_1);
for (int i = 1; i <= 12; i++) {
comboBox_1.addItem(i + "月");
}
comboBox.setSelectedItem("2021年");
comboBox_1.setSelectedItem("7月");
JButton button = new JButton("查詢");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String years = comboBox.getItemAt(comboBox.getSelectedIndex()).toString();
String mouth = comboBox_1.getItemAt(comboBox_1.getSelectedIndex()).toString();
Object[][] data = select.getFeeInfoByMonth(id, years, mouth);
df.setDataVector(data, header);
}
});
panel.add(button);
// // 創建表模型
// df = new DefaultTableModel(data, header) {
// // 設定表格內容不可被編輯
// public boolean isCellEditable(int row, int column) {
// return false;// 回傳true表示能編輯,false表示不能編輯
// }
// };
JButton btnexcel = new JButton("匯出資料導Excel");
btnexcel.setBounds(1057, 47, 147, 27);
getContentPane().add(btnexcel);
JButton btnNewButton = new JButton("顯示全部");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Object[][] data = select.getFeeInfo("");
df.setDataVector(data, header);
}
});
btnNewButton.setBounds(909, 47, 113, 27);
getContentPane().add(btnNewButton);
btnexcel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButtonActionPerformed(e);
}
});
// 設定單元格內容居中顯示
DefaultTableCellRenderer r = new DefaultTableCellRenderer();
r.setHorizontalAlignment(JLabel.CENTER);
jtable.setDefaultRenderer(Object.class, r);
// Object[][] data = select.getAdminInfo();
df.setDataVector(data, header);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
new UserLogin().setVisible(true);
// 加入動作
// GoodsManagement m = new GoodsManagement();
// m.setVisible(true);
}
});
}
// 匯出
private void jButtonActionPerformed(java.awt.event.ActionEvent evt) {
FileDialog fd = new FileDialog(this, "將資料保存到", FileDialog.SAVE);
fd.setLocation(1100, 600);
fd.setVisible(true);
String stringfile = fd.getDirectory() + fd.getFile() + ".xlsx";
try {
this.exportTable(jtable, new File(stringfile));
} catch (IOException ex) {
ex.printStackTrace();
}
}
/** 匯出JTable到excel */
public void exportTable(JTable table, File file) throws IOException {
TableModel model = table.getModel();
BufferedWriter bWriter = new BufferedWriter(new FileWriter(file));
for (int i = 0; i < model.getColumnCount(); i++) {
bWriter.write(model.getColumnName(i));
bWriter.write("\t");
}
bWriter.newLine();
for (int i = 0; i < model.getRowCount(); i++) {
for (int j = 0; j < model.getColumnCount(); j++) {
bWriter.write(model.getValueAt(i, j).toString());
bWriter.write("\t");
}
bWriter.newLine();
}
bWriter.close();
}
// public static void main(String[] args) {
// new UserFeeView("1").setVisible(true);
// }
}
? UserLogin(登錄界面)
package com.ynavc.Vive;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.UnsupportedLookAndFeelException;
import com.ynavc.Controller.Select;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Toolkit;
import javax.swing.JPasswordField;
import javax.swing.JCheckBox;
public class UserLogin extends JFrame {
Registered registered = new Registered();
static {
try {
// 這里是皮膚包可以隨意切換
javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel");
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.smart.SmartLookAndFeel");
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.luna.LunaLookAndFeel");
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.aluminium.AluminiumLookAndFeel");
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.bernstein.BernsteinLookAndFeel");
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.hifi.HiFiLookAndFeel");
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.aero.AeroLookAndFeel");
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.mint.MintLookAndFeel");
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
| UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
}
String uid;
private static JTextField username;
private JTextField password;
JCheckBox chckbxNewCheckBox;
public UserLogin() {
super("用戶登錄");
Select select = new Select();
this.setBounds(0, 0, 600, 350);
this.setLocationRelativeTo(null);// 讓視窗在螢屏中間顯示
this.setResizable(false);// 讓視窗大小不可改變
getContentPane().setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 用戶單擊視窗的關閉按鈕時程式執行的操作
this.setIconImage(Toolkit.getDefaultToolkit().getImage(UserLogin.class.getResource("/images/logo.png")));
JLabel usernameText = new JLabel("賬號:");
usernameText.setBounds(142, 70, 72, 18);
usernameText.setIcon(new ImageIcon(UserLogin.class.getResource("/images/userName.png")));
getContentPane().add(usernameText);
username = new JTextField();
username.setBounds(228, 67, 203, 24);
getContentPane().add(username);
username.setColumns(10);
JLabel passwordText = new JLabel("密碼:");
passwordText.setIcon(new ImageIcon(UserLogin.class.getResource("/images/password.png")));
passwordText.setBounds(142, 138, 72, 18);
getContentPane().add(passwordText);
password = new JPasswordField();
password.setColumns(10);
password.setBounds(228, 135, 203, 24);
getContentPane().add(password);
JButton logButton = new JButton("登錄");
logButton.setIcon(new ImageIcon(UserLogin.class.getResource("/images/login.png")));
logButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String uname = username.getText();
String pwd = password.getText();
if (chckbxNewCheckBox.isSelected()) {
if (uname.equals("") && pwd.equals("")) {
JOptionPane.showMessageDialog(null, "賬戶名或密碼未填寫!");
} else {
String sql = "select COUNT(*) from admin where account='" + uname + "' and password='" + pwd
+ "'";
int reselt = select.userloginSelect(sql);
if (reselt > 0) {
JOptionPane.showMessageDialog(null, "登錄成功!歡迎使用!");
new AdminView().setVisible(true);
dispose();
} else {
JOptionPane.showMessageDialog(null, "登錄失敗!賬戶名或密碼不正確!請重新輸入!");
}
}
} else {
if (uname.equals("") && pwd.equals("")) {
JOptionPane.showMessageDialog(null, "賬戶名或密碼未填寫!");
} else {
String sql = "select COUNT(*) from users where account='" + uname + "' and password='" + pwd
+ "'";
int reselt = select.userloginSelect(sql);
if (reselt > 0) {
sql = "select id from users where account='" + uname + "' and password='" + pwd
+ "'";
uid = String.valueOf(select.userloginSelect(sql));
// String namesql = "select name from users where id="+uid;
// select.get
JOptionPane.showMessageDialog(null, "登錄成功!歡迎使用!");
new UserFeeView(uid).setVisible(true);
dispose();
} else {
JOptionPane.showMessageDialog(null, "登錄失敗!賬戶名或密碼不正確!請重新輸入!");
}
}
}
}
});
logButton.setBounds(318, 228, 113, 27);
getContentPane().add(logButton);
JButton regButton = new JButton("重置");
regButton.setIcon(new ImageIcon(UserLogin.class.getResource("/images/reset.png")));
regButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
username.setText("");
password.setText("");
}
});
regButton.setBounds(142, 228, 113, 27);
getContentPane().add(regButton);
chckbxNewCheckBox = new JCheckBox("管理員登錄");
chckbxNewCheckBox.setBounds(331, 180, 118, 27);
getContentPane().add(chckbxNewCheckBox);
}
// public static String getUsername() {
// if (username.getText().equals("")) {
// return username.getText();
// }
// return "系統管理員";
// }
public static void main(String[] args) {
new UserLogin().setVisible(true);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/290639.html
標籤:java
