20150629_Andriod_06_插入_删除_弹出式操作数据

 

Fr_06_view_s6 --> activity_f6_insert
              --> activity_f7__delete

 

************************************************************************

package com.example.ht;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Menu;
import android.view.MenuItem;

 

 


import java.io.IOException;
//////////////////////////
import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.List; 
 

 

 

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import android.app.Activity; 
import android.app.Dialog; 
import android.content.Intent;
//import android.os.Bundle; 
import android.view.Gravity; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.Window; 
import android.view.WindowManager; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.ListView; 
import android.widget.SimpleAdapter; 
import android.widget.Toast;
//////////////////////////

public class Fr_06_view_s6 extends ActionBarActivity {

    ////////////////////////// 
    private Button btn2; 
    private Button btn3; 
    private ListView listView;
    private SimpleAdapter adapter; 
   
    private String str_del;
    private String str_insert1,str_insert2,str_insert5,str_insert6;
    //////////////////////////
   
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_fr_06_view_s6);
  
     //////////////////////////    
     btn2 = (Button) findViewById(R.id.fr_s6_btn2); 
     btn3 = (Button) findViewById(R.id.fr_s6_btn3); 
 
        btn2.setOnClickListener(new OnClickListener() { 
             
            @Override 
            public void onClick(View v) { 
                hideButton(true); 
                setAddDialog(); 
            } 
        }); 
 
        btn3.setOnClickListener(new OnClickListener() { 
             
            @Override 
            public void onClick(View v) { 
                hideButton(true); 
                setDeleteDialog(); 
            } 
        });
       
     /////////////////////////
 }
 
 
 ////////////////
 
 /**
     * 设置弹出删除对话框
     */ 
    private void setDeleteDialog() { 
         
        final Dialog dialog = new Dialog(Fr_06_view_s6.this); 
        //dialog.setContentView(R.layout.dialog_delete);
        dialog.setContentView(R.layout.activity_f7__delete);
        dialog.setTitle("输入想要删除的人员ID"); 
        Window dialogWindow = dialog.getWindow(); 
        WindowManager.LayoutParams lp = dialogWindow.getAttributes(); 
        dialogWindow.setGravity(Gravity.CENTER); 
        dialogWindow.setAttributes(lp); 
 
        //final EditText cNoEditText = (EditText) dialog.findViewById(R.id.editText1); 
        final EditText edit_del = (EditText) dialog.findViewById(R.id.editText_del);
        Button btnConfirm = (Button) dialog.findViewById(R.id.button1); 
        Button btnCancel = (Button) dialog.findViewById(R.id.button2); 
 
        btnConfirm.setOnClickListener(new OnClickListener() { 
 
            @Override 
            public void onClick(View v) { 
                //dbUtil.deleteCargoInfo(cNoEditText.getText().toString()); 
                dialog.dismiss(); 
                hideButton(false);
               
                ////////新线程////////
                str_del = edit_del.getText().toString().trim();
 
                //if ("".equals(str_del) || str_del.length() < 7) { 
                if ("".equals(str_del) || str_del.trim() == "您输入为空")
                { 
                 //edit_del.setText("您输入为空"); 
                    //edit_del.requestFocus(); 
                    //edit_del.setText(""); 
                    Toast.makeText(Fr_06_view_s6.this, "您输入为空", Toast.LENGTH_SHORT).show();
                    return;
                }
                else
                {
           initView();
                }
                //////////////////
               
                //Toast.makeText(MainActivity.this, "成功删除数据", Toast.LENGTH_SHORT).show();
                //Toast.makeText(Fr_06_view_s6.this, "成功删除数据", Toast.LENGTH_SHORT).show();
                //Toast.makeText(Fr_06_view_s6.this, str_del, Toast.LENGTH_SHORT).show();
            } 
        }); 
 
        btnCancel.setOnClickListener(new OnClickListener() { 
 
            @Override 
            public void onClick(View v) { 
                dialog.dismiss(); 
                hideButton(false); 
            } 
        }); 
         
        dialog.show(); 
    }
   
   
    ///////delete ws/////////
    ///////delete ws/////////
    ///////delete ws/////////
   
    private void initView()
    {
       String phone = str_del;
       getRemoteInfo(str_del);
    }

    //
    public void getRemoteInfo(final String phone) { 
    new Thread(new Runnable() { 
       
      @Override 
      public void run() { 
          // TODO Auto-generated method stub 
          // 命名空间 
          String nameSpace = "http://tempuri.org/"; 
          // 调用方法的名称 
          //String methodName = "selectAllCargoInfor"; 
          String methodName = "deleteCargoInfo";
          // EndPoint 
          String endPoint = "http://192.168.1.91:8028/an_sql_test1.asmx"; 
          // SOAP Action 
          // String soapAction = "http://192.168.1.91:8028/an_sql_test1.asmx/selectAllCargoInfor"; 
          String soapAction = "http://192.168.1.91:8028/an_sql_test1.asmx/deleteCargoInfo";
          // 指定WebService的命名空间和调用方法 
          SoapObject soapObject = new SoapObject(nameSpace, methodName); 
          // 设置需要调用WebService接口的两个参数mobileCode UserId 
          //soapObject.addProperty("Ts_01", ""); 
          soapObject.addProperty("Ts_01", str_del);
         
          // 生成调用WebService方法调用的soap信息,并且指定Soap版本 
          SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( 
                  SoapEnvelope.VER12); 
          envelope.bodyOut = soapObject; 
          // 是否调用DotNet开发的WebService 
          envelope.dotNet = true; 
          envelope.setOutputSoapObject(soapObject); 
          HttpTransportSE transport = new HttpTransportSE(endPoint); 
          try { 
              transport.call(soapAction, envelope); 
          } catch (IOException e) {
          //} catch (Exception e) {
              // TODO Auto-generated catch block 
              e.printStackTrace(); 
          }
         
          catch (XmlPullParserException e) { 
              // TODO Auto-generated catch block 
              e.printStackTrace(); 
          } 

         
          // 获取返回的数据 
          SoapObject object = (SoapObject) envelope.bodyIn; 
          // 获取返回的结果 

          String result = object.getProperty(0).toString(); 
          Message message = handler.obtainMessage(); 
          message.obj = result; 
          handler.sendMessage(message);
         
          /////////
      } 
    }).start(); 
    } 

    private Handler handler = new Handler(){ 
    public void handleMessage(android.os.Message msg) { 
      // 将WebService得到的结果返回给TextView
      //tv_result.setText(msg.obj.toString()); 
     
     String str_1;
     str_1 = msg.obj.toString();
     //如果要返回是否成功,应该再添加一组查询, 布尔类型。
     //Toast.makeText(Fr_06_view_s6.this, str_1, Toast.LENGTH_SHORT).show();
     Toast.makeText(Fr_06_view_s6.this, "成功删除数据", Toast.LENGTH_SHORT).show();
     
    }; 
    };

   
    ///////delete ws/////////
    ///////delete ws/////////
    ///////delete ws/////////
   

  
    /**
     * 设置弹出添加对话框
     */ 
    private void setAddDialog() { 
 
        //final Dialog dialog = new Dialog(MainActivity.this);
     final Dialog dialog = new Dialog(Fr_06_view_s6.this);
        //dialog.setContentView(R.layout.dialog_add);
     dialog.setContentView(R.layout.activity_f6_insert);
        dialog.setTitle("输入添加的货物的信息"); 
        Window dialogWindow = dialog.getWindow(); 
        WindowManager.LayoutParams lp = dialogWindow.getAttributes(); 
        dialogWindow.setGravity(Gravity.CENTER); 
        dialogWindow.setAttributes(lp); 
 
        final EditText insert_text1 = (EditText) dialog.findViewById(R.id.editText1); 
        final EditText insert_text2 = (EditText) dialog.findViewById(R.id.editText2);
        final EditText insert_text5 = (EditText) dialog.findViewById(R.id.EditText5); 
        final EditText insert_text6 = (EditText) dialog.findViewById(R.id.EditText6);
        Button btnConfirm = (Button) dialog.findViewById(R.id.button1); 
        Button btnCancel = (Button) dialog.findViewById(R.id.button2); 
 
        btnConfirm.setOnClickListener(new OnClickListener() { 
 
            @Override 
            public void onClick(View v) { 
                 
                //dbUtil.insertCargoInfo(cNameEditText.getText().toString(), cNumEditText.getText().toString()); 
                dialog.dismiss(); 
                hideButton(false);
               
                ////////新线程////////
                str_insert1 = insert_text1.getText().toString().trim();
                str_insert2 = insert_text2.getText().toString().trim();
                str_insert5 = insert_text5.getText().toString().trim();
                str_insert6 = insert_text6.getText().toString().trim();
               
                //if ("".equals(str_del) || str_del.length() < 7) { 
                if ("".equals(str_insert1) || str_insert1.trim() == "您输入为空")
                { 
                 //edit_del.setText("您输入为空"); 
                    //edit_del.requestFocus(); 
                    //edit_del.setText(""); 
                    Toast.makeText(Fr_06_view_s6.this, "您输入为空", Toast.LENGTH_SHORT).show();
                    return;
                }
                else
                {
           insert_into();
                }

                ////////新线程////////
               
                //Toast.makeText(MainActivity.this, "成功添加数据", Toast.LENGTH_SHORT).show(); 
                //Toast.makeText(Fr_06_view_s6.this, "成功添加数据", Toast.LENGTH_SHORT).show(); 
               
               
            } 
        }); 
 
        btnCancel.setOnClickListener(new OnClickListener() { 
 
            @Override 
            public void onClick(View v) { 
                dialog.dismiss(); 
                hideButton(false); 
            } 
        }); 
        dialog.show(); 
    } 
 
    ///////insert_ws/////////
    ///////insert_ws/////////
    ///////insert_ws/////////
   
    private void insert_into()
    {
       insert_into_data();
    }
   
    //
    public void insert_into_data() { 
    new Thread(new Runnable() { 
       
      @Override 
      public void run() { 
          // TODO Auto-generated method stub 
          // 命名空间 
          String nameSpace = "http://tempuri.org/"; 
          // 调用方法的名称 
          //String methodName = "selectAllCargoInfor"; 
          String methodName = "insertCargoInfo";
          // EndPoint 
          String endPoint = "http://192.168.1.91:8028/an_sql_test1.asmx"; 
          // SOAP Action 
          // String soapAction = "http://192.168.1.91:8028/an_sql_test1.asmx/selectAllCargoInfor"; 
          String soapAction = "http://192.168.1.91:8028/an_sql_test1.asmx/insertCargoInfo";
          // 指定WebService的命名空间和调用方法 
          SoapObject soapObject = new SoapObject(nameSpace, methodName); 
          // 设置需要调用WebService接口的两个参数mobileCode UserId 
          //soapObject.addProperty("Ts_01", ""); 
          soapObject.addProperty("Ts_01", str_insert1);
          soapObject.addProperty("Ts_02", str_insert2);
          soapObject.addProperty("Ts_03", str_insert5);
          soapObject.addProperty("Ts_06", str_insert6);
          // 生成调用WebService方法调用的soap信息,并且指定Soap版本 
          SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( 
                  SoapEnvelope.VER12); 
          envelope.bodyOut = soapObject; 
          // 是否调用DotNet开发的WebService 
          envelope.dotNet = true; 
          envelope.setOutputSoapObject(soapObject); 
          HttpTransportSE transport = new HttpTransportSE(endPoint); 
          try { 
              transport.call(soapAction, envelope); 
          } catch (IOException e) {
          //} catch (Exception e) {
              // TODO Auto-generated catch block 
              e.printStackTrace(); 
          }
         
          catch (XmlPullParserException e) { 
              // TODO Auto-generated catch block 
              e.printStackTrace(); 
          } 


          // 获取返回的数据 
          SoapObject object = (SoapObject) envelope.bodyIn; 
          // 获取返回的结果 

          String result = object.getProperty(0).toString(); 
          Message message = handler2.obtainMessage(); 
          message.obj = result; 
          handler2.sendMessage(message);
         
          /////////
      } 
    }).start(); 
    } 

    private Handler handler2 = new Handler(){ 
    public void handleMessage(android.os.Message msg) { 
      // 将WebService得到的结果返回给TextView
      //tv_result.setText(msg.obj.toString()); 
     
     String str_1;
     str_1 = msg.obj.toString();
     //如果要返回是否成功,应该再添加一组查询, 布尔类型。
     //Toast.makeText(Fr_06_view_s6.this, str_1, Toast.LENGTH_SHORT).show();
     Toast.makeText(Fr_06_view_s6.this, str_1.toString().trim(), Toast.LENGTH_SHORT).show();
     
    }; 
    };
   
    ///////insert_ws/////////
    ///////insert_ws/////////
    ///////insert_ws/////////
   
   
    /**
     * 设置button的可见性
     */ 
    private void hideButton(boolean result) { 
        if (result) { 
            btn2.setVisibility(View.GONE); 
            btn3.setVisibility(View.GONE); 
        } else {   
            btn2.setVisibility(View.VISIBLE); 
            btn3.setVisibility(View.VISIBLE); 
        } 
 
    } 
 
   
    /**
     * 返回按钮的重写
     */ 
    @Override 
    public void onBackPressed() 
    { 
        if (listView.getVisibility() == View.VISIBLE) { 
            listView.setVisibility(View.GONE); 
            hideButton(false); 
        }else { 
            //MainActivity.this.finish();
         Fr_06_view_s6.this.finish();
        } 
    } 
 
 /////////////

 
 

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.fr_06_view_s6, menu);
  return true;
 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  // Handle action bar item clicks here. The action bar will
  // automatically handle clicks on the Home/Up button, so long
  // as you specify a parent activity in AndroidManifest.xml.
  int id = item.getItemId();
  if (id == R.id.action_settings) {
   return true;
  }
  return super.onOptionsItemSelected(item);
 }
}

 


