package com.bigdo.app;
import org.json.JSONObject;
import com.bigdo.common.BDSQLiteHelper;
import com.bigdo.common.RConfig;
import com.bigdo.common.RState;
import com.bigdo.util.WSCheck;
import com.bigdo.util.WSHelper;
import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnDismissListener;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
public class Me_GrowthHistory_Detail_Activity extends BaseActivity {
int idgrow = 0;
String title, content, createtime;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.me_growthhistory_detail_activity);
getGrow();
View com_title = (View) findViewById(R.id.bd_title_host);
TextView bd_title_operate = (TextView) com_title
.findViewById(R.id.bd_title_operate);
bd_title_operate.setText("编 辑");
bd_title_operate.setVisibility(View.VISIBLE);
bd_title_operate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
editGrow();
}
});
ImageButton bd_title_back = (ImageButton) com_title
.findViewById(R.id.bd_title_back);
bd_title_back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
Button delgrow = (Button) findViewById(R.id.delgrow);
delgrow.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
delGrow();
}
});
}
private void editGrow() {
if (idgrow >= 0) {
Intent i = new Intent();
i.setClass(this, Me_Edit_GrowthHistory_Activity.class);
i.putExtra("tag", "update");
i.putExtra("idgrow", idgrow);
i.putExtra("title", title);
i.putExtra("content", content);
i.putExtra("createtime", createtime);
i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivityForResult(i, 1);
}
}
private void getGrow() {
idgrow = this.getIntent().getIntExtra("idgrow", -1);
if (idgrow >= 0) {
BDSQLiteHelper sqlobj = null;
SQLiteDatabase sqlobj_r = null;
Cursor cu = null;
try {
sqlobj = new BDSQLiteHelper(this);
sqlobj_r = sqlobj.getReadableDatabase();
String sqlt = "select * from grow where idgrow = ? limit 0,1";
cu = sqlobj_r.rawQuery(sqlt, new String[] { idgrow + "" });
if (cu.moveToFirst()) {
title = cu.getString(cu.getColumnIndex("title"));
content = cu.getString(cu.getColumnIndex("content"));
createtime = cu.getString(cu.getColumnIndex("createtime"));
}
} catch (Exception e2) {
this.messageBox("读取成长史信息出错");
}
try {
if (cu != null) {
cu.close();
cu = null;
}
} catch (Exception ex) {
}
try {
if (sqlobj_r != null) {
sqlobj_r.close();
sqlobj_r = null;
}
} catch (Exception ex) {
}
try {
if (sqlobj != null) {
sqlobj.close();
sqlobj = null;
}
} catch (Exception ex) {
}
View com_title = (View) findViewById(R.id.bd_title_host);
TextView bd_title_name = (TextView) com_title
.findViewById(R.id.bd_title_name);
bd_title_name.setText(title);
TextView grow_content = (TextView) findViewById(R.id.grow_content);
grow_content.setText(content);
}
}
private void delGrow() {
if (idgrow >= 0) {
JSONObject jparam = new JSONObject();
try {
jparam.put("idgrow", idgrow);
} catch (Exception e) {
this.messageBox("准备请求参数出错.");
return;
}
showProgress("删除中...");
String url = RConfig.delGrow(this);
String data = jparam.toString();
WSHelper ws = new WSHelper(this, "", false, handler, url, "",
WSHelper.getStringEntity(data), 0, 0, 0, 0, WSHelper.POST);
ws.start();
Log.e("delGrow", url);
Log.e("delGrow_data", data);
} else {
this.messageBox("成长史参数有误.");
}
}
@SuppressLint("HandlerLeak")
protected Handler handler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.arg1 == RState.WSCall) {
hiddenProgress();
JSONObject jresult = WSCheck.Json(
Me_GrowthHistory_Detail_Activity.this, msg);
if (jresult != null) {
delGrowLocal();
messageBox("删除成功", new OnDismissListener() {
@Override
public void onDismiss(DialogInterface arg0) {
setResult(1);
finish();
}
});
}
}
}
};
private void delGrowLocal() {
BDSQLiteHelper sqlobj = null;
SQLiteDatabase sqlobj_w = null;
sqlobj = new BDSQLiteHelper(this);
sqlobj_w = sqlobj.getWritableDatabase();
try {
sqlobj_w.delete("grow", "idgrow=?", new String[] { idgrow + "" });
} catch (Exception ee) {
}
try {
if (sqlobj_w != null) {
sqlobj_w.close();
sqlobj_w = null;
}
} catch (Exception ex) {
}
try {
if (sqlobj != null) {
sqlobj.close();
sqlobj = null;
}
} catch (Exception ex) {
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == 1) {
setResult(1);
getGrow();
}
}
@Override
public void onClearData() {
// TODO Auto-generated method stub
}
@Override
public void onVideoBroadcast(Intent intent) {
// TODO Auto-generated method stub
}
}