forked from hzuapps/android-labs-2017
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
xiwu zhong
committed
Jun 5, 2017
1 parent
7f72b8e
commit f4e8730
Showing
4 changed files
with
148 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 36 additions & 2 deletions
38
...va/edu/hzuapps/androidlabs/homeworks/net1414080903136/Net1414080903136ExpressInquiry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
||
} | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...bs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903136/db/ExpressDB.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
61 changes: 61 additions & 0 deletions
61
...s/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903136/db/ExpressDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
||
|
||
|
||
} |