private bool IsLastDoc(TsImage tsImageInfo)
        {
            try
            {
                //  Get the LastDoc of the Batch string
                var sLastDocId = new StringBuilder();
                sLastDocId.Append(TsMemFiles.GetInt("Image", "Level4", 0, LastDocInfo));
                sLastDocId.Append("-");
                sLastDocId.Append(TsMemFiles.GetInt("Image", "Level3", 0, LastDocInfo));
                sLastDocId.Append("-");
                sLastDocId.Append(TsMemFiles.GetInt("Image", "Level2", 0, LastDocInfo));
                var sCurrentDocId = new StringBuilder();
                sLastDocId.Append(tsImageInfo.Level4);
                sLastDocId.Append("-");
                sLastDocId.Append(tsImageInfo.Level3);
                sLastDocId.Append("-");
                sLastDocId.Append(tsImageInfo.Level2);

                if (sLastDocId.Equals(sCurrentDocId))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// <para>To Retrieve Data:</para>
        /// <list>
        /// <item>Dim sValue1 As String = New String(_TSMemFiles.GetString("Field Data", "FIELD_NAME", "", pbstrBlob))</item>
        /// </list>
        /// <para>To Save Data:</para>
        /// <list>
        /// <item>_TSMemFiles.SetString("Field Data", "FIELD_NAME", "FIELD_VALUE", pbstrBlob)</item>
        /// </list>
        /// </summary>
        /// <param name="lType"></param>
        /// <param name="pbstrBlob">Our BLOB file with all our information</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public int TSDataLookup(int lType, ref string pbstrBlob)
        {
            var iResult = 0;
            ErrMsg = string.Empty;

            try
            {
                try
                {
                    //  Populate Batch Info
                    CurrentBatch = new TsBatch
                    {
                        BatchName = TsMemFiles.GetString("Batches", "BatchName", string.Empty, pbstrBlob),
                        BatchDesc = TsMemFiles.GetString("Batches", "BatchDesc", string.Empty, pbstrBlob),
                        BatchId = TsMemFiles.GetInt("Batches", "BatchID", 0, pbstrBlob),
                        JobId = TsMemFiles.GetInt("Batches", "JobID", 0, pbstrBlob),
                        BatchLocation = TsMemFiles.GetInt("Batches", "BatchLocation", 0, pbstrBlob),
                        WfStatus = TsMemFiles.GetInt("Batches", "WFStatus", 0, pbstrBlob),
                        TemplateBatchId = TsMemFiles.GetInt("Batches", "TemplateBatchID", 0, pbstrBlob),
                        TotalImages = TsMemFiles.GetInt("Batches", "TotalImages", 0, pbstrBlob),
                        AppStep = TsMemFiles.GetInt("Batches", "AppStep", 0, pbstrBlob),
                        WfStep = TsMemFiles.GetInt("Batches", "WFStep", 0, pbstrBlob)
                    };

                    //  Just run one time
                    if (TsFieldList == null && !string.IsNullOrEmpty(CurrentBatch.BatchName) && CurrentBatch.TemplateBatchId > 0)
                    {
                        TsFieldList = _tsRepo.GetJobFieldList(CurrentBatch.TemplateBatchId, TsCallbackHelper);
                        LastDocInfo = _tsRepo.GetTsLastDocInfo(CurrentBatch.BatchId);
                    }

                    //  Populate Image Info
                    CurrentImage = new TsImage
                    {
                        ImageId = TsMemFiles.GetInt("Image", "ImageID", 0, pbstrBlob),
                        ImageNo = TsMemFiles.GetInt("Image", "ImageNo", 0, pbstrBlob),
                        ImageName = TsMemFiles.GetString("Image", "ImageName", string.Empty, pbstrBlob),
                        ImagePath = TsMemFiles.GetString("Image", "ImagePath", string.Empty, pbstrBlob),
                        LocalFile = TsMemFiles.GetString("Image", "ImageFile", string.Empty, pbstrBlob),
                        ImageType = TsMemFiles.GetInt("Image", "ImageType", 0, pbstrBlob),
                        Level1 = TsMemFiles.GetInt("Image", "Level1", 0, pbstrBlob),
                        Level2 = TsMemFiles.GetInt("Image", "Level2", 0, pbstrBlob),
                        Level3 = TsMemFiles.GetInt("Image", "Level3", 0, pbstrBlob),
                        Level4 = TsMemFiles.GetInt("Image", "Level4", 0, pbstrBlob),
                        Level5 = TsMemFiles.GetInt("Image", "Level5", 0, pbstrBlob),
                        FormName = TsMemFiles.GetString("FormResults", "FormName", string.Empty, pbstrBlob),
                        FormDesc = TsMemFiles.GetString("FormResults", "FormDesc", string.Empty, pbstrBlob),
                        LastPage = TsMemFiles.GetInt("Image", "LastPage", 0, pbstrBlob)
                    };

                    //  Implement BLOB Write Functionality for testing.
                    if (Support.WriteBlob)
                    {
                        try
                        {
                            if (!Directory.Exists(Support.BlobPath))
                            {
                                Directory.CreateDirectory(Support.BlobPath);
                            }

                            if (lType < 100)
                                File.WriteAllText(Path.Combine(Support.BlobPath, string.Format("Blob_{0}_{1}.ini", CurrentImage.ImageId.ToString().PadLeft(4, '0'), lType)), pbstrBlob);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

                switch (lType)
                {
                    case TSBATCH_OPEN:
                        //implement your functionality

                        break;
                    case TSBATCH_PROCESSREADY:
                        //implement your functionality

                        break;
                    case TSFIELD_CHECK:
                        //implement your functionality

                        break;
                    case TSFIELD_CORRECT:
                        //implement your functionality

                        break;
                    case TSFIELD_SHORTCUT:
                        //implement your functionality

                        break;
                    case TSFIELD_ACTIVATE:
                        //implement your functionality

                        break;
                    case TSFIELD_DEACTIVATE:
                        //implement your functionality

                        break;
                    case TSDATASET_LOAD:
                        //implement your functionality
                        MessageBox.Show(string.Format("BatchLocation: {0}", CurrentBatch.BatchLocation));
                        switch (CurrentBatch.BatchLocation)
                        {
                            case (int)ProcModule.AI:

                                break;
                            case (int)ProcModule.QA:
                            case (int)ProcModule.VR:
                                if (TsIndexPanel != null && CurrentImage.Level2 != PrevDocNo)
                                {
                                    TsIndexPanel.TsImageInfo = CurrentImage;

                                    //  Reset fields and update with values from TS

                                    PrevDocNo = CurrentImage.Level2;
                                    TsIndexPanel.LastFocusControl.Focus();
                                }
                                else if (TsIndexPanel != null)
                                {
                                    TsIndexPanel.TsImageInfo = CurrentImage;

                                    //  Make any needed changes to same document
                                }

                                var tsImageInfo = string.Empty;
                                var imageToGet = CurrentImage.ImageNo + 1;
                                var ret = TsCallbackHelper.GetImageInfoByNo(imageToGet, ref tsImageInfo);
                                MessageBox.Show(string.Format("GetImageInfo: {0}", ret));
                                File.WriteAllText(Path.Combine(Support.BlobPath, string.Format("ImageInfo_{0}_{1}.ini", CurrentImage.ImageId.ToString().PadLeft(4, '0'), imageToGet)), tsImageInfo);
                                break;
                        }
                        iResult = 1;
                        break;
                    case TSDATASET_CHECK:
                        //implement your functionality

                        break;
                    case TSDATASET_CORRECT:
                        //  Set common variables
                        iResult = 0;

                        //  Save whatever values we can
                        TsMemFiles.SetString("Lookup Actions", "MultiResults", "1", ref pbstrBlob);
                        //  Do not post any TS error messages.
                        TsMemFiles.SetString("Lookup Actions", "NoErrorMessage", "1", ref pbstrBlob);

                        //  *** Start work that happens in all modules ***

                        //  Get the FLDBarcode value
                        string FLDBarcode = Support.BlobReadField("FLDBarcode", pbstrBlob);

                        //  Start work per module
                        if (CurrentBatch != null)
                            switch (CurrentBatch.BatchLocation)
                            {
                                case 8:
                                case 16:
                                    //  AutoIndex

                                    break;
                                case 64:
                                    //  Verification

                                    break;
                                case 128:
                                    //  QA

                                    break;
                            }

                        iResult = 1;
                        break;
                    case TSDATASET_SAVE:
                        //implement your functionality

                        break;
                    case TSLOOKUP_UPDATE:
                        //implement your functionality

                        break;
                    case TSCUSTOM_API:
                        //implement your functionality
                        //iResult = TSCustomAPIProc(ref pbstrBlob);
                        break;
                }
            }
            catch (Exception ex)
            {
                iResult = -2;
                ErrMsg = string.Format("General Error During TSDataLookup: {0} - {1}", ex.Message, ex.StackTrace);
            }
            return (iResult);
        }