void cbTutorail_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (cbTutorail.SelectedValue == null) { return; } List <TutorailChapter> chapters; int selectValue = int.Parse(cbTutorail.SelectedValue.ToString()); using (var tutoraildb = new TutorailsDBContext()) { chapters = (from c in tutoraildb.Chapters where c.tutorialitem == selectValue select c).OrderBy(c => c.chapter_seq).ToList(); foreach (TutorailChapter c in chapters) { c.chapter_name = c.id + "_" + c.chapter_name; } lvChapter.ItemsSource = chapters; lvChapter.DisplayMemberPath = "chapter_name"; lvChapter.SelectedValuePath = "id"; } }
void cbCategory_SelectionChanged(object sender, SelectionChangedEventArgs e) { List <TutorailItem> tutorails; int selectValue = 49; if (cbCategory.SelectedValue != null) { selectValue = int.Parse(cbCategory.SelectedValue.ToString()); } using (var tutoraildb = new TutorailsDBContext()) { tutorails = (from i in tutoraildb.Items where i.category == selectValue select i).ToList <TutorailItem>(); foreach (TutorailItem i in tutorails) { i.item_name = i.id + "_" + i.item_name; } if (tutorails != null) { this.cbTutorail.ItemsSource = tutorails; this.cbTutorail.DisplayMemberPath = "item_name"; this.cbTutorail.SelectedValuePath = "id"; this.cbTutorail.SelectedIndex = 0; } } }
public void InitData() { using (var tutoraildb = new TutorailsDBContext()) { List <TutorailCategory> categorys = tutoraildb.Categorys.ToList <TutorailCategory>(); foreach (TutorailCategory tc in categorys) { tc.module_name = tc.id + "_" + tc.module_name; } this.cbCategory.ItemsSource = categorys; this.cbCategory.SelectedValuePath = "id"; this.cbCategory.DisplayMemberPath = "module_name"; this.cbCategory.SelectedValue = 49; } }
public IEnumerable <IGrouping <string, TutorailChapter> > GetTutorailMenuAndContent(int tutorailid, int chapterid, out TutorailChapter chapter) { TutorailChapter tcChapter = null; chapter = tcChapter; List <TutorailChapter> chapters; using (var db = new TutorailsDBContext()) { chapters = (from c in db.Chapters where c.tutorialitem == tutorailid select c ).OrderBy(c => c.chapter_seq).ToList <TutorailChapter>(); //var sqlParameter = new MySqlParameter("@tutorialitem", Request.QueryString["item"]); //sw.Start(); //chapters = db.Chapters.SqlQuery("select * from dt_tutorial_chapter where tutorialitem = @tutorialitem", sqlParameter).ToList(); //sw.Stop(); //long t2 = sw.ElapsedMilliseconds; if (chapters == null || chapters.Count == 0) { return(null); } chapter = (from c in db.Chapters where c.id == chapterid select c).Single(); var listChapterGroups = chapters.GroupBy(p => p.chapter_group); foreach (var group in listChapterGroups) { group.OrderBy(c => c.chapter_seq); } return(listChapterGroups); } }
private void btnEdit_Click(object sender, RoutedEventArgs e) { if (txtSource.Text == "" || txtReplace.Text == "") { MessageBox.Show("请输入正确的值"); return; } using (var tutorailDB = new TutorailsDBContext()) { var paraSource = new MySqlParameter("@source", txtSource.Text); var paraReplace = new MySqlParameter("@replace", txtReplace.Text); var id = new MySqlParameter("@id", EditChapterID); var result = tutorailDB.Database.ExecuteSqlCommand(@"update dt_tutorial_chapter set charpter_content = replace(charpter_content, @source, @replace) where id = @id;", paraSource, paraReplace, id); if (result != 0) { this.Close(); } } }
public void GenarateHtmFile() { IEnumerable <IGrouping <string, TutorailChapter> > dicMenu; TutorailChapter chapterContent; List <TutorailChapter> listChapters = null; List <TutorailItem> listTutorails = null; if (cbTutorail.SelectedValue == "" || lvChapter.SelectedValue == "") { return; } int intItemId; int intChapterId; int tutorailCategoryID; if (!int.TryParse(cbTutorail.SelectedValue.ToString(), out intItemId)) { return; } if (!int.TryParse(lvChapter.SelectedValue.ToString(), out intChapterId)) { return; } tutorailCategoryID = int.Parse(cbCategory.SelectedValue.ToString()); using (var tutoraildb = new TutorailsDBContext()) { if (cbGenarate.SelectionBoxItem.ToString() == "本类别") { listChapters = (from c in tutoraildb.Chapters join t in tutoraildb.Items on c.tutorialitem equals t.id where t.category == tutorailCategoryID select c).ToList <TutorailChapter>(); listTutorails = (from t in tutoraildb.Items where t.category == tutorailCategoryID select t).ToList(); genarateType = GenarateType.Category; } if (cbGenarate.SelectionBoxItem.ToString() == "本教程") { listChapters = (from c in tutoraildb.Chapters where c.tutorialitem == intItemId select c).ToList <TutorailChapter>(); genarateType = GenarateType.Tutorail; } if (cbGenarate.SelectionBoxItem.ToString() == "当前页面") { listChapters = (from c in tutoraildb.Chapters where c.id == intChapterId select c).ToList <TutorailChapter>(); genarateType = GenarateType.Page; } } if (genarateType == GenarateType.Category) { foreach (TutorailItem item in listTutorails) { dicMenu = GetTutorailMenuFromLocal(item.id, listChapters, genarateType); List <TutorailChapter> tchapters = (from c in listChapters where c.tutorialitem == item.id select c).ToList(); foreach (TutorailChapter chapter in tchapters) { CreateFile(dicMenu, chapter); } } } else if (genarateType == GenarateType.Tutorail) { dicMenu = GetTutorailMenuFromLocal(intItemId, listChapters, genarateType); foreach (TutorailChapter chapter in listChapters) { CreateFile(dicMenu, chapter); } } else { dicMenu = GetTutorailMenuAndContent(intItemId, intChapterId, out chapterContent); if (listChapters.Count > 0) { CreateFile(dicMenu, listChapters[0]); } } }