这两天来做一个:利用RFID管理样品安卓版的样品借用与归还的功能

这两天来做一个:利用RFID管理样品安卓版的样品借用与归还的功能场景:最近在做婚纱公司服装的管理项目,RFID标签是做成钮扣式的,直接缝在服装上,然后利用PDA采集RFID标签来管理服装。

欢迎大家来到IT世界,在知识的湖畔探索吧!

场景:最近在做婚纱公司服装的管理项目,RFID标签是做成钮扣式的,直接缝在服装上,然后利用PDA(安卓系统,支持RFID、一維条码、二維条码采集)采集RFID标签来管理服装。前期已经做好了RFID绑定服装的功能。

需求:样品在借出去的时候要登录借用人、借用部门,样品信息(RFID码、样品代码、名称、号码、颜色等),审核人审核后,才可拿走样品;归还时登记样品信息。再出借时,如果样品的状态如果是出借状态,那么不能再出借,只能先归还再出借。

分析:

1、前端(PDA安卓版)做一个样品借用与归还采集的功能

2、后端(WEB)做一个查看样品借用与归还明细功能。并且支持手动的”审核”、”已确认归还”功能

功能实现:

今天我们先来做PDA端的功能。

——-一、PDA端—————————————————————————————————————

1、在layout下创建一个activity_sampleborrow.xml,界面如下

这两天来做一个:利用RFID管理样品安卓版的样品借用与归还的功能

PDA 借用与归还的界面

