private void paperStackPanel_LostFocus(object sender, RoutedEventArgs e) { //保存文本内容和墨笔文件 if (type == "yd") { if (path_isf != "") { ScienceResearchDataSetNew.语段Row dr = (ScienceResearchDataSetNew.语段Row)yd_dt.Rows.Find(yd_id); //TextRange textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd); //dr.语段 = textRange.Text; string text2 = xamlManageClass.xaml_save(richTextBox); dr["语段"] = text2; dr["宽度"] = richTextBox.Width; yd_ta.Update(yd_dt); //保存墨笔文件 if (File.Exists(path_isf)) { File.Delete(path_isf); } FileStream file_ink = new FileStream(path_isf, FileMode.OpenOrCreate); textboxInkcavasUserControl.inkCanvas.Strokes.Save(file_ink); file_ink.Close(); } } }
/// <summary> /// 保存参考资料以及文章 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, RoutedEventArgs e) { if (type == "refer") { DataRow dr = yd_dt.NewRow(); string text2 = xamlManageClass.xaml_save(richTextBox); dr["语段"] = text2; dr["宽度"] = richTextBox.Width; yd_dt.Rows.Add(dr); yd_ta.Update(yd_dt); //保存墨笔文件 ScienceResearchDataSetNew.语段Row yd = (ScienceResearchDataSetNew.语段Row)yd_dt.Rows.Find(new_yd_id); yd.语段isf = @".\科学研究\语段ISF\" + yd.ID + ".isf"; yd_ta.Update(yd_dt); path_isf = yd.语段isf; path_isf = MainWindow.path_translate(path_isf); if (File.Exists(path_isf)) { File.Delete(path_isf); } FileStream file_ink = new FileStream(path_isf, FileMode.OpenOrCreate); textboxInkcavasUserControl.inkCanvas.Strokes.Save(file_ink); file_ink.Close(); //为语段添加关键词 if (gjc != null) { dr = yd_gjc_dt.NewRow(); dr["语段ID"] = new_yd_id; dr["关键词ID"] = gjc.ID; yd_gjc_dt.Rows.Add(dr); yd_gjc_ta.Update(yd_gjc_dt); } } else if (type == "wz") { //保存文章 //string text2 = xamlManageClass.xaml_save(richTextBox); string text2 = TextFile.GetStringOfRichTextBox(richTextBox); TextFile.SaveStringToFile(text2, path_wz); //保存墨笔文件 if (File.Exists(path_isf)) { File.Delete(path_isf); } FileStream file_ink = new FileStream(path_isf, FileMode.OpenOrCreate); textboxInkcavasUserControl.inkCanvas.Strokes.Save(file_ink); file_ink.Close(); } MessageBox.Show("保存成功"); }
public void creat_text(ScienceResearchDataSetNew.语段Row yd, ReferUserControl referUserControl) { if (yd.语段 != "") { ReferTabItemUserControl referTabItemUserControl = new ReferTabItemUserControl(yd); TabItem referTabItemTabItem = new TabItem(); referTabItemTabItem.Header = yd.ID.ToString(); referTabItemTabItem.Content = referTabItemUserControl; referUserControl.referTabControl.Items.Clear(); referUserControl.referTabControl.Items.Add(referTabItemTabItem); referUserControl.referTabControl.SelectedItem = referTabItemTabItem; } }
public void referDataGrid_MouseLeftButtonUp() { if (referDataGrid.CurrentItem != null) { //选择变化时,查询该语段对应的关键词 var data = (from yd_gjc in yd_gjc_dt join gjc in gjc_dt on yd_gjc.关键词ID equals gjc.ID where yd_gjc.语段ID == paraReferID select new Keyword { 关键词 = gjc.关键词 }).ToList(); referKeywordDataGrid.ItemsSource = data; //更新参考图片 string figure_path = ""; string figure_path_isf = ""; var data2 = from data_item in yd_dt where data_item.ID == paraReferID select data_item; foreach (var d2 in data2) { try { figure_path = d2.图片.ToString(); figure_path_isf = d2.图片isf.ToString(); } catch { } } figure_path = MainWindow.path_translate(figure_path); figure_path_isf = MainWindow.path_translate(figure_path_isf); //墨笔文件 ScienceResearchDataSetNew.语段Row yd = (ScienceResearchDataSetNew.语段Row)yd_dt.Rows.Find(paraReferID); if (figure_path_isf != "") { MainWindow.mainWindow.rightTabControl.SelectedItem = MainWindow.mainWindow.paragraphFigureTabItem_r; creat_figure(MainWindow.mainWindow.paragraphFigureUserControl_r, yd); } else { creat_text(yd, MainWindow.referUserControl_duanwen_right); MainWindow.mainWindow.rightTabControl.SelectedItem = MainWindow.referTabItem_duanwen_right; } } }
/// <summary> /// 删除某一语段 /// </summary> /// <param name="yd">语段</param> public static void DeleteYd(ScienceResearchDataSetNew.语段Row yd) { //删除关键词 var keyword_list = (from data_item in MainWindow.yd_gjc_dt where data_item.语段ID == yd.ID select data_item).ToList(); foreach (ScienceResearchDataSetNew.语段_关键词Row yd_gjc in keyword_list) { yd_gjc.Delete(); } MainWindow.yd_gjc_ta.Update(MainWindow.yd_gjc_dt); //删除语段 yd.Delete(); MainWindow.yd_ta.Update(MainWindow.yd_dt); }
private void UserControl_GotFocus(object sender, RoutedEventArgs e) { if (type == "yd") { //重新加载文件 ScienceResearchDataSetNew.语段Row para = (ScienceResearchDataSetNew.语段Row)yd_dt.Rows.Find(yd_id); string yd_xaml = para.语段; if (yd_xaml != "" && yd_xaml.Substring(0, 13) == "<FlowDocument") { 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); paragraphRichTextBox.Document = doc; } //设置该控件与墨笔属性控件的关联 //InkPropertiesUserControl.canvas = inkCanvas; //加载墨笔 if (path_isf != null) { path_isf = MainWindow.path_translate(path_isf); FileStream file_ink = new FileStream(path_isf, FileMode.OpenOrCreate); if (file_ink.Length != 0) { inkCanvas.Strokes = new StrokeCollection(file_ink); } file_ink.Close(); } } else if (type == "wz") { //不用进行任何操作 } }
/// <summary> /// 对一段话的语段模式进行识别,并且返回相应的模式序列 /// </summary> /// <param name="para_str">输入语段的字符串</param> public static List <int> shibie_para_yd(string para_str) { var yd_mode_list = (from yd in yd_dt where yd.分类 == "模式" select yd).ToList(); int yd_mode_count = yd_mode_list.Count; List <int> yd_mode_int_list = new List <int>(); //-----------------对每一语段模式进行判断------------------------------ for (int i = 0; i < yd_mode_count; i++) { ScienceResearchDataSetNew.语段Row yd = yd_mode_list[i]; string yd_str = yd.语段; Regex regImg = new Regex("{.{1,10000}}", RegexOptions.IgnoreCase); MatchCollection matches = regImg.Matches(yd_str); string yd_mode_array_str = matches[matches.Count - 1].Value; yd_mode_array_str = yd_mode_array_str.Substring(1, yd_mode_array_str.Length - 2); string[] yd_mode_array = yd_mode_array_str.Split(new char[1] { ',' }); //如果para_str包含yd_mode_array中的单词达到一定比例,则可称该语段拥有该模式 int count = 0; int yd_mode_array_count = yd_mode_array.Count(); for (int j = 0; j < yd_mode_array_count; j++) { if (para_str.IndexOf(yd_mode_array[j]) != -1) { count++; } } if ((double)count / yd_mode_array_count > MainWindow.yd_mode_rate) { yd_mode_int_list.Add(yd.ID); } } return(yd_mode_int_list); }
/// <summary> /// 失去焦点事件处理程序 /// </summary> public void textboxLostFocus() { //保存文本内容和墨笔文件 if (type == "yd") { if (path_isf != null) { ScienceResearchDataSetNew.语段Row dr = (ScienceResearchDataSetNew.语段Row)yd_dt.Rows.Find(yd_id); if (dr != null) { string text2 = xamlManageClass.xaml_save(paragraphRichTextBox); dr["语段"] = text2; dr["宽度"] = paragraphRichTextBox.Width; //try //{ yd_ta.Update(yd_dt); //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message); //} //保存墨笔文件 if (File.Exists(path_isf)) { File.Delete(path_isf); } FileStream file_ink = new FileStream(path_isf, FileMode.OpenOrCreate); inkCanvas.Strokes.Save(file_ink); file_ink.Close(); } } } }
public void creat_figure(ParagraphFigureUserControl paragraphFigureUserControl, ScienceResearchDataSetNew.语段Row yd) { int paraReferID = yd.ID; string figure_path = yd.图片; string figure_path_isf = yd.图片isf; 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.img.Source = img; //加载笔记 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\\" + paraReferID.ToString() + ".isf"; //更新数据库 var data3 = from data_item in yd_dt where data_item.ID == paraReferID select data_item; foreach (var d3 in data3) { d3.图片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; } } else { MessageBox.Show("图片文件不存在"); } }
/// <summary> /// 段文标签页 /// </summary> /// <param name="yd"></param> public ReferTabItemUserControl(ScienceResearchDataSetNew.语段Row yd) { //用于显示语段内容 InitializeComponent(); saveToolBar.Visibility = Visibility.Collapsed; partAllToolBar.Visibility = Visibility.Collapsed; scienceResearchKey = MainWindow.scienceResearchKey; partRadioButton.IsChecked = true; richTextBox = textboxInkcavasUserControl.paragraphRichTextBox; yd_id = yd.ID; LoadDataBase(); textboxInkcavasUserControl.yd_id = yd_id; string yd_xaml = yd.语段; yd_xaml = TextFile.ReplaceLowOrderASCIICharacters(yd_xaml); //yd_xaml = yd_xaml.Replace(";", " "); string condition = yd_xaml.Substring(0, 13); if (condition == "<FlowDocument") { richTextBox.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(yd.语段); //r.SetBinding(Run.TextProperty, binding); p.Inlines.Add(r); doc.Blocks.Add(p); richTextBox.Document = doc; } //加载墨笔 path_isf = yd.语段isf; path_isf = MainWindow.path_translate(path_isf); if (path_isf != "") { FileStream file_ink = new FileStream(path_isf, FileMode.OpenOrCreate); if (file_ink.Length != 0) { textboxInkcavasUserControl.inkCanvas.Strokes = new StrokeCollection(file_ink); } file_ink.Close(); } if (path_isf == "") { //保存数据库 yd.语段isf = @".\科学研究\语段ISF\" + yd.ID + ".isf"; yd_ta.Update(yd_dt); path_isf = yd.语段isf; path_isf = MainWindow.path_translate(path_isf); } type = "yd"; textboxInkcavasUserControl.type = "yd"; textboxInkcavasUserControl.path_isf = path_isf; //调整宽度 double width = yd.宽度; if (width > 0) { textboxInkcavasUserControl.paragraphRichTextBox.Width = width; textboxInkcavasUserControl.inkCanvas.Width = width; } else { textboxInkcavasUserControl.paragraphRichTextBox.Width = MainWindow.yd_ck_width; textboxInkcavasUserControl.inkCanvas.Width = MainWindow.yd_ck_width; } zhinengPipeiUserControl.referTabItemUserControl = this; zhinengPipeiUserControl.textboxInkcavasUserControl_using = textboxInkcavasUserControl; zhinengPipeiUserControl.type = "refer"; }