static void Main() { TextBook t1 = new TextBook("Test Book", "Ben Breshears", "Security Publishers", 1287503817104, "Tests", "Test Editor"); tw.DisplayBook(); tw.DisplayTextBook(); }
public static TextBook GetUpdatedTextBook(ApplicationContext db, TextBookInputViewModel inputModel) { TextBook book = db.TextBooks.Find(inputModel.Id); if (book == null) { return(null); } book.BookName = inputModel.BookName; book.Author = inputModel.Author; book.Pages = inputModel.Pages; book.ContentFilePath = inputModel.ContentFilePath; book.CoverFilePath = inputModel.CoverFilePath; book.Description = inputModel.Description; book.Genres.Clear(); ICollection <Genre> genres = GetGenresList(db, inputModel.GenresList); foreach (Genre g in genres) { book.Genres.Add(g); } SubscriptionType type = db.SubscriptionTypes.FirstOrDefault(s => s.Name == inputModel.SubscriptionType); if (type == null) { return(null); } book.SubscriptionType = type; return(book); }
//Read a text file private void ReadFileUsingStream(TextBook textBook) { using (StreamReader myReader = new StreamReader(GetFile())) { textBook.RawText = myReader.ReadToEnd(); //await myReader.ReadToEndAsync(); } }
public static TextBook GetNewTextBook(ApplicationContext db, TextBookInputViewModel inputModel) { TextBook book = new TextBook { BookName = inputModel.BookName, Author = inputModel.Author, Pages = inputModel.Pages, ContentFilePath = inputModel.ContentFilePath, CoverFilePath = inputModel.CoverFilePath, Description = inputModel.Description }; ICollection <Genre> genres = inputModel.GenresList.Trim().Split().Select(s => db.Genres.FirstOrDefault(g => g.Name == s)).ToList(); foreach (Genre g in genres) { book.Genres.Add(g); } SubscriptionType type = db.SubscriptionTypes.FirstOrDefault(s => s.Name == inputModel.SubscriptionType); if (type == null) { return(null); } book.SubscriptionType = type; return(book); }
public ActionResult ADD(TextBook te) { try { if (ef.TextBooks.FirstOrDefault(x => x.BookName == te.BookName.Trim() && x.Shan == true) != null) { TextBook ta = ef.TextBooks.FirstOrDefault(x => x.BookName == te.BookName); ta.Shan = false; ef.Entry(ta).State = EntityState.Modified; if (ef.SaveChanges() > 0) { return(Content("添加成功")); } } else { te.Shan = false; ef.Entry(te).State = EntityState.Added; if (ef.SaveChanges() > 0) { return(Content("添加成功")); } else { return(Content("失败")); } } return(Content("")); } catch (Exception ex) { return(Content(ex.ToString())); } }
public IActionResult BookInfo(int book_id, string type) { BookInfoContainerViewModel bookInfo = new BookInfoContainerViewModel { Type = type, }; switch (type) { case "text": TextBook textBook = db.TextBooks.Find(book_id); if (textBook == null) { return(NotFound()); } bookInfo.TextBook = textBook; bookInfo.IsAccessible = User.IsInRole("admin") || UserHelper.GetUserSubscriptionType(User, db).Level >= textBook.SubscriptionType.Level; break; case "audio": AudioBook audioBook = db.AudioBooks.Find(book_id); if (audioBook == null) { return(NotFound()); } bookInfo.AudioBook = audioBook; bookInfo.IsAccessible = User.IsInRole("admin") || UserHelper.GetUserSubscriptionType(User, db).Level >= audioBook.SubscriptionType.Level; break; default: return(NotFound()); } return(View(bookInfo)); }
private void GetWordCount(TextBook textBook) { //Split text file by spaces into a list and remove empty entries var myWordList = myWordCountUtils.SplitWords(textBook.RawText); //Add words to a dictionary object with the corresponding word count myWordCountUtils.WordCountDictionary(myWordList, textBook.WordDictionary); }
public IActionResult DeleteTextBook(int id) { TextBook toDelete = db.TextBooks.Find(id); db.TextBooks.Remove(toDelete); db.SaveChanges(); return(RedirectToAction("Index", "Home")); }
static void Main(string[] args) { TextBook t1 = new TextBook(10, "Man", 23.3); Console.WriteLine(t1.takeprice()); t1.Show(); TradeBook t2 = new TradeBook(20, "Month", 23.3); Console.WriteLine(t2.takeprice()); t2.Show(); }
public IActionResult SaveTextBookChanges(BookInputContainerViewModel bicvm) { TextBook book = ModelConvertationHelper.GetUpdatedTextBook(db, bicvm.TextBookPresentation); if (book == null) { return(View("~/Views/Shared/Error.cshtml")); } db.Entry(book).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Home")); }
//Ignore punctuation and capitalisation //I started implementing this to make it more user friendly and get more accurate results. I was trying to avoid having to use regex because of the impact it has on performance. //It might be worth using regex (\w+) and strip out words rather than trying to remove Romans, Punctuation and some special characters private void CleanupText(TextBook textBook) { //Remove modern roman numerals (NOTE: Case insensitive) textBook.RawText = myWordCountUtils.RegexCleaner(textBook.RawText, textBook.Pattern); //Format any capitalisation to lower case in text file textBook.RawText = textBook.RawText.ToLower(); //Remove Punctuation from text file textBook.RawText = myWordCountUtils.RemovePunctuation(textBook.RawText); //Remove new line, tab and numbers textBook.RawText = myWordCountUtils.CleanDistinctCharacters(textBook.RawText, textBook.StripCharacters); }
public ActionResult Clear(TextBook te) { string name = te.BookName; TextBook ta = ef.TextBooks.FirstOrDefault(x => x.BookName == te.BookName.Trim()); ta.Shan = true; ef.Entry(ta).State = EntityState.Modified; if (ef.SaveChanges() > 0) { return(Content("删除成功")); } else { return(Content("删除失败")); } }
public void Remove_RomanNumerals_FollowedBy_FullStop() { //Arrange // string pattern = @"(?=[MDCLXVI])M*(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3}[.])"; string inputText = "I. The beginning of things.II. Peter's coal-mine. I don't suppose they had..."; string expectedOutput = " The beginning of things. Peter's coal-mine. I don't suppose they had..."; var myWordCountUtils = new WordCountUtils(); var myTextBook = new TextBook(); //Act //inputText = System.Text.RegularExpressions.Regex.Replace(inputText, pattern, " "); inputText = myWordCountUtils.RegexCleaner(inputText, myTextBook.Pattern); //Assert Assert.AreEqual(expectedOutput, inputText); }
public IActionResult EditTextBook(int id) { TextBook textBook = db.TextBooks.Find(id); if (textBook == null) { return(View("~/Views/Shared/Error.cshtml")); } BookInputContainerViewModel bicvm = new BookInputContainerViewModel { TextBookPresentation = ModelConvertationHelper.GetTextBookInputViewModel(textBook), Type = "text" }; return(View("~/Views/ManageModel/EditBook.cshtml", bicvm)); }
public IActionResult AddTextBook(BookInputContainerViewModel bicvm) { TextBook book = ModelConvertationHelper.GetNewTextBook(db, bicvm.TextBookPresentation); if (book == null) { return(View("~/Views/Shared/Error.cshtml")); } foreach (Genre g in book.Genres) { db.Genres.Attach(g); } db.SubscriptionTypes.Attach(book.SubscriptionType); db.TextBooks.Add(book); db.SaveChanges(); return(RedirectToAction("AdminHome", "Home")); }
public static TextBookInputViewModel GetTextBookInputViewModel(TextBook book) { TextBookInputViewModel inputModel = new TextBookInputViewModel { Id = book.BookId, BookName = book.BookName, Author = book.Author, Pages = book.Pages, SubscriptionType = book.SubscriptionType.Name, ContentFilePath = book.ContentFilePath, CoverFilePath = book.CoverFilePath, Description = book.Description }; inputModel.GenresList = GetGenresString(book.Genres); return(inputModel); }
public ActionResult Update(TextBook te) { if (ef.TextBooks.FirstOrDefault(x => x.BookName == te.BookName.Trim() && x.GradeID == te.GradeID) != null) { return(Content("已经存在")); } TextBook a = new TextBook() { BookName = te.BookName.Trim(), GradeID = te.GradeID, BookID = te.BookID }; a.Shan = false; ef.Entry(a).State = EntityState.Modified; if (ef.SaveChanges() > 0) { return(Content("修改成功")); } return(Content("修改失败")); }
public ActionResult Select(string page, string TextBookID, string ChapterName) { int ye = Convert.ToInt32(page) == 0 ? 1 : Convert.ToInt32(page); List <ChapterS> li = Show(); List <ChapterS> pagedList = null; int GradID = Convert.ToInt32(TextBookID); TextBook GrNa = ef.TextBooks.FirstOrDefault(x => x.BookID == GradID && x.Shan == false); if (!string.IsNullOrEmpty(ChapterName) && !string.IsNullOrEmpty(TextBookID)) { if (GradID >= 1) { pagedList = li.Where(x => x.ChapterName.Contains(ChapterName) && x.BookName == GrNa.BookName).Skip((ye - 1) * 10).Take(10).ToList(); } else { pagedList = li.Where(x => x.ChapterName.Contains(ChapterName)).ToList(); } } else if (string.IsNullOrEmpty(ChapterName) && GradID >= 1) { pagedList = li.Where(x => x.BookName == GrNa.BookName).ToList(); } else if (string.IsNullOrEmpty(TextBookID)) { pagedList = li.Where(x => x.ChapterName.Contains(ChapterName)).ToList(); } else { pagedList = li.ToList(); } int CountYe = pagedList.Count % 10 > 0 ? (pagedList.Count / 10) + 1 : pagedList.Count / 10; var Tili = new { Li = pagedList.Skip((ye - 1) * 10).Take(10).ToList(), Ye = CountYe, Hang = page }; return(Json(Tili, JsonRequestBehavior.AllowGet)); }
public TextBookSearchResult(TextBook aTextBook) { theTextBook = aTextBook; }
public virtual void DesignateTextbook(TextBook b, Course c) { // Logic for the method body goes here; details omitted. }
public void GivenIHaveATextbook() { var textbook = new TextBook(); ScenarioContext.Current.Set(textbook); }
//Clear output and instantiate objects private void resetValues() { txtOutput.Clear();//Clear output content myTextBook = new TextBook(); myWordCountUtils = new WordCountUtils(); }
public ActionResult DeleteChapter(string stringName) { // char theLeve = stringName.Last(); // string theNew = stringName.Replace(theLeve, ' '); // stringName = theNew + theLeve; // string physicalPathPdf = HttpContext.Server.MapPath("../") + "UploadPdf"; // string physicalPathPdf = WebConfigurationManager.AppSettings["harddisk"] + ":\\upload"; // File.Delete(Server.MapPath(YourVirtualPath)); try { //List<AdditionalChapterText> theAddChapterText = work.AdditionalChapterTextRepository.Get(a => a.ParentName.Equals(stringName)).ToList(); //List<TextBook> theTextBook = work.TextBookRepository.Get(a => a.ParentName.Equals(stringName)).ToList(); //List<Chapter> theChapter = work.ChapterRepository.Get(a => a.ParentName.Equals(stringName)).ToList(); //if (theAddChapterText.Count() > 0) //{ // AdditionalChapterText theAC = theAddChapterText[0]; // work.AdditionalChapterTextRepository.Delete(theAC); // work.Save(); //} //if (theTextBook.Count() > 0) //{ // TextBook theText = theTextBook[0]; // work.TextBookRepository.Delete(theText); // work.Save(); //} //if (theChapter.Count() > 0) //{ // Chapter theChap = theChapter[0]; // work.ChapterRepository.Delete(theChap); // work.Save(); //} //delete a textbook else delete a chapter or a subchapter string endText = "TextBook.pdf"; string endAdditonalChapterText = "Additional-Text.pdf"; if (stringName.EndsWith(endAdditonalChapterText)) { // string rootFolderPath = physicalPathPdf; // string filesToDelete = stringName; // Only delete DOC files containing "DeleteMe" in their filenames // string[] fileList = System.IO.Directory.GetFiles(rootFolderPath, filesToDelete); // foreach (string file in fileList) // { // System.IO.File.Delete(file); AdditionalChapterText theAddCapText = work.AdditionalChapterTextRepository.Get(a => a.ParentName.Equals(stringName)).Single(); work.AdditionalChapterTextRepository.Delete(theAddCapText); work.Save(); // } } if (stringName.EndsWith(endText)) { // string rootFolderPath = physicalPathPdf; // string filesToDelete = stringName; // Only delete DOC files containing "DeleteMe" in their filenames // string[] fileList = System.IO.Directory.GetFiles(rootFolderPath, filesToDelete); // foreach (string file in fileList) // { // System.IO.File.Delete(file); TextBook theCap = work.TextBookRepository.Get(a => a.ParentName.Equals(stringName)).Single(); work.TextBookRepository.Delete(theCap); work.Save(); // } //if (fileList.Count() == 0) //{ // TextBook theCap = work.TextBookRepository.Get(a => a.ParentName.Equals(stringName)).Single(); // if (theCap != null) // work.TextBookRepository.Delete(theCap); // work.Save(); //} } else // if (stringName.EndsWith(endText)) { //string rootFolderPath = physicalPathPdf; //string filesToDelete = stringName; // Only delete DOC files containing "DeleteMe" in their filenames //string[] fileList = System.IO.Directory.GetFiles(rootFolderPath, filesToDelete); //foreach (string file in fileList) //{ // System.IO.File.Delete(file); Chapter theCap = work.ChapterRepository.Get(a => a.ParentName.Equals(stringName)).Single(); //when u delete a chapter, you must delete its additional chapters under it List <AdditionalChapterText> theAddChapt = work.AdditionalChapterTextRepository.Get(a => a.ChapterID == theCap.ChapterID).ToList(); // string rootFolderPath1 = physicalPathPdf; foreach (var theCha in theAddChapt) { work.AdditionalChapterTextRepository.Delete(theCha); // string filesToDelete2 = stringName; // Only delete DOC files containing "DeleteMe" in their filenames // string[] fileList3 = System.IO.Directory.GetFiles(rootFolderPath1, theCha.ParentName); // foreach (string fil1e in fileList3) //{ // System.IO.File.Delete(fil1e); // } } work.ChapterRepository.Delete(theCap); work.Save(); } // } } catch (IOException e) { } return(RedirectToAction("Index", new { id = 1 })); // return View(stringName); }
public ActionResult Create(UploadTextBookViewModel model, IEnumerable <HttpPostedFileBase> file) { try { if (Request.Files[0] == null) { new ModelError("No Uploaded Document!"); return(View(model)); } string TheFileName = System.IO.Path.GetFileName(Request.Files[0].FileName); if (!(TheFileName.EndsWith(".pdf"))) { ModelState.AddModelError("", "The Input File is not a .pdf file!"); return(View(model)); } string Usepath = WebConfigurationManager.AppSettings["usehardisk"]; if (Usepath == "YES") { model.TextBookTitle = model.TextBookTitle.TrimEnd().TrimStart(); string[] FileExtension = TheFileName.Split('.'); string[] videotitlewithSpaces = model.TextBookTitle.Split(' '); StringBuilder videotitlenamebuilder = new StringBuilder(); List <string> thevideoNameList = videotitlewithSpaces.ToList(); if (thevideoNameList.Count > 0) { int theLengthReal = 0; foreach (var s in thevideoNameList) { if (s != "") { theLengthReal = theLengthReal + 1; } } int theLength = theLengthReal; //thevideoNameList.Count; int counter = 1; foreach (var s in thevideoNameList) { if (s != "") { videotitlenamebuilder.Append(s); if (counter < theLength) { counter = counter + 1; videotitlenamebuilder.Append("-"); } } } model.TextBookTitle = videotitlenamebuilder.ToString(); } if (ModelState.IsValid) { Level SubjectLevel = work.LevelRepository.Get(a => a.LevelName.Equals(model.Level)).First(); ////create byte array of size equal to file input stream //byte[] fileData = new byte[Request.Files[0].InputStream.Length]; //// fileData ////add file input stream into byte array //Request.Files[0].InputStream.Read(fileData, 0, Convert.ToInt32(Request.Files[0].InputStream.Length)); //fileData.ToArray(); //string physicalPath = HttpContext.Server.MapPath("../") + "UploadImages";// +"\\"; //string physicalPathPdf = HttpContext.Server.MapPath("../") + "UploadPdf";// +"\\"; //ParentNameC = model.Level + "-" + model.Subject + "-" + model.TextBookTitle + "-" + "TextBook" + ".pdf"; ////for (int i = 0; i < Request.Files.Count; i++) ////{ string[] splitedLevel = model.Level.Split(' '); if (splitedLevel.Count() > 1) { model.Level = splitedLevel[0] + splitedLevel[1]; } //string SaveLocation = string.Format("{0}\\{1}", physicalPath, model.Level + "-" + model.Subject + "-" + model.TextBookTitle + "-" + "TextBook" + ".pdf"); //SaveLocationPdf = string.Format("{0}\\{1}", physicalPathPdf, model.Level + "-" + model.Subject + "-" + model.TextBookTitle + "-" + "TextBook" + ".pdf"); ParentNameC = model.Level + "-" + model.Subject + "-" + model.TextBookTitle + "-" + "TextBook" + ".pdf"; string path = WebConfigurationManager.AppSettings["harddisk"] + ":\\upload";; string SaveLocationPdf = string.Format("{0}\\{1}", path, model.Level + "-" + model.Subject + "-" + model.TextBookTitle + "-" + "TextBook" + ".pdf"); //// System.IO.Path.GetFileName(Request.Files[i].FileName); //Request.Files[0].SaveAs(SaveLocation);//.SaveAs(SaveLocation); //Request.Files[0].SaveAs(SaveLocationPdf); List <Course> theTextBookCourse = work.CourseRepository.Get(a => a.Name.Equals(model.Subject) && a.LevelID == SubjectLevel.LevelID).ToList(); // List<Course> theTextBookCourse = work.CourseRepository.Get(a => a.Name.Equals(model.Subject) && a.LevelID == SubjectLevel.LevelID).ToList(); if (theTextBookCourse.Count() > 0) { Course C = theTextBookCourse[0]; List <TextBook> theChaps = work.TextBookRepository.Get(a => a.CourseID == C.CourseID).ToList(); //find if we have duplicate copy foreach (var chap in theChaps) { string thePPArt = ParentNameC.Trim().ToLower(); string chap2 = chap.ParentName.Trim().ToLower(); if (chap2.Equals(thePPArt)) { ModelState.AddModelError("", "A Texbook of this Name Already Exist!"); UploadTextBookViewModel themodel = new UploadTextBookViewModel(); themodel.Level = "JSS1"; // themodel.Subject = model.Subject; return(View("Create")); } } } TextBook theTextBook = new TextBook { Name = model.TextBookTitle, ParentName = ParentNameC, path = SaveLocationPdf, CourseID = theTextBookCourse[0].CourseID }; //, FileData = fileData.ToArray() Request.Files[0].SaveAs(SaveLocationPdf);//.SaveAs(SaveLocation); work.TextBookRepository.Insert(theTextBook); work.Save(); } } else { model.TextBookTitle = model.TextBookTitle.TrimEnd().TrimStart(); string[] FileExtension = TheFileName.Split('.'); string[] videotitlewithSpaces = model.TextBookTitle.Split(' '); StringBuilder videotitlenamebuilder = new StringBuilder(); List <string> thevideoNameList = videotitlewithSpaces.ToList(); if (thevideoNameList.Count > 0) { int theLengthReal = 0; foreach (var s in thevideoNameList) { if (s != "") { theLengthReal = theLengthReal + 1; } } int theLength = theLengthReal; //thevideoNameList.Count; int counter = 1; foreach (var s in thevideoNameList) { if (s != "") { videotitlenamebuilder.Append(s); if (counter < theLength) { counter = counter + 1; videotitlenamebuilder.Append("-"); } } } model.TextBookTitle = videotitlenamebuilder.ToString(); } if (ModelState.IsValid) { //Level SubjectLevel = work.LevelRepository.Get(a => a.LevelName.Equals(model.Level)).First(); Level SubjectLevel = work.LevelRepository.Get(a => a.LevelName == model.Level).First(); //create byte array of size equal to file input stream byte[] fileData = new byte[Request.Files[0].InputStream.Length]; // fileData //add file input stream into byte array Request.Files[0].InputStream.Read(fileData, 0, Convert.ToInt32(Request.Files[0].InputStream.Length)); fileData.ToArray(); ////string physicalPath = HttpContext.Server.MapPath("../") + "UploadImages";// +"\\"; ////string physicalPathPdf = HttpContext.Server.MapPath("../") + "UploadPdf";// +"\\"; ////ParentNameC = model.Level + "-" + model.Subject + "-" + model.TextBookTitle + "-" + "TextBook" + ".pdf"; //////for (int i = 0; i < Request.Files.Count; i++) //////{ ////string SaveLocation = string.Format("{0}\\{1}", physicalPath, model.Level + "-" + model.Subject + "-" + model.TextBookTitle + "-" + "TextBook" + ".pdf"); ////SaveLocationPdf = string.Format("{0}\\{1}", physicalPathPdf, model.Level + "-" + model.Subject + "-" + model.TextBookTitle + "-" + "TextBook" + ".pdf"); string[] theLeve = model.Level.Split(' '); string theLevel1 = theLeve[0] + theLeve[1]; ParentNameC = theLevel1 + "-" + model.Subject + "-" + model.TextBookTitle + "-" + "TextBook" + ".pdf"; // string path = WebConfigurationManager.AppSettings["harddisk"] + ":\\upload"; ; // string SaveLocationPdf = string.Format("{0}\\{1}", path, model.Level + "-" + model.Subject + "-" + model.TextBookTitle + "-" + "TextBook" + ".pdf"); //// System.IO.Path.GetFileName(Request.Files[i].FileName); //Request.Files[0].SaveAs(SaveLocation);//.SaveAs(SaveLocation); //Request.Files[0].SaveAs(SaveLocationPdf); List <Course> theTextBookCourse = work.CourseRepository.Get(a => a.Name.Equals(model.Subject) && a.LevelID == SubjectLevel.LevelID).ToList(); // List<Course> theTextBookCourse = work.CourseRepository.Get(a => a.Name.Equals(model.Subject) && a.LevelID == SubjectLevel.LevelID).ToList(); if (theTextBookCourse.Count() > 0) { Course C = theTextBookCourse[0]; List <TextBook> theChaps = work.TextBookRepository.Get(a => a.CourseID == C.CourseID).ToList(); //find if we have duplicate copy foreach (var chap in theChaps) { string thePPArt = ParentNameC.Trim().ToLower(); string chap2 = chap.ParentName.Trim().ToLower(); if (chap2.Equals(thePPArt)) { ModelState.AddModelError("", "A Texbook of this Name Already Exist!"); UploadTextBookViewModel themodel = new UploadTextBookViewModel(); themodel.Level = "JSS1"; // themodel.Subject = model.Subject; return(View("Create")); } } } //TextBook theTextBook = new TextBook {FileData = fileData.ToArray(), Name = model.TextBookTitle, ParentName = ParentNameC, path = SaveLocationPdf, CourseID = theTextBookCourse[0].CourseID }; TextBook theTextBook = new TextBook { FileData = fileData.ToArray(), Name = model.TextBookTitle, ParentName = ParentNameC, CourseID = theTextBookCourse[0].CourseID }; //, FileData = fileData.ToArray() // Request.Files[0].SaveAs(SaveLocationPdf);//.SaveAs(SaveLocation); work.TextBookRepository.Insert(theTextBook); work.Save(); } } return(RedirectToAction("Create", new { id = 1 })); // TODO: Add insert logic here // return RedirectToAction("Index"); } catch { return(View()); } }
/// <summary> /// 将根目录下的Question Libraries下的每个EXCEL文件中的试题导入数据库并创建索引 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button3_Click(object sender, EventArgs e) { Dictionary <string, string> dic = new Dictionary <string, string>();//主要试题中的科目与数据库中textbookname的名称不一致,这里建立一个对应关系,key是试题中的名称,value是数据库中的名称 string[] subjectResourse = { "航海学(航海仪器)", "航海学(航海气象与海洋学)", "航海学(航海地文、天文)", "船舶管理", "船舶结构与货运", "航海英语", "船舶操纵与避碰(船舶操纵)", "船舶操纵与避碰(船舶避碰)", "基本安全-个人安全与社会责任", "基本安全-个人求生", "基本安全-防火与灭火", "基本安全-基本急救", "精通救生艇筏和救助艇培训", "高级消防培训", "精通急救培训" }; string[] subjectData = { "航海学(航海地文、天文和仪器)", "航海学(航海气象与海洋学)", "航海学(航海地文、天文和仪器)", "船舶管理(驾驶员)", "船舶结构与货运", "航海英语(二、三副)", "船舶操纵与避碰(船舶操纵)", "船舶操纵与避碰(船舶避碰)", "个人安全与社会责任", "个人求生", "防火与灭火", "基本急救", "救生艇筏和救助艇操作及管理", "高级消防", "精通医疗急救" }; if (subjectData.Length != subjectResourse.Length) { throw new ArgumentException("两个科目的长度不一致"); } for (int i = 0; i < subjectData.Length; i++) { dic.Add(subjectResourse[i], subjectData[i]); } Difficulty difficulty = new DifficultyManager().GetModel(1); //difficultyid为1 是难度不确定 Users user = (Users)Session["User"]; //得到当前登录的用户 TextBook textbook = null; Chapter chapter = new Chapter(); Chapter node = new Chapter(); QuestionManager questionmanager = new QuestionManager(); //获得获取根目录下Question Libraries文件中的试题文件 string[] QuestionLibraries = Directory.GetFiles(Server.MapPath("~\\Question Libraries")); foreach (String path in QuestionLibraries) { FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); IWorkbook workbook = null; //获得EXCEL文档 if (path.IndexOf(".xlsx") > 0) // 2007版本 { workbook = new XSSFWorkbook(fs); } else if (path.IndexOf(".xls") > 0) // 2003版本 { workbook = new HSSFWorkbook(fs); } ISheet sheet = workbook.GetSheetAt(0); //获得文档中的第一个工作表 IRow firstrow = sheet.GetRow(0); //获得工作表中的第一行 int column = firstrow.LastCellNum; //获得第一行中的列数 int rownum = sheet.LastRowNum; for (int i = 1; i < rownum; i++) { Question question = new Question(); IRow row = sheet.GetRow(i); //表格中的数据是从0列开始,分别是0AllID/1Id/2SN/3SNID/4Subject/5Chapter/6Node/7Title/8Choosea/9Chooseb/10Choosec/11Choosed/12Answer/13Explain/14ImageAddress/15Remark question.QuestionTitle = row.GetCell(7).StringCellValue.Trim(); question.AnswerA = row.GetCell(8).StringCellValue.Trim() + ""; question.AnswerB = row.GetCell(9).StringCellValue.Trim() + ""; question.AnswerC = row.GetCell(10).StringCellValue.Trim() + ""; question.AnswerD = row.GetCell(11).StringCellValue.Trim() + ""; question.CorrectAnswer = common.tryparse(row.GetCell(12).StringCellValue.Trim()); question.Explain = row.GetCell(13).StringCellValue.Trim(); question.ImageAddress = row.GetCell(14).StringCellValue.Trim(); question.DifficultyId = difficulty.DifficultyId; question.UserId = user.UserId; string subjectFromExcel = row.GetCell(4).StringCellValue.Trim(); string subjectFromDb = dic[subjectFromExcel].Trim(); if (textbook == null || textbook.TextBookName != subjectFromDb) { textbook = new TextBookManager().GetModel(subjectFromDb)[0]; } question.TextBookId = textbook.TextBookId; question.PaperCodeId = textbook.PaperCodeId; //后面开始处理章节标题,先检测章标题,后检测节标题 //如果章标题不存在,进添加进去,如果节标题不存在,也添加进去 string chapterFromExcel = row.GetCell(5).StringCellValue.Trim(); string nodeFromExcel = row.GetCell(6).StringCellValue.Trim(); //章标题为空,或者没有,则要新建 if (chapter.TextBookId != textbook.TextBookId || chapter.ChapterName != chapterFromExcel) { ChapterManager chaptermanager = new ChapterManager(); List <Chapter> list = chaptermanager.GetModel(textbook.TextBookId, chapterFromExcel); if (list.Count > 0) { chapter = list[0]; } else { chapter = new Chapter(); chapter.TextBookId = textbook.TextBookId; chapter.ChapterName = chapterFromExcel; chapter.ChapterParentNo = 0; chapter.ChapterDeep = 0; chapter.ChapterRemark = chapterFromExcel; int resu = new ChapterManager().Add(chapter); if (resu > 0) { chapter.ChapterId = resu; } else { throw new Exception("插入章标题失败。"); } } } if (node.TextBookId != textbook.TextBookId || node.ChapterName != nodeFromExcel) { ChapterManager chaptermanager = new ChapterManager(); List <Chapter> list = chaptermanager.GetModel(textbook.TextBookId, nodeFromExcel); if (list.Count > 0) { node = list[0]; } else { node = new Chapter(); node.TextBookId = textbook.TextBookId; node.ChapterName = nodeFromExcel; node.ChapterParentNo = chapter.ChapterId; node.ChapterDeep = 1; node.ChapterRemark = nodeFromExcel; int resu = new ChapterManager().Add(node); if (resu > 0) { node.ChapterId = resu; } else { throw new Exception("插入节标题失败。"); } } } question.ChapterId = node.ChapterId; question.Remark = row.GetCell(15).StringCellValue.Trim(); int qr = questionmanager.Add(question); question.QuestionId = qr; common.CreateIndexofQuestion(new DirectoryInfo(IndexPath), question); // Thread.Sleep(5000); Debug.WriteLine("科目:" + path + ", 第 " + i + " 题 :" + qr); } ; //一本试题结束 } ; //全部结束 common.ShowMessageBox(this.Page, "全部完成"); }
public void perkuliahan(Instructor dosen, TextBook book) { instructor = dosen; textbook = book; }