pull/17/head
Xie Changrong 3 years ago
parent 7889a9e970
commit d1f1936b09

@ -17,13 +17,14 @@
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/drawable/translucent_button.xml" value="0.194" />
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/drawable/translucent_edit.xml" value="0.1135" />
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/layout/activity_history.xml" value="0.22" />
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/layout/activity_main.xml" value="0.10235507246376811" />
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/layout/activity_main.xml" value="0.1" />
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/layout/activity_main2.xml" value="0.10235507246376811" />
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/layout/activity_menu.xml" value="0.33" />
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/layout/activity_no_pick.xml" value="0.2" />
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/layout/activity_sign_up.xml" value="0.10235507246376811" />
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/layout/activity_wait.xml" value="0.18" />
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/layout/buttom.xml" value="0.10235507246376811" />
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/layout/forget.xml" value="0.2630208333333333" />
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/layout/fragment_my.xml" value="0.10235507246376811" />
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/layout/item.xml" value="0.22" />
<entry key="..\:/shijianer/xcr_se/src/Logistics/app/src/main/res/layout/my_fragment1.xml" value="0.1" />

@ -25,7 +25,7 @@
android:name=".ui.MenuActivity"
android:exported="false" />
<activity
android:name=".ui.MainActivity"
android:name=".ui.LoginActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

@ -75,6 +75,65 @@ public class userManager {
return msg;
}
public int loginByPhone(String phonenum, String password){
HashMap<String, Object> map = new HashMap<>();
Connection connection = DBOpenHelper.getConn();
int msg = 0;
try{
String sql = "select * from users where phonenum = ?";
if(connection != null){
PreparedStatement ps = connection.prepareStatement(sql);
if(ps != null){
Log.e(TAG, "phonenum: " + phonenum);
ps.setString(1,phonenum);
ResultSet rs = ps.executeQuery();
int count = rs.getMetaData().getColumnCount();
while(rs.next()){
for(int i = 1; i <= count; i++){
String field = rs.getMetaData().getColumnName(i);
map.put(field, rs.getString(field));
}
}
connection.close();
ps.close();
password = MD5Utils.md5(password);
if(map.size() != 0){
StringBuilder s = new StringBuilder();
for(String key:map.keySet()){
if(key.equals("password")){
if(password.equals(map.get(key))){
msg = 1; //password correct
}else{
msg = 2; //password incorrect
}
break;
}
}
}else{
Log.e(TAG, "result is null");
msg = 3; //result is null
}
}else{
Log.e(TAG, "ps is null");
msg = 0;
}
}else{
Log.e(TAG, "connection is null");
msg = 0;
}
}catch (Exception e){
e.printStackTrace();
Log.d(TAG, "login bug: " + e.getMessage());
msg = 0;
}
return msg;
}
public User findUser(String username){
Connection connection = DBOpenHelper.getConn();
@ -137,4 +196,42 @@ public class userManager {
}
}
public int change(String phonenum, String password){
HashMap<String, Object> map = new HashMap<>();
Connection connection = DBOpenHelper.getConn();
int msg = 0;
try{
String sql = "update users set password = ? where phonenum = ?";
if(connection != null){
PreparedStatement ps = connection.prepareStatement(sql);
if(ps != null){
Log.e(TAG, "phonenum: " + phonenum);
password = MD5Utils.md5(password);
ps.setString(1,password);
ps.setString(2,phonenum);
ps.executeUpdate();
connection.close();
ps.close();
msg = 1;
}else{
Log.e(TAG, "ps is null");
msg = 0;
}
}else{
Log.e(TAG, "connection is null");
msg = 0;
}
}catch (Exception e){
e.printStackTrace();
Log.d(TAG, "login bug: " + e.getMessage());
msg = 0;
}
return msg;
}
}

