Esempio n. 1
0
        /// <summary>
        /// Add a tracker and serial number to the database.
        /// </summary>
        /// <param name="gatewayEntities"></param>
        /// <param name="macAddress">Expected to represent a 32-bit integer in hex format.</param>
        /// <param name="serialNumber"></param>
        /// <exception cref="System.FormatException">One or both parameters could not be parsed.</exception>
        /// <exception cref="System.OverflowException">One or both parameters represented numbers that were too large.</exception>
        static void AddTracker(
            Gateway.GatewayEntities gatewayEntities,
            DateTime batchDate,
            int tagNodeId,
            string macAddress,
            string serialNumber)
        {
            UInt64 macDummy;

            macDummy = UInt64.Parse(macAddress, NumberStyles.AllowHexSpecifier);
            // The parsed value is not used but we want the exception thrown for invalid format and overflow.

            var tracker = new Gateway.Tracker();

            tracker.MobileId = macAddress;
            gatewayEntities.AddToTrackers(tracker);
            gatewayEntities.SaveChanges();

            var serial = new Gateway.SerialNumber();

            serial.BatchDate          = batchDate;
            serial.TheSerialNumber    = serialNumber;
            serial.SerialNumberTypeId = tagNodeId;
            serial.TrackerId          = tracker.Id;

            gatewayEntities.AddToSerialNumbers(serial);

            gatewayEntities.SaveChanges();
        }
Esempio n. 2
0
        /// <summary>
        /// Send contents of serial, tracker model data directly to the printer.
        /// </summary>
        void PrintDirect()
        {
            Gateway.Tracker      tracker      = ViewModel.GatewayViewModel.Tracker;
            Gateway.SerialNumber serialNumber = ViewModel.GatewayViewModel.SerialNumber;

            List <Job> jobs = new List <Job>(1);

            jobs.Add(GetJobFromEntities(serialNumber, tracker));

            PrintJobs(jobs);
        }
Esempio n. 3
0
        /// <summary>
        /// Create a job entry from serial number and tracker data.
        /// </summary>
        /// <param name="serialNumber"></param>
        /// <param name="tracker"></param>
        /// <returns></returns>
        private Job GetJobFromEntities(Gateway.SerialNumber serialNumber, Gateway.Tracker tracker)
        {
            Job j = new Job();

            j.AssetId              = tracker.MobileId;
            j.AssetType            = (serialNumber.SerialNumberType == null) ? string.Empty : serialNumber.SerialNumberType.Name;
            j.BarCodeText          = GetBarCodeText(tracker.MobileId);
            j.BarCodeType          = Printing.BarCodeType.Code128;
            j.BatchDate            = serialNumber.BatchDate;
            j.DescriptiveTextLines = GetDescriptiveTextLines(ViewModel.GatewayViewModel);
            j.SerialNumber         = serialNumber.TheSerialNumber;

            return(j);
        }
Esempio n. 4
0
        /// <summary>
        /// Create a job entry from the serial, tracker information and add it to the job list.
        /// </summary>
        private void AddToQueue()
        {
            try
            {
                if (ViewModel == null)
                {
                    return;
                }

                Gateway.Tracker      tracker      = ViewModel.GatewayViewModel.Tracker;
                Gateway.SerialNumber serialNumber = ViewModel.GatewayViewModel.SerialNumber;

                if (tracker == null || serialNumber == null)
                {
                    return;
                }

                ViewModel.JobListViewModel.JobList.Add(GetJobFromEntities(serialNumber, tracker));
            }
            catch (Exception ex)
            {
                HandleGenericError(ex);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Look for and load serial, tracker information given a serial number.
        /// </summary>
        /// <returns>True if data was found, False otherwise.</returns>
        bool Search()
        {
            const string tag = ClassName + "Search:";

            string searchSerial = ViewModel.SearchViewModel.SerialNumberSearch.SerialNumber;

            Trace.TraceInformation(tag + "Serial={0}", searchSerial);

            Gateway.GatewayEntities gatewayEntities = GetGatewayEntities();

            if (gatewayEntities == null)
            {
                return(false);
            }

            var queryResult =
                from
                s in gatewayEntities.SerialNumbers
                where
                (s.TheSerialNumber == searchSerial)
                select
                s;

            Gateway.SerialNumber serialFound  = null;
            Gateway.Tracker      trackerFound = null;

            if (queryResult != null)
            {
                try
                {
                    serialFound = queryResult.First();
                }
                catch (InvalidOperationException)
                {
                    serialFound = null;
                }

                if (serialFound != null)
                {
                    var trackerQueryResult =
                        from
                        t in gatewayEntities.Trackers
                        where
                        (t.Id == serialFound.TrackerId)
                        select
                        t;

                    if (trackerQueryResult != null)
                    {
                        try
                        {
                            trackerFound = trackerQueryResult.First();
                        }
                        catch (InvalidOperationException)
                        {
                            Trace.TraceError(tag + "Tracker query returned 0 results.");
                            trackerFound = null;
                        }
                    }
                }
                else
                {
                    Trace.TraceInformation(tag + "Serial query returned 0 results.");
                }
            }
            else
            {
                Trace.TraceError(tag + "Serial query returned null.");
            }

            bool returnValue = false;

            if (serialFound == null || trackerFound == null)
            {
                MessageBox.Show(Local.Resources.NoRecordsFound, "", MessageBoxButton.OK, MessageBoxImage.Information);
                ViewModel.GatewayViewModel.SerialNumber = null;
                ViewModel.GatewayViewModel.Tracker      = null;
            }
            else
            {
                ViewModel.GatewayViewModel.SerialNumber = serialFound;
                ViewModel.GatewayViewModel.Tracker      = trackerFound;
                returnValue = true;
            }

            return(returnValue);
        }