代码如下:我就直接复制粘贴了,格式好像有些变了

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="match_parent"    android:layout_height="match_parent">
    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content">
        <Button            android:id="@+id/btn_sampleborrow_back"            android:layout_width="30dp"            android:layout_height="40dp"            android:background="@android:color/black"            android:text="@string/btn_back"            android:textColor="@android:color/white" />
        <TextView            android:layout_width="match_parent"            android:layout_height="40dp"            android:background="@android:color/black"            android:gravity="center"            android:text="样品借用与归还"            android:textColor="@android:color/white" />
    </LinearLayout>

    <LinearLayout        android:layout_width="match_parent"        android:layout_height="30dp"        android:layout_marginLeft="5dp"        android:layout_marginRight="5dp"        android:layout_marginTop="5dp"        android:gravity="center_vertical">
        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="类型: " />
        <RadioGroup            android:id="@+id/rg_sampleborrow_borrow"            android:orientation="horizontal"            android:layout_width="match_parent"            android:layout_height="wrap_content">
            <RadioButton                android:id="@+id/rb_sampleborrow_borrow"                android:text="借用"                android:checked="true"                android:layout_width="120dp"                android:layout_height="wrap_content" />
            <RadioButton                android:id="@+id/rb_sampleborrow_return"                android:text="归还"                android:layout_width="wrap_content"                android:layout_height="wrap_content" />
        </RadioGroup>
    </LinearLayout>

    <View        android:layout_width="fill_parent"        android:layout_height="1dp"        android:layout_marginLeft="5dp"        android:layout_marginRight="5dp"        android:background="#aa000000" />

    <LinearLayout        android:layout_width="match_parent"        android:layout_height="40dp"        android:layout_marginLeft="5dp"        android:layout_marginRight="5dp"        android:gravity="center_vertical">
        <TextView          android:id="@+id/tv_sampleborrow_borrow"  android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="借用人: " />
        <EditText            android:id="@+id/tv_sampleborrow_borrowobj"            android:singleLine="true"            android:textSize="12dp"            android:selectAllOnFocus="true"            android:paddingLeft="15dp"            android:layout_width="match_parent"            android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout        android:layout_width="match_parent"        android:layout_height="40dp"        android:layout_marginLeft="5dp"        android:layout_marginRight="5dp"        android:gravity="center_vertical">
        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="借用部门: " />
        <EditText            android:id="@+id/tv_sampleborrow_dept"            android:singleLine="true"            android:textSize="12dp"            android:selectAllOnFocus="true"            android:paddingLeft="15dp"            android:layout_width="match_parent"            android:layout_height="wrap_content" />
    </LinearLayout>

    <View        android:layout_width="fill_parent"        android:layout_height="1dp"        android:layout_marginLeft="5dp"        android:layout_marginRight="5dp"        android:background="#aa000000" />

    <!--以下是扫描、取消扫描、正在上传、扫描列表  固定有 -->    
      <LinearLayout        android:layout_width="match_parent"        android:layout_height="35dp"        android:layout_marginLeft="5dp"        android:layout_marginRight="5dp"        android:gravity="center_vertical">
        <TextView            android:textColor="@android:color/holo_blue_dark"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="件数:" />
        <TextView            android:id="@+id/tv_sampleborrow_cnt"            android:textColor="@android:color/holo_blue_dark"            android:textStyle="bold"            android:layout_width="65dp"            android:layout_height="wrap_content" />
        <Button            android:id="@+id/btn_sampleborrow_scan"            android:layout_width="120dp"            android:layout_height="30dp"            android:background="@drawable/bnt_shape"            android:text="@string/btn_sacn_start"            android:textColor="@android:color/white" />
        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:gravity="right"            android:layout_marginLeft="17dp">
            <FrameLayout                android:layout_width="match_parent"                android:layout_height="wrap_content">
                <Button                    android:id="@+id/btn_sampleborrow_cancelscan"                    android:layout_width="65dp"                    android:layout_height="30dp"                    android:background="@drawable/bnt_shapemin"                    android:text="取消扫描"                    android:visibility="gone"                    android:textColor="#1C86EE" />
                <TextView                    android:id="@+id/tv_sampleborrow_upping"                    android:text="正在上传.."                    android:textColor="@android:color/holo_blue_dark"                    android:visibility="gone"                    android:layout_width="match_parent"                    android:layout_height="wrap_content" />
            </FrameLayout>
        </LinearLayout>
    </LinearLayout>

    <LinearLayout        android:layout_width="match_parent"        android:layout_height="match_parent"        android:background="#EEEEEE"        android:layout_marginLeft="5dp"        android:layout_marginRight="5dp"        android:orientation="vertical">
        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content">
            <TextView                android:id="@+id/tv_sampleborrow_id"                android:layout_width="85dp"                android:layout_weight="1"                android:layout_height="20dp"                android:textSize="10sp"                android:textColor="#ff444444"                android:gravity="center"                android:singleLine="true"                android:text="ID"                android:textStyle="bold"/>
            <TextView                android:id="@+id/tv_sampleborrow_epc"                android:layout_width="200dp"                android:layout_weight="1"                android:layout_height="20dp"                android:textSize="10sp"                android:textColor="#ff444444"                android:gravity="center"                android:singleLine="true"                android:text="RFID码"                android:textStyle="bold"/>
            <TextView                android:id="@+id/tv_sampleborrow_times"                android:layout_width="160dp"                android:layout_weight="1"                android:layout_height="20dp"                android:textSize="10sp"                android:textColor="#ff444444"                android:gravity="center"                android:singleLine="true"                android:text="次数"                android:textStyle="bold"/>
        </LinearLayout>
        <View            android:layout_width="fill_parent"            android:layout_height="1dip"            android:background="#ff555555" />
        <ListView            android:id="@+id/lst_sampleborrow"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:fadingEdge="none"            android:paddingLeft="3.0sp"            android:paddingRight="3.0sp"            android:scrollbars="vertical"            android:scrollingCache="false"            android:divider="#63a219"            android:dividerHeight="1px"            android:transcriptMode="alwaysScroll" />
    </LinearLayout>

</LinearLayout>

欢迎大家来到IT世界,在知识的湖畔探索吧!

2、在java下创建SampleBorrowActivity的Java Class文件,代码如下:

欢迎大家来到IT世界,在知识的湖畔探索吧!package com.android.scanlable;

import android.app.DatePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import com.android.scanlable.entity.User;
import com.android.scanlable.myclass.HttpConnSoap;
import com.android.scanlable.myclass.PubCls;
import com.rfid.trans.ReadTag;
import com.rfid.trans.TagCallback;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class SampleBorrowActivity extends AppCompatActivity implements View.OnClickListener {
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        try {
            mContext = this;
            setContentView(R.layout.activity_sampleborrow);

            //初始化UI
            InitUI();
        } catch (Exception e) {

        }
    }

    User user;
    TextView tvBorrow;
    EditText edBorrowObj;
    EditText edDept;
    RadioButton rbBorrow;
    RadioGroup rg;

    String strServerToCliet="";//服务器返回客户端   借用部门    
