日期:2018.9.28

星期五

博客期:013

  说到这里,就二话不多说了!这次研习的是与Excel表相关联的方法

  1、导入jar包(需要自己下载)

  2、AccountManager类的实现(关键看非重复部分!)

package pop;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Calendar;
import java.util.Scanner; import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException; public class AccountManager {
//----------------<数据库>-----------------//
//数据组
private Account ku[] = new Account[5];
//记录名称
private String Infor = "files/accountinformation.xls";
private String List = "files/accountlist.xls";
private String Copy = "files/Lin.xls";
private String Today = "2018-09-28";
//----------------<界面函数>---------------//
//初始界面
public void FirstWin() throws IOException, RowsExceededException, WriteException, BiffException{
System.out.println("***************************************************************");
System.out.println(" 欢迎使用中国工商银行自动柜员系统");
System.out.println("***************************************************************");
System.out.println(" 请输入您的账号:");
Scanner sc = new Scanner(System.in);
String x = sc.next();
int existfor = 5;//此处用于测试是否账号不存在
for(int i=0;i<5;i++)//检测数组中是否存有该数据!
if(ku[i].GetaccountID().compareTo(x)==0)
{
existfor = i;
break;
}
if(existfor==5)
{
System.out.println(" #:该卡不是工行卡!");
FirstWin();
}
else
SecondWin(existfor); }
//密码输入界面
public void SecondWin(int pass) throws IOException, RowsExceededException, WriteException, BiffException{
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].Getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println(" 请输入您的密码:");
int times = 0;//记录输入密码的次数
Scanner sc = new Scanner (System.in);
while(times<3){
String saving = sc.nextLine();
if(ku[pass].Getaccountpassword().compareTo(saving)!=0)
System.out.println("密码录入错误");
else
break;
times++;
}
if(times==3)
FirstWin();
else
MainWin(pass);
}
//主界面
void MainWin(int pass) throws IOException, RowsExceededException, WriteException, BiffException{
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].Getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 1、存款;");
System.out.println(" 2、取款;");
System.out.println(" 3、转账汇款;");
System.out.println(" 4、修改密码;");
System.out.println(" 5、查询金额;");
System.out.println("****************************************************************");
System.out.println(" 请输入:");
Scanner sc = new Scanner (System.in);
int temp = sc.nextInt();
switch(temp)
{
case 1:ku[pass].Setoperatetype(1);writefile();fun1(pass);break;
case 2:ku[pass].Setoperatetype(2);writefile();fun2(pass);break;
case 3:ku[pass].Setoperatetype(3);writefile();fun3(pass);break;
case 4:ku[pass].Setoperatetype(4);writefile();fun4(pass);break;
case 5:ku[pass].Setoperatetype(5);writefile();fun5(pass);break;
default:MainWin(pass);break;
}
}
//存款界面
public void fun1(int pass) throws IOException, RowsExceededException, WriteException, BiffException{
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].Getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 请输入存款金额;");
Scanner sc = new Scanner (System.in);
if(sc.hasNext("q"))
FirstWin();
else
{
int JinE = sc.nextInt();//记录金额
if(JinE<=0)
{
System.out.println(" #:输入金额有误");
fun1(pass);
}
else
{
ku[pass].Setamount(ku[pass].Getamount()+JinE);
ku[pass].Setaccountbalance(ku[pass].Getaccountbalance()+JinE);
//-----------------------[数据载入文档]
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].Getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 当前账户存款操作成功。");
System.out.println(" 当前账户余额为:"+ku[pass].Getaccountbalance()+"元");
//----------------------------------------------------<以下为文件更新阶段
Copyfile();
File f = new File(List);
WritableWorkbook workbook = Workbook.createWorkbook(f);
WritableSheet sheet = workbook.createSheet("Test",0);
for (int i = 0; i < 1; i++)
{
Label lab = new Label(0,i,"账号");
sheet.addCell(lab);
lab = new Label(1,i,"操作日期");
sheet.addCell(lab);
lab = new Label(2,i,"操作内容");
sheet.addCell(lab);
lab = new Label(3,i,"操作金额");
sheet.addCell(lab);
}
for(int i=1;i<2;i++)
{
Label lab = new Label(0,i,ku[pass].GetaccountID());
sheet.addCell(lab);
lab = new Label(1,i,Today);
sheet.addCell(lab);
lab = new Label(2,i,"SaveMoney");
sheet.addCell(lab);
lab = new Label(3,i,Integer.toString(JinE));
sheet.addCell(lab);
}
Workbook readwb = Workbook.getWorkbook(new FileInputStream(Copy));
Sheet readsheet = readwb.getSheet(0);
int rsColumns = readsheet.getColumns();
int rsRows = readsheet.getRows();
for(int i=0;i<rsRows;i++)
{
for(int j=0;j<rsColumns;j++)
{
Cell cell = readsheet.getCell(j,i);
Label lab = new Label(j,i+2,cell.getContents());
sheet.addCell(lab);
}
}
workbook.write();
workbook.close();
writefile();
//----------------------------------------
MainWin(pass);
}
}
}
//取款界面
public void fun2(int pass) throws IOException, RowsExceededException, WriteException, BiffException{
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].Getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 当前账户每日可以支取2万元。");
System.out.println(" 1、100元");
System.out.println(" 2、500元");
System.out.println(" 3、1000元");
System.out.println(" 4、1500元");
System.out.println(" 5、2000元");
System.out.println(" 6、5000元;");
System.out.println(" 7、其他金额");
System.out.println(" 8、退卡");
System.out.println(" 9、返回");
System.out.println("****************************************************************");
System.out.println(" #:请选择");
Scanner sc = new Scanner (System.in);
int choice = sc.nextInt();
switch(choice){
case 1:
{
if(ku[pass].Getaccountbalance()<100)
{
System.out.println("账户余额不足");
fun2(pass);
}
else
{
ku[pass].Setamount(ku[pass].Getamount()+100);
ku[pass].Setaccountbalance(ku[pass].Getaccountbalance()-100);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].Getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 当前账户取款操作100元成功。");
System.out.println(" 当前账户余额为:"+ku[pass].Getaccountbalance()+"元");
//----------------------------------------------------<以下为文件更新阶段
Copyfile();
File f = new File(List);
WritableWorkbook workbook = Workbook.createWorkbook(f);
WritableSheet sheet = workbook.createSheet("Test",0);
for (int i = 0; i < 1; i++)
{
Label lab = new Label(0,i,"账号");
sheet.addCell(lab);
lab = new Label(1,i,"操作日期");
sheet.addCell(lab);
lab = new Label(2,i,"操作内容");
sheet.addCell(lab);
lab = new Label(3,i,"操作金额");
sheet.addCell(lab);
}
for(int i=1;i<2;i++)
{
Label lab = new Label(0,i,ku[pass].GetaccountID());
sheet.addCell(lab);
lab = new Label(1,i,Today);
sheet.addCell(lab);
lab = new Label(2,i,"GetMoney");
sheet.addCell(lab);
lab = new Label(3,i,Integer.toString(100));
sheet.addCell(lab);
}
Workbook readwb = Workbook.getWorkbook(new FileInputStream(Copy));
Sheet readsheet = readwb.getSheet(0);
int rsColumns = readsheet.getColumns();
int rsRows = readsheet.getRows();
for(int i=0;i<rsRows;i++)
{
for(int j=0;j<rsColumns;j++)
{
Cell cell = readsheet.getCell(j,i);
Label lab = new Label(j,i+2,cell.getContents());
sheet.addCell(lab);
}
}
workbook.write();
workbook.close();
writefile();
//-----------------------------------
MainWin(pass);
}
break;
}
case 2:
{
if(ku[pass].Getaccountbalance()<500)
{
System.out.println("账户余额不足");
fun2(pass);
}
else
{
ku[pass].Setamount(ku[pass].Getamount()+500);
ku[pass].Setaccountbalance(ku[pass].Getaccountbalance()-500);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].Getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 当前账户取款操作500元成功。");
System.out.println(" 当前账户余额为:"+ku[pass].Getaccountbalance()+"元");
//----------------------------------------------------<以下为文件更新阶段
Copyfile();
File f = new File(List);
WritableWorkbook workbook = Workbook.createWorkbook(f);
WritableSheet sheet = workbook.createSheet("Test",0);
for (int i = 0; i < 1; i++)
{
Label lab = new Label(0,i,"账号");
sheet.addCell(lab);
lab = new Label(1,i,"操作日期");
sheet.addCell(lab);
lab = new Label(2,i,"操作内容");
sheet.addCell(lab);
lab = new Label(3,i,"操作金额");
sheet.addCell(lab);
}
for(int i=1;i<2;i++)
{
Label lab = new Label(0,i,ku[pass].GetaccountID());
sheet.addCell(lab);
lab = new Label(1,i,Today);
sheet.addCell(lab);
lab = new Label(2,i,"GetMoney");
sheet.addCell(lab);
lab = new Label(3,i,Integer.toString(500));
sheet.addCell(lab);
}
Workbook readwb = Workbook.getWorkbook(new FileInputStream(Copy));
Sheet readsheet = readwb.getSheet(0);
int rsColumns = readsheet.getColumns();
int rsRows = readsheet.getRows();
for(int i=0;i<rsRows;i++)
{
for(int j=0;j<rsColumns;j++)
{
Cell cell = readsheet.getCell(j,i);
Label lab = new Label(j,i+2,cell.getContents());
sheet.addCell(lab);
}
}
workbook.write();
workbook.close();
writefile();
//-----------------------------------
MainWin(pass);
}
break;
}
case 3:
{
if(ku[pass].Getaccountbalance()<1000)
{
System.out.println("账户余额不足");
fun2(pass);
}
else
{
ku[pass].Setamount(ku[pass].Getamount()+1000);
ku[pass].Setaccountbalance(ku[pass].Getaccountbalance()-1000);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].Getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 当前账户取款操作1000元成功。");
System.out.println(" 当前账户余额为:"+ku[pass].Getaccountbalance()+"元");
//----------------------------------------------------<以下为文件更新阶段
Copyfile();
File f = new File(List);
WritableWorkbook workbook = Workbook.createWorkbook(f);
WritableSheet sheet = workbook.createSheet("Test",0);
for (int i = 0; i < 1; i++)
{
Label lab = new Label(0,i,"账号");
sheet.addCell(lab);
lab = new Label(1,i,"操作日期");
sheet.addCell(lab);
lab = new Label(2,i,"操作内容");
sheet.addCell(lab);
lab = new Label(3,i,"操作金额");
sheet.addCell(lab);
}
for(int i=1;i<2;i++)
{
Label lab = new Label(0,i,ku[pass].GetaccountID());
sheet.addCell(lab);
lab = new Label(1,i,Today);
sheet.addCell(lab);
lab = new Label(2,i,"GetMoney");
sheet.addCell(lab);
lab = new Label(3,i,Integer.toString(1000));
sheet.addCell(lab);
}
Workbook readwb = Workbook.getWorkbook(new FileInputStream(Copy));
Sheet readsheet = readwb.getSheet(0);
int rsColumns = readsheet.getColumns();
int rsRows = readsheet.getRows();
for(int i=0;i<rsRows;i++)
{
for(int j=0;j<rsColumns;j++)
{
Cell cell = readsheet.getCell(j,i);
Label lab = new Label(j,i+2,cell.getContents());
sheet.addCell(lab);
}
}
workbook.write();
workbook.close();
writefile();
//-----------------------------------
MainWin(pass);
}
break;
}
case 4:
{
if(ku[pass].Getaccountbalance()<1500)
{
System.out.println("账户余额不足");
fun2(pass);
}
else
{
ku[pass].Setamount(ku[pass].Getamount()+1500);
ku[pass].Setaccountbalance(ku[pass].Getaccountbalance()-1500);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].Getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 当前账户取款操作1500元成功。");
System.out.println(" 当前账户余额为:"+ku[pass].Getaccountbalance()+"元");
//----------------------------------------------------<以下为文件更新阶段
Copyfile();
File f = new File(List);
WritableWorkbook workbook = Workbook.createWorkbook(f);
WritableSheet sheet = workbook.createSheet("Test",0);
for (int i = 0; i < 1; i++)
{
Label lab = new Label(0,i,"账号");
sheet.addCell(lab);
lab = new Label(1,i,"操作日期");
sheet.addCell(lab);
lab = new Label(2,i,"操作内容");
sheet.addCell(lab);
lab = new Label(3,i,"操作金额");
sheet.addCell(lab);
}
for(int i=1;i<2;i++)
{
Label lab = new Label(0,i,ku[pass].GetaccountID());
sheet.addCell(lab);
lab = new Label(1,i,Today);
sheet.addCell(lab);
lab = new Label(2,i,"GetMoney");
sheet.addCell(lab);
lab = new Label(3,i,Integer.toString(1500));
sheet.addCell(lab);
}
Workbook readwb = Workbook.getWorkbook(new FileInputStream(Copy));
Sheet readsheet = readwb.getSheet(0);
int rsColumns = readsheet.getColumns();
int rsRows = readsheet.getRows();
for(int i=0;i<rsRows;i++)
{
for(int j=0;j<rsColumns;j++)
{
Cell cell = readsheet.getCell(j,i);
Label lab = new Label(j,i+2,cell.getContents());
sheet.addCell(lab);
}
}
workbook.write();
workbook.close();
writefile();
//-----------------------------------
MainWin(pass);
}
break;
}
case 5:
{
if(ku[pass].Getaccountbalance()<2000)
{
System.out.println("账户余额不足");
fun2(pass);
}
else
{
ku[pass].Setamount(ku[pass].Getamount()+2000);
ku[pass].Setaccountbalance(ku[pass].Getaccountbalance()-2000);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].Getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 当前账户取款操作2000元成功。");
System.out.println(" 当前账户余额为:"+ku[pass].Getaccountbalance()+"元");
//----------------------------------------------------<以下为文件更新阶段
Copyfile();
File f = new File(List);
WritableWorkbook workbook = Workbook.createWorkbook(f);
WritableSheet sheet = workbook.createSheet("Test",0);
for (int i = 0; i < 1; i++)
{
Label lab = new Label(0,i,"账号");
sheet.addCell(lab);
lab = new Label(1,i,"操作日期");
sheet.addCell(lab);
lab = new Label(2,i,"操作内容");
sheet.addCell(lab);
lab = new Label(3,i,"操作金额");
sheet.addCell(lab);
}
for(int i=1;i<2;i++)
{
Label lab = new Label(0,i,ku[pass].GetaccountID());
sheet.addCell(lab);
lab = new Label(1,i,Today);
sheet.addCell(lab);
lab = new Label(2,i,"GetMoney");
sheet.addCell(lab);
lab = new Label(3,i,Integer.toString(2000));
sheet.addCell(lab);
}
Workbook readwb = Workbook.getWorkbook(new FileInputStream(Copy));
Sheet readsheet = readwb.getSheet(0);
int rsColumns = readsheet.getColumns();
int rsRows = readsheet.getRows();
for(int i=0;i<rsRows;i++)
{
for(int j=0;j<rsColumns;j++)
{
Cell cell = readsheet.getCell(j,i);
Label lab = new Label(j,i+2,cell.getContents());
sheet.addCell(lab);
}
}
workbook.write();
workbook.close();
writefile();
//-----------------------------------
MainWin(pass);
}
break;
}
case 6:
{
if(ku[pass].Getaccountbalance()<5000)
{
System.out.println("账户余额不足");
fun2(pass);
}
else
{
ku[pass].Setamount(ku[pass].Getamount()+5000);
ku[pass].Setaccountbalance(ku[pass].Getaccountbalance()-5000);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].Getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 当前账户取款操作5000元成功。");
System.out.println(" 当前账户余额为:"+ku[pass].Getaccountbalance()+"元");
//----------------------------------------------------<以下为文件更新阶段
Copyfile();
File f = new File(List);
WritableWorkbook workbook = Workbook.createWorkbook(f);
WritableSheet sheet = workbook.createSheet("Test",0);
for (int i = 0; i < 1; i++)
{
Label lab = new Label(0,i,"账号");
sheet.addCell(lab);
lab = new Label(1,i,"操作日期");
sheet.addCell(lab);
lab = new Label(2,i,"操作内容");
sheet.addCell(lab);
lab = new Label(3,i,"操作金额");
sheet.addCell(lab);
}
for(int i=1;i<2;i++)
{
Label lab = new Label(0,i,ku[pass].GetaccountID());
sheet.addCell(lab);
lab = new Label(1,i,Today);
sheet.addCell(lab);
lab = new Label(2,i,"GetMoney");
sheet.addCell(lab);
lab = new Label(3,i,Integer.toString(5000));
sheet.addCell(lab);
}
Workbook readwb = Workbook.getWorkbook(new FileInputStream(Copy));
Sheet readsheet = readwb.getSheet(0);
int rsColumns = readsheet.getColumns();
int rsRows = readsheet.getRows();
for(int i=0;i<rsRows;i++)
{
for(int j=0;j<rsColumns;j++)
{
Cell cell = readsheet.getCell(j,i);
Label lab = new Label(j,i+2,cell.getContents());
sheet.addCell(lab);
}
}
workbook.write();
workbook.close();
writefile();
//-----------------------------------
MainWin(pass);
}
break;
}
case 7:
{
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].Getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 请输入取款金额:");
int num = sc.nextInt();
if(ku[pass].Getaccountbalance()<num)
{
System.out.println("账户余额不足");
fun2(pass);
}
else
{
ku[pass].Setamount(ku[pass].Getamount()+num);
ku[pass].Setaccountbalance(ku[pass].Getaccountbalance()-num);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].Getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("****************************************************************");
System.out.println(" 当前账户取款操作"+num+"元成功。");
System.out.println(" 当前账户余额为:"+ku[pass].Getaccountbalance()+"元");
writefile();
//----------------------------------------------------<以下为文件更新阶段
Copyfile();
File f = new File(List);
WritableWorkbook workbook = Workbook.createWorkbook(f);
WritableSheet sheet = workbook.createSheet("Test",0);
for (int i = 0; i < 1; i++)
{
Label lab = new Label(0,i,"账号");
sheet.addCell(lab);
lab = new Label(1,i,"操作日期");
sheet.addCell(lab);
lab = new Label(2,i,"操作内容");
sheet.addCell(lab);
lab = new Label(3,i,"操作金额");
sheet.addCell(lab);
}
for(int i=1;i<2;i++)
{
Label lab = new Label(0,i,ku[pass].GetaccountID());
sheet.addCell(lab);
lab = new Label(1,i,Today);
sheet.addCell(lab);
lab = new Label(2,i,"GetMoney");
sheet.addCell(lab);
lab = new Label(3,i,Integer.toString(num));
sheet.addCell(lab);
}
Workbook readwb = Workbook.getWorkbook(new FileInputStream(Copy));
Sheet readsheet = readwb.getSheet(0);
int rsColumns = readsheet.getColumns();
int rsRows = readsheet.getRows();
for(int i=0;i<rsRows;i++)
{
for(int j=0;j<rsColumns;j++)
{
Cell cell = readsheet.getCell(j,i);
Label lab = new Label(j,i+2,cell.getContents());
sheet.addCell(lab);
}
}
workbook.write();
workbook.close();
writefile();
//-----------------------------------
MainWin(pass);
}
break;
}
case 8:
{
FirstWin();
break;
}
case 9:
{
MainWin(pass);
break;
}
default:fun2(pass);break;
}
}
//转账汇款界面
public void fun3(int pass) throws IOException, RowsExceededException, WriteException, BiffException{
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].Getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println(" 请输入转账账户;");
Scanner sc = new Scanner (System.in);
if(sc.hasNext("q"))
FirstWin();
String temp = sc.next();
int tube = 5;//记录账户
for(int i=0;i<5;i++){
if(ku[i].GetaccountID().compareTo(temp)==0)
{
tube = i;
break;
}
}
if(tube==5)
{
System.out.println(" #:该用户不存在");
fun3(pass);
}
else
{
fun3_half(pass,tube);
}
}
public void fun3_half(int pass,int pass_to) throws IOException, RowsExceededException, WriteException, BiffException{
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].Getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println(" 请输入转账金额;");
Scanner sc = new Scanner (System.in);
if(sc.hasNext("q"))
FirstWin();
int JinE= sc.nextInt();
if(JinE>ku[pass].Getaccountbalance())
{
System.out.println("账户余额不足");
fun3_half(pass,pass_to);
}
else if(JinE<=0)
fun3_half(pass,pass_to);
else
{
StringBuffer sxw = new StringBuffer(ku[pass_to].Getaccountname());
sxw.deleteCharAt(0);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].Getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println(" 请确认是否向*"+sxw+"转账"+JinE+"元。");
String makesure = sc.next();
if(sc.hasNext("q"))
FirstWin();
if(makesure.compareTo("Y")==0)
{
ku[pass].Setaccountbalance(ku[pass].Getaccountbalance()-JinE);
ku[pass].Setamount(ku[pass].Getamount()+JinE);
ku[pass_to].Setaccountbalance(ku[pass_to].Getaccountbalance()+JinE);
ku[pass_to].Setamount(ku[pass_to].Getamount()+JinE);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].Getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println(" 当前账户向*"+sxw+"转账"+JinE+"元。");
System.out.println(" 当前账户余额为:"+ku[pass].Getaccountbalance()+"元");
}
//----------------------------------------------------<以下为文件更新阶段
Copyfile();
File f = new File(List);
WritableWorkbook workbook = Workbook.createWorkbook(f);
WritableSheet sheet = workbook.createSheet("Test",0);
for (int i = 0; i < 1; i++)
{
Label lab = new Label(0,i,"账号");
sheet.addCell(lab);
lab = new Label(1,i,"操作日期");
sheet.addCell(lab);
lab = new Label(2,i,"操作内容");
sheet.addCell(lab);
lab = new Label(3,i,"操作金额");
sheet.addCell(lab);
}
for(int i=1;i<2;i++)
{
Label lab = new Label(0,i,ku[pass].GetaccountID());
sheet.addCell(lab);
lab = new Label(1,i,Today);
sheet.addCell(lab);
lab = new Label(2,i,"RemoveMoney");
sheet.addCell(lab);
lab = new Label(3,i,Integer.toString(JinE));
sheet.addCell(lab);
}
Workbook readwb = Workbook.getWorkbook(new FileInputStream(Copy));
Sheet readsheet = readwb.getSheet(0);
int rsColumns = readsheet.getColumns();
int rsRows = readsheet.getRows();
for(int i=0;i<rsRows;i++)
{
for(int j=0;j<rsColumns;j++)
{
Cell cell = readsheet.getCell(j,i);
Label lab = new Label(j,i+2,cell.getContents());
sheet.addCell(lab);
}
}
workbook.write();
workbook.close();
//-----------------------------------
MainWin(pass);
}
}
//修改密码界面
public void fun4(int pass) throws IOException, RowsExceededException, WriteException, BiffException{
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].Getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
String str1,str2;
System.out.println(" 请输入当前密码: ");
Scanner sc = new Scanner (System.in);
str1 = sc.next();
if(sc.hasNext("q"))
FirstWin();
if(ku[pass].Getaccountpassword().compareTo(str1)==0)
{
System.out.println(" 请输入修改密码:");
str1 = sc.next();
if(sc.hasNext("q"))
FirstWin();
System.out.println(" 请输入确认密码:");
str2 = sc.next();
if(sc.hasNext("q"))
FirstWin();
if(str1.compareTo(str2)==0)
{
ku[pass].Setaccountpassword(str1);
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].Getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println(" 当前账户密码修改成功");
//----------------------------------------------------<以下为文件更新阶段
Copyfile();
File f = new File(List);
WritableWorkbook workbook = Workbook.createWorkbook(f);
WritableSheet sheet = workbook.createSheet("Test",0);
for (int i = 0; i < 1; i++)
{
Label lab = new Label(0,i,"账号");
sheet.addCell(lab);
lab = new Label(1,i,"操作日期");
sheet.addCell(lab);
lab = new Label(2,i,"操作内容");
sheet.addCell(lab);
lab = new Label(3,i,"操作金额");
sheet.addCell(lab);
}
for(int i=1;i<2;i++)
{
Label lab = new Label(0,i,ku[pass].GetaccountID());
sheet.addCell(lab);
lab = new Label(1,i,Today);
sheet.addCell(lab);
lab = new Label(2,i,"ChangPassword");
sheet.addCell(lab);
lab = new Label(3,i,"**********");
sheet.addCell(lab);
}
Workbook readwb = Workbook.getWorkbook(new FileInputStream(Copy));
Sheet readsheet = readwb.getSheet(0);
int rsColumns = readsheet.getColumns();
int rsRows = readsheet.getRows();
for(int i=0;i<rsRows;i++)
{
for(int j=0;j<rsColumns;j++)
{
Cell cell = readsheet.getCell(j,i);
Label lab = new Label(j,i+2,cell.getContents());
sheet.addCell(lab);
}
}
workbook.write();
workbook.close();
writefile();
//-----------------------------------
MainWin(pass);
}
else
{
System.out.println(" 修改密码与确认密码不一致");
fun4(pass);
}
}
else
{
System.out.println(" 当前密码录入错误");
fun4(pass);
}
}
//查询金额界面
public void fun5(int pass) throws IOException, RowsExceededException, WriteException, BiffException{
System.out.println("***************************************************************");
System.out.println(" 欢迎"+ku[pass].Getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("***************************************************************");
System.out.println(" 当前账户余额为:"+ku[pass].Getaccountbalance()+"元");
System.out.println(" 账户清单信息为:");
int sx = 1;
Workbook readwb = Workbook.getWorkbook(new FileInputStream(Copy));
Sheet readsheet = readwb.getSheet(0);
int rsRows = readsheet.getRows();
Copyfile();
for(int i=0;i<rsRows;i++)
{
Cell cell = readsheet.getCell(0,i);
if(ku[pass].GetaccountID().compareTo(cell.getContents())==0)
{
cell = readsheet.getCell(1,i);
String t1 = cell.getContents();
cell = readsheet.getCell(2,i);
String t2 = cell.getContents();
cell = readsheet.getCell(3,i);
String t3 = cell.getContents();
System.out.println(sx+"、"+t1+" "+t2+" "+t3);
sx++;
}
}
MainWin(pass);
}
//----------------<构造函数>---------------//
private void ResetDate(){
int y,m,d;
Calendar cal=Calendar.getInstance();
y=cal.get(Calendar.YEAR);
m=cal.get(Calendar.MONTH);
d=cal.get(Calendar.DATE);
String ms;
m++;
if(m<10)
ms = (String)("0"+m);
else
ms = (String)(""+m);
String ds;
if(d<10)
ds = (String)("0"+d);
else
ds = (String)(""+d);
Today = (String)(y+"-"+ms+"-"+ds);
}
public AccountManager() throws BiffException, IOException{
for(int i=0;i<5;i++)
ku[i] = new Account();
ResetDate();
readfile();
}
//写入
public void writefile() throws IOException, RowsExceededException, WriteException{
WritableWorkbook workbook = Workbook.createWorkbook(new File(Infor));
WritableSheet sheet = workbook.createSheet("Test",0);
Label lab = new Label(0,0,"账号");
sheet.addCell(lab);
Label labs = new Label(1,0,"账户名称");
sheet.addCell(labs);
Label labt = new Label(2,0,"最后操作日期");
sheet.addCell(labt);
Label labf = new Label(3,0,"目前操作数");
sheet.addCell(labf);
Label labfi = new Label(4,0,"密码");
sheet.addCell(labfi);
Label labsi = new Label(5,0,"余额");
sheet.addCell(labsi);
Label labse = new Label(6,0,"流水金额");
sheet.addCell(labse);
for (int i = 1; i <= 5; i++)
{
String t = ku[i-1].GetaccountID();
Label lab1 = new Label(0,i,t);
sheet.addCell(lab1);
t = ku[i-1].Getaccountname();
Label lab2 = new Label(1,i,t);
sheet.addCell(lab2);
t = ku[i-1].Getoperatedate();
Label lab3 = new Label(2,i,t);
sheet.addCell(lab3);
t = Integer.toString(ku[i-1].Getoperatetype());
Label lab4 = new Label(3,i,t);
sheet.addCell(lab4);
t = ku[i-1].Getaccountpassword();
Label lab5 = new Label(4,i,t);
sheet.addCell(lab5);
t = Integer.toString(ku[i-1].Getaccountbalance());
Label lab6 = new Label(5,i,t);
sheet.addCell(lab6);
t = Integer.toString(ku[i-1].Getamount());
Label lab7 = new Label(6,i,t);
sheet.addCell(lab7);
}
workbook.write();
workbook.close();
}
//读入
public void readfile() throws BiffException, IOException{
InputStream instream = new FileInputStream(Infor);
Workbook readwb = Workbook.getWorkbook(instream);
Sheet readsheet = readwb.getSheet(0);
for(int i=1;i<=5;i++)
{
String t1,t2,t3,t4,t5,t6,t7;
Cell cell = readsheet.getCell(0,i);
t1 = cell.getContents();
cell = readsheet.getCell(1,i);
t2 = cell.getContents();
cell = readsheet.getCell(2,i);
t3 = cell.getContents();
cell = readsheet.getCell(3,i);
t4 = cell.getContents();
cell = readsheet.getCell(4,i);
t5 = cell.getContents();
cell = readsheet.getCell(5,i);
t6 = cell.getContents();
cell = readsheet.getCell(6,i);
t7 = cell.getContents();
ku[i-1].Set(t1,t2,t3,Integer.parseInt(t4),t5,Integer.parseInt(t6),Integer.parseInt(t7));
}
}
//复制文件
public void Copyfile() throws RowsExceededException, WriteException, IOException, BiffException{
InputStream instream = new FileInputStream(List);
Workbook readwb = Workbook.getWorkbook(instream);
Sheet readsheet = readwb.getSheet(0);
int rsColumns = readsheet.getColumns();
int rsRows = readsheet.getRows();
WritableWorkbook workbook = Workbook.createWorkbook(new File(Copy));
WritableSheet sheet = workbook.createSheet("Test",0);
for (int i = 1; i < rsRows; i++)
{
for (int j = 0; j < rsColumns; j++)
{
Cell cell = readsheet.getCell(j,i);
Label lab = new Label(j,i-1,cell.getContents());
sheet.addCell(lab);
}
}
workbook.write();
workbook.close();
}
//----------------<主函数>-----------------//
public static void main(String[] args) throws IOException, RowsExceededException, WriteException, BiffException {
AccountManager ap = new AccountManager();
ap.FirstWin();
}
}

