跟SAP系统集成的Android应用

首先吐槽一点,这是我的第一个Android应用,很糙。

这个应用适合于上了SAP系统的企业内部使用,并且限于制造型MTO模式,需要针对生产订单报工操作的场景,因为此应用主要的一个目的,就是用来方便报工操作的。

为此,先上一幅程序目录结构全图:

下面将按源文件、资源文件、程序目录清单文件依次介绍:

源文件分为三个包:SAP业务逻辑操作包、对象实体包、工具包(包含访问SAP连接)

SAP业务逻辑操作包: com.fungchoi.sap

对象实体包: com.fungchoi.sap.entity

工具包: com.fungchoi.sap.util

 

SAP业务逻辑操作包按照业务逻辑顺序一共包含有8个程序文件,分别介绍如下:

应用登录:LoginActivity.java:

/**
 * 用户登录类
 */
package com.fungchoi.sap;

import java.lang.Thread.State;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.message.BasicNameValuePair;

import com.fungchoi.sap.entity.PassParameter;
import com.fungchoi.sap.util.Helper;
import com.fungchoi.sap.util.MyApplication;

import android.app.Activity;
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.Button;
import android.widget.EditText;

/**
 * @author Administrator
 * 
 */
public class LoginActivity extends Activity {

	private Activity activity;

	private EditText txtUserName;
	private EditText txtPassword;
	private Button btnLogin;

	private ProgressDialog pd;

	private PassParameter pp;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);

		// 当前活动
		activity = this;
		// 传递参数
		pp = new PassParameter();
		// 设置用户手机号码
		pp.setLTXA1(Helper.getPhoneNumber(activity));

		// 界面控件
		txtUserName = (EditText) this.findViewById(R.id.txtUserName);
		txtPassword = (EditText) this.findViewById(R.id.txtPassword);
		btnLogin = (Button) this.findViewById(R.id.btnLogin);

		// 判断网络连接
		if (!Helper.checkNet(this)) {
			Helper.message(this, "没有可用的3G或Wifi网络!");
			Helper.disenableButton(btnLogin);
			return;
		}

		// 将当前活动压入活动堆栈
		MyApplication.getInstance().addActivity(this);

		// 登录按钮注册事件
		btnLogin.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// 设置用户帐号和密码
				pp.setUserName(txtUserName.getText().toString().trim());
				pp.setPassword(txtPassword.getText().toString().trim());

				// 设置正在处理窗口
				pd = ProgressDialog.show(activity, "提示", "正在登录,请稍候...");

				// 启动线程
				if (thread.getState() == State.NEW) {
					thread.start();
				} else {
					thread.run();
				}
			}
		});
	}

	// 工作线程
	private Thread thread = new Thread() {
		@Override
		public void run() {
			// 从SAP系统获取数据
			String result = getJSONString(pp);

			Message message = handler.obtainMessage();
			Bundle b = new Bundle();
			b.putString("flag", result);
			message.setData(b);
			handler.sendMessage(message);
		}
	};

	// 更新UI
	private Handler handler = new Handler() {
		public void handleMessage(Message msg) {
			pd.dismiss();
			if ("success".equals(msg.getData().getString("flag"))) {
				Helper.enableButton(btnLogin);
				// thread.stop();
				// 成功登录,则跳转至开始报工界面
				dispatch(pp);
			} else {
				Helper.message(activity, "帐号或者密码错误!\n登录失败 !");
				thread.stop();
			}
		}
	};

	// 从SAP服务器获取内容(JSON字符串)
	private String getJSONString(PassParameter pp) {
		String url = Helper.getUrl("service0000");
		List<BasicNameValuePair> pairs = new ArrayList<BasicNameValuePair>();
		pairs.add(new BasicNameValuePair("UserName", pp.getUserName()));
		pairs.add(new BasicNameValuePair("Password", pp.getPassword()));
		return Helper.callSAPService(pp, url, pairs);
	}

	// 跳转到下一个Activity
	private void dispatch(PassParameter pp) {
		Intent intent = new Intent(this, MainActivity.class);
		Bundle bundle = new Bundle();
		bundle.putSerializable(PassParameter.PP_KEY, pp);
		intent.putExtras(bundle);

		startActivity(intent);
	}
}

应用主界面(生产订单查询界面): MainActivity.java

package com.fungchoi.sap;

import java.util.Calendar;
import java.util.Locale;

import com.fungchoi.sap.entity.PassParameter;
import com.fungchoi.sap.util.Helper;
import com.fungchoi.sap.util.MyApplication;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;

public class MainActivity extends Activity {
	private Activity activity;

	private EditText tempDate;
	private EditText txtBeginDate;
	private EditText txtEndDate;
	private EditText txtOrderCode;
	private EditText txtMaterialDesc;

	private int mYear;
	private int mMonth;
	private int mDay;

	private PassParameter pp;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		// 判断手机电量
		Helper.checkBattery(this);

		// 将当前活动压入活动堆栈
		MyApplication.getInstance().addActivity(this);

		// 当前活动
		activity = this;

		// 从意图里面接收上一个Activity传过来的数据
		Intent intent = this.getIntent();
		pp = (PassParameter) intent.getSerializableExtra(PassParameter.PP_KEY);

		// 获取当前日期实例
		final Calendar c = Calendar.getInstance(Locale.CHINA);
		mYear = c.get(Calendar.YEAR);
		mMonth = c.get(Calendar.MONTH);
		mDay = c.get(Calendar.DAY_OF_MONTH);

		// 界面控件
		txtBeginDate = (EditText) this.findViewById(R.id.txtBeginDate);
		txtEndDate = (EditText) this.findViewById(R.id.txtEndDate);
		// 设置默认日期
		Helper.updateDate(txtEndDate, mYear, mMonth, mDay);
		setBeginDate(c, -2);
		// 注册日期控件监听事件
		registerEvents();

		// 界面控件
		txtOrderCode = (EditText) this.findViewById(R.id.txtOrderCode);
		txtMaterialDesc = (EditText) this.findViewById(R.id.txtMatnr);

		// 按下返回键返回到上一个界面
		Button previous = (Button) this.findViewById(R.id.btnPrevious00);
		previous.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Helper.simulateKey(KeyEvent.KEYCODE_BACK);
			}
		});
		// 开始报工按钮,并注册监听事件
		Button btnStart = (Button) this.findViewById(R.id.btnStart);
		btnStart.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				pp.setBeginDate(txtBeginDate.getText().toString()
						.replaceAll("-", ""));
				pp.setEndDate(txtEndDate.getText().toString()
						.replaceAll("-", ""));
				pp.setOrderCode(txtOrderCode.getText().toString().trim());
				pp.setMaterialDesc(txtMaterialDesc.getText().toString().trim());
				dispatch(pp);
			}
		});
	}

	// 日期控件
	private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
		public void onDateSet(DatePicker view, int year, int monthOfYear,
				int dayOfMonth) {
			mYear = year;
			mMonth = monthOfYear;
			mDay = dayOfMonth;

			Helper.updateDate(tempDate, mYear, mMonth, mDay);
		}
	};

	// 显示日期控件
	private void showDialog() {
		DatePickerDialog dialog = new DatePickerDialog(this, mDateSetListener,
				mYear, mMonth, mDay);

		dialog.show();
	}

	// 注册事件
	private void registerEvents() {
		txtBeginDate.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Helper.hideIM(activity, v);
				tempDate = txtBeginDate;
				showDialog();
			}
		});
		txtEndDate.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Helper.hideIM(activity, v);
				tempDate = txtEndDate;
				showDialog();
			}
		});
		txtBeginDate.setOnFocusChangeListener(new OnFocusChangeListener() {
			public void onFocusChange(View v, boolean hasFocus) {
				if (hasFocus == true) {
					Helper.hideIM(activity, v);
					tempDate = txtBeginDate;
					showDialog();
				}
			}
		});
		txtEndDate.setOnFocusChangeListener(new OnFocusChangeListener() {
			public void onFocusChange(View v, boolean hasFocus) {
				if (hasFocus == true) {
					Helper.hideIM(activity, v);
					tempDate = txtEndDate;
					showDialog();
				}
			}
		});
	}

	// 跳转到下一个Activity
	private void dispatch(PassParameter pp) {
		Intent intent = new Intent(this, OrderListActivity.class);
		Bundle bundle = new Bundle();
		bundle.putSerializable(PassParameter.PP_KEY, pp);
		intent.putExtras(bundle);

		startActivity(intent);
	}

	// 设置开始日期
	private void setBeginDate(Calendar c, int val) {
		c.add(Calendar.DATE, val);
		int year = c.get(Calendar.YEAR);
		int month = c.get(Calendar.MONTH);
		int day = c.get(Calendar.DAY_OF_MONTH);
		txtBeginDate.setText(new StringBuilder().append(year).append("-")
				.append((month + 1) < 10 ? "0" + (month + 1) : (month + 1))
				.append("-").append((day < 10) ? "0" + day : day));
	}

}

生产订单列表选择界面: OrderListActivity.java

/**
 * 生产订单列表选择类
 */
package com.fungchoi.sap;

import java.lang.Thread.State;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import org.apache.http.message.BasicNameValuePair;

import com.fungchoi.sap.entity.Order;
import com.fungchoi.sap.entity.PassParameter;
import com.fungchoi.sap.util.Helper;
import com.fungchoi.sap.util.MyApplication;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.HorizontalScrollView;
import android.widget.RadioButton;
import android.widget.ScrollView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

/**
 * @author Administrator
 * 
 */
public class OrderListActivity extends Activity {
	private final int FP = ViewGroup.LayoutParams.FILL_PARENT;
	private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;

	private Activity activity;

	private ScrollView sv;
	private HorizontalScrollView hsv;
	private TableLayout tab;

	private PassParameter pp;
	private LinkedList<Order> orders;

	private ProgressDialog pd;
	private Button previous;
	private Button next;

	/**
	 * 
	 */
	public OrderListActivity() {
		// TODO Auto-generated constructor stub
	}

	// @SuppressWarnings("static-access")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.orderlist);

		// 当前活动
		activity = this;

		// 将当前活动压入活动堆栈
		MyApplication.getInstance().addActivity(this);

		// 获取界面控件对象
		sv = (ScrollView) this.findViewById(R.id.scrollView1);
		sv.setHorizontalScrollBarEnabled(true);
		hsv = (HorizontalScrollView) this
				.findViewById(R.id.horizontalScrollView1);
		tab = (TableLayout) hsv.getChildAt(0);

		// 按下返回键返回到上一个界面
		previous = (Button) this.findViewById(R.id.btnPrevious01);
		previous.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Helper.simulateKey(KeyEvent.KEYCODE_BACK);
			}
		});
		// 按下一步跳转到工序选择界面
		next = (Button) this.findViewById(R.id.btnNext01);
		next.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// 跳转到下一步之前判断是否选择了生产订单
				if (!Helper.checkRadioButton(tab)) {
					Helper.message(activity, "请选择一笔生产订单!");
					return;
				}
				dispatch(pp);
			}
		});

		// 从意图里面接收上一个Activity传过来的数据
		Intent intent = this.getIntent();
		pp = (PassParameter) intent.getSerializableExtra(PassParameter.PP_KEY);

		// 设置正在处理窗口
		pd = ProgressDialog.show(this, "提示", "正在处理,请稍候...");

		// 启动线程
		if (thread.getState() == State.NEW) {
			thread.start();
		} else {
			thread.run();
		}
	}

	// 工作线程
	private Thread thread = new Thread() {
		@Override
		public void run() {
			// 从SAP系统获取数据
			String result = getJSONString(pp);
			orders = parseFromJson(result);

			Message message = handler.obtainMessage();
			Bundle b = new Bundle();
			b.putString("flag", "ok");
			message.setData(b);
			handler.sendMessage(message);
		}
	};

	// 更新UI
	private Handler handler = new Handler() {
		public void handleMessage(Message msg) {
			Helper.enableButton(next);
			if ("ok".equals(msg.getData().getString("flag"))) {
				// 动态添加数据记录
				addRows(orders);
				pd.dismiss();
				thread.stop();
			}
		}
	};

	// 从SAP服务器获取内容(JSON字符串)
	private String getJSONString(PassParameter pp) {
		String url = Helper.getUrl("service0001");
		List<BasicNameValuePair> pairs = new ArrayList<BasicNameValuePair>();
		pairs.add(new BasicNameValuePair("BeginDate", pp.getBeginDate()));
		pairs.add(new BasicNameValuePair("EndDate", pp.getEndDate()));
		pairs.add(new BasicNameValuePair("OrderCode", pp.getOrderCode()));
		pairs.add(new BasicNameValuePair("MaterialDesc", pp.getMaterialDesc()));
		return Helper.callSAPService(pp, url, pairs);
	}

	// 根据JSON字符串解析成订单实体对象列表
	private LinkedList<Order> parseFromJson(String jsonData) {
		if (jsonData == null)
			return null;
		if ("".equals(jsonData))
			return null;
		Type listType = new TypeToken<LinkedList<Order>>() {
		}.getType();
		Gson gson = new Gson();
		LinkedList<Order> entitys = gson.fromJson(jsonData, listType);
		return entitys;
	}

	// 根据读取的记录动态添加列表行
	private Boolean addRows(LinkedList<Order> orders) {
		if (orders == null) {
			Helper.disenableButton(next);
			return false;
		}
		if (orders.isEmpty()) {
			Helper.disenableButton(next);
			return false;
		}

		TableRow row;
		TextView view;
		RadioButton radio;

		for (Order order : orders) {
			row = new TableRow(this);

			radio = new RadioButton(this);
			radio.setOnClickListener(new View.OnClickListener() {
				public void onClick(View v) {
					changedRadio((RadioButton) v);
				}
			});
			row.addView(radio);

			view = new TextView(this);
			view.setText(order.getAUFNR());
			row.addView(view);

			view = new TextView(this);
			view.setText(order.getMAKTX());
			row.addView(view);

			view = new TextView(this);
			view.setText(String.valueOf(order.getGAMNG()));
			row.addView(view);

			view = new TextView(this);
			view.setText(order.getMSEHT());
			row.addView(view);

			tab.addView(row, new TableLayout.LayoutParams(FP, WC));
		}
		return true;
	}

	// 当更改单选按钮时,获它所在行的订单编号及将其他的单选按钮置为未选中状态
	private void changedRadio(RadioButton rb) {
		int count = tab.getChildCount();
		TableRow row;
		RadioButton radio;
		for (int i = 1; i < count; i++) {
			row = (TableRow) tab.getChildAt(i);
			radio = (RadioButton) row.getChildAt(0);
			if (rb.equals(radio)) {
				pp.setAUFNR(((TextView) row.getChildAt(1)).getText().toString());
			} else {
				if (radio.isChecked()) {
					radio.setChecked(false);
				}
			}
		}
	}

	// 跳转到下一个Activity
	private void dispatch(PassParameter pp) {
		Intent intent = new Intent(this, StepListActivity.class);
		Bundle bundle = new Bundle();
		bundle.putSerializable(PassParameter.PP_KEY, pp);
		intent.putExtras(bundle);

		startActivity(intent);
	}

}

