255 lines
10 KiB
C#
255 lines
10 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Windows.Forms;
|
||
using DocumentManagement;
|
||
using DCSoft.Writer.Controls;
|
||
using System.CodeDom.Compiler;
|
||
using System.Reflection;
|
||
using Microsoft.CSharp;
|
||
using DCSoft.Writer;
|
||
using DCSoft.Writer.Dom;
|
||
using System.Xml;
|
||
|
||
namespace DrawGraphManagement
|
||
{
|
||
public partial class frmTemplateD : Form
|
||
{
|
||
private WriterControl myEditControl;
|
||
|
||
private frmTemplate temp;
|
||
|
||
private ucClassify ucClassify;
|
||
|
||
//private CompilerResults cr;
|
||
|
||
//private Type type;
|
||
|
||
private EventCodeCompiler codeCompiler;
|
||
|
||
public frmTemplateD()
|
||
{
|
||
InitializeComponent();
|
||
ucClassify = new DocumentManagement.ucClassify();
|
||
this.panel1.Controls.Add(ucClassify);
|
||
ucClassify.Dock = DockStyle.Fill;
|
||
ucClassify.IsReadOnly = false;
|
||
ucClassify.tv.NodeMouseClick += new TreeNodeMouseClickEventHandler(tv_NodeMouseClick);
|
||
ucClassify.ms.Items["添加同级目录ToolStripMenuItem"].Click += new EventHandler(添加同级目录ToolStripMenuItem_Click);
|
||
ucClassify.ms.Items["添加子目录ToolStripMenuItem"].Click += new EventHandler(添加子目录ToolStripMenuItem_Click);
|
||
ucClassify.ms.Items["重命名当前节点ToolStripMenuItem"].Click += new EventHandler(重命名当前节点ToolStripMenuItem_Click);
|
||
ucClassify.ms.Items["删除当前节点ToolStripMenuItem"].Click += new EventHandler(删除当前节点ToolStripMenuItem_Click);
|
||
ucClassify.RefreshTree();
|
||
|
||
temp = new frmTemplate();
|
||
myEditControl = temp.editControl;
|
||
|
||
//codeCompiler = new EventCodeCompiler(myEditControl,"","");
|
||
|
||
temp.TopLevel = false;
|
||
temp.Parent = panel2;
|
||
temp.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
|
||
temp.Dock = DockStyle.Fill;
|
||
temp.Show();
|
||
|
||
this.FormClosing += temp.frmTemplate_FormClosing;
|
||
}
|
||
#if debug
|
||
private void SetValueById(string Id, string type, object value)
|
||
{
|
||
var element = myEditControl.Document.GetElementsById(Id).FirstElement;
|
||
if (element != null)
|
||
{
|
||
var pChecked = element.GetType().GetProperty(type);
|
||
pChecked.SetValue(element, value, null);
|
||
element.EditorRefreshView();
|
||
}
|
||
}
|
||
|
||
private void SetValueByName(string name, string type,object value)
|
||
{
|
||
var element = myEditControl.Document.GetElementsByName(name).FirstElement;
|
||
if (element != null)
|
||
{
|
||
var pChecked = element.GetType().GetProperty(type);
|
||
pChecked.SetValue(element, value, null);
|
||
element.EditorRefreshView();
|
||
}
|
||
}
|
||
|
||
private bool GetCheckedValueByName(string name)
|
||
{
|
||
bool? result = null;
|
||
var element = myEditControl.Document.GetElementsByName(name).FirstElement;
|
||
if (element != null)
|
||
{
|
||
var pChecked = element.GetType().GetProperty("Checked");
|
||
result = Convert.ToBoolean(pChecked.GetValue(element, null));
|
||
}
|
||
return result.Value;
|
||
}
|
||
#endif
|
||
void tv_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
|
||
{
|
||
TreeNode node = e.Node;
|
||
if (e.Button == System.Windows.Forms.MouseButtons.Left && node != ucClassify.tv.SelectedNode)
|
||
{
|
||
try
|
||
{
|
||
if (myEditControl.Document.Modified)
|
||
{
|
||
DialogResult result = MessageBox.Show("文件已经修改,尚未保存,是否保存文件?"
|
||
, "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
|
||
MessageBoxDefaultButton.Button1);
|
||
switch (result)
|
||
{
|
||
case DialogResult.Yes:
|
||
codeCompiler = new EventCodeCompiler(ref myEditControl, temp.RTB_Click.Text, temp.RTB_Content.Text);
|
||
if (codeCompiler.Errors.Count > 0)
|
||
{
|
||
throw new Exception(codeCompiler.Errors[0].ErrorText);
|
||
}
|
||
temp.InsertOrUpdate();
|
||
break;
|
||
case DialogResult.No:
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
temp.model = DocumentDAL.GetTemplatebyId(int.Parse(node.Name));
|
||
this.Text = temp.model.XmlFileName;
|
||
if (temp.model.XmlStatic != string.Empty)
|
||
{
|
||
XmlDocument doc = new XmlDocument();
|
||
doc.LoadXml(temp.model.XmlStatic);
|
||
temp.RTB_Click.Text = doc.GetElementsByTagName("ClickEvent")[0].InnerText;
|
||
temp.RTB_Content.Text = doc.GetElementsByTagName("ContentChangedEnvent")[0].InnerText;
|
||
}
|
||
else
|
||
{
|
||
temp.RTB_Click.Text = "";
|
||
temp.RTB_Content.Text = "";
|
||
}
|
||
if (temp.model.XmlFile != string.Empty)
|
||
{
|
||
myEditControl.LoadDocumentFromString(temp.model.XmlFile, "xml");
|
||
this.codeCompiler = new EventCodeCompiler(ref myEditControl, temp.RTB_Click.Text, temp.RTB_Content.Text);
|
||
}
|
||
else
|
||
{
|
||
myEditControl.ExecuteCommand("FileNew", true, null);
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void 添加同级目录ToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
TreeNode node = ucClassify.tv.SelectedNode;
|
||
frmTitle f = new frmTitle();
|
||
f.model = new PrintTemplate()
|
||
{
|
||
ParentId = node.Parent == null ? 0 : int.Parse(node.Parent.Name),
|
||
OperatorNo = AIMSExtension.PublicMethod.OperatorNo
|
||
};
|
||
if (f.ShowDialog() != DialogResult.OK)
|
||
{
|
||
return;
|
||
}
|
||
DocumentDAL.InsertTemplate(f.model);
|
||
ucClassify.RefreshTree(f.model.Id.ToString());
|
||
}
|
||
|
||
private void 添加子目录ToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
frmTitle f = new frmTitle();
|
||
f.model = new PrintTemplate()
|
||
{
|
||
ParentId = int.Parse(ucClassify.tv.SelectedNode.Name),
|
||
OperatorNo = AIMSExtension.PublicMethod.OperatorNo
|
||
};
|
||
if (f.ShowDialog() != DialogResult.OK)
|
||
{
|
||
return;
|
||
}
|
||
DocumentDAL.InsertTemplate(f.model);
|
||
ucClassify.RefreshTree(f.model.Id.ToString());
|
||
//myEditControl.ExecuteCommand("FileNew", true, null);
|
||
}
|
||
|
||
private void 重命名当前节点ToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
frmTitle f = new frmTitle();
|
||
TreeNode node = ucClassify.tv.SelectedNode;
|
||
f.model = new PrintTemplate()
|
||
{
|
||
Id = int.Parse(node.Name),
|
||
XmlFileName = node.Text,
|
||
OperatorNo = AIMSExtension.PublicMethod.OperatorNo
|
||
};
|
||
f.ShowDialog();
|
||
if (f.DialogResult == DialogResult.OK)
|
||
{
|
||
DocumentDAL.UpdateTemplateName(f.model);
|
||
node.Text = f.model.XmlFileName;
|
||
this.Text = f.model.XmlFileName;
|
||
}
|
||
}
|
||
|
||
private void 删除当前节点ToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
TreeNode node = ucClassify.tv.SelectedNode;
|
||
if (node == null)
|
||
{
|
||
return;
|
||
}
|
||
//else if (node.Parent == null)
|
||
//{
|
||
// MessageBox.Show("根节点不可删除!");
|
||
// return;
|
||
//}
|
||
string text1 = "是否删除当前文档[" + node.Text + "]?";
|
||
//string text2 = "是否删除当前节点[" + node.Text + "]及其子文档?";
|
||
DialogResult result = MessageBox.Show(text1, "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
|
||
MessageBoxDefaultButton.Button1);
|
||
if (result == System.Windows.Forms.DialogResult.Yes)
|
||
{
|
||
DocumentDAL.DeleteTemplate(temp.model);
|
||
ucClassify.RefreshTree();
|
||
if (ucClassify.tv.Nodes.Count > 0)
|
||
{
|
||
ucClassify.tv.SelectedNode = ucClassify.tv.Nodes[0];
|
||
this.Text = ucClassify.tv.SelectedNode.Text;
|
||
temp.model = DocumentDAL.GetTemplatebyId(int.Parse(ucClassify.tv.SelectedNode.Name));
|
||
if (temp.model.XmlFile != string.Empty)
|
||
{
|
||
myEditControl.LoadDocumentFromString(temp.model.XmlFile, "xml");
|
||
this.codeCompiler = new EventCodeCompiler(ref myEditControl, temp.RTB_Click.Text, temp.RTB_Content.Text);
|
||
}
|
||
else
|
||
{
|
||
myEditControl.ExecuteCommand("FileNew", true, null);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message);
|
||
}
|
||
}
|
||
}
|
||
}
|