Skip to content

Commit

Permalink
Merge pull request #429 from zhongwbang/master
Browse files Browse the repository at this point in the history
#5 #34 第五次作业
  • Loading branch information
zengsn authored Jun 11, 2017
2 parents a375635 + f848a79 commit 600be8f
Show file tree
Hide file tree
Showing 12 changed files with 453 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"date":"2017.10.01","input":"1000","output":"200"}]
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 +
'}';



}
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import edu.hzuapps.androidlabs.R;

public class Net1414080903202Bill extends AppCompatActivity {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,90 @@

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import org.w3c.dom.Text;

import java.util.List;

import edu.hzuapps.androidlabs.R;

public class Net1414080903202Main_Check extends AppCompatActivity {

private List<Net1414080903202Account> list;
private Net1414080903202AccountDao dao;
private ListView accountCheck;
private MyAdpapter adpater;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_net1414080903202_main_check);
initView();
dao=new Net1414080903202AccountDao(this);
//从数据库中查询出所有数据
list=dao.queryAll();
adpater=new MyAdpapter();
accountCheck.setAdapter(adpater); //给ListView添加适配器
}

//初始化控件
private void initView(){
accountCheck=(ListView) findViewById(R.id.accountCheck);
//添加监听器
accountCheck.setOnItemClickListener(new MyOnItemClickListener());
}

//自定义适配器
private class MyAdpapter extends BaseAdapter{
public int getCount(){ //获取条目总数
return list.size();
}

@Override
public Object getItem(int position) { //根据位置获取对象
return null;
}

@Override
public long getItemId(int position) { //根据位置获取ID
return 0;
}

//获取一个条目视图
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View item=LayoutInflater.from(Net1414080903202Main_Check.this).inflate(R.layout.activity_net1414080903202_list_check,null);
TextView date=(TextView) item.findViewById(R.id.date);
TextView input=(TextView) item.findViewById(R.id.input);
TextView output=(TextView) item.findViewById(R.id.output);
TextView beizhu=(TextView) item.findViewById(R.id.beizhu);
TextView yingkui=(TextView) item.findViewById(R.id.yingkui);
TextView total=(TextView) item.findViewById(R.id.total);
date.setText(list.get(position).getDate());
input.setText(list.get(position).getInput()+"");
output.setText(list.get(position).getOutput()+"");
beizhu.setText(list.get(position).getBeizhu());
yingkui.setText(list.get(position).getYingkui()+"");
total.setText(list.get(position).getTotal()+"");
return null;
}

}

//ListView的Item点击事件
private class MyOnItemClickListener implements AdapterView.OnItemClickListener {

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//获取点击位置上的数据
Net1414080903202Account a=(Net1414080903202Account) parent.getItemAtPosition(position);
Toast.makeText(getApplicationContext(),a.toString(),Toast.LENGTH_SHORT).show();
}
}
}
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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onClick(View v) {
Intent intent = new Intent(Net1414080903202Navigation.this, Net1414080903202manage.class);
startActivity(intent);
}
}
});
btCheck.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Net1414080903202Navigation.this, Net1414080903202Main_Check.class);
startActivity(intent);
}
});
}
}
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);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

<ImageView
android:id="@+id/pic1"
android:layout_width="370dp"
android:layout_height="300dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:src="@drawable/hol1"/>
</RelativeLayout>
Loading

0 comments on commit 600be8f

Please sign in to comment.