工序列表选择界面:StepListActivity.java :

/**
 * 
 */
package com.fungchoi.sap;

import java.lang.Thread.State;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import org.apache.http.message.BasicNameValuePair;

import com.fungchoi.sap.entity.PassParameter;
import com.fungchoi.sap.entity.Step;
import com.fungchoi.sap.util.Helper;
import com.fungchoi.sap.util.MyApplication;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.InputType;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.HorizontalScrollView;
import android.widget.RadioButton;
import android.widget.ScrollView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

/**
 * @author Administrator
 * 
 */
public class StepListActivity extends Activity {
	private final int FP = ViewGroup.LayoutParams.FILL_PARENT;
	private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;

	private Activity activity;

	private ScrollView sv;
	private HorizontalScrollView hsv;
	private TableLayout tab;

	private PassParameter pp;
	private LinkedList<Step> steps;

	private ProgressDialog pd;
	private Button previous;
	private Button next;

	/**
	 * 
	 */
	public StepListActivity() {
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.steplist);

		// 当前活动
		activity = this;

		// 将当前活动压入活动堆栈
		MyApplication.getInstance().addActivity(this);

		// 获取界面控件对象
		sv = (ScrollView) this.findViewById(R.id.scrollView2);
		sv.setHorizontalScrollBarEnabled(true);
		hsv = (HorizontalScrollView) this
				.findViewById(R.id.horizontalScrollView2);
		tab = (TableLayout) hsv.getChildAt(0);

		// 按下返回键返回到上一个界面
		previous = (Button) this.findViewById(R.id.btnPrevious02);
		previous.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Helper.simulateKey(KeyEvent.KEYCODE_BACK);
			}
		});
		// 按下一步跳转到工序选择界面
		next = (Button) this.findViewById(R.id.btnNext02);
		next.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// 跳转到下一步之前判断是否选择了工序
				if (!Helper.checkRadioButton(tab)) {
					Helper.message(activity, "请选择一道工序!");
					return;
				}
				dispatch(pp);
			}
		});

		// 从意图里面接收上一个Activity传过来的数据
		Intent intent = this.getIntent();
		pp = (PassParameter) intent.getSerializableExtra(PassParameter.PP_KEY);

		// 设置正在处理窗口
		pd = ProgressDialog.show(this, "提示", "正在处理,请稍候...");

		// 启动线程
		if (thread.getState() == State.NEW) {
			thread.start();
		} else {
			thread.run();
		}
	}

	// 工作线程
	private Thread thread = new Thread() {
		@Override
		public void run() {
			// 从SAP系统获取数据
			String result = getJSONString(pp);
			steps = parseFromJson(result);

			Message message = handler.obtainMessage();
			Bundle b = new Bundle();
			b.putString("flag", "ok");
			message.setData(b);
			handler.sendMessage(message);
		}
	};

	// 更新UI
	private Handler handler = new Handler() {
		public void handleMessage(Message msg) {
			Helper.enableButton(next);
			if ("ok".equals(msg.getData().getString("flag"))) {
				// 动态添加数据记录
				addRows();
				pd.dismiss();
				thread.stop();
			}
		}
	};

	// 从SAP服务器获取内容(JSON字符串)
	private String getJSONString(PassParameter pp) {
		String url = Helper.getUrl("service0002");
		List<BasicNameValuePair> pairs = new ArrayList<BasicNameValuePair>();
		pairs.add(new BasicNameValuePair("OrderCode", pp.getAUFNR()));
		return Helper.callSAPService(pp, url, pairs);
	}

	// 根据JSON字符串解析成订单实体对象列表
	private LinkedList<Step> parseFromJson(String jsonData) {
		if (jsonData == null)
			return null;
		if ("".equals(jsonData))
			return null;
		Type listType = new TypeToken<LinkedList<Step>>() {
		}.getType();
		Gson gson = new Gson();
		LinkedList<Step> entitys = gson.fromJson(jsonData, listType);
		return entitys;
	}

	// 根据读取的记录动态添加列表行
	private Boolean addRows() {
		if (steps == null) {
			Helper.disenableButton(next);
			return false;
		}
		if (steps.isEmpty()) {
			Helper.disenableButton(next);
			return false;
		}

		TableRow row;
		TextView view;
		EditText edit;
		RadioButton radio;

		for (Step step : steps) {
			row = new TableRow(this);

			radio = new RadioButton(this);
			radio.setOnClickListener(new View.OnClickListener() {
				public void onClick(View v) {
					changedRadio((RadioButton) v);
				}
			});
			row.addView(radio);

			view = new TextView(this);
			view.setText(step.getVORNR());
			row.addView(view);

			view = new TextView(this);
			view.setText(step.getLTXA1());
			row.addView(view);

			edit = new EditText(this);
			edit.setInputType(InputType.TYPE_CLASS_NUMBER);
			edit.setText(String.valueOf(step.getMGVRG()));
			row.addView(edit);

			view = new TextView(this);
			view.setText(step.getMSEHT());
			row.addView(view);

			view = new TextView(this);
			view.setVisibility(View.INVISIBLE);
			view.setText(step.getMEINH());
			row.addView(view);

			tab.addView(row, new TableLayout.LayoutParams(FP, WC));
		}
		return true;
	}

	// 当更改单选按钮时,获它所在行的订单编号及将其他的单选按钮置为未选中状态
	private void changedRadio(RadioButton rb) {
		int count = tab.getChildCount();
		TableRow row;
		RadioButton radio;
		for (int i = 1; i < count; i++) {
			row = (TableRow) tab.getChildAt(i);
			radio = (RadioButton) row.getChildAt(0);
			if (rb.equals(radio)) {
				pp.setVORNR(((TextView) row.getChildAt(1)).getText().toString());
				pp.setLMNGA(Float.parseFloat(((TextView) row.getChildAt(3))
						.getText().toString().trim()));
				pp.setMEINH(((TextView) row.getChildAt(5)).getText().toString());
			} else {
				if (radio.isChecked()) {
					radio.setChecked(false);
				}
			}
		}
	}

	// 重新设置传递参数中的(选中工序的)工序数量
	private void resetLMNGA() {
		int count = tab.getChildCount();
		TableRow row;
		RadioButton radio;
		for (int i = 1; i < count; i++) {
			row = (TableRow) tab.getChildAt(i);
			radio = (RadioButton) row.getChildAt(0);
			if (radio.isChecked()) {
				pp.setLMNGA(Float.parseFloat(((TextView) row.getChildAt(3))
						.getText().toString().trim()));
				break;
			}
		}
	}

	// 跳转到下一个Activity
	private void dispatch(PassParameter pp) {
		resetLMNGA();

		Intent intent = new Intent(this, ZuoYeActivity.class);
		Bundle bundle = new Bundle();
		bundle.putSerializable(PassParameter.PP_KEY, pp);
		intent.putExtras(bundle);

		startActivity(intent);
	}

}

作业输入界面:ZuoYeActivity.java:

/**
 * 
 */
package com.fungchoi.sap;

import java.lang.Thread.State;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import org.apache.http.message.BasicNameValuePair;

import com.fungchoi.sap.entity.PassParameter;
import com.fungchoi.sap.entity.ZuoYe;
import com.fungchoi.sap.util.Helper;
import com.fungchoi.sap.util.MyApplication;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

/**
 * @author Administrator
 * 
 */
public class ZuoYeActivity extends Activity {

	private PassParameter pp;
	private LinkedList<ZuoYe> zuoyes;

	private ProgressDialog pd;
	private Button previous;
	private Button next;

	private EditText vgw01;
	private EditText vgw02;
	private EditText vgw03;
	private EditText vgw04;
	private EditText vgw05;
	private EditText vgw06;
	private EditText vge01;
	private EditText vge02;
	private EditText vge03;
	private EditText vge04;
	private EditText vge05;
	private EditText vge06;

	/**
	 * 
	 */
	public ZuoYeActivity() {
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.zuoye);

		MyApplication.getInstance().addActivity(this);

		vgw01 = (EditText) this.findViewById(R.id.txtVgw01);
		vgw02 = (EditText) this.findViewById(R.id.txtVgw02);
		vgw03 = (EditText) this.findViewById(R.id.txtVgw03);
		vgw04 = (EditText) this.findViewById(R.id.txtVgw04);
		vgw05 = (EditText) this.findViewById(R.id.txtVgw05);
		vgw06 = (EditText) this.findViewById(R.id.txtVgw06);
		vge01 = (EditText) this.findViewById(R.id.txtVge01);
		vge02 = (EditText) this.findViewById(R.id.txtVge02);
		vge03 = (EditText) this.findViewById(R.id.txtVge03);
		vge04 = (EditText) this.findViewById(R.id.txtVge04);
		vge05 = (EditText) this.findViewById(R.id.txtVge05);
		vge06 = (EditText) this.findViewById(R.id.txtVge06);

		// 按下返回键返回到上一个界面
		previous = (Button) this.findViewById(R.id.btnPrevious03);
		previous.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Helper.simulateKey(KeyEvent.KEYCODE_BACK);
			}
		});
		// 按下一步跳转到工序选择界面
		next = (Button) this.findViewById(R.id.btnNext03);
		next.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				dispatch(pp);
			}
		});

		// 从意图里面接收上一个Activity传过来的数据
		Intent intent = this.getIntent();
		pp = (PassParameter) intent.getSerializableExtra(PassParameter.PP_KEY);

		// 设置正在处理窗口
		pd = ProgressDialog.show(this, "提示", "正在处理,请稍候...");

		// 启动线程
		if (thread.getState() == State.NEW) {
			thread.start();
		} else {
			thread.run();
		}
	}

	// 工作线程
	private Thread thread = new Thread() {
		@Override
		public void run() {
			// 从SAP系统获取数据
			String result = getJSONString(pp);
			zuoyes = parseFromJson(result);

			Message message = handler.obtainMessage();
			Bundle b = new Bundle();
			b.putString("flag", "ok");
			message.setData(b);
			handler.sendMessage(message);
		}
	};

	// 更新UI
	private Handler handler = new Handler() {
		public void handleMessage(Message msg) {
			if ("ok".equals(msg.getData().getString("flag"))) {
				// 设置默认值
				setDefaultValue();
				pd.dismiss();
				thread.stop();
			}
		}
	};

	// 从SAP服务器获取内容(JSON字符串)
	private String getJSONString(PassParameter pp) {
		String url = Helper.getUrl("service0003");
		List<BasicNameValuePair> pairs = new ArrayList<BasicNameValuePair>();
		pairs.add(new BasicNameValuePair("OrderCode", pp.getAUFNR()));
		pairs.add(new BasicNameValuePair("StepCode", pp.getVORNR()));
		pairs.add(new BasicNameValuePair("Quantity", String.valueOf(pp
				.getLMNGA())));
		return Helper.callSAPService(pp, url, pairs);
	}

	// 根据JSON字符串解析成订单实体对象列表
	private LinkedList<ZuoYe> parseFromJson(String jsonData) {
		if (jsonData == null)
			return null;
		if ("".equals(jsonData))
			return null;
		Type listType = new TypeToken<LinkedList<ZuoYe>>() {
		}.getType();
		Gson gson = new Gson();
		LinkedList<ZuoYe> entitys = gson.fromJson(jsonData, listType);
		return entitys;
	}

	private Boolean setDefaultValue() {
		if (zuoyes == null)
			return false;
		if (zuoyes.isEmpty())
			return false;

		ZuoYe zuoye = zuoyes.getFirst();
		vgw01.setText(String.valueOf(zuoye.getVGW01()));
		vgw02.setText(String.valueOf(zuoye.getVGW02()));
		vgw03.setText(String.valueOf(zuoye.getVGW03()));
		vgw04.setText(String.valueOf(zuoye.getVGW04()));
		vgw05.setText(String.valueOf(zuoye.getVGW05()));
		vgw06.setText(String.valueOf(zuoye.getVGW06()));
		vge01.setText(zuoye.getVGE01());
		vge02.setText(zuoye.getVGE02());
		vge03.setText(zuoye.getVGE03());
		vge04.setText(zuoye.getVGE04());
		vge05.setText(zuoye.getVGE05());
		vge06.setText(zuoye.getVGE06());

		return true;
	}

	// 跳转到下一个Activity
	private void dispatch(PassParameter pp) {
		pp.setISM01(Float.parseFloat(vgw01.getText().toString()));
		pp.setISM02(Float.parseFloat(vgw02.getText().toString()));
		pp.setISM03(Float.parseFloat(vgw03.getText().toString()));
		pp.setISM04(Float.parseFloat(vgw04.getText().toString()));
		pp.setISM05(Float.parseFloat(vgw05.getText().toString()));
		pp.setISM06(Float.parseFloat(vgw06.getText().toString()));
		pp.setILE01(vge01.getText().toString());
		pp.setILE02(vge02.getText().toString());
		pp.setILE03(vge03.getText().toString());
		pp.setILE04(vge04.getText().toString());
		pp.setILE05(vge05.getText().toString());
		pp.setILE06(vge06.getText().toString());

		Intent intent = new Intent(this, DateTimeActivity.class);
		Bundle bundle = new Bundle();
		bundle.putSerializable(PassParameter.PP_KEY, pp);
		intent.putExtras(bundle);

		startActivity(intent);
	}

}

记账日期和时间界面:DateTimeActivity.java:

/**
 * 
 */
package com.fungchoi.sap;

import java.util.Calendar;
import java.util.Locale;

import com.fungchoi.sap.entity.PassParameter;
import com.fungchoi.sap.util.Helper;
import com.fungchoi.sap.util.MyApplication;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TimePicker;

