Exemple #1
0
        /// <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("保存成功");
        }
        private void createPaperButton_Click(object sender, RoutedEventArgs e)
        {
            //创建文章和空白语段
            string projectId = projectIdTextBox.Text;
            string paperName = paperNameTextBox.Text;

            //新建文章
            DataRow newRow;

            newRow = wz_dt.NewRow();

            try
            {
                newRow["文章名"]  = paperName;
                newRow["分类"]   = "创作";
                newRow["项目ID"] = projectId;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            wz_dt.Rows.Add(newRow);
            try
            {
                //新建空白语段
                wz_ta.Update(wz_dt);
                int paperId_white = newDataId;
                int duanshu       = 0;
                try
                {
                    duanshu = int.Parse(paraNumberTextBox.Text);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    var wz_del_list = (from wz in wz_dt
                                       where wz.ID == paperId_white
                                       select wz).ToList();

                    wz_del_list[0].Delete();
                    wz_ta.Update(wz_dt);
                }

                for (int i = 0; i < duanshu; i++)
                {
                    newRow         = yd_dt.NewRow();
                    newRow["排序"]   = i + 1;
                    newRow["文章ID"] = paperId_white;
                    yd_dt.Rows.Add(newRow);
                    try
                    {
                        yd_ta.Update(yd_dt);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        yd_ta.Fill(yd_dt);
                    }
                }

                //刷新打开文章表
                var data = from wz in wz_dt
                           where wz["分类"] != DBNull.Value && (string)wz["分类"] == "创作"
                           select new Paper2
                {
                    ID  = wz.ID,
                    文章名 = wz.文章名
                };
                paperDataGrid.ItemsSource = data;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                wz_ta.Fill(wz_dt);
            }

            MessageBox.Show("文章创建成功");
        }