@ -0,0 +1,200 @@
package com.example.logistics.ui;
import com.example.logistics.R;
import com.example.logistics.manager.goodManager;
import com.example.logistics.manager.operationManager;
import com.example.logistics.manager.userManager;
import com.example.logistics.entity.User;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import org.json.JSONException;
import org.json.JSONObject;
public class LoginActivity extends Activity {
private int islogin = 0;
private Button loginButton;
private Button signUpButton;
private Button forgetButton;
private Button phonenumButton;
private AlertDialog alert;
private Button changeButton;
private EditText fphonenum;
private EditText fpassword;
int flag = 0; //flag = 0 是用户名登录;=1是手机号
// 调用Actvity
private String TAG = "LoginActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loginButton = (Button) this.findViewById(R.id.LoginButton);
signUpButton = (Button) this.findViewById(R.id.SignUpButton);
forgetButton = (Button) this.findViewById(R.id.forget);
phonenumButton = (Button) this.findViewById(R.id.phonenum);
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
View view2 = View.inflate(LoginActivity.this, R.layout.forget, null);
builder.setTitle("取件").setView(view2);
alert = builder.create();
changeButton = (Button) view2.findViewById(R.id.change);
fphonenum = (EditText) view2.findViewById(R.id.fphonenum);
fpassword = (EditText) view2.findViewById(R.id.fpassword);
loginButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
login(v);
Log.d(TAG, "login");
}
}
);
signUpButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(LoginActivity.this, SignUpActivity.class);
Log.d(TAG, "signup");
startActivity(intent);
}
}
);
forgetButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
alert.show();
changeButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d(TAG, "change password");
change(view);
}
}
);
}
}
);
EditText userName = (EditText) this.findViewById(R.id.UserNameEdit);
phonenumButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
userName.setHint("请输入手机号");
flag = 1;
}
}
);
}
public void change(View view){
String phoneunm = fphonenum.getText().toString().trim();
String password = fpassword.getText().toString().trim();
new Thread() {
@Override
public void run() {
userManager userManager = new userManager();
int msg = userManager.change(phoneunm, password);
Log.d(TAG, "change");
if(msg != 1){
Log.d(TAG, "pickup,failed");
hand2.sendEmptyMessage(msg);
return;
}
Log.d(TAG, "change,success");
hand2.sendEmptyMessage(msg);
}
}.start();
}
public void login(View view){
EditText userName = (EditText) this.findViewById(R.id.UserNameEdit);
EditText passWord = (EditText) this.findViewById(R.id.PassWordEdit);
new Thread(){
@Override
public void run(){
userManager userManager = new userManager();
int msg = 0;
if(flag == 0){
msg = userManager.login(userName.getText().toString().trim(), passWord.getText().toString().trim());
}else if(flag == 1){
msg = userManager.loginByPhone(userName.getText().toString().trim(), passWord.getText().toString().trim());
}
Log.e("MAin", "msg");
hand1.sendEmptyMessage(msg);
if(msg == 1){
User owner = userManager.findUser(userName.getText().toString().trim());
Intent intent = new Intent(LoginActivity.this, MenuActivity.class);
if(flag == 1){
intent.putExtra("user", userName.getText().toString().trim());
}else{
intent.putExtra("user", owner.getPhoneNum());
}
startActivity(intent);
finish();
}
}
}.start();
}
@SuppressLint("HandlerLeak")
final Handler hand1 = new Handler(){
@Override
public void handleMessage(Message msg){
if(msg.what == 0){
Toast.makeText(getApplicationContext(), "登录失败", Toast.LENGTH_SHORT).show();
}else if(msg.what == 1){
Toast.makeText(getApplicationContext(), "登录成功", Toast.LENGTH_SHORT).show();
islogin = 1;
}else if(msg.what == 2){
Toast.makeText(getApplicationContext(), "密码错误", Toast.LENGTH_SHORT).show();
}else if(msg.what == 3){
Toast.makeText(getApplicationContext(), "账号不存在", Toast.LENGTH_SHORT).show();
}
}
};
@SuppressLint("HandlerLeak")
final Handler hand2 = new Handler() {
@Override
public void handleMessage(Message msg) {
if(msg.what == 0){
Toast.makeText(LoginActivity.this, "修改失败", Toast.LENGTH_SHORT).show();
}else if(msg.what == 1) {
Toast.makeText(LoginActivity.this, "修改成功", Toast.LENGTH_SHORT).show();
}
}
};
}