/**
 * @author Administrator
 * 
 */
public class DateTimeActivity extends Activity {
	private Activity activity;

	private PassParameter pp;

	private Button previous;
	private Button next;

	private EditText txtISDD;
	private EditText txtISDZ;
	private EditText txtIEDD;
	private EditText txtIEDZ;
	private EditText txtBUDAT;
	private EditText tempDate;
	private EditText tempTime;

	private int mYear;
	private int mMonth;
	private int mDay;
	private int mHour;
	private int mMinute;

	/**
	 * 
	 */
	public DateTimeActivity() {
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.datetime);

		MyApplication.getInstance().addActivity(this);

		activity = this;

		txtISDD = (EditText) this.findViewById(R.id.txtISDD);
		txtISDZ = (EditText) this.findViewById(R.id.txtISDZ);
		txtIEDD = (EditText) this.findViewById(R.id.txtIEDD);
		txtIEDZ = (EditText) this.findViewById(R.id.txtIEDZ);
		txtBUDAT = (EditText) this.findViewById(R.id.txtBUDAT);

		final Calendar c = Calendar.getInstance(Locale.CHINA);
		mYear = c.get(Calendar.YEAR);
		mMonth = c.get(Calendar.MONTH);
		mDay = c.get(Calendar.DAY_OF_MONTH);
		mHour = c.get(Calendar.HOUR_OF_DAY);
		mMinute = c.get(Calendar.MINUTE);

		Helper.updateDate(txtISDD, mYear, mMonth, mDay);
		Helper.updateDate(txtIEDD, mYear, mMonth, mDay);
		txtISDZ.setText("08:30");
		txtIEDZ.setText("17:30");
		Helper.updateDate(txtBUDAT, mYear, mMonth, mDay);

		// 日期控件注册
		registerEvents1();
		// 时间控件注册
		registerEvents2();

		// 按下返回键返回到上一个界面
		previous = (Button) this.findViewById(R.id.btnPrevious04);
		previous.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Helper.simulateKey(KeyEvent.KEYCODE_BACK);
			}
		});
		// 按下一步跳转到工序选择界面
		next = (Button) this.findViewById(R.id.btnNext04);
		next.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				dispatch(pp);
			}
		});

		// 从意图里面接收上一个Activity传过来的数据
		Intent intent = this.getIntent();
		pp = (PassParameter) intent.getSerializableExtra(PassParameter.PP_KEY);

	}

	// 跳转到下一个Activity
	private void dispatch(PassParameter pp) {
		pp.setISDD(txtISDD.getText().toString().replaceAll("-", ""));
		pp.setIEDD(txtIEDD.getText().toString().replaceAll("-", ""));
		pp.setISDZ(txtISDZ.getText().toString().replaceAll(":", "") + "00");
		pp.setIEDZ(txtIEDZ.getText().toString().replaceAll(":", "") + "00");
		pp.setBUDAT(txtBUDAT.getText().toString().replaceAll("-", ""));
		Intent intent = new Intent(this, EquipmentActivity.class);
		Bundle bundle = new Bundle();
		bundle.putSerializable(PassParameter.PP_KEY, pp);
		intent.putExtras(bundle);

		startActivity(intent);
	}

	// 日期控件注册事件
	private void registerEvents1() {
		txtISDD.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Helper.hideIM(activity, v);
				tempDate = txtISDD;
				showDialog1();
			}
		});
		txtIEDD.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Helper.hideIM(activity, v);
				tempDate = txtIEDD;
				showDialog1();
			}
		});
		txtISDD.setOnFocusChangeListener(new OnFocusChangeListener() {
			public void onFocusChange(View v, boolean hasFocus) {
				if (hasFocus == true) {
					Helper.hideIM(activity, v);
					tempDate = txtISDD;
					showDialog1();
				}
			}
		});
		txtIEDD.setOnFocusChangeListener(new OnFocusChangeListener() {
			public void onFocusChange(View v, boolean hasFocus) {
				if (hasFocus == true) {
					Helper.hideIM(activity, v);
					tempDate = txtIEDD;
					showDialog1();
				}
			}
		});
		txtBUDAT.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Helper.hideIM(activity, v);
				tempDate = txtBUDAT;
				showDialog1();
			}
		});
	}

	// 时间控件注册事件
	private void registerEvents2() {
		txtISDZ.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				tempTime = txtISDZ;
				showDialog2();
			}
		});
		txtIEDZ.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				tempTime = txtIEDZ;
				showDialog2();
			}
		});
		txtISDZ.setOnFocusChangeListener(new OnFocusChangeListener() {
			public void onFocusChange(View v, boolean hasFocus) {
				if (hasFocus == true) {
					Helper.hideIM(activity, v);
					tempTime = txtISDZ;
					showDialog2();
				}
			}
		});
		txtIEDZ.setOnFocusChangeListener(new OnFocusChangeListener() {
			public void onFocusChange(View v, boolean hasFocus) {
				if (hasFocus == true) {
					Helper.hideIM(activity, v);
					tempTime = txtIEDZ;
					showDialog2();
				}
			}
		});
	}

	// 显示日期控件
	private void showDialog1() {
		DatePickerDialog dialog = new DatePickerDialog(this, mDateSetListener,
				mYear, mMonth, mDay);

		dialog.show();
	}

	// 显示时间控件
	private void showDialog2() {
		TimePickerDialog dialog = new TimePickerDialog(this, mTimeSetListener,
				mHour, mMinute, true);

		dialog.show();
	}

	// 日期控件事件
	private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
		public void onDateSet(DatePicker view, int year, int monthOfYear,
				int dayOfMonth) {
			mYear = year;
			mMonth = monthOfYear;
			mDay = dayOfMonth;

			Helper.updateDate(tempDate, mYear, mMonth, mDay);
		}
	};

	// 时间控件事件
	private TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
		public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
			mHour = hourOfDay;
			mMinute = minute;

			Helper.updateTime(tempTime, mHour, mMinute);
		}
	};

}

设备列表选择界面:EquipmentActivity.java:

/**
 * 
 */
package com.fungchoi.sap;

import java.lang.Thread.State;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import org.apache.http.message.BasicNameValuePair;

import com.fungchoi.sap.entity.Machine;
import com.fungchoi.sap.entity.PassParameter;
import com.fungchoi.sap.util.Helper;
import com.fungchoi.sap.util.MyApplication;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.HorizontalScrollView;
import android.widget.RadioButton;
import android.widget.ScrollView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

/**
 * @author Administrator
 * 
 */
public class EquipmentActivity extends Activity {

	private final int FP = ViewGroup.LayoutParams.FILL_PARENT;
	private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;

	private Activity activity;

	private ScrollView sv;
	private HorizontalScrollView hsv;
	private TableLayout tab;

	private PassParameter pp;
	private LinkedList<Machine> machines;

	private ProgressDialog pd1;
	private ProgressDialog pd2;
	private Button previous;
	private Button finish;

	/**
	 * 
	 */
	public EquipmentActivity() {
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.equipment);

		// 当前活动
		activity = this;

		// 将当前活动压入活动堆栈
		MyApplication.getInstance().addActivity(this);

		// 获取界面控件对象
		sv = (ScrollView) this.findViewById(R.id.scrollView3);
		sv.setHorizontalScrollBarEnabled(true);
		hsv = (HorizontalScrollView) this
				.findViewById(R.id.horizontalScrollView3);
		tab = (TableLayout) hsv.getChildAt(0);

		// 按下返回键返回到上一个界面
		previous = (Button) this.findViewById(R.id.btnPrevious05);
		previous.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Helper.simulateKey(KeyEvent.KEYCODE_BACK);
			}
		});

		// 按完成按钮提交报工数据到SAP服务完成报工处理
		finish = (Button) this.findViewById(R.id.btnFinish);
		finish.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// 正式报工之前判断是否选择了机台或者手工组
				if (!Helper.checkRadioButton(tab)) {
					Helper.message(activity, "请选择一台设备或一个手工组!");
					return;
				}
				// 提交处理-报工
				process();
			}
		});

		// 从意图里面接收上一个Activity传过来的数据
		Intent intent = this.getIntent();
		pp = (PassParameter) intent.getSerializableExtra(PassParameter.PP_KEY);

		// 设置正在处理窗口
		pd1 = ProgressDialog.show(this, "提示", "正在处理,请稍候...");
		// 启动线程
		if (thread1.getState() == State.NEW) {
			thread1.start();
		} else {
			thread1.run();
		}
	}

	// 工作线程1
	private Thread thread1 = new Thread() {
		@Override
		public void run() {
			// 从SAP系统获取数据
			String result = getJSONString(pp);
			machines = parseFromJson(result);

			Message message = handler1.obtainMessage();
			Bundle b = new Bundle();
			b.putString("flag", "ok");
			message.setData(b);
			handler1.sendMessage(message);
		}
	};

	// 更新UI
	private Handler handler1 = new Handler() {
		public void handleMessage(Message msg) {
			Helper.enableButton(finish);
			if ("ok".equals(msg.getData().getString("flag"))) {
				// 动态添加数据记录
				addRows();
				pd1.dismiss();
				thread1.stop();
			}
		}
	};

	// 从SAP服务器获取内容(JSON字符串)
	private String getJSONString(PassParameter pp) {
		String url = Helper.getUrl("service0004");
		List<BasicNameValuePair> pairs = new ArrayList<BasicNameValuePair>();
		pairs.add(new BasicNameValuePair("OrderCode", pp.getAUFNR()));
		return Helper.callSAPService(pp, url, pairs);
	}

	// 根据JSON字符串解析成订单实体对象列表
	private LinkedList<Machine> parseFromJson(String jsonData) {
		if (jsonData == null)
			return null;
		if ("".equals(jsonData))
			return null;
		Type listType = new TypeToken<LinkedList<Machine>>() {
		}.getType();
		Gson gson = new Gson();
		LinkedList<Machine> entitys = gson.fromJson(jsonData, listType);
		return entitys;
	}

	// 根据读取的记录动态添加列表行
	private Boolean addRows() {
		if (machines == null) {
			Helper.disenableButton(finish);
			return false;
		}
		if (machines.isEmpty()) {
			Helper.disenableButton(finish);
			return false;
		}

		TableRow row;
		TextView view;
		RadioButton radio;

		for (Machine machine : machines) {
			row = new TableRow(this);

			radio = new RadioButton(this);
			radio.setOnClickListener(new View.OnClickListener() {
				public void onClick(View v) {
					changedRadio((RadioButton) v);
				}
			});
			row.addView(radio);

			view = new TextView(this);
			view.setText(machine.getZZSB());
			row.addView(view);

			view = new TextView(this);
			view.setText(machine.getZZSBMS());
			row.addView(view);

			tab.addView(row, new TableLayout.LayoutParams(FP, WC));
		}
		return true;
	}

	// 当更改单选按钮时,获它所在行的订单编号及将其他的单选按钮置为未选中状态
	private void changedRadio(RadioButton rb) {
		int count = tab.getChildCount();
		TableRow row;
		RadioButton radio;
		for (int i = 1; i < count; i++) {
			row = (TableRow) tab.getChildAt(i);
			radio = (RadioButton) row.getChildAt(0);
			if (rb.equals(radio)) {
				pp.setZZSB(((TextView) row.getChildAt(1)).getText().toString());
			} else {
				if (radio.isChecked()) {
					radio.setChecked(false);
				}
			}
		}
	}

	// 执行报工
	private void process() {
		// 设置正在处理窗口
		pd2 = ProgressDialog.show(this, "提示", "正在处理,请稍候...");
		// 启动线程
		if (thread2.getState() == State.NEW) {
			thread2.start();
		} else {
			thread2.run();
		}
	}

	// 提交处理,执行报工
	private String submit(PassParameter pp) {
		String url = Helper.getUrl("service0005");
		List<BasicNameValuePair> pairs = new ArrayList<BasicNameValuePair>();
		pairs.add(new BasicNameValuePair("AUFNR", pp.getAUFNR()));
		pairs.add(new BasicNameValuePair("VORNR", pp.getVORNR()));
		pairs.add(new BasicNameValuePair("LMNGA", String.valueOf(pp.getLMNGA())));
		pairs.add(new BasicNameValuePair("MEINH", pp.getMEINH()));
		pairs.add(new BasicNameValuePair("ISM01", String.valueOf(pp.getISM01())));
		pairs.add(new BasicNameValuePair("ILE01", pp.getILE01()));
		pairs.add(new BasicNameValuePair("ISM02", String.valueOf(pp.getISM02())));
		pairs.add(new BasicNameValuePair("ILE02", pp.getILE02()));
		pairs.add(new BasicNameValuePair("ISM03", String.valueOf(pp.getISM03())));
		pairs.add(new BasicNameValuePair("ILE03", pp.getILE03()));
		pairs.add(new BasicNameValuePair("ISM04", String.valueOf(pp.getISM04())));
		pairs.add(new BasicNameValuePair("ILE04", pp.getILE04()));
		pairs.add(new BasicNameValuePair("ISM05", String.valueOf(pp.getISM05())));
		pairs.add(new BasicNameValuePair("ILE05", pp.getILE05()));
		pairs.add(new BasicNameValuePair("ISM06", String.valueOf(pp.getISM06())));
		pairs.add(new BasicNameValuePair("ILE06", pp.getILE06()));
		pairs.add(new BasicNameValuePair("ISDD", pp.getISDD()));
		pairs.add(new BasicNameValuePair("ISDZ", pp.getISDZ()));
		pairs.add(new BasicNameValuePair("IEDD", pp.getIEDD()));
		pairs.add(new BasicNameValuePair("IEDZ", pp.getIEDZ()));
		pairs.add(new BasicNameValuePair("BUDAT", pp.getBUDAT()));
		pairs.add(new BasicNameValuePair("LTXA1", pp.getLTXA1()));
		pairs.add(new BasicNameValuePair("ZZSB", pp.getZZSB()));
		return Helper.callSAPService(pp, url, pairs);
	}

	// 工作线程1
	private Thread thread2 = new Thread() {
		@Override
		public void run() {
			// 提交数据到SAP系统进行处理-执行报工,返回报工结果
			String result = submit(pp);
			pp.setResult(result);

			Message message = handler2.obtainMessage();
			handler2.sendMessage(message);
		}
	};

	// 更新UI
	private Handler handler2 = new Handler() {
		public void handleMessage(Message msg) {
			pd2.dismiss();
			thread2.stop();
			// 跳转到结果界面
			dispatch(pp);
		}
	};

	// 跳转到下一个Activity
	private void dispatch(PassParameter pp) {
		Intent intent = new Intent(this, ResultActivity.class);
		Bundle bundle = new Bundle();
		bundle.putSerializable(PassParameter.PP_KEY, pp);
		intent.putExtras(bundle);

		startActivity(intent);
	}

}

