diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b589d56 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..28e2a16 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..1b16719 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..70c178a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index b72362b..64e7ee6 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,2 @@ # HomeCaicaitong 安卓小项目-家庭收支便签 -11 \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..6bc36b9 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,44 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdk 31 + + defaultConfig { + applicationId "com.example.homecaicaitong" + minSdk 21 + targetSdk 31 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + buildFeatures { + viewBinding true + } +} + +dependencies { + + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.3.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.annotation:annotation:1.2.0' + implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1' + implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/homecaicaitong/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/homecaicaitong/ExampleInstrumentedTest.java new file mode 100644 index 0000000..f6908ce --- /dev/null +++ b/app/src/androidTest/java/com/example/homecaicaitong/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.homecaicaitong; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.homecaicaitong", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..087d68e --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/homecaicaitong/Accountflag.java b/app/src/main/java/com/example/homecaicaitong/Accountflag.java new file mode 100644 index 0000000..674a66d --- /dev/null +++ b/app/src/main/java/com/example/homecaicaitong/Accountflag.java @@ -0,0 +1,50 @@ +package com.example.homecaicaitong; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import com.example.homecaicaitong.dao.FlagDAO; +import com.example.homecaicaitong.model.Tb_flag; + +public class Accountflag extends AppCompatActivity { + private EditText txtFlag; + private Button btnflagSaveButton;// ????Button??????? + private Button btnflagCancelButton;// ????Button??????? + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.accountflag); + + txtFlag = (EditText) findViewById(R.id.txtFlag);// ??????????? + btnflagSaveButton = (Button) findViewById(R.id.btnflagSave);// ??????水? + btnflagCancelButton = (Button) findViewById(R.id.btnflagCancel);// ????????? + btnflagSaveButton.setOnClickListener(new View.OnClickListener() {// ????水????ü?????? + @Override + public void onClick(View arg0) { + String strFlag = txtFlag.getText().toString();// ????????????? + if (!strFlag.isEmpty()) {// ?ж??????????? + FlagDAO flagDAO = new FlagDAO(Accountflag.this);// ????FlagDAO???? + Tb_flag tb_flag = new Tb_flag(flagDAO.getMaxId() + 1, strFlag);// ????Tb_flag???? + flagDAO.add(tb_flag);// ???????? + // ?????????? + Toast.makeText(Accountflag.this, "??????????????????????", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(Accountflag.this, "??????????", Toast.LENGTH_SHORT).show(); + } + } + }); + + btnflagCancelButton.setOnClickListener(new View.OnClickListener() {// ??????????ü?????? + @Override + public void onClick(View arg0) { + txtFlag.setText("");// ?????????? + } + }); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/homecaicaitong/AddInaccount.java b/app/src/main/java/com/example/homecaicaitong/AddInaccount.java new file mode 100644 index 0000000..065141e --- /dev/null +++ b/app/src/main/java/com/example/homecaicaitong/AddInaccount.java @@ -0,0 +1,113 @@ +package com.example.homecaicaitong; + +import androidx.appcompat.app.AppCompatActivity; + +import android.app.DatePickerDialog; +import android.app.Dialog; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.DatePicker; +import android.widget.EditText; +import android.widget.Spinner; +import android.widget.Toast; + +import com.example.homecaicaitong.dao.InaccountDAO; +import com.example.homecaicaitong.model.Tb_inaccount; + +import java.util.Calendar; + +public class AddInaccount extends AppCompatActivity { + private static final int DATE_DIALOG_ID = 0;// 创建日期对话框常量 + private EditText txtInMoney, txtInTime, txtInHandler, txtInMark;// 创建4个EditText对象 + private Spinner spInType;// 创建Spinner对象 + private Button btnInSaveButton;// 创建Button对象“保存” + private Button btnInCancelButton;// 创建Button对象“取消” + + private int mYear;// 年 + private int mMonth;// 月 + private int mDay;// 日 + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.addinaccount);// 设置布局文件 + txtInMoney = (EditText) findViewById(R.id.txtInMoney);// 获取金额文本框 + txtInTime = (EditText) findViewById(R.id.txtInTime);// 获取时间文本框 + txtInHandler = (EditText) findViewById(R.id.txtInHandler);// 获取付款方文本框 + txtInMark = (EditText) findViewById(R.id.txtInMark);// 获取备注文本框 + spInType = (Spinner) findViewById(R.id.spInType);// 获取类别下拉列表 + btnInSaveButton = (Button) findViewById(R.id.btnInSave);// 获取保存按钮 + btnInCancelButton = (Button) findViewById(R.id.btnInCancel);// 获取取消按钮 + + txtInTime.setOnClickListener(new View.OnClickListener() {// 为时间文本框设置单击监听事件 + @Override + public void onClick(View arg0) { + showDialog(DATE_DIALOG_ID);// 显示日期选择对话框 + } + }); + + btnInSaveButton.setOnClickListener(new View.OnClickListener() {// 为保存按钮设置监听事件 + @Override + public void onClick(View arg0) { + String strInMoney = txtInMoney.getText().toString();// 获取金额文本框的值 + if (!strInMoney.isEmpty()) {// 判断金额不为空 + // 创建InaccountDAO对象 + InaccountDAO inaccountDAO = new InaccountDAO(AddInaccount.this); + // 创建Tb_inaccount对象 + Tb_inaccount tb_inaccount = new Tb_inaccount(inaccountDAO.getMaxId() + 1, Double.parseDouble(strInMoney), txtInTime.getText() + .toString(), spInType.getSelectedItem().toString(), txtInHandler.getText().toString(), txtInMark.getText().toString()); + inaccountDAO.add(tb_inaccount);// 添加收入信息 + // 弹出信息提示 + Toast.makeText(AddInaccount.this, "〖新增收入〗数据添加成功!", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(AddInaccount.this, "请输入收入金额!", Toast.LENGTH_SHORT).show(); + } + } + }); + + btnInCancelButton.setOnClickListener(new View.OnClickListener() {// 为取消按钮设置监听事件 + @Override + public void onClick(View arg0) { + txtInMoney.setText("");// 设置金额文本框为空 + txtInMoney.setHint("0.00");// 为金额文本框设置提示 + txtInTime.setText("");// 设置时间文本框为空 + txtInTime.setHint("2011-01-01");// 为时间文本框设置提示 + txtInHandler.setText("");// 设置付款方文本框为空 + txtInMark.setText("");// 设置备注文本框为空 + spInType.setSelection(0);// 设置类别下拉列表默认选择第一项 + } + }); + + final Calendar c = Calendar.getInstance();// 获取当前系统日期 + mYear = c.get(Calendar.YEAR);// 获取年份 + mMonth = c.get(Calendar.MONTH);// 获取月份 + mDay = c.get(Calendar.DAY_OF_MONTH);// 获取天数 + + updateDisplay();// 显示当前系统时间 + } + + @Override + protected Dialog onCreateDialog(int id) {// 重写onCreateDialog方法 + + switch (id) { + case DATE_DIALOG_ID:// 弹出日期选择对话框 + return new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay); + } + return null; + } + + private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() { + public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { + mYear = year;// 为年份赋值 + mMonth = monthOfYear;// 为月份赋值 + mDay = dayOfMonth;// 为天赋值 + updateDisplay();// 显示设置的日期 + } + }; + + private void updateDisplay() { + // 显示设置的时间 + txtInTime.setText(new StringBuilder().append(mYear).append("-").append(mMonth + 1).append("-").append(mDay)); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/homecaicaitong/AddOutaccount.java b/app/src/main/java/com/example/homecaicaitong/AddOutaccount.java new file mode 100644 index 0000000..a42f70a --- /dev/null +++ b/app/src/main/java/com/example/homecaicaitong/AddOutaccount.java @@ -0,0 +1,116 @@ +package com.example.homecaicaitong; + +import androidx.appcompat.app.AppCompatActivity; + +import android.app.DatePickerDialog; +import android.app.Dialog; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.DatePicker; +import android.widget.EditText; +import android.widget.Spinner; +import android.widget.Toast; + +import com.example.homecaicaitong.dao.OutaccountDAO; +import com.example.homecaicaitong.model.Tb_outaccount; + +import java.util.Calendar; + +public class AddOutaccount extends AppCompatActivity { + protected static final int DATE_DIALOG_ID = 0;// 创建日期对话框常量 + EditText txtMoney, txtTime, txtAddress, txtMark;// 创建4个EditText对象 + Spinner spType;// 创建Spinner对象 + Button btnSaveButton;// 创建Button对象“保存” + Button btnCancelButton;// 创建Button对象“取消” + + private int mYear;// 年 + private int mMonth;// 月 + private int mDay;// 日 + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.addoutaccount);// 设置布局文件 + txtMoney = (EditText) findViewById(R.id.txtMoney);// 获取金额文本框 + txtTime = (EditText) findViewById(R.id.txtTime);// 获取时间文本框 + txtAddress = (EditText) findViewById(R.id.txtAddress);// 获取地点文本框 + txtMark = (EditText) findViewById(R.id.txtMark);// 获取备注文本框 + spType = (Spinner) findViewById(R.id.spType);// 获取类别下拉列表 + btnSaveButton = (Button) findViewById(R.id.btnSave);// 获取保存按钮 + btnCancelButton = (Button) findViewById(R.id.btnCancel);// 获取取消按钮 + + txtTime.setOnClickListener(new View.OnClickListener() {// 为时间文本框设置单击监听事件 + + @Override + public void onClick(View arg0) { + showDialog(DATE_DIALOG_ID);// 显示日期选择对话框 + } + }); + + btnSaveButton.setOnClickListener(new View.OnClickListener() {// 为保存按钮设置监听事件 + + @Override + public void onClick(View arg0) { + String strMoney = txtMoney.getText().toString();// 获取金额文本框的值 + if (!strMoney.isEmpty()) {// 判断金额不为空 + // 创建OutaccountDAO对象 + OutaccountDAO outaccountDAO = new OutaccountDAO(AddOutaccount.this); + // 创建Tb_outaccount对象 + Tb_outaccount tb_outaccount = new Tb_outaccount(outaccountDAO.getMaxId() + 1, Double.parseDouble(strMoney), txtTime.getText() + .toString(), spType.getSelectedItem().toString(), txtAddress.getText().toString(), txtMark.getText().toString()); + outaccountDAO.add(tb_outaccount);// 添加支出信息 + // 弹出信息提示 + Toast.makeText(AddOutaccount.this, "〖新增支出〗数据添加成功!", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(AddOutaccount.this, "请输入支出金额!", Toast.LENGTH_SHORT).show(); + } + } + }); + + btnCancelButton.setOnClickListener(new View.OnClickListener() {// 为取消按钮设置监听事件 + + @Override + public void onClick(View arg0) { + txtMoney.setText("");// 设置金额文本框为空 + txtMoney.setHint("0.00");// 为金额文本框设置提示 + txtTime.setText("");// 设置时间文本框为空 + txtTime.setHint("2011-01-01");// 为时间文本框设置提示 + txtAddress.setText("");// 设置地点文本框为空 + txtMark.setText("");// 设置备注文本框为空 + spType.setSelection(0);// 设置类别下拉列表默认选择第一项 + } + }); + + final Calendar c = Calendar.getInstance();// 获取当前系统日期 + mYear = c.get(Calendar.YEAR);// 获取年份 + mMonth = c.get(Calendar.MONTH);// 获取月份 + mDay = c.get(Calendar.DAY_OF_MONTH);// 获取天数 + + updateDisplay();// 显示当前系统时间 + } + + @Override + protected Dialog onCreateDialog(int id) {// 重写onCreateDialog方法 + + switch (id) { + case DATE_DIALOG_ID:// 弹出日期选择对话框 + return new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay); + } + return null; + } + + private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() { + public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { + mYear = year;// 为年份赋值 + mMonth = monthOfYear;// 为月份赋值 + mDay = dayOfMonth;// 为天赋值 + updateDisplay();// 显示设置的日期 + } + }; + + private void updateDisplay() { + // 显示设置的时间 + txtTime.setText(new StringBuilder().append(mYear).append("-").append(mMonth + 1).append("-").append(mDay)); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/homecaicaitong/FlagManage.java b/app/src/main/java/com/example/homecaicaitong/FlagManage.java new file mode 100644 index 0000000..b1ff709 --- /dev/null +++ b/app/src/main/java/com/example/homecaicaitong/FlagManage.java @@ -0,0 +1,54 @@ +package com.example.homecaicaitong; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import com.example.homecaicaitong.dao.FlagDAO; +import com.example.homecaicaitong.model.Tb_flag; + +public class FlagManage extends AppCompatActivity { + private EditText txtFlag;// 创建EditText对象 + private Button btnEdit, btnDel;// 创建两个Button对象 + private String strid;// 创建字符串,表示便签的id + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.flagmanage);// 设置布局文件 + txtFlag = (EditText) findViewById(R.id.txtFlagManage);// 获取便签文本框 + btnEdit = (Button) findViewById(R.id.btnFlagManageEdit);// 获取修改按钮 + btnDel = (Button) findViewById(R.id.btnFlagManageDelete);// 获取删除按钮 + + Intent intent = getIntent();// 创建Intent对象 + Bundle bundle = intent.getExtras();// 获取便签id + strid = bundle.getString(Showinfo.FLAG);// 将便签id转换为字符串 + final FlagDAO flagDAO = new FlagDAO(FlagManage.this);// 创建FlagDAO对象 + txtFlag.setText(flagDAO.find(Integer.parseInt(strid)).getFlag());// 根据便签id查找便签信息,并显示在文本框中 + + btnEdit.setOnClickListener(new View.OnClickListener() {// 为修改按钮设置监听事件 + @Override + public void onClick(View arg0) { + Tb_flag tb_flag = new Tb_flag();// 创建Tb_flag对象 + tb_flag.setid(Integer.parseInt(strid));// 设置便签id + tb_flag.setFlag(txtFlag.getText().toString());// 设置便签值 + flagDAO.update(tb_flag);// 修改便签信息 + // 弹出信息提示 + Toast.makeText(FlagManage.this, "〖便签数据〗修改成功!", Toast.LENGTH_SHORT).show(); + } + }); + + btnDel.setOnClickListener(new View.OnClickListener() {// 为删除按钮设置监听事件 + @Override + public void onClick(View arg0) { + flagDAO.detele(Integer.parseInt(strid));// 根据指定的id删除便签信息 + Toast.makeText(FlagManage.this, "〖便签数据〗删除成功!", Toast.LENGTH_SHORT).show(); + } + }); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/homecaicaitong/Inaccountinfo.java b/app/src/main/java/com/example/homecaicaitong/Inaccountinfo.java new file mode 100644 index 0000000..662d0e5 --- /dev/null +++ b/app/src/main/java/com/example/homecaicaitong/Inaccountinfo.java @@ -0,0 +1,71 @@ +package com.example.homecaicaitong; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.TextView; + +import com.example.homecaicaitong.dao.InaccountDAO; +import com.example.homecaicaitong.model.Tb_inaccount; + +import java.util.List; + +public class Inaccountinfo extends AppCompatActivity { + private static final String FLAG = "id";// 定义一个常量,用来作为请求码 + private ListView lvinfo;// 创建ListView对象 + private String strType = "";// 创建字符串,记录管理类型 + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.inaccountinfo);// 设置布局文件 + lvinfo = (ListView) findViewById(R.id.lvinaccountinfo);// 获取布局文件中的ListView组件 + + showInfo(R.id.btnininfo);// 调用自定义方法显示收入信息 + + lvinfo.setOnItemClickListener(new AdapterView.OnItemClickListener() {// 为ListView添加项单击事件 + + // 覆写onItemClick方法 + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + String strInfo = String.valueOf(((TextView) view).getText());// 记录收入信息 + String strid = strInfo.substring(0, strInfo.indexOf('|'));// 从收入信息中截取收入编号 + Intent intent = new Intent(Inaccountinfo.this, InfoManage.class);// 创建Intent对象 + intent.putExtra(FLAG, new String[] { strid, strType });// 设置传递数据 + startActivity(intent);// 执行Intent操作 + } + }); + } + + private void showInfo(int intType) {// 用来根据传入的管理类型,显示相应的信息 + String[] strInfos = null;// 定义字符串数组,用来存储收入信息 + ArrayAdapter arrayAdapter = null;// 创建ArrayAdapter对象 + strType = "btnininfo";// 为strType变量赋值 + InaccountDAO inaccountinfo = new InaccountDAO(Inaccountinfo.this);// 创建InaccountDAO对象 + // 获取所有收入信息,并存储到List泛型集合中 + List listinfos = inaccountinfo.getScrollData(0, (int) inaccountinfo.getCount()); + strInfos = new String[listinfos.size()];// 设置字符串数组的长度 + int m = 0;// 定义一个开始标识 + for (Tb_inaccount tb_inaccount : listinfos) {// 遍历List泛型集合 + // 将收入相关信息组合成一个字符串,存储到字符串数组的相应位置 + strInfos[m] = tb_inaccount.getid() + "|" + tb_inaccount.getType() + " " + String.valueOf(tb_inaccount.getMoney()) + "元 " + + tb_inaccount.getTime(); + m++;// 标识加1 + } + // 使用字符串数组初始化ArrayAdapter对象 + arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, strInfos); + lvinfo.setAdapter(arrayAdapter);// 为ListView列表设置数据源 + } + + @Override + protected void onRestart() { + // TODO Auto-generated method stub + super.onRestart();// 实现基类中的方法 + showInfo(R.id.btnininfo);// 显示收入信息 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/homecaicaitong/InfoManage.java b/app/src/main/java/com/example/homecaicaitong/InfoManage.java new file mode 100644 index 0000000..9bc8a32 --- /dev/null +++ b/app/src/main/java/com/example/homecaicaitong/InfoManage.java @@ -0,0 +1,163 @@ +package com.example.homecaicaitong; + +import androidx.appcompat.app.AppCompatActivity; + +import android.app.DatePickerDialog; +import android.app.Dialog; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.DatePicker; +import android.widget.EditText; +import android.widget.Spinner; +import android.widget.TextView; +import android.widget.Toast; + +import com.example.homecaicaitong.dao.InaccountDAO; +import com.example.homecaicaitong.dao.OutaccountDAO; +import com.example.homecaicaitong.model.Tb_inaccount; +import com.example.homecaicaitong.model.Tb_outaccount; + +import java.util.Calendar; + +public class InfoManage extends AppCompatActivity { + private static final int DATE_DIALOG_ID = 0;// 创建日期对话框常量 + private TextView tvtitle, textView;// 创建两个TextView对象 + private EditText txtMoney, txtTime, txtHA, txtMark;// 创建4个EditText对象 + private Spinner spType;// 创建Spinner对象 + private Button btnEdit, btnDel;// 创建两个Button对象 + private String[] strInfos;// 定义字符串数组 + private String strid, strType;// 定义两个字符串变量,分别用来记录信息编号和管理类型 + + private int mYear;// 年 + private int mMonth;// 月 + private int mDay;// 日 + + private OutaccountDAO outaccountDAO = new OutaccountDAO(InfoManage.this);// 创建OutaccountDAO对象 + private InaccountDAO inaccountDAO = new InaccountDAO(InfoManage.this);// 创建InaccountDAO对象 + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.infomanage);// 设置布局文件 + tvtitle = (TextView) findViewById(R.id.inouttitle);// 获取标题标签对象 + textView = (TextView) findViewById(R.id.tvInOut);// 获取地点/付款方标签对象 + txtMoney = (EditText) findViewById(R.id.txtInOutMoney);// 获取金额文本框 + txtTime = (EditText) findViewById(R.id.txtInOutTime);// 获取时间文本框 + spType = (Spinner) findViewById(R.id.spInOutType);// 获取类别下拉列表 + txtHA = (EditText) findViewById(R.id.txtInOut);// 获取地点/付款方文本框 + txtMark = (EditText) findViewById(R.id.txtInOutMark);// 获取备注文本框 + btnEdit = (Button) findViewById(R.id.btnInOutEdit);// 获取修改按钮 + btnDel = (Button) findViewById(R.id.btnInOutDelete);// 获取删除按钮 + + Intent intent = getIntent();// 创建Intent对象 + Bundle bundle = intent.getExtras();// 获取传入的数据,并使用Bundle记录 + strInfos = bundle.getStringArray(Showinfo.FLAG);// 获取Bundle中记录的信息 + strid = strInfos[0];// 记录id + strType = strInfos[1];// 记录类型 + if (strType.equals("btnoutinfo")) {// 如果类型是btnoutinfo + + tvtitle.setText("支出管理");// 设置标题为“支出管理” + textView.setText("地 点:");// 设置“地点/付款方”标签文本为“地 点:” + // 根据编号查找支出信息,并存储到Tb_outaccount对象中 + Tb_outaccount tb_outaccount = outaccountDAO.find(Integer.parseInt(strid)); + txtMoney.setText(String.valueOf(tb_outaccount.getMoney()));// 显示金额 + txtTime.setText(tb_outaccount.getTime());// 显示时间 + spType.setPrompt(tb_outaccount.getType());// 显示类别 + txtHA.setText(tb_outaccount.getAddress());// 显示地点 + txtMark.setText(tb_outaccount.getMark());// 显示备注 + } else if (strType.equals("btnininfo")) {// 如果类型是btnininfo + + tvtitle.setText("收入管理");// 设置标题为“收入管理” + textView.setText("付款方:");// 设置“地点/付款方”标签文本为“付款方:” + // 根据编号查找收入信息,并存储到Tb_outaccount对象中 + Tb_inaccount tb_inaccount = inaccountDAO.find(Integer.parseInt(strid)); + txtMoney.setText(String.valueOf(tb_inaccount.getMoney()));// 显示金额 + txtTime.setText(tb_inaccount.getTime());// 显示时间 + spType.setPrompt(tb_inaccount.getType());// 显示类别 + txtHA.setText(tb_inaccount.getHandler());// 显示付款方 + txtMark.setText(tb_inaccount.getMark());// 显示备注 + } + + txtTime.setOnClickListener(new View.OnClickListener() {// 为时间文本框设置单击监听事件 + @Override + public void onClick(View arg0) { + showDialog(DATE_DIALOG_ID);// 显示日期选择对话框 + } + }); + + btnEdit.setOnClickListener(new View.OnClickListener() {// 为修改按钮设置监听事件 + @Override + public void onClick(View arg0) { + if (strType.equals("btnoutinfo")) {// 判断类型如果是btnoutinfo + + Tb_outaccount tb_outaccount = new Tb_outaccount();// 创建Tb_outaccount对象 + tb_outaccount.setid(Integer.parseInt(strid));// 设置编号 + tb_outaccount.setMoney(Double.parseDouble(txtMoney.getText().toString()));// 设置金额 + tb_outaccount.setTime(txtTime.getText().toString());// 设置时间 + tb_outaccount.setType(spType.getSelectedItem().toString());// 设置类别 + tb_outaccount.setAddress(txtHA.getText().toString());// 设置地点 + tb_outaccount.setMark(txtMark.getText().toString());// 设置备注 + outaccountDAO.update(tb_outaccount);// 更新支出信息 + } else if (strType.equals("btnininfo")) {// 判断类型如果是btnininfo + + Tb_inaccount tb_inaccount = new Tb_inaccount();// 创建Tb_inaccount对象 + tb_inaccount.setid(Integer.parseInt(strid));// 设置编号 + tb_inaccount.setMoney(Double.parseDouble(txtMoney.getText().toString()));// 设置金额 + tb_inaccount.setTime(txtTime.getText().toString());// 设置时间 + tb_inaccount.setType(spType.getSelectedItem().toString());// 设置类别 + tb_inaccount.setHandler(txtHA.getText().toString());// 设置付款方 + tb_inaccount.setMark(txtMark.getText().toString());// 设置备注 + inaccountDAO.update(tb_inaccount);// 更新收入信息 + } + // 弹出信息提示 + Toast.makeText(InfoManage.this, "〖数据〗修改成功!", Toast.LENGTH_SHORT).show(); + } + }); + + btnDel.setOnClickListener(new View.OnClickListener() {// 为删除按钮设置监听事件 + @Override + public void onClick(View arg0) { + if (strType.equals("btnoutinfo")) {// 判断类型如果是btnoutinfo + + outaccountDAO.detele(Integer.parseInt(strid));// 根据编号删除支出信息 + } else if (strType.equals("btnininfo")) {// 判断类型如果是btnininfo + + inaccountDAO.detele(Integer.parseInt(strid));// 根据编号删除收入信息 + } + Toast.makeText(InfoManage.this, "〖数据〗删除成功!", Toast.LENGTH_SHORT).show(); + } + }); + + final Calendar c = Calendar.getInstance();// 获取当前系统日期 + mYear = c.get(Calendar.YEAR);// 获取年份 + mMonth = c.get(Calendar.MONTH);// 获取月份 + mDay = c.get(Calendar.DAY_OF_MONTH);// 获取天数 + updateDisplay();// 显示当前系统时间 + } + + @Override + protected Dialog onCreateDialog(int id) {// 重写onCreateDialog方法 + + switch (id) { + case DATE_DIALOG_ID:// 弹出日期选择对话框 + return new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay); + } + return null; + } + + private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() { + public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { + mYear = year;// 为年份赋值 + mMonth = monthOfYear;// 为月份赋值 + mDay = dayOfMonth;// 为天赋值 + updateDisplay();// 显示设置的日期 + } + }; + + private void updateDisplay() { + // 显示设置的时间 + txtTime.setText(new StringBuilder().append(mYear).append("-").append(mMonth + 1).append("-").append(mDay)); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/homecaicaitong/Login.java b/app/src/main/java/com/example/homecaicaitong/Login.java new file mode 100644 index 0000000..1760ada --- /dev/null +++ b/app/src/main/java/com/example/homecaicaitong/Login.java @@ -0,0 +1,54 @@ +package com.example.homecaicaitong; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import com.example.homecaicaitong.dao.PwdDAO; + +public class Login extends AppCompatActivity { + private EditText txtlogin;// 创建EditText对象 + private Button btnlogin, btnclose;// 创建两个Button对象 + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.login);// 设置布局文件 + + txtlogin = (EditText) findViewById(R.id.txtLogin);// 获取密码文本框 + btnlogin = (Button) findViewById(R.id.btnLogin);// 获取登录按钮 + btnclose = (Button) findViewById(R.id.btnClose);// 获取取消按钮 + + btnlogin.setOnClickListener(new View.OnClickListener() {// 为登录按钮设置监听事件 + @Override + public void onClick(View arg0) { + Intent intent = new Intent(Login.this, MainActivity.class);// 创建Intent对象 + PwdDAO pwdDAO = new PwdDAO(Login.this);// 创建PwdDAO对象 + // 判断是否有密码及是否输入了密码 + if ((pwdDAO.getCount() == 0 || pwdDAO.find().getPassword().isEmpty()) && txtlogin.getText().toString().isEmpty()) { + startActivity(intent);// 启动主Activity + } else { + // 判断输入的密码是否与数据库中的密码一致 + if (pwdDAO.find().getPassword().equals(txtlogin.getText().toString())) { + startActivity(intent);// 启动主Activity + } else { + // 弹出信息提示 + Toast.makeText(Login.this, "请输入正确的密码!", Toast.LENGTH_SHORT).show(); + } + } + txtlogin.setText("");// 清空密码文本框 + } + }); + + btnclose.setOnClickListener(new View.OnClickListener() {// 为取消按钮设置监听事件 + @Override + public void onClick(View arg0) { + finish();// 退出当前程序 + } + }); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/homecaicaitong/MainActivity.java b/app/src/main/java/com/example/homecaicaitong/MainActivity.java new file mode 100644 index 0000000..9f0b8ee --- /dev/null +++ b/app/src/main/java/com/example/homecaicaitong/MainActivity.java @@ -0,0 +1,169 @@ +package com.example.homecaicaitong; + +import android.content.Context; +import android.content.Intent; +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.GridView; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.appcompat.app.AppCompatActivity; + +import java.util.ArrayList; +import java.util.List; + +public class MainActivity extends AppCompatActivity { + private GridView gvInfo;// 创建GridView对象 + // 定义字符串数组,存储系统功能 + private String[] titles = new String[] { "新增支出", "新增收入", "我的支出", "我的收入", "数据管理", "系统设置", "收支便签", "退出" }; + // 定义int数组,存储功能对应的图标 + private int[] images = new int[] { R.drawable.addoutaccount, R.drawable.addinaccount, R.drawable.outaccountinfo, R.drawable.inaccountinfo, + R.drawable.showinfo, R.drawable.sysset, R.drawable.accountflag, R.drawable.exit }; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + + gvInfo = (GridView) findViewById(R.id.gvInfo);// 获取布局文件中的gvInfo组件 + PictureAdapter adapter = new PictureAdapter(titles, images, this);// 创建pictureAdapter对象 + gvInfo.setAdapter(adapter);// 为GridView设置数据源 + gvInfo.setOnItemClickListener(new AdapterView.OnItemClickListener() {// 为GridView设置项单击事件 + @Override + public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) { + Intent intent = null;// 创建Intent对象 + switch (arg2) { + case 0: + intent = new Intent(MainActivity.this, AddOutaccount.class);// 使用AddOutaccount窗口初始化Intent + startActivity(intent);// 打开AddOutaccount + break; + case 1: + intent = new Intent(MainActivity.this, AddInaccount.class);// 使用AddInaccount窗口初始化Intent + startActivity(intent);// 打开AddInaccount + break; + case 2: + intent = new Intent(MainActivity.this, Outaccountinfo.class);// 使用Outaccountinfo窗口初始化Intent + startActivity(intent);// 打开Outaccountinfo + break; + case 3: + intent = new Intent(MainActivity.this, Inaccountinfo.class);// 使用Inaccountinfo窗口初始化Intent + startActivity(intent);// 打开Inaccountinfo + break; + case 4: + intent = new Intent(MainActivity.this, Showinfo.class);// 使用Showinfo窗口初始化Intent + startActivity(intent);// 打开Showinfo + break; + case 5: + intent = new Intent(MainActivity.this, Sysset.class);// 使用Sysset窗口初始化Intent + startActivity(intent);// 打开Sysset + break; + case 6: + intent = new Intent(MainActivity.this, Accountflag.class);// 使用Accountflag窗口初始化Intent + startActivity(intent);// 打开Accountflag + break; + case 7: + finish();// 关闭当前Activity + } + } + }); + } +} +class PictureAdapter extends BaseAdapter {// 创建基于BaseAdapter的子类 + + private LayoutInflater inflater;// 创建LayoutInflater对象 + private List pictures;// 创建List泛型集合 + + // 为类创建构造函数 + public PictureAdapter(String[] titles, int[] images, Context context) { + super(); + pictures = new ArrayList();// 初始化泛型集合对象 + inflater = LayoutInflater.from(context);// 初始化LayoutInflater对象 + for (int i = 0; i < images.length; i++)// 遍历图像数组 + { + Picture picture = new Picture(titles[i], images[i]);// 使用标题和图像生成Picture对象 + pictures.add(picture);// 将Picture对象添加到泛型集合中 + } + } + + @Override + public int getCount() {// 获取泛型集合的长度 + if (null != pictures) {// 如果泛型集合不为空 + return pictures.size();// 返回泛型长度 + } else { + return 0;// 返回0 + } + } + + @Override + public Object getItem(int arg0) { + return pictures.get(arg0);// 获取泛型集合指定索引处的项 + } + + @Override + public long getItemId(int arg0) { + return arg0;// 返回泛型集合的索引 + } + + @Override + public View getView(int arg0, View arg1, ViewGroup arg2) { + ViewHolder viewHolder;// 创建ViewHolder对象 + if (arg1 == null) {// 判断图像标识是否为空 + + arg1 = inflater.inflate(R.layout.gvitem, null);// 设置图像标识 + viewHolder = new ViewHolder();// 初始化ViewHolder对象 + viewHolder.title = (TextView) arg1.findViewById(R.id.ItemTitle);// 设置图像标题 + viewHolder.image = (ImageView) arg1.findViewById(R.id.ItemImage);// 设置图像的二进制值 + arg1.setTag(viewHolder);// 设置提示 + } else { + viewHolder = (ViewHolder) arg1.getTag();// 设置提示 + } + viewHolder.title.setText(pictures.get(arg0).getTitle());// 设置图像标题 + viewHolder.image.setImageResource(pictures.get(arg0).getImageId());// 设置图像的二进制值 + return arg1;// 返回图像标识 + } +} + +class ViewHolder {// 创建ViewHolder类 + + public TextView title;// 创建TextView对象 + public ImageView image;// 创建ImageView对象 +} + +class Picture {// 创建Picture类 + + private String title;// 定义字符串,表示图像标题 + private int imageId;// 定义int变量,表示图像的二进制值 + + public Picture() {// 默认构造函数 + + super(); + } + + public Picture(String title, int imageId) {// 定义有参构造函数 + + super(); + this.title = title;// 为图像标题赋值 + this.imageId = imageId;// 为图像的二进制值赋值 + } + + public String getTitle() {// 定义图像标题的可读属性 + return title; + } + + public void setTitle(String title) {// 定义图像标题的可写属性 + this.title = title; + } + + public int getImageId() {// 定义图像二进制值的可读属性 + return imageId; + } + + public void setimageId(int imageId) {// 定义图像二进制值的可写属性 + this.imageId = imageId; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/homecaicaitong/Outaccountinfo.java b/app/src/main/java/com/example/homecaicaitong/Outaccountinfo.java new file mode 100644 index 0000000..b84a50e --- /dev/null +++ b/app/src/main/java/com/example/homecaicaitong/Outaccountinfo.java @@ -0,0 +1,71 @@ +package com.example.homecaicaitong; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.TextView; + +import com.example.homecaicaitong.dao.OutaccountDAO; +import com.example.homecaicaitong.model.Tb_outaccount; + +import java.util.List; + +public class Outaccountinfo extends AppCompatActivity { + public static final String FLAG = "id";// 定义一个常量,用来作为请求码 + ListView lvinfo;// 创建ListView对象 + String strType = "";// 创建字符串,记录管理类型 + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.outaccountinfo);// 设置布局文件 + lvinfo = (ListView) findViewById(R.id.lvoutaccountinfo);// 获取布局文件中的ListView组件 + + ShowInfo(R.id.btnoutinfo);// 调用自定义方法显示支出信息 + + lvinfo.setOnItemClickListener(new AdapterView.OnItemClickListener()// 为ListView添加项单击事件 + { + // 覆写onItemClick方法 + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + String strInfo = String.valueOf(((TextView) view).getText());// 记录支出信息 + String strid = strInfo.substring(0, strInfo.indexOf('|'));// 从支出信息中截取支出编号 + Intent intent = new Intent(Outaccountinfo.this, InfoManage.class);// 创建Intent对象 + intent.putExtra(FLAG, new String[] { strid, strType });// 设置传递数据 + startActivity(intent);// 执行Intent操作 + } + }); + } + + private void ShowInfo(int intType) {// 用来根据传入的管理类型,显示相应的信息 + String[] strInfos = null;// 定义字符串数组,用来存储支出信息 + ArrayAdapter arrayAdapter = null;// 创建ArrayAdapter对象 + strType = "btnoutinfo";// 为strType变量赋值 + OutaccountDAO outaccountinfo = new OutaccountDAO(Outaccountinfo.this);// 创建OutaccountDAO对象 + // 获取所有支出信息,并存储到List泛型集合中 + List listoutinfos = outaccountinfo.getScrollData(0, (int) outaccountinfo.getCount()); + strInfos = new String[listoutinfos.size()];// 设置字符串数组的长度 + int i = 0;// 定义一个开始标识 + for (Tb_outaccount tb_outaccount : listoutinfos) {// 遍历List泛型集合 + // 将支出相关信息组合成一个字符串,存储到字符串数组的相应位置 + strInfos[i] = tb_outaccount.getid() + "|" + tb_outaccount.getType() + " " + String.valueOf(tb_outaccount.getMoney()) + "元 " + + tb_outaccount.getTime(); + i++;// 标识加1 + } + // 使用字符串数组初始化ArrayAdapter对象 + arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, strInfos); + lvinfo.setAdapter(arrayAdapter);// 为ListView列表设置数据源 + } + + @Override + protected void onRestart() { + // TODO Auto-generated method stub + super.onRestart();// 实现基类中的方法 + ShowInfo(R.id.btnoutinfo);// 显示收入信息 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/homecaicaitong/Showinfo.java b/app/src/main/java/com/example/homecaicaitong/Showinfo.java new file mode 100644 index 0000000..8c2f7f4 --- /dev/null +++ b/app/src/main/java/com/example/homecaicaitong/Showinfo.java @@ -0,0 +1,139 @@ +package com.example.homecaicaitong; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.ListView; +import android.widget.TextView; + +import com.example.homecaicaitong.dao.FlagDAO; +import com.example.homecaicaitong.dao.InaccountDAO; +import com.example.homecaicaitong.dao.OutaccountDAO; +import com.example.homecaicaitong.model.Tb_flag; +import com.example.homecaicaitong.model.Tb_inaccount; +import com.example.homecaicaitong.model.Tb_outaccount; + +import java.util.List; + +public class Showinfo extends AppCompatActivity { + public static final String FLAG = "id";// 定义一个常量,用来作为请求码 + private Button btnoutinfo, btnininfo, btnflaginfo;// 创建3个Button对象 + private ListView lvinfo;// 创建ListView对象 + private String strType = "";// 创建字符串,记录管理类型 + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.showinfo);// 设置布局文件 + + lvinfo = (ListView) findViewById(R.id.lvinfo);// 获取布局文件中的ListView组件 + btnoutinfo = (Button) findViewById(R.id.btnoutinfo);// 获取布局文件中的支出信息按钮 + btnininfo = (Button) findViewById(R.id.btnininfo);// 获取布局文件中的收入信息按钮 + btnflaginfo = (Button) findViewById(R.id.btnflaginfo);// 获取布局文件中的便签信息按钮 + + showInfo(R.id.btnoutinfo);// 默认显示支出信息 + + btnoutinfo.setOnClickListener(new View.OnClickListener() {// 为支出信息按钮设置监听事件 + @Override + public void onClick(View arg0) { + showInfo(R.id.btnoutinfo);// 显示支出信息 + } + }); + + btnininfo.setOnClickListener(new View.OnClickListener() {// 为收入信息按钮设置监听事件 + @Override + public void onClick(View arg0) { + showInfo(R.id.btnininfo);// 显示收入信息 + } + }); + btnflaginfo.setOnClickListener(new View.OnClickListener() {// 为便签信息按钮设置监听事件 + @Override + public void onClick(View arg0) { + showInfo(R.id.btnflaginfo);// 显示便签信息 + } + }); + + lvinfo.setOnItemClickListener(new AdapterView.OnItemClickListener() {// 为ListView添加项单击事件 + + // 覆写onItemClick方法 + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + String strInfo = String.valueOf(((TextView) view).getText());// 记录单击的项信息 + String strid = strInfo.substring(0, strInfo.indexOf('|'));// 从项信息中截取编号 + Intent intent = null;// 创建Intent对象 + if (strType == "btnoutinfo" | strType == "btnininfo") {// 判断如果是支出或者收入信息 + intent = new Intent(Showinfo.this, InfoManage.class);// 使用InfoManage窗口初始化Intent对象 + intent.putExtra(FLAG, new String[] { strid, strType });// 设置要传递的数据 + } else if (strType == "btnflaginfo") {// 判断如果是便签信息 + intent = new Intent(Showinfo.this, FlagManage.class);// 使用FlagManage窗口初始化Intent对象 + intent.putExtra(FLAG, strid);// 设置要传递的数据 + } + startActivity(intent);// 执行Intent,打开相应的Activity + } + }); + } + + private void showInfo(int intType) {// 用来根据传入的管理类型,显示相应的信息 + String[] strInfos = null;// 定义字符串数组,用来存储收入信息 + ArrayAdapter arrayAdapter = null;// 创建ArrayAdapter对象 + switch (intType) {// 以intType为条件进行判断 + case R.id.btnoutinfo:// 如果是btnoutinfo按钮 + strType = "btnoutinfo";// 为strType变量赋值 + OutaccountDAO outaccountinfo = new OutaccountDAO(Showinfo.this);// 创建OutaccountDAO对象 + // 获取所有支出信息,并存储到List泛型集合中 + List listoutinfos = outaccountinfo.getScrollData(0, (int) outaccountinfo.getCount()); + strInfos = new String[listoutinfos.size()];// 设置字符串数组的长度 + int i = 0;// 定义一个开始标识 + for (Tb_outaccount tb_outaccount : listoutinfos) {// 遍历List泛型集合 + // 将支出相关信息组合成一个字符串,存储到字符串数组的相应位置 + strInfos[i] = tb_outaccount.getid() + "|" + tb_outaccount.getType() + " " + String.valueOf(tb_outaccount.getMoney()) + "元 " + + tb_outaccount.getTime(); + i++;// 标识加1 + } + break; + case R.id.btnininfo:// 如果是btnininfo按钮 + strType = "btnininfo";// 为strType变量赋值 + InaccountDAO inaccountinfo = new InaccountDAO(Showinfo.this);// 创建InaccountDAO对象 + // 获取所有收入信息,并存储到List泛型集合中 + List listinfos = inaccountinfo.getScrollData(0, (int) inaccountinfo.getCount()); + strInfos = new String[listinfos.size()];// 设置字符串数组的长度 + int m = 0;// 定义一个开始标识 + for (Tb_inaccount tb_inaccount : listinfos) {// 遍历List泛型集合 + // 将收入相关信息组合成一个字符串,存储到字符串数组的相应位置 + strInfos[m] = tb_inaccount.getid() + "|" + tb_inaccount.getType() + " " + String.valueOf(tb_inaccount.getMoney()) + "元 " + + tb_inaccount.getTime(); + m++;// 标识加1 + } + break; + case R.id.btnflaginfo:// 如果是btnflaginfo按钮 + strType = "btnflaginfo";// 为strType变量赋值 + FlagDAO flaginfo = new FlagDAO(Showinfo.this);// 创建FlagDAO对象 + // 获取所有便签信息,并存储到List泛型集合中 + List listFlags = flaginfo.getScrollData(0, (int) flaginfo.getCount()); + strInfos = new String[listFlags.size()];// 设置字符串数组的长度 + int n = 0;// 定义一个开始标识 + for (Tb_flag tb_flag : listFlags) {// 遍历List泛型集合 + // 将便签相关信息组合成一个字符串,存储到字符串数组的相应位置 + strInfos[n] = tb_flag.getid() + "|" + tb_flag.getFlag(); + if (strInfos[n].length() > 15)// 判断便签信息的长度是否大于15 + strInfos[n] = strInfos[n].substring(0, 15) + "……";// 将位置大于15之后的字符串用……代替 + n++;// 标识加1 + } + break; + } + // 使用字符串数组初始化ArrayAdapter对象 + arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, strInfos); + lvinfo.setAdapter(arrayAdapter);// 为ListView列表设置数据源 + } + + @Override + protected void onRestart() { + super.onRestart();// 实现基类中的方法 + showInfo(R.id.btnoutinfo);// 显示支出信息 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/homecaicaitong/Sysset.java b/app/src/main/java/com/example/homecaicaitong/Sysset.java new file mode 100644 index 0000000..c16f701 --- /dev/null +++ b/app/src/main/java/com/example/homecaicaitong/Sysset.java @@ -0,0 +1,51 @@ +package com.example.homecaicaitong; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import com.example.homecaicaitong.dao.PwdDAO; +import com.example.homecaicaitong.model.Tb_pwd; + +public class Sysset extends AppCompatActivity { + private EditText txtpwd;// 创建EditText对象 + private Button btnSet, btnsetCancel;// 创建两个Button对象 + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.sysset);// 设置布局文件 + + txtpwd = (EditText) findViewById(R.id.txtPwd);// 获取密码文本框 + btnSet = (Button) findViewById(R.id.btnSet);// 获取设置按钮 + btnsetCancel = (Button) findViewById(R.id.btnsetCancel);// 获取取消按钮 + + btnSet.setOnClickListener(new View.OnClickListener() {// 为设置按钮添加监听事件 + @Override + public void onClick(View arg0) { + PwdDAO pwdDAO = new PwdDAO(Sysset.this);// 创建PwdDAO对象 + Tb_pwd tb_pwd = new Tb_pwd(txtpwd.getText().toString());// 根据输入的密码创建Tb_pwd对象 + if (pwdDAO.getCount() == 0) {// 判断数据库中是否已经设置了密码 + pwdDAO.add(tb_pwd);// 添加用户密码 + } else { + pwdDAO.update(tb_pwd);// 修改用户密码 + } + // 弹出信息提示 + Toast.makeText(Sysset.this, "〖密码〗设置成功!", Toast.LENGTH_SHORT).show(); + } + }); + + btnsetCancel.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View arg0) { + txtpwd.setText("");// 清空密码文本框 + txtpwd.setHint("请输入密码");// 为密码文本框设置提示 + } + }); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/homecaicaitong/dao/DBOpenHelper.java b/app/src/main/java/com/example/homecaicaitong/dao/DBOpenHelper.java new file mode 100644 index 0000000..943876f --- /dev/null +++ b/app/src/main/java/com/example/homecaicaitong/dao/DBOpenHelper.java @@ -0,0 +1,30 @@ +package com.example.homecaicaitong.dao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; + +public class DBOpenHelper extends SQLiteOpenHelper { + private static final int VERSION = 1;// 定义数据库版本号 + private static final String DBNAME = "account.db";// 定义数据库名 + + public DBOpenHelper(Context context) {// 定义构造函数 + + super(context, DBNAME, null, VERSION);// 重写基类的构造函数 + } + + @Override + public void onCreate(SQLiteDatabase db) {// 创建数据库 + db.execSQL("create table tb_outaccount (_id integer primary key,money decimal,time varchar(10)," + + "type varchar(10),address varchar(100),mark varchar(200))");// 创建支出信息表 + db.execSQL("create table tb_inaccount (_id integer primary key,money decimal,time varchar(10)," + + "type varchar(10),handler varchar(100),mark varchar(200))");// 创建收入信息表 + db.execSQL("create table tb_pwd (password varchar(20))");// 创建密码表 + db.execSQL("create table tb_flag (_id integer primary key,flag varchar(200))");// 创建便签信息表 + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {// 覆写基类的onUpgrade方法,以便数据库版本更新 + + } +} diff --git a/app/src/main/java/com/example/homecaicaitong/dao/FlagDAO.java b/app/src/main/java/com/example/homecaicaitong/dao/FlagDAO.java new file mode 100644 index 0000000..a46e410 --- /dev/null +++ b/app/src/main/java/com/example/homecaicaitong/dao/FlagDAO.java @@ -0,0 +1,124 @@ +package com.example.homecaicaitong.dao; + import android.content.Context; + import android.database.Cursor; + import android.database.sqlite.SQLiteDatabase; + import java.util.ArrayList; + import java.util.List; + import com.example.homecaicaitong.model.Tb_flag; +public class FlagDAO { + private DBOpenHelper helper;// 创建DBOpenHelper对象 + private SQLiteDatabase db;// 创建SQLiteDatabase对象 + + public FlagDAO(Context context) {// 定义构造函数 + + helper = new DBOpenHelper(context);// 初始化DBOpenHelper对象 + } + + /** + * 添加便签信息 + * + * @param tb_flag + */ + public void add(Tb_flag tb_flag) { + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + db.execSQL("insert into tb_flag (_id,flag) values (?,?)", new Object[] { tb_flag.getid(), tb_flag.getFlag() });// 执行添加便签信息操作 + } + + /** + * 更新便签信息 + * + * @param tb_flag + */ + public void update(Tb_flag tb_flag) { + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + db.execSQL("update tb_flag set flag = ? where _id = ?", new Object[] { tb_flag.getFlag(), tb_flag.getid() });// 执行修改便签信息操作 + } + + /** + * 查找便签信息 + * + * @param id + * @return + */ + public Tb_flag find(int id) { + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + Cursor cursor = db.rawQuery("select _id,flag from tb_flag where _id = ?", new String[] { String.valueOf(id) });// 根据编号查找便签信息,并存储到Cursor类中 + if (cursor.moveToNext()) {// 遍历查找到的便签信息 + + // 将遍历到的便签信息存储到Tb_flag类中 + return new Tb_flag(cursor.getInt(cursor.getColumnIndex("_id")), cursor.getString(cursor.getColumnIndex("flag"))); + } + return null;// 如果没有信息,则返回null + } + + /** + * 刪除便签信息 + * + * @param ids + */ + public void detele(Integer... ids) { + if (ids.length > 0) {// 判断是否存在要删除的id + + StringBuffer sb = new StringBuffer();// 创建StringBuffer对象 + for (int i = 0; i < ids.length; i++) {// 遍历要删除的id集合 + + sb.append('?').append(',');// 将删除条件添加到StringBuffer对象中 + } + sb.deleteCharAt(sb.length() - 1);// 去掉最后一个“,“字符 + db = helper.getWritableDatabase();// 创建SQLiteDatabase对象 + // 执行删除便签信息操作 + db.execSQL("delete from tb_flag where _id in (" + sb + ")", (Object[]) ids); + } + } + + /** + * 获取便签信息 + * + * @param start + * 起始位置 + * @param count + * 每页显示数量 + * @return + */ + public List getScrollData(int start, int count) { + List lisTb_flags = new ArrayList();// 创建集合对象 + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + // 获取所有便签信息 + Cursor cursor = db.rawQuery("select * from tb_flag limit ?,?", new String[] { String.valueOf(start), String.valueOf(count) }); + while (cursor.moveToNext()) {// 遍历所有的便签信息 + + // 将遍历到的便签信息添加到集合中 + lisTb_flags.add(new Tb_flag(cursor.getInt(cursor.getColumnIndex("_id")), cursor.getString(cursor.getColumnIndex("flag")))); + } + return lisTb_flags;// 返回集合 + } + + /** + * 获取总记录数 + * + * @return + */ + public long getCount() { + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + Cursor cursor = db.rawQuery("select count(_id) from tb_flag", null);// 获取便签信息的记录数 + if (cursor.moveToNext()) {// 判断Cursor中是否有数据 + + return cursor.getLong(0);// 返回总记录数 + } + return 0;// 如果没有数据,则返回0 + } + + /** + * 获取便签最大编号 + * + * @return + */ + public int getMaxId() { + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + Cursor cursor = db.rawQuery("select max(_id) from tb_flag", null);// 获取便签信息表中的最大编号 + while (cursor.moveToLast()) {// 访问Cursor中的最后一条数据 + return cursor.getInt(0);// 获取访问到的数据,即最大编号 + } + return 0;// 如果没有数据,则返回0 + } +} diff --git a/app/src/main/java/com/example/homecaicaitong/dao/InaccountDAO.java b/app/src/main/java/com/example/homecaicaitong/dao/InaccountDAO.java new file mode 100644 index 0000000..5c268a0 --- /dev/null +++ b/app/src/main/java/com/example/homecaicaitong/dao/InaccountDAO.java @@ -0,0 +1,137 @@ +package com.example.homecaicaitong.dao; + +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; + +import java.util.ArrayList; +import java.util.List; + + import com.example.homecaicaitong.model.Tb_inaccount; + +public class InaccountDAO { + private DBOpenHelper helper;// 创建DBOpenHelper对象 + private SQLiteDatabase db;// 创建SQLiteDatabase对象 + + public InaccountDAO(Context context) {// 定义构造函数 + + helper = new DBOpenHelper(context);// 初始化DBOpenHelper对象 + } + + /** + * 添加收入信息 + * + * @param tb_inaccount + */ + public void add(Tb_inaccount tb_inaccount) { + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + // 执行添加收入信息操作 + db.execSQL("insert into tb_inaccount (_id,money,time,type,handler,mark) values (?,?,?,?,?,?)", + new Object[] { tb_inaccount.getid(), tb_inaccount.getMoney(), tb_inaccount.getTime(), tb_inaccount.getType(), tb_inaccount.getHandler(), + tb_inaccount.getMark() }); + } + + /** + * 更新收入信息 + * + * @param tb_inaccount + */ + public void update(Tb_inaccount tb_inaccount) { + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + // 执行修改收入信息操作 + db.execSQL("update tb_inaccount set money = ?,time = ?,type = ?,handler = ?,mark = ? where _id = ?", new Object[] { tb_inaccount.getMoney(), + tb_inaccount.getTime(), tb_inaccount.getType(), tb_inaccount.getHandler(), tb_inaccount.getMark(), tb_inaccount.getid() }); + } + + /** + * 查找收入信息 + * + * @param id + * @return + */ + public Tb_inaccount find(int id) { + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + Cursor cursor = db.rawQuery("select _id,money,time,type,handler,mark from tb_inaccount where _id = ?", new String[] { String.valueOf(id) });// 根据编号查找收入信息,并存储到Cursor类中 + if (cursor.moveToNext()) {// 遍历查找到的收入信息 + + // 将遍历到的收入信息存储到Tb_inaccount类中 + return new Tb_inaccount(cursor.getInt(cursor.getColumnIndex("_id")), cursor.getDouble(cursor.getColumnIndex("money")), cursor.getString(cursor + .getColumnIndex("time")), cursor.getString(cursor.getColumnIndex("type")), cursor.getString(cursor.getColumnIndex("handler")), + cursor.getString(cursor.getColumnIndex("mark"))); + } + return null;// 如果没有信息,则返回null + } + + /** + * 刪除收入信息 + * + * @param ids + */ + public void detele(Integer... ids) { + if (ids.length > 0) {// 判断是否存在要删除的id + + StringBuffer sb = new StringBuffer();// 创建StringBuffer对象 + for (int i = 0; i < ids.length; i++) {// 遍历要删除的id集合 + + sb.append('?').append(',');// 将删除条件添加到StringBuffer对象中 + } + sb.deleteCharAt(sb.length() - 1);// 去掉最后一个“,“字符 + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + // 执行删除收入信息操作 + db.execSQL("delete from tb_inaccount where _id in (" + sb + ")", (Object[]) ids); + } + } + + /** + * 获取收入信息 + * + * @param start + * 起始位置 + * @param count + * 每页显示数量 + * @return + */ + public List getScrollData(int start, int count) { + List tb_inaccount = new ArrayList();// 创建集合对象 + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + // 获取所有收入信息 + Cursor cursor = db.rawQuery("select * from tb_inaccount limit ?,?", new String[] { String.valueOf(start), String.valueOf(count) }); + while (cursor.moveToNext()) {// 遍历所有的收入信息 + + // 将遍历到的收入信息添加到集合中 + tb_inaccount.add(new Tb_inaccount(cursor.getInt(cursor.getColumnIndex("_id")), cursor.getDouble(cursor.getColumnIndex("money")), cursor + .getString(cursor.getColumnIndex("time")), cursor.getString(cursor.getColumnIndex("type")), cursor.getString(cursor + .getColumnIndex("handler")), cursor.getString(cursor.getColumnIndex("mark")))); + } + return tb_inaccount;// 返回集合 + } + + /** + * 获取总记录数 + * + * @return + */ + public long getCount() { + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + Cursor cursor = db.rawQuery("select count(_id) from tb_inaccount", null);// 获取收入信息的记录数 + if (cursor.moveToNext()) {// 判断Cursor中是否有数据 + + return cursor.getLong(0);// 返回总记录数 + } + return 0;// 如果没有数据,则返回0 + } + + /** + * 获取收入最大编号 + * + * @return + */ + public int getMaxId() { + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + Cursor cursor = db.rawQuery("select max(_id) from tb_inaccount", null);// 获取收入信息表中的最大编号 + while (cursor.moveToLast()) {// 访问Cursor中的最后一条数据 + return cursor.getInt(0);// 获取访问到的数据,即最大编号 + } + return 0;// 如果没有数据,则返回0 + } +} diff --git a/app/src/main/java/com/example/homecaicaitong/dao/OutaccountDAO.java b/app/src/main/java/com/example/homecaicaitong/dao/OutaccountDAO.java new file mode 100644 index 0000000..950858c --- /dev/null +++ b/app/src/main/java/com/example/homecaicaitong/dao/OutaccountDAO.java @@ -0,0 +1,136 @@ +package com.example.homecaicaitong.dao; + +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; + +import java.util.ArrayList; +import java.util.List; + import com.example.homecaicaitong.model.Tb_outaccount; + +public class OutaccountDAO { + private DBOpenHelper helper;// 创建DBOpenHelper对象 + private SQLiteDatabase db;// 创建SQLiteDatabase对象 + + public OutaccountDAO(Context context) {// 定义构造函数 + + helper = new DBOpenHelper(context);// 初始化DBOpenHelper对象 + } + + /** + * 添加支出信息 + * + * @param tb_outaccount + */ + public void add(Tb_outaccount tb_outaccount) { + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + // 执行添加支出信息操作 + db.execSQL("insert into tb_outaccount (_id,money,time,type,address,mark) values (?,?,?,?,?,?)", + new Object[] { tb_outaccount.getid(), tb_outaccount.getMoney(), tb_outaccount.getTime(), tb_outaccount.getType(), tb_outaccount.getAddress(), + tb_outaccount.getMark() }); + } + + /** + * 更新支出信息 + * + * @param tb_outaccount + */ + public void update(Tb_outaccount tb_outaccount) { + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + // 执行修改支出信息操作 + db.execSQL("update tb_outaccount set money = ?,time = ?,type = ?,address = ?,mark = ? where _id = ?", new Object[] { tb_outaccount.getMoney(), + tb_outaccount.getTime(), tb_outaccount.getType(), tb_outaccount.getAddress(), tb_outaccount.getMark(), tb_outaccount.getid() }); + } + + /** + * 查找支出信息 + * + * @param id + * @return + */ + public Tb_outaccount find(int id) { + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + Cursor cursor = db.rawQuery("select _id,money,time,type,address,mark from tb_outaccount where _id = ?", new String[] { String.valueOf(id) });// 根据编号查找支出信息,并存储到Cursor类中 + if (cursor.moveToNext()) {// 遍历查找到的支出信息 + + // 将遍历到的支出信息存储到Tb_outaccount类中 + return new Tb_outaccount(cursor.getInt(cursor.getColumnIndex("_id")), cursor.getDouble(cursor.getColumnIndex("money")), cursor.getString(cursor + .getColumnIndex("time")), cursor.getString(cursor.getColumnIndex("type")), cursor.getString(cursor.getColumnIndex("address")), + cursor.getString(cursor.getColumnIndex("mark"))); + } + return null;// 如果没有信息,则返回null + } + + /** + * 刪除支出信息 + * + * @param ids + */ + public void detele(Integer... ids) { + if (ids.length > 0) {// 判断是否存在要删除的id + + StringBuffer sb = new StringBuffer();// 创建StringBuffer对象 + for (int i = 0; i < ids.length; i++) {// 遍历要删除的id集合 + + sb.append('?').append(',');// 将删除条件添加到StringBuffer对象中 + } + sb.deleteCharAt(sb.length() - 1);// 去掉最后一个“,“字符 + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + // 执行删除支出信息操作 + db.execSQL("delete from tb_outaccount where _id in (" + sb + ")", (Object[]) ids); + } + } + + /** + * 获取支出信息 + * + * @param start + * 起始位置 + * @param count + * 每页显示数量 + * @return + */ + public List getScrollData(int start, int count) { + List tb_outaccount = new ArrayList();// 创建集合对象 + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + // 获取所有支出信息 + Cursor cursor = db.rawQuery("select * from tb_outaccount limit ?,?", new String[] { String.valueOf(start), String.valueOf(count) }); + while (cursor.moveToNext()) {// 遍历所有的支出信息 + + // 将遍历到的支出信息添加到集合中 + tb_outaccount.add(new Tb_outaccount(cursor.getInt(cursor.getColumnIndex("_id")), cursor.getDouble(cursor.getColumnIndex("money")), cursor + .getString(cursor.getColumnIndex("time")), cursor.getString(cursor.getColumnIndex("type")), cursor.getString(cursor + .getColumnIndex("address")), cursor.getString(cursor.getColumnIndex("mark")))); + } + return tb_outaccount;// 返回集合 + } + + /** + * 获取总记录数 + * + * @return + */ + public long getCount() { + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + Cursor cursor = db.rawQuery("select count(_id) from tb_outaccount", null);// 获取支出信息的记录数 + if (cursor.moveToNext()) {// 判断Cursor中是否有数据 + + return cursor.getLong(0);// 返回总记录数 + } + return 0;// 如果没有数据,则返回0 + } + + /** + * 获取支出最大编号 + * + * @return + */ + public int getMaxId() { + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + Cursor cursor = db.rawQuery("select max(_id) from tb_outaccount", null);// 获取支出信息表中的最大编号 + while (cursor.moveToLast()) {// 访问Cursor中的最后一条数据 + return cursor.getInt(0);// 获取访问到的数据,即最大编号 + } + return 0;// 如果没有数据,则返回0 + } +} diff --git a/app/src/main/java/com/example/homecaicaitong/dao/PwdDAO.java b/app/src/main/java/com/example/homecaicaitong/dao/PwdDAO.java new file mode 100644 index 0000000..71e14a0 --- /dev/null +++ b/app/src/main/java/com/example/homecaicaitong/dao/PwdDAO.java @@ -0,0 +1,64 @@ +package com.example.homecaicaitong.dao; + +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; + + import com.example.homecaicaitong.model.Tb_pwd; + +public class PwdDAO { + private DBOpenHelper helper;// 创建DBOpenHelper对象 + private SQLiteDatabase db;// 创建SQLiteDatabase对象 + + public PwdDAO(Context context) {// 定义构造函数 + + helper = new DBOpenHelper(context);// 初始化DBOpenHelper对象 + } + + /** + * 添加密码信息 + * + * @param tb_pwd + */ + public void add(Tb_pwd tb_pwd) { + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + // 执行添加密码操作 + db.execSQL("insert into tb_pwd (password) values (?)", new Object[] { tb_pwd.getPassword() }); + } + + /** + * 设置密码信息 + * + * @param tb_pwd + */ + public void update(Tb_pwd tb_pwd) { + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + // 执行修改密码操作 + db.execSQL("update tb_pwd set password = ?", new Object[] { tb_pwd.getPassword() }); + } + + /** + * 查找密码信息 + * + * @return + */ + public Tb_pwd find() { + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + // 查找密码并存储到Cursor类中 + Cursor cursor = db.rawQuery("select password from tb_pwd", null); + if (cursor.moveToNext()) {// 遍历查找到的密码信息 + // 将密码存储到Tb_pwd类中 + return new Tb_pwd(cursor.getString(cursor.getColumnIndex("password"))); + } + return null;// 如果没有信息,则返回null + } + + public long getCount() { + db = helper.getWritableDatabase();// 初始化SQLiteDatabase对象 + Cursor cursor = db.rawQuery("select count(password) from tb_pwd", null);// 获取密码信息的记录数 + if (cursor.moveToNext()) {// 判断Cursor中是否有数据 + return cursor.getLong(0);// 返回总记录数 + } + return 0;// 如果没有数据,则返回0 + } +} diff --git a/app/src/main/java/com/example/homecaicaitong/model/Tb_flag.java b/app/src/main/java/com/example/homecaicaitong/model/Tb_flag.java new file mode 100644 index 0000000..1d84986 --- /dev/null +++ b/app/src/main/java/com/example/homecaicaitong/model/Tb_flag.java @@ -0,0 +1,35 @@ +package com.example.homecaicaitong.model; + + +public class Tb_flag// 便签信息实体类 +{ + private int _id;// 存储便签编号 + private String flag;// 存储便签信息 + + public Tb_flag() {// 默认构造函数 + super(); + } + + // 定义有参构造函数,用来初始化便签信息实体类中的各个字段 + public Tb_flag(int id, String flag) { + super(); + this._id = id;// 为便签号赋值 + this.flag = flag;// 为便签信息赋值 + } + + public int getid() {// 设置便签编号的可读属性 + return _id; + } + + public void setid(int id) {// 设置便签编号的可写属性 + this._id = id; + } + + public String getFlag() {// 设置便签信息的可读属性 + return flag; + } + + public void setFlag(String flag) {// 设置便签信息的可写属性 + this.flag = flag; + } +} diff --git a/app/src/main/java/com/example/homecaicaitong/model/Tb_inaccount.java b/app/src/main/java/com/example/homecaicaitong/model/Tb_inaccount.java new file mode 100644 index 0000000..11d7387 --- /dev/null +++ b/app/src/main/java/com/example/homecaicaitong/model/Tb_inaccount.java @@ -0,0 +1,74 @@ +package com.example.homecaicaitong.model; + +public class Tb_inaccount {// 收入信息实体类 + + private int _id;// 存储收入编号 + private double money;// 存储收入金额 + private String time;// 存储收入时间 + private String type;// 存储收入类别 + private String handler;// 存储收入付款方 + private String mark;// 存储收入备注 + + public Tb_inaccount() {// 默认构造函数 + super(); + } + + // 定义有参构造函数,用来初始化收入信息实体类中的各个字段 + public Tb_inaccount(int id, double money, String time, String type, String handler, String mark) { + super(); + this._id = id;// 为收入编号赋值 + this.money = money;// 为收入金额赋值 + this.time = time;// 为收入时间赋值 + this.type = type;// 为收入类别赋值 + this.handler = handler;// 为收入付款方赋值 + this.mark = mark;// 为收入备注赋值 + } + + public int getid() {// 设置收入编号的可读属性 + return _id; + } + + public void setid(int id) {// 设置收入编号的可写属性 + this._id = id; + } + + public double getMoney() {// 设置收入金额的可读属性 + return money; + } + + public void setMoney(double money) {// 设置收入金额的可写属性 + this.money = money; + } + + public String getTime() {// 设置收入时间的可读属性 + return time; + } + + public void setTime(String time) {// 设置收入时间的可写属性 + this.time = time; + } + + public String getType() {// 设置收入类别的可读属性 + return type; + } + + public void setType(String type) {// 设置收入类别的可写属性 + this.type = type; + } + + public String getHandler() {// 设置收入付款方的可读属性 + return handler; + } + + public void setHandler(String handler) {// 设置收入付款方的可写属性 + this.handler = handler; + } + + public String getMark() {// 设置收入备注的可读属性 + return mark; + } + + public void setMark(String mark) {// 设置收入备注的可写属性 + this.mark = mark; + } +} diff --git a/app/src/main/java/com/example/homecaicaitong/model/Tb_outaccount.java b/app/src/main/java/com/example/homecaicaitong/model/Tb_outaccount.java new file mode 100644 index 0000000..51f2ecb --- /dev/null +++ b/app/src/main/java/com/example/homecaicaitong/model/Tb_outaccount.java @@ -0,0 +1,74 @@ +package com.example.homecaicaitong.model; + +public class Tb_outaccount// 支出信息实体类 +{ + private int _id;// 存储支出编号 + private double money;// 存储支出金额 + private String time;// 存储支出时间 + private String type;// 存储支出类别 + private String address;// 存储支出地点 + private String mark;// 存储支出备注 + + public Tb_outaccount() {// 默认构造函数 + super(); + } + + // 定义有参构造函数,用来初始化支出信息实体类中的各个字段 + public Tb_outaccount(int id, double money, String time, String type, String address, String mark) { + super(); + this._id = id;// 为支出编号赋值 + this.money = money;// 为支出金额赋值 + this.time = time;// 为支出时间赋值 + this.type = type;// 为支出类别赋值 + this.address = address;// 为支出地点赋值 + this.mark = mark;// 为支出备注赋值 + } + + public int getid() {// 设置支出编号的可读属性 + return _id; + } + + public void setid(int id) {// 设置支出编号的可写属性 + this._id = id; + } + + public double getMoney() {// 设置支出金额的可读属性 + return money; + } + + public void setMoney(double money) {// 设置支出金额的可写属性 + this.money = money; + } + + public String getTime() {// 设置支出时间的可读属性 + return time; + } + + public void setTime(String time) {// 设置支出时间的可写属性 + this.time = time; + } + + public String getType() {// 设置支出类别的可读属性 + return type; + } + + public void setType(String type) {// 设置支出类别的可写属性 + this.type = type; + } + + public String getAddress() {// 设置支出地点的可读属性 + return address; + } + + public void setAddress(String address) {// 设置支出地点的可写属性 + this.address = address; + } + + public String getMark() {// 设置支出备注的可读属性 + return mark; + } + + public void setMark(String mark) {// 设置支出备注的可写属性 + this.mark = mark; + } +} diff --git a/app/src/main/java/com/example/homecaicaitong/model/Tb_pwd.java b/app/src/main/java/com/example/homecaicaitong/model/Tb_pwd.java new file mode 100644 index 0000000..d04d568 --- /dev/null +++ b/app/src/main/java/com/example/homecaicaitong/model/Tb_pwd.java @@ -0,0 +1,24 @@ +package com.example.homecaicaitong.model; + + +public class Tb_pwd// 密码数据表实体类 +{ + private String password;// 定义字符串,表示用户密码 + + public Tb_pwd() {// 默认构造函数 + super(); + } + + public Tb_pwd(String password) {// 定义有参构造函数 + super(); + this.password = password;// 为密码赋值 + } + + public String getPassword() {// 定义密码的可读属性 + return password; + } + + public void setPassword(String password) {// 定义密码的可写属性 + this.password = password; + } +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/accountflag.png b/app/src/main/res/drawable/accountflag.png new file mode 100644 index 0000000..ed11e5f Binary files /dev/null and b/app/src/main/res/drawable/accountflag.png differ diff --git a/app/src/main/res/drawable/addinaccount.png b/app/src/main/res/drawable/addinaccount.png new file mode 100644 index 0000000..10d456b Binary files /dev/null and b/app/src/main/res/drawable/addinaccount.png differ diff --git a/app/src/main/res/drawable/addoutaccount.png b/app/src/main/res/drawable/addoutaccount.png new file mode 100644 index 0000000..7b079b2 Binary files /dev/null and b/app/src/main/res/drawable/addoutaccount.png differ diff --git a/app/src/main/res/drawable/appicon.png b/app/src/main/res/drawable/appicon.png new file mode 100644 index 0000000..1a53e00 Binary files /dev/null and b/app/src/main/res/drawable/appicon.png differ diff --git a/app/src/main/res/drawable/exit.png b/app/src/main/res/drawable/exit.png new file mode 100644 index 0000000..e1ec62c Binary files /dev/null and b/app/src/main/res/drawable/exit.png differ diff --git a/app/src/main/res/drawable/ic_launcher.png b/app/src/main/res/drawable/ic_launcher.png new file mode 100644 index 0000000..d709724 Binary files /dev/null and b/app/src/main/res/drawable/ic_launcher.png differ diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/inaccountinfo.png b/app/src/main/res/drawable/inaccountinfo.png new file mode 100644 index 0000000..4f1eeeb Binary files /dev/null and b/app/src/main/res/drawable/inaccountinfo.png differ diff --git a/app/src/main/res/drawable/outaccountinfo.png b/app/src/main/res/drawable/outaccountinfo.png new file mode 100644 index 0000000..d754091 Binary files /dev/null and b/app/src/main/res/drawable/outaccountinfo.png differ diff --git a/app/src/main/res/drawable/showinfo.png b/app/src/main/res/drawable/showinfo.png new file mode 100644 index 0000000..d6be386 Binary files /dev/null and b/app/src/main/res/drawable/showinfo.png differ diff --git a/app/src/main/res/drawable/sysset.png b/app/src/main/res/drawable/sysset.png new file mode 100644 index 0000000..3ff15a3 Binary files /dev/null and b/app/src/main/res/drawable/sysset.png differ diff --git a/app/src/main/res/layout/accountflag.xml b/app/src/main/res/layout/accountflag.xml new file mode 100644 index 0000000..6bc43f2 --- /dev/null +++ b/app/src/main/res/layout/accountflag.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + +