diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml
new file mode 100644
index 0000000..70f212e
--- /dev/null
+++ b/.idea/dbnavigator.xml
@@ -0,0 +1,414 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 010018f..b4f9524 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -21,10 +21,10 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
- implementation 'androidx.appcompat:appcompat:1.0.2'
- implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
+ implementation 'androidx.appcompat:appcompat:1.4.1'
+ implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.12'
- androidTestImplementation 'androidx.test.ext:junit:1.1.0'
- androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
+ androidTestImplementation 'androidx.test.ext:junit:1.1.3'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'liji.library.dev:citypickerview:1.1.0'
}
diff --git a/app/src/main/java/com/yemamacake/cn/activity/MainActivity.java b/app/src/main/java/com/yemamacake/cn/activity/MainActivity.java
index c594972..df5bb8c 100644
--- a/app/src/main/java/com/yemamacake/cn/activity/MainActivity.java
+++ b/app/src/main/java/com/yemamacake/cn/activity/MainActivity.java
@@ -1,14 +1,18 @@
package com.yemamacake.cn.activity;
import android.content.Intent;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
+import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.yemamacake.cn.R;
+import com.yemamacake.cn.database.MamacakeUser;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button registerButton, loginButton;
@@ -29,6 +33,21 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
startActivity(intent);
break;
case R.id.login:
+ if(validateLogin())
+ {
+ Intent intent1 = new Intent(MainActivity.this,UserActivity.class);
+ Bundle bundle = new Bundle();
+ MamacakeUser mamacakeUser = new MamacakeUser(MainActivity.this);
+ bundle.putString("username",usernameText.getText().toString());
+ bundle = mamacakeUser.queryUserInfo(mamacakeUser.getReadableDatabase(), bundle);
+ intent1.putExtras(bundle);
+ startActivity(intent1);
+
+
+ }
+ else {
+ Toast.makeText(MainActivity.this, "账号或密码错误", Toast.LENGTH_SHORT).show();
+ }
break;
}
}
@@ -42,4 +61,15 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
registerButton = findViewById(R.id.register);
registerButton.setOnClickListener(this);
}
+ private boolean validateLogin() {
+ String username = usernameText.getText().toString();
+ MamacakeUser mamacakeUser = new MamacakeUser(MainActivity.this);
+ String password = paswdEdit.getText().toString();
+ SQLiteDatabase sqLiteDatabase = mamacakeUser.getReadableDatabase();
+ Cursor cursor = sqLiteDatabase.rawQuery("select * from cake_user where username=? and password=?", new String[]{username, password});
+ if (cursor.getCount() > 0) {
+ return true;
+ }
+ return false;
+ }
}
diff --git a/app/src/main/java/com/yemamacake/cn/activity/RegisterActivity.java b/app/src/main/java/com/yemamacake/cn/activity/RegisterActivity.java
index 5c5fe8e..0d67617 100644
--- a/app/src/main/java/com/yemamacake/cn/activity/RegisterActivity.java
+++ b/app/src/main/java/com/yemamacake/cn/activity/RegisterActivity.java
@@ -1,6 +1,8 @@
package com.yemamacake.cn.activity;
+import android.content.ContentValues;
import android.content.Intent;
+import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
@@ -15,6 +17,7 @@ import androidx.appcompat.app.AppCompatActivity;
import com.lljjcoder.citypickerview.widget.CityPicker;
import com.yemamacake.cn.R;
+import com.yemamacake.cn.database.MamacakeUser;
public class RegisterActivity extends AppCompatActivity implements View.OnClickListener, RadioGroup.OnCheckedChangeListener {
private EditText usernameEdit, passwordEdit, surePasswordEdit;
@@ -122,6 +125,9 @@ public class RegisterActivity extends AppCompatActivity implements View.OnCli
bundle.putString("password", password);
bundle.putString("sex", sexStr);
bundle.putString("city", city);
+ MamacakeUser mamacakeUser = new MamacakeUser(RegisterActivity.this);
+ SQLiteDatabase sqLiteDatabase = mamacakeUser.getWritableDatabase();
+ insertData(sqLiteDatabase,bundle);
intent.putExtras(bundle);
startActivity(intent);
} else {
@@ -142,4 +148,13 @@ public class RegisterActivity extends AppCompatActivity implements View.OnCli
//根据用户选择来改变sex的值
sexStr = checkedId == R.id.reg_man ? "男" : "女";
}
+ private void insertData(SQLiteDatabase sqLiteDatabase, Bundle bundle) {
+ ContentValues contentValues = new ContentValues();
+ contentValues.put("username", bundle.getString("username"));
+ contentValues.put("password", bundle.getString("password"));
+ contentValues.put("sex", bundle.getString("sex"));
+ contentValues.put("city", bundle.getString("city"));
+ sqLiteDatabase.insert("cake_user", null, contentValues);
+ sqLiteDatabase.close();
+ }
}
diff --git a/app/src/main/java/com/yemamacake/cn/database/MamacakeUser.java b/app/src/main/java/com/yemamacake/cn/database/MamacakeUser.java
new file mode 100644
index 0000000..3f58b17
--- /dev/null
+++ b/app/src/main/java/com/yemamacake/cn/database/MamacakeUser.java
@@ -0,0 +1,52 @@
+package com.yemamacake.cn.database;
+
+import android.content.ContentValues;
+import android.content.Context;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteOpenHelper;
+import android.os.Bundle;
+
+import androidx.annotation.Nullable;
+
+public class MamacakeUser extends SQLiteOpenHelper {
+ public MamacakeUser(@Nullable Context context) {
+ super(context, "yemamadatabase", null, 1);
+ }
+
+ @Override
+ public void onCreate(SQLiteDatabase sqLiteDatabase) {
+ String sql = "create table cake_user(id integer primary key autoincrement, username varchar(50), password varchar(50),sex varchar(10),city carchar(50))";
+ sqLiteDatabase.execSQL(sql);
+
+ }
+
+ @Override
+ public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
+
+ }
+ //插入操作
+ public void insertUser(SQLiteDatabase sqLiteDatabase, String username, String password, String sex, String city) {
+ ContentValues contentValues = new ContentValues();
+ contentValues.put("username", username);
+ contentValues.put("password", password);
+ contentValues.put("sex", sex);
+ contentValues.put("city", city);
+ sqLiteDatabase.insert("cake_user", null, contentValues);
+ sqLiteDatabase.close();
+ }
+ public Bundle queryUserInfo(SQLiteDatabase sqLiteDatabase, Bundle bundle) {
+ String username = bundle.getString("username");
+ Cursor cursor = sqLiteDatabase.rawQuery("select * from cake_user where username=?", new String[]{username});
+ if (cursor != null) {
+ while (cursor.moveToNext()) {
+ bundle.putString("sex", cursor.getString(3));
+ bundle.putString("city", cursor.getString(4));
+ }
+ }
+ cursor.close();
+ sqLiteDatabase.close();
+ return bundle;
+ }
+
+}
diff --git a/yemamadatabase.db b/yemamadatabase.db
new file mode 100644
index 0000000..755fbab
Binary files /dev/null and b/yemamadatabase.db differ