访问SAP报工处理结果界面: ResultActivity.java :

/**
 * 处理结果
 */
package com.fungchoi.sap;

import com.fungchoi.sap.entity.PassParameter;
import com.fungchoi.sap.util.Helper;
import com.fungchoi.sap.util.MyApplication;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
 * @author Administrator
 * 
 */
public class ResultActivity extends Activity {

	/**
	 * 
	 */
	public ResultActivity() {
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.result);

		MyApplication.getInstance().addActivity(this);

		// 从意图里面接收上一个Activity传过来的数据
		Intent intent = this.getIntent();
		PassParameter pp = (PassParameter) intent
				.getSerializableExtra(PassParameter.PP_KEY);

		TextView view = (TextView) this.findViewById(R.id.txtContent);
		view.setText(pp.getResult());

		// 按下返回键返回到上一个界面
		Button previous = (Button) this.findViewById(R.id.btnPrevious06);
		previous.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Helper.simulateKey(KeyEvent.KEYCODE_BACK);
			}
		});

		// 退出系统
		Button exit = (Button) this.findViewById(R.id.btnExit);
		exit.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				MyApplication.getInstance().exit();
			}
		});
	}

}

 

com.fungchoi.sap.entity包包含6个实体对象文件:

用户对象:User.java

/**
 * 
 */
package com.fungchoi.sap.entity;

/**
 * @author Administrator
 *
 */
public class User {

	/**
	 * 
	 */
	public User() {
		// TODO Auto-generated constructor stub
	}
	
	private String userName;
	private String password;
	
	/**
	 * @return the userName
	 */
	public String getUserName() {
		return userName;
	}
	/**
	 * @param userName the userName to set
	 */
	public void setUserName(String userName) {
		this.userName = userName;
	}

	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}	

}

  

生产订单对象:Order.java

/**
 * 
 */
package com.fungchoi.sap.entity;

/**
 * @author Administrator
 *
 */
public class Order {
	private String AUFNR;//	1 Types	AUFNR	CHAR	12	0	订单号 
	private String MAKTX;//1 Types	MAKTX	CHAR	40	0	物料描述(短文本) 
	private int GAMNG;//1 Types	GAMNG	QUAN	13	3	订单数量总计
	private int IGMNG;//1 Types	CO_IGMNG	QUAN	13	3	确认订单中的产量确认
	private String MEINS;//1 Types	MEINS	UNIT	3	0	基本计量单位
	private String MSEHT;//1 Types	MSEHT	CHAR	10	0	度量单位文本(最多10个字符)
	/**
	 * @return the aUFNR
	 */
	public String getAUFNR() {
		return AUFNR;
	}
	/**
	 * @param aUFNR the aUFNR to set
	 */
	public void setAUFNR(String aUFNR) {
		AUFNR = aUFNR;
	}
	/**
	 * @return the mAKTX
	 */
	public String getMAKTX() {
		return MAKTX;
	}
	/**
	 * @param mAKTX the mAKTX to set
	 */
	public void setMAKTX(String mAKTX) {
		MAKTX = mAKTX;
	}
	/**
	 * @return the gAMNG
	 */
	public int getGAMNG() {
		return GAMNG;
	}
	/**
	 * @param gAMNG the gAMNG to set
	 */
	public void setGAMNG(int gAMNG) {
		GAMNG = gAMNG;
	}
	/**
	 * @return the iGMNG
	 */
	public int getIGMNG() {
		return IGMNG;
	}
	/**
	 * @param iGMNG the iGMNG to set
	 */
	public void setIGMNG(int iGMNG) {
		IGMNG = iGMNG;
	}
	/**
	 * @return the mEINS
	 */
	public String getMEINS() {
		return MEINS;
	}
	/**
	 * @param mEINS the mEINS to set
	 */
	public void setMEINS(String mEINS) {
		MEINS = mEINS;
	}
	/**
	 * @return the mSEHT
	 */
	public String getMSEHT() {
		return MSEHT;
	}
	/**
	 * @param mSEHT the mSEHT to set
	 */
	public void setMSEHT(String mSEHT) {
		MSEHT = mSEHT;
	}

}

  

工序实体对象:Step.java

/**
 * 
 */
package com.fungchoi.sap.entity;

/**
 * @author Administrator
 *
 */
public class Step {

	/**
	 * 
	 */
	public Step() {
		// TODO Auto-generated constructor stub
	}
	
	private String VORNR;//	1 Types	VORNR	CHAR	4	0	操作/活动编号
	private String STEUS;//	1 Types	STEUS	CHAR	4	0	控制码 
	private String LTXA1;//	1 Types	LTXA1	CHAR	40	0	工序短文本 
	private float MGVRG;//	1 Types	MGVRG	QUAN	13	3	工序数量
	private String MEINH;//	1 Types	VORME	UNIT	3	0	作业/工序的计量单位 
	private String MSEHT;//	1 Types	MSEHT	CHAR	10	0	度量单位文本(最多10个字符)
	private String RUECK;//确认号
	/**
	 * @return the vORNR
	 */
	public String getVORNR() {
		return VORNR;
	}
	/**
	 * @param vORNR the vORNR to set
	 */
	public void setVORNR(String vORNR) {
		VORNR = vORNR;
	}
	/**
	 * @return the sTEUS
	 */
	public String getSTEUS() {
		return STEUS;
	}
	/**
	 * @param sTEUS the sTEUS to set
	 */
	public void setSTEUS(String sTEUS) {
		STEUS = sTEUS;
	}
	/**
	 * @return the lTXA1
	 */
	public String getLTXA1() {
		return LTXA1;
	}
	/**
	 * @param lTXA1 the lTXA1 to set
	 */
	public void setLTXA1(String lTXA1) {
		LTXA1 = lTXA1;
	}
	/**
	 * @return the mGVRG
	 */
	public float getMGVRG() {
		return MGVRG;
	}
	/**
	 * @param mGVRG the mGVRG to set
	 */
	public void setMGVRG(float mGVRG) {
		MGVRG = mGVRG;
	}
	/**
	 * @return the mEINH
	 */
	public String getMEINH() {
		return MEINH;
	}
	/**
	 * @param mEINH the mEINH to set
	 */
	public void setMEINH(String mEINH) {
		MEINH = mEINH;
	}
	/**
	 * @return the mSEHT
	 */
	public String getMSEHT() {
		return MSEHT;
	}
	/**
	 * @param mSEHT the mSEHT to set
	 */
	public void setMSEHT(String mSEHT) {
		MSEHT = mSEHT;
	}
	/**
	 * @return the rUECK
	 */
	public String getRUECK() {
		return RUECK;
	}
	/**
	 * @param rUECK the rUECK to set
	 */
	public void setRUECK(String rUECK) {
		RUECK = rUECK;
	}
	
	

}

  

作业实体对象:ZuoYe.java

package com.fungchoi.sap.entity;

public class ZuoYe {

	public ZuoYe() {
		// TODO Auto-generated constructor stub
	}
    
	private float VGW01;//	1 Types	VGWRT	QUAN	9	3	标准值 
	private float VGW02;//	1 Types	VGWRT	QUAN	9	3	标准值 
	private float VGW03;//	1 Types	VGWRT	QUAN	9	3	标准值 
	private float VGW04;//	1 Types	VGWRT	QUAN	9	3	标准值 
	private float VGW05;//	1 Types	VGWRT	QUAN	9	3	标准值 
	private float VGW06;//	1 Types	VGWRT	QUAN	9	3	标准值 
	private String VGE01;//	1 Types	VGWRTEH	UNIT	3	0	标准值计量单位 
	private String VGE02;//	1 Types	VGWRTEH	UNIT	3	0	标准值计量单位 
	private String VGE03;//	1 Types	VGWRTEH	UNIT	3	0	标准值计量单位 
	private String VGE04;//	1 Types	VGWRTEH	UNIT	3	0	标准值计量单位 
	private String VGE05;//	1 Types	VGWRTEH	UNIT	3	0	标准值计量单位 
	private String VGE06;//	1 Types	VGWRTEH	UNIT	3	0	标准值计量单位 
	/**
	 * @return the vGW01
	 */
	public float getVGW01() {
		return VGW01;
	}
	/**
	 * @param vGW01 the vGW01 to set
	 */
	public void setVGW01(float vGW01) {
		VGW01 = vGW01;
	}
	/**
	 * @return the vGW02
	 */
	public float getVGW02() {
		return VGW02;
	}
	/**
	 * @param vGW02 the vGW02 to set
	 */
	public void setVGW02(float vGW02) {
		VGW02 = vGW02;
	}
	/**
	 * @return the vGW03
	 */
	public float getVGW03() {
		return VGW03;
	}
	/**
	 * @param vGW03 the vGW03 to set
	 */
	public void setVGW03(float vGW03) {
		VGW03 = vGW03;
	}
	/**
	 * @return the vGW04
	 */
	public float getVGW04() {
		return VGW04;
	}
	/**
	 * @param vGW04 the vGW04 to set
	 */
	public void setVGW04(float vGW04) {
		VGW04 = vGW04;
	}
	/**
	 * @return the vGW05
	 */
	public float getVGW05() {
		return VGW05;
	}
	/**
	 * @param vGW05 the vGW05 to set
	 */
	public void setVGW05(float vGW05) {
		VGW05 = vGW05;
	}
	/**
	 * @return the vGW06
	 */
	public float getVGW06() {
		return VGW06;
	}
	/**
	 * @param vGW06 the vGW06 to set
	 */
	public void setVGW06(float vGW06) {
		VGW06 = vGW06;
	}
	/**
	 * @return the vGE01
	 */
	public String getVGE01() {
		return VGE01;
	}
	/**
	 * @param vGE01 the vGE01 to set
	 */
	public void setVGE01(String vGE01) {
		VGE01 = vGE01;
	}
	/**
	 * @return the vGE02
	 */
	public String getVGE02() {
		return VGE02;
	}
	/**
	 * @param vGE02 the vGE02 to set
	 */
	public void setVGE02(String vGE02) {
		VGE02 = vGE02;
	}
	/**
	 * @return the vGE03
	 */
	public String getVGE03() {
		return VGE03;
	}
	/**
	 * @param vGE03 the vGE03 to set
	 */
	public void setVGE03(String vGE03) {
		VGE03 = vGE03;
	}
	/**
	 * @return the vGE04
	 */
	public String getVGE04() {
		return VGE04;
	}
	/**
	 * @param vGE04 the vGE04 to set
	 */
	public void setVGE04(String vGE04) {
		VGE04 = vGE04;
	}
	/**
	 * @return the vGE05
	 */
	public String getVGE05() {
		return VGE05;
	}
	/**
	 * @param vGE05 the vGE05 to set
	 */
	public void setVGE05(String vGE05) {
		VGE05 = vGE05;
	}
	/**
	 * @return the vGE06
	 */
	public String getVGE06() {
		return VGE06;
	}
	/**
	 * @param vGE06 the vGE06 to set
	 */
	public void setVGE06(String vGE06) {
		VGE06 = vGE06;
	}
	
	
}

  

设备实体对象:Machine.java

/**
 * 
 */
package com.fungchoi.sap.entity;

/**
 * @author Administrator
 *
 */
public class Machine {

	/**
	 * 
	 */
	public Machine() {
		// TODO Auto-generated constructor stub
	}
	
	private String ZZSB;//	1 Types	ZZSB	CHAR	10	0	设备编号
	private String ZZSBMS;//	1 Types	ZZSBMS	CHAR	20	0	设备描述
	/**
	 * @return the zZSB
	 */
	public String getZZSB() {
		return ZZSB;
	}
	/**
	 * @param zZSB the zZSB to set
	 */
	public void setZZSB(String zZSB) {
		ZZSB = zZSB;
	}
	/**
	 * @return the zZSBMS
	 */
	public String getZZSBMS() {
		return ZZSBMS;
	}
	/**
	 * @param zZSBMS the zZSBMS to set
	 */
	public void setZZSBMS(String zZSBMS) {
		ZZSBMS = zZSBMS;
	}

}

  

传递参数对象:PassParameter.java

package com.fungchoi.sap.entity;

import java.io.Serializable;

