From 08c8ef330131aeaf0713da89d78abaabfee39a41 Mon Sep 17 00:00:00 2001 From: gdutwen <7537542+gdutwen@user.noreply.gitee.com> Date: Thu, 28 May 2020 15:06:51 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E9=94=80=E5=94=AE=E5=91=98=E7=AA=97?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MainW1.java | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 MainW1.java diff --git a/MainW1.java b/MainW1.java new file mode 100644 index 0000000..57eae38 --- /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); + } +} -- Gitee From 41649a2594c85248916621003f5eee0a63e4f1b6 Mon Sep 17 00:00:00 2001 From: gdutwen <7537542+gdutwen@user.noreply.gitee.com> Date: Mon, 1 Jun 2020 15:53:32 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20Logi?= =?UTF-8?q?nListener.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LoginListener.java | 82 ---------------------------------------------- 1 file changed, 82 deletions(-) delete mode 100644 LoginListener.java diff --git a/LoginListener.java b/LoginListener.java deleted file mode 100644 index 4cb4835..0000000 --- a/LoginListener.java +++ /dev/null @@ -1,82 +0,0 @@ - -import java.awt.*; -import java.sql.*; -import javax.swing.ImageIcon; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JTextField; -import javax.swing.JPasswordField; -import javax.swing.JButton; -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.Statement; -import static java.lang.Class.forName; -import com.mysql.jdbc.Driver; -public class LoginListener implements ActionListener { - - private int flag=0; - private JTextField user; - private JPasswordField password; - private JFrame login; - - public LoginListener(JFrame login, JTextField user, JPasswordField password) { - this.login = login; - this.user = user; - this.password = password;//将值传递给Listener - } - - public void actionPerformed(ActionEvent e) { - String url = "jdbc:mysql://localhost:3306/user?serverTimezone=UTC"; - String USER = "root"; - String PASSWORD = "00000000"; - try { - Class.forName("com.mysql.cj.jdbc.Driver"); //加载驱动 - System.out.println("数据库驱动加载成功"); - Connection conn = DriverManager.getConnection(url,USER,PASSWORD); //输入密码和url与数据库建立连接 - System.out.println("数据库连接成功"); - Statement statement = conn.createStatement(); - ResultSet rs = statement.executeQuery("select * from login"); //sql语言找到login表 用rs指向它 - while (rs.next()) { //rs.next()可以使rs指向下一行 - 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(); //如果用户名密码匹配成功,就运行下一个窗口的代码 - 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); - - - } - }catch(SQLException se){ - se.printStackTrace(); - }catch(Exception w){ - w.printStackTrace(); - }finally{ - - } - } -} - - - -- Gitee From 359d9de7766cfdffeeabbb53af632e1f29a3ef12 Mon Sep 17 00:00:00 2001 From: gdutwen <7537542+gdutwen@user.noreply.gitee.com> Date: Mon, 1 Jun 2020 15:54:40 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E5=93=8D=E5=BA=94=EF=BC=9A=E4=B8=8D=E5=90=8C=E7=9A=84=E8=BA=AB?= =?UTF-8?q?=E4=BB=BD=E8=BF=9B=E5=85=A5=E4=B8=8D=E5=90=8C=E7=9A=84=E7=AA=97?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LoginListener.java | 86 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 LoginListener.java diff --git a/LoginListener.java b/LoginListener.java new file mode 100644 index 0000000..bcb9614 --- /dev/null +++ b/LoginListener.java @@ -0,0 +1,86 @@ +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; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; +import static java.lang.Class.forName; +import surpermarket.*; +public class LoginListener implements ActionListener { + + private JTextField user; + private JPasswordField password; + private JFrame login; + + public LoginListener(JFrame login, JTextField user, JPasswordField password) { + this.login = login; + this.user = user; + this.password = password;//ֵݸListener + } + + public void actionPerformed(ActionEvent e) { + 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.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 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) + JOptionPane.showMessageDialog(null," ˺Ż"); + }catch(SQLException se){ + se.printStackTrace(); + }catch(Exception w){ + w.printStackTrace(); + }finally{ + + } + } +} + + + -- Gitee From 58d5d996683df0e5e2362ca03448699e105017f7 Mon Sep 17 00:00:00 2001 From: gdutwen <7537542+gdutwen@user.noreply.gitee.com> Date: Mon, 1 Jun 2020 15:55:58 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=AA=97=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MainW2.java | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 MainW2.java diff --git a/MainW2.java b/MainW2.java new file mode 100644 index 0000000..4ab469c --- /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); + } + +} -- Gitee From f4ef75b8c719bbdc273b5a25c5539d1635549e0c Mon Sep 17 00:00:00 2001 From: gdutwen <7537542+gdutwen@user.noreply.gitee.com> Date: Mon, 1 Jun 2020 19:25:48 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E8=B4=A6=E6=88=B7=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8D=E5=AF=86=E7=A0=81=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Accountcomm.java | 230 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 230 insertions(+) create mode 100644 Accountcomm.java diff --git a/Accountcomm.java b/Accountcomm.java new file mode 100644 index 0000000..7c4c720 --- /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); + + + + + } +} -- Gitee From 60240f790059f351c4ee192036a3b37a50b0c626 Mon Sep 17 00:00:00 2001 From: gdutwen <7537542+gdutwen@user.noreply.gitee.com> Date: Wed, 3 Jun 2020 16:25:40 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E8=BF=84=E4=BB=8A=E4=B8=BA=E6=AD=A2?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=9A=84=E9=83=A8=E5=88=86=20=20=E4=B8=BB?= =?UTF-8?q?=E5=87=BD=E6=95=B0=EF=BC=9ALogin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- surpermarket/Accountcomm.java | 233 ++++++++++++ surpermarket/Date_Change.java | 21 ++ surpermarket/DeleteAccount.java | 69 ++++ surpermarket/DeleteStaff.java | 70 ++++ surpermarket/Goodscomm.java | 283 ++++++++++++++ surpermarket/InsertAccount.java | 74 ++++ surpermarket/InsertCargosold.java | 132 +++++++ surpermarket/InsertStaff.java | 75 ++++ surpermarket/Login.java | 76 ++++ surpermarket/LoginListener.java | 86 +++++ surpermarket/MainW2.java | 95 +++++ surpermarket/MianW1.java | 130 +++++++ surpermarket/QueryALLAccount.java | 101 +++++ surpermarket/QueryALLStaff.java | 103 +++++ surpermarket/QueryAccount.java | 125 +++++++ surpermarket/QueryCargo.java | 454 +++++++++++++++++++++++ surpermarket/QueryStaff.java | 178 +++++++++ surpermarket/Query_Enter_Exit_Cargo.java | 176 +++++++++ surpermarket/Query_turnover.java | 71 ++++ surpermarket/UpdateAccount.java | 78 ++++ 20 files changed, 2630 insertions(+) create mode 100644 surpermarket/Accountcomm.java create mode 100644 surpermarket/Date_Change.java create mode 100644 surpermarket/DeleteAccount.java create mode 100644 surpermarket/DeleteStaff.java create mode 100644 surpermarket/Goodscomm.java create mode 100644 surpermarket/InsertAccount.java create mode 100644 surpermarket/InsertCargosold.java create mode 100644 surpermarket/InsertStaff.java create mode 100644 surpermarket/Login.java create mode 100644 surpermarket/LoginListener.java create mode 100644 surpermarket/MainW2.java create mode 100644 surpermarket/MianW1.java create mode 100644 surpermarket/QueryALLAccount.java create mode 100644 surpermarket/QueryALLStaff.java create mode 100644 surpermarket/QueryAccount.java create mode 100644 surpermarket/QueryCargo.java create mode 100644 surpermarket/QueryStaff.java create mode 100644 surpermarket/Query_Enter_Exit_Cargo.java create mode 100644 surpermarket/Query_turnover.java create mode 100644 surpermarket/UpdateAccount.java diff --git a/surpermarket/Accountcomm.java b/surpermarket/Accountcomm.java new file mode 100644 index 0000000..33e979c --- /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 0000000..7c8e0fd --- /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 0000000..38969ad --- /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; // ݿIJ + 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 0000000..5119625 --- /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; // ݿIJ + 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 0000000..cf41cad --- /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