-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathFrmCreateUser.java
More file actions
121 lines (108 loc) · 3.4 KB
/
FrmCreateUser.java
File metadata and controls
121 lines (108 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package hms;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class FrmCreateUser extends JFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;
JLabel title,lblUser,lblPass,lblRetype,welcome,lblType;
JComboBox<String> jcbType;
JTextField jtfUser;
JPasswordField jpfPass,jpfRetype;
JButton btnCreate;
String arr[]={"admin","operator","doctor"};
FrmCreateUser()
{
super("User Registration");
setLayout(null);
setIconImage(new ImageIcon("images/HMS_logo.jpg").getImage());
getContentPane().setBackground(Color.white);
setTitle("Registration");
welcome=new JLabel(new ImageIcon("images/hms_banner.jpg"));
welcome.setBounds(250,150,800,100);
add(welcome);
title=new JLabel(new ImageIcon("images/register.jpg"));
title.setBounds(500,300,400,60);
add(title);
lblType=new JLabel("User Type");
lblType.setBounds(500, 380, 140, 25);
add(lblType);
jcbType=new JComboBox<>(arr);
jcbType.setBounds(600,380,130,25);
add(jcbType);
lblUser=new JLabel("User Name");
lblUser.setBounds(500,420,140,25);
add(lblUser);
jtfUser=new JTextField();
jtfUser.requestFocus();
jtfUser.setBounds(600,420,130,25);
add(jtfUser);
lblPass=new JLabel("Password");
lblPass.setBounds(500,460,140,25);
add(lblPass);
jpfPass=new JPasswordField();
jpfPass.setBounds(600,460,130,25);
add(jpfPass);
lblRetype=new JLabel("ReType");
lblRetype.setBounds(500,500,140,25);
add(lblRetype);
jpfRetype=new JPasswordField();
jpfRetype.setBounds(600,500,140,25);
add(jpfRetype);
btnCreate=new JButton("Register");
btnCreate.setBounds(500,540,100,30);
btnCreate.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
String type=(String)jcbType.getSelectedItem();
String user=jtfUser.getText();
String pass=new String(jpfPass.getPassword());
String retype=new String(jpfRetype.getPassword());
if(type.isEmpty() || user.isEmpty() || pass.isEmpty() || retype.isEmpty())
JOptionPane.showMessageDialog(null,"All Fields Are Mandatry To Fill","Error",JOptionPane.ERROR_MESSAGE);
else if(!(pass.length()>=8 && pass.length()<=15))
JOptionPane.showMessageDialog(null,"Password Should be 8 to 15 Characters Long","Error",JOptionPane.ERROR_MESSAGE);
else if(!pass.equals(retype))
JOptionPane.showMessageDialog(null,"Password and Re Type must match","Error",JOptionPane.ERROR_MESSAGE);
else
{
DConnection dc=new DConnection();
dc.executeOther("insert into users values('"+user+"','"+pass+"','"+type+"')");
dispose();
String s="Welcome "+type+"! Your Id Is "+user+" and Password is "+pass;
JOptionPane.showMessageDialog(null,s,"Created Sucessfully",JOptionPane.INFORMATION_MESSAGE);
new FrmLogin();
return;
}
jtfUser.requestFocus();
}
});
try
{
DConnection dc=new DConnection();
ResultSet rst=dc.executeQuery("select count(*) from users");
rst.next();
int c=rst.getInt(1);
dc.close();
if(c==0)
{
jcbType.setSelectedItem("admin");
jcbType.setEnabled(false);
}
else
jcbType.setEnabled(true);
}
catch(SQLException e)
{
e.printStackTrace();
}
add(btnCreate);
setExtendedState(JFrame.MAXIMIZED_BOTH);
setVisible(true);
}
}