Administrator 5 years ago
parent 87ba099096
commit 8f6460d2f7

@ -29,7 +29,7 @@ public class UserService {
}
public int login(String username,String password){
conn = db.getConnection();
conn = DatabaseHelper.getConnection();
Statement sttmt;
try{
sttmt = conn.createStatement();
@ -57,7 +57,7 @@ public class UserService {
}
public boolean register(User user){
conn = db.getConnection();//将用户的信息上传到数据库上传成功返回true失败false
conn = DatabaseHelper.getConnection();//将用户的信息上传到数据库上传成功返回true失败false
try{
String sql = "insert into user_info(username,password,role,phone) values('"+user.getUsername()+"','"+user.getPassword()+"','"+user.getRole()+"','"+user.getPhone()+"')";
Statement sttmt = conn.createStatement();
@ -71,7 +71,7 @@ public class UserService {
}
public boolean donate(long stu_id,long user_id,float money){
conn = db.getConnection();//将用户捐款信息上传到数据库成功返回true失败返回false
conn = DatabaseHelper.getConnection();//将用户捐款信息上传到数据库成功返回true失败返回false
try{
String time=getNetTime();
// Date date = new Date();sdf.format(date)
@ -101,13 +101,17 @@ public class UserService {
String format = formatter.format(calendar.getTime());
return format;
}
public boolean longterm(String name,String phone,String descri, Long ID){
conn = db.getConnection();//将长期资助信息上传到数据库成功返回true失败返回false
public boolean longterm(String name, Long stu_id,Long user_id){
conn = DatabaseHelper.getConnection();//将长期资助信息上传到数据库成功返回true失败返回false
try{
String sql = "insert into usr_help_req(name,phone,descri,ID) values('"+name+"','"+phone+"','"+descri+"','"+ID+"')";
//name,phone,descri,ID
String sql = "insert into usr_long_help(stu_id,user_id,flags) values('"+stu_id+"','"+user_id+"','"+0+"')";
// where null=(select name from user_info where user_id='"+user_id+"')
String sql1="update user_info set name='"+name+"' where (select name from (select name from user_info where user_id='"+user_id+"') t1 ) is not null";
//update user_info set name="你的好爸爸" where (select name from (select name from user_info where user_id=1) t1 ) is null
//stuid,useerid,flags
Statement sttmt = conn.createStatement();
sttmt.executeUpdate(sql);
sttmt.executeUpdate(sql1);
sttmt.close();
return true;
}
@ -120,7 +124,7 @@ public class UserService {
//SQLiteDatabase sdb=dbHelper.getReadableDatabase();
String sql="select * from user_info where username = '" + username+"'and password = '"+password+"'";
User user = new User();
conn = db.getConnection();
conn = DatabaseHelper.getConnection();
try{
Statement sttmt = conn.createStatement();
ResultSet rs = sttmt.executeQuery(sql);
@ -141,7 +145,7 @@ public class UserService {
public boolean UploadInfo(News news){//用户上传信息到数据库,服务器
String sql = "insert into stu_info(name,descri) values('"+news.getName()+"','"+news.getDescri() + "')";
conn = db.getConnection();
conn = DatabaseHelper.getConnection();
try{
Statement sttmt = conn.createStatement();
sttmt.executeUpdate(sql);
@ -156,7 +160,7 @@ public class UserService {
public void getAllNews(Context context,ArrayList<News> list){
//ArrayList<News> mlist = list;
String sql = "select * from stu_info where flags = 1";
conn = db.getConnection();
conn = DatabaseHelper.getConnection();
try{
Statement sttmt = conn.createStatement();
ResultSet rs = sttmt.executeQuery(sql);
@ -178,7 +182,7 @@ public class UserService {
public void getDonateRecords(ArrayList<Record> recordlist,long user_id){
String sql = "select * from record,stu_info where record.stu_id = stu_info.stu_id and record.user_id='"+user_id+"'";
conn = db.getConnection();
conn = DatabaseHelper.getConnection();
try{
Statement sttmt = conn.createStatement();
ResultSet rs = sttmt.executeQuery(sql);
@ -199,7 +203,7 @@ public class UserService {
public void getDonatedRecords(ArrayList<Record> recordlist,long id){
String sql = "select * from record,user_info where record.user_id = user_info.user_id and record.stu_id = '"+id+"'";
conn = db.getConnection();
conn = DatabaseHelper.getConnection();
try{
Statement sttmt = conn.createStatement();
ResultSet rs = sttmt.executeQuery(sql);

@ -65,11 +65,11 @@ public class DonateActivity extends AppCompatActivity {
// }
// });
}
public void onToMain(View view){
Intent intent = new Intent(DonateActivity.this, MainActivity.class);
startActivity(intent);
// public void onToMain(View view){
// Intent intent = new Intent(DonateActivity.this, MainActivity.class);
// startActivity(intent);
// MessageCommit();
}
// }
public void onClick(View view){
money=findViewById(R.id.Money);
@ -151,6 +151,8 @@ public class DonateActivity extends AppCompatActivity {
else{
Looper.prepare();
Toast toast=Toast.makeText(DonateActivity.this, "提交成功",Toast.LENGTH_LONG);
Intent intent = new Intent(DonateActivity.this, MainActivity.class);
startActivity(intent);
float money=Float.parseFloat(mon);
userService.donate(stu_id,user_id,money);
toast.setGravity(Gravity.CENTER, 100, 100);

@ -24,7 +24,7 @@ public class LongTermDonate extends AppCompatActivity {
UserService userService=new UserService();
//String username;
//String stu_name;
Long id;
Long stu_id,user_id;
Handler mHandler = new Handler(){//用于处理子线程传回的消息对主线的UI进行修改
int flag = -1;
@Override
@ -32,15 +32,15 @@ public class LongTermDonate extends AppCompatActivity {
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 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;
@ -56,32 +56,28 @@ public class LongTermDonate extends AppCompatActivity {
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);
stu_id= getIntent().getLongExtra("stu_id",0);
user_id=getIntent().getLongExtra("user_id",0);
}
public void onClick(View view){
name=findViewById(R.id.Name);
number=findViewById(R.id.TeleNumber);
des=findViewById(R.id.Desp);
// 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 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);
@ -90,52 +86,54 @@ public class LongTermDonate extends AppCompatActivity {
if (isMatch) return 1;
return 0;
}
private int judgedes(String des){
if ((des == null) || ("".equals(des)))
return 0;
return 1;//描述不为空
}
// 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 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);
// String num = number.getText().toString();
// String DESP=des.getText().toString();
// flag = judgenum(num);//判断手机号
// 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){
// if(flag==1){
// message.what = 1;
// message.obj = "电话号码位数不对";
// mHandler.sendMessage(message);
// }
// else if(flag==2){
// message.what = 1;
// message.obj = "请输入正确的电话号码";
// mHandler.sendMessage(message);
// }
if(flag11==0){
message.what = 3;
message.obj = "姓名输入不对";
mHandler.sendMessage(message);
}
else if(flag1==0){
message.what = 2;
message.obj = "描述为空,请输入一些描述";
mHandler.sendMessage(message);
}
// else if(flag1==0){
// message.what = 2;
// message.obj = "描述为空,请输入一些描述";
// mHandler.sendMessage(message);
// }
else{
Looper.prepare();
userService.longterm(nam,stu_id,user_id);
Toast toast=Toast.makeText(LongTermDonate.this, "提交成功",Toast.LENGTH_LONG);
Intent intent = new Intent(LongTermDonate.this, MainActivity.class);
startActivity(intent);
//userService.donate(username,stu_name,id,money);
userService.longterm(nam,num,DESP,id);
toast.setGravity(Gravity.CENTER, 100, 100);
toast.show();

@ -40,7 +40,7 @@ public class NewsContentActivity extends AppCompatActivity{
onToLongTerm();
}
public void onToDonate( ){
Button button1 = (Button) findViewById(R.id.button);//id后面为上方button的id
Button button1 = findViewById(R.id.button);//id后面为上方button的id
button1.setOnClickListener(new View.OnClickListener() {
@ -67,13 +67,14 @@ public class NewsContentActivity extends AppCompatActivity{
}
public void onToLongTerm( ){
Button longterm=(Button) findViewById(R.id.longterm);
Button longterm= 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);
intent.putExtra("user_id",user_id);
startActivity(intent);
}
});

@ -30,6 +30,7 @@ public class UploadActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload);
context = this;
//stu_pic = findViewById(R.id.stu_pic);
}

@ -1,6 +1,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_marginTop="50dp">
<!--<LinearLayout
@ -69,29 +70,13 @@
android:inputType="numberDecimal"
/>
</LinearLayout>
<LinearLayout
android:layout_width="481dp"
<Button
android:layout_width="wrap_content"
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="onToMain"
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>
android:layout_gravity="center"
android:onClick="onClick"
android:text="提交">
</Button>
</LinearLayout>

@ -2,27 +2,29 @@
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_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/name"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp">
android:layout_weight="0"
android:textColor="@color/colorAccent"
android:text="姓名" />
<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="1"
android:hint="请输入你的姓名"
android:inputType="textPersonName" />
</LinearLayout>
<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"
@ -66,31 +68,25 @@
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
<!-- <Button
android:id="@+id/commit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="75dp"
android:onClick="onToMain"
android:text="跳转首页"></Button>
-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_gravity="center"
android:onClick="onClick"
android:text="提交">
</Button>
</LinearLayout>
</LinearLayout>

@ -54,35 +54,33 @@
android:padding="15dp"
android:scrollbars="vertical"
android:textSize="18sp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<Button
android:id="@+id/browse_donated_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:text="捐助信息" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/longterm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:text="长期捐助" />
<Button
android:id="@+id/browse_donated_btn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="40dp"
android:text="捐助信息" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:onClick="onToMain"
android:text="捐助" />
</LinearLayout>
<Button
android:id="@+id/longterm"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="40dp"
android:text="长期捐助" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="40dp"
android:onClick="onToMain"
android:text="捐助" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>

Loading…
Cancel
Save