Пример #1
0
        //发送盘点结果
        private void menuItem4_Click(object sender, EventArgs e)
        {
            //发送前先将读取标签的操作停止
            if (this.menuItem5.Checked == true)//正在循环读取标签
            {
                __timer.Enabled        = false;
                this.menuItem5.Checked = false;
            }

            string       strTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            List <tagID> list    = new List <tagID>();

            foreach (System.Windows.Forms.ListViewItem lvi in this.listView1.Items)
            {
                if (lvi.Checked == true)
                {
                    tagID tag1 = new tagID(lvi.Text, strTime, InventoryCommand.盘点);
                    list.Add(tag1);
                }
            }

            string         jsonString = tagID.toJSONFromList(list);
            HttpWebConnect helper     = new HttpWebConnect();

            helper.RequestCompleted += new deleGetRequestObject(helper_RequestCompleted);
            string url = RestUrl.addScanedTags;

            helper.TryPostData(url, jsonString);
        }
Пример #2
0
        void helper_RequestCompleted(object o)
        {
            deleControlInvoke dele = delegate(object ol)
            {
                string    tags  = (string)ol;
                object    olist = fastJSON.JSON.Instance.ToObjectListDic(tags);
                ArrayList array = (ArrayList)olist;
                bool      bOK   = true;
                for (int i = 0; i < array.Count; i++)
                {
                    Dictionary <string, object> dicTemp = (Dictionary <string, object>)array[i];
                    tagID t = tagID.createInstance(dicTemp);
                    if (t.state != "ok")
                    {
                        bOK = false;
                        MessageBox.Show("发送扫描数据失败,请重试!", "信息提示");
                        break;
                    }
                }

                if (bOK == true)
                {
                    MessageBox.Show("发送扫描数据成功!", "信息提示");
                }
            };

            this.Invoke(dele, o);
        }
Пример #3
0
        void helper_RequestCompleted_getScanTags(object o)
        {
            string strTags = (string)o;

            Debug.WriteLine(
                string.Format("frmStorageManage.helper_RequestCompleted_getScanTags  ->  = {0}"
                              , strTags));
            object            olist = fastJSON.JSON.Instance.ToObjectList(strTags, typeof(List <tagID>), typeof(tagID));
            deleControlInvoke dele  = delegate(object ol)
            {
                List <tagID> tagList = (List <tagID>)ol;
                if (tagList.Count > 0)
                {
                    tagID t = tagList[tagList.Count - 1];
                    this.__lastTagTimeStamp = t.startTime;
                    for (int i = 0; i < tagList.Count; i++)
                    {
                        tagID temp = tagList[i];
                        LinkEPCToProduct(temp.tag);
                    }
                }
            };

            this.Invoke(dele, olist);
        }
Пример #4
0
        void addTagsToServer(string tag)
        {
            //Debug.WriteLine("addTagsToServer -> " + tag);
            //读到一个新标签后,检查缓存池,会有三种情况:
            //1 该epc尚未加入到缓存池中
            //2 该epc已经加入到缓存池中,但是在缓冲时间之内
            //3 epc在缓冲池中,且储存时间已经超过缓冲时间
            DataRow[] rows  = null;
            TimeSpan  tsGap = DateTime.Now - staticClass.timeBase;
            long      gap   = (long)tsGap.TotalMilliseconds - this.__reader_info.interval; //距离现在差距缓冲时间间隔的时间点

            rows = __dtTagTemp.Select("time > " + gap + " and tag = '" + tag + "'");       //只要大于这个时间点说明离现在近
            if (rows.Length > 0)                                                           //说明tag等于epc的那个标签已经尚在缓冲时间之内,不能重新上传
            {
                return;
            }
            else
            {
                //如果上不存在epc,则要添加到缓冲池中
                rows = null;
                rows = this.__dtTagTemp.Select("tag = '" + tag + "'");
                if (rows.Length <= 0)
                {
                    this.__dtTagTemp.Rows.Add(new object[] { tag, tsGap.TotalMilliseconds });
                }
                else
                {
                    //这里还剩下的只有 已经加入了缓冲池,但是已经超过缓冲时间的标签,因此只需更新读取时间即可
                    rows[0]["time"] = tsGap.TotalMilliseconds;//记录从应用启动到现在的毫秒数
                }
            }
            tagID  tagIDTag = new tagID(tag, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), this.__reader_info.flag);
            string log      = "发送标签 " + tagIDTag.tag + " " + tagIDTag.startTime;

            this.appendLog(log);

            string         jsonString = fastJSON.JSON.Instance.ToJSON(tagIDTag);
            HttpWebConnect helper     = new HttpWebConnect();

            helper.RequestCompleted += new deleGetRequestObject(helper_RequestCompleted);
            string url = RestUrl.addScanedTag;

            helper.TryPostData(url, jsonString);
            //foreach (string flag in this.flagList)
            //{
            //    //Debug.WriteLine(
            //    //    string.Format("frmMain.addTagstoServer  -> web add  = flag = {0}  epc = {1}"
            //    //    , flag, tag));
            //    tagID tagIDTag = new tagID(tag, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), flag);
            //    string log = "发送标签 " + tagIDTag.tag + " " + tagIDTag.startTime;
            //    this.appendLog(log);

            //    string jsonString = fastJSON.JSON.Instance.ToJSON(tagIDTag);
            //    HttpWebConnect helper = new HttpWebConnect();
            //    helper.RequestCompleted += new deleGetRequestObject(helper_RequestCompleted);
            //    string url = RestUrl.addScanedTag;
            //    helper.TryPostData(url, jsonString);
            //}
        }
Пример #5
0
        void helper_RequestCompleted(object o)
        {
            deleControlInvoke dele = delegate(object otag)
            {
                try
                {
                    tagID  tag = (tagID)fastJSON.JSON.Instance.ToObject((string)otag, typeof(tagID));
                    string log = "发送标签 " + tag.tag + " 成功" + "  " + tag.startTime;

                    this.appendLog(log);
                }
                catch (System.Exception ex)
                {
                }
            };

            this.Invoke(dele, o);
        }
Пример #6
0
        void helper_RequestCompleted(object o)
        {
            deleControlInvoke dele = delegate(object otag)
            {
                try
                {
                    tagID tag = (tagID)fastJSON.JSON.Instance.ToObject((string)otag, typeof(tagID));
                    this.lblStatus.Text = "发送标签 " + tag.tag + " 成功" + "  " + tag.startTime;
                    Debug.WriteLine("helper_RequestCompleted -> " + this.lblStatus.Text);

                    this.appendLog(this.lblStatus.Text);
                }
                catch (System.Exception ex)
                {
                }
            };

            this.Invoke(dele, o);
        }
Пример #7
0
        static void Main(string[] args)
        {
            //unitTestClass ucreated = Activator.CreateInstance<unitTestClass>();
            //Type type = typeof(unitTestClass);
            //FieldInfo[] fi = type.GetFields(BindingFlags.Public | BindingFlags.Instance);
            //foreach (FieldInfo f in fi)
            //{
            //    Console.WriteLine("fieldInfo name -> {0} type -> {1}", f.Name, f.FieldType);
            //}

            unitTestClass u          = new unitTestClass("c1", 2);
            string        jsonString = fastJSON.JSON.Instance.ToJSON(u);

            Debug.WriteLine(jsonString);

            List <tagID> tagList = new List <tagID>();
            tagID        t1      = new tagID("t1", "111", "cmd");
            tagID        t2      = new tagID("t2", "111", "cmd");

            tagList.Add(t1);
            tagList.Add(t2);
            string tagJson1          = tagID.toJSONFromList(tagList);
            string tagJson           = fastJSON.JSON.Instance.ToJSON(tagList);
            List <unitTestClass> ltc = new List <unitTestClass>();

            ltc.Add(new unitTestClass("l1", 1));
            ltc.Add(new unitTestClass("l2", 2));
            ltc.Add(new unitTestClass("l3", 3));
            ltc.Add(new unitTestClass("l4", 4));
            string listJsonString = fastJSON.JSON.Instance.ToJSON(ltc);

            Debug.WriteLine(listJsonString);

            string jsons = "{\"name\":\"c2\",\"count\":20}";
            object o     = fastJSON.JSON.Instance.ToObject(jsons, typeof(unitTestClass));
            Dictionary <string, object> dic = (Dictionary <string, object>)o;

            foreach (KeyValuePair <string, object> kvp in dic)
            {
                Console.WriteLine("Key = {0}, Value = {1}",
                                  kvp.Key, kvp.Value);
            }
            unitTestClass u1 = unitTestClass.createUnitTestClass(dic);


            string    listJsons = "[{\"name\":\"l1\",\"count\":1},{\"name\":\"l2\",\"count\":2},{\"name\":\"l3\",\"count\":3},{\"name\":\"l4\",\"count\":4}]";
            object    olist     = fastJSON.JSON.Instance.ToObjectListDic(listJsons);
            ArrayList array     = (ArrayList)olist;

            for (int i = 0; i < array.Count; i++)
            {
                Dictionary <string, object> dicTemp = (Dictionary <string, object>)array[i];
                foreach (KeyValuePair <string, object> kvp in dicTemp)
                {
                    Console.WriteLine("Key = {0}, Value = {1}",
                                      kvp.Key, kvp.Value);
                }
            }


            //unitTestClass u2 = fastJSON.JSON.Instance.ToObject<unitTestClass>(jsons);
            // unitTestClass u2 = (unitTestClass)o;
            //Debug.WriteLine(u2.name);
            //Debug.WriteLine(u2.count);
            Console.Read();
        }