private void btnLoadInk_Click(object sender, RoutedEventArgs e) { WindowsFormsHostUserControl host = (WindowsFormsHostUserControl)((TabItem)applicationTabControl.SelectedItem).Content; handle = host.handle_application; ParagraphFigureUserControl paragraphFigureUserControl = new ParagraphFigureUserControl(); //paragraphFigureUserControl.HideToolBar(); TabItem paragraphFigureTabItem = new TabItem(); paragraphFigureTabItem.Header = "图片"; paragraphFigureTabItem.Content = paragraphFigureUserControl; applicationTabControl.Items.Add(paragraphFigureTabItem); applicationTabControl.SelectedItem = paragraphFigureTabItem; //加载图片 System.Drawing.Bitmap bitBmp = MainWindow.PrtWindow(handle); BitmapSource bs = Imaging.CreateBitmapSourceFromHBitmap(bitBmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); ImageSource img = bs; paragraphFigureUserControl.img.Source = img; }
/// <summary> /// 获取同单词word对应的段图、段文和Xps文件 /// </summary> /// <param name="danci"></param> public void pipei_dc(string danci) { if (danci != "") { set_refer(); danci = danci.Replace("\r", ""); danci = danci.Replace("\n", ""); var dc_list = (from dc in dc_dt where dc.单词 == danci select dc).ToList(); if (dc_list.Count == 0) { MessageBox.Show("不存在单词:" + danci); return; } var gjc_list = (from dc_gjc in dc_gjc_dt where dc_gjc.单词ID == dc_list[0].ID select dc_gjc.关键词Row).ToList(); if (gjc_list.Count == 0) { createReferTextXps(null, dc_list[0]); } else { string gjc_output_str = "选中的单词含有以下关键词:"; for (int i = 0; i < gjc_list.Count; i++) { //对关键词对应的语段生成段图和段文 if (ModeSetup.pipeiDictionary["is_dc_yd_pipei"] == "是") { var yd_list = (from gjc in gjc_dt join yd_gjc in MainWindow.yd_gjc_dt on gjc.ID equals yd_gjc.关键词ID join yd in MainWindow.yd_dt on yd_gjc.语段ID equals yd.ID where gjc.ID == gjc_list[i].ID select yd).ToList(); for (int j = 0; j < yd_list.Count; j++) { //段图 if (yd_list[j].图片 != "") { ParagraphFigureUserControl paragraphFigureUserControl = new ParagraphFigureUserControl(); ParaResourceClass_PaperDataGrid paraResourceClass_PaperDataGrid = new ParaResourceClass_PaperDataGrid(); paraResourceClass_PaperDataGrid.creat_figure(paragraphFigureUserControl, yd_list[j]); TabItem referTabItemTabItem = new TabItem(); referTabItemTabItem.Header = yd_list[j].ID; referTabItemTabItem.Content = paragraphFigureUserControl; referUserControl_using.referTabControl.Items.Add(referTabItemTabItem); } //段文 if (yd_list[j].语段 != "") { ReferUserControl referUserControl = new ReferUserControl("yd"); ParaResourceClass_PaperDataGrid paraResourceClass_PaperDataGrid = new ParaResourceClass_PaperDataGrid(); paraResourceClass_PaperDataGrid.creat_text(yd_list[j], referUserControl); TabItem referTabItemTabItem = new TabItem(); referTabItemTabItem.Header = yd_list[j].ID; referTabItemTabItem.Content = referUserControl; referUserControl_using.referTabControl.Items.Add(referTabItemTabItem); } } } //ReferText和Xps gjc_output_str += gjc_list[i].关键词 + ","; var dc_list2 = (from dc_gjc in dc_gjc_dt where dc_gjc.关键词ID == gjc_list[i].ID select dc_gjc.单词Row).ToList(); for (int j = 0; j < dc_list2.Count; j++) { //对该单词生成一个ReferText和Xps标签页 ScienceResearchDataSetNew.关键词Row gjc_page = gjc_list[i]; ScienceResearchDataSetNew.单词Row dc_page = dc_list2[j]; createReferTextXps(gjc_page, dc_page); } //对于文章创作标签页,跳参后要将关键词标注 if (type == "paper") { //对keywordDataGrid2中的选项做标识 for (int j = 0; j < keywordDataGrid2.Items.Count; j++) { ScienceResearchDataSetNew.关键词Row drv = keywordDataGrid2.Items[j] as ScienceResearchDataSetNew.关键词Row; string gjc = drv.关键词; if (gjc == gjc_list[i].关键词) { DataGridRow row = (DataGridRow)keywordDataGrid2.ItemContainerGenerator.ContainerFromIndex(j); row.Foreground = new SolidColorBrush(ColorManager.color_mode_word); } } } } } if (referUserControl_using.referTabControl.Items.Count > 0) { referUserControl_using.referTabControl.SelectedIndex = 0; } } }
private void pageLoad(int start, int sectionLength) { pageTextBox.Text = (start / sectionLength + 1).ToString(); //按语段+关键字循环 for (int i = 0; i < sectionLength; i++) { if (startPoint + i < length) { int paraId = paragraphIdKeywords[startPoint + i].paragraphId; string gjc = paragraphIdKeywords[startPoint + i].keyword; var paragraph = from data_item in yd_dt where data_item.ID == paraId select data_item; foreach (var para in paragraph) { //语段编号 textBlock = new TextBlock(); textBlock.Inlines.Add(new Run(para.ID.ToString() + ":" + gjc) { Foreground = Brushes.Red }); paperStackPanel.Children.Add(textBlock); //文本框 if (para["分类"].ToString() != "图片语段") { string path_isf = ""; path_isf = para.语段isf; if (path_isf == "") { //保存数据库 para.语段isf = @".\科学研究\语段ISF\" + para.ID + ".isf"; yd_ta.Update(yd_dt); path_isf = para.语段isf; } textboxInkcavasUserControl = new TextboxInkcavasUserControl(path_isf); textboxInkcavasUserControl.GotFocus += textboxInkcavasUserControl_GotFocus; textboxInkcavasUserControl.StylusDown += TextboxInkcavasUserControl_StylusDown; textboxInkcavasUserControl.PreviewMouseLeftButtonDown += TextboxInkcavasUserControl_PreviewMouseLeftButtonDown; textboxInkcavasUserControl.yd_dt = yd_dt; textboxInkcavasUserControl.yd_ta = yd_ta; double width = para.宽度; if (width > 0) { textboxInkcavasUserControl.paragraphRichTextBox.Width = width; textboxInkcavasUserControl.inkCanvas.Width = width; } else { textboxInkcavasUserControl.paragraphRichTextBox.Width = MainWindow.yd_cz_width; textboxInkcavasUserControl.inkCanvas.Width = MainWindow.yd_cz_width; } //Binding binding = new Binding(); //binding.Source = para; //binding.Path = new PropertyPath("语段"); //binding.Mode = BindingMode.TwoWay; //textboxInkcavasUserControl.paragraphRichTextBox.SetBinding(TextBox.TextProperty, binding); string yd_xaml = para.语段; string condition = yd_xaml.Substring(0, 13); if (condition == "<FlowDocument") { textboxInkcavasUserControl.paragraphRichTextBox.Document = xamlManageClass.xaml_load(yd_xaml); } else { FlowDocument doc = new FlowDocument(); doc.LineHeight = 10; Paragraph p = new Paragraph(); p.LineHeight = 30; Run r = new Run(para.语段); //r.SetBinding(Run.TextProperty, binding); p.Inlines.Add(r); doc.Blocks.Add(p); textboxInkcavasUserControl.paragraphRichTextBox.Document = doc; } paperStackPanel.Children.Add(textboxInkcavasUserControl); textboxInkcavasUserControl.yd_id = para.ID; } else { string figure_path = ""; string figure_path_isf = ""; var data4 = from data_item in yd_dt where data_item.ID == para.ID select data_item; foreach (var d4 in data4) { figure_path = d4.图片.ToString(); figure_path_isf = d4.图片isf.ToString(); } figure_path = MainWindow.path_translate(figure_path); figure_path_isf = MainWindow.path_translate(figure_path_isf); ParagraphFigureUserControl paragraphFigureUserControl = new ParagraphFigureUserControl(); if (File.Exists(figure_path)) { //存在图片 //BitmapImage img = new BitmapImage(); //img.BeginInit(); //img.CacheOption = BitmapCacheOption.OnLoad; //img.UriSource = new Uri(figure_path); //img.EndInit(); //ImageSource img = new BitmapImage(new Uri(figure_path, UriKind.RelativeOrAbsolute)); //ImageSource img2=img.Clone(); BitmapImage bitmapImage; BinaryReader reader = new BinaryReader(File.Open(figure_path, FileMode.Open)); FileInfo fi = new FileInfo(figure_path); byte[] bytes = reader.ReadBytes((int)fi.Length); reader.Close(); bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = new MemoryStream(bytes); bitmapImage.EndInit(); paragraphFigureUserControl.img.Source = bitmapImage; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; } else { //不存在图片的时候 } paragraphFigureUserControl.grid.RowDefinitions[0].Height = new GridLength(0); paragraphFigureUserControl.paragraphId = para.ID; paragraphFigureUserControl.GotFocus += ParagraphFigureUserControl_GotFocus; paragraphFigureUserControl.StylusDown += ParagraphFigureUserControl_StylusDown; if (File.Exists(figure_path_isf)) { FileStream file_ink = new FileStream(figure_path_isf, FileMode.OpenOrCreate); if (file_ink.Length != 0) { paragraphFigureUserControl.canvas.Strokes = new StrokeCollection(file_ink); } file_ink.Close(); paragraphFigureUserControl.figure_path_isf = figure_path_isf; } else { paragraphFigureUserControl.canvas.Strokes.Clear(); figure_path_isf = ".\\科学研究\\图片ISF\\" + para.ID + ".isf"; //更新数据库 var data5 = from data_item in yd_dt where data_item.ID == para.ID select data_item; foreach (var d5 in data5) { d5.图片isf = figure_path_isf; yd_ta.Update(yd_dt); } //更新墨笔文件路径 figure_path_isf = MainWindow.path_translate(figure_path_isf); paragraphFigureUserControl.figure_path_isf = figure_path_isf; } paperStackPanel.Children.Add(paragraphFigureUserControl); } //所有参考语段的图片 var data3 = from gjc2 in gjc_dt join yd_gjc in yd_gjc_dt on gjc2.ID equals yd_gjc.关键词ID join yd in yd_dt on yd_gjc.语段ID equals yd.ID where gjc2.关键词 == gjc select new ParagraphID { 语段ID = yd.ID }; foreach (var d3 in data3) { textBlock = new TextBlock(); textBlock.Text = d3.语段ID.ToString(); paperStackPanel.Children.Add(textBlock); string figure_path = ""; string figure_path_isf = ""; var data4 = from data_item in yd_dt where data_item.ID == d3.语段ID select data_item; foreach (var d4 in data4) { try { figure_path = d4.图片.ToString(); figure_path_isf = d4.图片isf.ToString(); } catch { } finally { } } figure_path = MainWindow.path_translate(figure_path); figure_path_isf = MainWindow.path_translate(figure_path_isf); if (File.Exists(figure_path)) { ImageSource img = new BitmapImage(new Uri(figure_path, UriKind.RelativeOrAbsolute)); ParagraphFigureUserControl p = new ParagraphFigureUserControl(); p.img.Source = img; p.grid.RowDefinitions[0].Height = new GridLength(0); if (File.Exists(figure_path_isf)) { FileStream file_ink = new FileStream(figure_path_isf, FileMode.OpenOrCreate); if (file_ink.Length != 0) { p.canvas.Strokes = new StrokeCollection(file_ink); } file_ink.Close(); p.figure_path_isf = figure_path_isf; } else { p.canvas.Strokes.Clear(); figure_path_isf = ".\\科学研究\\图片ISF\\" + d3.语段ID.ToString() + ".isf"; //更新数据库 var data5 = from data_item in yd_dt where data_item.ID == d3.语段ID select data_item; foreach (var d5 in data5) { d5.图片isf = figure_path_isf; yd_ta.Update(yd_dt); } //更新墨笔文件路径 figure_path_isf = MainWindow.path_translate(figure_path_isf); p.figure_path_isf = figure_path_isf; } paperStackPanel.Children.Add(p); } } } } } foreach (object t in paperStackPanel.Children) { string name = t.GetType().FullName; if (name == "ScienceResearchWpfApplication.TextManage.TextboxInkcavasUserControl") { ((TextboxInkcavasUserControl)t).inkCanvas.SetValue(Grid.ZIndexProperty, 1); ((TextboxInkcavasUserControl)t).paragraphRichTextBox.SetValue(Grid.ZIndexProperty, 0); } } }