master
yang 3 years ago
parent 1d90fe82db
commit 99212e7c67

@ -12,6 +12,12 @@
android:theme="@style/Theme.Chengzi"
tools:replace="android:theme"
tools:targetApi="31">
<activity
android:name=".IndexAcitvity"
android:exported="false" />
<activity
android:name=".OrangeDatabase"
android:exported="false" />
<activity
android:name=".Adapter"
android:exported="false" />
@ -26,16 +32,16 @@
android:exported="false" />
<activity
android:name=".CategoryActivity"
android:exported="false"/>
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

@ -0,0 +1,13 @@
package com.example.chengzi;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class IndexAcitvity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}

@ -6,6 +6,8 @@ import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
@ -39,16 +41,32 @@ public class MainActivity extends AppCompatActivity {
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
username_str = username_Text.getText().toString();
passward_str = passward_Text.getText().toString();
if(!username_str.equals("")||!passward_str.equals("")) {
Intent intent = new Intent();
intent.setClass(MainActivity.this, userinformation.class);
startActivity(intent);
}else {
Toast.makeText(MainActivity.this,"请输入用户名或密码",Toast.LENGTH_SHORT).show();
if(validataLogin())
{
Intent intent1 = new Intent(MainActivity.this,CategoryActivity.class);
Bundle bundle = new Bundle();
OrangeDatabase orangeDatabase = new OrangeDatabase(MainActivity.this);
bundle.putString("username",username_Text.getText().toString());
bundle = orangeDatabase.queryUserInfo(
orangeDatabase.getReadableDatabase(),bundle);
intent1.putExtras(bundle);
startActivity(intent1);
}
else {
Toast.makeText(MainActivity.this,"账号或者密码错误",Toast.LENGTH_SHORT).show();
}
}
});
}
private boolean validataLogin(){
username_str = username_Text.getText().toString();
passward_str = passward_Text.getText().toString();
OrangeDatabase orangeDatabase = new OrangeDatabase(MainActivity.this);
SQLiteDatabase sqLiteDatabase = orangeDatabase.getReadableDatabase();
Cursor cursor = sqLiteDatabase.rawQuery("select * from orange_user where username=? and password=?", new String[]{username_str, passward_str});
if (cursor.getCount() > 0) {
return true;
}
return false;
}
}

@ -0,0 +1,50 @@
package com.example.chengzi;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
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;
public class OrangeDatabase extends SQLiteOpenHelper {
public OrangeDatabase(@Nullable Context context){
super(context,"orange",null,1);
}
@Override
public void onCreate(SQLiteDatabase db) {
String sql = "create table orange_user(id integer primary key autoincrement, username varchar(50), password varchar(50),sex varchar(10),city carchar(50))";
db.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
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("orange_user", null, contentValues);
sqLiteDatabase.close();
}
public Bundle queryUserInfo(SQLiteDatabase sqLiteDatabase, Bundle bundle) {
String username = bundle.getString("username");
Cursor cursor = sqLiteDatabase.rawQuery("select * from orange_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;
}
}

@ -5,7 +5,9 @@ import static androidx.constraintlayout.helper.widget.MotionEffect.TAG;
import androidx.annotation.IdRes;
import androidx.appcompat.app.AppCompatActivity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
@ -77,13 +79,16 @@ public class reigester extends AppCompatActivity{
if(passward_str1.equals(passward_str2)){
if(!name_str.equals("")||!passward_str1.equals("")){
if(!city.equals("")){
Intent intent = new Intent(reigester.this,userinformation.class);
Bundle bundle = new Bundle();
bundle.putString("reg_username",name_str);
bundle.putString("reg_passward",passward_str1);
bundle.putString("reg_sure_passward",passward_str2);
bundle.putString("sex",sex_str);
bundle.putString("city",city);
OrangeDatabase orangeDatabase = new OrangeDatabase(reigester.this);
SQLiteDatabase sqLiteDatabase = orangeDatabase.getWritableDatabase();
insertData(sqLiteDatabase,bundle);
Intent intent = new Intent(reigester.this,MainActivity.class);
intent.putExtras(bundle);
startActivity(intent);
} else {
@ -114,4 +119,13 @@ public class reigester extends AppCompatActivity{
public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i){
sex_str=i==R.id.reg_man?"男性":"女性";
}
private void insertData(SQLiteDatabase sqLiteDatabase, Bundle bundle){
ContentValues contentValues = new ContentValues();
contentValues.put("username",bundle.getString("reg_username"));
contentValues.put("password",bundle.getString("reg_passward"));
contentValues.put("sex", bundle.getString("sex"));
contentValues.put("city", bundle.getString("city"));
sqLiteDatabase.insert("orange_user", null, contentValues);
sqLiteDatabase.close();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 899 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/content_index"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="2dp"
android:src="@drawable/index"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="书城"
android:textColor="#000"
android:textSize="17sp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/content_bangdan"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="2dp"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/bangdan"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="榜单"
android:textColor="#000"
android:textSize="17sp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/content_shujia"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="2dp"
android:src="@drawable/shujia"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="书架"
android:textColor="#000"
android:textSize="18sp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/content_me"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="2dp"
android:src="@drawable/me"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="我"
android:textColor="#000"
android:textSize="18sp"/>
</LinearLayout>
</LinearLayout>

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
tools:context=".IndexAcitvity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5">
<include layout="@layout/content_nav"/>
</LinearLayout>
<FrameLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp">
<include layout="@layout/content_nav"/>
</LinearLayout>
</LinearLayout>
Loading…
Cancel
Save