@ -1,91 +0,0 @@
package com.example.logistics.ui;
import com.example.logistics.R;
import com.example.logistics.manager.userManager;
import com.example.logistics.entity.User;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
private int islogin = 0;
// 调用Actvity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button loginButton = (Button) this.findViewById(R.id.LoginButton);
Button signUpButton = (Button) this.findViewById(R.id.SignUpButton);
loginButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
login(v);
}
}
);
signUpButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, SignUpActivity.class);
startActivity(intent);
}
}
);
}
public void login(View view){
EditText userName = (EditText) this.findViewById(R.id.UserNameEdit);
EditText passWord = (EditText) this.findViewById(R.id.PassWordEdit);
new Thread(){
@Override
public void run(){
userManager userManager = new userManager();
int msg = userManager.login(userName.getText().toString().trim(), passWord.getText().toString().trim());
Log.e("MAin", "msg");
hand1.sendEmptyMessage(msg);
if(msg == 1){
User owner = userManager.findUser(userName.getText().toString().trim());
Intent intent = new Intent(MainActivity.this, MenuActivity.class);
intent.putExtra("user", owner.getPhoneNum());
startActivity(intent);
finish();
}
}
}.start();
}
@SuppressLint("HandlerLeak")
final Handler hand1 = new Handler(){
@Override
public void handleMessage(Message msg){
if(msg.what == 0){
Toast.makeText(getApplicationContext(), "登录失败", Toast.LENGTH_SHORT).show();
}else if(msg.what == 1){
Toast.makeText(getApplicationContext(), "登录成功", Toast.LENGTH_SHORT).show();
islogin = 1;
}else if(msg.what == 2){
Toast.makeText(getApplicationContext(), "密码错误", Toast.LENGTH_SHORT).show();
}else if(msg.what == 3){
Toast.makeText(getApplicationContext(), "账号不存在", Toast.LENGTH_SHORT).show();
}
}
};
}

@ -9,15 +9,12 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.Nullable;
import com.example.logistics.R;
import org.w3c.dom.Text;
public class MeUI extends Fragment implements View.OnClickListener{
private LinearLayout ll_waiting;
private LinearLayout ll_history;
@ -67,7 +64,7 @@ public class MeUI extends Fragment implements View.OnClickListener{
break;
case R.id.exit:
Toast.makeText(mContext, "exit", Toast.LENGTH_SHORT).show();
intent = new Intent(mContext, MainActivity.class);
intent = new Intent(mContext, LoginActivity.class);
startActivity(intent);
getActivity().finish();
break;

@ -211,7 +211,6 @@ public class PickUpUI extends Fragment implements View.OnClickListener{
builder.setTitle("取件").setView(view2);
alert2 = builder.create();
alert2.show();
button.setOnClickListener(new View.OnClickListener() {

@ -38,7 +38,7 @@ public class SignUpActivity extends Activity {
@Override
public void onClick(View v) {
// 跳转到登录界面
Intent intent = new Intent(SignUpActivity.this, MainActivity.class);
Intent intent = new Intent(SignUpActivity.this, LoginActivity.class);
startActivity(intent);
}
}
@ -106,7 +106,7 @@ public class SignUpActivity extends Activity {
Toast.makeText(getApplicationContext(), "该账号已存在,请换一个注册", Toast.LENGTH_SHORT).show();
}else if(msg.what == 2){
Toast.makeText(getApplicationContext(), "注册成功", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(SignUpActivity.this, MainActivity.class);
Intent intent = new Intent(SignUpActivity.this, LoginActivity.class);
startActivity(intent);
}
}

@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.logistics.ui.MainActivity">
tools:context="com.example.logistics.ui.LoginActivity">
<!--使用线性布局-->
<LinearLayout
android:id="@+id/linearLayout2"
@ -110,6 +110,29 @@
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/forget"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_marginLeft="15dp"
android:background="#F5F5F5"
android:text="忘记密码" />
<Button
android:id="@+id/phonenum"
android:layout_width="249dp"
android:layout_height="20dp"
android:background="#F5F5F5"
android:gravity="right"
android:text="手机号登录" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/fphonenum"
android:hint="请输入注册时手机号"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/fpassword"
android:hint="请输入新密码"
/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="修改"
android:id="@+id/change"/>
</LinearLayout>
Loading…
Cancel
Save