附带文件截图:

Java 本周四、五的相关研究——Excel 的文件管理(数据库初步)的更多相关文章

  1. Java多线程--线程安全问题的相关研究

    在刚刚学线程的时候我们经常会碰到这么一个问题:模拟火车站售票窗口售票.代码如下: package cn.blogs.com.isole; /* 模拟火车站售票窗口售票,假设有50张余票 */ publ ...

  2. Java实现抽奖模块的相关分享

    Java实现抽奖模块的相关分享 最近进行的项目中,有个抽奖的需求,今天就把相关代码给大家分享一下. 一.DAO层 /** * 获取奖品列表 * @param systemVersion 手机系统版本( ...

  3. java的poi技术读,写Excel[2003-2007,2010]

    在上一篇blog:java的poi技术读取Excel[2003-2007,2010] 中介绍了关于java中的poi技术读取excel的相关操作 读取excel和MySQL相关: java的poi技术 ...

  4. Java 字符串拼接 五种方法的性能比较分析 从执行100次到90万次

    [请尊重原创版权,如需引用,请注明来源及地址] > 字符串拼接一般使用“+”,但是“+”不能满足大批量数据的处理,Java中有以下五种方法处理字符串拼接,各有优缺点,程序开发应选择合适的方法实现 ...

  5. VSTO学习笔记(五)批量编辑Excel 2010 x64

    原文:VSTO学习笔记(五)批量编辑Excel 2010 x64 近期因为工作的需要,经常要批量处理大量的Excel文件,如果纯手工一个个修改,非常的麻烦,于是写了这么一个帮助类,希望能对你有所帮助. ...

  6. java的poi技术读取和导入Excel实例

    本篇文章主要介绍了java的poi技术读取和导入Excel实例,报表输出是Java应用开发中经常涉及的内容,有需要的可以了解一下. 报表输出是Java应用开发中经常涉及的内容,而一般的报表往往缺乏通用 ...

  7. Java基于注解和反射导入导出Excel

    代码地址如下:http://www.demodashi.com/demo/11995.html 1. 构建项目 使用Spring Boot快速构建一个Web工程,并导入与操作Excel相关的POI包以 ...

  8. 和朱晔一起复习Java并发(五):并发容器和同步器

    本节我们先会来复习一下java.util.concurrent下面的一些并发容器,然后再会来简单看一下各种同步器. ConcurrentHashMap和ConcurrentSkipListMap的性能 ...

  9. Java操作Jxl实现导出数据生成Excel表格数据文件

    实现:前台用的框架是Easyui+Bootstrap结合使用,需要引入相应的Js.Css文件.页面:Jsp.拦截请求:Servlet.逻辑处理:ClassBean.数据库:SQLserver. 注意: ...

随机推荐

  1. 2.4 if-else

    if-else 想一想:在使用if的时候,它只能做到满足条件时要做的事情.那万一需要在不满足条件的时候,做某些事,该怎么办呢? 答:使用 if-else <1>if-else的使用格式 i ...

  2. RHEL 6.4 通过mysql安装文件安装mysql

    参考文章:http://www.linuxidc.com/Linux/2013-12/93507.htm 1.首先下载mysql安装文件 我是下载的最新版的5.6 2. 以RPM方式安装MySQL 在 ...

  3. 关于reduce的参数问题

    ECMAScript 5还新增了两个缩小数组的方法: reduce() 和 reduceRight() .这两个方法都会迭代数组的所有项,然后构建一个最终返回的值.其中, reduce() 方法从数组 ...

  4. Idea快捷操作

    command+N 导入jar包 在方法体内部有for循环,在IntellJ中是输入fori,然后会有一个提示,选中需要的for循环即可 System.out.println();在IntellJ中是 ...

  5. 顶层const

    顶层const:指针本身是一个常量 底层const:指针所指对象是一个常量 顶层const可以表示任意的对象是常量,这一点对任何数据类型都适用,如算术类型.类.指针等 底层const则与指针和引用等复 ...

  6. 2017-2018-2 20165234 实验二 《Java面向对象程序设计》实验报告

    一.实验报告封面 课程:Java程序设计  班级:1652班  姓名:刘津甫  学号:20165234 指导教师:娄嘉鹏  实验日期:2018年4月13日 实验时间:15:35 - 17:15  实验 ...

  7. v2v-VMware/VSphere中虚机离线迁移至openstack平台

    先决条件 exsi到openstack的迁移,分为两种,一种是静态迁移,另一种是在线迁移. 静态迁移(offline migration)也叫做常规迁移,离线迁移.在迁移之前将虚拟机暂停,同时拷贝虚拟 ...

  8. css干货部分

    1.css的引入方式(三种): a.行内样式<div> <p style="color: green">我是一个段落</p> </div& ...

  9. keepalived的vip无法ping通【原创】

    今天收到redis的keepalived vip无法ping通的告警,查看服务器和服务时发现vip在服务器上,服务也正常.只能在本机ping通,跨网段无法ping通.切换keepalived vip至 ...

  10. MySQL数据库的锁详解【转】

    当然在我们的数据库中也有锁用来控制资源的并发访问,这也是数据库和文件系统的区别之一. 为什么要懂数据库锁? 通常来说对于一般的开发人员,在使用数据库的时候一般懂点 DQL(select),DML(in ...