public class PassParameter implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -3185894960099294258L;

	public final static String PP_KEY = "com.fungchoi.sap.pp";
	
	//帐号和密码
	private String userName;//帐号
	private String password;//密码
	
	//查询参数
	private String beginDate;//订单开始日期
	private String endDate;//订单结束日期
	private String orderCode;//订单部分编码或者完整编码
	private String materialDesc;//物料部分描述或者完整描述
	
	//报工参数
	private String AUFNR;//订单
	private String VORNR;//工序
	private float LMNGA;//产量
	private String MEINH;//单位
	private float ISM01;//人工
	private float ISM02;//动力
	private float ISM03;//机器
	private float ISM04;//油墨
	private float ISM05;//通用材料
	private float ISM06;//其他
	private String ILE01;//人工-单位
	private String ILE02;//动力-单位
	private String ILE03;//机器-单位
	private String ILE04;//油墨-单位
	private String ILE05;//通用材料-单位
	private String ILE06;//其他-单位
	private String ISDD;//开始执行日期
	private String IEDD;//结束执行日期
	private String ISDZ;//开始执行时间
	private String IEDZ;//结束执行时间
	private String BUDAT;//记账日期
	private String LTXA1;//确认文本-报工者的手机号码
	private String ZZSB;//设备编码或者手工组
	
	//处理结果
	private String result;//报工返回处理结果
		
	/**
	 * @return the beginDate
	 */
	public String getBeginDate() {
		return beginDate;
	}
	/**
	 * @param beginDate the beginDate to set
	 */
	public void setBeginDate(String beginDate) {
		this.beginDate = beginDate;
	}
	/**
	 * @return the endDate
	 */
	public String getEndDate() {
		return endDate;
	}
	/**
	 * @param endDate the endDate to set
	 */
	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}
	/**
	 * @return the materialDesc
	 */
	public String getMaterialDesc() {
		return materialDesc;
	}
	/**
	 * @param materialDesc the materialDesc to set
	 */
	public void setMaterialDesc(String materialDesc) {
		this.materialDesc = materialDesc;
	}
	/**
	 * @return the aUFNR
	 */
	public String getAUFNR() {
		return AUFNR;
	}
	/**
	 * @param aUFNR the aUFNR to set
	 */
	public void setAUFNR(String aUFNR) {
		AUFNR = aUFNR;
	}
	/**
	 * @return the vORNR
	 */
	public String getVORNR() {
		return VORNR;
	}
	/**
	 * @param vORNR the vORNR to set
	 */
	public void setVORNR(String vORNR) {
		VORNR = vORNR;
	}
	/**
	 * @return the lMNGA
	 */
	public float getLMNGA() {
		return LMNGA;
	}
	/**
	 * @param lMNGA the lMNGA to set
	 */
	public void setLMNGA(float lMNGA) {
		LMNGA = lMNGA;
	}
	/**
	 * @return the iSM01
	 */
	public float getISM01() {
		return ISM01;
	}
	/**
	 * @param iSM01 the iSM01 to set
	 */
	public void setISM01(float iSM01) {
		ISM01 = iSM01;
	}
	/**
	 * @return the iSM02
	 */
	public float getISM02() {
		return ISM02;
	}
	/**
	 * @param iSM02 the iSM02 to set
	 */
	public void setISM02(float iSM02) {
		ISM02 = iSM02;
	}
	/**
	 * @return the iSM03
	 */
	public float getISM03() {
		return ISM03;
	}
	/**
	 * @param iSM03 the iSM03 to set
	 */
	public void setISM03(float iSM03) {
		ISM03 = iSM03;
	}
	/**
	 * @return the iSM04
	 */
	public float getISM04() {
		return ISM04;
	}
	/**
	 * @param iSM04 the iSM04 to set
	 */
	public void setISM04(float iSM04) {
		ISM04 = iSM04;
	}
	/**
	 * @return the iSM05
	 */
	public float getISM05() {
		return ISM05;
	}
	/**
	 * @param iSM05 the iSM05 to set
	 */
	public void setISM05(float iSM05) {
		ISM05 = iSM05;
	}
	/**
	 * @return the iSM06
	 */
	public float getISM06() {
		return ISM06;
	}
	/**
	 * @param iSM06 the iSM06 to set
	 */
	public void setISM06(float iSM06) {
		ISM06 = iSM06;
	}
	/**
	 * @return the iLE01
	 */
	public String getILE01() {
		return ILE01;
	}
	/**
	 * @param iLE01 the iLE01 to set
	 */
	public void setILE01(String iLE01) {
		ILE01 = iLE01;
	}
	/**
	 * @return the iLE02
	 */
	public String getILE02() {
		return ILE02;
	}
	/**
	 * @param iLE02 the iLE02 to set
	 */
	public void setILE02(String iLE02) {
		ILE02 = iLE02;
	}
	/**
	 * @return the iLE03
	 */
	public String getILE03() {
		return ILE03;
	}
	/**
	 * @param iLE03 the iLE03 to set
	 */
	public void setILE03(String iLE03) {
		ILE03 = iLE03;
	}
	/**
	 * @return the iLE04
	 */
	public String getILE04() {
		return ILE04;
	}
	/**
	 * @param iLE04 the iLE04 to set
	 */
	public void setILE04(String iLE04) {
		ILE04 = iLE04;
	}
	/**
	 * @return the iLE05
	 */
	public String getILE05() {
		return ILE05;
	}
	/**
	 * @param iLE05 the iLE05 to set
	 */
	public void setILE05(String iLE05) {
		ILE05 = iLE05;
	}
	/**
	 * @return the iLE06
	 */
	public String getILE06() {
		return ILE06;
	}
	/**
	 * @param iLE06 the iLE06 to set
	 */
	public void setILE06(String iLE06) {
		ILE06 = iLE06;
	}
	/**
	 * @return the iSDD
	 */
	public String getISDD() {
		return ISDD;
	}
	/**
	 * @param iSDD the iSDD to set
	 */
	public void setISDD(String iSDD) {
		ISDD = iSDD;
	}
	/**
	 * @return the iEDD
	 */
	public String getIEDD() {
		return IEDD;
	}
	/**
	 * @param iEDD the iEDD to set
	 */
	public void setIEDD(String iEDD) {
		IEDD = iEDD;
	}
	/**
	 * @return the iSDZ
	 */
	public String getISDZ() {
		return ISDZ;
	}
	/**
	 * @param iSDZ the iSDZ to set
	 */
	public void setISDZ(String iSDZ) {
		ISDZ = iSDZ;
	}
	/**
	 * @return the iEDZ
	 */
	public String getIEDZ() {
		return IEDZ;
	}
	/**
	 * @param iEDZ the iEDZ to set
	 */
	public void setIEDZ(String iEDZ) {
		IEDZ = iEDZ;
	}
	/**
	 * @return the zZSB
	 */
	public String getZZSB() {
		return ZZSB;
	}
	/**
	 * @param zZSB the zZSB to set
	 */
	public void setZZSB(String zZSB) {
		ZZSB = zZSB;
	}
	/**
	 * @return the orderCode
	 */
	public String getOrderCode() {
		return orderCode;
	}
	/**
	 * @param orderCode the orderCode to set
	 */
	public void setOrderCode(String orderCode) {
		this.orderCode = orderCode;
	}
	/**
	 * @return the mEINH
	 */
	public String getMEINH() {
		return MEINH;
	}
	/**
	 * @param mEINH the mEINH to set
	 */
	public void setMEINH(String mEINH) {
		MEINH = mEINH;
	}
	/**
	 * @return the lTXA1
	 */
	public String getLTXA1() {
		return LTXA1;
	}
	/**
	 * @param lTXA1 the lTXA1 to set
	 */
	public void setLTXA1(String lTXA1) {
		LTXA1 = lTXA1;
	}
	/**
	 * @return the result
	 */
	public String getResult() {
		return result;
	}
	/**
	 * @param result the result to set
	 */
	public void setResult(String result) {
		this.result = result;
	}
	/**
	 * @return the bUDAT
	 */
	public String getBUDAT() {
		return BUDAT;
	}
	/**
	 * @param bUDAT the bUDAT to set
	 */
	public void setBUDAT(String bUDAT) {
		BUDAT = bUDAT;
	}
	/**
	 * @return the userName
	 */
	public String getUserName() {
		return userName;
	}
	/**
	 * @param userName the userName to set
	 */
	public void setUserName(String userName) {
		this.userName = userName;
	}
	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}
	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}
	
	
}

com.fungchoi.sap.util工具包有两个程序文件:

Helper类:

/**
 * 帮助类
 */
package com.fungchoi.sap.util;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.LinkedList;
import java.util.List;

import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;

import com.fungchoi.sap.R;
import com.fungchoi.sap.entity.PassParameter;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Instrumentation;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.IBinder;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TableLayout;
import android.widget.TableRow;

/**
 * @author Administrator
 * 
 */
public final class Helper {
	private final static String host = "10.10.100.239";
	private final static int port = 8000;
	private final static String client = "500";

	// private final static String userName = "test01";
	// private final static String password = "4480340";

	/**
	 * 
	 */
	public Helper() {
	}

	// 调用系统按键-返回键
	public static void simulateKey(final int KeyCode) {
		new Thread() {
			public void run() {
				try {
					Instrumentation inst = new Instrumentation();
					inst.sendKeyDownUpSync(KeyCode);
				} catch (Exception e) {
					Log.e("Exception when sendKeyDownUpSync", e.toString());
				}
			}
		}.start();
	}

	// 更新日期
	public static void updateDate(EditText et, int mYear, int mMonth, int mDay) {
		et.setText(new StringBuilder().append(mYear).append("-")
				.append((mMonth + 1) < 10 ? "0" + (mMonth + 1) : (mMonth + 1))
				.append("-").append((mDay < 10) ? "0" + mDay : mDay));
	}

	// 更新时间
	public static void updateTime(EditText et, int mHour, int mMinute) {
		et.setText(new StringBuilder()
				.append((mHour < 10) ? "0" + mHour : mHour).append(":")
				.append((mMinute < 10) ? "0" + mMinute : mMinute));

	}

	// 隐藏手机键盘
	public static void hideIM(Activity activity, View edt) {
		try {
			InputMethodManager im = (InputMethodManager) activity
					.getSystemService(Activity.INPUT_METHOD_SERVICE);
			IBinder windowToken = edt.getWindowToken();

			if (windowToken != null) {
				im.hideSoftInputFromWindow(windowToken, 0);
			}
		} catch (Exception e) {

		}
	}

	// 根据JSON字符串解析成实体对象列表
	public static <T> LinkedList<T> parseOrderFromJson(String jsonData) {
		if (jsonData == null)
			return null;
		if ("".equals(jsonData))
			return null;
		Type listType = new TypeToken<LinkedList<T>>() {
		}.getType();
		Gson gson = new Gson();
		LinkedList<T> entitys = gson.fromJson(jsonData, listType);
		return entitys;
	}

	// 获取URL
	public static String getUrl(String service) {
		StringBuilder sb = new StringBuilder();
		sb.append("/sap/bc/icf/").append(service).append("?sap-client=")
				.append(Helper.client);
		return sb.toString();
	}

	// 访问SAP服务
	public static String callSAPService(PassParameter pp, String url,
			List<BasicNameValuePair> pairs) {
		String result = "";
		HttpHost targetHost = new HttpHost(Helper.host, Helper.port, "http");
		DefaultHttpClient httpclient = new DefaultHttpClient();
		httpclient.getCredentialsProvider().setCredentials(
				new AuthScope(targetHost.getHostName(), targetHost.getPort()),
				new UsernamePasswordCredentials(pp.getUserName(), pp
						.getPassword()));

		// // Create AuthCache instance
		// AuthCache authCache = new BasicAuthCache();
		// // Generate BASIC scheme object and add it to the local auth cache
		// BasicScheme basicAuth = new BasicScheme();
		// authCache.put(targetHost, basicAuth);
		//
		// // Add AuthCache to the execution context
		// BasicHttpContext localcontext = new BasicHttpContext();
		// localcontext.setAttribute(ClientContext.AUTH_SCHEME_PREF, authCache);

		HttpPost request = new HttpPost(url);
		try {
			request.setEntity(new UrlEncodedFormEntity(pairs, HTTP.UTF_8));
		} catch (UnsupportedEncodingException e) {
			result = null;// "UnsupportedEncodingException.";
		}
		ResponseHandler<String> handler = new BasicResponseHandler();
		try {
			result = httpclient.execute(targetHost, request, handler);
		} catch (ClientProtocolException e) {
			result = null;// "ClientException.";
		} catch (IOException e) {
			result = null;// "IOException.";
		} catch (Exception e) {
			result = null;
		}

		httpclient.getConnectionManager().shutdown();
		return result;
	}

	// 禁用按钮
	public static void disenableButton(Button button) {
		if (button == null) {
			return;
		}
		if (button.isEnabled()) {
			button.setEnabled(false);
		}
	}

	// 启用按钮
	public static void enableButton(Button button) {
		if (button == null) {
			return;
		}
		if (!button.isEnabled()) {
			button.setEnabled(true);
		}
	}

	// 设置窗口标题图标
	public static void setIcon(Activity act) {
		Window win = act.getWindow();
		win.requestFeature(Window.FEATURE_LEFT_ICON);
		win.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
				R.drawable.fc24);
	}

	// 判断手机电量,低于10%给予用户一个提示
	private static Activity bat_activity;

	public static void checkBattery(Activity activity) {
		bat_activity = activity;
		bat_activity.registerReceiver(mReceiver, new IntentFilter(
				Intent.ACTION_BATTERY_CHANGED));
	}

	private static BroadcastReceiver mReceiver = new BroadcastReceiver() {
		public void onReceive(Context context, Intent intent) {
			int level = intent.getIntExtra("level", 0);
			// level加%就是当前电量了
			if (level <= 10) {
				new AlertDialog.Builder(bat_activity).setTitle("提醒")
						.setMessage("你的手机电量现在只有" + level + "%\n请及时充电!")
						.setPositiveButton("确定", null).show();
			}
			// 注销对手机电量的监听
			bat_activity.unregisterReceiver(mReceiver);
		}
	};

	// 判断3G网络或者WIFI网络连接
	public static boolean checkNet(Activity activity) {
		ConnectivityManager mConnectivity = (ConnectivityManager) activity
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		TelephonyManager mTelephony = (TelephonyManager) activity
				.getSystemService(Context.TELEPHONY_SERVICE);
		// 检查网络连接,如果无网络可用,就不需要进行连网操作等
		NetworkInfo info = mConnectivity.getActiveNetworkInfo();
		if (info == null || !mConnectivity.getBackgroundDataSetting()) {
			return false;
		}
		// 判断网络连接类型,3G或wifi里是否连接
		int netType = info.getType();
		int netSubtype = info.getSubtype();
		if (netType == ConnectivityManager.TYPE_WIFI) {
			return info.isConnected();
		} else if (netType == ConnectivityManager.TYPE_MOBILE
				&& netSubtype == TelephonyManager.NETWORK_TYPE_UMTS
				&& !mTelephony.isNetworkRoaming()) {
			return info.isConnected();
		} else {
			return false;
		}
	}

	// 弹出错误信息
	public static void message(Activity activity, String msg) {
		new AlertDialog.Builder(activity).setTitle("错误").setMessage(msg)
				.setPositiveButton("确定", null).show();
	}

	// 获取手机号码,但不一定能获取到,如果SIM卡已经写入了本机号码便能获取
	public static String getPhoneNumber(Activity activity) {
		TelephonyManager tm = (TelephonyManager) activity
				.getSystemService(Context.TELEPHONY_SERVICE);
		return tm.getLine1Number();
	}

	public static boolean checkRadioButton(TableLayout tab) {
		int count = tab.getChildCount();
		boolean flag = false;
		TableRow row;
		RadioButton radio;
		for (int i = 1; i < count; i++) {
			row = (TableRow) tab.getChildAt(i);
			radio = (RadioButton) row.getChildAt(0);
			if (radio.isChecked()) {
				flag = true;
			}
		}
		return flag;
	}

}

MyApplication类:

/**
 * 完美退出系统
 */
