예제 #1
0
 private static List <Magazine> CheckMagazines(LibraryInstance firstMergingFile, LibraryInstance secondMergingFile)
 {
     if (firstMergingFile.listOfMagazines != null)
     {
         for (int i = 0; i < secondMergingFile.listOfMagazines.Count; i++)
         {
             for (int k = 0; k < firstMergingFile.listOfMagazines.Count; k++)
             {
                 if (secondMergingFile.listOfMagazines[i].Title == firstMergingFile.listOfMagazines[k].Title &&
                     secondMergingFile.listOfMagazines[i].Topic == firstMergingFile.listOfMagazines[k].Topic)
                 {
                     firstMergingFile.listOfMagazines[k].CopiesAvailable += secondMergingFile.listOfMagazines[i].CopiesAvailable;
                     continue;
                 }
                 else
                 {
                     firstMergingFile.listOfMagazines.Add(secondMergingFile.listOfMagazines[i]);
                 }
             }
         }
     }
     else
     {
         for (int i = 0; i < secondMergingFile.listOfMagazines.Count; i++)
         {
             firstMergingFile.listOfMagazines.Add(secondMergingFile.listOfMagazines[i]);
         }
     }
     return(firstMergingFile.listOfMagazines);
 }
예제 #2
0
 private static List <TechnicalLiterature> CheckTechLit(LibraryInstance firstMergingFile, LibraryInstance secondMergingFile)
 {
     if (firstMergingFile.listOfTechLit != null)
     {
         for (int i = 0; i < secondMergingFile.listOfTechLit.Count; i++)
         {
             for (int k = 0; k < firstMergingFile.listOfTechLit.Count; k++)
             {
                 if (secondMergingFile.listOfTechLit[i].Title == firstMergingFile.listOfTechLit[k].Title &&
                     secondMergingFile.listOfTechLit[i].ScientificField == firstMergingFile.listOfTechLit[k].ScientificField)
                 {
                     firstMergingFile.listOfTechLit[k].CopiesAvailable += secondMergingFile.listOfTechLit[i].CopiesAvailable;
                     continue;
                 }
                 else
                 {
                     firstMergingFile.listOfTechLit.Add(secondMergingFile.listOfTechLit[i]);
                 }
             }
         }
     }
     else
     {
         for (int i = 0; i < secondMergingFile.listOfTechLit.Count; i++)
         {
             firstMergingFile.listOfTechLit.Add(secondMergingFile.listOfTechLit[i]);
         }
     }
     return(firstMergingFile.listOfTechLit);
 }
예제 #3
0
 private static List <Fiction> CheckFiction(LibraryInstance firstMergingFile, LibraryInstance secondMergingFile)
 {
     if (firstMergingFile.listOfFictions != null)
     {
         for (int i = 0; i < secondMergingFile.listOfFictions.Count; i++)
         {
             for (int k = 0; k < firstMergingFile.listOfFictions.Count; k++)
             {
                 if (secondMergingFile.listOfFictions[i].Title == firstMergingFile.listOfFictions[k].Title &&
                     secondMergingFile.listOfFictions[i].Authors == firstMergingFile.listOfFictions[k].Authors)
                 {
                     firstMergingFile.listOfFictions[k].CopiesAvailable += secondMergingFile.listOfFictions[i].CopiesAvailable;
                     continue;
                 }
                 else
                 {
                     firstMergingFile.listOfFictions.Add(secondMergingFile.listOfFictions[i]);
                 }
             }
         }
     }
     else
     {
         for (int i = 0; i < secondMergingFile.listOfFictions.Count; i++)
         {
             firstMergingFile.listOfFictions.Add(secondMergingFile.listOfFictions[i]);
         }
     }
     return(firstMergingFile.listOfFictions);
 }
