java考勤管理系统数据库实现
4.2设计代码
J a v a源程序:
i m p o r t j a v a.a w t.*;
i m p o r t j a v a.a w t.e v e n t.*;
i m p o r t j a v a x.s w i n g.*;
i m p o r t j a v a.a w t.*;
i m p o r t j a v a.s q l.*;
i m p o r t j a v a.l a n g.*;
i m p o r t j a v a.u t i l.*;
i m p o r t j a v a x.s w i n g.t a b l e.*;
i m p o r t j a v a.m a t h.*;
c l a s s D B_L S i m p l e m e n t s A c t i o n L i s t e n e r{
J F r a m e f r a m e=n e w J F r a m e("欢迎进入L S工资管理系统");
J L a b e l l a b e l=n e w J L a b e l("09网络2_54_李胜",J L a b e l.C E N T E R); J B u t t o n b u t t o n1=n e w J B u t t o n("进入系统");
J B u t t o n b u t t o n2=n e w J B u t t o n("退出系统");
I m a g e I c o n i m=n e w I m a g e I c o n("1.j p g");
J L a b e l a1=n e w J L a b e l(i m);
v o i d C r e a t e(){
J P a n e l p c o n t e n t P a n e=(J P a n e l)f r a m e.g e t C o n t e n t P a n e();
J P a n e l p c o n t e n t P a n e1=n e w J P a n e l();
p c o n t e n t P a n e.a d d(l a b e l);
p c o n t e n t P a n e.s e t L a y o u t(n e w F l o w L a yo u t());
p c o n t e n t P a n e.a d d(b u t t o n1);
p c o n t e n t P a n e.a d d(b u t t o n2);
p c o n t e n t P a n e.a d d(n e w L a b e l(""));
p c o n t e n t P a n e.a d d(a1);
p c o n t e n t P a n e.s e t B a c k g r o u n d(C o l o r.g r e e n);
p c o n t e n t P a n e.s e t V i s i b l e(t r u e);
b u t t o n1.a d d A
c t i o n L i s t e n e r(t h i s);
b u t t o n2.a d d A
c t i o n L i s t e n e r(t h i s);
f r a m e.s e t D e f a u l t C l o s e O p e r a t i o n(J F r a m e.E X I T_O N_C L O S E);
f r a m e.p a c k();
f r a m e.s e t Bo u n d s(200,100,550,600);
f r a m e.s e t V i s i b l e(t r u e);
}
p u b l i c s t a t i c v o i d m a i n(S t r i n g[]a r g s){
D B_L S d o m e=n e w D B_L S();
d o m e.C r
e a t e();
}
p u b l i c v o i d a c t i o n P e r f o r m e d(A c t i o n E v e n t e){
i f(b u t t o n1.e q u a l s(e.g e t S o u r c e())){
D L d l=n e w D L();
d l.c r
e a t e();
}
i f(b u t t o n2.e q u a l s(e.g e t S o u r c e())){//退出
S y s t e m.e x i t(0);
}
}
}
c l a s s D L i m p l e m e n t s A c t i o n L i s t e n e r{
J F r a m e f r a m e=n e w J F r a m e("职工/管理员登陆");
J L a b e l l a b e l1=n e w J L a b e l("用户名");
J L a b e l l a b e l2=n e w J L a b e l("密码");
J B u t t o n l o g o n Bu t t o n1=n e w J B u t t o n("管理员登录");
J B u t t o n l o g o n Bu t t o n2=n e w J B u t t o n("职工登录");
J B u t t o n c a n c e l B u t t o n=n e w J B u t t o n("退出");
J T e x t F i e l d t1=n e w J T e x t F i e l d(0);
J T e x t F i e l d t2=n e w J T e x t F i e l d(0);
I m a g e I c o n i m=n e w I m a g e I c o n("2.j p g");
J L a b e l a2=n e w J L a b e l(i m);
J T e x t F i e l d u s e r n a m e=n e w J T e x t F i e l d(9);
J P a s s w o r d F i e l d p a s s w o r d=n e w J P a s s w o r d F i e l d(9); v o i d c r e a t e(){
J P a n e l p=(J P a n e l)f r a m e.g e t C o n t e n t P a n e();
J P a n e l p1=n e w J P a n e l();
p.s e t L a y o u t(n e w F l o w L a y o u t());
p.a d d(l a b e l1);
p.s e t S i z e(5,5);
p.s e t L o c a t i o n(4,8);
p.a d d(u s e r n a m e);
p.s e t S i z e(100,200);
p.s e t L o c a t i o n(800,800);
p.a d d(l a b e l2);
p.s e t S i z e(50,20);
p.s e t L o c a t i o n(40,80);
p.a d d(p a s s w o r d);
p.s e t S i z e(100,20);
p.s e t L o c a t i o n(80,120);
p.a d d(l o g o n B u t t o n1);
p.a d d(n e w J L a b e l(""));
p.a d d(l o g o n B u t t o n2);
p.a d d(n e w J L a b e l(""));
p.a d d(c a n c e l B u t t o n);
p.a d d(n e w J L a b e l(""));
p.a d d(a2);
p.a d d(t1);
p.a d d(t2);
p.s e t B a c k g r o u n d(C o l o r.b l u e);
p.s e t V i s i b l e(t r u e);
l o g o n B u t t o n1.a d d A c t i o n L i s t e n e r(t h i s);
l o g o n B u t t o n2.a d d A c t i o n L i s t e n e r(t h i s);
c a n c e l B u t t o n.a
d d A c t i o n L i s t
e n e r(t h i s);
f r a m e.s e t D e f a u l t C l o s e O p e r a t i o n(J F r a m e.E X I T_O N_C L O S E);
f r a m e.p a c k();
f r a m e.s e t B o u n d s(200,100,750,550);
f r a m e.s e t V i s i b l e(t r u e);
}
p u b l i c v o i d a c t i o n P e r f o r m e d(A c t i o n E v e n t e){
i f(l o g o n B u t t o n1.e q u a l s(e.g e t S o u r c e())&&(u s e r n a m e.g e t T e x t().e q u a l s("123")==t r u e)&&(p a s s w o r d.g e t T e x t().e q u a l s("123")==t r u e)){
G Z G L Z J M g z=n e w G Z G L Z J M();
g z.c r e a t e();
}
e l s e{J O p t i o n P a n e.s h o w M e s s a g e D i a l o g(n u l l,"对不起,你输入的密码错误!");
};
i f(l o g o n B u t t o n2.e q u a l s(e.g e t S o u r c e())&&(u s e r n a m e.g e t T e x t().e q u a l s(t1.g e t T e x t())==t r u e)&&(p a s s w o r d.g e t T e x t().e q u a l s(t2.g e t T e x t())==t r u e)){
X K x k=n e w X K();
x k.c r e a t e();
C o n n e c t i o n c o n;
S t a t e m e n t s q l;
R e s u l t S e t r s;
V e c t o r v e c t o r=n e w V e c t o r();
t r y{
C l a s s.f o r N a m e("s u n.j d b c.o d b c.J d b c O d b c
D r i v e r");
}c a t c h(C l a s s N o t F o u n d E x c e p t i o n e1){
S y s t e m.o u t.p r i n t l n(""+e1);
}
t r y{
c o n=D r i v e r M a n a g e r.g e t C o n n e c t i o n("j
d b c:o d b c:123","","");
s q l= c o n.c r e a t e S t a t e m e n t(R e s u l t S e t.T Y P E_S C R O L L_S E N S I T I V E,R e s u l t S e t.C O N C U R_R E A D_O N L Y);
s q l.e x e c u t e Q u e r y("S E L E C T G n o,m m F R O M Y W H E R E G n o="+t1.g e t T e x t()+"A N D m m="+t2.g e t T e x t());
}c a t c h(S Q L E x c e p t i o n e1){
S y s t e m.o u t.p r i n t l n(e1);
}
}
i f(c a n c e l B u t t o n.e q u a l s(e.g e t S o u r c e())){
S y s t e m.e x i t(0);
}
}
}
c l a s s G Z G L Z J M e x t e n
d s J F r a m
e i m p l e m e n t s A c t i o n L i s t e n e r{
J F r a m e f=n e w J F r a m e("工资管理系统");
J B u t t o n b1=n e w J B u t t o n("津贴管理");
J B u t t o n b2=n e w J B u t t o n("总查询");
J B u t t o n b3=n e w J B u t t o n("工资管理");
J B u t t o n b4=n e w J B u t t o n("后勤管理");
J B u t t o n b6=n e w J B u t t o n("员工个人信息管理");
J B u t t o n b5=n e w J B u t t o n("返回");
I m a g e I c o n i m=n e w I m a g e I c o n("3.j p g");
J L a b e l a3=n e w J L a b e l(i m);
v o i d c r e a t e(){
J P a n e l p=(J P a n e l)f.g e t C o n t e n t P a n e();
J P a n e l p1=n e w J P a n e l();
p.s e t L a y o u t(n e w F l o w L a y o u t());
p.a d d(b1);
p.a d d(n e w J L a b e l(""));
p.a d d(b6);
p.a d d(n e w J L a b e l(""));
p.a d d(b3);
p.a d d(n e w J L a b e l(""));
p.a d d(b4);
p.a d d(n e w J L a b e l(""));
p.a d d(b2);
p.a d d(n e w J L a b e l(""));
p.a d d(b5);
p.a d d(a3);
p.s e t B a c k g r o u n d(C o l o r.r e d);
p.s e t V i s i b l e(t r u e);
b1.a d d A c t i o n L i s t e n e r(t h i s);
b2.a d d A c t i o n L i s t e n e r(t h i s);
b3.a d d A c t i o n L i s t e n e r(t h i s);
b4.a d d A c t i o n L i s t e n e r(t h i s);
b5.a d d A c t i o n L i s t e n e r(t h i s);
b6.a d d A c t i o n L i s t e n e r(t h i s);
f.s e t B o u n d s(200,100,800,600);
f.s e t V i s i b l e(t r u e);
}
p u b l i c v o i d a c t i o n P e r f o r m e d(A c t i o n E v e n t e){
i f(b5.e q u a l s(e.g e t S o u r c e())){//返回
D L d=n e w D L();
f.d i s p o s e();
}
i f(b1.e q u a l s(e.g e t S o u r c e())){//津贴管理
J T G L j t=n e w J T G L();
j t.c r e a t e();
}
i f(b6.e q u a l s(e.g e t S o u r c e())){//员工个人信息管理
Y G G L y g=n e w Y G G L();
y g.c r e a t e();
}
i f(b2.e q u a l s(e.g e t S o u r c e())){//查询
X K x k=n e w X K();
x k.c r e a t e();
}
i f(b4.e q u a l s(e.g e t S o u r c e())){//后勤管理
K Q G L k q=n e w K Q G L();
k q.c r e a t e();
}
i f(b3.e q u a l s(e.g e t S o u r c e())){//工资管理
G Z G L g z=n e w G Z G L();
g z.c r e a t e();
}
}
}
c l a s s K Q G L i m p l e m e n t s A c t i o n L i s t e n e r{
J F r a m e f=n e w J F r a m e("录入修改删除考勤信息");
J B u t t o n b1=n e w J B u t t o n("录入");
J B u t t o n b2=n e w J B u t t o n("修改");
J B u t t o n b3=n e w J B u t t o n("删除");
J B u t t o n b4=n e w J B u t t o n("查询所有");
J B u t t o n b5=n e w J B u t t o n("返回");
J T e x t F i e l d t f1=n e w J T e x t F i e l d(4);
J T e x t F i e l d t f2=n e w J T e x t F i e l d(4);
J T e x t F i e l d t f3=n e w J T e x t F i e l d(4);
J T e x t F i e l d t f4=n e w J T e x t F i e l d(4);
J T e x t F i e l d t f5=n e w J T e x t F i e l d(6);
J B u t t o n b6=n e w J B u t t o n("查询单人考勤");
S t r i n g[]c l o u m={"职工号","缺勤天数","缺勤类别","缺勤时间"};
O b j e c t[][]r o w=n e w O b j e c t[50][4];
J T a b l e t a b l e=n e w J T a b l e(r o w,c l o u m);
J S c r o l l P a n e s c r o l l p a n e=n e w J S c r o l l P a n e(t a b l e);
J S p l i t P a n e s p l i t p a n e=n e w J S p l i t P a n e(J S p l i t P a n e.V E R T I C A L_S P L I T);
v o i d c r e a t e()
{
J P a n e l p=(J P a n e l)f.g e t C o n t e n t P a n e();
p.s e t L a y o u t(n e w F l o w L a yo u t());
//p.a d d(s c r o l l p a n e);
p.a d d(s p l i t p a n e);
J P a n e l p1=n e w J P a n e l();
p1.a d d(b1);
p1.a d d(b2);
p1.a d d(b3);
p1.a d d(b4);
p1.a d d(b6);
p1.a d d(b5);
J P a n e l p2=n e w J P a n e l();
p2.s e t B a c k g r o u n d(C o l o r.r e d);
p2.a d d(s c r o l l p a n e);
J P a n e l p3=n e w J P a n e l();
p.s e t L a y o u t(n e w F l o w L a y o u t());
p.a d d(n e w J L a b e l(""));
p.a d d(n e w J L a b e l("职工号"));
p.a d d(t f1);
p.a d d(n e w J L a b e l("缺勤天数"));
p.a d d(t f2);
p.a d d(n e w J L a b e l("缺勤类别"));
p.a d d(t f3);
p.a d d(n e w J L a b e l(""));
p.a d d(n e w J L a b e l("缺勤时间"));
p.a d d(t f4);
p.a d d(n e w J L a b e l("在此处输入职工号点击查询删除")); p.a d d(t f5);
s p l i t p a n e.a d d(p1,s p l i t p a n e.T O P);
s p l i t p a n e.a d d(p2,s p l i t p a n e.BO T T O M);
s p l i t p a n e.s e t D i v i d e r L o c a t i o n(50);
p.s e t B a c k g r o u n d(C o l o r.C Y A N);
b1.a d d A c t i o n L i s t e n e r(t h i s);
b2.a d d A c t i o n L i s t e n e r(t h i s);
b3.a d d A c t i o n L i s t e n e r(t h i s);
b4.a d d A c t i o n L i s t e n e r(t h i s);
b5.a d d A c t i o n L i s t e n e r(t h i s);
b6.a d d A c t i o n L i s t e n e r(t h i s);
f.s e t B o u n d s(200,100,500,600);
f.s e t R e s i z a b l e(t r u e);//可以调整界面大小
f.s e t V i s i b l e(t r u e);
}
p u b l i c v o i d a c t i o n P e r f o r m e d(A c t i o n E v e n t e){
i f(b1.e q u a l s(e.g e t S o u r c e())){//添加
C o n n e c t i o n c o n;
S t a t e m e n t s q l;
R e s u l t S e t r s;
t r y{
C l a s s.f o r N a m e("s u n.j d b c.o d b c.J d b c O d b c
D r i v e r");
}c a t c h(C l a s s N o t F o u n d E x c e p t i o n e1){
S y s t e m.o u t.p r i n t l n(""+e1);
}
t r y{
c o n=D r i v e r M a n a g e r.g e t C o n n e c t i o n("j
d b c:o d b c:123","","");
s q l=c o n.c r e a t e S t a t e m e n t();
S t r i n g i n s e r t S t r="I N S E R T I N T O K V A L U E S"+"("+"'"+t f1.g e t T e x t()+"'"+","+ t f2.g e t T e x t()+","+"'"+t f3.g e t T e x t()+"'"+","+t f4.g e t T e x t()+")";
s q l.e x e c u t e U p d a t e(i n s e r t S t r);
c o n.c l o s e();
}c a t c h(S Q L E x c e p t i o n e1){
S y s t e m.o u t.p r i n t l n(e1);
}
}
i f(b2.e q u a l s(e.g e t S o u r c e())){//修改
C o n n e c t i o n c o n;
S t a t e m e n t s q l;
R e s u l t S e t r s;
t r y{
C l a s s.f o r N a m e("s u n.j d b c.o d b c.J d b c O d b c
D r i v e r");
}c a t c h(C l a s s N o t F o u n d E x c e p t i o n e1){
S y s t e m.o u t.p r i n t l n(""+e1);
}
t r y{
c o n=D r i v e r M a n a g e r.g e t C o n n e c t i o n("j
d b c:o d b c:123","","");
s q l=c o n.c r e a t e S t a t e m e n t();
s q l.e x e c u t e U p d a t e("U P D A T E K S E T t s="+t f2.g e t T e x t()+"W H E R E K n o="+t f1.g e t T e x t()+"");
s q l.e x e c u t e U p d a t e("U P D A T E K S E T l b="+t f3.g e t T e x t()+"W H E R E K n o="+t f1.g e t T e x t()+"");
s q l.e x e c u t e U p d a t e("U P D A T E K S E T s j="+t f4.g e t T e x t()+"W H E R E K n o="+t f1.g e t T e x t()+"");
c o n.c l o s e();
}c a t c h(S Q L E x c e p t i o n e1){
S y s t e m.o u t.p r i n t l n(e1);
}
}
i f(b3.e q u a l s(e.g e t S o u r c e())){//删除
C o n n e c t i o n c o n;
S t a t e m e n t s q l;
R e s u l t S e t r s;
t r y{
C l a s s.f o r N a m e("s u n.j d b c.o d b c.J d b c O d b c
D r i v e r");
}c a t c h(C l a s s N o t F o u n d E x c e p t i o n e1){
S y s t e m.o u t.p r i n t l n(""+e1);
}
t r y{
c o n=D r i v e r M a n a g e r.g e t C o n n e c t i o n("j
d b c:o d b c:123","","");
s q l= c o n.c r e a t e S t a t e m e n t(R e s u l t S e t.T Y P E_S C R O L L_S E N S I T I V E,R e s u l t S e t.C O N C U R_R E A D_O N L Y);
s q l.e x e c u t e U p d a t e("D E L E T E F R O M K W H E R E K n o="+t f5.g e t T e x t());
c o n.c l o s e();
}c a t c h(S Q L E x c e p t i o n e1){
S y s t e m.o u t.p r i n t l n(e1);
}
}
i f(b4.e q u a l s(e.g e t S o u r c e())){//查询全部
C o n n e c t i o n c o n;
S t a t e m e n t s q l;
R e s u l t S e t r s;
V e c t o r v e c t o r=n e w V e c t o r();
t r y{
C l a s s.f o r N a m e("s u n.j d b c.o d b c.J d b c O d b c
D r i v e r");
}c a t c h(C l a s s N o t F o u n d E x c e p t i o n e1){
S y s t e m.o u t.p r i n t l n(""+e1);
}
t r y{
c o n=D r i v e r M a n a g e r.g e t C o n n e c t i o n("j
d b c:o d b c:123","s a","");
s q l= c o n.c r e a t e S t a t e m e n t(R e s u l t S e t.T Y P E_S C R O L L_S E N S I T I V E,R e s u l t S e t.C O N C U R_R E A D_O N L Y);
i f(b4.e q u a l s(e.g e t S o u r c e())){
f o r(i n t i=0;i<50;i++)
f o r(i n t j=0;j<4;j++)
t a b l e.s e t V a l u e A t("",i,j);
r s=s q l.e x e c u t e Q u e r y("S E L E C T*F R O M K O R D E R B Y K n o D E S C");
i n t k=-1;
w h i l e(r s.n e x t()){
++k;
S t r i n g K n o=r s.g e t S t r i n g(1);
S t r i n g t s=r s.g e t S t r i n g(2);
S t r i n g l b=r s.g e t S t r i n g(3);
S t r i n g s j=r s.g e t S t r i n g(4);
t a b l e.s e t V a l u e A t(K n o,k,0);
t a b l e.s e t V a l u e A t(t s,k,1);
t a b l e.s e t V a l u e A t(l b,k,2);
t a b l e.s e t V a l u e A t(s j,k,3);
}
}
}c a t c h(S Q L E x c e p t i o n e1){
S y s t e m.o u t.p r i n t l n(e1);
}
}
i f(b6.e q u a l s(e.g e t S o u r c e())){//查询关键字
C o n n e c t i o n c o n;
S t a t e m e n t s q l;
R e s u l t S e t r s;
V e c t o r v e c t o r=n e w V e c t o r();
t r y{
C l a s s.f o r N a m e("s u n.j d b c.o d b c.J d b c O d b c
D r i v e r");
}c a t c h(C l a s s N o t F o u n d E x c e p t i o n e1){
S y s t e m.o u t.p r i n t l n(""+e1);
}
t r y{
c o n=D r i v e r M a n a g e r.g e t C o n n e c t i o n("j
d b c:o d b c:123","s a","");
s q l= c o n.c r e a t e S t a t e m e n t(R e s u l t S e t.T Y P E_S C R O L L_S E N S I T I V E,R e s u l t S e t.C O N C U R_R E A D_O N L Y);
i f(b6.e q u a l s(e.g e t S o u r c e())){
f o r(i n t i=0;i<50;i++)
f o r(i n t j=0;j<4;j++)
t a b l e.s e t V a l u e A t("",i,j);
r s=s q l.e x e c u t e Q u e r y("S E L E C T*F R O M K W H E R E K n o="+t f5.g e t T e x t());
i n t k=-1;
w h i l e(r s.n e x t()){
++k;
S t r i n g K n o=r s.g e t S t r i n g(1);
S t r i n g t s=r s.g e t S t r i n g(2);
S t r i n g l b=r s.g e t S t r i n g(3);
S t r i n g s j=r s.g e t S t r i n g(4);
t a b l e.s e t V a l u e A t(K n o,k,0);
t a b l e.s e t V a l u e A t(t s,k,1);
t a b l e.s e t V a l u e A t(l b,k,2);
t a b l e.s e t V a l u e A t(s j,k,3);
}
}
}c a t c h(S Q L E x c e p t i o n e1){
S y s t e m.o u t.p r i n t l n(e1);
}
}
i f(b5.e q u a l s(e.g e t S o u r c e())){//返回
D L d l=n e w D L();
f.d i s p o s e();
}
}
}