Skip to content

Commit

Permalink
hzuapps#5 hzuapps#90 第五次作业
Browse files Browse the repository at this point in the history
  • Loading branch information
xiwu zhong committed Jun 5, 2017
1 parent 7f72b8e commit f4e8730
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
import java.util.List;

import edu.hzuapps.androidlabs.R;
import edu.hzuapps.androidlabs.homworks.net1414080903136.db.ExpressDB;

public class Net1414080903136Activity extends FragmentActivity {
public static String url;
Button bt;
EditText et1;
EditText et2;
public static Button bt;
public static EditText et1;
public static EditText et2;
private ViewPager mViewpager;
private FragmentPagerAdapter mAdapter;
private List<Fragment> mDatas;
Expand All @@ -37,6 +38,9 @@ protected void onCreate(Bundle savedInstanceState) {
initView();
}
private void initView() {
bt= (Button) findViewById(R.id.bt);
et1= (EditText) findViewById(R.id.et1);
et2= (EditText) findViewById(R.id.et2);
ExpressInquiryTV= (TextView) findViewById(R.id.ExpressInquiry);
SiteQueryTV= (TextView) findViewById(R.id.SiteQuery);
MyExpressTV= (TextView) findViewById(R.id.MyExpress);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,56 @@
package edu.hzuapps.androidlabs.homworks.net1414080903136;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import edu.hzuapps.androidlabs.R;
import edu.hzuapps.androidlabs.homworks.net1414080903136.db.ExpressDB;
import edu.hzuapps.androidlabs.homworks.net1414080903136.db.ExpressDao;

import static edu.hzuapps.androidlabs.homworks.net1414080903136.Net1414080903136Activity.bt;

/**
* Created by xx on 2017/5/15.
*/

public class Net1414080903136ExpressInquiry extends Fragment{

ExpressDB expressDB;
private Button queryBt;
private EditText comName;
private EditText exNum;
private ExpressDao expressDao;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.tab1_net1414080903136,container,false);
View view=inflater.inflate(R.layout.tab1_net1414080903136,container,false);
queryBt= (Button) view.findViewById(R.id.bt);
comName= (EditText) view.findViewById(R.id.et1);
exNum=(EditText) view.findViewById(R.id.et2);
expressDao=new ExpressDao(getContext());
queryBt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//测试数据
String companyName=comName.getText().toString();
String expressNum=exNum.getText().toString();
String date="2017-5-18";
String content="惠州学院快递服务站正在第1次派件 电话:15766844117 请保持电话畅通、耐心等待";
String state="派件";
expressDao.insert(companyName,expressNum,date,content,state);
}
});
return view;


}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

package edu.hzuapps.androidlabs.homworks.net1414080903136.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;




public class ExpressDB extends SQLiteOpenHelper{

//数据库版本号
private static final int DATABASE_VERSION=1;
//数据库名称
private static final String DATABASE_NAME="express.db";
public ExpressDB(Context context){
super(context,DATABASE_NAME,null,DATABASE_VERSION);
}



@Override
public void onCreate(SQLiteDatabase db) {

//创建数据表

String CREATE_TABLE_EXPRESS="CREATE TABLE Express("
+"ExpressCom TEXT,"
+"ExNumber TEXT,"
+"ExTime TEXT,"
+"ExContext TEXT,"
+"ExStatus TEXT)";
db.execSQL(CREATE_TABLE_EXPRESS);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS Express");

onCreate(db);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package edu.hzuapps.androidlabs.homworks.net1414080903136.db;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;


public class ExpressDao {
private ExpressDB expressDB;

public ExpressDao(Context context){
expressDB=new ExpressDB(context);
}

public int insert(String company,String exNum,String time,String context,String status){
SQLiteDatabase db=expressDB.getWritableDatabase();
ContentValues values=new ContentValues();
values.put("ExpressCom",company);
values.put("ExNumber",exNum);
values.put("ExTime",time);
values.put("ExContext",context);
values.put("ExStatus",status);
long exID=db.insert("Express",null,values);
db.close();
return (int)exID;
}
public void update(String company,String exNum,String time,String context,String status){
SQLiteDatabase db=expressDB.getWritableDatabase();
ContentValues values=new ContentValues();

values.put("ExTime",time);
values.put("ExContext",context);
values.put("ExStatus",status);
db.update("Express",values,"ExNumber=?",new String[] {exNum });
db.close();
}

public String getContentById(String ExNumber){
SQLiteDatabase db=expressDB.getReadableDatabase();
String content="";
String selectQuery="SELECT *"+
" FROM Express"
+ " WHERE "
+"ExNumber=?";
int iCount=0;
Cursor cursor=db.rawQuery(selectQuery,new String[]{ExNumber});
if(cursor.moveToFirst()){
do{
content =cursor.getString(cursor.getColumnIndex("ExContext"));
}while(cursor.moveToNext());
}
cursor.close();
db.close();
return content;
}




}

0 comments on commit f4e8730

Please sign in to comment.