Ejemplo n.º 1
0
        // 撈出此本書的最新的章節
        public int 目前最新章節(AddBooks b)
        {
            SqlConnection con = new SqlConnection(myDBConnectionString);

            con.Open();

            string     tSQL = "select max(bc_Chapters) as bc_Chapters from BooksChapters where b_id = @bId";
            SqlCommand cmd  = new SqlCommand(tSQL, con);

            cmd.Parameters.AddWithValue("bId", b.b_id);
            SqlDataReader reader = cmd.ExecuteReader();

            int 目前最新章節數 = 0;

            if (b.b_id != null)
            {
                if (reader.Read())
                {
                    目前最新章節數 = (int)reader["bc_Chapters"];
                }
            }

            reader.Close();
            con.Close();

            return(目前最新章節數);
        }
Ejemplo n.º 2
0
        public string 書籍封面圖片命名(AddBooks b)
        {
            // 取得副檔名
            int    point     = b.Image.FileName.IndexOf(".");
            string extention = b.Image.FileName.Substring(point, b.Image.FileName.Length - point);
            // 命名封面檔名
            string photoName = b.b_id + "-cover" + extention;

            return(photoName);
        }
Ejemplo n.º 3
0
        // 將資料儲存到 BookOutline 與 BooksChapters 資料表
        public void 儲存章節標題及檔名(AddBooks b, AddBooksFiles bf, AddBooksChapters bc)
        {
            SqlConnection con = new SqlConnection(myDBConnectionString);

            con.Open();

            // 新增到書籍章節資料表
            string     tSQL = "Insert into BooksChapters (b_id,bc_Chapters,bc_Content)Values(@bId,@bcChapters,@bcContent)";
            SqlCommand cmd  = new SqlCommand(tSQL, con);

            cmd.Parameters.AddWithValue("bId", b.b_id);
            cmd.Parameters.AddWithValue("bcChapters", bc.bc_Chapters);
            cmd.Parameters.AddWithValue("bcContent", bc.bc_Content);

            cmd.ExecuteNonQuery();

            // 撈回 BooksChapters 資料表,目前自動編號的最大值 (要塞到 BooksFiles 資料表使用的)
            string        tSQL1  = "select max(bc_id) as bc_id from BooksChapters";
            SqlCommand    cmd1   = new SqlCommand(tSQL1, con);
            SqlDataReader reader = cmd1.ExecuteReader();

            int maxbc_id = 0;

            if (reader.Read())
            {
                maxbc_id = (int)reader["bc_id"];
            }

            reader.Close();


            // 新增到書籍檔案資料表
            string     tSQL2 = "";
            SqlCommand cmd2  = new SqlCommand();

            cmd2.Connection = con;

            foreach (string Files in bf.FilesName)
            {
                tSQL2            = "Insert into BooksFiles (bc_id,bf_FileName)Values('" + maxbc_id + "','" + Files + "')";
                cmd2.CommandText = tSQL2;
                cmd2.ExecuteNonQuery();
            }

            con.Close();
        }
Ejemplo n.º 4
0
        // 新增書籍基本資料
        // 使用資料表:Books、BooksAuthor
        // 將資料儲存到 Books 資料表
        public void Create(AddBooks b)
        {
            SqlConnection con = new SqlConnection(myDBConnectionString);

            con.Open();

            //Insert into Books (b_id,b_Name,b_Info,b_Image,b_Type,b_PublishedDate,b_DatePrice,b_ISBN,b_AgeRating,p_id)Values(1234,'aaa','bbb','c','d','1996/09/07','1','g',1,1)

            string tSQL = "Insert into Books (b_id,b_Name,b_Info,b_Image,b_Type,b_PublishedDate,b_DatePrice,b_ISBN,b_AgeRating,b_Series_yn,b_Put_yn,p_id)Values(" +
                          "@bid,@bName,@bInfo,@bImage,@bType,@bPublishedDate,@bDatePrice,@bISBN,@bAgeRating,@bSeries,'n',@pID)";
            SqlCommand cmd = new SqlCommand(tSQL, con);

            cmd.Parameters.AddWithValue("bid", b.b_id);
            cmd.Parameters.AddWithValue("bName", b.b_Name);
            cmd.Parameters.AddWithValue("bInfo", b.b_Info);
            cmd.Parameters.AddWithValue("bImage", b.b_Image);
            cmd.Parameters.AddWithValue("bType", b.b_Type);
            cmd.Parameters.AddWithValue("bPublishedDate", b.b_PublishedDate);
            cmd.Parameters.AddWithValue("bDatePrice", b.b_DatePrice);
            cmd.Parameters.AddWithValue("bISBN", b.b_ISBN);
            cmd.Parameters.AddWithValue("bAgeRating", b.b_AgeRating);

            // 連載情況
            char 連載情況;

            if (b.b_Series_yn == "連載中")
            {
                連載情況 = 'y';
                cmd.Parameters.AddWithValue("bSeries", 連載情況);
            }
            else if (b.b_Series_yn == "已完結")
            {
                連載情況 = 'n';
                cmd.Parameters.AddWithValue("bSeries", 連載情況);
            }
            cmd.Parameters.AddWithValue("pID", b.p_id);

            cmd.ExecuteNonQuery();
            con.Close();
        }