Skip to content

Commit

Permalink
hzuapps#5 hzuapps#129 第五次作业
Browse files Browse the repository at this point in the history
  • Loading branch information
14YuQingBin committed Jun 2, 2017
1 parent 61eb62b commit d235ea3
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_net1414080903130_employees);

Button yuangongreturn = (Button)findViewById(R.id.employees_return);
Button yuangongreturn = (Button)findViewById(R.id.enroll_return);
yuangongreturn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package edu.hzuapps.androidlabs.homeworks.net1414080903130;

import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

import edu.hzuapps.androidlabs.R;

public class Net1414080903130EnrollActivity extends AppCompatActivity {
EditText a,b,c,d;

RadioButton rbCustomer;
RadioButton rbEmployee;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -23,6 +29,9 @@ protected void onCreate(Bundle savedInstanceState) {
c = (EditText)findViewById(R.id.enroll_againpassword);
d = (EditText)findViewById(R.id.enroll_call);

rbCustomer= (RadioButton) findViewById(R.id.enroll_customer);
rbEmployee= (RadioButton) findViewById(R.id.enroll_employee);

Button fanhui = (Button)findViewById(R.id.enroll_return);
fanhui.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -42,6 +51,7 @@ public void onClick(View v) {
"注册不成功!",Toast.LENGTH_SHORT).show();

}else{
save(a.getText().toString(),b.getText().toString(),rbCustomer.isChecked());
Toast.makeText(Net1414080903130EnrollActivity.this,
"注册成功!",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Net1414080903130EnrollActivity.this,Net1414080903130LoginActivity.class);
Expand All @@ -62,5 +72,15 @@ private boolean check(){
}
return false;
}
public void save(String username,String password,boolean isCustomer){
Net1414080903130MySQLiteOpenHelper helper=new Net1414080903130MySQLiteOpenHelper(this);
SQLiteDatabase db=helper.getWritableDatabase();
ContentValues values=new ContentValues();
values.put("username",username);
values.put("password",password);
values.put("customer",isCustomer?"true":"false");
db.insert("user",null,values);
db.close();
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package edu.hzuapps.androidlabs.homeworks.net1414080903130;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
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 edu.hzuapps.androidlabs.R;

Expand Down Expand Up @@ -36,20 +38,40 @@ public void onClick(View v) {
String str_name = name.getText().toString();
String str_password = password.getText().toString();
//判断语句
Log.d("LoginActivity", str_name);
Log.d("LoginActivity", str_password);
if ("guke".equals(str_name) && "123".equals(str_password)) {
int n=check(str_name,str_password);
if (n==1){
Intent intent = new Intent(Net1414080903130LoginActivity.this, Net1414080903130CustomerActivity.class);
startActivity(intent);
} else if ("yuangong".equals(str_name) && "123".equals(str_password)) {
}else if(n==0){
Intent intent = new Intent(Net1414080903130LoginActivity.this, Net1414080903130EmployeesActivity.class);
startActivity(intent);
}else{
Toast.makeText(Net1414080903130LoginActivity.this,"用户名/密码错误!!",Toast.LENGTH_LONG).show();
}

}
});
}

public int check(String username,String password){
Net1414080903130MySQLiteOpenHelper helper=new Net1414080903130MySQLiteOpenHelper(this);
SQLiteDatabase db=helper.getReadableDatabase();
Cursor cursor= db.query("user",null,null,null,null,null,null);
while(cursor.moveToNext()){
String u=cursor.getString(cursor.getColumnIndex("username"));
String p=cursor.getString(cursor.getColumnIndex("password"));
if(u.equals(username)&&p.equals(password)){
if (cursor.getString(cursor.getColumnIndex("customer")).equals("true")){
return 1;
}else{
return 0;
}
}
}
cursor.close();
return -1;
};

}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package edu.hzuapps.androidlabs.homeworks.net1414080903130;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
* Created by 程序出错 on 2017/5/25.
*/

public class Net1414080903130MySQLiteOpenHelper extends android.database.sqlite.SQLiteOpenHelper {
public Net1414080903130MySQLiteOpenHelper(Context context) {
super(context, "Hotel", null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table user(username varchar(20),password varchar(20),customer varchar(4));");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/customer">
android:background="@drawable/cusstomer">

<LinearLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -39,8 +39,7 @@
android:orientation="horizontal"
android:layout_marginTop="140dp"
android:layout_alignParentStart="true"
android:layout_marginStart="39dp"
android:layout_alignParentLeft="true">
android:layout_marginStart="39dp">
<TextView
android:layout_marginRight="1dp"
android:layout_marginLeft="26dp"
Expand Down Expand Up @@ -179,17 +178,15 @@
android:layout_height="wrap_content"
android:text="登记"
android:layout_marginTop="400dp"
android:layout_marginStart="220dp"
android:layout_marginLeft="220dp" />
android:layout_marginStart="220dp"/>

<Button
android:id="@+id/customer_return"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="返回"
android:layout_marginStart="65dp"
android:layout_marginTop="400dp"
android:layout_marginLeft="65dp" />
android:layout_marginTop="400dp" />

</RelativeLayout>

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/employees">
android:background="@drawable/enployee">

<LinearLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -39,8 +39,7 @@
android:orientation="horizontal"
android:layout_marginTop="135dp"
android:layout_alignParentStart="true"
android:layout_marginStart="39dp"
android:layout_alignParentLeft="true">
android:layout_marginStart="39dp">
<TextView
android:layout_marginRight="1dp"
android:layout_marginLeft="26dp"
Expand Down Expand Up @@ -157,8 +156,7 @@
android:text="员工信息"
android:textSize="28dp"
android:layout_marginStart="25dp"
android:layout_centerHorizontal="true"
android:layout_marginLeft="25dp" />
android:layout_centerHorizontal="true"/>

<Button
android:id="@+id/employees_input"
Expand All @@ -168,9 +166,7 @@
android:layout_alignBaseline="@+id/employees_return"
android:layout_alignBottom="@+id/employees_return"
android:layout_alignEnd="@+id/linearLayout"
android:layout_marginEnd="27dp"
android:layout_marginRight="27dp"
android:layout_alignRight="@+id/linearLayout" />
android:layout_marginEnd="27dp" />

</RelativeLayout>

Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
android:orientation="horizontal"
android:layout_marginTop="135dp"
android:layout_alignParentStart="true"
android:layout_marginStart="39dp"
android:layout_alignParentLeft="true">
android:layout_marginStart="39dp">
<TextView
android:layout_marginRight="1dp"
android:layout_marginLeft="26dp"
Expand All @@ -49,14 +48,14 @@
android:text="类型:"
android:textSize="20dp"/>
<RadioButton
android:id="@+id/enroll_male"
android:id="@+id/enroll_employee"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:checked="false"
android:text="员工"
android:textSize="20dp"/>
<RadioButton
android:id="@+id/enroll_female"
android:id="@+id/enroll_customer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="顾客"
Expand Down Expand Up @@ -122,8 +121,7 @@
android:text="账号注册"
android:textSize="28dp"
android:layout_marginStart="25dp"
android:layout_centerHorizontal="true"
android:layout_marginLeft="25dp" />
android:layout_centerHorizontal="true"/>

<LinearLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -168,9 +166,7 @@
android:layout_marginEnd="24dp"
android:layout_alignBaseline="@+id/enroll_return"
android:layout_alignBottom="@+id/enroll_return"
android:layout_alignEnd="@+id/linearLayout2"
android:layout_alignRight="@+id/linearLayout2"
android:layout_marginRight="24dp" />
android:layout_alignEnd="@+id/linearLayout2" />

</RelativeLayout>

0 comments on commit d235ea3

Please sign in to comment.