📄 add_user_m.java
字号:
package project;
import javax.swing.JOptionPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.sql.ResultSet;
import java.sql.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
//新增操作员信息管理模块操作
public class Add_user_M {
DataBase db = null;
JFrame mainframe = null;
JPanel Add_user_M_panel = null;
public Add_user_M(JFrame mainframe, JPanel password_change) {
this.mainframe = mainframe;
this.Add_user_M_panel = Add_user_M_panel;
}
public int add_new_user(String name_text, String pwd1, String pwd2,
int pri_num) {
if (name_text.equals("")) {
JOptionPane.showMessageDialog(this.mainframe, "请为新用户输入用户名!", "提示",
JOptionPane.INFORMATION_MESSAGE);
return 0;
}
if (pwd1.equals("")) {
JOptionPane.showMessageDialog(this.mainframe, "请设置初始密码!", "提示",
JOptionPane.INFORMATION_MESSAGE);
return 1;
}
if (pwd2.equals("")) {
JOptionPane.showMessageDialog(this.mainframe, "请再次输入初始密码!", "提示",
JOptionPane.INFORMATION_MESSAGE);
return 2;
}
if (!pwd1.equals(pwd2)) {
JOptionPane.showMessageDialog(this.mainframe, "您的初始密码设置有误,请重输!", "提示",
JOptionPane.INFORMATION_MESSAGE);
return 3;
}
if (pri_num < 0) {
JOptionPane.showMessageDialog(this.mainframe, "请为新用户选择权限!", "提示",
JOptionPane.INFORMATION_MESSAGE);
return 4;
}
DataBase db = new DataBase();
String sql = "select * from login_table where loginName='" + name_text +
"'";
ResultSet rs = db.executeQuery(sql);
try {
if (rs.next()) {
rs.close();
db.close();
JOptionPane.showMessageDialog(this.mainframe, "已经存在同名用户,请重新输入用户名!",
"提示", JOptionPane.INFORMATION_MESSAGE);
return 5;
}
else {
rs.close();
String new_sql = "insert into login_table values('" + name_text + "','" +
pwd1 + "'," + pri_num + ")";
int res = db.executeUpdate(new_sql);
db.close();
if (res > 0) {
JOptionPane.showMessageDialog(this.mainframe, "新增用户成功!", "提示",
JOptionPane.INFORMATION_MESSAGE);
return 6;
}
else {
JOptionPane.showMessageDialog(this.mainframe, "新增用户失败!", "提示",
JOptionPane.INFORMATION_MESSAGE);
return 7;
}
}
}
catch (SQLException ex) {
ex.printStackTrace();
try {
rs.close();
db.close();
}
catch (SQLException ex1) {
ex1.printStackTrace();
}
finally {
JOptionPane.showMessageDialog(this.mainframe, "数据库出现错误!", "提示",
JOptionPane.INFORMATION_MESSAGE);
return -1;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -