protected bool initStorage()
        {
            String dbPath      = ReaderConfig.getInstance().DBPath.Trim();
            String storagePath = ReaderConfig.getInstance().StoragePath.Trim();

            if (dbPath == null || dbPath.Equals("") || !File.Exists(dbPath))
            {
                return(false);
            }
            if (storagePath == null || storagePath.Equals("") || !Directory.Exists(storagePath))
            {
                return(false);
            }

            InventoryStore inventoryStore = InventoryStore.getInstance();

            if (inventoryStore.InventoryDataTable == null || inventoryStore.InventoryDataTable.Rows.Count <= 0)
            {
                try
                {
                    inventoryStore.InventoryDataTable = DBInventoryRecords.listInventoryItems();
                    if (inventoryStore.InventoryDataTable.Rows.Count <= 0)
                    {
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        public void updateSelectedInventoryRecord(InventoryRecord selectedInventoryRecord)
        {
            InventoryRecord databindingRecord = InventoryStore.getInstance().SelectedInventoryRecord;

            if (selectedInventoryRecord != null)
            {
                databindingRecord.RecordId    = selectedInventoryRecord.RecordId;
                databindingRecord.Name        = selectedInventoryRecord.Name;
                databindingRecord.ChineseName = selectedInventoryRecord.ChineseName;
                databindingRecord.StudentNo   = selectedInventoryRecord.StudentNo;
                databindingRecord.Program     = selectedInventoryRecord.Program;
                databindingRecord.Title       = selectedInventoryRecord.Title;
                databindingRecord.GradYear    = selectedInventoryRecord.GradYear;
                databindingRecord.Degree      = selectedInventoryRecord.Degree;
                if (selectedInventoryRecord.Access != null && !"".Equals(selectedInventoryRecord.Access.Trim()))
                {
                    databindingRecord.Access = AccessModeMap[selectedInventoryRecord.Access];
                }
                databindingRecord.BoxNo        = selectedInventoryRecord.BoxNo;
                databindingRecord.Assign       = selectedInventoryRecord.Assign;
                databindingRecord.Received     = selectedInventoryRecord.Received;
                databindingRecord.ApprovalDate = selectedInventoryRecord.ApprovalDate;
                databindingRecord.Embargo      = selectedInventoryRecord.Embargo;
                databindingRecord.Release      = selectedInventoryRecord.Release;
            }
            else
            {
                databindingRecord.RecordId     = "";
                databindingRecord.Name         = "";
                databindingRecord.ChineseName  = "";
                databindingRecord.StudentNo    = "";
                databindingRecord.Program      = "";
                databindingRecord.Title        = "";
                databindingRecord.GradYear     = "";
                databindingRecord.Degree       = "";
                databindingRecord.Access       = "";
                databindingRecord.BoxNo        = 0;
                databindingRecord.Assign       = "";
                databindingRecord.Received     = null;
                databindingRecord.ApprovalDate = null;
                databindingRecord.Embargo      = "";
                databindingRecord.Release      = "";
            }
        }
Ejemplo n.º 3
0
        public void loadSelectedThesisFile()
        {
            ViewModel.getInstance().ProgressBarColor = Color.Yellow;
            MaskedFileInfo selectedFileInfo          = ViewModel.getInstance().SelectedThesisFile;
            ViewModel      viewModel = ViewModel.getInstance();

            if (selectedFileInfo != null)
            {
                viewModel.SaveButtonEnabled = false;
                ThesisRecord thesisRecord = MainThread.getInstance().ThesisRecord;
                thesisRecord.clearExtractedData();
                viewModel.SelectedThesisFile       = selectedFileInfo;
                viewModel.EnableContentFileListbox = false;
                thesisRecord.PdfTexts = "";

                PdfReaderHelper.getInstance().unload();
                string tempPdfFileName = FileUtils.CopyPdfToTemp(selectedFileInfo.FileInfo.FullName);
                loadPDF(tempPdfFileName);
                viewModel.EnableContentFileListbox = true;

                determineThesisRecord(thesisRecord);

                MainThread.getInstance().MatchingInventoryList.Clear();
                List <InventoryRecord> matchingInventoryRecords = getMatchingInventoryRecordList(thesisRecord);
                if (matchingInventoryRecords.Count > 0)
                {
                    foreach (InventoryRecord matchingRecord in matchingInventoryRecords)
                    {
                        MainThread.getInstance().MatchingInventoryList.Add(matchingRecord);
                    }
                    InventoryStore.getInstance().updateSelectedInventoryRecord(matchingInventoryRecords.First());
                }
                else
                {
                    InventoryStore.getInstance().updateSelectedInventoryRecord(null);
                }
                //markupRecordDifference();
                thesisRecord.EnableValidation = true;
                viewModel.SaveButtonEnabled   = true;
            }
            ViewModel.getInstance().ProgressPercentage += 50;
        }
        public void run()
        {
            this.started = true;

            ViewModel.getInstance().MenuButtonEnabled = true;
            ViewModel.getInstance().SaveButtonEnabled = false;

            if (String.IsNullOrWhiteSpace(ReaderConfig.getInstance().InstanceName))
            {
                var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                for (int i = 0; i < 2; i++)
                {
                    var random = new Random();
                    ReaderConfig.getInstance().InstanceName += chars[random.Next(chars.Length)];
                    Thread.Sleep(random.Next(500));
                }
                ReaderConfig.getInstance().SaveSettings();
            }

            if (String.IsNullOrWhiteSpace(ReaderConfig.getInstance().InstanceName))
            {
                while (!PdfReaderHelper.getInstance().ContainerPanel.IsHandleCreated)
                {
                    Thread.Sleep(100);
                }
                MessageBox.Show(PdfReaderHelper.getInstance().ContainerPanel, "Please enter a unique Instance Name!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                while (String.IsNullOrWhiteSpace(ReaderConfig.getInstance().InstanceName))
                {
                    Thread.Sleep(100);
                }
            }

            while (started)
            {
                string contentPath = ReaderConfig.getInstance().ContentPath;
                ViewModel.getInstance().DatabaseStatusColor = initStorage() ? SystemColors.Control : Color.Red;
                try
                {
                    if (contentPath == null || "".Equals(contentPath) || !Directory.Exists(contentPath))
                    {
                        foreach (DriveInfo drive in DriveInfo.GetDrives())
                        {
                            if (drive.DriveType == DriveType.CDRom && drive.IsReady)
                            {
                                contentPath = drive.Name;
                            }
                        }
                        if (contentPath != null && !"".Equals(contentPath) && Directory.Exists(contentPath))
                        {
                            ReaderConfig.getInstance().ContentPath = contentPath;
                            ReaderConfig.getInstance().SaveSettings();
                        }
                    }
                    if (contentPath != null && !"".Equals(contentPath) && Directory.Exists(contentPath))
                    {
                        if (readDiscContent(contentPath))
                        {
                            PdfReaderHelper.getInstance().unload();
                            ViewModel viewModel = ViewModel.getInstance();
                            viewModel.ResetView();
                            this.ThesisRecord.clearExtractedData();
                            InventoryStore.getInstance().updateSelectedInventoryRecord(null);
                            MainThread.getInstance().MatchingInventoryList.Clear();

                            FileUtils.CleanUpStaging();
                            FileUtils.CleanUpTemp();

                            DiscContentsProcessor.getInstance().process();
                        }
                    }
                }
                catch (IOException ioe)
                {
                    MessageBox.Show(PdfReaderHelper.getInstance().ContainerPanel, ioe.Message + Environment.NewLine + ioe.StackTrace, ioe.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Thread.Sleep(1000);
            }
        }
Ejemplo n.º 5
0
        //public void markupRecordDifference()
        //{
        //    Color EMPTY_VALUE_COLOR = Color.Yellow;
        //    Color CONFLICT_VALUE_COLOR = Color.Pink;
        //    Color MATCH_VALUE_COLOR = Color.LightGreen;

        //    ViewModel viewModel = ViewModel.getInstance();
        //    ThesisRecord thesisRecord = MainThread.getInstance().ThesisRecord;
        //    InventoryRecord invRecord = InventoryStore.getInstance().SelectedInventoryRecord;

        //    viewModel.ChineseNameInputColor = SystemColors.Window;
        //    viewModel.EnglishNameInputColor = SystemColors.Window;
        //    viewModel.StudentIdInputColor = SystemColors.Window;
        //    viewModel.DegreeInputColor = SystemColors.Window;
        //    viewModel.YearInputColor = SystemColors.Window;
        //    viewModel.ProgramInputColor = SystemColors.Window;
        //    viewModel.TitleInputColor = SystemColors.Window;
        //    viewModel.AccessInputColor = SystemColors.Window;
        //    viewModel.ReceivedDateInputColor = SystemColors.Window;

        //    // Chinese Name
        //    if (thesisRecord.ChineseName == null)
        //        thesisRecord.ChineseName = "";
        //    if (String.IsNullOrEmpty(thesisRecord.ChineseName) && String.IsNullOrEmpty(invRecord.ChineseName))
        //        viewModel.ChineseNameInputColor = CONFLICT_VALUE_COLOR;
        //    else if (String.IsNullOrEmpty(thesisRecord.ChineseName) && !String.IsNullOrEmpty(invRecord.ChineseName))
        //    {
        //        thesisRecord.ChineseName = invRecord.ChineseName;
        //        viewModel.ChineseNameInputColor = EMPTY_VALUE_COLOR;
        //    }
        //    else
        //        viewModel.ChineseNameInputColor = thesisRecord.ChineseName.Equals(invRecord.ChineseName) ? MATCH_VALUE_COLOR : CONFLICT_VALUE_COLOR;

        //    // English Name
        //    if (thesisRecord.EnglishName == null)
        //        thesisRecord.EnglishName = "";
        //    if (String.IsNullOrEmpty(thesisRecord.EnglishName) && String.IsNullOrEmpty(invRecord.Name))
        //        viewModel.EnglishNameInputColor = CONFLICT_VALUE_COLOR;
        //    else if(String.IsNullOrEmpty(thesisRecord.EnglishName) && !String.IsNullOrEmpty(invRecord.Name))
        //    {
        //        thesisRecord.EnglishName = invRecord.Name;
        //        viewModel.EnglishNameInputColor = EMPTY_VALUE_COLOR;
        //    }
        //    else
        //        viewModel.EnglishNameInputColor = thesisRecord.EnglishName.Equals(invRecord.Name) ? MATCH_VALUE_COLOR : CONFLICT_VALUE_COLOR;

        //    // Student ID
        //    if (thesisRecord.StudentId == null)
        //        thesisRecord.StudentId = "";
        //    if (String.IsNullOrEmpty(thesisRecord.StudentId) && String.IsNullOrEmpty(invRecord.StudentNo))
        //        viewModel.StudentIdInputColor = CONFLICT_VALUE_COLOR;
        //    else if (String.IsNullOrEmpty(thesisRecord.StudentId) && !String.IsNullOrEmpty(invRecord.StudentNo))
        //    {
        //        thesisRecord.StudentId = invRecord.StudentNo;
        //        viewModel.StudentIdInputColor = EMPTY_VALUE_COLOR;
        //    }
        //    else
        //        viewModel.StudentIdInputColor = thesisRecord.StudentId.Equals(invRecord.StudentNo) ? MATCH_VALUE_COLOR : CONFLICT_VALUE_COLOR;

        //    // Degree
        //    if (String.IsNullOrEmpty(thesisRecord.Degree))
        //        viewModel.DegreeInputColor = CONFLICT_VALUE_COLOR;
        //    else
        //        viewModel.DegreeInputColor = EMPTY_VALUE_COLOR;

        //    // Year
        //    if (thesisRecord.Year == null)
        //        thesisRecord.Year = "";
        //    if (String.IsNullOrEmpty(thesisRecord.Year) && String.IsNullOrEmpty(invRecord.GradYear))
        //        viewModel.YearInputColor = CONFLICT_VALUE_COLOR;
        //    else if (String.IsNullOrEmpty(thesisRecord.Year) && !String.IsNullOrEmpty(invRecord.GradYear))
        //    {
        //        thesisRecord.Year = invRecord.GradYear;
        //        viewModel.YearInputColor = EMPTY_VALUE_COLOR;
        //    }
        //    else
        //        viewModel.YearInputColor = thesisRecord.Year.Equals(invRecord.GradYear) ? MATCH_VALUE_COLOR : CONFLICT_VALUE_COLOR;

        //    // Programme
        //    if (thesisRecord.Programme == null)
        //        thesisRecord.Programme = "";
        //    if (String.IsNullOrEmpty(thesisRecord.Programme) && String.IsNullOrEmpty(invRecord.Program))
        //        viewModel.ProgramInputColor = CONFLICT_VALUE_COLOR;
        //    else if (String.IsNullOrEmpty(thesisRecord.Programme) && !String.IsNullOrEmpty(invRecord.Program))
        //    {
        //        thesisRecord.Programme = invRecord.Program;
        //        viewModel.ProgramInputColor = EMPTY_VALUE_COLOR;
        //    }
        //    else
        //        viewModel.ProgramInputColor = thesisRecord.Programme.Equals(invRecord.Program) ? MATCH_VALUE_COLOR : CONFLICT_VALUE_COLOR;

        //    // Title
        //    if (thesisRecord.ThesisTitle == null)
        //        thesisRecord.ThesisTitle = "";
        //    if (String.IsNullOrEmpty(thesisRecord.ThesisTitle) && String.IsNullOrEmpty(invRecord.Title))
        //        viewModel.TitleInputColor = CONFLICT_VALUE_COLOR;
        //    else if (String.IsNullOrEmpty(thesisRecord.ThesisTitle) && !String.IsNullOrEmpty(invRecord.Title))
        //    {
        //        thesisRecord.ThesisTitle = invRecord.Title;
        //        viewModel.TitleInputColor = EMPTY_VALUE_COLOR;
        //    }
        //    else
        //        viewModel.TitleInputColor = thesisRecord.ThesisTitle.Equals(invRecord.Title) ? MATCH_VALUE_COLOR : CONFLICT_VALUE_COLOR;

        //    // Access
        //    if (String.IsNullOrEmpty(thesisRecord.AccessMode) && String.IsNullOrEmpty(invRecord.Access))
        //    {
        //        thesisRecord.AccessMode = InventoryStore.ACCESS_MODE_RESTRICTED_KEY;
        //        viewModel.AccessInputColor = CONFLICT_VALUE_COLOR;
        //    }
        //    else if (String.IsNullOrEmpty(thesisRecord.AccessMode) && !String.IsNullOrEmpty(invRecord.Access))
        //    {
        //        thesisRecord.AccessMode = invRecord.Access;
        //        viewModel.AccessInputColor = EMPTY_VALUE_COLOR;
        //    }
        //    else
        //        viewModel.AccessInputColor = thesisRecord.AccessMode.Equals(invRecord.Access) ? MATCH_VALUE_COLOR : CONFLICT_VALUE_COLOR;

        //    // Received Date
        //    if (invRecord.Received != null)
        //        thesisRecord.ReceivedDate = DateTime.ParseExact(invRecord.Received, DEFAULT_DATE_FORMAT, CultureInfo.InvariantCulture);
        //    else
        //        thesisRecord.ReceivedDate = DateTime.Now;
        //    viewModel.ReceivedDateInputColor = EMPTY_VALUE_COLOR;
        //}

        public List <InventoryRecord> getMatchingInventoryRecordList(ThesisRecord thesisRecord)
        {
            List <InventoryRecord> matchingInventoryRecordList = new List <InventoryRecord>();

            if (thesisRecord == null || (String.IsNullOrEmpty(thesisRecord.ChineseName) && String.IsNullOrEmpty(thesisRecord.EnglishName) && String.IsNullOrEmpty(thesisRecord.StudentId) &&
                                         String.IsNullOrEmpty(thesisRecord.Degree) && String.IsNullOrEmpty(thesisRecord.Year) && String.IsNullOrEmpty(thesisRecord.Programme) &&
                                         String.IsNullOrEmpty(thesisRecord.ThesisTitle) && String.IsNullOrEmpty(thesisRecord.AccessMode) && thesisRecord.ReceivedDate == null))
            {
                return(matchingInventoryRecordList);
            }

            DataTable      inventoryDataTable = InventoryStore.getInstance().InventoryDataTable;
            List <DataRow> matchingDataRows   = new List <DataRow>();

            string filterString = "";

            if (!String.IsNullOrEmpty(thesisRecord.StudentId))
            {
                filterString += "(STUDENT_NO LIKE '%" + thesisRecord.StudentId + "') OR ";
            }

            filterString += "(RECORD_ID <> ''";
            if (!String.IsNullOrEmpty(thesisRecord.ChineseName))
            {
                filterString += " AND C_NAME LIKE '%" + thesisRecord.ChineseName + "%'";
            }
            if (!String.IsNullOrEmpty(thesisRecord.EnglishName))
            {
                filterString += " AND NAME LIKE '%" + thesisRecord.EnglishName + "%'";
            }
            if (!String.IsNullOrEmpty(thesisRecord.StudentId))
            {
                filterString += " AND STUDENT_NO LIKE '%" + thesisRecord.StudentId + "%'";
            }

            /*if (!String.IsNullOrEmpty(thesisRecord.Degree))
             *  filterString += " AND DEGREE LIKE '%" + thesisRecord.Degree + "%'";*/
            if (!String.IsNullOrEmpty(thesisRecord.Year))
            {
                filterString += " AND GRAD_YEAR LIKE '%" + thesisRecord.Year + "%'";
            }

            /*if (!String.IsNullOrEmpty(thesisRecord.Programme))
             *  filterString += " AND PROGRAM LIKE '%" + thesisRecord.Programme + "%'";*/
            /*if (!String.IsNullOrEmpty(thesisRecord.ThesisTitle))
             *  filterString += " AND TITLE LIKE '%" + thesisRecord.ThesisTitle + "%'";*/
            if (!String.IsNullOrEmpty(thesisRecord.AccessMode))
            {
                filterString += " AND ACCESS LIKE '%" + thesisRecord.AccessMode + "%'";
            }
            if (thesisRecord.ReceivedDate != null)
            {
                filterString += " AND RECEIVED LIKE '%" + thesisRecord.ReceivedDate.ToString() + "%'";
            }
            if (filterString.Length > 0)
            {
                filterString += ")";
                matchingDataRows.AddRange(inventoryDataTable.Select(filterString, "STUDENT_NO ASC"));
            }

            foreach (DataRow row in matchingDataRows)
            {
                InventoryRecord invRecord = new InventoryRecord();
                invRecord.RecordId    = (string)row["RECORD_ID"];
                invRecord.Name        = (string)row["NAME"];
                invRecord.ChineseName = (string)row["C_NAME"];
                invRecord.StudentNo   = (string)row["STUDENT_NO"];
                invRecord.Program     = (string)row["PROGRAM"];
                invRecord.Title       = (string)row["TITLE"];
                invRecord.GradYear    = (string)row["GRAD_YEAR"];
                invRecord.Degree      = (string)row["DEGREE"];
                invRecord.Access      = (string)row["ACCESS"];
                invRecord.BoxNo       = (int)row["BOX_NO"];
                invRecord.Assign      = (string)row["ASSIGN"];
                try
                {
                    if (row["RECEIVED"] != null)
                    {
                        DateTime receivedDateTime = (DateTime)row["RECEIVED"];
                        invRecord.Received = receivedDateTime.ToString(DEFAULT_DATE_FORMAT);
                    }
                    if (row["GCEXCO_APPROVAL_DATE"] != null)
                    {
                        DateTime approvalDateTime = (DateTime)row["GCEXCO_APPROVAL_DATE"];
                        invRecord.ApprovalDate = approvalDateTime.ToString(DEFAULT_DATE_FORMAT);
                    }
                }
                catch (Exception)
                {
                    /*Do nothing*/
                }

                invRecord.Embargo = (string)row["EMBARGO"];
                invRecord.Release = (string)row["RELEASE"];
                matchingInventoryRecordList.Add(invRecord);
            }

            return(matchingInventoryRecordList);
        }