⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1.bak

📁 的反反复复反反复复反反复复反反复复反反复复反反复复方法
💻 BAK
字号:
package dao;

import java.util.*;
import java.io.*;
import java.sql.*;
import com.kettas.common.*;

import entity.Admin;
import entity.AdminDAO;
import exception.InfrastructureException;

public class FileAdminDAOImpl implements AdminDAO {

	public FileAdminDAOImpl() throws InfrastructureException {
		Admin superadmin = new Admin();

		superadmin.setId(Long.parseLong("0"));
		superadmin.setLoginName("kettas");
		superadmin.setLoginPassword("kettas");
		superadmin.setName("kettas");
		superadmin.setPhone("62790000");
		superadmin.setEmail("kettas@kettas.com.cn");
		superadmin.setEnrollDate(null);

		try {
			FileOutputStream file1 = new FileOutputStream("superadmin.dat");
			ObjectOutputStream fo = new ObjectOutputStream(file1);
			fo.writeObject(superadmin);
			fo.flush();
		} catch (IOException e) {
		}
		try {
			FileInputStream fileIn = new FileInputStream("superadmin.dat");
			ObjectInputStream fin = new ObjectInputStream(fileIn);
			while (true) {
				Object o = fin.readObject();
				Admin a = (Admin) o;
			//	System.out.println(a);
			}
		} catch (FileNotFoundException e) {

		} catch (IOException e) {

		} catch (ClassNotFoundException e) {

		}
		/*
		 * try { FileOutputStream file = new FileOutputStream("a.txt");
		 * PrintWriter pw = new PrintWriter(file); Long Id = superadmin.getId();
		 * String loginName = superadmin.getLoginName(); String
		 * loginPassword=superadmin.getLoginPassword(); String
		 * name=superadmin.getName(); String phone=superadmin.getPhone(); String
		 * email=superadmin.getEmail(); Date
		 * enrollDate=superadmin.getEnrollDate(); pw.println("Id:"+Id);
		 * pw.println("loginName:"+" "+loginName); pw.println("loginPassword:"+"
		 * "+loginPassword); pw.println("name:"+ " "+name);
		 * pw.println("phone:"+" "+phone); pw.println("email:"+" "+email);
		 * pw.println("enrollDate:"+" "+enrollDate); pw.flush(); } catch
		 * (FileNotFoundException e) { // TODO Auto-generated catch block
		 * e.printStackTrace(); }
		 */

		// System.out.println(superadmin.getEmail());
	}

	public void deleteAdmin(Long adminId) throws InfrastructureException {
        System.out.println(adminId);
		
		ObjectInputStream fin = null;
		try {
			FileInputStream fileIn = new FileInputStream("superadmin.dat");
			fin = new ObjectInputStream(fileIn);
		} catch (FileNotFoundException e) {
		} catch (IOException e) {
		}
		while (true) {
			Object o = null;
			try {
				o = fin.readObject();
			} catch (IOException e) {
			} catch (ClassNotFoundException e) {
			}
			Admin a = (Admin) o;
			while (true) {
				ObjectOutputStream fo = null;
				try {
					FileOutputStream file1 = new FileOutputStream(
							"superadmin.dat");
					fo = new ObjectOutputStream(file1);
					if (a.getId() == adminId)
						continue;
					fo.writeObject(a);
				} catch (FileNotFoundException e) {
				} catch (IOException e) {
					try {
						fo.close();
					} catch (IOException e1) {
					}
				}
			}
		}
	}

	public void insertAdmin(Admin admin) throws InfrastructureException {
		System.out.println("请输入您的用户ID:");
		String id = SystemIn.readString();
		admin.setId(Long.parseLong(id));
		System.out.println("请输入您的名字:");
		String name = SystemIn.readString();
		admin.setName(name);
		System.out.println("请输入您的登录名:");
		String loginName = SystemIn.readString();
		admin.setLoginName(loginName);
		System.out.println("请输入您的登录密码:");
		String loginPassword = SystemIn.readString();
		admin.setLoginPassword(loginPassword);
		System.out.println("请输入您的电话:");
		String phone = SystemIn.readString();
		admin.setPhone(phone);
		System.out.println("请输入您的邮箱:");
		String email = SystemIn.readString();
		admin.setEmail(email);
		System.out.println("请输入您的注册日期:");
		// String enrollDate = SystemIn.readString();
		admin.setEnrollDate(null);
		ObjectOutputStream font = null;
		try {
			FileOutputStream file = new FileOutputStream("superadmin.dat");
			font = new ObjectOutputStream(file);
			font.writeObject(admin);
		} catch (FileNotFoundException e) {
		} catch (IOException e) {
			try {
				font.close();
			} catch (IOException e1) {
			}
		}
	}

	public Admin selectAdminById(Long admin) throws InfrastructureException {
		Admin o = null;
		ObjectInputStream fin = null;
		try {
			FileInputStream file1 = new FileInputStream("superadmin.dat");
			fin = new ObjectInputStream(file1);
			while (true) {
				Object o1 = fin.readObject();
				Admin admin1 = (Admin) o1;
				// System.out.println(o1.getClass().getName());
				if (admin1.getId() == admin)
					o = (Admin) o1;
			}
		} catch (FileNotFoundException e) {

		} catch (IOException e) {
			try {
				fin.close();
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		} catch (ClassNotFoundException e) {

		}
		return o;
	}

	public Admin selectAdminByLoginName(String loginName)
			throws InfrastructureException {
		// List<Admin> list = new ArrayList<Admin>();
		Admin admin = null;
		ObjectInputStream fin = null;
		try {
			FileInputStream file1 = new FileInputStream("superadmin.dat");
			fin = new ObjectInputStream(file1);
			while (true) {
				Object o = fin.readObject();
				Admin a = (Admin) o;
				if (a.getLoginName().equals(loginName)) {
					admin = a;
					// return a;
				}

			}
		} catch (FileNotFoundException e) {

		} catch (IOException e) {
			try {
				fin.close();
			} catch (IOException e1) {
			}

		} catch (ClassNotFoundException e) {

	}

		return admin; 

	}

	public Collection selectAllAdmin() throws InfrastructureException {
		List list = new ArrayList();
		ObjectInputStream fin = null;
		Admin admin;
		try {
			FileInputStream file = new FileInputStream("superadmin.dat");
			fin = new ObjectInputStream(file);
			while (true) {
				Object o = fin.readObject();
				Admin a = (Admin) o;
				list.add(a);
			}
		} catch (FileNotFoundException e) {

		} catch (IOException e) {
			try {
				fin.close();
			} catch (IOException e1) {
			}

		} catch (ClassNotFoundException e) {

		}
		return list;
	}

	public void updateAdmin(Admin admin) throws InfrastructureException {

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -