edit-task
Home
Up
Delete
Task Name:
Task Description:
NEW PAGE VERSION -
TaskGroup ID:
Start Date:
Start Time:
Duration:
Priority:
Status:
To Do
Completed
In Process
Add Photo:
Owner ID:
Content:
use HTML
Edit Content
<h1 style="text-align: center;">PG import/articles -v-001</h1> <h2>[previously]</h2> <div><ol> <li>] <a href="/view/task?id=5617" target="_blank">PAGE - import/articles</a> - description and history of page, versions list</li> </ol></div> <h2>[currently]</h2> <div><ol> <li>[2013-08-05] NEW PAGE VERSON - ] ADD more qry's for ...</li> <ol> <li>] record created date</li> </ol></ol></div> <h2>[next]</h2> <ol> <li>] </li> </ol> <div> <div> @* CUT FROM case import_library (MOVED to sospep. </div> <div> var db_src = Database.Open(@Session["current_db"].ToString());</div> <div> // NEED = GET conn string name of user selected db, use dbid to look it up in db_owners table OR used jq to pull from select box:selected text</div> <div> // Select sName from db_owner WHERE id = dbID </div> <div> var db_dest = Database.Open(destination_sospep);</div> <div> </div> <div> // GET LIBRARY record</div> <div> var srcLibrary = db_src.QuerySingle("select * from libraries WHERE id_library=@0",srcLibraryId);</div> <div> // GET BOOKSinLIBRARY</div> <div> var srcBooks = db_src.Query("select * from books WHERE parent_id=@0",srcLibraryId);</div> <div> </div> <div> // PUT BOOKSinLIBRARY</div> <div> sqlQ="INSERT INTO libraries (name_library,description_library) VALUES (@0,@1)";</div> <div> db_dest.Execute(sqlQ, srcLibrary.name_library, srcLibrary.description_library);</div> <div> </div> <div> // PUT THE BOOKS into the destination library</div> <div> // NEED the id of the library in the destination library </div> <div> var destLibId = db_dest.QueryValue("SELECT id_library FROM libraries WHERE name_library =@0",srcLibrary.name_library); </div> <div> sqlQ1="INSERT INTO books (name_book,description_book,parent_id) VALUES (@0,@1,@2)";</div> <div> </div> <div> // +] NEXT= REPLACE this loop w/ SELECT INTO</div> <div> // SELECT INTO `destination`.`libraries (SELECT * from `src.libraries WHERE id_library=@0")</div> <div> foreach(var book in srcBooks) { </div> <div> db_dest.Execute(sqlQ1, book.name_book, book.description_book,destLibId);</div> <div> // REV bookIds.Add(book.id_book);</div> <div> // REV books=books+book.id_book.ToString()+",";</div> <div> }</div> <div> </div> <div> // GET the chapters in this book</div> <div> // var sqlQ2 = "select * from chapters where parent_id IN ("+ bookIds.ToString()+")";</div> <div> // ERROR - looks like doesnt </div> <div> //REV // books = books.TrimEnd(',');</div> <div> </div> <div> @* WORKING - STRUCTURE ONLY - INSERT chapters into each book * @ </div> <div> foreach (var book in srcBooks){</div> <div> // var bk_id=book.id_book;</div> <div> var destBkId = db_dest.QueryValue("SELECT id_book FROM books WHERE name_book =@0",book.name_book);</div> <div> srcChapters =db_src.Query("SELECT * FROM chapters WHERE parent_id=@0",book.id_book);</div> <div> </div> <div> foreach (var chapter in srcChapters){</div> <div> sqlQ3 = "INSERT INTO chapters (name_chapter,description_chapter,parent_id) VALUES (@0,@1,@2)";</div> <div> db_dest.Execute(sqlQ3, chapter.name_chapter, chapter.description_chapter,destBkId);</div> <div> }</div> <div> }</div> <div> </div> <div> @* STRUCTURE + CONTENT (articles) - insert articles into chapters * @</div> <div> </div> <div> foreach (var book in srcBooks){</div> <div> // var bk_id=book.id_book;</div> <div> var destBkId = db_dest.QueryValue("SELECT id_book FROM books WHERE name_book =@0",book.name_book);</div> <div> srcChapters =db_src.Query("SELECT * FROM chapters WHERE parent_id=@0",book.id_book); </div> <div> </div> <div> foreach (var chapter in srcChapters){</div> <div> // var bk_id=book.id_book;</div> <div> var destChId = db_dest.QueryValue("SELECT id_chapter FROM chapters WHERE name_chapter=@0",chapter.name_chapter);</div> <div> srcArticles =db_src.Query("SELECT * FROM articles WHERE parent_id=@0",chapter.id_chapter);</div> <div> </div> <div> foreach (var article in srcArticles){</div> <div> sqlQ4 = "INSERT INTO articles (name_article,description_article,parent_id,content_article,content_format,priority,photo,status,owner) VALUES (@0,@1,@2,@3,@4,@5,@6,@7,@8)";</div> <div> db_dest.Execute(sqlQ4, article.name_article, article.description_article,destChId,article.content_article,article.content_format,article.priority,article.photo,article.status,article.owner);</div> <div> }</div> <div> }</div> <div> }</div> <div> //Response.Redirect("~/");</div> <div> *@</div> <div><hr />IMPORT BOOK moved to sospep.</div> </div> <div> <div> @*</div> <div> // SET src_db, dest_db</div> <div> db_src = Database.Open(@Session["current_db"].ToString());</div> <div> db_dest = Database.Open(destination_sospep);</div> <div> </div> <div> sqlQ4 = "INSERT INTO articles (name_article,description_article,parent_id,content_article,content_format,priority,photo,status,owner) VALUES (@0,@1,@2,@3,@4,@5,@6,@7,@8)"; </div> <div> // GET BOOKinLIBRARY to EXPORT - have book id </div> <div> // var srcBook = db_src.QuerySingle("select * from books WHERE parent_id=@0",srcLibraryId);</div> <div> var srcBook = db_src.QuerySingle("select * from books WHERE id_book=@0",srcBookId);</div> <div> </div> <div> // PUT BOOKinLIBRARY</div> <div> sqlQ1="INSERT INTO books (name_book,description_book,parent_id) VALUES (@0,@1,@2)"; </div> <div> db_dest.Execute(sqlQ1,srcBook.name_book,srcBook.description_book,destLibraryId);</div> <div> // REV + 2nd conditon </div> <div> // GET id of book we just added</div> <div> destBkId2 = db_dest.QueryValue("SELECT (id_book) from books WHERE name_book=@0 && parent_id=@1",srcBook.name_book,destLibraryId); </div> <div> // GET - all the CHAPTERS from the srcBOOK</div> <div> srcChapters = db_src.Query("select * from chapters WHERE parent_id=@0",srcBook.id_book);</div> <div> // PUT - each chapter into the destination library</div> <div> sqlQ3 = "INSERT INTO chapters (name_chapter,description_chapter,parent_id) VALUES (@0,@1,@2)";</div> <div> </div> <div> foreach (var chapter in srcChapters){</div> <div> srcArticles = db_src.Query("SELECT * FROM articles WHERE parent_id=@0",chapter.id_chapter); </div> <div> db_dest.Execute(sqlQ3, chapter.name_chapter, chapter.description_chapter, destBkId2);</div> <div> // var destBKId = db_dest.QueryValue("SELECT id_book FROM books WHERE name_book=@0",chapter.name_cha);</div> <div> // REV - WORKS add parent-par to see if why no articles</div> <div> destChId2 = db_dest.QueryValue("SELECT id_chapter FROM chapters WHERE name_chapter=@0 && parent_id=@1",chapter.name_chapter,destBkId2);</div> <div> foreach (var article in srcArticles){</div> <div> sqlQ4 = "INSERT INTO articles (name_article,description_article,parent_id,content_article,content_format,priority,photo,status,owner) VALUES (@0,@1,@2,@3,@4,@5,@6,@7,@8)";</div> <div> db_dest.Execute(sqlQ4, article.name_article, article.description_article,destChId2,article.content_article,article.content_format,article.priority,article.photo,article.status,article.owner);</div> <div> }</div> <div> }</div> <div> *@</div> </div> <div><hr /></div> <div>IMPORT CHAPTER moved to sospep.</div> <div> <div>@*</div> <div> db_dest.Execute(sqlQ1,srcChapter.name_chapter,srcChapter.description_chapter,destBookId); </div> <div> // NEED = ] srcChapterId, ] destBookId FROM UI ( ] add hidden form input, ] set in export button click e, ] add sel to get value, ] add function to fill sel )</div> <div> // GET id of CHAPTER we just added</div> <div> destChId2 = db_dest.QueryValue("SELECT (id_chapter) from chapters WHERE name_chapter=@0 && parent_id=@1",srcChapter.name_chapter,destBookId);</div> <div> *@ </div> </div>