package com.jqyd.son;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;
import com.jqyd.adapter.MyAdapter;
import com.jqyd.app.MyApp;
import com.jqyd.manager.Khcj;
import com.jqyd.manager.R;
import com.jqyd.model.OrderDetailModel;
import com.jqyd.model.OrderMxDetailModel;
import com.jqyd.shareInterface.CheckState_interface;
import com.jqyd.shareInterface.GpsService;
import com.jqyd.shareInterface.MyIntent;
import com.jqyd.shareInterface.Optdb_interfce;
import com.jqyd.shareInterface.Optsharepre_interface;
import com.jqyd.shareInterface.SystemInfo;
import com.jqyd.shareInterface.UpdataToServer;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;
public class InfoAndAct extends Activity implements OnClickListener {
private TextView info;
private EditText spyj;
private Button agree;
private Button disagree;
private MyApp myApp;
private ListView listView;
private MyAdapter adapter;
private ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
private String orderCounts = "0";
private Bundle bundle = null;
private String clDays = "";
private String jhlx = "";
private ArrayList<String> dzxCustList = new ArrayList<String>();//存放待执行客户id
private String value = "";
private String xdr = "";//用于订单
private Optdb_interfce db;
private int ts = 0;//1、差旅开始时间大于当前服务器端时间
private Button ckfj;
String filename="";
String filepath="";
private ProgressDialog proDia;
boolean b = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.infoandact);
info = (TextView) this.findViewById(R.id.info);
spyj = (EditText) this.findViewById(R.id.spyj);
agree = (Button) this.findViewById(R.id.agree);
disagree = (Button) this.findViewById(R.id.disagree);
listView = (ListView) this.findViewById(R.id.list);
ckfj = (Button) findViewById(R.id.ckfj);
agree.setOnClickListener(this);
disagree.setOnClickListener(this);
Intent intent = this.getIntent();
myApp = (MyApp) this.getApplication();
String moduleName = intent.getStringExtra("sort");
System.out.println("审批111111111111111111111111---------------------"+moduleName+","+intent.getStringExtra("dbType"));
if(moduleName.equals("1") || moduleName.equals("3")){
String sort = intent.getStringExtra("dbType");
bundle = intent.getExtras();
//审批类别(1、请假、2、订单、3、计划 4、差旅)
if(sort.equals("1")){
this.setTitle("请假审批");
value = "单据编号:"+bundle.getString("spid")
+"<p>员工姓名:"+bundle.getString("zdmc")+"</p>"
+"<p>手机号码:"+bundle.getString("regsim")+"</p>"
+"<p>归属部门:"+bundle.getString("department")+"</p>"
+"<p>假期类别:"+bundle.getString("qjlb")+"</p>"
+"<p>开始时间:"+bundle.getString("ksrq")+"</p>"
+"<p>结束时间:"+bundle.getString("jsrq")+"</p>"
+"<p>请假天数:"+bundle.getString("day")+"天</p>"
+"<p>请假时长:"+bundle.getString("hour")+"小时</p>"
+"<p>请假原因:"+bundle.getString("bz")+"</p>"
+"<p>填写日期:"+bundle.getString("addtime")+"</p>";
}else if(sort.equals("2")){
this.setTitle("订单审批");
OrderDetailModel orderinfo = myApp.getOrderinfo();
ArrayList<OrderMxDetailModel> ordermx = myApp.getList_ordermx();
orderCounts = orderinfo.getAllcount();
xdr = orderinfo.getXdr();
//"订单编号:"+orderinfo.getDdbh()
value = "客户名称:"+orderinfo.getCname()
//+"<br>收货人:"+orderinfo.getShr()+"</br>"
//+"<br>联系电话:"+orderinfo.getLinktel()+"</br>"
//+"<br>收货地址:"+orderinfo.getShdz()+"</br>"
+"<p>交货日期:"+orderinfo.getJhtime()+"</p>"
+"<p>下单日期:"+orderinfo.getXdTime()+"</p>"
+"<p>订单总金额:"+orderinfo.getAllcount()+"元</p>"
//+"<br>备注:"+orderinfo.getBz()+"</br>"
+"<br><font color=red>------以下为商品信息------</font></br>";
//加载商品信息
HashMap<String,String> map = null;
String goodInfo = "";
for(int i=0;i<ordermx.size();i++){
OrderMxDetailModel detail = ordermx.get(i);
System.out.println("-----------"+detail.getSpname());
map = new HashMap<String, String>();
/* goodInfo = "商品名称:"+detail.getSpname()
+"<br>规格型号:"+detail.getGgxh()+"</br>"
+"<br>单位:"+detail.getUnit()+"</br>"
+"<br>参考单价:"+detail.getCkprice()+"</br>"
+"<br>实际售价:"+detail.getSaleprice()+"</br>"
+"<br>订购数量:"+detail.getSpnum()+"</br>";
map.put("textView1", goodInfo);
list.add(map);*/
goodInfo = detail.getSpname()
+"<p>"+detail.getGgxh()+"</p>"
+"<p>参考单价:"+detail.getCkprice()+"元 实际售价:"+detail.getSaleprice()+"元</p>"
+"订购数量:"+detail.getSpnum()+detail.getUnit();
map.put("textView1", goodInfo);
list.add(map);
}
setShow();
}else if(sort.equals("3")){
this.setTitle("计划审批");
//计划类型(1-客户走访 2-陌生走访 3-再次拜访 4-市场检查 5-促销执行)
jhlx = bundle.getString("type");
if(jhlx.equals("1")){
jhlx = "客户走访 ";
}else if(jhlx.equals("2")){
jhlx = "陌生走访";
}else if(jhlx.equals("3")){
jhlx = "再次拜访";
}else if(jhlx.equals("4")){
jhlx = "市场检查";
}else if(jhlx.equals("5")){
jhlx = "促销执行";
}
String allCust_Name = "";
String yzxCust_name = "";
String dzxCust_name = "";
int allCust_num = 0;
int yzxCust_num = 0;
int dzxCust_num = 0;
value = "单据编号:"+bundle.getString("spid")
+"<br>员工姓名:"+bundle.getString("zdmc")+"</br>"
+"<br>手机号码:"+bundle.getString("sjhm")+"</br>"
+"<br>填写日期:"+bundle.getString("addtime")+"</br>"
+"<br>开始时间:"+bundle.getString("begTime")+"</br>"
+"<br>结束时间:"+bundle.getString("endTime")+"</br>"
+"<br>计划类型:"+jhlx+"</br>"
+"<br>客户数量:"+bundle.getString("cusum")+"个</br>";
if(!jhlx.equals("陌生走访")){
System.out.println("*********:"+bundle.getString("allCusts").toString());
//分解客户信息
String []allCusts = bundle.getString("allCusts").split("#");
if(!bundle.getString("allCusts").equals(",") && !bundle.getString("allCusts").equals("")){
for(int i=0;i<allCusts.length;i++){
System.out.println("--------"+allCusts[i]);
allCust_Name += allCusts[i].split(",")[1]+",";
}
allCust_Name = allCust_Name.substring(0,allCust_Name.length()-1);
//allCust_num = allCusts.length;
}
value+="<br>目标客户:"+allCust_Name+"</br>";
}
Optsharepre_interface share_obj = new Optsharepre_interface(InfoAndAct.this);
//判断是需要用户执行还是上级主管审核
String regguid = bundle.getString("guid");
//登录用户的guid和计划执行的guid相等、执行状态为待执行或执行中、审批状态为已同意的情况下为执行计划,否则为审批计划
System.out.println("**********************"+share_obj.getDataFromPres("GUID"));
System.out.println("**********************"+bundle.getString("zxzt"));
System.out.println("**********************"+bundle.getString("spzt"));
System.out.println("**********************"+regguid);
if(regguid.equals(share_obj.getDataFromPres("GUID")) && !(bundle.getString("zxzt").equals("2")) && bundle.getString("spzt").equals("4")){
this.setTitle("计划执行");
if(!jhlx.equals("陌生走访")){
String []yzxCusts = bundle.getString("yzxCusts").split("#");
if(!bundle.getString("yzxCusts").equals(",") && !bundle.getString("yzxCusts").equals("")){
/* for(int i=0;i<yzxCusts.length;i++){
yzxCust_name += yzxCusts[i].split(",")[1]+",";
}
yzxCust_name = yzxCust_name.substring(0,yzxCust_name.length()-1);*/
yzxCust_num = yzxCusts.length;
}
String []dzxCusts = bundle.getString("dzxCusts").split("#");
System.out.println("待执行客户------------"+bundle.getString("dzxCustList"));
if(!bundle.getString("dzxCusts").equals(",") && !bundle.getString("dzxCusts").equals("")){
for(int i=0;i<dzxCusts.length;i++){
//dzxCust_name += dzxCusts[i].split(",")[1]+",";
dzxCustList.add(dzxCusts[i].split(",")[0]);
}
//dzxCust_name = dzxCust_name.substring(0,dzxCust_name.length()-1);
dzxCust_num = dzxCusts.length;
}
value+="<br>已执行客户:"+yzxCust_num+"个</br>";
//+"<br>待执行客户:"+dzxCust_num+"</br>"
}
//执行
spyj.setVisibility(EditText.GONE);
agree.setText("执 行");
disagree.setText("返 回");
}else{
//审核
}
}else if(sort.equals("4")){
this.setTitle("差旅审批");
value = "单据编号:"+bundle.getString("spid")
+"<p>员工姓名:"+bundle.getString("zdmc")+"</p>"
+"<p>手机号码:"+bundle.getString("regsim")+"</p>"
+"<p>归属部门:"+bundle.getString("groupName")+"</p>"
+"<p>交通方式:"+bundle.getString("jtfs")+"</p>"
+"<p>开始时间:"+bundle.getString("cfrq")+"</p>"
+"<p>结束时间:"+bundle.getString("fhrq")+"</p>"
+"<p>出发地点:"+bundle.getString("pro_start")+bundle.getString("city_start")+bundle.getString("country_start")+"</p>"
+"<p>出差地点:"+bundle.getString("pro_end")+bundle.getString("city_end")+bundle.getString("country_end")+"</p>"
+"<p>出差事由:"+bundle.getString("ccsy")+"</p>"
+"<p>填写日期:"+bundle.getString("addtime")+"</p>";
clDays = bundle.getString("day");
Optsharepre_interface share_obj = new Optsharepre_interface(InfoAndAct.this);
//判断是需要用户执行还是上级主管审核
String regguid = bundle.getString("guid");
//登录用户的guid和计划执行的guid相等、执行状态为待执行或执行中、审批状态为已同意的情况下为执行计划,否则为审批计划
if(regguid.equals(share_obj.getDataFromPres("GUID")) && !(bundle.getString("zxzt").equals("2")) && bundle.getString("spzt").equals("4")){
String cfrq = bundle.getString("cfrq");
String fhrq = bundle.getString("fhrq");
String serverDate = bundle.getString("serverDate");
SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
Date ks = null;
Date fw = null;
Date js = null;
try {
ks = ft.parse(cfrq);
js = ft.parse(fhrq);
fw = ft.parse(serverDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(fw.getTime()>=ks.getTime() && fw.getTime()<=js.getTime() && bundle.getString("zxzt").equals("0")){//差旅开始时间大于当前服务器端时间并且小于结束时间
agree.setText("开 始");
disagree.setText("返 回");
}else if(bundle.getString("zxzt").equals("1")){
agree.setText("结 束");
disagree.setText("返 回");
}else if(fw.getTime()<ks.getTime()){
ts = 1;
agree.setText("开 始");
disagree.setText("返 回");
}else if(fw.getTime()>js.getTime() && bundle.getString("zxzt").equals("0")){
agree.setText("结 束");
disagree.setText("返 回");
}
spyj.setVisibility(EditText.GONE);
}else{
//审核
}
}else if(sort.equals("5")){//签到信息
this.setTitle("考勤预警");
value = "员工姓名:"+bundle.getString("userName")
+"<p>"+"签到时间:"+bundle.getString("time")+"</p>"
+"<p>"+"签到地点:"+bundle.getString("addr")+"</p>"
+"<p>"+"备注:"+bundle.getString("bz")+"</p>";
spyj.setVisibility(EditText.GONE);
}else if(sort.equals("6")){//签退信息
this.setTitle("考勤预警");
value = "员工姓名:"+bundle.getString("userName")
+"<p>"+"签退时间:"+bundle.getString("time")+"</p>"
+"<p>"+"签退地点:"+bundle.getString("addr")+"</p>"
+"<p>"+"备注:"+bundle.getString("bz")+"</p>";
spyj.setVisibility(EditText.GONE);
}else if(sort.equals("7")){//脱岗信息
this.setTitle("脱岗预警");
value = "员工姓名:"+bundle.getString("userName")
+"<p>"+"脱岗时间:"+bundle.getString("time")+"</p>"
+"<p>"+"脱岗时所在区域:"+bundle.getString("addr")+"</p>"
+"<p>"+"位置详情:"+bundle.getString("bz")+"</p>";
spyj.setVisibility(EditText.GONE);
}
}else if(moduleName.equals("5")){//我的任务
bundle = intent.getExtras();
this.setTitle("任务查看");
value = bundle.getString("tcontent");
spyj.setHint("请输入回复内容");
filename=bundle.getString("filename");
filepath=bundle.getString("filepath");
int hasfile = bundle.getInt("hasfile");
if(hasfile==1){
ckfj.setVisibility(View.VISIBLE);
ckfj.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String downpath="";
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
downpath = Environment.getExternalStorageDirectory().getPath() ;
}else{
downpath = getFilesDir().getAbsolutePath() ;
}
Log.e("filepath", filepath);
Log.e("downpath", downpath);
DownFileThread dft=new DownFileThread(filepath,downpath ,filename);
dft.start();
}
});
}
}
switch(Integer.valueOf(moduleName).intValue()){
case 1:
agree.setVisibility(Button.VISIBLE);
disagree.setVisibility(Button.VISIBLE);
break;
case 3:
agree.setVisibility(Button.GONE);
disagree.setVisibility(Button.GONE);
spyj.setText(bundle.getString("spbz"));
spyj.setEnabled(false);
spyj.setHint("");
break;
case 5:
agree.setVisibility(Button.VISIBLE);
disagree.setVisibility(Button.VISIBLE);
agree.setText("回 复");
disagree.setText("返 回");
break;
}
info.setText(Html.fromHtml(value));
}
@Override
protected void onResume() {
super.onResume();
b = true;
}
@Override
protected void onPause() {
super.onPause();
b = false;
}
//设置界面显示
public void setShow(){
adapter=new MyAdapter(list, this,1);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
}
});
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
//关闭GPS搜星
closeGps();
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v == agree){
if(agree.getText().toString().equals("执 行")){
//启动gps
//startGps();
Intent intent = new Intent();
intent.putStringArrayListExtra("custIds", dzxCustList);
intent.putExtra("spid", bundle.getString("spid"));
System.out.println("计划类型----------"+jhlx);
if(bundle.getString("type").equals("1")){
myApp.setModuleName("jh_khzf");
intent.setClass(InfoAndAct.this, Khlb.class);
}else if(bundle.getString("type").equals("2")){
myApp.setModuleName("jh_msbf");
intent.setClass(InfoAndAct.this, Khcj.class);
}else if(bundle.getString("type").equals("3")){
myApp.setModuleName("jh_echf");
intent.setClass(InfoAndAct.this, Khlb.class);
}else if(bundle.getString("type").equals("4")){
myApp.setModuleName("jh_scjc");
intent.setClass(InfoAndAct.this, Khlb.class);
}else if(bundle.getString("type").equals("5")){
myApp.setModuleName("jh_cxzx");
intent.setClass(InfoAndAct.this, Khlb.class);
}
startActivity(intent);
}else if(agree.getText().toString().equals("开 始") || agree.getText().toString().equals("结 束")){
if(agree.getText().toString().equals("开 始") && ts !=1){
new TravelThread(1).start();
}else if(agree.getText().toString().equals("开 始") && ts ==1){
warnTell("请在"+bundle.getString("cfrq")+"之后再开始执行!");
}else{
new TravelThread(2).start();
}
}else if(agree.getText().toString().equals("回 复")){
new TaskThread().start();
}else{
new SpsbThread(1).start();
}
}else if(v == disagree){
if(disagree.getText().toString().equals("返 回")){
finish();
}else{
new SpsbThread(2).start();
}
}
}
class DownFileThread extends Thread {
private String path;
private String serverPath;
private String fileName;
public DownFileThread(String serverPath,String path,String fileName) {
super();
this.path = path;
this.serverPath = serverPath;
this.fileName = fileName;
}
@Override
public void run() {
Looper.prepare();
Message msg=new Message();
msg.what=4;
myHander.sendMessage(msg);
Message msg2=new Message();
msg2.what=5;
Bundle bundle = new Bundle();
//下载文件
if(down(serverPath, path, fileName)==0){
System.out.println("下载成功");
Intent intent=null;
String[] n=fileName.split("\\.");
if("doc".equals(n[n.length-1].toLowerCase())){//后缀为doc
intent=MyIntent.getWordFileIntent(path+File.separator+fileName);
}else if("xls".equals(n[n.length-1].toLowerCase())){//后缀为xls
intent=MyIntent.getExcelFileIntent(path+File.separator+fileName);
}else if("ppt".equals(n[n.length-1].toLowerCase())){
intent=MyIntent.getPptFileIntent(path+File.separator+fileName);
}else if("pdf".equals(n[n.length-1].toLowerCase())){
intent=MyIntent.getPdfFileIntent(path+File.separator+fileName);
}else if("docx".equals(n[n.length-1].toLowerCase())){
intent=MyIntent.getWord07FileIntent(path+File.separator+fileName);
}else if("xlsx".equals(n[n.length-1].toLowerCase())){
intent=MyIntent.getExcel07FileIntent(path+File.separator+fileName);
}else if("txt".equals(n[n.length-1].toLowerCase())){
intent=MyIntent.getTextFileIntent(path+File.separator+fileName,false);
}
if(null!=intent){
startActivity(intent);
}else{
bundle.putString("msg", "打开失败,格式不支持");
}
msg2.setData(bundle);
myHander.sendMessage(msg2);
}else if(down(serverPath, path, fileName)==2){
bundle.putString("msg", "下载成功");
msg2.setData(bundle);
myHander.sendMessage(msg2);
}else if(down(serverPath, path, fileName)==-1){
bundle.putString("msg", "下载失败");
msg2.setData(bundle);
myHander.sendMessage(msg2);
}else {
bundle.putString("msg", "网络连接失败");
msg2.setData(bundle);
myHander.sendMessage(msg2);
}
Looper.loop();
}
}
public int down(String url, String sdPath, String fileName){
HttpClient client = new DefaultHttpClient();
System.out.println("URL地址--"+url);
HttpGet get = new HttpGet(url);
HttpResponse response;
try {
response = client.execute(get);
HttpEntity entity = response.getEntity();
long length = entity.getContentLength();
System.out.println("长度为:"+length);
InputStream is = entity.getContent();//获取http内容流
//写文件
FileOutputStream fileOutputStream = null;
if (is != null) {
File file = new File(sdPath);
if (!file.exists()) {
file.mkdirs();
}
System.out.println("sdPath " +sdPath);
System.out.println("fileName " +fileName);
File resultFile = new File(sdPath, fileName);
if(!resultFile.exists()){
resultFile.createNewFile();
fileOutputStream = new FileOutputStream(resultFile);
byte[] buf = new byte[1024];
int ch = -1;
int count = 0;
while ( (ch = is.read(buf)) != -1 ) {
// baos.write(buf, 0, ch);
fileOutputStream.write(buf, 0, ch);
count += ch;
if (length > 0) {
}
}
System.out.println("文件大小:"+resultFile.length());
if(resultFile.length()==0){
return 2;//文件下载成功,但是文件内容为空
}else{
return 0;//下载成功,返回0
}
}else{
System.out.println("文件已存在!");
return 0;//等同于下载成功
}
}
fileOutputStream.flush();
if (fileOutputStream != null) {
fileOutputStream.close();
}
}catch(Exception e){
e.printStackTrace();
return 1;
}
return -1;//文件输入流为空,返回-1
}
/**
* 审批上报线程
* @author Administrator
*
*/
class SpsbThread extends Thread {
private int spzt;//1、同意2、拒绝
public SpsbThread(int spzt) {
this.spzt = spzt;
}
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
Looper.prepare();
Message message = new Message();
message.what = 1;
myHander.sendMessage(message);
Message message2 = new Message();
message2.what = 2;
JSONObject object = new JSONObject();
db = new Optdb_interfce(InfoAndAct.this);
Optsharepre_interface share_obj = new Optsharepre_interface(InfoAndAct.this);
//获得登录者姓名
String userName = db.searchEmpName(share_obj.getDataFromPres("GUID"));
db.close_SqlDb();
try {
object.put("spid", bundle.getString("spid"));
object.put("splb", bundle.getString("splb"));
object.put("sjzg", share_obj.getDataFromPres("SJZG"));
object.put("gguid", share_obj.getDataFromPres("GGUID"));
object.put("regguid", share_obj.getDataFromPres("GUID"));
object.put("spjg", spzt);
object.put("odrderprices", orderCounts);
object.put("bz", spyj.getText().toString());
object.put("qjDays", bundle.getString("day"));
object.put("zdName", userName);
object.put("spcs", bundle.getString("spcs"));
object.put("clDays", clDays);
object.put("xdr",xdr);
object.put("sqrguid", bundle.getString("guid"));
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("审批上报--------------------"+object.toString());
// 请求服务器
String result = new UpdataToServer(InfoAndAct.this).dataToServer("SPSB", object);
if (result != null && !result.equals("-1") && !result.equals("500")) {
try {
JSONObject obj = new JSONObject(result);
String res = obj.getString("result");
if (res.equals("0")) {
bundle.putString("msg", "审批成功");
} else {
String errMsg = obj.getString("detail");
bundle.putString("msg", errMsg);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else if(result.equals("-1")){
bundle.putString("msg", "抱歉,网络连接失败!");
} else if(result.equals("500")){
bundle.putString("msg", "审批失败,请联系你的管理员!");
}
message2.setData(bundle);
myHander.sendMessage(message2);
Looper.loop();
}
}
/**
* 任务回复处理线程
* @author Administrator
*
*/
class TaskThread extends Thread {
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
Looper.prepare();
Message message = new Message();
message.what = 1;
myHander.sendMessage(message);
Message message2 = new Message();
message2.what = 2;
JSONObject object = new JSONObject();
Optsharepre_interface share_obj = new Optsharepre_interface(InfoAndAct.this);
try {
object.put("gguid", share_obj.getDataFromPres("GGUID"));
object.put("guid", share_obj.getDataFromPres("GUID"));
object.put("tcode", bundle.getString("tcode"));
object.put("tcontent", spyj.getText().toString());
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("任务回复处理--------------------"+object.toString());
// 请求服务器
String result = new UpdataToServer(InfoAndAct.this).dataToServer("RWHF", object);
if (result != null && !result.equals("-1") && !result.equals("500")) {
try {
JSONObject obj = new JSONObject(result);
String errMsg = obj.getString("detail");
bundle.putString("msg", errMsg);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else if(result.equals("-1")){
bundle.putString("msg", "抱歉,网络连接失败!");
} else if(result.equals("500")){
bundle.putString("msg", "回复失败,请联系你的管理员!");
}
message2.setData(bundle);
myHander.sendMessage(message2);
Looper.loop();
}
}
/**
* 差旅处理线程
* @author Administrator
*
*/
class TravelThread extends Thread {
private int zt;//1、开始2、结束
public TravelThread(int zt) {
this.zt = zt;
}
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
Looper.prepare();
Message message = new Message();
message.what = 1;
myHander.sendMessage(message);
Message message2 = new Message();
message2.what = 2;
JSONObject object = new JSONObject();
Optsharepre_interface share_obj = new Optsharepre_interface(InfoAndAct.this);
try {
object.put("spid", bundle.getString("spid"));
object.put("zx", zt);
object.put("regguid", share_obj.getDataFromPres("GUID"));
object.put("id", bundle.getString("id"));
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("差旅处理--------------------"+object.toString());
// 请求服务器
String result = new UpdataToServer(InfoAndAct.this).dataToServer("CLZX", object);
if (result != null && !result.equals("-1") && !result.equals("500")) {
try {
JSONObject obj = new JSONObject(result);
String res = obj.getString("result");
if (res.equals("0")) {
bundle.putString("msg", "处理成功");
} else {
String errMsg = obj.getString("detail");
bundle.putString("msg", errMsg);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else if(result.equals("-1")){
bundle.putString("msg", "抱歉,网络连接失败!");
} else if(result.equals("500")){
bundle.putString("msg", "处理失败,请联系你的管理员!");
}
message2.setData(bundle);
myHander.sendMessage(message2);
Looper.loop();
}
}
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);
Bundle data = msg.getData();
String message = data.getString("msg");
showToast(message);
break;
case 4:
proDia=new ProgressDialog(InfoAndAct.this);
proDia.setTitle("下载文件");
proDia.setMessage("下载文件中,请稍候……");
proDia.setProgressStyle(ProgressDialog.STYLE_SPINNER);
proDia.show();
break;
case 5:
proDia.cancel();
Bundle msgdata = msg.getData();
String messagexx = msgdata.getString("msg");
if(b){
Toast.makeText(InfoAndAct.this,messagexx,Toast.LENGTH_SHORT).show();
}
break;
}
}
};
/**
* 警告提示
*/
public void warnTell(String message){
new AlertDialog.Builder(InfoAndAct.this).setTitle("警告").setMessage(message)
.setPositiveButton("确定", null).show();
}
/**
* 结果显示
*
* @param message
*/
public void showToast(final String message) {
new AlertDialog.Builder(InfoAndAct.this).setTitle("提示").setMessage(message)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if(message.contains("成功")){
finish();
}
}
}).show();
}
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
ProgressDialog dialog = new ProgressDialog(InfoAndAct.this);
dialog.setIndeterminate(true);
dialog.setCancelable(false);
switch (id) {
case 1:
dialog.setMessage("正在上传,请稍候……");
break;
}
return dialog;
}
/**
* 检测并启动Gps搜星
*/
public void startGps(){
int gps_flag = new CheckState_interface(InfoAndAct.this).checkGpState();
if(gps_flag == 1){//GPS设备已打开
Intent stateService = new Intent(InfoAndAct.this, GpsService.class);
startService(stateService);
/* jqgjService = new JqgjService();
jqgjService.startGpsRun();*/
}else{//GPS设备未打开
new Toast(InfoAndAct.this).makeText(this, "GPS模块不可用,请打开GPS功能!",
Toast.LENGTH_LONG).show();
}
}
/**
* 检测并关闭Gps设备
*/
public void closeGps(){
SystemInfo sys = new SystemInfo(InfoAndAct.this);
boolean flag = sys.isServiceRunning("com.jqyd.shareInterface.GpsService");
if(flag){
Intent intent = new Intent(InfoAndAct.this, GpsService.class);
stopService(intent);
}
}
}