diff --git a/Accountcomm.java b/Accountcomm.java new file mode 100644 index 0000000000000000000000000000000000000000..7c4c72010898b921fbb2ffa4aebb2d18e039273b --- /dev/null +++ b/Accountcomm.java @@ -0,0 +1,230 @@ +package surpermarket; + +import java.awt.EventQueue; + +import javax.swing.JFrame; +import javax.swing.JLabel; +import java.awt.Font; +import java.awt.TextArea; + +import javax.swing.JTextField; + + + +import javax.swing.JButton; +import javax.swing.JTextArea; +import java.awt.event.ActionListener; +import java.awt.geom.Area; +import java.sql.Connection; +import java.sql.DriverManager; +import java.awt.event.ActionEvent; +import surpermarket.QueryAccount; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.Statement; +import java.sql.ResultSet; +import javax.swing.JOptionPane; + +public class Accountcomm { + + private JFrame frame; + private JTextField T_account; + private JTextField T_password; + private JTextField T_position; + + /** + * Launch the application. + */ + public static void main(String[] args) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + Accountcomm window = new Accountcomm(); + window.frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + /** + * Create the application. + */ + public Accountcomm() { + initialize(); + } + + /** + * Initialize the contents of the frame. + */ + private void initialize() { + frame = new JFrame(); + frame.setTitle("\u767B\u5F55\u4FE1\u606F"); + frame.getContentPane().setLayout(null); + + + JLabel lblNewLabel = new JLabel("\u8D26\u53F7"); + lblNewLabel.setBounds(59, 82, 70, 39); + lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 18)); + frame.getContentPane().add(lblNewLabel); + + JLabel lblNewLabel_1 = new JLabel("\u5BC6\u7801"); + lblNewLabel_1.setBounds(59, 164, 70, 39); + lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 18)); + frame.getContentPane().add(lblNewLabel_1); + + JButton B_add = new JButton("\u589E\u52A0"); + B_add.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + + try { + surpermarket.InsertAccount insert=new InsertAccount(T_account.getText(), T_password.getText(),T_position.getText()); + } catch (Exception e1) { + // TODO 自动生成的 catch 块 + e1.printStackTrace(); + } + } + }); + B_add.setBounds(10, 308, 97, 39); + B_add.setFont(new Font("宋体", Font.PLAIN, 15)); + frame.getContentPane().add(B_add); + + JButton B_question = new JButton("\u67E5\u8BE2"); + JTextArea textArea = new JTextArea(); //新建显示内容窗口TextArea + textArea.setBounds(519, 142, 371, 304); + + textArea.setEditable(false); + textArea.setVisible(true); + + frame.getContentPane().add(textArea); + B_question.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { //查询按钮的响应 + + //与前端对接 显示查询内容 +//// + + String account=null; + String password=null; + String position=null; + if(T_account.getText().length()!=0) account=T_account.getText(); + if(T_password.getText().length()!=0) password=T_password.getText(); + if(T_position.getText().length()!=0) position=T_position.getText(); + try { + + QueryAccount Q= new QueryAccount(account,password,position); //新建对象 + String[] strings=Q.getstr(); + textArea.setText(""); //先设置显示面板为空 + int i=0; + while(strings[i*3].length()!=0) { + textArea.append(strings[i*3+0]+" "+strings[i*3+1]+" "+strings[i*3+2]+" "); + textArea.append("\n"); + i++; + } + //在textArea显示出其中的一个内容 +// a.setText(strings[0]+" "+strings[1]+" "+strings[2]); + + } catch (Exception e1) { + // TODO 自动生成的 catch 块 + e1.printStackTrace(); + } +// textArea.append("1111111111111111"); //测试是否是显示出了问题 +// + + + + + } + + +// +// + + }); + B_question.setBounds(117, 308, 97, 39); + B_question.setFont(new Font("宋体", Font.PLAIN, 15)); + frame.getContentPane().add(B_question); + + JButton B_update = new JButton("\u4FEE\u6539"); + B_update.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + surpermarket.UpdateAccount update=new surpermarket.UpdateAccount(T_account.getText(),T_password.getText(),T_position.getText()); //调用后台Update类 + } catch (Exception e1) { + // TODO 自动生成的 catch 块 + e1.printStackTrace(); + } + + } + }); + B_update.setBounds(239, 308, 97, 39); + B_update.setFont(new Font("宋体", Font.PLAIN, 15)); + frame.getContentPane().add(B_update); + + JButton B_delete = new JButton("\u5220\u9664"); + B_delete.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + surpermarket.DeleteAccount delete=new surpermarket.DeleteAccount(T_account.getText()); //调用后台DELETE类 + } catch (Exception e1) { + // TODO 自动生成的 catch 块 + e1.printStackTrace(); + } + } + }); + B_delete.setBounds(10, 370, 97, 39); + B_delete.setFont(new Font("宋体", Font.PLAIN, 15)); + frame.getContentPane().add(B_delete); + + JButton B_questionall = new JButton("\u67E5\u8BE2\u5168\u4F53"); + B_questionall.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + surpermarket.QueryALLAccount qa=new surpermarket.QueryALLAccount(); //调用后台DELETE类 + String[] strings=qa.getstr(); + textArea.setText("账号 密码 职位 \n"); //先设置显示面板为空 + int i=0; + while(strings[i*3].length()!=0) { + textArea.append(strings[i*3+0]+" "+strings[i*3+1]+" "+strings[i*3+2]+" "); + textArea.append("\n"); + i++; + } + } catch (Exception e1) { + // TODO 自动生成的 catch 块 + e1.printStackTrace(); + } + + } + }); + B_questionall.setBounds(117, 370, 145, 76); + B_questionall.setFont(new Font("宋体", Font.PLAIN, 15)); + frame.getContentPane().add(B_questionall); + + JLabel lblNewLabel_1_1 = new JLabel("\u6743\u9650"); + lblNewLabel_1_1.setBounds(59, 238, 70, 39); + lblNewLabel_1_1.setFont(new Font("宋体", Font.PLAIN, 18)); + frame.getContentPane().add(lblNewLabel_1_1); + + T_account = new JTextField(); + T_account.setBounds(158, 71, 215, 37); + T_account.setFont(new Font("宋体", Font.PLAIN, 16)); + T_account.setColumns(10); + frame.getContentPane().add(T_account); + + T_password = new JTextField(); + T_password.setBounds(148, 164, 215, 37); + T_password.setFont(new Font("宋体", Font.PLAIN, 16)); + T_password.setColumns(10); + frame.getContentPane().add(T_password); + + T_position = new JTextField(); + T_position.setBounds(148, 238, 215, 37); + T_position.setFont(new Font("宋体", Font.PLAIN, 16)); + T_position.setColumns(10); + frame.getContentPane().add(T_position); + + + + + } +} diff --git a/LoginListener.java b/LoginListener.java index 4cb48355c9c497136d83ac25fd4582ca9025cdfb..bcb96142c9609c8495b555fa9b355ef874df05b6 100644 --- a/LoginListener.java +++ b/LoginListener.java @@ -1,9 +1,10 @@ - +package surpermarket; import java.awt.*; import java.sql.*; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JTextField; import javax.swing.JPasswordField; import javax.swing.JButton; @@ -13,10 +14,9 @@ import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import static java.lang.Class.forName; -import com.mysql.jdbc.Driver; +import surpermarket.*; public class LoginListener implements ActionListener { - private int flag=0; private JTextField user; private JPasswordField password; private JFrame login; @@ -24,50 +24,54 @@ public class LoginListener implements ActionListener { public LoginListener(JFrame login, JTextField user, JPasswordField password) { this.login = login; this.user = user; - this.password = password;//灏嗗间紶閫掔粰Listener + this.password = password;//将值传递给Listener } public void actionPerformed(ActionEvent e) { - String url = "jdbc:mysql://localhost:3306/user?serverTimezone=UTC"; + String url = "jdbc:mysql://localhost:3306/supermarket?&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC"; String USER = "root"; String PASSWORD = "00000000"; + int flag=0; try { - Class.forName("com.mysql.cj.jdbc.Driver"); //鍔犺浇椹卞姩 - System.out.println("鏁版嵁搴撻┍鍔ㄥ姞杞芥垚鍔"); - Connection conn = DriverManager.getConnection(url,USER,PASSWORD); //杈撳叆瀵嗙爜鍜寀rl涓庢暟鎹簱寤虹珛杩炴帴 - System.out.println("鏁版嵁搴撹繛鎺ユ垚鍔"); + Class.forName("com.mysql.jdbc.Driver"); + System.out.println("数据库驱动加载成功"); + Connection conn = DriverManager.getConnection(url, USER, PASSWORD); + System.out.println("数据库连接成功"); Statement statement = conn.createStatement(); - ResultSet rs = statement.executeQuery("select * from login"); //sql璇█鎵惧埌login琛 鐢╮s鎸囧悜瀹 - while (rs.next()) { //rs.next()鍙互浣縭s鎸囧悜涓嬩竴琛 - if (user.getText().equals(rs.getString("username")) && password.getText().equals(rs.getString("password"))) { - JFrame new1 = new JFrame(); - new1.setSize(340, 500); - new1.setDefaultCloseOperation(3); - new1.setLocationRelativeTo(null); - new1.setVisible(true); - login.dispose(); //濡傛灉鐢ㄦ埛鍚嶅瘑鐮佸尮閰嶆垚鍔燂紝灏辫繍琛屼笅涓涓獥鍙g殑浠g爜 + ResultSet rs = statement.executeQuery("select * from account"); + + + while (rs.next()){ + + if (user.getText().equals(rs.getString("Account")) && password.getText().equals(rs.getString("Password"))) { + if("经理".equals(rs.getString("Position"))) { //如果身份是经理则打开管理员界面 + try { + MainW2 window1 = new MainW2(); + + } catch (Exception f) { + f.printStackTrace(); + } + } + else { + try { //否则打开售货员界面 + MianW1 window2 = new MianW1(); + + } catch (Exception b) { + b.printStackTrace(); + } + } + + + login.dispose(); flag=1; break; - } - - } - if(flag==0){ - JFrame new2 = new JFrame(); - new2.setSize(200, 200); - new2.setDefaultCloseOperation(3); - new2.setLocationRelativeTo(null); - new2.setVisible(true); - - JLabel labIcon=new JLabel("鐢ㄦ埛鍚嶆垨瀵嗙爜閿欒"); - Font font= new Font("瀹嬩綋",Font.PLAIN,15); - labIcon.setFont(font);//璁剧疆瀛椾綋 - Dimension dim=new Dimension(150,150); - labIcon.setPreferredSize(dim); - labIcon.setHorizontalAlignment(JLabel.CENTER);//璁剧疆瀛椾綋灞呬腑 - new2.add(labIcon); - + } + } + + if(flag==0) + JOptionPane.showMessageDialog(null," 账号或者密码错误"); }catch(SQLException se){ se.printStackTrace(); }catch(Exception w){ diff --git a/MainW1.java b/MainW1.java new file mode 100644 index 0000000000000000000000000000000000000000..57eae380492f25068719ce24b8af70ac02d19b0c --- /dev/null +++ b/MainW1.java @@ -0,0 +1,89 @@ +package surpermarket; + +import java.awt.EventQueue; + +import javax.swing.JFrame; +import javax.swing.JLabel; +import java.awt.Font; +import javax.swing.JButton; +import javax.swing.JTextField; + +public class MianW1 { + + private JFrame frame; + private JTextField textField; + private JTextField textField_1; + + /** + * Launch the application. + */ + public static void main(String[] args) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + MianW1 window = new MianW1(); + window.frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + /** + * Create the application. + */ + public MianW1() { + initialize(); + } + + /** + * Initialize the contents of the frame. + */ + private void initialize() { + frame = new JFrame(); + frame.setBounds(100, 100, 692, 490); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.getContentPane().setLayout(null); + + JLabel lblNewLabel = new JLabel("\u8BA2\u5355\u7F16\u53F7"); + lblNewLabel.setFont(new Font("瀹嬩綋", Font.PLAIN, 13)); + lblNewLabel.setBounds(10, 10, 61, 29); + frame.getContentPane().add(lblNewLabel); + + JLabel lblXxxxx = new JLabel("XXXXX"); + lblXxxxx.setFont(new Font("瀹嬩綋", Font.PLAIN, 13)); + lblXxxxx.setBounds(93, 10, 61, 29); + frame.getContentPane().add(lblXxxxx); + + JButton btnNewButton = new JButton("\u65B0\u5EFA\u8BA2\u5355"); + btnNewButton.setFont(new Font("瀹嬩綋", Font.PLAIN, 14)); + btnNewButton.setBounds(505, 10, 140, 45); + frame.getContentPane().add(btnNewButton); + + JLabel lblNewLabel_1 = new JLabel("\u5546\u54C1\u7F16\u53F7"); + lblNewLabel_1.setFont(new Font("瀹嬩綋", Font.PLAIN, 18)); + lblNewLabel_1.setBounds(123, 146, 82, 45); + frame.getContentPane().add(lblNewLabel_1); + + textField = new JTextField(); + textField.setBounds(233, 146, 209, 34); + frame.getContentPane().add(textField); + textField.setColumns(10); + + JLabel lblNewLabel_1_1 = new JLabel("\u5546\u54C1\u6570\u91CF"); + lblNewLabel_1_1.setFont(new Font("瀹嬩綋", Font.PLAIN, 18)); + lblNewLabel_1_1.setBounds(123, 228, 82, 45); + frame.getContentPane().add(lblNewLabel_1_1); + + textField_1 = new JTextField(); + textField_1.setColumns(10); + textField_1.setBounds(233, 226, 209, 34); + frame.getContentPane().add(textField_1); + + JButton btnNewButton_1 = new JButton("\u786E\u5B9A"); + btnNewButton_1.setFont(new Font("瀹嬩綋", Font.PLAIN, 14)); + btnNewButton_1.setBounds(505, 369, 140, 45); + frame.getContentPane().add(btnNewButton_1); + } +} diff --git a/MainW2.java b/MainW2.java new file mode 100644 index 0000000000000000000000000000000000000000..4ab469cd8c1edb702d7e41bf5fb30f91c0222938 --- /dev/null +++ b/MainW2.java @@ -0,0 +1,70 @@ +package surpermarket; + +import java.awt.EventQueue; + +import javax.swing.JFrame; +import javax.swing.JButton; +import java.awt.Font; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + +public class MainW2 { + + private JFrame frame; + + /** + * Launch the application. + */ + public static void main(String[] args) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + MainW2 window = new MainW2(); + window.frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + /** + * Create the application. + */ + public MainW2() { + initialize(); + } + + /** + * Initialize the contents of the frame. + */ + private void initialize() { + frame = new JFrame(); + frame.setTitle("\u7BA1\u7406\u7A97\u53E3"); + frame.setBounds(100, 100, 812, 654); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.getContentPane().setLayout(null); + frame.setVisible(true); + + JButton btnNewButton = new JButton("\u8D27\u7269\u64CD\u4F5C"); + btnNewButton.setFont(new Font("宋体", Font.PLAIN, 18)); + btnNewButton.setBounds(31, 62, 131, 48); + frame.getContentPane().add(btnNewButton); + + JButton btnNewButton_1 = new JButton("\u804C\u5DE5\u4FE1\u606F\u64CD\u4F5C"); + btnNewButton_1.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + + } + }); + btnNewButton_1.setFont(new Font("宋体", Font.PLAIN, 18)); + btnNewButton_1.setBounds(279, 65, 179, 52); + frame.getContentPane().add(btnNewButton_1); + + JButton btnNewButton_2 = new JButton("\u8D26\u53F7\u5BC6\u7801\u64CD\u4F5C"); + btnNewButton_2.setFont(new Font("宋体", Font.PLAIN, 18)); + btnNewButton_2.setBounds(603, 46, 146, 92); + frame.getContentPane().add(btnNewButton_2); + } + +} diff --git a/surpermarket/Accountcomm.java b/surpermarket/Accountcomm.java new file mode 100644 index 0000000000000000000000000000000000000000..33e979c0e5981736564ac8a55d9fa0e4ea35c23a --- /dev/null +++ b/surpermarket/Accountcomm.java @@ -0,0 +1,233 @@ +package surpermarket; + +import java.awt.EventQueue; + +import javax.swing.JFrame; +import javax.swing.JLabel; +import java.awt.Font; +import java.awt.TextArea; + +import javax.swing.JTextField; + + + +import javax.swing.JButton; +import javax.swing.JTextArea; +import java.awt.event.ActionListener; +import java.awt.geom.Area; +import java.sql.Connection; +import java.sql.DriverManager; +import java.awt.event.ActionEvent; +import surpermarket.QueryAccount; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.Statement; +import java.sql.ResultSet; +import javax.swing.JOptionPane; + +public class Accountcomm { + + private JFrame frame; + private JTextField T_account; + private JTextField T_password; + private JTextField T_position; + + /** + * Launch the application. + */ + public static void main(String[] args) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + Accountcomm window = new Accountcomm(); + window.frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + /** + * Create the application. + */ + public Accountcomm() { + initialize(); + } + + /** + * Initialize the contents of the frame. + */ + private void initialize() { + frame = new JFrame(); + frame.setAlwaysOnTop(true); + frame.setTitle("\u767B\u5F55\u4FE1\u606F\u7BA1\u7406"); + frame.getContentPane().setLayout(null); + frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + frame.setVisible(true); + + + JLabel lblNewLabel = new JLabel("\u8D26\u53F7"); + lblNewLabel.setBounds(59, 82, 70, 39); + lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 18)); + frame.getContentPane().add(lblNewLabel); + + JLabel lblNewLabel_1 = new JLabel("\u5BC6\u7801"); + lblNewLabel_1.setBounds(59, 164, 70, 39); + lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 18)); + frame.getContentPane().add(lblNewLabel_1); + + JButton B_add = new JButton("\u589E\u52A0"); + B_add.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + + try { + surpermarket.InsertAccount insert=new InsertAccount(T_account.getText(), T_password.getText(),T_position.getText()); + } catch (Exception e1) { + // TODO 自动生成的 catch 块 + e1.printStackTrace(); + } + } + }); + B_add.setBounds(10, 308, 97, 39); + B_add.setFont(new Font("宋体", Font.PLAIN, 15)); + frame.getContentPane().add(B_add); + + JButton B_question = new JButton("\u67E5\u8BE2"); + JTextArea textArea = new JTextArea(); //新建显示内容窗口TextArea + textArea.setBounds(436, 60, 371, 304); + + textArea.setEditable(false); + textArea.setVisible(true); + + frame.getContentPane().add(textArea); + B_question.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { //查询按钮的响应 + + //与前端对接 显示查询内容 +//// + + String account=null; + String password=null; + String position=null; + if(T_account.getText().length()!=0) account=T_account.getText(); + if(T_password.getText().length()!=0) password=T_password.getText(); + if(T_position.getText().length()!=0) position=T_position.getText(); + try { + + QueryAccount Q= new QueryAccount(account,password,position); //新建对象 + String[] strings=Q.getstr(); + textArea.setText(""); //先设置显示面板为空 + int i=0; + while(strings[i*3].length()!=0) { + textArea.append(strings[i*3+0]+" "+strings[i*3+1]+" "+strings[i*3+2]+" "); + textArea.append("\n"); + i++; + } + //在textArea显示出其中的一个内容 +// a.setText(strings[0]+" "+strings[1]+" "+strings[2]); + + } catch (Exception e1) { + // TODO 自动生成的 catch 块 + e1.printStackTrace(); + } +// textArea.append("1111111111111111"); //测试是否是显示出了问题 +// + + + + + } + + +// +// + + }); + B_question.setBounds(117, 308, 97, 39); + B_question.setFont(new Font("宋体", Font.PLAIN, 15)); + frame.getContentPane().add(B_question); + + JButton B_update = new JButton("\u4FEE\u6539"); + B_update.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + surpermarket.UpdateAccount update=new surpermarket.UpdateAccount(T_account.getText(),T_password.getText(),T_position.getText()); //调用后台Update类 + } catch (Exception e1) { + // TODO 自动生成的 catch 块 + e1.printStackTrace(); + } + + } + }); + B_update.setBounds(239, 308, 97, 39); + B_update.setFont(new Font("宋体", Font.PLAIN, 15)); + frame.getContentPane().add(B_update); + + JButton B_delete = new JButton("\u5220\u9664"); + B_delete.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + surpermarket.DeleteAccount delete=new surpermarket.DeleteAccount(T_account.getText()); //调用后台DELETE类 + } catch (Exception e1) { + // TODO 自动生成的 catch 块 + e1.printStackTrace(); + } + } + }); + B_delete.setBounds(10, 370, 97, 39); + B_delete.setFont(new Font("宋体", Font.PLAIN, 15)); + frame.getContentPane().add(B_delete); + + JButton B_questionall = new JButton("\u67E5\u8BE2\u5168\u4F53"); + B_questionall.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + surpermarket.QueryALLAccount qa=new surpermarket.QueryALLAccount(); //调用后台DELETE类 + String[] strings=qa.getstr(); + textArea.setText("账号 密码 职位 \n"); //先设置显示面板为空 + int i=0; + while(strings[i*3].length()!=0) { + textArea.append(strings[i*3+0]+" "+strings[i*3+1]+" "+strings[i*3+2]+" "); + textArea.append("\n"); + i++; + } + } catch (Exception e1) { + // TODO 自动生成的 catch 块 + e1.printStackTrace(); + } + + } + }); + B_questionall.setBounds(117, 370, 145, 76); + B_questionall.setFont(new Font("宋体", Font.PLAIN, 15)); + frame.getContentPane().add(B_questionall); + + JLabel lblNewLabel_1_1 = new JLabel("\u6743\u9650"); + lblNewLabel_1_1.setBounds(59, 238, 70, 39); + lblNewLabel_1_1.setFont(new Font("宋体", Font.PLAIN, 18)); + frame.getContentPane().add(lblNewLabel_1_1); + + T_account = new JTextField(); + T_account.setBounds(158, 71, 215, 37); + T_account.setFont(new Font("宋体", Font.PLAIN, 16)); + T_account.setColumns(10); + frame.getContentPane().add(T_account); + + T_password = new JTextField(); + T_password.setBounds(148, 164, 215, 37); + T_password.setFont(new Font("宋体", Font.PLAIN, 16)); + T_password.setColumns(10); + frame.getContentPane().add(T_password); + + T_position = new JTextField(); + T_position.setBounds(148, 238, 215, 37); + T_position.setFont(new Font("宋体", Font.PLAIN, 16)); + T_position.setColumns(10); + frame.getContentPane().add(T_position); + + + + + } +} diff --git a/surpermarket/Date_Change.java b/surpermarket/Date_Change.java new file mode 100644 index 0000000000000000000000000000000000000000..7c8e0fde75c0aea0907c200576f20f858e3cae4b --- /dev/null +++ b/surpermarket/Date_Change.java @@ -0,0 +1,21 @@ +package surpermarket; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class Date_Change { + String[] formatStrings = { "y/M/d", "y.M.d", "y-M-d" }; // + + public Date tryParse(String dateString) { + for (String formatString : formatStrings) { + try { + return new SimpleDateFormat(formatString).parse(dateString); + } catch (ParseException e) { + } + } + + return null; + } + +} \ No newline at end of file diff --git a/surpermarket/DeleteAccount.java b/surpermarket/DeleteAccount.java new file mode 100644 index 0000000000000000000000000000000000000000..38969ad2a58519761822704bb6d8f7282ad09c55 --- /dev/null +++ b/surpermarket/DeleteAccount.java @@ -0,0 +1,69 @@ +package surpermarket; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; + +import javax.swing.JOptionPane; + +public class DeleteAccount +{ + + // 加载数据库驱动 com.mysql.jdbc.Driver + public static final String DBDRIVER = "com.mysql.cj.jdbc.Driver"; + + // 获取mysql连接地址 + public static final String DBURL = "jdbc:mysql://localhost:3306/supermarket?&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC"; + + // 数据名称 + public static final String DBUSER = "root"; + + // 数据库密码 + public static final String DBPASS = "00000000"; + + + public DeleteAccount(String account) throws Exception{ + + if(account==null) { //判断输入框账号是否为空 + + JOptionPane.showMessageDialog(null,"对不起!必须输入账号方可执行删除。"); + } + else { + + Connection conn = null; // 数据的连接 + PreparedStatement pstmt = null; // 数据库的操作 + ResultSet rs = null; + + String sql = "SELECT Account,Password,Position FROM ACCOUNT WHERE Account=?"; //实例sql查询语句 + + Class.forName(DBDRIVER); //加载驱动程序 + conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS); //连接MySQL数据库时,要写上连接的用户名和密码 + + pstmt = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); //实例化Preparedstatsment对象 + + pstmt.setString(1,account); //按顺序设置?内容 + + rs = pstmt.executeQuery(); //执行数据库查询操作 + + if(rs.next()==false) { //判断表中是否已有该账户 + JOptionPane.showMessageDialog(null,"该账户不存在,请检查是否输入错误账户信息。"); + } + else { + rs.last(); //移动到最后一行 + rs.deleteRow(); //执行删除操作 + JOptionPane.showMessageDialog(null,"删除完成!"); + } + rs.close(); + pstmt.close(); + conn.close(); + } + } + + + //--------测试------------------ + public static void main(String[] args) throws Exception { + new DeleteAccount("zhanhao"); //执行删除操作只需获取输入框中的用户账号 + } + +} \ No newline at end of file diff --git a/surpermarket/DeleteStaff.java b/surpermarket/DeleteStaff.java new file mode 100644 index 0000000000000000000000000000000000000000..51196253712afd6f4455faea11e8694a83099016 --- /dev/null +++ b/surpermarket/DeleteStaff.java @@ -0,0 +1,70 @@ +package surpermarket; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; + +import javax.swing.JOptionPane; + +public class DeleteStaff +{ + + // 加载数据库驱动 com.mysql.jdbc.Driver + public static final String DBDRIVER = "com.mysql.cj.jdbc.Driver"; + + // 获取mysql连接地址 + public static final String DBURL = "jdbc:mysql://localhost:3306/supermarket?&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC"; + + // 数据名称 + public static final String DBUSER = "root"; + + // 数据库密码 + public static final String DBPASS = "00000000"; + + + public DeleteStaff(String sno) throws Exception{ + + if(sno==null) { //判断输入框中职工编号是否为空 + + JOptionPane.showMessageDialog(null,"对不起!职工编号不能为空,请重新输入方可删除。"); + } + else { + + Connection conn = null; // 数据的连接 + PreparedStatement pstmt = null; // 数据库的操作 + ResultSet rs = null; + + String sql = "SELECT Sno,Sname,Sposition,Sphone FROM STAFF WHERE Sno=?"; + + Class.forName(DBDRIVER); //加载驱动程序 + conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS); //连接MySQL数据库时,要写上连接的用户名和密码 + + pstmt = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); //实例化Preparedstatsment对象 + + pstmt.setString(1,sno); //按顺序设置?内容 + + rs = pstmt.executeQuery(); //执行数据库查询操作 + + if(rs.next()==false) { //判断表中是否已有该编号员工 + + JOptionPane.showMessageDialog(null,"该编号员工不存在,请检查是否输入错误编号。"); + } + else { + rs.last(); //移动到最后一行 + rs.deleteRow(); //执行删除操作 + JOptionPane.showMessageDialog(null,"删除完成!"); + } + rs.close(); + pstmt.close(); + conn.close(); + } + } + + + //--------测试------------------ + public static void main(String[] args) throws Exception { + new DeleteStaff("3118005097"); //删除员工表信息继续获取职工编号 + } + +} \ No newline at end of file diff --git a/surpermarket/Goodscomm.java b/surpermarket/Goodscomm.java new file mode 100644 index 0000000000000000000000000000000000000000..cf41cad3aed0900d86adb36a90f4f0c24395e5fd --- /dev/null +++ b/surpermarket/Goodscomm.java @@ -0,0 +1,283 @@ +package surpermarket; + +import java.awt.EventQueue; + +import javax.swing.JFrame; +import javax.swing.JLabel; +import java.awt.Font; +import javax.swing.JTextField; +import javax.swing.JButton; +import javax.swing.JTextArea; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + +public class Goodscomm { + + private JFrame frame; + private JTextField T_bigType; + private JTextField T_smallType; + private JTextField T_goodsName; + private JTextField T_singalPrice; + private JTextField T_Num; + private JTextField T_enterPrice; + private JTextField T_startTime; + private JTextField T_endTime; + + /** + * Launch the application. + */ + public static void main(String[] args) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + Goodscomm window = new Goodscomm(); + window.frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + /** + * Create the application. + */ + public Goodscomm() { + initialize(); + } + + /** + * Initialize the contents of the frame. + */ + private void initialize() { + frame = new JFrame(); + frame.setBounds(100, 100, 947, 636); + frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + frame.getContentPane().setLayout(null); + frame.setVisible(true); + + JTextArea textArea = new JTextArea(); + textArea.setEditable(false); + textArea.setBounds(52, 249, 694, 328); + frame.getContentPane().add(textArea); + + JLabel lblNewLabel = new JLabel("\u5927\u7C7B\u540D"); + lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 15)); + lblNewLabel.setBounds(41, 43, 63, 31); + frame.getContentPane().add(lblNewLabel); + + JLabel lblNewLabel_1 = new JLabel("\u5C0F\u7C7B\u540D"); + lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 15)); + lblNewLabel_1.setBounds(36, 100, 63, 31); + frame.getContentPane().add(lblNewLabel_1); + + JLabel lblNewLabel_2 = new JLabel("\u5546\u54C1\u540D"); + lblNewLabel_2.setFont(new Font("宋体", Font.PLAIN, 15)); + lblNewLabel_2.setBounds(34, 149, 63, 31); + frame.getContentPane().add(lblNewLabel_2); + + JLabel lblNewLabel_3 = new JLabel("\u5355\u4EF7"); + lblNewLabel_3.setFont(new Font("宋体", Font.PLAIN, 15)); + lblNewLabel_3.setBounds(33, 193, 63, 31); + frame.getContentPane().add(lblNewLabel_3); + + JLabel lblNewLabel_4 = new JLabel("\u6570\u91CF"); + lblNewLabel_4.setFont(new Font("宋体", Font.PLAIN, 15)); + lblNewLabel_4.setBounds(291, 37, 63, 31); + frame.getContentPane().add(lblNewLabel_4); + + JLabel lblNewLabel_5 = new JLabel("\u8FDB\u4EF7"); + lblNewLabel_5.setFont(new Font("宋体", Font.PLAIN, 15)); + lblNewLabel_5.setBounds(288, 78, 63, 31); + frame.getContentPane().add(lblNewLabel_5); + + JLabel lblNewLabel_6 = new JLabel("\u8D77\u59CB\u65F6\u95F4"); + lblNewLabel_6.setFont(new Font("宋体", Font.PLAIN, 15)); + lblNewLabel_6.setBounds(282, 128, 63, 31); + frame.getContentPane().add(lblNewLabel_6); + + JLabel lblNewLabel_7 = new JLabel("\u622A\u6B62\u65F6\u95F4"); + lblNewLabel_7.setFont(new Font("宋体", Font.PLAIN, 15)); + lblNewLabel_7.setBounds(284, 184, 63, 31); + frame.getContentPane().add(lblNewLabel_7); + + T_bigType = new JTextField(); + T_bigType.setBounds(91, 39, 125, 29); + frame.getContentPane().add(T_bigType); + T_bigType.setColumns(10); + + T_smallType = new JTextField(); + T_smallType.setColumns(10); + T_smallType.setBounds(93, 98, 125, 29); + frame.getContentPane().add(T_smallType); + + T_goodsName = new JTextField(); + T_goodsName.setColumns(10); + T_goodsName.setBounds(96, 149, 125, 29); + frame.getContentPane().add(T_goodsName); + + T_singalPrice = new JTextField(); + T_singalPrice.setColumns(10); + T_singalPrice.setBounds(97, 191, 125, 29); + frame.getContentPane().add(T_singalPrice); + + T_Num = new JTextField(); + T_Num.setColumns(10); + T_Num.setBounds(342, 38, 125, 29); + frame.getContentPane().add(T_Num); + + T_enterPrice = new JTextField(); + T_enterPrice.setColumns(10); + T_enterPrice.setBounds(341, 80, 125, 29); + frame.getContentPane().add(T_enterPrice); + + T_startTime = new JTextField(); + T_startTime.setColumns(10); + T_startTime.setBounds(348, 125, 125, 29); + frame.getContentPane().add(T_startTime); + + T_endTime = new JTextField(); + T_endTime.setColumns(10); + T_endTime.setBounds(351, 182, 125, 29); + frame.getContentPane().add(T_endTime); + + JButton B_soldOrder = new JButton("\u9500\u552E\u6392\u884C"); + B_soldOrder.setFont(new Font("宋体", Font.PLAIN, 16)); + B_soldOrder.setBounds(549, 205, 101, 35); + frame.getContentPane().add(B_soldOrder); + + JButton B_soldAnalysis = new JButton("\u9500\u552E\u5206\u6790"); + B_soldAnalysis.setFont(new Font("宋体", Font.PLAIN, 16)); + B_soldAnalysis.setBounds(669, 205, 101, 35); + frame.getContentPane().add(B_soldAnalysis); + + JButton B_enterOutGoods = new JButton("\u51FA\u5165\u5E93\u67E5\u8BE2"); + B_enterOutGoods.setToolTipText("\u586B\u5199\u5927\u7C7B/\u5C0F\u7C7B\u5176\u4E2D\u4E00\u4E2A\uFF0C\u5E76\u8F93\u5165\u8D77\u59CB\u65F6\u95F4"); + B_enterOutGoods.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + + String st =T_smallType.getText(); + String bt =T_bigType.getText(); + String cn=T_goodsName.getText(); + + surpermarket.Query_Enter_Exit_Cargo qee =new surpermarket.Query_Enter_Exit_Cargo(cn, T_startTime.getText(), T_endTime.getText()); + + String[] strings=qee.getstr(); + textArea.setText(""); + int i=0; + while(strings[i].length()!=0) { + textArea.append(strings[i]); + textArea.append("\n"); + i++; + } + + + } + }); + B_enterOutGoods.setFont(new Font("宋体", Font.PLAIN, 16)); + B_enterOutGoods.setBounds(766, 27, 126, 46); + frame.getContentPane().add(B_enterOutGoods); + + JButton B_soldHistory = new JButton("\u6D41\u6C34"); + B_soldHistory.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + surpermarket.Query_turnover qt =new Query_turnover(T_startTime.getText(), T_endTime.getText()); + String string=qt.getstr(); + textArea.setText(string); + } + }); + B_soldHistory.setFont(new Font("宋体", Font.PLAIN, 16)); + B_soldHistory.setBounds(780, 201, 101, 35); + frame.getContentPane().add(B_soldHistory); + + JButton B_update = new JButton("\u4FEE\u6539"); + B_update.setFont(new Font("宋体", Font.PLAIN, 16)); + B_update.setBounds(766, 91, 126, 46); + frame.getContentPane().add(B_update); + + JButton B_enter = new JButton("\u5165\u5E93"); + B_enter.setFont(new Font("宋体", Font.PLAIN, 16)); + B_enter.setBounds(766, 140, 126, 46); + frame.getContentPane().add(B_enter); + + JButton B_queryGoods = new JButton("\u67E5\u8BE2\u5546\u54C1\u4FE1\u606F"); + B_queryGoods.setToolTipText(" \u8F93\u5165\u5927\u7C7B\u540D/\u5C0F\u7C7B\u540D/\u5546\u54C1\u540D"); + B_queryGoods.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + + QueryCargo qc; + try { + String bigtype =null; + String smalltype =null; + String cname =null; + if(T_bigType.getText().length()!=0) bigtype=T_bigType.getText(); + if(T_smallType.getText().length()!=0) smalltype=T_smallType.getText(); + if(T_goodsName.getText().length()!=0) cname=T_goodsName.getText(); + qc = new QueryCargo(bigtype, smalltype,cname ); + String sb=qc.getstb(); + String[] sm =qc.getstm(); + String[] sr =qc.getstr(); + + textArea.setText(" 货物大类编号:"+sb+"\n"); + textArea.append("-------------------------------------------- \n"); + + textArea.append("货物小类信息:\n"); + int x=0; + while(sm[x]!=null) x=x+3; + for(int i=0;i