📄 weekinfstore.java
字号:
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Date;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreNotOpenException;
/*
* 创建日期 2006-12-6
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
/**
* @author Administrator
*
* TODO 要更改此生成的类型注释的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
public class WeekInfStore{//保存对课程各种操作的方法的具体实现,后台逻辑运算
//建立一个静态记录用于整个程序
static RecordStore weekinf;
/**
* @param name
* @throws Exception
*/
public WeekInfStore(){
try {
weekinf=RecordStore.openRecordStore("Week_Inf_Store",true);
} catch (RecordStoreException e1) {
e1.printStackTrace();
}
if(empty(weekinf) ){
try {
About about=new About();
about.set_defalt();
} catch (IOException e3) {
e3.printStackTrace();
}
}
}
boolean empty(RecordStore rs){
try {
if(rs.getNumRecords()==0){
return true;
}
} catch (RecordStoreNotOpenException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
return false;
}
static boolean set_word(String s,boolean password){
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(byteOutputStream);
try {
dataOutputStream.writeUTF(s);
dataOutputStream.flush();
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
byte[] recordOut = byteOutputStream.toByteArray();
if(!password){
try {
weekinf.setRecord(37,recordOut, 0, recordOut.length);
return true;
} catch (RecordStoreException e1) {
try {
weekinf.addRecord(recordOut, 0, recordOut.length);
return true;
} catch (RecordStoreException e4) {
// TODO 自动生成 catch 块
e4.printStackTrace();
}
e1.printStackTrace();
}
}
else{
try {
weekinf.setRecord(38,recordOut, 0, recordOut.length);
return true;
} catch (RecordStoreException e1) {
try {
weekinf.addRecord(recordOut, 0, recordOut.length);
return true;
} catch (RecordStoreException e4) {
// TODO 自动生成 catch 块
e4.printStackTrace();
}
e1.printStackTrace();
}
}
try {
dataOutputStream.close();
} catch (IOException e2) {
// TODO 自动生成 catch 块
e2.printStackTrace();
}
try {
byteOutputStream.close();
} catch (IOException e3) {
// TODO 自动生成 catch 块
e3.printStackTrace();
}
return false;
}
static String get_word(boolean password) {
String s=new String();
ByteArrayInputStream byteInputStream=null;
DataInputStream dataInputStream =null;
if(!password){
try {
byteInputStream = new ByteArrayInputStream(weekinf.getRecord(37));
} catch (RecordStoreException e1) {
e1.printStackTrace();
}
}
else{
try {
byteInputStream = new ByteArrayInputStream(weekinf.getRecord(38));
} catch (RecordStoreException e1) {
e1.printStackTrace();
}
}
dataInputStream = new DataInputStream(byteInputStream);
try {
s=dataInputStream.readUTF();
dataInputStream.close();
byteInputStream.close();
return s;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
static boolean set_term_date(Date begin,Date end) throws IOException{
int[] a=new int[3];
int[] b=new int[3];
a=DateManager.get_year_mon_day(begin);
b=DateManager.get_year_mon_day( end);
int beginw=DateManager.weekday( begin);
int endw=DateManager.weekday( end);
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(byteOutputStream);
dataOutputStream.writeInt(a[0]);
dataOutputStream.writeInt(a[1]);
dataOutputStream.writeInt(a[2]);
dataOutputStream.writeInt(b[0]);
dataOutputStream.writeInt(b[1]);
dataOutputStream.writeInt(b[2]);
dataOutputStream.writeInt(beginw);
dataOutputStream.writeInt(endw);
try {
dataOutputStream.flush();
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
byte[] recordOut = byteOutputStream.toByteArray();
try {
weekinf.setRecord(36,recordOut, 0, recordOut.length);
return true;
} catch (RecordStoreException e1) {
try {
weekinf.addRecord(recordOut, 0, recordOut.length);
return true;
} catch (RecordStoreException e4) {
// TODO 自动生成 catch 块
e4.printStackTrace();
}
e1.printStackTrace();
}
try {
dataOutputStream.close();
} catch (IOException e2) {
// TODO 自动生成 catch 块
e2.printStackTrace();
}
try {
byteOutputStream.close();
} catch (IOException e3) {
// TODO 自动生成 catch 块
e3.printStackTrace();
}
return false;
}
static int[] get_term_date() {
int[] d=new int[8];
ByteArrayInputStream byteInputStream=null;
DataInputStream dataInputStream =null;
try {
byteInputStream = new ByteArrayInputStream(weekinf.getRecord(36));
} catch (RecordStoreException e1) {
e1.printStackTrace();
}
dataInputStream = new DataInputStream(byteInputStream);
try {
for(int i=0;i<8;i++){
d[i]=dataInputStream.readInt();
}
dataInputStream.close();
byteInputStream.close();
return d;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
static date get_aday(int weekday,int classth) {
date one=new date(true);
ByteArrayInputStream byteInputStream;
try {
byteInputStream = new ByteArrayInputStream(weekinf.getRecord((weekday-1)*5+classth));
DataInputStream dataInputStream = new DataInputStream(byteInputStream);
one.course1 = dataInputStream.readUTF();
one.begin1=dataInputStream.readInt();
one.end1=dataInputStream.readInt();
one.where1 = dataInputStream.readUTF();
one.weekday1=weekday;
one.classth1 =classth;
dataInputStream.close();
byteInputStream.close();
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
return one;
}
static boolean add(boolean delete,int weekday,int classth ,String course,int begin,int end,String where) throws IOException{
if(weekday<1||weekday>7||classth<1||classth>5||course.equals("")||course==null||where.equals("")||where==null)
return false;
int dix=(weekday-1)*5+classth;
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(byteOutputStream);
if(delete){
dataOutputStream.writeUTF(course);
dataOutputStream.writeInt(begin);
dataOutputStream.writeInt(end);
dataOutputStream.writeUTF(where);
}
else{
date inf=new date(true);
inf = get_aday(weekday,classth);
if(inf.course1.equals("无课程")){
inf.course1=course;
inf.begin1=begin;
inf.end1 =end;
inf.where1 =where;
}
else{
if(inf.begin1<begin){
inf.course1 =inf.course1 +"#"+course;
inf.begin1 =inf.begin1 +begin*100;
inf.end1 =inf.end1 +end*100;
inf.where1 =inf.where1 +"#"+where;
}
else{
inf.course1 =course+"#"+inf.course1 ;
inf.begin1 =inf.begin1 *100+begin;
inf.end1 =inf.end1 *100+end;
inf.where1 =where+"#"+inf.where1 ;
}
}
dataOutputStream.writeUTF(inf.course1 );
dataOutputStream.writeInt(inf.begin1 );
dataOutputStream.writeInt(inf.end1 );
dataOutputStream.writeUTF(inf.where1 );
}
try {
dataOutputStream.flush();
} catch (IOException e) {
e.printStackTrace();
}
byte[] recordOut = byteOutputStream.toByteArray();
try {
weekinf.setRecord(dix,recordOut, 0, recordOut.length);
dataOutputStream.close();
byteOutputStream.close();
return true;
} catch (RecordStoreException e1) {
try {
weekinf.addRecord(recordOut,0,recordOut.length);
dataOutputStream.close();
byteOutputStream.close();
return true;
} catch (RecordStoreException e4) {
// TODO 自动生成 catch 块
e4.printStackTrace();
}
e1.printStackTrace();
}
return false;
}
public static date get(int weekday,int Weekth){
if(Weekth<0)
return null;
date aDayCourse= new date(false);
String c1=new String();
String c2=new String();
String w1=new String();
String w2=new String();
int pos;
int dix;
dix=(weekday-1)*5;
ByteArrayInputStream byteInputStream;
DataInputStream dataInputStream;
for(int i=1;i<=5;i++){
try {
byteInputStream = new ByteArrayInputStream(weekinf.getRecord(dix+i));
dataInputStream = new DataInputStream(byteInputStream);
aDayCourse.course[i-1] = dataInputStream.readUTF();
aDayCourse.begin[i-1]=dataInputStream.readInt();
aDayCourse.end[i-1]=dataInputStream.readInt();
aDayCourse.where[i-1] = dataInputStream.readUTF();
if(aDayCourse.begin[i-1]>100){
pos=aDayCourse.course[i-1].indexOf("#");
c1=aDayCourse.course[i-1].substring(0,pos);
c2=aDayCourse.course[i-1].substring(pos+1,aDayCourse.course[i-1].length());
pos=aDayCourse.where[i-1].indexOf("#");
w1=aDayCourse.where[i-1].substring(0,pos);
w2=aDayCourse.where[i-1].substring(pos+1,aDayCourse.where[i-1].length());
if(Weekth>aDayCourse.end[i-1]%100){
aDayCourse.begin[i-1]=aDayCourse.begin[i-1]/100;
aDayCourse.end[i-1]=aDayCourse.end[i-1]/100;
aDayCourse.course[i-1]=c2;
aDayCourse.where[i-1]=w2;
}
else{
aDayCourse.begin[i-1]=aDayCourse.begin[i-1]%100;
aDayCourse.end[i-1]=aDayCourse.end[i-1]%100;
aDayCourse.course[i-1]=c1;
aDayCourse.where[i-1]=w1;
}
}
for(int k=0;k<5;k++){
if(aDayCourse.end [k]<Weekth||aDayCourse.begin[k] >Weekth)
aDayCourse.course[k] ="无课程";
}
dataInputStream.close();
byteInputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return aDayCourse;
}
static void delete_all() throws IOException{
for(int i=1;i<=7;i++)
for(int j=1;j<=5;j++)
add(true,i,j,"无课程",0,0,"0");
Date d=new Date();
set_term_date(d,d);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -