Esempio n. 1
0
 public AddSourceController(Novel novel)
 {
     InitializeComponent();
     this.novel = novel;
     sourceSelector.DataSource = SourceManager.SourceLocation;
 }
        public static void AddNovel(Novel n)
        {
            using (SqlConnection connection = GetNovelDB())
            {
                //"INSERT INTO novel (novel_id, title,state,last_played_chapter_id,source,source_id,updated_chapter_count,rank) VALUES(@novel_id,@title,@state,@last_played_chapter_id,@source,@source_id,@updated_chapter_count,@rank)";
                SqlCommand cmd = new SqlCommand(insertNovelCommand, connection);
                cmd.Parameters.AddWithValue("@novel_id", n.NovelTitle.GetHashCode());
                cmd.Parameters.AddWithValue("@title", n.NovelTitle);
                cmd.Parameters.AddWithValue("@state", (int)n.State);
                cmd.Parameters.AddWithValue("@last_played_chapter_id", n.LastPlayedChapterID);
                //cmd.Parameters.AddWithValue("@source", n.Source.ToString());
                //cmd.Parameters.AddWithValue("@source_id", n.SourceID);
                cmd.Parameters.AddWithValue("@updated_chapter_count", n.NewChapterCount);
                cmd.Parameters.AddWithValue("@rank", n.Rank);

                cmd.ExecuteNonQuery();
            }

        }
Esempio n. 3
0
 partial void UpdateNovel(Novel instance);
Esempio n. 4
0
 partial void DeleteNovel(Novel instance);
Esempio n. 5
0
 partial void InsertNovel(Novel instance);
        /*============Public Function=======*/

        public Tuple<bool, string> AddNovel(string novelTitle, Source.SourceManager.Sources source, int sourceID)
        {
            foreach (Novel n in _novelList)
            {
                if (novelTitle.Equals(n.NovelTitle))
                {
                    Tuple<bool, string> failReturn = new Tuple<bool, string>(false, novelTitle + " already exists.");
                    return failReturn;
                }
            }

            string newNovelLocation = Path.Combine(Configuration.Instance.NovelFolderLocation, novelTitle);

            if (!Directory.Exists(newNovelLocation))
            {
                Directory.CreateDirectory(newNovelLocation);
                Directory.CreateDirectory(Path.Combine(newNovelLocation, "audios"));
                Directory.CreateDirectory(Path.Combine(newNovelLocation, "texts"));
                File.Create(Path.Combine(newNovelLocation, Configuration.Instance.ReplaceSpecification));
                File.Create(Path.Combine(newNovelLocation, Configuration.Instance.DeleteSpecification));
            }
            else
            {
                if (!Directory.Exists(Path.Combine(newNovelLocation, "audios")))
                    Directory.CreateDirectory(Path.Combine(newNovelLocation, "audios"));

                if (!Directory.Exists(Path.Combine(newNovelLocation, "texts")))
                    Directory.CreateDirectory(Path.Combine(newNovelLocation, "texts"));

                if (!File.Exists(Path.Combine(newNovelLocation, Configuration.Instance.ReplaceSpecification)))
                    File.Create(Path.Combine(newNovelLocation, Configuration.Instance.ReplaceSpecification));

                if (!File.Exists(Path.Combine(newNovelLocation, Configuration.Instance.DeleteSpecification)))
                    File.Create(Path.Combine(newNovelLocation, Configuration.Instance.DeleteSpecification));
            }

            Novel newNovel = new Novel(novelTitle);
            _novelList.Insert(GetNonDroppedNovelCount(), newNovel);
            Tuple<bool, string> successfulReturn = new Tuple<bool, string>(true, novelTitle + " successfully added.");
            return successfulReturn;

        }
Esempio n. 7
0
 public void SetReadingNovel(Novel n)
 {
     this.novel = n;
     this.Text  = n.NovelTitle;
     dgvChapterList.DataSource = n.Chapters;
 }
 public void SetReadingNovel(Novel n)
 {
     this.novel = n;
     this.Text = n.NovelTitle;
     dgvChapterList.DataSource = n.Chapters;
 }
        /*============Public Function=======*/

        public Novel AddNovel(string novelTitle, ISource source, out string message)
        {
            foreach (Novel n in _novelList)
            {
                if (novelTitle.Equals(n.NovelTitle))
                {
                    message = novelTitle + " already exists.";
                    return(null);
                }
            }

            string newNovelLocation = Path.Combine(Configuration.Instance.NovelFolderLocation, novelTitle);

            if (!Directory.Exists(newNovelLocation))
            {
                Directory.CreateDirectory(newNovelLocation);
                Directory.CreateDirectory(Path.Combine(newNovelLocation, "audios"));
                Directory.CreateDirectory(Path.Combine(newNovelLocation, "texts"));
                File.Create(Path.Combine(newNovelLocation, Configuration.Instance.ReplaceSpecification));
                File.Create(Path.Combine(newNovelLocation, Configuration.Instance.DeleteSpecification));
            }
            else
            {
                if (!Directory.Exists(Path.Combine(newNovelLocation, "audios")))
                {
                    Directory.CreateDirectory(Path.Combine(newNovelLocation, "audios"));
                }

                if (!Directory.Exists(Path.Combine(newNovelLocation, "texts")))
                {
                    Directory.CreateDirectory(Path.Combine(newNovelLocation, "texts"));
                }

                if (!File.Exists(Path.Combine(newNovelLocation, Configuration.Instance.ReplaceSpecification)))
                {
                    File.Create(Path.Combine(newNovelLocation, Configuration.Instance.ReplaceSpecification));
                }

                if (!File.Exists(Path.Combine(newNovelLocation, Configuration.Instance.DeleteSpecification)))
                {
                    File.Create(Path.Combine(newNovelLocation, Configuration.Instance.DeleteSpecification));
                }
            }
            Novel newNovel = new Novel();

            using (var transaction = new TransactionScope())
            {
                try
                {
                    newNovel.NovelTitle        = novelTitle;
                    newNovel.LastReadChapterID = -1;
                    newNovel.State             = Novel.NovelState.Active;
                    newNovel.Reading           = false;
                    newNovel.Rank = GetNonDroppedNovelCount();
                    libraryData.Novels.InsertOnSubmit(newNovel);
                    libraryData.SubmitChanges();
                    newNovel.Initiate();
                    _novelList.Insert(GetNonDroppedNovelCount(), newNovel);
                    UpdateNovelRanking();
                    string msg;
                    newNovel.AddSource(source, false, out msg);
                    transaction.Complete();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Unable to add novel");
                    Console.WriteLine(e.ToString());
                    message = "Unable to add novel " + novelTitle;
                    return(null);
                }
            }

            message = novelTitle + " successfully added.";
            return(newNovel);
        }