コード例 #1
0
        public static string GetFileURL(string pAuthor, string pBookName, string pFileName)
        {
            string strBookName = CreateName(pBookName);
            //string strFileLocation = FileLocation(CreateLocation(pAuthor,strBookName),pFileName);
            string strRootLocation = LycuteApplication.GetLocationString();
            string strRealLocation = strRootLocation + "\\" + Naming.CreateLocation(pAuthor, strBookName) + "\\" + pFileName;//strFileLocation;

            return(strRealLocation);
        }
コード例 #2
0
        private void btn_ok_Click(object sender, RoutedEventArgs e)
        {
            StoreLocation store = new StoreLocation();

            LycuteApplication.SetLocation(tbx_Store.Content.ToString());
            store.CreateDatabase(tbx_Store.Content.ToString());
            DBHelper.ConfigDatabase();
            //alert
            Common.AlertDiag alert1 = new Common.AlertDiag();
            alert1._strAlertNote = "Location of e-book library is changed";
            alert1.ShowInTaskbar = false;
            alert1.WindowStyle   = WindowStyle.ToolWindow;
            alert1.CancelButton  = Visibility.Hidden;
            alert1.ShowDialog();

            m.loadMain(new Home());
        }
コード例 #3
0
        public static void ConfigDatabase()
        {
            string strLocation = LycuteApplication.GetLocationString();

            if (strLocation != "" && strLocation != null)
            {
                string strConnection = "metadata=res://*/LibraryModel.csdl|res://*/LibraryModel.ssdl|res://*/LibraryModel.msl;provider=System.Data.SqlServerCe.3.5;provider connection string=\"Data Source=" + strLocation + "\\Library.sdf\";";
                var    config        = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

                config.ConnectionStrings.ConnectionStrings["LibraryEntities"].ConnectionString = strConnection;;
                config.Save(ConfigurationSaveMode.Modified, true);

                // Now edit the in-memory values to match
                //Properties.Settings.Default["LibraryEntities"] = strConnection;


                ConfigurationManager.RefreshSection("connectionStrings");
            }
        }
コード例 #4
0
        public static string CreateLocation(string pAuthor, string pBookName)
        {
            string strFileLocation    = "";
            string strStructureFolder = LycuteApplication.GetStructureFolderString();

            switch (strStructureFolder)
            {
            case "AE":
                strFileLocation = pAuthor + "\\" + pBookName;
                break;

            case "EA":
                strFileLocation = pBookName + "\\" + pAuthor;
                break;

            case "E":
                strFileLocation = pBookName;
                break;
            }
            return(strFileLocation);
        }
コード例 #5
0
      private string CreateOldDirectory(string oldAuhthor, string oldTitle)
      {
          string oldDirectory = LycuteApplication.GetLocationString() + "\\" + Naming.CreateLocation(oldAuhthor, Naming.CreateName(oldTitle));

          return(oldDirectory);
      }
コード例 #6
0
 public ConfigLocation()
 {
     InitializeComponent();
     tbx_Store.Content = LycuteApplication.GetLocationString();
     this.Loaded      += new RoutedEventHandler(loadParent);
 }
コード例 #7
0
        public void Add(Book pEbook, string pAuthor, string pReview, string pEbookSource, string pOldEbookFile)
        {
            string strBookName = "";

            strBookName = Naming.CreateName(pEbook.bok_Title);
            string shortDirectory = Naming.CreateLocation(ConvertData.ToList(pAuthor)[0], strBookName);
            string newDirectory   = LycuteApplication.GetLocationString() + "\\" + shortDirectory;

            //check new directory is availble
            Directory.CreateDirectory(newDirectory);

            //Copy image
            string strFileType = "";
            string strImageURL = "";

            if (pEbook.bok_ImageURl != "" && pEbook.bok_ImageURl != null)
            {
                string[] arrayImageSourceURL = pEbook.bok_ImageURl.Split(new string[] { "///" }, StringSplitOptions.None);
                string   pImageSourceURL     = arrayImageSourceURL[arrayImageSourceURL.Count() - 1].Replace("/", "\\");

                strFileType = Naming.GetFileType(pImageSourceURL);
                strImageURL = Naming.FileLocation(newDirectory, "cover." + strFileType);
                //copy image
                if (pImageSourceURL != strImageURL)
                {
                    copy.Copy(pImageSourceURL, strImageURL, "file");
                }
            }
            //copy file
            copy.Copy(pEbookSource, Naming.FileLocation(newDirectory, pEbook.bok_Title + "." + Naming.GetFileType(pOldEbookFile)), "file");
            //edit review
            EditReview(newDirectory + "\\review.xml", pReview);
            //Save data
            using (LibraryEntities mainDB = new LibraryEntities())
            {
                Book b = new Book();
                b.bok_Edition = pEbook.bok_Edition;
                if (strFileType != "")
                {
                    b.bok_ImageURl = "cover." + strFileType;
                }
                b.bok_ISBN     = pEbook.bok_ISBN;
                b.bok_ID       = System.Guid.NewGuid().ToString();
                b.bok_Modified = pEbook.bok_Modified;
                b.bok_Rank     = pEbook.bok_Rank;
                b.bok_Title    = pEbook.bok_Title;
                b.bok_Volume   = pEbook.bok_Volume;
                b.bok_Year     = pEbook.bok_Year;
                b.bok_Location = pEbook.bok_Title + "." + Naming.GetFileType(pOldEbookFile);
                b.lng_ID       = "0";
                b.bok_Review   = "review.xml";

                Publisher pbl = publisherLib.AddPublisher(pEbook.Publisher, b.Publisher);
                b.pbl_ID = pbl.pbl_ID;


                List <string> auNames = authorLib.AddAuthor(pEbook.Authors, null, "");

                foreach (string name in auNames)
                {
                    var aut = (from author in mainDB.Authors
                               where author.ath_Name == name
                               select author).First();
                    aut.Books.Add(b);
                    //mainDB.AddToAuthors(au);
                }

                mainDB.AddToBooks(b);
                mainDB.SaveChanges();
            }
        }
コード例 #8
0
        /*Edit ebook*/
        public void Edit(Book pEbook, string pAuthor, string pOldDirectory, string pReview, string pOldEbookFile)
        {
            string strBookName = "";

            //error to create folder with voulume
            //if(pEbook.bok_Volume==1){
            strBookName = Naming.CreateName(pEbook.bok_Title);
            //}
            //else
            //{
            //    strBookName = Naming.CreateName(pEbook.bok_Title,pEbook.bok_Volume.ToString());
            //}
            string shortDirectory = Naming.CreateLocation(ConvertData.ToList(pAuthor)[0], strBookName);
            string newDirectory   = LycuteApplication.GetLocationString() + "\\" + shortDirectory;

            //check new directory is availble
            if (pOldDirectory != newDirectory)
            {
                //if (!copy.DirectoryIsExist(newDirectory))
                //{
                Directory.CreateDirectory(newDirectory);
                copy.Copy(pOldDirectory, newDirectory, pOldEbookFile, pEbook.bok_Title);
                copy.Delete(pOldDirectory, "folder");
                //}
            }
            //Copy image
            string strFileType = "";
            string strImageURL = "";

            if (pEbook.bok_ImageURl != "" && pEbook.bok_ImageURl != null)
            {
                string[] arrayImageSourceURL = pEbook.bok_ImageURl.Split(new string[] { "///" }, StringSplitOptions.None);
                string   pImageSourceURL     = arrayImageSourceURL[arrayImageSourceURL.Count() - 1].Replace("/", "\\");

                strFileType = Naming.GetFileType(pImageSourceURL);
                strImageURL = Naming.FileLocation(newDirectory, "cover." + strFileType);
                //copy image
                if (pImageSourceURL != strImageURL)
                {
                    copy.Copy(pImageSourceURL, strImageURL, "file");
                }
            }
            //Edit book
            LibraryEntities mainDB = new LibraryEntities();
            var             ebooks = (from ebook in mainDB.Books
                                      where ebook.bok_ID == pEbook.bok_ID
                                      select ebook).First();

            ebooks.bok_Edition = pEbook.bok_Edition;
            ebooks.bok_ISBN    = pEbook.bok_ISBN;
            if (strFileType != "")
            {
                ebooks.bok_ImageURl = "cover." + strFileType;
            }
            ebooks.bok_Modified = pEbook.bok_Modified;
            ebooks.bok_Rank     = pEbook.bok_Rank;
            ebooks.bok_Title    = pEbook.bok_Title;
            ebooks.bok_Volume   = pEbook.bok_Volume;
            ebooks.bok_Year     = pEbook.bok_Year;
            ebooks.bok_Location = pEbook.bok_Title + "." + Naming.GetFileType(pOldEbookFile);
            //add publisher if it is not exist and add publisher to EBook
            Publisher pbl = publisherLib.AddPublisher(pEbook.Publisher, ebooks.Publisher);

            if (pbl != null)
            {
                ebooks.pbl_ID = pbl.pbl_ID;
            }
            //add author
            List <string> auNames = authorLib.AddAuthor(pEbook.Authors, ebooks.Authors, ebooks.bok_ID);

            foreach (string name in auNames)
            {
                var aut = (from author in mainDB.Authors
                           where author.ath_Name == name
                           select author).First();
                aut.Books.Add(ebooks);
                //mainDB.AddToAuthors(au);
            }
            //save to database
            mainDB.SaveChanges();
            //edit review
            EditReview(newDirectory + "\\review.xml", pReview);
        }