package com.fungchoi.sap.util;

import java.util.LinkedList;
import java.util.List;

import android.app.Activity;
import android.app.Application;

/**
 * @author Administrator
 * 
 */
public class MyApplication extends Application {
	private List<Activity> activityList = new LinkedList<Activity>();
	private static MyApplication instance;

	/**
	 * 
	 */
	private MyApplication() {
		// TODO Auto-generated constructor stub
	}

	// 单例模式中获取唯一的MyApplication实例
	public static MyApplication getInstance() {
		if (null == instance) {
			instance = new MyApplication();
		}
		return instance;
	}

	// 添加Activity到容器中
	public void addActivity(Activity activity) {
		activityList.add(activity);
	}

	// 遍历所有Activity并finish
	public void exit() {
		for (Activity activity : activityList) {
			activity.finish();
		}
		System.exit(0);
	}
}

图片资源文件:

布局资源文件:

login.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    
    <TextView 
        android:textStyle="bold"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/strLogin" ></TextView>
    
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="@color/white"></TextView>
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:focusable="true" 
        android:focusableInTouchMode="true">
        <TextView
            android:textStyle="bold"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strUserName" ></TextView>
        <EditText
            android:id="@+id/txtUserName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="text">
        </EditText>
    </LinearLayout>    
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:focusable="true" 
        android:focusableInTouchMode="true">
        <TextView
            android:textStyle="bold"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strPassword" ></TextView>
        <EditText
            android:id="@+id/txtPassword"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword">
        </EditText>
    </LinearLayout>     
    
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="@color/white"></TextView>

    <Button
        android:id="@+id/btnLogin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/strLoginText"
        android:layout_gravity="right"
        android:textStyle="bold" ></Button>

</LinearLayout>

main.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/strQuery"
        android:textStyle="bold" >
    </TextView>

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="@color/white" >
    </TextView>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strBeginDate"
            android:textStyle="bold" >
        </TextView>

        <EditText
            android:id="@+id/txtBeginDate"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="date" >
        </EditText>
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strEndDate"
            android:textStyle="bold" >
        </TextView>

        <EditText
            android:id="@+id/txtEndDate"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="date" >
        </EditText>
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strAufnr"
            android:textStyle="bold" >
        </TextView>

        <EditText
            android:id="@+id/txtOrderCode"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="number" >
        </EditText>
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strMatnr"
            android:textStyle="bold" >
        </TextView>

        <EditText
            android:id="@+id/txtMatnr"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="text" >
        </EditText>
    </LinearLayout>

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="@color/white" >
    </TextView>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/btnPrevious00"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strPrevious"
            android:textStyle="bold" >
        </Button>

        <Button
            android:id="@+id/btnStart"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strStart"
            android:textStyle="bold" >
        </Button>
    </LinearLayout>

</LinearLayout>

orderlist.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/strOrderlist" ></TextView>
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="@color/white"></TextView>
    
    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="fill_parent"   
        android:layout_height="300dip"  
        android:scrollbars="vertical"  >
        <HorizontalScrollView
            android:id="@+id/horizontalScrollView1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:fillViewport="true" >
            <TableLayout  
                android:id="@+id/tabOrderList"  
                android:layout_width="wrap_content"  
                android:layout_height="wrap_content"  
                android:stretchColumns="2" >
                <TableRow>
                    <RadioButton 
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:visibility="invisible"></RadioButton>
                    <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/strAufnr2" ></TextView>
                
                     <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/strMatnr2" ></TextView>
                     
                     <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/strQuantity" ></TextView>
                
                     <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/strUnit" ></TextView>
                </TableRow>        
            </TableLayout>
        </HorizontalScrollView>
    </ScrollView>
    
    
    <TextView 
        android:id="@+id/line4"
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="@color/white"></TextView>
    
    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
        <Button
            android:id="@+id/btnPrevious01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strPrevious"
            android:textStyle="bold" ></Button>
        <Button
            android:id="@+id/btnNext01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strNext"
            android:textStyle="bold" ></Button>
    </LinearLayout>
        
</LinearLayout>

steplist.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    
    <TextView
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/strSteplist" ></TextView>
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="@color/white"></TextView>
    
    <ScrollView
        android:id="@+id/scrollView2"
        android:layout_width="fill_parent"   
        android:layout_height="300dip"  
        android:scrollbars="vertical"  >
        <HorizontalScrollView
            android:id="@+id/horizontalScrollView2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:fillViewport="true" >
            <TableLayout  
                android:id="@+id/tabStepList"  
                android:layout_width="wrap_content"  
                android:layout_height="wrap_content"  
                android:stretchColumns="2" >
                <TableRow>
                    <RadioButton 
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:visibility="invisible"></RadioButton>
                    <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/strVornr" ></TextView>
                
                     <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/strItxa1" ></TextView>
                     
                     <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/strMgvrg" ></TextView>
                
                     <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/strMeinh" ></TextView>
                </TableRow>        
            </TableLayout>
        </HorizontalScrollView>
    </ScrollView>
    
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="@color/white"></TextView>
    
    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
        <Button
            android:id="@+id/btnPrevious02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strPrevious"
            android:textStyle="bold" ></Button>
        <Button
            android:id="@+id/btnNext02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strNext"
            android:textStyle="bold" ></Button>
    </LinearLayout>

</LinearLayout>

zuoye.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    
    <TextView
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/strZuoye" ></TextView>
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="@color/white"></TextView>
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:focusable="true" 
        android:focusableInTouchMode="true">
        <TextView
            android:textStyle="bold"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strVgw01" ></TextView>
        <EditText
            android:id="@+id/txtVgw01"
            android:layout_width="200dip"
            android:layout_height="wrap_content"
            android:inputType="numberDecimal">
        </EditText>
        <EditText
            android:id="@+id/txtVge01"
            android:layout_width="60dip"
            android:layout_height="wrap_content"
            android:inputType="text">
        </EditText>
    </LinearLayout>
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:focusable="true" 
        android:focusableInTouchMode="true">
        <TextView
            android:textStyle="bold"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strVgw02" ></TextView>
        <EditText
            android:id="@+id/txtVgw02"
            android:layout_width="200dip"
            android:layout_height="wrap_content"
            android:inputType="numberDecimal">
        </EditText>
        <EditText
            android:id="@+id/txtVge02"
            android:layout_width="60dip"
            android:layout_height="wrap_content"
            android:inputType="text">
        </EditText>
    </LinearLayout>
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:focusable="true" 
        android:focusableInTouchMode="true">
        <TextView
            android:textStyle="bold"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strVgw03" ></TextView>
        <EditText
            android:id="@+id/txtVgw03"
            android:layout_width="200dip"
            android:layout_height="wrap_content"
            android:inputType="numberDecimal">
        </EditText>
        <EditText
            android:id="@+id/txtVge03"
            android:layout_width="60dip"
            android:layout_height="wrap_content"
            android:inputType="text">
        </EditText>
    </LinearLayout>
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:focusable="true" 
        android:focusableInTouchMode="true">
        <TextView
            android:textStyle="bold"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strVgw04" ></TextView>
        <EditText
            android:id="@+id/txtVgw04"
            android:layout_width="200dip"
            android:layout_height="wrap_content"
            android:inputType="numberDecimal">
        </EditText>
        <EditText
            android:id="@+id/txtVge04"
            android:layout_width="60dip"
            android:layout_height="wrap_content"
            android:inputType="text">
        </EditText>
    </LinearLayout>
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:focusable="true" 
        android:focusableInTouchMode="true">
        <TextView
            android:textStyle="bold"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strVgw05" ></TextView>
        <EditText
            android:id="@+id/txtVgw05"
            android:layout_width="200dip"
            android:layout_height="wrap_content"
            android:inputType="numberDecimal">
        </EditText>
        <EditText
            android:id="@+id/txtVge05"
            android:layout_width="60dip"
            android:layout_height="wrap_content"
            android:inputType="text">
        </EditText>
    </LinearLayout>
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:focusable="true" 
        android:focusableInTouchMode="true">
        <TextView
            android:textStyle="bold"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strVgw06" ></TextView>
        <EditText
            android:id="@+id/txtVgw06"
            android:layout_width="200dip"
            android:layout_height="wrap_content"
            android:inputType="numberDecimal">
        </EditText>
        <EditText
            android:id="@+id/txtVge06"
            android:layout_width="60dip"
            android:layout_height="wrap_content"
            android:inputType="text">
        </EditText>
    </LinearLayout>
    
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="@color/white"></TextView>
    
    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
        <Button
            android:id="@+id/btnPrevious03"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strPrevious"
            android:textStyle="bold" ></Button>
        <Button
            android:id="@+id/btnNext03"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strNext"
            android:textStyle="bold" ></Button>
    </LinearLayout>

</LinearLayout>

datetime.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    
    <TextView
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/strDatetime" ></TextView>
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="@color/white"></TextView>
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:focusable="true" 
        android:focusableInTouchMode="true">
        <EditText
            android:id="@+id/txtISDD"
            android:layout_width="200dip"
            android:layout_height="wrap_content"
            android:inputType="date">
        </EditText>
        <EditText
            android:id="@+id/txtISDZ"
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:inputType="time">
        </EditText>
    </LinearLayout>
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:focusable="true" 
        android:focusableInTouchMode="true">
        <EditText
            android:id="@+id/txtIEDD"
            android:layout_width="200dip"
            android:layout_height="wrap_content"
            android:inputType="date">
        </EditText>
        <EditText
            android:id="@+id/txtIEDZ"
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:inputType="time">
        </EditText>
    </LinearLayout>
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:focusable="true" 
        android:focusableInTouchMode="true">
        <EditText
            android:id="@+id/txtBUDAT"
            android:layout_width="200dip"
            android:layout_height="wrap_content"
            android:inputType="date">
        </EditText>
    </LinearLayout>
    
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="@color/white"></TextView>
    
    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
        <Button
            android:id="@+id/btnPrevious04"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strPrevious"
            android:textStyle="bold" ></Button>
        <Button
            android:id="@+id/btnNext04"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strNext"
            android:textStyle="bold" ></Button>
    </LinearLayout>
    
</LinearLayout>

equiment.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    
    <TextView
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/strEquipment" ></TextView>
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="@color/white"></TextView>
    
    <ScrollView
        android:id="@+id/scrollView3"
        android:layout_width="fill_parent"   
        android:layout_height="300dip"  
        android:scrollbars="vertical"  >
        <HorizontalScrollView
            android:id="@+id/horizontalScrollView3"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:fillViewport="true" >
            <TableLayout  
                android:id="@+id/tabEquipmentList"  
                android:layout_width="wrap_content"  
                android:layout_height="wrap_content"  
                android:stretchColumns="2" >
                <TableRow>
                    <RadioButton 
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:visibility="invisible"></RadioButton>
                    <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/strZzsb" ></TextView>
                
                     <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/strZzsbms" ></TextView>
                </TableRow>        
            </TableLayout>
        </HorizontalScrollView>
    </ScrollView>
    
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="@color/white"></TextView>
    
    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
        <Button
            android:id="@+id/btnPrevious05"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strPrevious"
            android:textStyle="bold" ></Button>
        <Button
            android:id="@+id/btnFinish"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strFinish"
            android:textStyle="bold" ></Button>
    </LinearLayout>

</LinearLayout>

result.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    
    <TextView 
        android:textStyle="bold"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/strResult" ></TextView>
    
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="@color/white"></TextView>
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" 
        android:focusable="true" 
        android:focusableInTouchMode="true">
        <TextView 
            android:id="@+id/txtContent"
            android:textStyle="bold"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" ></TextView>
    </LinearLayout>
    
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="@color/white"></TextView>
    
    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
        <Button
            android:id="@+id/btnPrevious06"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strPrevious"
            android:textStyle="bold" ></Button>
        <Button
            android:id="@+id/btnExit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strExit"
            android:textStyle="bold" ></Button>
    </LinearLayout>
</LinearLayout>

最后奉上程序清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.fungchoi.sap"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15" />
    <!-- Internet Permissions -->    
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <!-- Network State Permissions -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    

    <application
        android:icon="@drawable/fc48"
        android:label="@string/app_name" >
        <activity
            android:name=".LoginActivity"          
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="nosensor" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="nosensor"></activity>
        <activity
            android:name=".OrderListActivity"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="nosensor"></activity>
        <activity 
            android:name=".StepListActivity"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="nosensor"></activity>
        <activity 
            android:name=".ZuoYeActivity"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="nosensor"></activity>
        <activity 
            android:name=".DateTimeActivity"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="nosensor"></activity>
        <activity 
            android:name=".EquipmentActivity"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="nosensor"></activity>
        <activity 
            android:name=".ResultActivity"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="nosensor"></activity>
    </application>

</manifest>

最终的效果图:

 

说完Android Client部分,现在来聊一聊SAP部分:

首先得应用事务码SICF创建ICF服务:

现在来看一看每一个服务的处理逻辑部分

service0000:

method IF_HTTP_EXTENSION~HANDLE_REQUEST.
  data: lv_username type String,
        lv_password type String.

  lv_username = server->request->get_form_field( 'UserName' )."get_form_field get_uri_parameter get_header_field
  lv_password = server->request->get_form_field( 'Password' )."get_form_field


  CALL METHOD server->response->set_header_field( name = 'Content-Type' value = 'text/plain; charset=utf-8' ).
  call method server->response->set_cdata( data = 'success' ).


endmethod.

service0001:

method IF_HTTP_EXTENSION~HANDLE_REQUEST.
  data: lv_begindate type afko-gstrp,
        lv_enddate type afko-gltrp,
        lv_ordercode type String,
        lv_material type makt-maktx,

        wa_list type ZFC_PPS029,
        ltd_list like table of wa_list,
        lv_count type i,
        lv_OrderList type ref to ZJSON4ABAP,
        content type string.

  lv_begindate = server->request->get_form_field( 'BeginDate' )."get_form_field get_uri_parameter get_header_field
  lv_enddate = server->request->get_form_field( 'EndDate' )."get_form_field
  lv_ordercode = server->request->get_form_field( 'OrderCode' )."get_form_field
  lv_material = server->request->get_form_field( 'MaterialDesc' )."get_form_field

  CALL FUNCTION 'ZFC_PPF011'
    EXPORTING
      BEGINDATE          = lv_begindate
      ENDDATE            = lv_enddate
      ORDERCODE          = lv_ordercode
      MATERIALDESC       = lv_material
    TABLES
      ORDERLIST          = ltd_list.


  CALL METHOD server->response->set_header_field( name = 'Content-Type' value = 'text/plain; charset=utf-8' ).

  describe table ltd_list lines lv_count.
  if lv_count > 0.
    create object lv_OrderList.
    content = lv_OrderList->json( abapdata = ltd_list name = '' ).
  endif.

  call method server->response->set_cdata( data = content ).