//--------------以下是扫描识别固定的参数------------------
    TextView tvCnt, tvUpping;
    Button btnScan, btnCancelScan;
    ListView lst;

    public static class InventoryTagMap {
        public String strEPC;
        public int antenna;
        public String strRSSI;
        public int nReadCount;
    }

    List<InventoryTagMap> data;
    static List<InventoryTagMap> lsTagList = new ArrayList<InventoryTagMap>();
    Map<String, Integer> dtIndexMap = new LinkedHashMap<String, Integer>();
    Handler mHandler;
    MyAdapter myAdapter;
    Context mContext;
    boolean isCanceled = true;

    static final int MSG_UPDATE_LISTVIEW = 0;
    static final int MSG_UPDATE_SUCCESS = 1;
    static final int MSG_UPPING_SHOW = 2;
    static final int MSG_UPPING_HIDE = 3;
    //-----------以下是扫描识别固定的参数-------------------------
    private void InitUI() {
        //获取上个页面传下来的 用户信息
        Bundle bundle = getIntent().getExtras();
        user = (User) bundle.getSerializable("user");

        //---------以下是扫描固定要用到的--------------------
        btnScan = findViewById(R.id.btn_sampleborrow_scan);
        btnScan.setOnClickListener(this);
        btnCancelScan = findViewById(R.id.btn_sampleborrow_cancelscan);
        btnCancelScan.setOnClickListener(this);

        lst = findViewById(R.id.lst_sampleborrow);
        tvCnt = findViewById(R.id.tv_sampleborrow_cnt);
        tvUpping=findViewById(R.id.tv_sampleborrow_upping);
        //---------以上是扫描固定要用到的--------------------
        findViewById(R.id.btn_sampleborrow_back).setOnClickListener(this);

        tvBorrow=findViewById(R.id.tv_sampleborrow_borrow);
        edBorrowObj=findViewById(R.id.tv_sampleborrow_borrowobj);
        edDept=findViewById(R.id.tv_sampleborrow_dept);

        rbBorrow=findViewById(R.id.rb_sampleborrow_borrow);
        rg = (RadioGroup) findViewById(R.id.rg_sampleborrow_borrow);
        //设置监听器
        rg.setOnCheckedChangeListener(new radioGroupListener());

        mHandler = new Handler() {

            @Override            public void handleMessage(Message msg) {
                // TODO Auto-generated method stub
                //if (isCanceled) return;
                switch (msg.what) {
                    case MSG_UPDATE_LISTVIEW:
                        data = lsTagList;
                        if (myAdapter == null) {
                            myAdapter = new MyAdapter(SampleBorrowActivity.this, new ArrayList(data));
                            lst.setAdapter(myAdapter);
                        } else {
                            myAdapter.mList = new ArrayList(data);
                        }
                        tvCnt.setText(String.valueOf(myAdapter.getCount()));
                        myAdapter.notifyDataSetChanged();
                        break;
                    case MSG_UPDATE_SUCCESS:
                        cancelScan();
                        edDept.setText(strServerToCliet);
                        tvUpping.setVisibility(View.GONE);
                        break;
                    case MSG_UPPING_SHOW:
                        tvUpping.setVisibility(View.VISIBLE);
                        btnCancelScan.setVisibility(View.GONE);
                        break;
                    case MSG_UPPING_HIDE:
                        tvUpping.setVisibility(View.GONE);
                        btnCancelScan.setVisibility(View.VISIBLE);
                        Log.i("-----------结束隐藏------------", "-----------------------");
                        break;
                    default:
                        break;
                }
                super.handleMessage(msg);
            }

        };
    }

    @Override    public void onClick(View v) {
        Intent intent;
        switch (v.getId()) {
            case R.id.btn_sampleborrow_back:
                //返回
                cancelScan();
                finish();
                break;
            case R.id.btn_sampleborrow_scan:
                //扫描
                scan();
                break;
            case R.id.btn_sampleborrow_cancelscan:
                //取消扫描
                cancelScan();
                tvCnt.setText("0");
                break;
        }
    }

    private void scan() {
        try {
            if ( rbBorrow.isChecked() && edBorrowObj.getText().toString() == "" && edDept.getText().toString() == "") {
                Toast.makeText(getApplicationContext(), "借用人/借用部门不能为空", Toast.LENGTH_LONG).show();
                return;
            }

            if (btnScan.getText() == getString(R.string.btn_sacn_start)) {
                SharedPreferences sharedPreferences = getSharedPreferences("UHF", Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sharedPreferences.edit();
                editor.putBoolean("TID", PubCls.ScanTID);
                editor.commit();//同步提交到磁盘文件,因而会出现阻塞等的现象,如果要确保提交成功,尽量使用commit
                editor.apply();
                isCanceled = false;
                if (myAdapter != null) {
                    tvCnt.setText("0");
                    myAdapter.notifyDataSetChanged();
                    mHandler.removeMessages(MSG_UPDATE_LISTVIEW);
                    mHandler.sendEmptyMessage(MSG_UPDATE_LISTVIEW);
                }

                if (!rbBorrow.isChecked())//归还
                {
                    edDept.setText("");
                    edBorrowObj.setText("");
                }

                btnScan.setText(getString(R.string.btn_sacn_end));
                btnCancelScan.setVisibility(View.VISIBLE);
                lsTagList = new ArrayList<InventoryTagMap>();
                dtIndexMap = new LinkedHashMap<String, Integer>();
                MsgCallback callback = new MsgCallback();
                Reader.rrlib.SetCallBack(callback);
                Reader.rrlib.StartRead(mContext);
            } else {
                stopScan();
                //完成并上传
                Runnable run = new Runnable() {
                    @Override                    public void run() {
                        Looper.prepare();

                        AlertDialog.Builder isExit;
                        ArrayList<String> alParas = new ArrayList<String>();
                        ArrayList<String> alParaVs = new ArrayList<String>();
                        ArrayList<String> alResults = new ArrayList<String>();
                        alParas.clear();
                        alParaVs.clear();
                        alResults.clear();
                        try {
                            mHandler.sendEmptyMessage(MSG_UPPING_SHOW);

                            alParas.add("cBorrowObj");
                            alParaVs.add(edBorrowObj.getText().toString());
                            alParas.add("cDept");
                            alParaVs.add(edDept.getText().toString());
                            alParas.add("cOptUser");
                            alParaVs.add(user.getsUserCode());
                            alParas.add("bIsBorrow");
                            if (rbBorrow.isChecked())
                                alParaVs.add("1");
                            else                                alParaVs.add("0");

                            alParas.add("cRfidCodes");
                            String sCode = "";
                            for (int ii = 0; ii < lsTagList.size(); ii++) {
                                Log.i("--------------ID " + String.valueOf(ii) + "=----------", lsTagList.get(ii).strEPC);
                                sCode += lsTagList.get(ii).strEPC + ",";
                            }
                            sCode = sCode.substring(0, sCode.length() - 1);//去掉最后的逗号
                            alParaVs.add(sCode);

                            HttpConnSoap soap = new HttpConnSoap();
                            alResults = soap.GetWebServreString("updataSampleBorrow", alParas, alParaVs);
                            if (alResults.size() > 0) {
                                String strResults = alResults.get(0);//"0|上传成功 或 -1|上传失败
                                String[] strResult = strResults.split("\\|");
                                if (strResult[0].equals("-1")) {
                                    isExit = new AlertDialog.Builder(SampleBorrowActivity.this);
                                    isExit.setMessage(strResult[1]);
                                    isExit.setPositiveButton("确定", null);
                                    isExit.show();
                                    mHandler.sendEmptyMessage(MSG_UPPING_HIDE);
                                    //Toast.makeText(getApplicationContext(), strResult[1], Toast.LENGTH_LONG).show(); 
                                } else {
                                    //上传成功
                                    strServerToCliet=strResult[2].toString()+","+strResult[3].toString();
                                    mHandler.sendEmptyMessage(MSG_UPDATE_SUCCESS);
                                    Toast.makeText(getApplicationContext(), strResult[1], Toast.LENGTH_LONG).show();
                                }

                            } else {
                                mHandler.sendEmptyMessage(MSG_UPPING_HIDE);
                                //Toast.makeText(getApplicationContext(), "上传失败,请检查网络环境及其他", Toast.LENGTH_LONG).show();
                                isExit = new AlertDialog.Builder(SampleBorrowActivity.this);
                                isExit.setMessage("上传失败,请检查网络环境及其他");
                                isExit.setPositiveButton("确定", null);
                                isExit.show();
                            }
                        } catch (Exception ex) {
                            mHandler.sendEmptyMessage(MSG_UPPING_HIDE);
                            isExit = new AlertDialog.Builder(SampleBorrowActivity.this);
                            isExit.setMessage("上传错误:" + ex.getMessage());
                            isExit.setPositiveButton("确定", null);
                            isExit.show();
                        }

                        Looper.loop();
                    }
                };

                new Thread(run).start();
            }
        } catch (Exception e) {
            cancelScan();
            Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
        }
    }

    private void cancelScan() {
        try {
            Log.i("---------cancelScan---stop1---------------", "cancelScan:");
            stopScan();
            Log.i("---------cancelScan---stop2---------------", "cancelScan:");
            btnScan.setText(getString(R.string.btn_sacn_start));
            btnCancelScan.setVisibility(View.GONE);
        } catch (Exception e) {
            Log.i("---------cancelScan---stop3---------------", e.getMessage());
            Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
        }
    }

    private void stopScan() {
        Reader.rrlib.StopRead();
        isCanceled = true;
    }

    //-------以下是扫描固定要用到的----------------
   class MyAdapter extends BaseAdapter {

        private Context mContext;
        private List<InventoryTagMap> mList;
        private LayoutInflater layoutInflater;

        public MyAdapter(Context context, List<InventoryTagMap> list) {
            mContext = context;
            mList = list;
            layoutInflater = LayoutInflater.from(context);
        }

        @Override        public int getCount() {
            // TODO Auto-generated method stub
            return mList.size();
        }

        @Override        public Object getItem(int position) {
            // TODO Auto-generated method stub
           return mList.get(position);
        }

        @Override        public long getItemId(int arg0) {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override        public View getView(int position, View view, ViewGroup viewParent) {
            // TODO Auto-generated method stub
            ItemView iv = null;
            if (view == null) {
                iv = new ItemView();
                view = layoutInflater.inflate(R.layout.list, null);
                iv.tvId = (TextView) view.findViewById(R.id.id_text);
                iv.tvEpc = (TextView) view.findViewById(R.id.epc_text);
                iv.tvTime = (TextView) view.findViewById(R.id.times_text);
                ////iv.tvRssi = (TextView) view.findViewById(R.id.rssi_text);//
                // iv.tvAnt = (TextView)view.findViewById(R.id.ant_text);
                view.setTag(iv);
            } else {
                iv = (ItemView) view.getTag();
            }
            String epc = mList.get(position).strEPC;
            Integer findIndex = dtIndexMap.get(epc);
            if (findIndex != null) {
                iv.tvId.setText(String.valueOf(findIndex + 1));
                iv.tvEpc.setText(epc);
                iv.tvTime.setText(String.valueOf(mList.get(position).nReadCount));
                ////iv.tvRssi.setText(mList.get(position).strRSSI);//
               /*int ant = mList.get(position).antenna; 
                String str = Integer.toBinaryString(ant);
                String temp = str;
                for(int m=0;m<8-str.length();m++)
                {
                		temp="0"+temp;
                } 
                iv.tvAnt.setText(temp);*/ 
            }

            return view;
        }

        public class ItemView {
            TextView tvId;
            TextView tvEpc;
            TextView tvTime;
            TextView tvRssi;
            TextView tvAnt;
        }
    }
    
    class radioGroupListener implements OnCheckedChangeListener {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            // 选中状态改变时被触发
            switch (checkedId) {
                case R.id.rb_sampleborrow_borrow:
                    // 当用户选择借用
                    tvBorrow.setText("借用人");
                    break;
                case R.id.rb_sampleborrow_return:
                    // 当用户选择归还
                    tvBorrow.setText("归还人");
                    break;
            }
        }
    }

    public class MsgCallback implements TagCallback {
        @Override        public void tagCallback(ReadTag arg0) {
            // TODO Auto-generated method stub
            String epc = arg0.epcId.toUpperCase();
            InventoryTagMap m;
            Reader.rrlib.beginSound(true);
            Integer findIndex = dtIndexMap.get(epc);
            if (findIndex == null) {
                dtIndexMap.put(epc, dtIndexMap.size());
                m = new InventoryTagMap();
                m.strEPC = epc;
                m.antenna = arg0.antId;
                m.strRSSI = String.valueOf(arg0.rssi);
                m.nReadCount = 1;
                //dtIndexMa
                lsTagList.add(m);
            } else {
                m = lsTagList.get(findIndex);
                m.antenna |= arg0.antId;
                m.nReadCount++;
                m.strRSSI = String.valueOf(arg0.rssi);
            }
            mHandler.removeMessages(MSG_UPDATE_LISTVIEW);
            mHandler.sendEmptyMessage(MSG_UPDATE_LISTVIEW);
        }

        @Override        public int tagCallbackFailed(int reason) {
            // TODO Auto-generated method stub
            return 0;
        }
    }
    //-------以上是扫描固定要用到的----------------
   //-----------以下为隐藏软键盘-------------------------------
  @Override    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            View v = getCurrentFocus();
            if (isShouldHideKeyboard(v, ev)) {
                hideKeyboard(v.getWindowToken());
            }
        }
        return super.dispatchTouchEvent(ev);
    }

     /**
      * 根据EditText所在坐标和用户点击的坐标相对比,来判断是否隐藏键盘,因为当用户点击EditText时则不能隐藏
      *
      * @param v
      * @param event
      * @return
      */
   private boolean isShouldHideKeyboard(View v, MotionEvent event) {
        if (v != null && (v instanceof EditText)) {
            int[] l = {0, 0};
            v.getLocationInWindow(l);
            int left = l[0],
                    top = l[1],
                    bottom = top + v.getHeight(),
                    right = left + v.getWidth();
            if (event.getX() > left && event.getX() < right
                    && event.getY() > top && event.getY() < bottom) {
                // 点击EditText的事件,忽略它。
                return false;
            } else {
                return true;
            }
        }
        // 如果焦点不是EditText则忽略,这个发生在视图刚绘制完,第一个焦点不在EditText上,和用户用轨迹球选择其他的焦点
       return false;
    }

    /**
    * 获取InputMethodManager,隐藏软键盘
    *
    * @param token
    */
  private void hideKeyboard(IBinder token) {
        if (token != null) {
            InputMethodManager im = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            im.hideSoftInputFromWindow(token, InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }

}

3、在Webservice下添加updataSampleBorrow过程,代码如下:

[WebMethod(Description = "上传样品借用及归还数据,返回 -1|提示信息 或者 0|上传成功|借用部门")]
        public string updataSampleBorrow(string cBorrowObj, string cDept, string cOptUser, string bIsBorrow, string cRfidCodes)
        {
            //cRfidCodes用逗号隔开
            try
            {
                List<string> lstSql = new List<string>();
                string[] cRfidCode = cRfidCodes.Split(',');
                sbWriteLog = new StringBuilder();
                DbHelper db = new DbHelper();
                string str = "";

                sbWriteLog.AppendLine("------" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "--开始-----------------");
                for (int i = 0; i < cRfidCode.Length; i++)
                {
                    if (bIsBorrow == "1")//借用
                    {
                        //查找是否已绑定服装信息
                        sSql = "select cFzCode,cLastUseState from bs_RfidCodeInfo where cRfidCode='" + cRfidCode[i] + "'";
                        DataTable dtrfid = new DataTable();
                        dtrfid = db.getDataTable(sSql);
                        if (dtrfid == null || dtrfid.Rows.Count <= 0)
                            return "-1|ID= " + (i + 1).ToString() + " ,RFID码=\r\n" + cRfidCode[i] + "\r\n未绑定服装信息,不可出借";

                        if (dtrfid.Rows[0]["cLastUseState"].ToString() == "出借中")
                            return "-1|ID= " + (i + 1).ToString() + " ,RFID码=\r\n" + cRfidCode[i] + "\r\n状态为未归还,请先确认已归还,再出借";

                        //查找是否有出借信息
                        sSql = "select 1 from si_SampleBorrow where cRfidCode='" + cRfidCode[i] + "' and isnull(cReturnObj,'')='' ";
                        DataTable dt = new DataTable();
                        dt = db.getDataTable(sSql);
                        if (dt != null && dt.Rows.Count > 0)
                            return "-1|ID= " + (i + 1).ToString() + " ,RFID码=\r\n" + cRfidCode[i] + "\r\n状态为未归还,请先确认已归还,再出借";

                        sSql = "insert into si_SampleBorrow(cRfidCode,cSamCode,iQty,cBorrowObj,dBorrowTime,cDept,iState,isReturn,cOptUser,dCreateTime) values("
                            + "'" + cRfidCode[i] + "',"
                            + "'" + dtrfid.Rows[0]["cFzCode"].ToString() + "',"
                            + "'1',"
                            + "'" + cBorrowObj + "',"
                            + "getdate(),"
                            + "'" + cDept + "',"
                            + "'待审核',"
                            + "'0',"
                            + "'" + cOptUser + "',"
                            + "getdate() "
                            + ")";
                        sbWriteLog.AppendLine(sSql);
                        lstSql.Add(sSql);

                        //更新RFID信息表的门店信息
                        sSql = "update bs_RfidCodeInfo set cLastUseState='出借中',dLastUseTime=getdate() where cRfidCode='" + cRfidCode[i] + "' ";
                        lstSql.Add(sSql);
                        sbWriteLog.AppendLine(sSql);

                        str = cDept;
                    }
                    else//归还
                    {
                        //查找是否有做出借动作
                        sSql = "select * from si_SampleBorrow where cRfidCode='" + cRfidCode[i] + "' and isnull(cReturnObj,'')='' ";
                        DataTable dt = new DataTable();
                        dt = db.getDataTable(sSql);
                        if (dt == null || dt.Rows.Count <= 0)
                            return "-1|ID= " + (i + 1).ToString() + " ,RFID码=\r\n" + cRfidCode[i] + "\r\n没有出借记录,无法归还,请核对再操作";

                        //更新出租记录
                        sSql = "update si_SampleBorrow set isReturn=1,iState='已归还',cReturnObj='" + cBorrowObj + "',dReturnTime=getdate() where cRfidCode='" + cRfidCode[i] + "' and isnull(cReturnObj,'')='' ";
                        lstSql.Add(sSql);
                        sbWriteLog.AppendLine(sSql);

                        //更新RFID信息表的门店信息
                        sSql = "update bs_RfidCodeInfo set cLastUseState='已归还',dLastUseTime=getdate() where cRfidCode='" + cRfidCode[i] + "' ";
                        lstSql.Add(sSql);
                        sbWriteLog.AppendLine(sSql);

                        str = dt.Rows[0]["cDept"].ToString();
                    }
                }

                if (db.executeSQLTran(lstSql) > 0)
                    return "0|上传成功|" + str;
                else
                {
                    writeLog("样品借用与归还", sbWriteLog.ToString());
                    return "-1|上传失败:写入数据库失败";
                }
            }
            catch (Exception ex)
            {
                sbWriteLog.AppendLine("------------错误信息-------------:" + ex.Message);
                writeLog("样品借用与归还", sbWriteLog.ToString());
                return "-1|" + ex.Message;
            }
        }

——-至此,PDA端的功能已全部实现————————————————————————————

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://itzsg.com/37881.html

(0)

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

联系我们YX

mu99908888

在线咨询: 微信交谈

邮件:itzsgw@126.com

工作时间:时刻准备着!

关注微信