package com.jqyd.son; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import org.json.JSONException; import org.json.JSONObject; import com.jqyd.app.MyApp; import com.jqyd.manager.R; import com.jqyd.manager.TabTitle; import com.jqyd.model.EmpsModule; import com.jqyd.model.MyPlanModule; import com.jqyd.shareInterface.Optdb_interfce; import com.jqyd.shareInterface.Optsharepre_interface; import com.jqyd.shareInterface.UpdataToServer; import android.app.Activity; import android.app.AlertDialog; import android.app.DatePickerDialog; import android.app.Dialog; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.view.View; import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.DatePicker; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.Spinner; import android.widget.AdapterView.OnItemSelectedListener; public class Jhgl extends Activity implements OnClickListener { private Spinner jhlb; private EditText ksrq; private EditText jsrq; private EditText jhsl; private EditText customers; private EditText bz; private EditText sjr; private Button add; private Button add_cust; private Button up; private Button back; private LinearLayout jhsl_layout; private LinearLayout mbkh_layout; private LinearLayout sjr_layout; private Calendar c; private ArrayAdapter<String> adapter_jhlb=null; private Optsharepre_interface share_obj = null; private Optdb_interfce db = null; private int flag = 0;//0、开始日期1、结束日期 private MyApp myApp; private ArrayList<String> custIds = new ArrayList<String>(); private ArrayList<String> custNames = new ArrayList<String>(); private ArrayList<String> lxrTels = new ArrayList<String>(); private ArrayList<String> lxrTelAndNames = new ArrayList<String>(); private String cids = ""; private String tels = ""; private String names = ""; private String guids = ""; private int jhsl_cust = 0; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.jhap); jhlb = (Spinner) this.findViewById(R.id.jhlb); ksrq = (EditText) this.findViewById(R.id.ksrq); jsrq = (EditText) this.findViewById(R.id.jsrq); jhsl = (EditText) this.findViewById(R.id.jhsl); customers = (EditText) this.findViewById(R.id.customers); sjr = (EditText) this.findViewById(R.id.sjr); bz = (EditText) this.findViewById(R.id.bz); add = (Button) this.findViewById(R.id.add); add_cust = (Button) this.findViewById(R.id.add_cust); up = (Button) this.findViewById(R.id.up); back = (Button) this.findViewById(R.id.back); jhsl_layout = (LinearLayout) this.findViewById(R.id.jhsl_layout); mbkh_layout = (LinearLayout) this.findViewById(R.id.mbkh_layout); sjr_layout = (LinearLayout) this.findViewById(R.id.sjr_layout); sjr_layout.setVisibility(LinearLayout.VISIBLE); ksrq.setOnClickListener(this); jsrq.setOnClickListener(this); up.setOnClickListener(this); back.setOnClickListener(this); add_cust.setOnClickListener(this); add.setOnClickListener(this); myApp = (MyApp) this.getApplication(); init(); initEnter(); } //赋默认值 public void init(){ c = Calendar.getInstance(); //业务时间默认当天 Date date = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); String mDateTime1 = formatter.format(date); ksrq.setText(mDateTime1); jsrq.setText(mDateTime1); jhsl.setText("0"); ArrayList<String> jhlbList = new ArrayList<String>(); jhlbList.add("客户走访"); jhlbList.add("陌生拜访"); jhlbList.add("二次回访"); jhlbList.add("市场检查"); jhlbList.add("促销执行"); adapter_jhlb = new ArrayAdapter<String>(Jhgl.this, android.R.layout.simple_spinner_item, jhlbList); adapter_jhlb.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // 绑定适配器 jhlb.setAdapter(adapter_jhlb); jhlb.setOnItemSelectedListener(new OnItemSelectedListener(){ @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub if(jhlb.getSelectedItem().equals("陌生拜访")){ jhsl_layout.setVisibility(LinearLayout.VISIBLE); mbkh_layout.setVisibility(LinearLayout.GONE); }else{ jhsl_layout.setVisibility(LinearLayout.GONE); mbkh_layout.setVisibility(LinearLayout.VISIBLE); } } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub }}); } @Override public void onClick(View v) { // TODO Auto-generated method stub if(v == ksrq){ flag = 0; getDate(); }else if(v == jsrq){ flag = 1; getDate(); }else if(v == up){ if(jhlb.getSelectedItem().equals("陌生拜访") && jhsl.getText().toString().equals("")){ warnTell("请输入计划数量!"); }else if(!jhlb.getSelectedItem().equals("陌生拜访") && customers.getText().toString().equals("")){ warnTell("请选择目标客户!"); }else{ if(!jhlb.getSelectedItem().equals("陌生拜访")){ jhsl_cust = custIds.size(); }else{ jhsl_cust = Integer.parseInt(jhsl.getText().toString()); } // db = new Optdb_interfce(Jhgl.this); share_obj = new Optsharepre_interface(Jhgl.this); //获得登录者姓名 //String userName = db.searchEmpName(share_obj.getDataFromPres("GUID")); //db.close_SqlDb(); MyPlanModule plan = new MyPlanModule(); plan.setCosim(share_obj.getDataFromPres("COSIM")); plan.setRegsim(tels); plan.setGuid(guids); plan.setGguid(share_obj.getDataFromPres("GGUID")); plan.setZdmc(names); plan.setBz(bz.getText().toString()); plan.setJhlb(jhlb.getSelectedItemPosition()+1); plan.setJhsl(jhsl_cust); plan.setKsrq(ksrq.getText().toString()); plan.setJsrq(jsrq.getText().toString()); plan.setCustnames(customers.getText().toString()); new JhapThread(plan).start(); } }else if(v == back){ finish(); }else if(v == add_cust){ myApp.setModuleName("jhgl_cust"); startActivity(new Intent().setClass(Jhgl.this, TabTitle.class)); finish(); }else if(v == add){ startActivity(new Intent().setClass(Jhgl.this, MyOneData.class).putExtra("moduleName", "jhgl_emp_list")); finish(); } } /** * 判断是否二次进入当前界面 */ public void initEnter(){ //System.out.println("二次进宫-----------------"+myApp.getModuleName()); //System.out.println("二次进宫-----------------"+myApp.getLxrTel().size()+"---------"+myApp.getLxrTelAndName().size()); String showLxrs = ""; String showCusts = ""; //if(myApp.getIsInit() == 1){//二次进入 // if(myApp.getModuleName().equals("jh_cust")){ //为客户赋值 custIds = myApp.getCustId(); custNames = myApp.getCustIdAndName(); if(custIds.size()>0){ for(int i=0;i<custNames.size();i++){ showCusts+=custNames.get(i)+","; } for(int i=0;i<custIds.size();i++){ cids+=custIds.get(i)+","; } showCusts = showCusts.substring(0, showCusts.length()-1); cids = cids.substring(0, cids.length()-1); if(!customers.getText().toString().equals("")){ showCusts = customers.getText().toString()+","+showCusts; } customers.setText(showCusts); } //}else if(myApp.getModuleName().equals("jh_emp")){ //为员工赋值 lxrTels = myApp.getLxrTel(); lxrTelAndNames = myApp.getLxrTelAndName(); if(lxrTels.size()>0){ for(int i=0;i<lxrTelAndNames.size();i++){ showLxrs+=lxrTelAndNames.get(i)+","; } //根据员工手机号码查询员工guid,姓名 db = new Optdb_interfce(Jhgl.this); for(int i=0;i<lxrTels.size();i++){ tels+=lxrTels.get(i)+","; ArrayList<Object> list = db.searchEmps("EMPS",lxrTels.get(i)); for(int k=0;k<list.size();k++){ EmpsModule emp = (EmpsModule) list.get(k); guids+=emp.getGuid()+","; names+=emp.getXm()+","; } } showLxrs = showLxrs.substring(0, showLxrs.length()-1); tels = tels.substring(0, tels.length()-1); guids = guids.substring(0, guids.length()-1); names = names.substring(0, names.length()-1); if(!sjr.getText().toString().equals("")){ showLxrs = sjr.getText().toString()+","+showLxrs; } sjr.setText(showLxrs); } //} //} } //弹出日期框 public void getDate() { new DatePickerDialog(Jhgl.this, new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker arg0, int year, int month, int date) { // TODO Auto-generated method stub String m = ""; String d = ""; if ((month + 1) < 10) { m = "0" + (month + 1); } else { m = (month + 1) + ""; } if (date < 10) { d = "0" + date; } else { d = date + ""; } String time = year + "-" + m + "-" + d; if(flag == 0){ ksrq.setText(time); }else{ jsrq.setText(time); } } }, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)).show(); } /** * 清空历史数据 */ public void cheanHisdatas(){ sjr.setText(""); customers.setText(""); bz.setText(""); init(); } /** * 非空警告提示 */ public void warnTell(String message){ new AlertDialog.Builder(Jhgl.this).setTitle("警告").setMessage(message) .setPositiveButton("确定", null).show(); } /** * 计划安排线程 * @author Administrator * */ class JhapThread extends Thread { private MyPlanModule plan; public JhapThread(MyPlanModule plan) { this.plan = plan; } @Override public void run() { // TODO Auto-generated method stub super.run(); Looper.prepare(); Message message = new Message(); message.what = 1; myHander.sendMessage(message); Message message2 = new Message(); message2.what = 2; Bundle bundle = new Bundle(); JSONObject object = new JSONObject(); try { object.put("cosim", plan.getCosim()); object.put("regsim", plan.getRegsim()); object.put("guid", plan.getGuid()); object.put("gguid", plan.getGguid()); object.put("zdmc", plan.getZdmc()); object.put("bz", plan.getBz()); object.put("jhlb", plan.getJhlb()); object.put("jhsl", plan.getJhsl()); object.put("ksrq", plan.getKsrq()); object.put("jsrq", plan.getJsrq()); object.put("custnames", plan.getCustnames()); object.put("custids", cids); object.put("zguid", new Optsharepre_interface(Jhgl.this).getDataFromPres("GUID")); object.put("sjzg", ""); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // 请求服务器 String result = new UpdataToServer(Jhgl.this).dataToServer("JHGL", object); if (result != null && !result.equals("-1")) { try { JSONObject obj = new JSONObject(result); String res = obj.getString("result"); if (res.equals("0")) { bundle.putString("msg","上传成功"); } else { bundle.putString("msg","上传失败!"); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }else { bundle.putString("msg","对不起,网络连接失败!"); } message2.setData(bundle); myHander.sendMessage(message2); Looper.loop(); } } Handler myHander = new Handler() { @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub super.handleMessage(msg); switch (msg.what) { case 1: showDialog(1); break; case 2: removeDialog(1); Bundle data = msg.getData(); String message = data.getString("msg"); showToast(message); break; } } }; /** * 结果显示 * * @param message */ public void showToast(final String message) { new AlertDialog.Builder(Jhgl.this).setTitle("提示").setMessage(message) .setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if(message.contains("成功")){ cheanHisdatas(); } } }).show(); } @Override protected Dialog onCreateDialog(int id) { // TODO Auto-generated method stub ProgressDialog dialog = new ProgressDialog(Jhgl.this); dialog.setIndeterminate(true); dialog.setCancelable(false); switch (id) { case 1: dialog.setMessage("正在上传,请稍候……"); break; } return dialog; } }