endmethod.

 

service0002:

method IF_HTTP_EXTENSION~HANDLE_REQUEST.
  data: lv_ordercode type afko-aufnr,

        wa_list type ZFC_PPS030,
        ltd_list like table of wa_list,
        lv_count type i,
        StepList type ref to ZJSON4ABAP,
        content type string.

  lv_ordercode = server->request->get_form_field( 'OrderCode' )."get_form_field get_uri_parameter get_header_field

  CALL FUNCTION 'ZFC_PPF012'
    EXPORTING
      ORDERCODE       = lv_ordercode
    TABLES
      STEPLIST        = ltd_list.


  CALL METHOD server->response->set_header_field( name = 'Content-Type' value = 'text/plain; charset=utf-8' ).

  describe table ltd_list lines lv_count.
  if lv_count > 0.
    create object StepList.
    content = StepList->json( abapdata = ltd_list name = '' ).
  endif.

  call method server->response->set_cdata( data = content ).


endmethod.

 

service0003:

method IF_HTTP_EXTENSION~HANDLE_REQUEST.
  data: lv_ordercode type afko-aufnr,
        lv_vornr type afvc-vornr,
        lv_quantity type afvv-mgvrg,

        wa_list type ZFC_PPS031,
        ltd_list like table of wa_list,
        lv_count type i,
        ZuoYeList type ref to ZJSON4ABAP,
        content type string.

  lv_ordercode = server->request->get_form_field( 'OrderCode' )."get_form_field get_uri_parameter get_header_field
  lv_vornr = server->request->get_form_field( 'StepCode' )."get_form_field
  lv_quantity = server->request->get_form_field( 'Quantity' )."get_form_field

  CALL FUNCTION 'ZFC_PPF013'
   EXPORTING
     ORDERCODE       = lv_ordercode
     STEPNUM         = lv_vornr
     QUANTITY        = lv_quantity
   TABLES
     ZUOYE           = ltd_list.


  CALL METHOD server->response->set_header_field( name = 'Content-Type' value = 'text/plain; charset=utf-8' ).

  describe table ltd_list lines lv_count.
  if lv_count > 0.
    create object ZuoYeList.
    content = ZuoYeList->json( abapdata = ltd_list name = '' ).
  endif.

  call method server->response->set_cdata( data = content ).


endmethod.

 

service0004:

method IF_HTTP_EXTENSION~HANDLE_REQUEST.
  data: lv_ordercode type afko-aufnr,

        wa_list type ZFC_PPS032,
        ltd_list like table of wa_list,
        lv_count type i,
        MachineList type ref to ZJSON4ABAP,
        content type string.

  lv_ordercode = server->request->get_form_field( 'OrderCode' )."get_form_field get_uri_parameter get_header_field

  CALL FUNCTION 'ZFC_PPF014'
    EXPORTING
      ORDERCODE         = lv_ordercode
    TABLES
      MACHINELIST       = ltd_list.


  CALL METHOD server->response->set_header_field( name = 'Content-Type' value = 'text/plain; charset=utf-8' ).

  describe table ltd_list lines lv_count.
  if lv_count > 0.
    create object MachineList.
    content = MachineList->json( abapdata = ltd_list name = '' ).
  endif.

  call method server->response->set_cdata( data = content ).


endmethod.

 

service0005:

method IF_HTTP_EXTENSION~HANDLE_REQUEST.
  data: lv_AUFNR type afru-aufnr,
        lv_VORNR type afru-vornr,
        lv_LMNGA type BDC_FVAL,"afru-lmnga,
        lv_MEINH type afru-meinh,
        lv_ISM01 type BDC_FVAL,"afru-ism01,
        lv_ILE01 type afru-ile01,
        lv_ISM02 type BDC_FVAL,"afru-ism02,
        lv_ILE02 type afru-ile02,
        lv_ISM03 type BDC_FVAL,"afru-ism03,
        lv_ILE03 type afru-ile03,
        lv_ISM04 type BDC_FVAL,"afru-ism04,
        lv_ILE04 type afru-ile04,
        lv_ISM05 type BDC_FVAL,"afru-ism05,
        lv_ILE05 type afru-ile05,
        lv_ISM06 type BDC_FVAL,"afru-ism06,
        lv_ILE06 type afru-ile06,
        lv_ISDD type afru-isdd,
        lv_ISDZ type afru-isdz,
        lv_IEDD type afru-iedd,
        lv_IEDZ type afru-iedz,
        lv_BUDAT type afru-budat,
        lv_LTXA1 type afru-ltxa1,
        lv_ZZSB type afru-zzsb,

        wa_list type ZFC_PPS029,
        ltd_list like table of wa_list,
        lv_count type i,
        lv_OrderList type ref to ZJSON4ABAP,
        content type string.

  lv_AUFNR = server->request->get_form_field( 'AUFNR' ).
  lv_VORNR = server->request->get_form_field( 'VORNR' ).
  lv_LMNGA = server->request->get_form_field( 'LMNGA' ).
  lv_MEINH = server->request->get_form_field( 'MEINH' ).
  lv_ISM01 = server->request->get_form_field( 'ISM01' ).
  lv_ILE01 = server->request->get_form_field( 'ILE01' ).
  lv_ISM02 = server->request->get_form_field( 'ISM02' ).
  lv_ILE02 = server->request->get_form_field( 'ILE02' ).
  lv_ISM03 = server->request->get_form_field( 'ISM03' ).
  lv_ILE03 = server->request->get_form_field( 'ILE03' ).
  lv_ISM04 = server->request->get_form_field( 'ISM04' ).
  lv_ILE04 = server->request->get_form_field( 'ILE04' ).
  lv_ISM05 = server->request->get_form_field( 'ISM05' ).
  lv_ILE05 = server->request->get_form_field( 'ILE05' ).
  lv_ISM06 = server->request->get_form_field( 'ISM06' ).
  lv_ILE06 = server->request->get_form_field( 'ILE06' ).
  lv_ISDD = server->request->get_form_field( 'ISDD' ).
  lv_ISDZ = server->request->get_form_field( 'ISDZ' ).
  lv_IEDD = server->request->get_form_field( 'IEDD' ).
  lv_IEDZ = server->request->get_form_field( 'IEDZ' ).
  lv_BUDAT = server->request->get_form_field( 'BUDAT' ).
  lv_LTXA1 = server->request->get_form_field( 'LTXA1' ).
  lv_ZZSB = server->request->get_form_field( 'ZZSB' ).

  CALL FUNCTION 'ZFC_PPF015'
    EXPORTING
      AUFNR         = lv_AUFNR
      VORNR         = lv_VORNR
      LMNGA         = lv_LMNGA
      MEINH         = lv_MEINH

      ISM01         = lv_ISM01
      ILE01         = lv_ILE01

      ISM02         = lv_ISM02
      ILE02         = lv_ILE02

      ISM03         = lv_ISM03
      ILE03         = lv_ILE03

      ISM04         = lv_ISM04
      ILE04         = lv_ILE04

      ISM05         = lv_ISM05
      ILE05         = lv_ILE05

      ISM06         = lv_ISM06
      ILE06         = lv_ILE06

      ISDD          = lv_ISDD
      ISDZ          = lv_ISDZ

      IEDD          = lv_IEDD
      IEDZ          = lv_IEDZ

      BUDAT         = lv_BUDAT
      LTXA1         = lv_LTXA1
      ZZSB          = lv_ZZSB
    IMPORTING
      MESSAGE       = content.





  CALL METHOD server->response->set_header_field( name = 'Content-Type' value = 'text/plain; charset=utf-8' ).

  call method server->response->set_cdata( data = content ).


endmethod.

在每一个服务处理逻辑里面又分别引用到了SAP处理函数:

FUNCTION ZFC_PPF011.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(BEGINDATE) TYPE  CO_GSTRP
*"     VALUE(ENDDATE) TYPE  CO_GLTRP
*"     VALUE(ORDERCODE) TYPE  STRING OPTIONAL
*"     VALUE(MATERIALDESC) TYPE  MAKTX OPTIONAL
*"  TABLES
*"      ORDERLIST STRUCTURE  ZFC_PPS029 OPTIONAL
*"----------------------------------------------------------------------

    data: lv_text type string,
          lv_code type string,
          lv_temp type string,
          lth_orderlist type ZFC_PPS029.

    concatenate '%' MATERIALDESC '%' into lv_text.
    concatenate '%' ORDERCODE '%' into lv_code.

    select ak~AUFNR
           mt~MAKTX
           ak~GAMNG
           ak~IGMNG
           ak~GMEIN as MEINS
           ta~mseht
    into corresponding fields of table orderlist
    from afko as ak
    inner join makt as mt on mt~matnr = ak~plnbez and mt~spras = '1'
    left join t006a as ta on ta~msehi = ak~gmein and ta~spras = '1'
    where ak~aufnr like lv_code and
          ( ( ak~gstrp between begindate and enddate ) or ( ak~gltrp between begindate and enddate ) ) and
          mt~maktx like lv_text.

    loop at orderlist into lth_orderlist.
      clear lv_temp.
      select single js~stat
        into lv_temp
        from aufk as ak
        inner join jest as js on ak~OBJNR = js~OBJNR and js~INACT <> 'X'
        inner join tj02t as tt on tt~ISTAT = js~STAT and tt~SPRAS = '1'
        where ak~aufnr = lth_orderlist-aufnr and ( tt~ISTAT = 'I0002' or tt~ISTAT = 'I0010' ).

      if lv_temp <> 'I0002' and lv_temp <> 'I0010'.
        delete table orderlist from lth_orderlist.
      endif.
    endloop.

    sort orderlist by aufnr descending.


ENDFUNCTION.
FUNCTION ZFC_PPF012.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(ORDERCODE) TYPE  AUFNR
*"  TABLES
*"      STEPLIST STRUCTURE  ZFC_PPS030 OPTIONAL
*"----------------------------------------------------------------------

    data: lth_steplist type ZFC_PPS030,
          lv_sum type afvv-mgvrg.

    select distinct
        ac~vornr"工序序号
        ac~steus"控制码
        ac~ltxa1"工序描述
        av~mgvrg"工序数量
        av~MEINH"作业/工序的计量单位
        ta~mseht"中文单位
        ac~rueck"确认号
        into corresponding fields of table steplist
        from afko as ak
        inner join afvc as ac on ac~aufpl = ak~aufpl
        inner join afvv as av on av~aufpl = ac~aufpl and av~aplzl = ac~aplzl
        left join t006a as ta on ta~msehi = av~meinh and ta~spras = '1'
        where ak~aufnr = ordercode and ( ac~steus = 'ZP01' or ac~steus = 'ZP03' ).

    loop at steplist into lth_steplist.
      clear lv_sum.
      select sum( gmnga ) into lv_sum
        from afru
        where rueck = lth_steplist-rueck and STOKZ = '' and STZHL = ''."STOKZ = 'X'表示已冲销,被取消报工的原始记录;STZHL >= 1 表示取消报工的记录
      if lv_sum > 0.
        lth_steplist-mgvrg = lth_steplist-mgvrg - lv_sum.
        if lth_steplist-mgvrg <= 0.
          delete table steplist from lth_steplist.
        else.
          modify steplist from lth_steplist transporting mgvrg.
        endif.
      endif.
    endloop.

    sort steplist by vornr ascending.

ENDFUNCTION.
FUNCTION ZFC_PPF013.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(ORDERCODE) TYPE  AUFNR
*"     VALUE(STEPNUM) TYPE  VORNR
*"     VALUE(QUANTITY) TYPE  MGVRG
*"  TABLES
*"      ZUOYE STRUCTURE  ZFC_PPS031 OPTIONAL
*"----------------------------------------------------------------------
data: begin of lth_zuoye,
        BMSCH like afvv-bmsch,
        VGW01 like afvv-vgw01,
        VGW02 like afvv-vgw02,
        VGW03 like afvv-vgw03,
        VGW04 like afvv-vgw04,
        VGW05 like afvv-vgw05,
        VGW06 like afvv-vgw06,
        VGE01 like afvv-vge01,
        VGE02 like afvv-vge02,
        VGE03 like afvv-vge03,
        VGE04 like afvv-vge04,
        VGE05 like afvv-vge05,
        VGE06 like afvv-vge06,
        MGVRG like afvv-mgvrg,
      end of lth_zuoye,
      lth_zuoye2 type zfc_pps031.

select single
    av~BMSCH
    av~VGW01
    av~VGW02
    av~VGW03
    av~VGW04
    av~VGW05
    av~VGW06
    av~VGE01
    av~VGE02
    av~VGE03
    av~VGE04
    av~VGE05
    av~VGE06
    av~MGVRG
    into (lth_zuoye-BMSCH,
    lth_zuoye-VGW01,
    lth_zuoye-VGW02,
    lth_zuoye-VGW03,
    lth_zuoye-VGW04,
    lth_zuoye-VGW05,
    lth_zuoye-VGW06,
    lth_zuoye-VGE01,
    lth_zuoye-VGE02,
    lth_zuoye-VGE03,
    lth_zuoye-VGE04,
    lth_zuoye-VGE05,
    lth_zuoye-VGE06,
    lth_zuoye-MGVRG)
    from afko as ak
    inner join afvc as ac on ac~aufpl = ak~aufpl
    inner join afvv as av on av~aufpl = ac~aufpl and av~aplzl = ac~aplzl
    where ak~aufnr = ordercode and ac~vornr = stepnum and ( ac~steus = 'ZP01' or ac~steus = 'ZP03' ).

if quantity <> lth_zuoye-mgvrg.
  lth_zuoye-vgw01 = quantity * lth_zuoye-vgw01 / lth_zuoye-bmsch.
  lth_zuoye-vgw02 = quantity * lth_zuoye-vgw02 / lth_zuoye-bmsch.
  lth_zuoye-vgw03 = quantity * lth_zuoye-vgw03 / lth_zuoye-bmsch.
  lth_zuoye-vgw04 = quantity * lth_zuoye-vgw04 / lth_zuoye-bmsch.
  lth_zuoye-vgw05 = quantity * lth_zuoye-vgw05 / lth_zuoye-bmsch.
  lth_zuoye-vgw06 = quantity * lth_zuoye-vgw06 / lth_zuoye-bmsch.
