-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
1,714 additions
and
12 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
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
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
14 changes: 14 additions & 0 deletions
14
demo/src/main/java/com/liqi/myutils/demo/db/DBManagerOperation.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,14 @@ | ||
package com.liqi.myutils.demo.db; | ||
|
||
import android.content.Context; | ||
|
||
import com.liqi.utils.db.BaseDBManagerOperation; | ||
|
||
/** | ||
* 数据库信息表业务操作对象 | ||
*/ | ||
public class DBManagerOperation { | ||
public static BaseDBManagerOperation BaseDBManagerOperation(Context context) { | ||
return BaseDBManagerOperation.getBaseDBManagerOperation(new DatabaseTableHelper(context.getApplicationContext())); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
demo/src/main/java/com/liqi/myutils/demo/db/DatabaseTableHelper.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,35 @@ | ||
package com.liqi.myutils.demo.db; | ||
|
||
|
||
import android.content.Context; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.database.sqlite.SQLiteOpenHelper; | ||
|
||
/** | ||
* 创建数据库表对象 | ||
* | ||
* @author Liqi | ||
*/ | ||
public class DatabaseTableHelper extends SQLiteOpenHelper implements OnDatabaseTableHelperListener{ | ||
|
||
public DatabaseTableHelper(Context context) { | ||
|
||
// 调用父类构造方法创建数据库 | ||
super(context, TABLE_DB, null, TEST_VERSION); | ||
} | ||
|
||
@Override | ||
public void onCreate(SQLiteDatabase db) { | ||
// 营销订单 | ||
db.execSQL("CREATE TABLE " + TEST_NAME + " (id integer primary key , "+TEST_CONTENT_ONE+" text, "+TEST_CONTENT_TWO+" text, "+TEST_CONTENT_THREE+" text, "+TEST_CONTENT_FOUR+" text)"); | ||
|
||
} | ||
|
||
@Override | ||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | ||
// 判断数据库是否存在,存在就删掉然后重新创建表 | ||
db.execSQL("DROP TABLE IF EXISTS " + TEST_NAME); | ||
onCreate(db); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
demo/src/main/java/com/liqi/myutils/demo/db/OnDatabaseTableHelperListener.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,16 @@ | ||
package com.liqi.myutils.demo.db; | ||
|
||
/** 数据库表名和表字段接口 | ||
* Created by LiQi on 2017/12/6. | ||
*/ | ||
|
||
public interface OnDatabaseTableHelperListener { | ||
String TABLE_DB="TEST_TABLE_DB"; | ||
int TEST_VERSION=1; | ||
String TEST_NAME="TEST_NAME", | ||
TEST_CONTENT_ONE="TEST_CONTENT_ONE" | ||
,TEST_CONTENT_TWO="TEST_CONTENT_TWO", | ||
TEST_CONTENT_THREE="TEST_CONTENT_THREE", | ||
TEST_CONTENT_FOUR="TEST_CONTENT_FOUR"; | ||
|
||
} |
156 changes: 156 additions & 0 deletions
156
demo/src/main/java/com/liqi/myutils/demo/db/TestDataBaseOperateActivity.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,156 @@ | ||
package com.liqi.myutils.demo.db; | ||
|
||
import android.content.Context; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.TextView; | ||
|
||
import com.liqi.myutils.demo.R; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Map; | ||
|
||
/** | ||
* 数据库操作演示界面 | ||
* <p> | ||
* MVP模式 | ||
* </P> | ||
* Created by LiQi on 2017/12/6. | ||
*/ | ||
|
||
public class TestDataBaseOperateActivity extends AppCompatActivity implements View.OnClickListener,TestDataBaseOperateP.OnTestDataBaseOperateListener<ArrayList<Map<String, String>>>{ | ||
private TextView content; | ||
private EditText add_key_one, add_key_two, add_key_three, add_key_four, | ||
query_key_one, query_key_two, query_key_three, query_key_four, | ||
update_key_one, update_key_two, update_key_three, update_key_four, | ||
delete_key_one, delete_key_two, delete_key_three, delete_key_four; | ||
private int queryCode; | ||
|
||
private Button query_key_query; | ||
private TestDataBaseOperateP<ArrayList<Map<String, String>>> mPresenter; | ||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.test_data_base_operate_layout); | ||
content = (TextView) findViewById(R.id.content); | ||
add_key_one = (EditText) findViewById(R.id.add_key_one); | ||
add_key_two = (EditText) findViewById(R.id.add_key_two); | ||
add_key_three = (EditText) findViewById(R.id.add_key_three); | ||
add_key_four = (EditText) findViewById(R.id.add_key_four); | ||
query_key_one = (EditText) findViewById(R.id.query_key_one); | ||
query_key_two = (EditText) findViewById(R.id.query_key_two); | ||
query_key_three = (EditText) findViewById(R.id.query_key_three); | ||
query_key_four = (EditText) findViewById(R.id.query_key_four); | ||
update_key_one = (EditText) findViewById(R.id.update_key_one); | ||
update_key_two = (EditText) findViewById(R.id.update_key_two); | ||
update_key_three = (EditText) findViewById(R.id.update_key_three); | ||
update_key_four = (EditText) findViewById(R.id.update_key_four); | ||
delete_key_one = (EditText) findViewById(R.id.delete_key_one); | ||
delete_key_two = (EditText) findViewById(R.id.delete_key_two); | ||
delete_key_three = (EditText) findViewById(R.id.delete_key_three); | ||
delete_key_four = (EditText) findViewById(R.id.delete_key_four); | ||
findViewById(R.id.add_key_add).setOnClickListener(this); | ||
query_key_query = (Button) findViewById(R.id.query_key_query); | ||
query_key_query.setOnClickListener(this); | ||
findViewById(R.id.update_key_update).setOnClickListener(this); | ||
findViewById(R.id.delete_key_delete).setOnClickListener(this); | ||
mPresenter=new TestDataBaseOperateP<>(this); | ||
} | ||
|
||
@Override | ||
public void presenterDataOk(ArrayList<Map<String, String>> presenterData) { | ||
String hint = "数据库操作执行失败"; | ||
if (null != presenterData && !presenterData.isEmpty()) { | ||
hint = ""; | ||
for (Map<String, String> map : presenterData) { | ||
if (!map.isEmpty()) { | ||
for (Map.Entry<String, String> entry : map.entrySet()) { | ||
hint += "key:" + entry.getKey() + " values:" + entry.getValue() + "\n"; | ||
} | ||
} | ||
} | ||
} | ||
content.setText("操作数据库提示信息:\n" + hint); | ||
} | ||
|
||
@Override | ||
public void presenterDataNo(int tag) { | ||
|
||
} | ||
|
||
@Override | ||
public Context getContext() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
switch (v.getId()) { | ||
//增加 | ||
case R.id.add_key_add: | ||
String one = add_key_one.getText().toString().trim(); | ||
String two = add_key_two.getText().toString().trim(); | ||
String three = add_key_three.getText().toString().trim(); | ||
String four = add_key_four.getText().toString().trim(); | ||
mPresenter.write(one, two, three, four); | ||
break; | ||
//查询-轮流调用数据库查询工具方法 | ||
case R.id.query_key_query: | ||
|
||
String queryOne = query_key_one.getText().toString().trim(); | ||
String queryTwo = query_key_two.getText().toString().trim(); | ||
String queryThree = query_key_three.getText().toString().trim(); | ||
String queryFour = query_key_four.getText().toString().trim(); | ||
queryCode++; | ||
switch (queryCode) { | ||
case 1: | ||
mPresenter.allPrecisionFindByIdList(queryOne, queryTwo, queryThree, queryFour); | ||
break; | ||
case 2: | ||
mPresenter.orPrecisionFindByIdList(queryOne, queryTwo, queryThree, queryFour); | ||
break; | ||
case 3: | ||
mPresenter.allFuzzyFindByIdList(queryOne, queryTwo, queryThree, queryFour); | ||
break; | ||
case 4: | ||
mPresenter.andFuzzyFindByIdList(queryOne, queryTwo, queryThree, queryFour); | ||
break; | ||
case 5: | ||
mPresenter.allPrecisionFindByIdMap(queryOne, queryTwo, queryThree, queryFour); | ||
break; | ||
case 6: | ||
mPresenter.orPrecisionFindByIdMap(queryOne, queryTwo, queryThree, queryFour); | ||
break; | ||
case 7: | ||
mPresenter.allFuzzyFindByIdMap(queryOne, queryTwo, queryThree, queryFour); | ||
break; | ||
case 8: | ||
mPresenter.andFuzzyFindByIdMap(queryOne, queryTwo, queryThree, queryFour); | ||
queryCode = 0; | ||
break; | ||
} | ||
query_key_query.setText("查询数据库>>" + (queryCode + 1)); | ||
break; | ||
//更新 | ||
case R.id.update_key_update: | ||
String updateOne = update_key_one.getText().toString().trim(); | ||
String updateTwo = update_key_two.getText().toString().trim(); | ||
String updateThree = update_key_three.getText().toString().trim(); | ||
String updateFour = update_key_four.getText().toString().trim(); | ||
mPresenter.update(updateOne, updateTwo, updateThree, updateFour); | ||
break; | ||
//删除 | ||
case R.id.delete_key_delete: | ||
String deleteOne = delete_key_one.getText().toString().trim(); | ||
String deleteTwo = delete_key_two.getText().toString().trim(); | ||
String deleteThree = delete_key_three.getText().toString().trim(); | ||
String deleteFour = delete_key_four.getText().toString().trim(); | ||
mPresenter.delete(deleteOne, deleteTwo, deleteThree, deleteFour); | ||
break; | ||
} | ||
} | ||
} |
Oops, something went wrong.