diff --git a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/1414080903202.json b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/1414080903202.json new file mode 100644 index 00000000..ac6dc498 --- /dev/null +++ b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/1414080903202.json @@ -0,0 +1 @@ +[{"date":"2017.10.01","input":"1000","output":"200"}] diff --git a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202Account.java b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202Account.java new file mode 100644 index 00000000..30960392 --- /dev/null +++ b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202Account.java @@ -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 + + '}'; + + + + } +} diff --git a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202AccountDao.java b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202AccountDao.java new file mode 100644 index 00000000..b2bceadf --- /dev/null +++ b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202AccountDao.java @@ -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 queryAll() { + SQLiteDatabase db = helper.getReadableDatabase(); + Cursor cursor = db.query("account", null, null, null, null, null, null); + List list = new ArrayList(); + 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; + } +} diff --git a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202Bill.java b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202Bill.java index c08b77e1..38b7711f 100644 --- a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202Bill.java +++ b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202Bill.java @@ -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 diff --git a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202Main_Check.java b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202Main_Check.java index d6fc1232..4307f057 100644 --- a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202Main_Check.java +++ b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202Main_Check.java @@ -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 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(); + } } } diff --git a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202MyHelper.java b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202MyHelper.java new file mode 100644 index 00000000..c0182f7b --- /dev/null +++ b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202MyHelper.java @@ -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"); + } + +} diff --git a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202Navigation.java b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202Navigation.java index f2369756..dabf1c2e 100644 --- a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202Navigation.java +++ b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202Navigation.java @@ -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); + } + }); } } diff --git a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202manage.java b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202manage.java index cac59251..df66f767 100644 --- a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202manage.java +++ b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903202/Net1414080903202manage.java @@ -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 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); } + } diff --git a/AndroidLabs/app/src/main/res/layout/activity_net1414080903202_bill.xml b/AndroidLabs/app/src/main/res/layout/activity_net1414080903202_bill.xml index be4f3bfd..9efe0e9c 100644 --- a/AndroidLabs/app/src/main/res/layout/activity_net1414080903202_bill.xml +++ b/AndroidLabs/app/src/main/res/layout/activity_net1414080903202_bill.xml @@ -12,9 +12,8 @@ diff --git a/AndroidLabs/app/src/main/res/layout/activity_net1414080903202_list_check.xml b/AndroidLabs/app/src/main/res/layout/activity_net1414080903202_list_check.xml index 1a1d7a52..f5ab3163 100644 --- a/AndroidLabs/app/src/main/res/layout/activity_net1414080903202_list_check.xml +++ b/AndroidLabs/app/src/main/res/layout/activity_net1414080903202_list_check.xml @@ -14,6 +14,7 @@ android:layout_height="wrap_content"> - +