예제 #4
0
 private static List <ScientificArticle> CheckSciArticles(LibraryInstance firstMergingFile, LibraryInstance secondMergingFile)
 {
     if (firstMergingFile.listOfScientificArticles != null)
     {
         for (int i = 0; i < secondMergingFile.listOfScientificArticles.Count; i++)
         {
             for (int k = 0; k < firstMergingFile.listOfScientificArticles.Count; k++)
             {
                 if (secondMergingFile.listOfScientificArticles[i].Title == firstMergingFile.listOfScientificArticles[k].Title &&
                     secondMergingFile.listOfScientificArticles[i].ScientificFiled == firstMergingFile.listOfScientificArticles[k].ScientificFiled)
                 {
                     firstMergingFile.listOfScientificArticles[k].CopiesAvailable += secondMergingFile.listOfScientificArticles[i].CopiesAvailable;
                     continue;
                 }
                 else
                 {
                     firstMergingFile.listOfScientificArticles.Add(secondMergingFile.listOfScientificArticles[i]);
                 }
             }
         }
     }
     else
     {
         for (int i = 0; i < secondMergingFile.listOfScientificArticles.Count; i++)
         {
             firstMergingFile.listOfScientificArticles.Add(secondMergingFile.listOfScientificArticles[i]);
         }
     }
     return(firstMergingFile.listOfScientificArticles);
 }
예제 #5
0
 private static List <Newspaper> CheckNewsPaper(LibraryInstance firstMergingFile, LibraryInstance secondMergingFile)
 {
     if (firstMergingFile.listOfNewspaper != null)
     {
         for (int i = 0; i < secondMergingFile.listOfNewspaper.Count; i++)
         {
             for (int k = 0; k < firstMergingFile.listOfNewspaper.Count; k++)
             {
                 if (secondMergingFile.listOfNewspaper[i].Title == firstMergingFile.listOfNewspaper[k].Title &&
                     secondMergingFile.listOfNewspaper[i].MainTopicForTheEdition == firstMergingFile.listOfNewspaper[k].MainTopicForTheEdition)
                 {
                     firstMergingFile.listOfNewspaper[k].CopiesAvailable += secondMergingFile.listOfNewspaper[i].CopiesAvailable;
                     continue;
                 }
                 else
                 {
                     firstMergingFile.listOfNewspaper.Add(secondMergingFile.listOfNewspaper[i]);
                 }
             }
         }
     }
     else
     {
         for (int i = 0; i < secondMergingFile.listOfNewspaper.Count; i++)
         {
             firstMergingFile.listOfNewspaper.Add(secondMergingFile.listOfNewspaper[i]);
         }
     }
     return(firstMergingFile.listOfNewspaper);
 }
예제 #6
0
        private void btnMergeLibrarys_Click(object sender, EventArgs e)
        {
            try
            {
                LibraryInstance mergingLibraryInstance = new LibraryInstance();
                string          firstFilePath          = "";
                string          secondFilePath         = "";

                OpenFileDialog ofdOne = new OpenFileDialog();
                ofdOne.Title = "Select first file for merging";
                if (ofdOne.ShowDialog() == DialogResult.OK)
                {
                    firstFilePath = ofdOne.FileName;

                    OpenFileDialog ofdTwo = new OpenFileDialog();
                    ofdTwo.Title = "Select second library for merging";
                    if (ofdTwo.ShowDialog() == DialogResult.OK)
                    {
                        secondFilePath = ofdTwo.FileName;

                        mergingLibraryInstance = Helper.MergeLibrary(firstFilePath, secondFilePath);

                        string savingPath = "";

                        SaveFileDialog sfd = new SaveFileDialog();
                        if (sfd.ShowDialog() == DialogResult.OK)
                        {
                            savingPath = sfd.FileName;

                            Helper.SaveLibrary(savingPath, mergingLibraryInstance);
                            MessageBox.Show("Mergging libraries was successfull!");
                        }
                        else
                        {
                            MessageBox.Show("There was no saving derectory. Library not saved!");
                        }
                    }
                }
            }
            catch (IOException)
            {
                MessageBox.Show("Something went wrong with openning the files!");
            }
            catch (JsonException)
            {
                MessageBox.Show("The information from the file does not contain JSON object or the JSON object is corrupted!!");
            }
        }
