package com.example.gzznproject;
import java.util.ArrayList;
import java.util.HashMap;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnCreateContextMenuListener;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;public classLogListActivity extends Activity {
SimpleAdapter adapter;
SqliteDBHelper helper;publicListView listview;public HashMaphashmap;public static ArrayList>arrayList;public static intenegerid;public static intflagid;public static intuserid;
@Overrideprotected voidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loglist);
_getdataview();
listview.setOnCreateContextMenuListener(listener);
}//listview数据绑定
public void_getdataview() {
listview=(ListView) findViewById(R.id.listView);
adapter= new SimpleAdapter(LogListActivity.this, getdata(),
R.layout.item,new String[] { "ConstrName", "WorkTime"},new int[] { R.id.txt_ConstrName, R.id.txt_WorkTime });
listview.setAdapter(adapter);
}//长按菜单
OnCreateContextMenuListener listener = newOnCreateContextMenuListener() {
@Overridepublic voidonCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
menu.setHeaderTitle("操作提示");
menu.add(0, 2, 0, "文件上传");
menu.add(0, 0, 0, "编辑");
menu.add(0, 1, 0, "删除");
}
};
@Overridepublicboolean onContextItemSelected(MenuItem item) {
final AdapterContextMenuInfo info=(AdapterContextMenuInfo) item
.getMenuInfo();
hashmap= arrayList.get((int) info.id);
Object obj= hashmap.get("ID");int id =Integer.parseInt(String.valueOf(obj));if (item.getItemId() == 1) {if (id == -1) {
Toast.makeText(getApplicationContext(),"没有选中数据!",
Toast.LENGTH_SHORT).show();
}else{
helper.Delete(id);
_getdataview();
Toast.makeText(getApplicationContext(),"数据删除成功!",
Toast.LENGTH_SHORT).show();
}
}else if (item.getItemId() == 0) {if (id == -1) {
Toast.makeText(getApplicationContext(),"没有选中数据!",
Toast.LENGTH_SHORT).show();
}else{
LogManagerActivity.hashmap=hashmap;
Intent intent= newIntent();
intent.setClass(LogListActivity.this, LogManagerActivity.class);
startActivity(intent);
}
}else if (item.getItemId() == 2) {
String url= "http://117.34.91.186:8347/WebServices/InsertLog.asmx";
String nameSpace= "http://tempuri.org/";
String SOAP_ACTION= "http://tempuri.org/InserttionLog";
String method= "InserttionLog";
SoapObject request= newSoapObject(nameSpace, method);
request.addProperty("Id", userid);
request.addProperty("ConstrName", hashmap.get("ConstrName")
.toString()== null ? "" : hashmap.get("ConstrName")
.toString());
request.addProperty("Enginer",
hashmap.get("Enginer").toString() == null ? "": hashmap
.get("Enginer").toString());
request.addProperty("DepartID",
hashmap.get("ID").toString() == null ? "" : hashmap.get("ID").toString());
request.addProperty("EngineName", hashmap.get("EnginerName")
.toString()== null ? "" : hashmap.get("EnginerName")
.toString());
request.addProperty("EnginerAddress", hashmap.get("EnginerAddress")
.toString()== null ? "" : hashmap.get("EnginerAddress")
.toString());
request.addProperty("WorkContent", hashmap.get("WorkContent")
.toString()== null ? "" : hashmap.get("WorkContent")
.toString());
request.addProperty("WorkRemark", hashmap.get("WorkRemark")
.toString()== null ? "" : hashmap.get("WorkRemark")
.toString());
request.addProperty("TodayPlan", hashmap.get("TodayPlan")
.toString()== null ? "" : hashmap.get("TodayPlan")
.toString());
request.addProperty("TorrowPlan", hashmap.get("TorrowPlan")
.toString()== null ? "" : hashmap.get("TorrowPlan")
.toString());
request.addProperty("Remark",
hashmap.get("Remark").toString() == null ? "": hashmap
.get("Remark").toString());
request.addProperty("WorkTime",
hashmap.get("WorkTime").toString() == null ? "": hashmap
.get("WorkTime").toString());
SoapSerializationEnvelope envelope= newSoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.bodyOut=request;
envelope.dotNet= true;
AndroidHttpTransport transport= newAndroidHttpTransport(url);try{if(isOpenNetwork()) {
transport.call(SOAP_ACTION, envelope);if (envelope.getResponse() != null) {
Objectobject =envelope.getResponse();
boolean result=Boolean
.parseBoolean(object.toString());if (result == true) {
Toast.makeText(getApplicationContext(),"上传成功!",
Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(),"上传失败!",
Toast.LENGTH_SHORT).show();
}
}
}else{
Toast.makeText(getApplicationContext(),"当前网络不可用不能上传文件!",
Toast.LENGTH_SHORT).show();
}
}catch(Exception e) {
e.printStackTrace();
}
}else{return false;
}returnsuper.onContextItemSelected(item);
}//绑定listview的数据源
public ArrayList>getdata() {
helper= new SqliteDBHelper(this);
SQLiteDatabase mdb=helper.getReadableDatabase();
Cursor c= mdb.rawQuery("select * from myLog", null);
arrayList= new ArrayList>();while(c.moveToNext()) {
hashmap= new HashMap();
hashmap.put("ID", c.getString(0));
hashmap.put("ConstrName", c.getString(1));
hashmap.put("Enginer", c.getString(2));
hashmap.put("DepartID", c.getString(3));
hashmap.put("EnginerName", c.getString(4));
hashmap.put("EnginerAddress", c.getString(5));
hashmap.put("WorkContent", c.getString(6));
hashmap.put("WorkRemark", c.getString(7));
hashmap.put("TodayPlan", c.getString(8));
hashmap.put("TorrowPlan", c.getString(9));
hashmap.put("Remark", c.getString(10));
hashmap.put("WorkTime", c.getString(11));
hashmap.put("DeletionStateCode", c.getString(12));
hashmap.put("Enabled", c.getString(13));
hashmap.put("SortCode", c.getString(14));
hashmap.put("Description", c.getString(15));
hashmap.put("CreateOn", c.getString(16));
hashmap.put("CreateUserId", c.getString(17));
hashmap.put("CreateBy", c.getString(18));
hashmap.put("ModifiedOn", c.getString(19));
hashmap.put("ModifiedUserId", c.getString(20));
hashmap.put("ModifiedBy", c.getString(21));
hashmap.put("Crsign", c.getString(22));
hashmap.put("Telphone", c.getString(23));
hashmap.put("Departname", c.getString(24));
hashmap.put("Itemid", c.getString(25));
hashmap.put("Itemname", c.getString(26));
arrayList.add(hashmap);
}returnarrayList;
}
@Overridepublicboolean onCreateOptionsMenu(Menu menu) {//getMenuInflater().inflate(R.menu.main, menu);
menu.add(0, 1, 1, "添加数据");
menu.add(0, 2, 1, "树形结构");return true;
}
@Overridepublicboolean onOptionsItemSelected(MenuItem item) {if (item.getItemId() == 1) {
Intent itent= newIntent();
itent.setClass(LogListActivity.this, LogManagerActivity.class);
startActivity(itent);
}else{
Intent itent= newIntent();
itent.setClass(LogListActivity.this, TreeStructure.class);
startActivity(itent);
}return false;
}//监听网络状态
privateboolean isOpenNetwork() {
ConnectivityManager connManager=(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);if (connManager.getActiveNetworkInfo() != null) {returnconnManager.getActiveNetworkInfo().isAvailable();
}return false;
}
}