📄 stream.cs
字号:
/// <summary>
/// 属性:用户ID
/// </summary>
public int UserID
{
get
{
return nUserID;
}
set
{
nUserID=value;
}
}
/// <summary>
/// 属性:流程定义字符串
/// </summary>
public string StreamDef
{
get
{
return cStream;
}
set
{
cStream=value;
}
}
/// <summary>
/// 属性:系统标识,标识此流程是否系统流程
/// </summary>
public bool SystemSign
{
get
{
return systemSign;
}
set
{
systemSign=value;
}
}
/// <summary>
/// 获取数据集
/// </summary>
/// <returns>成功或失败</returns>
private void SetData()
{
this.oobjs.GetData();
}
/// <summary>
/// 根据索引字段查询单一的元素,不能与foreach共同使用
/// </summary>
/// <param name="id"></param>
/// <returns>查到/没有查到</returns>
public bool Search(int StreamID)
{
string sql="SELECT StreamID, StreamName, LastEditDate, UserID, Stream, SystemSign,Description FROM Stream where StreamID='"+StreamID.ToString()+"'";//在此填写你的Sql语句
System.Data.SqlClient.SqlDataReader oDataReader;
try
{
oDataReader=this.RunCommand(sql);
}
catch(System.Data.SqlClient.SqlException e)
{
if(this.Connection.State==System.Data.ConnectionState.Open)
this.Connection.Close();
this.Connection.Dispose();
throw new AppException("执行下列SQL语句出错:\n\r"+sql,e);
}
//设置各属性质
if(oDataReader.Read())
{
//以下代码为类:Stream的属性变量
if (!oDataReader.IsDBNull(0))
{
this.nStreamID=oDataReader.GetInt32(0);
}
if (!oDataReader.IsDBNull(1))
{
this.cStreamName=oDataReader.GetString(1);
}
if (!oDataReader.IsDBNull(2))
{
this.dLastEditDate=oDataReader.GetDateTime(2);
}
if (!oDataReader.IsDBNull(3))
{
this.nUserID=oDataReader.GetInt32(3);
}
if (!oDataReader.IsDBNull(4))
{
this.cStream=oDataReader.GetString(4);
}
if (!oDataReader.IsDBNull(5))
{
this.systemSign=oDataReader.GetBoolean(5);
}
if (!oDataReader.IsDBNull(6))
{
this.description=oDataReader.GetString(6);
}
else
this.description="";
oDataReader.Close();
if(this.Connection.State==System.Data.ConnectionState.Open)
this.Connection.Close();
this.Connection.Dispose();
return true;
}
else
{
oDataReader.Close();
if(this.Connection.State==System.Data.ConnectionState.Open)
this.Connection.Close();
this.Connection.Dispose();
return false;
}
}
private Streams oobjs; //构造函数
/// <summary>
/// 从容器类中构造
/// </summary>
/// <param name="toobjs"></param>
public Stream(Streams toobjs)
{
oobjs=toobjs;
}
public Stream()
{
}
public Stream(string newConnectionString):base( newConnectionString)
{
}
/// <summary>
/// 获取当前的对象
/// </summary>
object IEnumerator.Current
{
get
{
return this;
}
}
/// <summary>
/// 下一个对象
/// </summary>
/// <returns>有或无</returns>
public bool MoveNext()
{
if(oobjs.oDataSet==null)
{
SetData();
if(oobjs.nCurrentRecordNum<0)
oobjs.nCurrentRecordNum=0;
}
if(oobjs.PageSize>0)
{
if(oobjs.nCurrentRecordNum+(oobjs.PageNum-1)*oobjs.PageSize>=oobjs.RecordCount||oobjs.CurrentRecordNum>oobjs.PageSize-1)
{
this.oobjs.CurrentRecordNum=0;
return false;
}
}
else
{
if(oobjs.nCurrentRecordNum>=oobjs.RecordCount)
{
this.oobjs.CurrentRecordNum=0;
return false;
}
}
//以下代码为类:Stream的属性变量
try
{
nStreamID=System.Convert.ToInt32(oobjs.oDataSet.Tables["Stream"].Rows[oobjs.nCurrentRecordNum][0]);
}
catch(System.Exception ErrorExcept_Property_0)
{
ErrorLog.WriteLog(ErrorExcept_Property_0.Message);
nStreamID=0;
}
try
{
cStreamName=System.Convert.ToString(oobjs.oDataSet.Tables["Stream"].Rows[oobjs.nCurrentRecordNum][1]);
}
catch(System.Exception ErrorExcept_Property_1)
{
ErrorLog.WriteLog(ErrorExcept_Property_1.Message);
cStreamName="";
}
try
{
dLastEditDate=System.Convert.ToDateTime(oobjs.oDataSet.Tables["Stream"].Rows[oobjs.nCurrentRecordNum][2]);
}
catch(System.Exception ErrorExcept_Property_2)
{
ErrorLog.WriteLog(ErrorExcept_Property_2.Message);
dLastEditDate=System.DateTime.MinValue;
}
try
{
nUserID=System.Convert.ToInt32(oobjs.oDataSet.Tables["Stream"].Rows[oobjs.nCurrentRecordNum][3]);
}
catch(System.Exception ErrorExcept_Property_3)
{
ErrorLog.WriteLog(ErrorExcept_Property_3.Message);
nUserID=0;
}
try
{
cStream=System.Convert.ToString(oobjs.oDataSet.Tables["Stream"].Rows[oobjs.nCurrentRecordNum][4]);
}
catch(System.Exception ErrorExcept_Property_4)
{
ErrorLog.WriteLog(ErrorExcept_Property_4.Message);
cStream="";
}
try
{
systemSign=System.Convert.ToBoolean(oobjs.oDataSet.Tables["Stream"].Rows[oobjs.nCurrentRecordNum][5]);
}
catch(System.Exception ErrorExcept_Property_5)
{
ErrorLog.WriteLog(ErrorExcept_Property_5.Message);
systemSign=false;
}
try
{
description=System.Convert.ToString(oobjs.oDataSet.Tables["Stream"].Rows[oobjs.nCurrentRecordNum][6]);
}
catch(System.Exception ErrorExcept_Property_6)
{
ErrorLog.WriteLog(ErrorExcept_Property_6.Message);
description="";
}
oobjs.nCurrentRecordNum++;
return true;
}
/// <summary>
/// 复位
/// </summary>
public void Reset()
{
}
}
}
}
namespace OI.Business
{
public class Stream
{
private System.Xml.XmlDocument oXmlDocument;
private string streamDef;//流程定义文件名字
private string errorMessage;
/// <summary>
/// 新建工作流
/// </summary>
public Stream()
{
oXmlDocument=new System.Xml.XmlDocument();
oXmlDocument.Load(OI.Modules.Config.GetSetting("stream")+"\\default.config");
this.streamDef=System.Guid.NewGuid().ToString()+".config";
try
{
oXmlDocument.Save(OI.Modules.Config.GetSetting("stream")+"\\"+streamDef);
}
catch(System.Exception e)
{
throw new AppException("保存工作流失败",e);
}
}
/// <summary>
/// 实例化一个已有的流ID
/// </summary>
/// <param name="StreamID">工作流ID</param>
public Stream(int StreamID)
{
oXmlDocument=new System.Xml.XmlDocument();
Data.Streams.Stream oStream=new OI.Data.Streams.Stream();
if(oStream.Search(StreamID))
{
streamDef=oStream.StreamDef;
try
{
oXmlDocument.Load(OI.Modules.Config.GetSetting("stream")+"\\"+streamDef);
}
catch
{
throw new AppException("实例化工作流发生异常:未找到工作流文件"+OI.Modules.Config.GetSetting("stream")+"\\"+streamDef);
}
}
else
{
throw new AppException("实例化工作流发生异常:未找到工作流文件");
}
}
/// <summary>
/// 实例化已有的流
/// </summary>
/// <param name="XmlStream">流程定义文件名字</param>
public Stream(string streamDef)
{
this.streamDef=streamDef;
oXmlDocument=new System.Xml.XmlDocument();
try
{
oXmlDocument.Load(OI.Modules.Config.GetSetting("stream")+"\\"+streamDef);
}
catch
{
throw new AppException("实例化工作流发生异常:未找到工作流文件"+OI.Modules.Config.GetSetting("stream")+"\\"+streamDef);
}
}
/// <summary>
/// 自定义错误信息,只读
/// </summary>
public string ErrorMessage
{
get
{
string str=this.errorMessage;
this.errorMessage="";
return str;
}
}
/// <summary>
/// 定义流程的文件名,只读
/// </summary>
public string StreamDef
{
get
{
return this.streamDef;
}
}
public int NewNodeID()
{
string str="//NodeId";
System.Xml.XmlNodeList oXmlNodeList=this.oXmlDocument.DocumentElement.SelectNodes(str);
int i=0;
foreach(System.Xml.XmlNode oXmlNode in oXmlNodeList)
{
if(System.Int32.Parse(oXmlNode.InnerText)>i)
i=System.Int32.Parse(oXmlNode.InnerText);
}
i++;
return i;
}
public string GetXml()
{
return this.oXmlDocument.InnerXml;
}
/// <summary>
/// 在当前工作点前面插入工作流节点
/// </summary>
/// <param name="node">工作流节点</param>
/// <param name="nodeId">插入位置</param>
public bool InsertNodeAfter(Node node,int nodeId)
{
this.errorMessage="";
string str;
//首先检查该节点是否存在
str="/Stream/Node/NodeId[.='"+node.NodeId.ToString()+"']";
if(this.oXmlDocument.DocumentElement.SelectSingleNode(str)!=null)
{
throw new AppException("试图添加具有重复节点ID值"+node.NodeId.ToString());
}
//检查指向的节点是否存在
if(node.NextNodeId>0)
{
str="//NodeId[.='"+node.NextNodeId.ToString()+"']";
if(this.oXmlDocument.DocumentElement.SelectSingleNode(str)==null)
{
this.errorMessage="没有指定同意时指向的工作流节点";
return false;
}
}
Node otmpNode=this.FindNodeById(nodeId);
if(otmpNode.NodeType==1&&node.NodeType!=2)
{
this.errorMessage="第一个工作点类型应为公文起草";
return false;
}
System.Xml.XmlElement nodeElement=this.GetXmlNode(node);
this.oXmlDocument.DocumentElement.InsertAfter(nodeElement,this.oXmlDocument.DocumentElement.SelectSingleNode("//NodeId[.="+nodeId.ToString()+"]").ParentNode);
//更新相邻的节点
str="//NodeId[.='"+nodeId.ToString()+"']";
System.Xml.XmlNode oXmlNode =this.oXmlDocument.DocumentElement.SelectSingleNode(str);
if(oXmlNode.ParentNode.SelectSingleNode("NextNodeId")!=null)
{
oXmlNode.ParentNode.SelectSingleNode("NextNodeId").InnerText=node.NodeId.ToString();
}
//保存修改
if(this.streamDef==null||this.streamDef=="")
this.streamDef=System.Guid.NewGuid().ToString()+".config";
try
{
oXmlDocument.Save(OI.Modules.Config.GetSetting("stream")+"\\"+streamDef);
}
catch(System.Exception e)
{
throw new AppException("保存工作流失败",e);
}
return true;
}
/// <summary>
/// 修改节点
/// </summary>
/// <param name="newnode">新节点</param>
/// <returns></returns>
public bool EditNode(Node newnode)
{
this.errorMessage="";
string str;
//移除原有的节点
str="/Stream/Node/NodeId[.='"+newnode.NodeId.ToString()+"']";
System.Xml.XmlNode oldNode=this.oXmlDocument.DocumentElement.SelectSingleNode(str).ParentNode;
System.Xml.XmlNode preNode=oldNode.PreviousSibling;
oldNode.RemoveAll();
this.oXmlDocument.DocumentElement.RemoveChild(oldNode);
//检查指向的节点是否存在
if(newnode.NextNodeId>0)
{
str="//NodeId[.='"+newnode.NextNodeId.ToString()+"']";
if(this.oXmlDocument.DocumentElement.SelectSingleNode(str)==null)
{
this.errorMessage="没有指定同意时指向的工作流节点";
return false;
}
}
System.Xml.XmlElement nodeElement=this.GetXmlNode(newnode);
this.oXmlDocument.DocumentElement.InsertAfter(nodeElement,preNode);
//更新相邻的节点
if(preNode.SelectSingleNode("NextNodeId")!=null)
{
preNode.SelectSingleNode("NextNodeId").InnerText=newnode.NodeId.ToString();
}
foreach(Node otmpNode in this.NodeIdList())
{
if(otmpNode.NodeType==1)
{
//找到开始节点的下一个节点
Node tmpNode=this.FindNodeById(otmpNode.NextNodeId);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -