protected void DoGenerateLeftHtml(BOOKLIST info, FileInfo fiLeft) { if (fiLeft.Exists) { fiLeft.Delete(); } using (StreamWriter sw = new StreamWriter(fiLeft.OpenWrite(), Encoding.UTF8)) { // <!--[#獨立編號#]--> sw.WriteLine("<!--{0}-->", info.獨立編號); sw.WriteLine("<div class=\"popBook\">"); sw.WriteLine("<div class=\"leftContent\">"); //<h2>[#推薦作者#]</h2> sw.WriteLine("<h2>{0}</h2>", info.推薦作者); // <div class="bookimg"><img src="[#獨立編號#]/03.jpg" alt="" style="max-width:190px;max-heigth:270px;" /></div> sw.WriteLine("<div class=\"bookimg\"><img src=\"{0}/03.jpg\" alt=\"\" style=\"max-width:190px;max-heigth:270px;\" /></div>" , info.獨立編號); // <h3>[#推薦書籍#]</h3> sw.WriteLine("<h3>{0}</h3>" , info.推薦書籍); sw.WriteLine("</div>"); sw.WriteLine("<div class=\"backBtn\"><a style=\"cursor: pointer\" onClick=\"parent.$.fn.colorbox.close(); \"></a></div>"); //< div class="voteBtn"><a href = "../../[#VOTE_PAGE(大分類)#]?cb=[#大分類#]&cm=[#中分類#]&sid=[#獨立編號#]#anchor1" target="_blank"></a></div> sw.WriteLine("<div class=\"voteBtn\"><a href = \"../../{0}?cb={1}&cm={2}&sid={3}#anchor1\" target=\"_blank\"></a></div>" , DetermineVotePage(info.大分類) , info.大分類 , info.中分類 , info.獨立編號); //<div class="infoBtn"><a href = "http://www.eslite.com/product.aspx?pgid=[#ProductGuid#]&utm_source=eslite&utm_medium=eslite&utm_campaign=161019_award_p2" target="_blank"></a></div> sw.WriteLine("<div class=\"infoBtn\"><a href = \"http://www.eslite.com/product.aspx?pgid={0}&utm_source=eslite&utm_medium=eslite&utm_campaign=161019_award_p2\" target=\"_blank\"></a></div>" , info.ProductGuid); sw.WriteLine("</div>"); _logger.Info("產生 left.html of {0}: {1}", info.獨立編號, fiLeft.FullName); } }
/// <summary> /// 判斷 image 01,02,03 的來源目錄。 /// </summary> protected string DoDetermineImageSourceFolder(DirectoryInfo srcFolder, BOOKLIST info) { if (info.大分類 == "a") { return(string.Format("{0}\\最想賣\\{1}_{2}\\", srcFolder.FullName, info.大分類, info.ISBN)); } else if (info.大分類 == "b") { return(string.Format("{0}\\最想幫孩子說服爸媽買\\{1}_{2}\\", srcFolder.FullName, info.大分類, info.ISBN)); } else if (info.大分類 == "c") { return(string.Format("{0}\\在地作家\\{1}_{2}\\", srcFolder.FullName, info.大分類, info.ISBN)); } // otherwise throw new ApplicationException("無法判斷照片來源目錄!"); }
/// <summary> /// 匯入書單統整檔 /// </summary> protected int DoImportBooklist(FileInfo fi, MetaDatabaseEntities ctx) { try { // resource ExcelPackage ep = new ExcelPackage(fi); ExcelWorksheet ws = ep.Workbook.Worksheets[1]; // sheet1 // GO //using (var ctx = new MetaDatabaseEntities()) using (var txn = ctx.Database.BeginTransaction()) { _logger.Info("清空資料..."); ctx.Database.ExecuteSqlCommand("DELETE FROM [BOOKLIST]"); _logger.Info("匯入資料..."); // data row, 取值, 1-base for (int rowIdx = 2; rowIdx <= ws.Dimension.End.Row; rowIdx++) { BOOKLIST nr = new BOOKLIST(); nr.項次 = int.Parse(ws.Cells[rowIdx, 1].GetValue <string>()); nr.大分類 = ws.Cells[rowIdx, 2].GetValue <string>().Trim(); nr.中分類 = ws.Cells[rowIdx, 3].GetValue <string>().Trim(); nr.獨立編號 = ws.Cells[rowIdx, 4].GetValue <string>().Trim(); nr.圖檔名 = ws.Cells[rowIdx, 5].GetValue <string>().Trim(); nr.ProductGuid = ws.Cells[rowIdx, 6].GetValue <string>().Trim(); nr.順序 = int.Parse(ws.Cells[rowIdx, 7].GetValue <string>()); nr.屬性 = ws.Cells[rowIdx, 8].GetValue <string>().Trim(); nr.推薦書籍 = ws.Cells[rowIdx, 9].GetValue <string>().Trim(); nr.ISBN = ws.Cells[rowIdx, 10].GetValue <string>().Trim(); nr.MCH = ws.Cells[rowIdx, 11].GetValue <string>().Trim(); nr.分類 = ws.Cells[rowIdx, 12].GetValue <string>().Trim(); nr.出版日期 = ws.Cells[rowIdx, 13].GetValue <DateTime>(); nr.出版社 = ws.Cells[rowIdx, 14].GetValue <string>().Trim(); nr.推薦單位 = IsNull(ws.Cells[rowIdx, 15].GetValue <string>().Trim()); nr.推薦總編 = IsNull(ws.Cells[rowIdx, 16].GetValue <string>().Trim()); nr.職銜 = IsNull(ws.Cells[rowIdx, 17].GetValue <string>().Trim()); nr.總編推薦文 = IsNull(ws.Cells[rowIdx, 18].GetValue <string>().Trim()); nr.推薦職人店別 = IsNull(ws.Cells[rowIdx, 19].GetValue <string>().Trim()); nr.職人姓名 = IsNull(ws.Cells[rowIdx, 20].GetValue <string>().Trim()); nr.職人推薦文 = IsNull(ws.Cells[rowIdx, 21].GetValue <string>().Trim()); nr.推薦作者 = IsNull(ws.Cells[rowIdx, 22].GetValue <string>().Trim()); nr.Tag = ws.Cells[rowIdx, 23].GetValue <string>().Trim(); // 判斷 nr.書落 = DoDetermineBookBlog(nr.大分類, nr.中分類); ctx.BOOKLIST.Add(nr); } ctx.SaveChanges(); // success txn.Commit(); return(ctx.BOOKLIST.Count()); } } catch (Exception ex) { throw new ApplicationException("DoImportBooklist fail. " + ex.Message, ex); } }
protected void DoGenerateRightHtml(BOOKLIST info, FileInfo fiRight, BookBlogFirstLastUid firstLastUid) { if (fiRight.Exists) { fiRight.Delete(); } using (StreamWriter sw = new StreamWriter(fiRight.OpenWrite(), Encoding.UTF8)) { // <!--[#獨立編號#]--> sw.WriteLine("<!--{0}-->", info.獨立編號); sw.WriteLine("<div class=\"popBook\">"); //<div class="prev"><a href="../../book_want.aspx?sid=[#獨立編號-1#]" target="_blank"></a></div> if (info.獨立編號 != firstLastUid.FirstUid) // 不是第一筆 { sw.WriteLine("<div class=\"prev\"><a href=\"../../{0}?sid={1}{2:000}\" target=\"_blank\"></a></div>" , DetermineWantPage(info.大分類) , info.大分類 , info.順序 - 1); } //<div class="next"><a href="../../book_want.aspx?sid=[#獨立編號+1#]" target="_blank"></a></div> if (info.獨立編號 != firstLastUid.LastIUid) // 不是最末筆 { sw.WriteLine("<div class=\"next\"><a href=\"../../{0}?sid={1}{2:000}\" target=\"_blank\"></a></div>" , DetermineWantPage(info.大分類) , info.大分類 , info.順序 + 1); } sw.WriteLine("<div class=\"rightContent\">"); //<% WHEN[#屬性#] == "總編|兩者" %> //<div class="titleBar"><h1><img src="../img/book_title01.png" width="150" height="44" alt=""/></h1></div> //<h2>[#推薦單位#] / [#推薦總編#] [#職銜#]</h2> //<p>[#總編推薦文#]</p> if (info.屬性 == "總編" || info.屬性 == "兩者") { sw.WriteLine("<div class=\"titleBar\"><h1><img src=\"../img/book_title01.png\" width=\"150\" height=\"44\" alt=\"\"/></h1></div>"); sw.WriteLine("<h2>{0} / {1} {2}</h2>", info.推薦單位, info.推薦總編, info.職銜); sw.WriteLine("<p>{0}</p>", info.總編推薦文); } // <% WHEN [#屬性#] == "職人|兩者" %> //<div class="titleBar2"><h1><img src="../img/book_title02.png" width="150" height="44" alt=""/></h1></div> //<h2>[#推薦職人店別#] / [#職人姓名#] </h2> //<p>[#職人推薦文#]</p> if (info.屬性 == "職人" || info.屬性 == "兩者") { sw.WriteLine("<div class=\"titleBar2\"><h1><img src=\"../img/book_title02.png\" width=\"150\" height=\"44\" alt=\"\"/></h1></div>"); sw.WriteLine("<h2>{0} / {1}</h2>", info.推薦職人店別, info.職人姓名); sw.WriteLine("<p>{0}</p>", info.職人推薦文); } sw.WriteLine("</div>"); sw.WriteLine("</div>"); _logger.Info("產生 right.html of {0}: {1}", info.獨立編號, fiRight.FullName); } }
/// <summary> /// 判斷 images_books_c 的目的目錄。 /// </summary> protected DirectoryInfo DoDetermineImageTargetFolder_BooksC(DirectoryInfo tgtFolder, BOOKLIST info) { DirectoryInfo imgTgtFolder = new DirectoryInfo(string.Format("{0}\\images_books_c\\", tgtFolder.FullName)); // make image target folder if (!imgTgtFolder.Exists) { imgTgtFolder.Create(); } return(imgTgtFolder); }
/// <summary> /// 判斷 image 01,02,03 的目的目錄。 /// </summary> protected DirectoryInfo DoDetermineImageTargetFolder(DirectoryInfo tgtFolder, BOOKLIST info) { DirectoryInfo imgTgtFolder = new DirectoryInfo(string.Format("{0}\\book\\{1}\\{2}\\", tgtFolder.FullName, info.書落, info.獨立編號)); // make image target folder if (!imgTgtFolder.Exists) { imgTgtFolder.Create(); } return(imgTgtFolder); }