endif.

if lth_zuoye-vgw01 >= 60.
  lth_zuoye-vgw01 = lth_zuoye-vgw01 / 60.
  lth_zuoye-vge01 = 'H'.
endif.

if lth_zuoye-vgw02 >= 60.
  lth_zuoye-vgw02 = lth_zuoye-vgw02 / 60.
  lth_zuoye-vge02 = 'H'.
endif.

if lth_zuoye-vgw03 >= 60.
  lth_zuoye-vgw03 = lth_zuoye-vgw03 / 60.
  lth_zuoye-vge03 = 'H'.
endif.

if lth_zuoye-vgw05 >= 60.
  lth_zuoye-vgw05 = lth_zuoye-vgw05 / 60.
  lth_zuoye-vge05 = 'H'.
endif.

if lth_zuoye-vgw06 >= 60.
  lth_zuoye-vgw06 = lth_zuoye-vgw06 / 60.
  lth_zuoye-vge06 = 'H'.
endif.

move-corresponding lth_zuoye to lth_zuoye2.
append lth_zuoye2 to zuoye.

ENDFUNCTION.
FUNCTION ZFC_PPF014.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(ORDERCODE) TYPE  AUFNR
*"  TABLES
*"      MACHINELIST STRUCTURE  ZFC_PPS032 OPTIONAL
*"----------------------------------------------------------------------

data: begin of lth_machine,
        zzsb like zfc_pptm_sbnl-zzsb,
        zzsbms like zfc_pptm_sbnl-zzsbms,
      end of lth_machine.


select distinct
    sb~ZZSB
    sb~ZZSBMS
    into corresponding fields of table machinelist
    from afko as ak
    inner join afvc as ac on ac~aufpl = ak~aufpl
    inner join afvv as av on av~aufpl = ac~aufpl and av~aplzl = ac~aplzl
    left join crhd as ch on ch~objid = ac~arbid
    inner join ZFC_PPTM_SBNL as sb on sb~arbpl = ch~arbpl
    where ak~aufnr = ordercode and ( ac~steus = 'ZP01' or ac~steus = 'ZP03' ).

loop at machinelist into lth_machine.
  if lth_machine-zzsb+0(2) = 'ZX'.
    delete table machinelist from lth_machine.
  endif.
endloop.

sort machinelist by zzsb descending.

ENDFUNCTION.
FUNCTION ZFC_PPF015.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(AUFNR) TYPE  AUFNR
*"     VALUE(VORNR) TYPE  VORNR
*"     VALUE(LMNGA) TYPE  BDC_FVAL
*"     VALUE(MEINH) TYPE  RU_VORME
*"     VALUE(ISM01) TYPE  BDC_FVAL
*"     VALUE(ILE01) TYPE  CO_ISMNGEH
*"     VALUE(ISM02) TYPE  BDC_FVAL
*"     VALUE(ILE02) TYPE  CO_ISMNGEH
*"     VALUE(ISM03) TYPE  BDC_FVAL
*"     VALUE(ILE03) TYPE  CO_ISMNGEH
*"     VALUE(ISM04) TYPE  BDC_FVAL
*"     VALUE(ILE04) TYPE  CO_ISMNGEH
*"     VALUE(ISM05) TYPE  BDC_FVAL
*"     VALUE(ILE05) TYPE  CO_ISMNGEH
*"     VALUE(ISM06) TYPE  BDC_FVAL
*"     VALUE(ILE06) TYPE  CO_ISMNGEH
*"     VALUE(ISDD) TYPE  RU_ISDD
*"     VALUE(ISDZ) TYPE  RU_ISDZ
*"     VALUE(IEDD) TYPE  RU_IEDD
*"     VALUE(IEDZ) TYPE  RU_IEDZ
*"     VALUE(BUDAT) TYPE  BUCHDATUM
*"     VALUE(LTXA1) TYPE  CO_RTEXT
*"     VALUE(ZZSB) TYPE  ZZSB
*"  EXPORTING
*"     VALUE(MESSAGE) TYPE  CHAR8000_D
*"----------------------------------------------------------------------

    "-----------------先对生产订单进行校验-------开始---------------------
    data: lv_aufnr like afko-aufnr,
          lv_flag type c length 1,
          lv_iscan type c length 1 value 'X'.
    lv_aufnr = aufnr.
    shift lv_aufnr left deleting leading '0'.
    lv_flag = lv_aufnr+0(1).
    if lv_flag = '6'.
      CALL FUNCTION 'ZFC_PPF038'
       EXPORTING
         P_AUFNR       = aufnr
         P_VORNR       = vornr
       IMPORTING
         P_FLAG        = lv_iscan.

      if lv_iscan = ''.
        message = '半品组件存在不全完报工情况!'.
        return.
      endif.
    endif.
    "-----------------先对生产订单进行校验-------结束---------------------


    DATA: bdcdata_wa  TYPE BDCDATA,
          bdcdata_tab TYPE TABLE OF BDCDATA.
    DATA: wa_bdcmsg TYPE BDCMSGCOLL,
          it_bdcmsg TYPE TABLE OF BDCMSGCOLL.

    DATA opt TYPE CTU_PARAMS.

    DATA: gth_timeticket type BAPI_PP_TIMETICKET,
          gtd_timeticket type table of BAPI_PP_TIMETICKET.

    "设置初始值
    CLEAR bdcdata_wa.
    bdcdata_wa-program  = 'SAPLCORU_S'.
    bdcdata_wa-dynpro   = '0100'.
    bdcdata_wa-dynbegin = 'X'."开始标志
    APPEND bdcdata_wa TO bdcdata_tab.

    "---------模拟屏字段赋值开始-----------------------------
    "生产订单
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-AUFNR'.
    bdcdata_wa-fval = AUFNR.
    APPEND bdcdata_wa TO bdcdata_tab.

    "工序
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-VORNR'.
    bdcdata_wa-fval = VORNR.
    APPEND bdcdata_wa TO bdcdata_tab.

    "确认类型
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-AUERU'.
    bdcdata_wa-fval = '1'.
    APPEND bdcdata_wa TO bdcdata_tab.

    "产量
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-LMNGA'.
    bdcdata_wa-fval = LMNGA.
    APPEND bdcdata_wa TO bdcdata_tab.

    "产量-单位
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-MEINH'.
    bdcdata_wa-fval = MEINH.
    APPEND bdcdata_wa TO bdcdata_tab.

    "人工
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-ISM01'.
    bdcdata_wa-fval = ISM01.
    APPEND bdcdata_wa TO bdcdata_tab.

    "人工-单位
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-ILE01'.
    bdcdata_wa-fval = ILE01.
    APPEND bdcdata_wa TO bdcdata_tab.

    "动力
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-ISM02'.
    bdcdata_wa-fval = ISM02.
    APPEND bdcdata_wa TO bdcdata_tab.

    "动力-单位
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-ILE02'.
    bdcdata_wa-fval = ILE02.
    APPEND bdcdata_wa TO bdcdata_tab.

    "机器
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-ISM03'.
    bdcdata_wa-fval = ISM03.
    APPEND bdcdata_wa TO bdcdata_tab.

    "机器-单位
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-ILE03'.
    bdcdata_wa-fval = ILE03.
    APPEND bdcdata_wa TO bdcdata_tab.

    "油墨
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-ISM04'.
    bdcdata_wa-fval = ISM04.
    APPEND bdcdata_wa TO bdcdata_tab.

    "油墨-单位
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-ILE04'.
    bdcdata_wa-fval = ILE04.
    APPEND bdcdata_wa TO bdcdata_tab.

    "通用材料
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-ISM05'.
    bdcdata_wa-fval = ISM05.
    APPEND bdcdata_wa TO bdcdata_tab.

    "通用材料-单位
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-ILE05'.
    bdcdata_wa-fval = ILE05.
    APPEND bdcdata_wa TO bdcdata_tab.

    "其他
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-ISM06'.
    bdcdata_wa-fval = ISM06.
    APPEND bdcdata_wa TO bdcdata_tab.

    "其他-单位
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-ILE06'.
    bdcdata_wa-fval = ILE06.
    APPEND bdcdata_wa TO bdcdata_tab.

    "开始执行日期
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-ISDD'.
    bdcdata_wa-fval = ISDD.
    APPEND bdcdata_wa TO bdcdata_tab.

    "开始执行时间
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-ISDZ'.
    bdcdata_wa-fval = ISDZ.
    APPEND bdcdata_wa TO bdcdata_tab.

    "结束执行日期
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-IEDD'.
    bdcdata_wa-fval = IEDD.
    APPEND bdcdata_wa TO bdcdata_tab.

    "结束执行时间
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-IEDZ'.
    bdcdata_wa-fval = IEDZ.
    APPEND bdcdata_wa TO bdcdata_tab.

    "记账日期
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-BUDAT'.
    bdcdata_wa-fval = BUDAT.
    APPEND bdcdata_wa TO bdcdata_tab.

    "确认文本
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'AFRUD-LTXA1'.
    bdcdata_wa-fval = LTXA1.
    APPEND bdcdata_wa TO bdcdata_tab.

    "设备编号
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'ZAFRU-ZZSB'.
    bdcdata_wa-fval = ZZSB.
    APPEND bdcdata_wa TO bdcdata_tab.

*    "工厂
*    CLEAR bdcdata_wa.
*    bdcdata_wa-fnam = 'AFVGD-WERKS'.
*    bdcdata_wa-fval = '1000'.
*    APPEND bdcdata_wa TO bdcdata_tab.
*
*    "工作中心
*    CLEAR bdcdata_wa.
*    bdcdata_wa-fnam = 'AFVGD-ARBPL'.
*    bdcdata_wa-fval = 'ZX030104'.
*    APPEND bdcdata_wa TO bdcdata_tab.
*
*    "物料
*    CLEAR bdcdata_wa.
*    bdcdata_wa-fnam = 'CAUFVD-MATNR'.
*    bdcdata_wa-fval = '610000000001'.
*    APPEND bdcdata_wa TO bdcdata_tab.


    "获取确认号
    gth_timeticket-ORDERID  = AUFNR.
    gth_timeticket-OPERATION  = VORNR.
    append gth_timeticket to gtd_timeticket.
    CALL FUNCTION 'BAPI_PRODORDCONF_GET_TT_PROP'
      TABLES
        TIMETICKETS = gtd_timeticket.
    IF SY-SUBRC = 0.
      read table gtd_timeticket index 1 into gth_timeticket.
      CLEAR bdcdata_wa.
      bdcdata_wa-fnam = 'AFRUD-RUECK'.
      bdcdata_wa-fval = gth_timeticket-CONF_NO.
      APPEND bdcdata_wa TO bdcdata_tab.
    endif.
    "---------模拟屏字段赋值结束-----------------------------

    "模拟点击屏幕保存按钮
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'BDC_OKCODE'.
    bdcdata_wa-fval = '=BU'.
    APPEND bdcdata_wa TO bdcdata_tab.

    "-----------------为了避开--是否确定选择额外设备?--开始-------------------------------
    CLEAR bdcdata_wa.
    bdcdata_wa-program  = 'SAPLXCOF'.
    bdcdata_wa-dynpro   = '0900'.
    bdcdata_wa-dynbegin = 'X'."开始标志
    APPEND bdcdata_wa TO bdcdata_tab.
    "回车
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'BDC_OKCODE'.
    bdcdata_wa-fval = '/00'.
    APPEND bdcdata_wa TO bdcdata_tab.
    "确定
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'BDC_OKCODE'.
    bdcdata_wa-fval = '=YES'.
    APPEND bdcdata_wa TO bdcdata_tab.
    "回车
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'BDC_OKCODE'.
    bdcdata_wa-fval = '/00'.
    APPEND bdcdata_wa TO bdcdata_tab.
    "-----------------为了避开--是否确定选择额外设备?--结束-------------------------------

    "-----------------为了避开--过量交货黄色警告信息--开始-------------------------------
    CLEAR bdcdata_wa.
    bdcdata_wa-program  = 'SAPLCORU_S'.
    bdcdata_wa-dynpro   = '0100'.
    bdcdata_wa-dynbegin = 'X'."开始标志
    APPEND bdcdata_wa TO bdcdata_tab.
    "回车
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'BDC_OKCODE'.
    bdcdata_wa-fval = '/00'.
    APPEND bdcdata_wa TO bdcdata_tab.
    "确定
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'BDC_OKCODE'.
    bdcdata_wa-fval = '/00'.
    APPEND bdcdata_wa TO bdcdata_tab.
    "回车
    CLEAR bdcdata_wa.
    bdcdata_wa-fnam = 'BDC_OKCODE'.
    bdcdata_wa-fval = '/00'.
    APPEND bdcdata_wa TO bdcdata_tab.
    "-----------------为了避开--过量交货黄色警告信息--结束-------------------------------

    opt-dismode = 'N'.
    opt-defsize = 'X'.
    CALL TRANSACTION 'CO11N' USING bdcdata_tab OPTIONS FROM opt MESSAGES INTO it_bdcmsg.

    IF SY-SUBRC = 0.
      MESSAGE = '报工成功!'.
    ELSE.
      data: lv_temp type string.
      MESSAGE = '报工失败!请尝试在SAP系统报工。服务器程序执行错误。'.
      LOOP AT it_bdcmsg INTO wa_bdcmsg.
        CALL FUNCTION 'MESSAGE_TEXT_BUILD'
          EXPORTING
            msgid               = wa_bdcmsg-msgid
            msgnr               = wa_bdcmsg-msgnr
            msgv1               = wa_bdcmsg-msgv1
            msgv2               = wa_bdcmsg-msgv2
            msgv3               = wa_bdcmsg-msgv3
            msgv4               = wa_bdcmsg-msgv4
          IMPORTING
            message_text_output = lv_temp.
        concatenate message lv_temp into message.
      ENDLOOP.
    ENDIF.

ENDFUNCTION.

SAP里面引用到的数据结构就不弄出来了,太麻烦了。

 

 

 

 

转载于:https://www.cnblogs.com/dashan/p/3685646.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值