From d1f1936b09db56d3673bf66c09f5a345c93b7686 Mon Sep 17 00:00:00 2001 From: Xie Changrong <1225674957@qq.com> Date: Sun, 12 Jun 2022 20:56:17 +0800 Subject: [PATCH] update --- ...流管理系统需求构思及描述.docx | Bin 0 -> 162 bytes src/Logistics/.idea/misc.xml | 3 +- .../app/src/main/AndroidManifest.xml | 2 +- .../logistics/manager/userManager.java | 97 +++++++++ .../example/logistics/ui/LoginActivity.java | 200 ++++++++++++++++++ .../example/logistics/ui/MainActivity.java | 91 -------- .../java/com/example/logistics/ui/MeUI.java | 5 +- .../com/example/logistics/ui/PickUpUI.java | 1 - .../example/logistics/ui/SignUpActivity.java | 4 +- .../app/src/main/res/layout/activity_main.xml | 25 ++- .../app/src/main/res/layout/forget.xml | 37 ++++ 11 files changed, 364 insertions(+), 101 deletions(-) create mode 100644 doc/~$无人物流管理系统需求构思及描述.docx create mode 100644 src/Logistics/app/src/main/java/com/example/logistics/ui/LoginActivity.java delete mode 100644 src/Logistics/app/src/main/java/com/example/logistics/ui/MainActivity.java create mode 100644 src/Logistics/app/src/main/res/layout/forget.xml diff --git a/doc/~$无人物流管理系统需求构思及描述.docx b/doc/~$无人物流管理系统需求构思及描述.docx new file mode 100644 index 0000000000000000000000000000000000000000..17560ba09dd561c2cd7ca0d90f235b72783af9bf GIT binary patch literal 162 zcmZRsNG@U^889thzST*OhT*?i`PY=}h-w$D6 cSnndi>sNOJt|?4@mE-Sv1_n`>8H^1K0Gt{WeE - + + diff --git a/src/Logistics/app/src/main/AndroidManifest.xml b/src/Logistics/app/src/main/AndroidManifest.xml index fc78965..bb8590b 100644 --- a/src/Logistics/app/src/main/AndroidManifest.xml +++ b/src/Logistics/app/src/main/AndroidManifest.xml @@ -25,7 +25,7 @@ android:name=".ui.MenuActivity" android:exported="false" /> diff --git a/src/Logistics/app/src/main/java/com/example/logistics/manager/userManager.java b/src/Logistics/app/src/main/java/com/example/logistics/manager/userManager.java index 0f50cf0..9a88384 100644 --- a/src/Logistics/app/src/main/java/com/example/logistics/manager/userManager.java +++ b/src/Logistics/app/src/main/java/com/example/logistics/manager/userManager.java @@ -75,6 +75,65 @@ public class userManager { return msg; } + public int loginByPhone(String phonenum, String password){ + HashMap 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 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; + } + } diff --git a/src/Logistics/app/src/main/java/com/example/logistics/ui/LoginActivity.java b/src/Logistics/app/src/main/java/com/example/logistics/ui/LoginActivity.java new file mode 100644 index 0000000..7b4ba8d --- /dev/null +++ b/src/Logistics/app/src/main/java/com/example/logistics/ui/LoginActivity.java @@ -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(); + } + } + }; + +} \ No newline at end of file diff --git a/src/Logistics/app/src/main/java/com/example/logistics/ui/MainActivity.java b/src/Logistics/app/src/main/java/com/example/logistics/ui/MainActivity.java deleted file mode 100644 index b2e3517..0000000 --- a/src/Logistics/app/src/main/java/com/example/logistics/ui/MainActivity.java +++ /dev/null @@ -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(); - } - } - }; - -} \ No newline at end of file diff --git a/src/Logistics/app/src/main/java/com/example/logistics/ui/MeUI.java b/src/Logistics/app/src/main/java/com/example/logistics/ui/MeUI.java index 84e6ba6..f49574c 100644 --- a/src/Logistics/app/src/main/java/com/example/logistics/ui/MeUI.java +++ b/src/Logistics/app/src/main/java/com/example/logistics/ui/MeUI.java @@ -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; diff --git a/src/Logistics/app/src/main/java/com/example/logistics/ui/PickUpUI.java b/src/Logistics/app/src/main/java/com/example/logistics/ui/PickUpUI.java index d0d0912..0ffd4f1 100644 --- a/src/Logistics/app/src/main/java/com/example/logistics/ui/PickUpUI.java +++ b/src/Logistics/app/src/main/java/com/example/logistics/ui/PickUpUI.java @@ -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() { diff --git a/src/Logistics/app/src/main/java/com/example/logistics/ui/SignUpActivity.java b/src/Logistics/app/src/main/java/com/example/logistics/ui/SignUpActivity.java index d63254a..55ef479 100644 --- a/src/Logistics/app/src/main/java/com/example/logistics/ui/SignUpActivity.java +++ b/src/Logistics/app/src/main/java/com/example/logistics/ui/SignUpActivity.java @@ -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); } } diff --git a/src/Logistics/app/src/main/res/layout/activity_main.xml b/src/Logistics/app/src/main/res/layout/activity_main.xml index 939e667..9e033a5 100644 --- a/src/Logistics/app/src/main/res/layout/activity_main.xml +++ b/src/Logistics/app/src/main/res/layout/activity_main.xml @@ -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"> + + +