长期捐助完成

my
Administrator 5 years ago
parent 1c6e8c9a11
commit ebfc23a1cf

@ -11,7 +11,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".BrowseDonatedRecordActivity"></activity>
<activity android:name=".LongTermDonate"></activity>
<activity android:name=".BrowseDonatedRecordActivity" />
<activity android:name=".DonateActivity" />
<activity android:name=".BrowseDonateRecordActivity" />
<activity android:name=".NewsContentActivity" />

@ -83,6 +83,21 @@ public class UserService {
e.printStackTrace();
}
return false;
}
public boolean longterm(String name,String phone,String descri, Long ID){
conn = db.getConnection();//将长期资助信息上传到数据库成功返回true失败返回false
try{
String sql = "insert into usr_help_req(name,phone,descri,ID) values('"+name+"','"+phone+"','"+descri+"','"+ID+"')";
//name,phone,descri,ID
Statement sttmt = conn.createStatement();
sttmt.executeUpdate(sql);
sttmt.close();
return true;
}
catch (Exception e){
e.printStackTrace();
}
return false;
}
public String getRole(String username){//从数据库获取用户的角色
//SQLiteDatabase sdb=dbHelper.getReadableDatabase();

@ -0,0 +1,149 @@
package hunnu.sj.raise_money;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import hunnu.sj.raise_money.DataBase.UserService;
import hunnu.sj.raise_money.MainActivity;
import hunnu.sj.raise_money.R;
public class LongTermDonate extends AppCompatActivity {
UserService userService=new UserService();
//String username;
//String stu_name;
Long id;
Handler mHandler = new Handler(){//用于处理子线程传回的消息对主线的UI进行修改
int flag = -1;
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
String txt;
switch (msg.what){
case 1:
flag = 1;
txt = (String) msg.obj;
number.setError(txt);
break;
case 2:
flag=2;
txt = (String) msg.obj;
des.setError(txt);
case 3:
flag=3;
txt = (String) msg.obj;
name.setError(txt);
}
}
};
EditText name;
EditText number;
EditText des;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_long_term_donate);
id= getIntent().getLongExtra("stu_id",0);
}
public void onToMain(View view){
Intent intent = new Intent(LongTermDonate.this, MainActivity.class);
startActivity(intent);
}
public void onClick(View view){
name=findViewById(R.id.Name);
number=findViewById(R.id.TeleNumber);
des=findViewById(R.id.Desp);
new CommitThread().start();
}
private int judgenum(String num){
if(num.length()!=11) return 1;
Pattern p = null;
Matcher m = null;
boolean b = false;
p = Pattern.compile("^[1][3,5,8][0-9]{9}$"); // 验证手机号
m = p.matcher(num);
b = m.matches();
if(!b) return 2;
return 3;
}
private int judgenam(String nam){//验证名字
String regEx = "[\u4E00-\u9FA5]{2,5}(?:·[\u4E00-\u9FA5]{2,5})*";
Pattern pattern = Pattern.compile(regEx);
Matcher matcher = pattern.matcher(nam);
boolean isMatch = matcher.matches();
if (isMatch) return 1;
return 0;
}
private int judgedes(String des){
if ((des == null) || ("".equals(des)))
return 0;
return 1;//描述不为空
}
class CommitThread extends Thread{
@Override
public void run() {
int flag = -1;//先设置flag为-1
int flag1=-1;
int flag11=-1;
String num = number.getText().toString();
String nam=name.getText().toString();
String DESP=des.getText().toString();
flag = judgenum(num);//判断手机号
flag11=judgenam(nam);
flag11 = judgedes(DESP);
Message message = mHandler.obtainMessage();
if(flag==1){
message.what = 1;
message.obj = "电话号码位数不对";
mHandler.sendMessage(message);
}
else if(flag==2){
message.what = 1;
message.obj = "请输入正确的电话号码";
mHandler.sendMessage(message);
}
else if(flag11==0){
message.what = 3;
message.obj = "姓名输入不对";
mHandler.sendMessage(message);
}
else if(flag1==0){
message.what = 2;
message.obj = "描述为空,请输入一些描述";
mHandler.sendMessage(message);
}
else{
Looper.prepare();
Toast toast=Toast.makeText(LongTermDonate.this, "提交成功",Toast.LENGTH_LONG);
//userService.donate(username,stu_name,id,money);
userService.longterm(nam,num,DESP,id);
toast.setGravity(Gravity.CENTER, 100, 100);
toast.show();
Looper.loop();
finish();
}
}
}
}

@ -36,6 +36,7 @@ public class NewsContentActivity extends AppCompatActivity{
onToDonate();
onBrowseRecord();
onToLongTerm();
}
public void onToDonate( ){
Button button1 = (Button) findViewById(R.id.button);//id后面为上方button的id
@ -64,5 +65,16 @@ public class NewsContentActivity extends AppCompatActivity{
}
});
}
public void onToLongTerm( ){
Button longterm=(Button) findViewById(R.id.longterm);
longterm.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(NewsContentActivity.this, LongTermDonate.class);//this前面为当前activty名称class前面为要跳转到得activity名称
intent.putExtra("stu_id",stu_id);
startActivity(intent);
}
});
}
}

@ -0,0 +1,96 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp">
<TextView
android:id="@+id/name"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/colorAccent"
android:text="姓名" />
<EditText
android:id="@+id/Name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:hint="请输入你的姓名"
android:inputType="textPersonName" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/teleNumber"
android:layout_width="40dp"
android:layout_height="34dp"
android:layout_weight="1"
android:maxLength="11"
android:numeric="integer"
android:textColor="@color/colorAccent"
android:text="电话号码" />
<EditText
android:id="@+id/TeleNumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:hint="请输入你的电话号码"
android:inputType="textPersonName" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<TextView
android:id="@+id/desp"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/colorAccent"
android:text="输入你的信息描述" />
<EditText
android:id="@+id/Desp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:hint="信息描述"
/>
</LinearLayout>
<LinearLayout
android:layout_width="481dp"
android:layout_height="wrap_content"
android:layout_marginTop="40dp">
<Button
android:id="@+id/commit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="75dp"
android:onClick="onToDonate"
android:text="跳转首页"></Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:onClick="onClick"
android:text="提交">
</Button>
</LinearLayout>
</LinearLayout>

@ -68,7 +68,7 @@
android:text="捐助信息" />
<Button
android:id="@+id/button2"
android:id="@+id/longterm"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
@ -80,7 +80,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="40dp"
android:onClick="onBrowseRecord"
android:onClick="onToMain"
android:text="捐助" />
</LinearLayout>

Loading…
Cancel
Save