-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #429 from zhongwbang/master
- Loading branch information
Showing
12 changed files
with
453 additions
and
30 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...s/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/1414080903202.json
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 @@ | ||
[{"date":"2017.10.01","input":"1000","output":"200"}] |
91 changes: 91 additions & 0 deletions
91
...main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202Account.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,91 @@ | ||
package edu.hzuapps.androidlabs.homeworks.net1414080903202; | ||
|
||
/** | ||
* Created by Administrator on 2017/5/23. | ||
*/ | ||
|
||
public class Net1414080903202Account { | ||
private String date; | ||
private Float input; | ||
private Float output; | ||
private String beizhu; | ||
private Float yingkui; | ||
private Float total; | ||
|
||
public String getDate() { | ||
return date; | ||
} | ||
|
||
public void setDate(String date) { | ||
this.date = date; | ||
} | ||
|
||
public Float getInput() { | ||
return input; | ||
} | ||
|
||
public void setInput(Float input) { | ||
this.input = input; | ||
} | ||
|
||
public Float getOutput() { | ||
return output; | ||
} | ||
|
||
public void setOutput(Float output) { | ||
this.output = output; | ||
} | ||
|
||
public String getBeizhu() { | ||
return beizhu; | ||
} | ||
|
||
public void setBeizhu(String beizhu) { | ||
this.beizhu = beizhu; | ||
} | ||
|
||
public Float getYingkui() { | ||
return yingkui; | ||
} | ||
|
||
public void setYingkui(Float yingkui) { | ||
this.yingkui = yingkui; | ||
} | ||
|
||
public Float getTotal() { | ||
return total; | ||
} | ||
|
||
public void setTotal(Float total) { | ||
this.total = total; | ||
} | ||
|
||
public Net1414080903202Account(String date, Float input, Float output, String beizhu, Float yingkui, Float total) { | ||
super(); | ||
this.date = date; | ||
this.input = input; | ||
this.output = output; | ||
this.beizhu = beizhu; | ||
this.yingkui = yingkui; | ||
this.total = total; | ||
} | ||
|
||
public Net1414080903202Account() { | ||
super(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Net1414080903202Account{" + | ||
"date='" + date + '\'' + | ||
", input=" + input + | ||
", output=" + output + | ||
", beizhu='" + beizhu + '\'' + | ||
", yingkui=" + yingkui + | ||
", total=" + total + | ||
'}'; | ||
|
||
|
||
|
||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...n/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202AccountDao.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,59 @@ | ||
package edu.hzuapps.androidlabs.homeworks.net1414080903202; | ||
|
||
import android.accounts.Account; | ||
import android.content.ContentValues; | ||
import android.content.Context; | ||
import android.database.Cursor; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.database.sqlite.SQLiteDatabaseCorruptException; | ||
import android.renderscript.Sampler; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
|
||
/** | ||
* Created by Administrator on 2017/5/26. | ||
*/ | ||
|
||
public class Net1414080903202AccountDao { | ||
private Net1414080903202MyHelper helper; | ||
public Net1414080903202AccountDao(Context context){ | ||
//创建Dao时,创建Helper | ||
helper=new Net1414080903202MyHelper(context); | ||
} | ||
|
||
public void insert(Net1414080903202Account account){ | ||
//获取数据对象 | ||
SQLiteDatabase db=helper.getWritableDatabase(); | ||
//用来装载要插入的数据的MAP | ||
ContentValues values=new ContentValues(); | ||
values.put("date",account.getDate()); | ||
values.put("input",account.getInput()); | ||
values.put("output",account.getOutput()); | ||
values.put("beizhu",account.getBeizhu()); | ||
values.put("yingkui",account.getYingkui()); | ||
values.put("total",account.getTotal()); | ||
//向account表插入数据values | ||
db.close(); | ||
} | ||
|
||
public List<Net1414080903202Account> queryAll() { | ||
SQLiteDatabase db = helper.getReadableDatabase(); | ||
Cursor cursor = db.query("account", null, null, null, null, null, null); | ||
List<Net1414080903202Account> list = new ArrayList<Net1414080903202Account>(); | ||
while (cursor.moveToNext()) { | ||
String date = cursor.getString(cursor.getColumnIndex("date")); | ||
Float input = cursor.getFloat(1); | ||
Float output = cursor.getFloat(2); | ||
String beizhu = cursor.getString(3); | ||
Float yingkui = cursor.getFloat(4); | ||
Float total = cursor.getFloat(5); | ||
list.add(new Net1414080903202Account(date, input, output, beizhu, yingkui, total)); | ||
} | ||
cursor.close(); | ||
db.close(); | ||
return list; | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
...ain/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202MyHelper.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,27 @@ | ||
package edu.hzuapps.androidlabs.homeworks.net1414080903202; | ||
|
||
import android.content.Context; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.database.sqlite.SQLiteOpenHelper; | ||
|
||
/** | ||
* Created by Administrator on 2017/5/15. | ||
*/ | ||
|
||
public class Net1414080903202MyHelper extends SQLiteOpenHelper{ | ||
|
||
public Net1414080903202MyHelper(Context context){ | ||
super(context,"itcast",null,1); | ||
} | ||
|
||
@Override | ||
public void onCreate(SQLiteDatabase db) { | ||
System.out.println("onCreate"); | ||
db.execSQL("CREATE TABLE accont(date VARCHAR(20) PRIMARY KEY AUTOINCREMENT,input REA" + | ||
"L,output REAL,beizhu VARCHAR(20),yingkui REAL,total REAL)"); | ||
} | ||
public void onUpgrade(SQLiteDatabase db,int oldVersion,int newVersion){ | ||
System.out.println("onUpgrade"); | ||
} | ||
|
||
} |
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
55 changes: 55 additions & 0 deletions
55
.../main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202manage.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,21 +1,76 @@ | ||
package edu.hzuapps.androidlabs.homeworks.net1414080903202; | ||
|
||
import android.accounts.Account; | ||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
import android.content.DialogInterface; | ||
import android.content.Intent; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.Toast; | ||
|
||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.logging.SimpleFormatter; | ||
|
||
import edu.hzuapps.androidlabs.R; | ||
|
||
public class Net1414080903202manage extends AppCompatActivity { | ||
private List<Net1414080903202Account> list; | ||
private EditText et_input; | ||
private EditText et_output; | ||
private EditText et_beizhu; | ||
private Button btn_tijiao; | ||
|
||
@SuppressLint("LongLogTag") | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_net1414080903202manage); | ||
//获取布局文件中的控件 | ||
et_input=(EditText) findViewById(R.id.input); | ||
et_output=(EditText) findViewById(R.id.output); | ||
et_beizhu=(EditText) findViewById(R.id.beizhu); | ||
btn_tijiao=(Button) findViewById(R.id.tijiao); | ||
btn_tijiao.setOnClickListener(new ButtonListener()); | ||
} | ||
|
||
//定义Button按钮的点击事件 | ||
private class ButtonListener implements View.OnClickListener { | ||
@Override | ||
public void onClick(View view){ | ||
switch (view.getId()){ | ||
case R.id.tijiao: | ||
Net1414080903202AccountDao accountDao=new Net1414080903202AccountDao(Net1414080903202manage.this); | ||
String date=getDate(); | ||
String input=et_input.getText().toString().trim(); | ||
String output=et_output.getText().toString().trim(); | ||
String beizhu=et_beizhu.getText().toString().trim(); | ||
String yingkui=String.valueOf(Float.parseFloat(input)-Float.parseFloat(output)); | ||
list=accountDao.queryAll(); | ||
Float total=list.get(list.size()-1).getTotal(); | ||
|
||
Net1414080903202Account account=new Net1414080903202Account(date,Float.parseFloat(input),Float.parseFloat(output),beizhu,Float.parseFloat(yingkui),total); | ||
accountDao.insert(account); | ||
Toast.makeText(Net1414080903202manage.this,"数据提交成功",Toast.LENGTH_SHORT).show(); | ||
break; | ||
} | ||
} | ||
|
||
} | ||
|
||
public String getDate(){ | ||
Date date=new Date(); | ||
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd"); | ||
return format.format(date); | ||
} | ||
|
||
|
||
} |
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
Oops, something went wrong.