Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.EventQueue;
- import java.awt.Font;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.DataOutputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.sql.Blob;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JTextField;
- import javax.swing.JComboBox;
- import javax.swing.JFileChooser;
- @SuppressWarnings("serial")
- public class Operator extends JFrame implements ActionListener{
- private static Operator frame = new Operator();
- public JLabel lblOperator;
- private JTextField username;
- private String selectedTemplate;
- private JLabel doc3, doc4, doc5, lblError;
- private JLabel doc_name3, doc_name4, doc_name5;
- private JButton btnAdd3, btnAdd4, btnAdd5;
- private String path = "jdbc:mysql://localhost:8889/DocumentsWork";
- private Connection connection;
- private Statement statement;
- private JFileChooser openFile = new JFileChooser();
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- public Operator()
- {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 500, 300);
- getContentPane().setLayout(null);
- JLabel operatorLabel = new JLabel("Оператор:");
- operatorLabel.setBounds(12, 10, 75, 30);
- getContentPane().add(operatorLabel);
- lblOperator = new JLabel();
- lblOperator.setBounds(85, 10, 147, 30);
- getContentPane().add(lblOperator);
- JLabel userLabel = new JLabel("Пользователь:");
- userLabel.setBounds(12,40, 100, 30);
- getContentPane().add(userLabel);
- JLabel patternLabel = new JLabel("Шаблон:");
- patternLabel.setBounds(244, 9, 65, 30);
- getContentPane().add(patternLabel);
- username = new JTextField();
- username.setBounds(105, 40, 127, 30);
- getContentPane().add(username);
- JButton btnGetData = new JButton("Получить данные");
- btnGetData.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- GetData();
- }
- });
- btnGetData.setBounds(280, 41, 138, 31);
- getContentPane().add(btnGetData);
- JLabel doc1 = new JLabel("Паспорт:");
- doc1.setFont(new Font("Lucida Grande", Font.BOLD, 13));
- doc1.setBounds(12, 90, 100, 30);
- getContentPane().add(doc1);
- JLabel doc2 = new JLabel("Заявление:");
- doc2.setFont(new Font("Lucida Grande", Font.BOLD, 13));
- doc2.setBounds(12, 115, 100, 30);
- getContentPane().add(doc2);
- doc3 = new JLabel("СНИЛС:");
- doc3.setFont(new Font("Lucida Grande", Font.BOLD, 13));
- doc3.setBounds(12, 140, 100, 30);
- getContentPane().add(doc3);
- doc4 = new JLabel("Регистрация:");
- doc4.setFont(new Font("Lucida Grande", Font.BOLD, 13));
- doc4.setBounds(12, 165, 100, 30);
- getContentPane().add(doc4);
- doc5 = new JLabel("Полис:");
- doc5.setFont(new Font("Lucida Grande", Font.BOLD, 13));
- doc5.setBounds(12, 190, 100, 30);
- getContentPane().add(doc5);
- JLabel doc_name1 = new JLabel("Документ отсутствует");
- doc_name1.setFont(new Font("Lucida Grande", Font.ITALIC, 13));
- doc_name1.setBounds(110, 90, 200, 30);
- getContentPane().add(doc_name1);
- JLabel doc_name2 = new JLabel("Документ отсутствует");
- doc_name2.setFont(new Font("Lucida Grande", Font.ITALIC, 13));
- doc_name2.setBounds(110, 115, 200, 30);
- getContentPane().add(doc_name2);
- doc_name3 = new JLabel("Документ отсутствует");
- doc_name3.setFont(new Font("Lucida Grande", Font.ITALIC, 13));
- doc_name3.setBounds(110, 140, 200, 30);
- getContentPane().add(doc_name3);
- doc_name4 = new JLabel("Документ отсутствует");
- doc_name4.setFont(new Font("Lucida Grande", Font.ITALIC, 13));
- doc_name4.setBounds(110, 165, 200, 30);
- getContentPane().add(doc_name4);
- doc_name5 = new JLabel("Документ отсутствует");
- doc_name5.setFont(new Font("Lucida Grande", Font.ITALIC, 13));
- doc_name5.setBounds(110, 190, 200, 30);
- getContentPane().add(doc_name5);
- JButton btnAdd1 = new JButton("Загрузить");
- btnAdd1.setBounds(350, 90, 110, 25);
- btnAdd1.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e)
- {
- int res = openFile.showDialog(null, "Выберите файл: ");
- if (res == JFileChooser.APPROVE_OPTION)
- {
- doc_name1.setText(openFile.getSelectedFile().getName());
- try {
- InsertData("Passport", new FileInputStream(new File(openFile.getSelectedFile().getAbsolutePath())));
- } catch (FileNotFoundException e1) {
- e1.printStackTrace();
- }
- }
- };
- });
- getContentPane().add(btnAdd1);
- JButton btnAdd2 = new JButton("Загрузить");
- btnAdd2.setBounds(350, 115, 110, 25);
- btnAdd2.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e)
- {
- int res = openFile.showDialog(null, "Выберите файл: ");
- if (res == JFileChooser.APPROVE_OPTION)
- {
- doc_name2.setText(openFile.getSelectedFile().getName());
- try {
- InsertData("Claim", new FileInputStream(new File(openFile.getSelectedFile().getAbsolutePath())));
- } catch (FileNotFoundException e1) {
- e1.printStackTrace();
- }
- }
- };
- });
- getContentPane().add(btnAdd2);
- btnAdd3 = new JButton("Загрузить");
- btnAdd3.setBounds(350, 140, 110, 25);
- btnAdd3.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e) {
- int res = openFile.showDialog(null, "Выберите файл: ");
- if (res == JFileChooser.APPROVE_OPTION) {
- doc_name3.setText(openFile.getSelectedFile().getName());
- try {
- InsertData("SNILS", new FileInputStream(new File(openFile.getSelectedFile().getAbsolutePath())));
- } catch (FileNotFoundException e1) {
- e1.printStackTrace();
- }
- }
- };
- });
- getContentPane().add(btnAdd3);
- btnAdd4 = new JButton("Загрузить");
- btnAdd4.setBounds(350, 165, 110, 25);
- btnAdd4.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e) {
- int res = openFile.showDialog(null, "Выберите файл: ");
- if (res == JFileChooser.APPROVE_OPTION) {
- doc_name4.setText(openFile.getSelectedFile().getName());
- try {
- InsertData("Registration", new FileInputStream(new File(openFile.getSelectedFile().getAbsolutePath())));
- } catch (FileNotFoundException e1) {
- e1.printStackTrace();
- }
- }
- };
- });
- getContentPane().add(btnAdd4);
- btnAdd5 = new JButton("Загрузить");
- btnAdd5.setBounds(350, 190, 110, 25);
- btnAdd5.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e) {
- int res = openFile.showDialog(null, "Выберите файл: ");
- if (res == JFileChooser.APPROVE_OPTION) {
- doc_name5.setText(openFile.getSelectedFile().getName());
- try {
- InsertData("Policy", new FileInputStream(new File(openFile.getSelectedFile().getAbsolutePath())));
- } catch (FileNotFoundException e1) {
- e1.printStackTrace();
- }
- }
- };
- });
- getContentPane().add(btnAdd5);
- String[] currentTemplate = { "Дарственная", "Бракосочетание", "Страхование жизни" };
- JComboBox comboBox = new JComboBox(currentTemplate);
- comboBox.setSelectedIndex(0);
- selectedTemplate = comboBox.getSelectedItem().toString();
- SetVisibility();
- comboBox.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e)
- {
- selectedTemplate = comboBox.getSelectedItem().toString();
- SetVisibility();
- }
- });
- comboBox.setBounds(322, 10, 138, 30);
- getContentPane().add(comboBox);
- JButton btnExit = new JButton("Выход");
- btnExit.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- btnExit.setBounds(408, 243, 86, 29);
- getContentPane().add(btnExit);
- lblError = new JLabel("Пользователь отсутствует");
- lblError.setBounds(12, 73, 355, 16);
- lblError.setFont(new Font("Lucida Grande", Font.BOLD, 13));
- lblError.setForeground(Color.RED);
- lblError.setVisible(false);
- getContentPane().add(lblError);
- }
- private void SetVisibility()
- {
- if (selectedTemplate == "Дарственная")
- {
- doc3.setVisible(false);
- doc4.setVisible(false);
- doc5.setVisible(false);
- doc_name3.setVisible(false);
- doc_name4.setVisible(false);
- doc_name5.setVisible(false);
- btnAdd3.setVisible(false);
- btnAdd4.setVisible(false);
- btnAdd5.setVisible(false);
- }
- else if (selectedTemplate == "Страхование жизни")
- {
- doc3.setVisible(true);
- doc4.setVisible(true);
- doc5.setVisible(true);
- doc_name3.setVisible(true);
- doc_name4.setVisible(true);
- doc_name5.setVisible(true);
- btnAdd3.setVisible(true);
- btnAdd4.setVisible(true);
- btnAdd5.setVisible(true);
- }
- else if (selectedTemplate == "Бракосочетание")
- {
- doc3.setVisible(true);
- doc4.setVisible(true);
- doc5.setVisible(false);
- doc_name3.setVisible(true);
- doc_name4.setVisible(true);
- doc_name5.setVisible(false);
- btnAdd3.setVisible(true);
- btnAdd4.setVisible(true);
- btnAdd5.setVisible(false);
- }
- }
- public void GetData()
- {
- try
- {
- Class.forName("com.mysql.cj.jdbc.Driver");
- connection = DriverManager.getConnection(path, "admin", "");
- statement = connection.createStatement();
- String sql = "Select * from Users where Username='" + username.getText().toString() + "' and Type='User'";
- ResultSet rs = statement.executeQuery(sql);
- if (!rs.next())
- lblError.setVisible(true);
- else
- {
- lblError.setText("Текущий пользователь: " + username.getText().toString());
- lblError.setForeground(Color.GREEN);
- lblError.setVisible(true);
- }
- connection.close();
- }
- catch(Exception e)
- {
- System.out.print(e);
- }
- }
- private void InsertData(String fileType, InputStream inputStream)
- {
- try
- {
- PreparedStatement st = null;
- Class.forName("com.mysql.cj.jdbc.Driver");
- connection = DriverManager.getConnection(path, "admin", "");
- statement = connection.createStatement();
- String str = "SELECT ID FROM Users WHERE Username ='" + username.getText().toString() + "'";
- ResultSet rs = statement.executeQuery(str);
- rs.next();
- String sql = "INSERT INTO AllFiles VALUES (NULL, '" + rs.getInt(1) + "','" + fileType + "',?,'" + 0 + "');";
- st = connection.prepareStatement(sql);
- st.setBinaryStream(1, inputStream);
- st.executeUpdate();
- connection.close();
- }
- catch(Exception e)
- {
- System.out.print(e);
- }
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- // TODO Auto-generated method stub
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement