package com.jqyd.son;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import org.json.JSONException;
import org.json.JSONObject;
import com.jqyd.adapter.MyAdapter;
import com.jqyd.manager.R;
import com.jqyd.model.PublicInfoModule;
import com.jqyd.shareInterface.Optdb_interfce;
import com.jqyd.shareInterface.Optsharepre_interface;
import com.jqyd.shareInterface.UpdataToServer;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.AdapterView;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
public class GgList extends Activity{
private ListView listView;
private MyAdapter adapter;
private EditText ksrq;
private EditText jsrq;
private ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
private ArrayList<Bundle> listBundle = new ArrayList<Bundle>();
String moduleName = "";
private Calendar c;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.gglist);
listView = (ListView) this.findViewById(R.id.gongglist);
Intent intent = this.getIntent();
moduleName = intent.getStringExtra("moduleName");
}
//初始化
public void initDate(){
c = Calendar.getInstance();
//业务时间默认当天
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String mDateTime1 = formatter.format(date);
ksrq.setText(mDateTime1);
jsrq.setText(mDateTime1);
}
//设置界面显示
public void setShow(){
adapter=new MyAdapter(list, this,7);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
Bundle bundle = listBundle.get(position);
int state = bundle.getInt("state");
if(state == 1){//未阅读,向服务器发送更新阅读状态请求,同时更新终端数据库中的数据
String zguid = new Optsharepre_interface(GgList.this).getDataFromPres("GUID");
JSONObject object = new JSONObject();
try {
object.put("gid", bundle.getInt("gid"));
object.put("zguid", zguid);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Optdb_interfce db = new Optdb_interfce(GgList.this);
db.updateReadState("T_PUBINFOS", bundle.getInt("gid"));
db.close_SqlDb();
new UpdataToServer(GgList.this).dataToServer("GGTZ", object);
}
Intent intent =new Intent();
intent.putExtras(bundle);
intent.putExtra("moduleName", "ggtz");
intent.setClass(GgList.this, Info.class);
startActivity(intent);
}
});
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
if(moduleName.equals("unread")){
cxFromDb("1");
}else if(moduleName.equals("all")){
cxFromDb("");
}
}
/**
* 查询服务
*/
public void cxFromDb(String select){
list.clear();
listBundle.clear();
ArrayList<Object> listDatas= new Optdb_interfce(GgList.this).searchPubinfos_new(select);
HashMap<String,String> map = null;
Bundle bundle = null;
for(int i=0;i<listDatas.size();i++){
PublicInfoModule pub = (PublicInfoModule) listDatas.get(i);
map = new HashMap<String, String>();
map.put("textView1", pub.getTitle());
map.put("textView2", pub.getAdd_time());
map.put("state", pub.getState()+"");
list.add(map);
//********************************************************************
bundle = new Bundle();
bundle.putString("title", pub.getTitle());
bundle.putString("content", pub.getContent());
bundle.putString("g_cosim", pub.getAdduser());
bundle.putString("addtime", pub.getAdd_time());
bundle.putInt("state", pub.getState());
bundle.putInt("gid", pub.getGid());
listBundle.add(bundle);
}
if(list.size()>0){
setShow();
}else{
showToast("没有新的公告和通知!");
}
}
//弹出日期框
public void getDate() {
new DatePickerDialog(GgList.this,
new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker arg0, int year, int month,
int date) {
// TODO Auto-generated method stub
String m = "";
String d = "";
if ((month + 1) < 10) {
m = "0" + (month + 1);
} else {
m = (month + 1) + "";
}
if (date < 10) {
d = "0" + date;
} else {
d = date + "";
}
String time = year + "-" + m + "-" + d;
ksrq.setText(time);
}
}, c.get(Calendar.YEAR), c.get(Calendar.MONTH),
c.get(Calendar.DAY_OF_MONTH)).show();
}
Handler myHander = new Handler(){
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
switch(msg.what){
case 1:
showDialog(1);
break;
case 2:
removeDialog(1);
setShow();
break;
case 3:
removeDialog(1);
Bundle bundle = msg.getData();
showToast(bundle.getString("msg"));
break;
}
}
};
/**
* 结果显示
* @param message
*/
public void showToast(String message){
new AlertDialog.Builder(GgList.this)
.setTitle("提示")
.setMessage(message)
.setPositiveButton("确定", null)
.show();
}
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
ProgressDialog dialog = new ProgressDialog(GgList.this);
dialog.setIndeterminate(true);
dialog.setCancelable(false);
switch(id){
case 1:
dialog.setMessage("正在查询,请稍候……");
break;
case 2:
break;
case 3:
break;
}
return dialog;
}
}