/// <summary>
        /// Extracts a <see cref="DataPackageInfo"/> from an input stream.
        /// Throws if the data cannot be parsed.
        /// </summary>
        public override DataPackageInfo ParseInfo(Stream input)
        {
            DataPackageInfo ret = null;

            //StreamReader is left un-disposed (finalization does not close stream)
            var streamReader = new StreamReader(input);

            using (var jsonReader = new JsonTextReader(streamReader)) {
                jsonReader.CloseInput = false;

                ParseObject(jsonReader, new Dictionary <string, Func <JsonTextReader, ParsingContinuation> > {
                    { InformationPropertyName, r => {
                          ret = Json.Deserialize <DataPackageInfo>(r);
                          return(ParsingContinuation.Stop);
                      } }
                }, r => { });
            }

            if (ret == null)
            {
                throw new JsonSerializationException("JSON data did not contain package information");
            }

            return(ret);
        }
Пример #2
0
        //分析扫到的条烟是否在包中,接收到数据后的事件
        private void PackageOk(DataPackageInfo _code)
        {
            var code = _code.CodeData;

            if (code == "")
            {
                return;
            }


            var package = orderHandle.GetCurrentCustomerPackageShow();

            lock (lockkk)
            {
                package.ReadedCount++;
            }
            int index = 0;


            foreach (PickPackageDetail pd in package.PackageDetails)
            {
                if (code == pd.ProductID.Trim())
                {
                    this.PerformSafely(() => {
                        packageShowTable.Rows[index]["readed"] = (Convert.ToInt32(packageShowTable.Rows[index]["readed"].ToString()) + 1).ToString();
                    });

                    pd.Readed++;
                    break;
                }


                if (package.HasAbmormal && package.AbnormalreadCount < 3)
                {
                    lock (lockkk)
                    {
                        package.AbnormalreadCount++;
                    }
                }
            }



            if (package.ReadedCount >= package.CigaretteCount)
            {
                this.PerformSafely(() => {
                    listBoxMessageShow.Items.Clear();
                });

                Task.Factory.StartNew(() => {
                    foreach (PickPackageDetail temp in package.PackageDetails)
                    {
                        int result = temp.Quantity - temp.Readed;

                        ResultAnalysis(result, package.AbnormalreadCount, package.CigaretteCount, temp);
                    }
                    var pack = orderHandle.localDatabase.dataBase.Packages.FirstOrDefault(c => c.PickPackageID == package.PickPackageID);
                    foreach (PickPackageDetail temp in package.PackageDetails)
                    {
                        if (temp.Result == (int)ReadResult.LESS || temp.Result == (int)ReadResult.MORE)
                        {
                            pack.Result = (int)ReadResult.LESS;
                            orderHandle.localDatabase.dataBase.Entry(pack).State = System.Data.Entity.EntityState.Modified;
                            orderHandle.localDatabase.dataBase.SaveChanges();
                            break;
                        }
                        pack.Result = (int)ReadResult.OK;
                        orderHandle.localDatabase.dataBase.Entry(pack).State = System.Data.Entity.EntityState.Modified;
                        orderHandle.localDatabase.dataBase.SaveChanges();
                    }

                    OkNGFlag(package.CigaretteCount - package.CigaretteOKCount, package.AbnormalreadCount, package);
                });

                PackageMoveNext();
            }
        }