コード例 #9
0
        /*Show ebook data from database*/
        //public ObservableCollection<Book> Search(string pKeywords)
        //{
        //    LibraryEntities mainDB = new LibraryEntities();
        //    var ebooks = from ebook in mainDB.Books
        //                 select ebook;
        //    if (pKeywords != null && pKeywords != "")
        //    {
        //        ebooks = from ebook in mainDB.Books
        //                 where ebook.bok_Title.Contains(pKeywords)
        //                 select ebook ;
        //    }
        //    ObservableCollection<Book> obserCollectionBook=new ObservableCollection<Book>(ebooks);

        //    foreach (var b in obserCollectionBook)
        //    {
        //        string strAuthors = AuthorLib.ToString(b.Authors);
        //        string strFirstAuthor = ConvertData.ToList(strAuthors)[0];
        //        b.bok_ImageURl = LycuteApplication.GetLocationString() + "\\"+Naming.CreateLocation(strFirstAuthor,Naming.CreateName(b.bok_Title))+"\\"+b.bok_ImageURl;
        //        b.bok_Rank = Rank.RankImage(Convert.ToInt32(b.bok_Rank));
        //        b.bok_Review = GetReview(LycuteApplication.GetLocationString() + "\\" + Naming.CreateLocation(strFirstAuthor, Naming.CreateName(b.bok_Title)) + "\\" + b.bok_Review);

        //    }
        //    return obserCollectionBook;
        //}

        //need to optimus
        public ObservableCollection <Book> Search(Dictionary <string, string> pKeywords)
        {
            LibraryEntities mainDB = new LibraryEntities();
            var             ebooks = from ebook in mainDB.Books
                                     from auth in ebook.Authors
                                     select ebook;

            if (pKeywords != null)
            {
                string author    = "";
                string publisher = "";
                string title     = "";
                if (pKeywords.ContainsKey("author"))
                {
                    author = pKeywords["author"];
                }
                if (pKeywords.ContainsKey("publisher"))
                {
                    publisher = pKeywords["publisher"];
                }
                if (pKeywords.ContainsKey("title"))
                {
                    title = pKeywords["title"];
                }
                if (author != "" && publisher != "" && title != "")
                {
                    ebooks = from ebook in mainDB.Books
                             from auth in ebook.Authors
                             where ebook.bok_Title.Contains(pKeywords["title"])
                             where auth.ath_Name.Contains(author)
                             where ebook.Publisher.pbl_Name.Contains(publisher)
                             select ebook;
                }
                else if (author != "" && title != "")
                {
                    ebooks = from ebook in mainDB.Books
                             from auth in ebook.Authors
                             where ebook.bok_Title.Contains(title)
                             where auth.ath_Name.Contains(author)
                             select ebook;
                }
                else if (publisher != "" && title != "")
                {
                    ebooks = from ebook in mainDB.Books
                             where ebook.bok_Title.Contains(title)
                             where ebook.Publisher.pbl_Name.Contains(publisher)
                             select ebook;
                }
                else if (author != "" && title == "")
                {
                    ebooks = from ebook in mainDB.Books
                             from auth in ebook.Authors
                             //where ebook.bok_Title.Contains(pKeywords["title"])
                             where auth.ath_Name.Contains(author)
                             select ebook;
                }
                else if (publisher != "" && title == "")
                {
                    ebooks = from ebook in mainDB.Books
                             //where ebook.bok_Title.Contains(pKeywords["title"])
                             where ebook.Publisher.pbl_Name.Contains(publisher)
                             select ebook;
                }
                else if (title != "")
                {
                    ebooks = from ebook in mainDB.Books
                             where ebook.bok_Title.Contains(title)
                             //where ebook.Publisher.pbl_Name.Contains(publisher)
                             select ebook;
                }
            }
            ObservableCollection <Book> obserCollectionBook = new ObservableCollection <Book>(ebooks);

            foreach (var b in obserCollectionBook)
            {
                string strAuthors     = AuthorLib.ToString(b.Authors);
                string strFirstAuthor = ConvertData.ToList(strAuthors)[0];
                b.bok_ImageURl = LycuteApplication.GetLocationString() + "\\" + Naming.CreateLocation(strFirstAuthor, Naming.CreateName(b.bok_Title)) + "\\" + b.bok_ImageURl;
                b.bok_Rank     = Rank.RankImage(Convert.ToInt32(b.bok_Rank));
                b.bok_Review   = GetReview(LycuteApplication.GetLocationString() + "\\" + Naming.CreateLocation(strFirstAuthor, Naming.CreateName(b.bok_Title)) + "\\" + b.bok_Review);
            }
            return(obserCollectionBook);
        }