************************************************************************
************************************************************************


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.ht.Fr_06_view_s6" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/Fr_Form_06" />

    <Button
        android:id="@+id/fr_s6_btn2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="133dp"
        android:text="@string/btn2" />

    <Button
        android:id="@+id/fr_s6_btn3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/fr_s6_btn2"
        android:layout_centerHorizontal="true"
        android:text="@string/btn3" />

</RelativeLayout>

************************************************************************
************************************************************************

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.ht.F7_Delete" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/F7_Form" />

    <EditText
        android:id="@+id/editText_del"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/linearLayout1"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="66dp"
        android:ems="10"
        android:hint="@string/delete_hint" />

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="47dp"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button1"
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:text="@string/confirm" />

        <Button
            android:id="@+id/button2"
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:layout_marginLeft="40dip"
            android:text="@string/cancel" />
    </LinearLayout>

</RelativeLayout>

 

************************************************************************
************************************************************************

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.ht.F6_insert" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/F6_Form" />

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText2"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="54dp"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button1"
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:text="@string/confirm" />

        <Button
            android:id="@+id/button2"
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:layout_marginLeft="40dip"
            android:text="@string/cancel" />
    </LinearLayout>

    <EditText
        android:id="@+id/editText1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText2"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="30dp"
        android:ems="10"
        android:hint="@string/add_hint1" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/EditText5"
        android:layout_below="@+id/editText1"
        android:ems="10"
        android:hint="@string/add_hint2"
        android:inputType="number" />

    <EditText
        android:id="@+id/EditText5"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/EditText6"
        android:layout_below="@+id/editText2"
        android:ems="10"
        android:hint="@string/add_hint5" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/EditText6"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/EditText5"
        android:ems="10"
        android:hint="@string/add_hint6"
        android:inputType="number" />

</RelativeLayout>

 


************************************************************************
************************************************************************

 

你可能感兴趣的:(andriod)