diff --git a/app/src/main/java/hunnu/sj/raise_money/DataBase/UserService.java b/app/src/main/java/hunnu/sj/raise_money/DataBase/UserService.java index 7d77002..b6d47b8 100644 --- a/app/src/main/java/hunnu/sj/raise_money/DataBase/UserService.java +++ b/app/src/main/java/hunnu/sj/raise_money/DataBase/UserService.java @@ -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 list){ //ArrayList 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 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 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); diff --git a/app/src/main/java/hunnu/sj/raise_money/DonateActivity.java b/app/src/main/java/hunnu/sj/raise_money/DonateActivity.java index b205f58..a0e37f6 100644 --- a/app/src/main/java/hunnu/sj/raise_money/DonateActivity.java +++ b/app/src/main/java/hunnu/sj/raise_money/DonateActivity.java @@ -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); diff --git a/app/src/main/java/hunnu/sj/raise_money/LongTermDonate.java b/app/src/main/java/hunnu/sj/raise_money/LongTermDonate.java index c31bf71..2c19ec3 100644 --- a/app/src/main/java/hunnu/sj/raise_money/LongTermDonate.java +++ b/app/src/main/java/hunnu/sj/raise_money/LongTermDonate.java @@ -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(); diff --git a/app/src/main/java/hunnu/sj/raise_money/NewsContentActivity.java b/app/src/main/java/hunnu/sj/raise_money/NewsContentActivity.java index f41d5cf..7d9980b 100644 --- a/app/src/main/java/hunnu/sj/raise_money/NewsContentActivity.java +++ b/app/src/main/java/hunnu/sj/raise_money/NewsContentActivity.java @@ -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); } }); diff --git a/app/src/main/java/hunnu/sj/raise_money/UploadActivity.java b/app/src/main/java/hunnu/sj/raise_money/UploadActivity.java index 8ff322e..1eb533a 100644 --- a/app/src/main/java/hunnu/sj/raise_money/UploadActivity.java +++ b/app/src/main/java/hunnu/sj/raise_money/UploadActivity.java @@ -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); } diff --git a/app/src/main/res/layout/activity_donate.xml b/app/src/main/res/layout/activity_donate.xml index d2450a9..bd5c54b 100644 --- a/app/src/main/res/layout/activity_donate.xml +++ b/app/src/main/res/layout/activity_donate.xml @@ -1,6 +1,7 @@ - - - - +--> - + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_news_content.xml b/app/src/main/res/layout/fragment_news_content.xml index 4a1c9d4..0b2b2f9 100644 --- a/app/src/main/res/layout/fragment_news_content.xml +++ b/app/src/main/res/layout/fragment_news_content.xml @@ -54,35 +54,33 @@ android:padding="15dp" android:scrollbars="vertical" android:textSize="18sp" /> + +