Beispiel #1
0
        /// <summary>
        /// 把章节列表存入数据库,以便在阅读界面调用
        /// </summary>
        void InsertDB()
        {
            string sql = "select count(*) from chapters where webIndex=@ID and novel=@novel";
            List <SQLiteParameter> parameters = new List <SQLiteParameter>();

            parameters.Add(new SQLiteParameter("ID", Tools.source.ID));
            parameters.Add(new SQLiteParameter("novel", tmpNovelName));
            int count = Convert.ToInt32(MySqlite.GetFirstResult(sql, parameters));

            if (count != chapters.Count)  //章节数不一样,再更新数据库
            {
                //删除原有的
                sql        = "delete from chapters where webIndex=@ID and novel=@novel";
                parameters = new List <SQLiteParameter>();
                parameters.Add(new SQLiteParameter("ID", Tools.source.ID));
                parameters.Add(new SQLiteParameter("novel", tmpNovelName));
                MySqlite.ExecSql(sql, parameters);
                //插入新的
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < chapters.Count; i++)
                {
                    sb.Append("insert into chapters values('");
                    sb.Append(tmpNovelName).Append("','");       //小说名
                    sb.Append(chapters[i].chapter).Append("',"); //章节名
                    sb.Append(Tools.source.ID).Append(",'");     //网站索引
                    sb.Append(chapters[i].site).Append("');");   //小说地址
                    if (i % 200 == 0 || i == chapters.Count - 1)
                    {
                        MySqlite.ExecSql(sb.ToString());
                        sb = new StringBuilder();
                    }
                }
            }
            Invoke(new Action(delegate
            {
                label_state.Text = "";
            }));
        }