团队作业(五):冲刺总结4

团队作业(五):冲刺总结4

项目名:电子公文传输系统

成员分工:熊悠越(前端开发)、罗杰逊+谷丰宇(后端开发)、陈夏林(数据库管理)、董准(系统测试与维护)

日期:2023.12.11

今日任务完成情况
前后端部分代码

import java.io.*;
import java.net.*;
public class FileServer extends Thread{
	private static Socket s;
	private static ServerSocket serverSocket;
	private File source = new File("C:\\Users\\14914\\Desktop\\test\\moren55.txt");//服务端显示文件的存放位置
	static ServerSocket server;
	//6788端口负责向客户端发送文件
	static {
		try {
			server = new ServerSocket(6788);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public FileServer(Socket s, File source) throws IOException {
		super();
		this.s = s;
		this.source = source;
	}

	/**
	 * 获取想要客户端下载的目标文件的文件名
	 * @param s
	 * @return
	 * @throws IOException
	 */
	public static String getfilepath(Socket s) throws IOException {
		String name = null;
		InputStream is = null;
		try {
			//读取文件名
			is = s.getInputStream();
			int len1;
			byte[] bs = new byte[1024];
			len1 = is.read(bs);
			name = new String(bs, 0, len1);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return name;
	}

	@Override
	public void run() {
		DataInputStream bis = null;
		DataOutputStream bos = null;
			try {
//				//获取源文件的输入流
				System.out.println(source.getAbsolutePath());
				bis = new DataInputStream(new FileInputStream(source));
				//获取socket的输出流并包装
				Socket s = server.accept();
				bos = new DataOutputStream(s.getOutputStream());
				byte[] b = new byte[1027 * 9];
				int len = 0;
				System.out.println("向 " + s.getInetAddress().getHostAddress() + "开始传输....");
				while ((len = bis.read(b)) != -1) {
					bos.write(b, 0, len);
				}
				System.out.println("向 " + s.getInetAddress().getHostAddress() + "传输完成!");
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				try {
					if (bos != null) bos.flush();bos.close();
					if (bis != null) bis.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
	}

	public void netStartServer() throws IOException {
		System.out.println("SOFEEM文件服务器已启动,等待连接...");
		//循环监听是否有客户端上传到服务器文件
		new FileTransferServer().start();
		while(true){
			File source = new File(new FileTree().serverfilename);
			Socket s = server.accept();
			System.out.println(s.getInetAddress().getHostAddress()+"进入服务器,准备传输...");
			source = new File(getfilepath(s));
			//根据每一个连接的客户端启动一条子线程
			new FileServer(s, source).start();
		}
	}

	public  static void main(String[] args) throws IOException {
		System.out.println("SOFEEM文件服务器已启动,等待连接...");
		//循环监听是否有客户端上传到服务器文件
		new FileTransferServer().start();
		while(true){
			File source = new File(new FileTree().serverfilename);
			Socket s = server.accept();
			System.out.println(s.getInetAddress().getHostAddress()+"进入服务器,准备传输...");
			source = new File(getfilepath(s));
			//根据每一个连接的客户端启动一条子线程
			new FileServer(s, source).start();
		}
	}

 }

登录部分代码


import java.awt.BorderLayout;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

 

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JRadioButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JPasswordField;

import javax.swing.JTextField;

import javax.swing.SwingConstants;

 

public class Login extends JFrame implements ActionListener

{

	private JPasswordField mima1 = new JPasswordField(30);    // 创建文本行组件, 30 列
    private JTextField zh1 = new JTextField(30);
    private	JButton dl1 = new JButton("登陆");
    private	JButton zb1 = new JButton("注册账号");
    private JLabel zh2 = new JLabel("账号:");
    private JLabel mima2 = new JLabel("密码:");
    BackgroundPanel bgp;
    JFrame f;
    String st5 = "1";
    String st6 = "0";

	public Login() 

	{

		f = new JFrame("登陆界面");
        f.setBounds(200, 150, 555, 420);
        f.setLayout(null);
        bgp=new BackgroundPanel((new ImageIcon("C:\\Users\\14914\\Desktop\\图片中转站\\背景\\2.jpg")).getImage());

		bgp.setBounds(0,0,555,188);
        zh1.setBounds(120, 190, 300, 40);
        mima1.setBounds(120, 238, 300, 40);
        dl1.setBounds(120, 300, 300, 46);
        zh2.setBounds(70, 190, 50, 40);
        zb1.setBounds(0, 350, 90, 25);
        mima2.setBounds(70, 238, 50, 40);
        // 把组件添加进窗口f中
        f.add(mima1);
        f.add(zh1);
        f.add(dl1);
        f.add(zb1);
        f.add(zh2);
        f.add(mima2);
        f.add(bgp);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
		
        KeyListener key_Listener = new KeyListener()

		{

        	public void keyTyped(KeyEvent e) {}

			public void keyReleased(KeyEvent e){}

			public void keyPressed(KeyEvent e){

				if(e.getKeyChar() == KeyEvent.VK_ENTER )

				{
					PreparedStatement ps=null;
		            Connection ct=null;
		            ResultSet rs=null;
		            String st1 = "null";
		            {
		            	try {
		                //1.加载驱动
							Class.forName("com.mysql.cj.jdbc.Driver");
		                //2.得到链接 127.0.0.1:1433
		                ct=DriverManager.getConnection
		                ("jdbc:mysql://127.0.0.1:3307/myfiletra?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2B8","root","123456");
		               String sql="select password from user where id = ?";
		                ps=ct.prepareStatement(sql);
		                //给?赋值
		                ps.setString(1, zh1.getText());
		                rs=ps.executeQuery();
		                while(rs.next()){
		                st1=rs.getString(1).trim();
		                }
		            }catch(Exception d) {
		                d.printStackTrace();
		            }finally {
		                try {
		                    if(rs!=null)rs.close();
		                    if(ps!=null)ps.close();
		                    if(ct!=null)ct.close();
		                }catch(Exception d) {
		                    d.printStackTrace();
		                }
		            }
					if(st1.equals(String.valueOf(mima1.getPassword())))

					{
			            f.setVisible(false);
						JOptionPane.showMessageDialog(null, "登录成功,欢迎到来!");
						//显示信息提示框
						(new FileTree()).show(true);;

					}
					else
					{
						JOptionPane.showMessageDialog(null, "用户或密码错误!请从新登录!");
						//显示信息提示框
						zh1.setText("");
						mima1.setText("");

					}

				}
				}

			}
		};
		mima1.addKeyListener(key_Listener);
		dl1.addActionListener(this); //登录增加事件监听
		this.pack();  		//表示随着面板自动调整大小
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	}
	public void actionPerformed(ActionEvent q)  //
	{
		if(q.getSource() == dl1) {
			PreparedStatement ps = null;
			Connection ct = null;
			ResultSet rs = null;
			String st1 = "null";
			try {
				//1.加载驱动
				Class.forName("com.mysql.cj.jdbc.Driver");
				//2.得到链接 127.0.0.1:1433
				ct = DriverManager.getConnection
						("jdbc:mysql://127.0.0.1:3307/myfiletra?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2B8","root","123456");
				String sql = "select id from user where id = ?";
				ps = ct.prepareStatement(sql);
				//给?赋值
				ps.setString(1, zh1.getText());
				rs = ps.executeQuery();
				while (rs.next()) {
					st1 = rs.getString(1).trim();
				}
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				try {
					if (rs != null) rs.close();
					if (ps != null) ps.close();
					if (ct != null) ct.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			if(st1.equals(String.valueOf(mima1.getPassword())))

			{
				f.setVisible(false);
				JOptionPane.showMessageDialog(null, "登录成功,欢迎到来!");
				//显示信息提示框
				(new FileTree()).show(true);;

			}
			else
			{
				JOptionPane.showMessageDialog(null, "用户或密码错误!请从新登录!");
				//显示信息提示框
				zh1.setText("");
				mima1.setText("");
			}
		}
		}



	public static void main(String[] args)

	{

		JFrame.setDefaultLookAndFeelDecorated(true);
		new Login();

	}

}

任务分配:
以上代码均已托管至公文传输系统实现代码/冲刺

冲刺第四天

第四天 负责人 工作量
调试数据库 陈夏林 3
数据库初始化设置 陈夏林 1
完善文件上传下载模块 谷丰宇、罗杰逊 2
基于角色的权限控制设计 谷丰宇、罗杰逊 1
适配增加的功能 谷丰宇、罗杰逊 1
完善用户功能接口 董准、熊悠越 2
根据后端接口完善前端界面 董准、熊悠越 3
明日任务安排 董准 1

明日任务安排

第五天 工作量
继续调试数据库 2
完善接口 3
完成数据库初始化设置 2
主干功能完善 2
完善文件上传下载模块 2
适配增加的功能 2
风格化样式 2
根据后端接口完善前端界面 3
明日任务安排 1
posted @ 2023-12-11 18:42  20211428谷丰宇  阅读(11)  评论(0编辑  收藏  举报