예제 #7
0
        public static List <PaperWork> Search(string keyWord, LibraryInstance instance)
        {
            List <PaperWork> result = new List <PaperWork>();

            for (int i = 0; i < instance.listOfFictions.Count; i++)
            {
                if (instance.listOfFictions[i].Title.Contains(keyWord) || instance.listOfFictions[i].Authors.Contains(keyWord))
                {
                    result.Add(instance.listOfFictions[i]);
                }
            }

            for (int i = 0; i < instance.listOfMagazines.Count; i++)
            {
                if (instance.listOfMagazines[i].Title.Contains(keyWord) || instance.listOfMagazines[i].Topic.Contains(keyWord))
                {
                    result.Add(instance.listOfMagazines[i]);
                }
            }

            for (int i = 0; i < instance.listOfNewspaper.Count; i++)
            {
                if (instance.listOfNewspaper[i].Title.Contains(keyWord) || instance.listOfNewspaper[i].MainTopicForTheEdition.Contains(keyWord))
                {
                    result.Add(instance.listOfNewspaper[i]);
                }
            }

            for (int i = 0; i < instance.listOfScientificArticles.Count; i++)
            {
                if (instance.listOfScientificArticles[i].Title.Contains(keyWord) || instance.listOfScientificArticles[i].ScientificFiled.Contains(keyWord))
                {
                    result.Add(instance.listOfNewspaper[i]);
                }
            }

            for (int i = 0; i < instance.listOfTechLit.Count; i++)
            {
                if (instance.listOfTechLit[i].Title.Contains(keyWord) || instance.listOfTechLit[i].ScientificField.Contains(keyWord))
                {
                    result.Add(instance.listOfTechLit[i]);
                }
            }

            return(result);
        }
예제 #8
0
        public static LibraryInstance MergeLibrary(string firstFilePath, string secondFilePath)
        {
            string          firstMergngString = File.ReadAllText(firstFilePath);
            LibraryInstance firstMergingFile  = JsonConvert.DeserializeObject <LibraryInstance>(firstMergngString);

            string          secondMergingString = File.ReadAllText(secondFilePath);
            LibraryInstance secondMergingFile   = JsonConvert.DeserializeObject <LibraryInstance>(secondMergingString);


            firstMergingFile.listOfFictions = CheckFiction(firstMergingFile, secondMergingFile);

            firstMergingFile.listOfMagazines = CheckMagazines(firstMergingFile, secondMergingFile);

            firstMergingFile.listOfNewspaper = CheckNewsPaper(firstMergingFile, secondMergingFile);

            firstMergingFile.listOfScientificArticles = CheckSciArticles(firstMergingFile, secondMergingFile);

            firstMergingFile.listOfTechLit = CheckTechLit(firstMergingFile, secondMergingFile);

            return(firstMergingFile);
        }
예제 #9
0
 private void btnLoad_Click(object sender, EventArgs e)
 {
     try
     {
         string         loadPath = "";
         OpenFileDialog fd       = new OpenFileDialog();
         fd.Title = "Select library";
         if (fd.ShowDialog() == DialogResult.OK)
         {
             loadPath        = fd.FileName;
             libraryInstance = Helper.LoadLibrary(loadPath);
             MessageBox.Show("The library was loaded successfully!");
         }
     }
     catch (IOException)
     {
         MessageBox.Show("There was a problem with opennign the file!");
     }
     catch (JsonException)
     {
         MessageBox.Show("The file does not contain JSON object or the object was corrupted!");
     }
 }
예제 #10
0
        public static void SaveLibrary(string path, LibraryInstance saveLibrary)
        {
            string savedString = JsonConvert.SerializeObject(saveLibrary, Formatting.Indented);

            File.WriteAllText(path + ".json", savedString);
        }