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.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.jqyd.adapter.MyAdapter;
import com.jqyd.app.MyApp;
import com.jqyd.app.VirtualData;
import com.jqyd.manager.R;
import com.jqyd.model.CoUserModule;
import com.jqyd.shareInterface.Optdb_interfce;
import com.jqyd.shareInterface.Optsharepre_interface;
import com.jqyd.shareInterface.UpdataToServer;
import com.jqyd.son.Xxcx.CxThread;
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.Looper;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
public class Xxcx extends Activity implements OnClickListener {
private EditText sj;
private Button cx;
private ListView listView;
private Calendar c;
private MyAdapter adapter;
private ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
private ArrayList<Bundle> listBundle = new ArrayList<Bundle>();
private MyApp myApp ;
private String biaozhi;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.xxcx);
sj = (EditText) this.findViewById(R.id.sj);
cx = (Button) this.findViewById(R.id.cx);
listView = (ListView) this.findViewById(R.id.list);
sj.setOnClickListener(this);
cx.setOnClickListener(this);
init();
myApp = (MyApp) this.getApplication();
biaozhi = myApp.getModuleName();
}
//初始化
public void init(){
c = Calendar.getInstance();
//业务时间默认当天
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String mDateTime1 = formatter.format(date);
sj.setText(mDateTime1);
}
//设置界面显示
public void setShow(){
adapter=new MyAdapter(list, this,6);
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);
Intent intent =new Intent();
String bs = "";
if(biaozhi.equals("qygg") || biaozhi.equals("ywtz")){
bs = "ggtz";
}else if(biaozhi.equals("dxqf")){
bs = "sms";
}
intent.putExtra("moduleName", bs);
intent.putExtras(bundle);
intent.setClass(Xxcx.this, Info.class);
startActivity(intent);
}
});
}
/**
* 查询企业公告信息
*/
public String cxQyggFromServer(){
list.clear();
//list = VirtualData.getInfo();
String mgs = "";
String date = sj.getText().toString();
JSONObject object = new JSONObject();
Optsharepre_interface share_obj = new Optsharepre_interface(Xxcx.this);
try {
object.put("zguid", share_obj.getDataFromPres("GUID"));
object.put("cxrq", date);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String result = new UpdataToServer(Xxcx.this).searchFromServer("QYGG", object);
if(!result.equals("") && !result.equals("-1") && !result.equals("500")){
JSONObject obj = null;
try {
obj = new JSONObject(result);
} catch (JSONException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
try {
JSONObject jg = (JSONObject) obj.get("cxjg");
if(jg.getString("result").equals("0")){//有数据
HashMap<String,String> map = null;
Bundle bundle = null;
JSONArray cxnrs = (JSONArray) obj.get("cxnr");
for(int i=0;i<cxnrs.length();i++){
try {
JSONObject obj_gg = (JSONObject) cxnrs.get(i);
bundle = new Bundle();
bundle.putString("title", obj_gg.getString("title"));
bundle.putString("content", obj_gg.getString("content"));
bundle.putString("g_cosim", obj_gg.getString("adduser"));
bundle.putString("addtime", obj_gg.getString("add_time"));
listBundle.add(bundle);
map = new HashMap<String,String>();
map.put("textView1", obj_gg.getString("title"));
list.add(map);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
mgs = "0";//成功获得数据
}else{
mgs = jg.getString("detail");
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else if(result.equals("-1")){
mgs = "抱歉,网络连接失败!";
}else{
mgs = "查询失败,请联系你的管理员!";
}
return mgs;
}
/**
* 查询业务通知信息
*/
public String cxYwtzFromServer(){
list.clear();
//list = VirtualData.getInfo();
String mgs = "";
String date = sj.getText().toString();
JSONObject object = new JSONObject();
Optsharepre_interface share_obj = new Optsharepre_interface(Xxcx.this);
try {
object.put("zguid", share_obj.getDataFromPres("GUID"));
object.put("cxrq", date);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String result = new UpdataToServer(Xxcx.this).searchFromServer("YWTZ", object);
if(!result.equals("") && !result.equals("-1") && !result.equals("500")){
JSONObject obj = null;
try {
obj = new JSONObject(result);
} catch (JSONException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
try {
JSONObject jg = (JSONObject) obj.get("cxjg");
if(jg.getString("result").equals("0")){//有数据
HashMap<String,String> map = null;
Bundle bundle = null;
JSONArray cxnrs = (JSONArray) obj.get("cxnr");
for(int i=0;i<cxnrs.length();i++){
try {
JSONObject obj_gg = (JSONObject) cxnrs.get(i);
bundle = new Bundle();
bundle.putString("title", obj_gg.getString("title"));
bundle.putString("content", obj_gg.getString("content"));
bundle.putString("g_cosim", obj_gg.getString("adduser"));
bundle.putString("addtime", obj_gg.getString("add_time"));
listBundle.add(bundle);
map = new HashMap<String,String>();
map.put("textView1", obj_gg.getString("title"));
list.add(map);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
mgs = "0";//成功获得数据
}else{
mgs = jg.getString("detail");
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else if(result.equals("-1")){
mgs = "抱歉,网络连接失败!";
}else{
mgs = "查询失败,请联系你的管理员!";
}
return mgs;
}
/**
* 查询短信信息
*/
public String cxSmsFromServer(){
list.clear();
//list = VirtualData.getInfo();
String mgs = "";
String date = sj.getText().toString();
JSONObject object = new JSONObject();
Optsharepre_interface share_obj = new Optsharepre_interface(Xxcx.this);
try {
object.put("cosim", share_obj.getDataFromPres("COSIM"));
object.put("regsim", share_obj.getDataFromPres("REGSIM"));
object.put("cxrq", date);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String result = new UpdataToServer(Xxcx.this).searchFromServer("SMS", object);
if(!result.equals("") && !result.equals("-1") && !result.equals("500")){
JSONObject obj = null;
try {
obj = new JSONObject(result);
} catch (JSONException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
try {
JSONObject jg = (JSONObject) obj.get("cxjg");
if(jg.getString("result").equals("0")){//有数据
HashMap<String,String> map = null;
Bundle bundle = null;
JSONArray cxnrs = (JSONArray) obj.get("cxnr");
for(int i=0;i<cxnrs.length();i++){
try {
JSONObject obj_gg = (JSONObject) cxnrs.get(i);
bundle = new Bundle();
bundle.putString("fsrq", obj_gg.getString("fsrq"));
bundle.putString("operSjhm", obj_gg.getString("operSjhm"));
bundle.putString("bjhm", obj_gg.getString("bjhm"));
bundle.putString("content", obj_gg.getString("content"));
listBundle.add(bundle);
map = new HashMap<String,String>();
map.put("textView1", obj_gg.getString("content"));
list.add(map);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
mgs = "0";//成功获得数据
}else{
mgs = jg.getString("detail");
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else if(result.equals("-1")){
mgs = "抱歉,网络连接失败!";
}else{
mgs = "查询失败,请联系你的管理员!";
}
return mgs;
}
/**
* 处理线程
*/
class CxThread extends Thread implements Runnable{
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
Looper.prepare();
Message msg =new Message();
msg.what = 1;
myHander.sendMessage(msg);
Message msg2 =new Message();
String result = "查询失败,请联系你的管理员!";
if(myApp.getModuleName().equals("qygg")){
result = cxQyggFromServer();
}else if(myApp.getModuleName().equals("ywtz")){
result = cxYwtzFromServer();
}else if(myApp.getModuleName().equals("dxqf")){
result = cxSmsFromServer();
}
Bundle bunlde = new Bundle();
if(result.equals("0")){
msg2.what = 2;
}else{
msg2.what = 3;
bunlde.putString("msg", result);
}
msg2.setData(bunlde);
myHander.sendMessage(msg2);
Looper.loop();
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v == sj){
getDate();
}else if(v == cx){
new CxThread().start();
}
}
//弹出日期框
public void getDate() {
new DatePickerDialog(Xxcx.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;
sj.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);
setShow();
Bundle bundle = msg.getData();
showToast(bundle.getString("msg"));
break;
}
}
};
/**
* 结果显示
* @param message
*/
public void showToast(String message){
new AlertDialog.Builder(Xxcx.this)
.setTitle("提示")
.setMessage(message)
.setPositiveButton("确定", null)
.show();
}
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
ProgressDialog dialog = new ProgressDialog(Xxcx.this);
dialog.setIndeterminate(true);
dialog.setCancelable(false);
switch(id){
case 1:
dialog.setMessage("正在查询,请稍候……");
break;
case 2:
break;
case 3:
break;
}
return dialog;
}
}