using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Xml.Serialization;
using System.Reflection;
using System.Data;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Configuration;
namespace InfoPath.NET
{
/// <summary>
/// InfoPath 的摘要说明。
/// </summary>
///
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="InfoPathWebServiceForMisSoap", Namespace="http://tempuri.org/")]
public class InfoPath:System.Web.Services.Protocols.SoapHttpClientProtocol
{
public InfoPath()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#region 定义局部变量和属性
//定义变量
private string _InfoPathFileName = "";
private string _OperationID = "";
private string _FlowID ="";
private string _FileID = "";
private string _FileQcr = "";
private string _FileState = "";
private string _WebServiceURL = "";
private string _CurrentReader = "";
private DataSet dsColNam;
private string TemplateName;
/// <summary>
/// 获取或设置InfoPath(*.xsn)文件的名称,名称包括完整路径
/// </summary>
public string InfoPathFileName
{
get
{
if (_InfoPathFileName.Trim() == string.Empty)
{
_InfoPathFileName = System.Web.HttpContext.Current.Request.MapPath("\\XTGL\\Template\\Splc\\") + ADOFactory.ADOFactory.Instance().ExeSqlForString("SELECT MBWZ FROM ZDY_YW_M WHERE YW_ID = '"+OperationID+"'");
}
return _InfoPathFileName;
}
set
{
_InfoPathFileName = value;
}
}
/// <summary>
/// 获取或设置业务编号
/// </summary>
public string OperationID
{
get
{
return _OperationID;
}
set
{
_OperationID = value;
}
}
/// <summary>
/// 获取或设置流程编号
/// </summary>
public string FlowID
{
get
{
if (_FlowID.Trim() == string.Empty)
{
_FlowID = ADOFactory.ADOFactory.Instance().ExeSqlForString("select ywlc_id from dbo.LC_WJSPXX_M where yw_id = '"+OperationID+"' and file_id = '"+FileID+"' and zt = '1'");
}
return _FlowID;
}
set
{
_FlowID = value;
}
}
/// <summary>
/// 获取或设置文件编号
/// </summary>
public string FileID
{
get
{
if (_FileID.Trim().ToUpper() == "INSERT")
{
BestPublicClass.BestPublicClass Bpc = new BestPublicClass.BestPublicClass();
//动态加载类
_FileID = Bpc.GetPkOfTable(getTableName());
}
return _FileID;
}
set
{
_FileID = value;
}
}
/// <summary>
/// 文件起建人
/// </summary>
public string FileQcr
{
get
{
return _FileQcr;
}
set
{
_FileQcr = value;
}
}
/// <summary>
/// 文件状态
/// </summary>
public string FileState
{
get
{
return _FileState;
}
set
{
_FileState = value;
}
}
/// <summary>
/// 获取或设置WebService IP地址(比例:192.168.0.251)
/// </summary>
public string WebServiceURL
{
get
{
if (_WebServiceURL.Trim() == string.Empty)
{
if (ConfigurationSettings.AppSettings["WebServerPort"].ToString().Trim() != string.Empty)
{
_WebServiceURL = ConfigurationSettings.AppSettings["WebServerIP"].ToString() + ":" + ConfigurationSettings.AppSettings["WebServerPort"].ToString();
}
else
{
_WebServiceURL = ConfigurationSettings.AppSettings["WebServerIP"].ToString();
}
}
return _WebServiceURL;
}
set
{
_WebServiceURL = value;
}
}
/// <summary>
/// 获取或设置当前审稿人
/// </summary>
public string CurrentReader
{
get
{
return _CurrentReader;
}
set
{
_CurrentReader = value;
}
}
ADOFactory.ADOFactory Db = ADOFactory.ADOFactory.Instance();
#endregion
#region 扩展 InfoPath
/// <summary>
///功能说明:提取InfoPath文件并修改以下文件信息\r\n
/// 1.manifest.xsf 文件中的WebService服务器地址
/// 2.template.xml 文件中的初始值
/// 3.sampledata.xml 文件中的初始值
/// 根据流程环节修改其InfoPath表单中控件的相应属性
///开发人员:陈国银
///创建日期:2005-01-07
///版 本 号:V1.0
///修改日期:
///修改版本:
/// </summary>
public void InfoPathPro()
{
FlowPublic.WebServiceURL = WebServiceURL;
//定位相关文件位置
string XsfName = ""; //manifest.xsf
TemplateName = Guid.NewGuid().ToString().ToUpper();
//创建目录
string Exported = "TempFiles\\Exported\\" + TemplateName;
string SourcePath = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + Exported;
if (Directory.Exists(SourcePath) == false) Directory.CreateDirectory(System.Web.HttpContext.Current.Request.PhysicalApplicationPath + Exported);
//提取xsn文件
Process.Start("expand.exe",InfoPathFileName + " -F:* " + SourcePath);
//等待提取完成
System.Threading.Thread.Sleep(1000);
//*******************************************************************************
//修改相关文件中控件的属性
//*******************************************************************************
//获取xsf文件
DirectoryInfo di;
di = new DirectoryInfo(SourcePath);
//获取目录下的文件信息
FileInfo[] fi = di.GetFiles();
//获取文件位置
for (int i=0;i<fi.Length;i++)
{
if(fi[i].Name.Trim().Length>3)
{
if(fi[i].Name.Trim().Substring(fi[i].Name.Trim().Length-3,3).ToUpper()=="XSF")
{
XsfName = fi[i].Name.Trim();
break;
}
}
}
//未发现xsf文件
if (XsfName.Trim() == string.Empty)
{
System.Web.HttpContext.Current.Response.Write("<script langauge=javascript>alert('未能获取xsf文件,系统终止!');</script>");
return;
}
//流程控制
ControllerForXSN(SourcePath);
//修改和控制 Manifest.xsf 文件
ModifyForXSN(SourcePath);
//初始化数据
InitializeForXSN(SourcePath);
//打开模板文件到客户端
System.Web.HttpContext.Current.Response.Write("<script language=javascript>window.open('/"+Exported.Replace("\\","/")+"/template.xml');</script>");
}
#endregion
#region 修改和控制 Manifest.xsf 文件
/// <summary>
/// 修改和控制 Manifest.xsf 文件包括WebService地址,附加文件属性等
/// </summary>
private void ModifyForXSN(string SourcePath)
{
string XsfName = "manifest.xsf"; //manifest.xsf
//读取xsf文件信息
System.Xml.XmlDocument xsf = new System.Xml.XmlDocument();
xsf.Load(SourcePath + "\\" + XsfName);
//**************************************************************************
//更新WebService服务器地址(包括获取数据和提交数据的WebService服务器地址)
//**************************************************************************
//a.wsdl
System.Xml.XmlNodeList oWebServiceAdapterListWsdl = xsf.DocumentElement.GetElementsByTagName("xsf:webServiceAdapter");
for (int i=0; i<oWebServiceAdapterListWsdl.Count; i++)
{
//设置URL
System.Xml.XmlElement oWsdlUrl = (System.Xml.XmlElement)oWebServiceAdapterListWsdl.Item(i);
//提取更改前WS的地址
string OldWsdl = oWsdlUrl.GetAttribute("wsdlUrl").ToString();
string OldServerIP = OldWsdl.Substring(0,OldWsdl.IndexOf("/",7));
string NewWsdl = OldWsdl.Replace(OldServerIP,"http://"+WebServiceURL);
//更新Wsdl
oWsdlUrl.SetAttribute("wsdlUrl",NewWsdl);
}
//b.ServiceUrl
System.Xml.XmlNodeList oWebServiceAdapterListService = xsf.DocumentElement.GetElementsByTagName("xsf:operation");
for (int i=0; i<oWebServiceAdapterListService.Count; i++)
{
//设置URL
System.Xml.XmlElement oServiceUrl = (System.Xml.XmlElement)oWebServiceAdapterListService.Item(i);
//提取更改前WS的地址
string OldServiceUrl = oServiceUrl.GetAttribute("serviceUrl").ToString();
string OldUrlIP = OldServiceUrl.Substring(0,OldServiceUrl.IndexOf("/",7));
string NewWsdl = OldServiceUrl.Replace(OldUrlIP,"http://"+WebServiceURL);
//更新Wsdl
oServiceUrl.SetAttribute("serviceUrl",NewWsdl);
}
//添加附加文件//生成项目选择XML文件
if (TaskPaneMsg(OperationID,SourcePath))
{
TaskPaneFile(SourcePath);
System.Xml.XmlNodeList xFiles = xsf.DocumentElement.GetElementsByTagName("xsf:files");
if (xFiles.Count> 0)
{
System.Xml.XmlElement xFile = (System.Xml.XmlElement)xFiles.Item(0);
//主文件 html
AppendNodeList(xsf,xFile,"TaskPane.htm");
//xml文件
AppendNodeList(xsf,xFile,"TaskPane.xml");
//css文件
AppendNodeList(xsf,xFile,"TaskPane.css");
//js文件
AppendNodeList(xsf,xFile,"TaskPane.js");
//增加配置文件
AppendSet(xsf);
}
}
//删除xsf发布位置使发布位置为当前位置
xsf.DocumentElement.RemoveAttribute("publishUrl");
//修改表单编号(ID)
xsf.DocumentElement.RemoveAttribute("name");
//去掉空白部位
xsf.PreserveWhitespace = true;
//保存xsf文件
xsf.Save(SourcePath + "\\" + XsfName);
}
#endregion
#region 初始化数据
/// <summary>
/// 初始化数据
/// </summary>
private void InitializeForXSN(string SourcePath)
{
//**************************************************************************
//修改InfoPath(*.xsn)包中XML文件的初始值
//template.xml
string TempXmlName = "template.xml"; //template.xml
System.Xml.XmlDocument TmpXml = new System.Xml.XmlDocument();
TmpXml.Load(SourcePath + "\\" + TempXmlName);
//赋值到InfoPath控件上
DataSet OFData = new DataSet();
//Web服务地址
this.Url = "http://"+WebServiceURL+"/InfoPathWebServiceForMis/InfoPathWebServiceForMis.asmx";
//从Web服务上获取数据
OFData = GetData();
//赋值到控件
if (OFData != null)
{
for (int i=0;i<OFData.Tables[0].Columns.Count;i++)
{
try
{
string ColNam = OFData.Tables[0].Columns[i].ColumnName.ToString();
System.Xml.XmlNodeList TmpObject = TmpXml.DocumentElement.GetElementsByTagName(ColNam);
TmpObject.Item(0).InnerText = OFData.Tables[0].Rows[0][i].ToString();
}
catch
{
//对象未找到,不能赋值
}
}
try
{
//设置业务编号
System.Xml.XmlNodeList TmpOFID = TmpXml.DocumentElement.GetElementsByTagName("业务编号");
TmpOFID.Item(0).InnerText = OperationID;
//设置流程编号
System.Xml.XmlNodeList TmpFlowID = TmpXml.DocumentElement.GetElementsByTagName("流程编号");
TmpFlowID.Item(0).InnerText = FlowID;
//设置文件编号
System.Xml.XmlNodeList TmpFileID = TmpXml.DocumentElement.GetElementsByTagName("文件编号");
//生成新的FileID
TmpFileID.Item(0).InnerText = FileID;
//设置文件状态
System.Xml.XmlNodeList TmpFileState = TmpXml.DocumentElement.GetElementsByTagName("文件状态");
TmpFileState.Item(0).InnerText = FileState;
//设置文件起草人
System.Xml.XmlNodeList TmpFileQcr = TmpXml.DocumentElement.GetElementsByTagName("起草人");
TmpFileQcr.Item(0).InnerText = FileQcr;
}
catch
{
System.Web.HttpContext.Current.Response.Write("<script langauge=javascript>alert('不能初始化表单值,请检查模板表单是否按指定要求创建的!系统终止!');</script>");
return;
}
}
OFData = null;
//保存文件
TmpXml.PreserveWhitespace = false;
TmpXml.Save(SourcePath + "\\" + TempXmlName);
}
#endregion
#region 流程控制和用户操作权限
/// <summary>
/// 流程控制和用户操作权限
/// </summary>
private void ControllerForXSN(string SourcePath)
{
//**************************************************************************
//设置部分控件为只读用于控制流程
//★★★★☆
//**************************************************************************
//打开View1.xsl文件
System.Xml.XmlDocument TmpXsl = new System.Xml.XmlDocument();
TmpXsl.Load(SourcePath + "\\view1.xsl");
//查找对应的字段名称
System.Xml.XmlNodeList Yw = TmpXsl.DocumentElement.SelectNodes("descendant::span");
//获取xd前缀
string predt=TmpXsl.DocumentElement.GetNamespaceOfPrefix("xd");
//记录允许操作的字段
dsColNam = new DataSet();
DataTable myDataTable = new DataTable("AccessColNam");
DataColumn myDataColumn;
myDataColumn = new DataColumn();
myDataColumn.DataType= System.Type.GetType("System.String");
myDataColumn.ColumnName = "ColNam";
myDataTable.Columns.Add(myDataColumn);
dsColNam.Tables.Add(myDataTable);
//控制
ControlRange(Yw,predt);
//保存文件
TmpXsl.Save(SourcePath + "\\view1.xsl");
}
/// <summary>
/// 控制内容
/// </summary>
/// <param name="xnl"></param>
/// <param name="predt"></param>
private void ControlRange(System.Xml.XmlNodeList xnl,string predt)
{
//=============================================================
//文件状态
// 0:文件起草
// 1:待办
// 2:审批中
// 3:办理中
// 4:办理中
// 7:作废
// 8:正式文件
// 9:手动增加
//=============================================================
//控制流程
if (FileState.ToString() != "9") //流程
{
//文件全部加锁
FileBelock(xnl,predt);
//获取当前审批人操作此表单的状态
int iState = Db.ExeSqlForInt("SELECT count(*) FROM LC_WJSPXX_M WHERE File_id='"+FileID+"' AND YW_ID='"+OperationID+"' and sbspr='"+CurrentReader+"' and zt = '1' ");
if(iState > 0)
{
//部份解锁
//====================================================================
//可以修改起草内容
int iDrafto = Db.ExeSqlForInt("SELECT Count(*) FROM LC_YWLCDY_M WHERE KXGQCNR='1' and ywlc_id = '"+FlowID+"'");
if (iDrafto == 1)
{
FileDraftOut(xnl,predt);
}
//审批范围
string sAuditing = Db.ExeSqlForString("SELECT SPHF FROM LC_YWLCDY_M WHERE YWLC_ID = (SELECT TOP 1 YWLC_ID FROM LC_WJSPXX_M WHERE File_ID = '"+FileID+"' AND YW_ID='"+OperationID+"' AND ZT = '1')");
if (sAuditing.Trim().ToString().Length > 0)
{
string[] Fw = sAuditing.Split(';');
//解锁
for (int w=0;w<Fw.Length;w++)
{
string ColNam = Db.ExeSqlForString("SELECT ZDZWMC FROM ZDY_EXCEL_M WHERE EXCEL_ID = '"+Fw[w]+"'");
SetControl(xnl,predt,ColNam);
}
}
}
else
{
//起草
FileDraftOut(xnl,predt);
}
}
}
/// <summary>
/// 设置文件加锁
/// </summary>
private void FileBelock(System.Xml.XmlNodeList xnl,string predt)
{
for (int j=0;j<xnl.Count;j++)
{
System.Xml.XmlElement xdEditReadOnly = (System.Xml.XmlElement)xnl.Item(j);
//设置只读
xdEditReadOnly.SetAttribute("disableEditing",predt,"yes");
//设置颜色
string style = "";
try
{
style = xdEditReadOnly.Attributes["style"].Value.ToString();
if (style.Trim() != string.Empty) style += ";";
}
catch
{}
xdEditReadOnly.SetAttribute("style",style + "BACKGROUND-COLOR: #d7d9e8");
//设置提示
string Tooltip = "";
try
{
Tooltip = xdEditReadOnly.Attributes["title"].Value.ToString();
if (Tooltip.Trim() != string.Empty) Tooltip += ";";
}
catch
{}
xdEditReadOnly.SetAttribute("title",Tooltip + "你没有权限编辑该数据哦!");
}
}
/// <summary>
/// 文件起草
/// </summary>
/// <param name="xnl"></param>
/// <param name="predt"></param>
private void FileDraftOut(System.Xml.XmlNodeList xnl,string predt)
{
//父码
string sParentID = Db.ExeSqlForString("SELECT FM FROM LC_YWLCDY_M WHERE YWLC_ID = '"+FlowID+"'");
//审批范围
string sRange = Db.ExeSqlForString("SELECT SPHF from LC_YWLCDY_M where yw_id = '"+OperationID+"' AND SPCC = 0 and fm = '"+sParentID+"'");
if (sRange.Trim().ToString().Length > 0)
{
string[] qFw = sRange.Split(';');
//解锁
for (int w=0;w<qFw.Length;w++)
{
string ColNam = Db.ExeSqlForString("SELECT ZDZWMC FROM ZDY_EXCEL_M WHERE EXCEL_ID = '"+qFw[w]+"'");
SetControl(xnl,predt,ColNam);
}
}
}
/// <summary>
/// 设置控制属性
/// </summary>
/// <param name="xnl"></param>
/// <param name="predt"></param>
/// <param name="ColNam"></param>
/// <param name="AttributeVal"></param>
private void SetControl(System.Xml.XmlNodeList xnl,string predt,string ColNam)
{
///Todaydo
///
//将该字段名记录到数据集中
DataRow myDataRow;
myDataRow = dsColNam.Tables[0].NewRow();
myDataRow["ColNam"] = ColNam;
dsColNam.Tables[0].Rows.Add(myDataRow);
for (int j=0;j<xnl.Count;j++)
{
try
{
string sColN = xnl.Item(j).Attributes["xd:binding"].Value.ToString();
sColN = sColN.Substring(sColN.LastIndexOf("/") + 1);
if (sColN == ColNam)
{
System.Xml.XmlElement xdEditReadOnly = (System.Xml.XmlElement)xnl.Item(j);
//设置只读
xdEditReadOnly.RemoveAttribute("disableEditing");
//设置颜色
string style = "";
try
{
style = xdEditReadOnly.Attributes["style"].Value.ToString();
if (style.Trim() != string.Empty) style += ";";
}
catch
{}
xdEditReadOnly.SetAttribute("style",style + "BACKGROUND-COLOR: white");
//设置提示
xdEditReadOnly.RemoveAttribute("title");
}
}
catch
{
//找不到控件
}
}
}
#endregion
#region 设置和增加 xmlChild
/// <summary>
/// 增加子项
/// </summary>
/// <param name="e"></param>
/// <param name="FileName"></param>
private void AppendNodeList(System.Xml.XmlDocument xsf,System.Xml.XmlElement e,string FileName)
{
string prex=xsf.DocumentElement.GetNamespaceOfPrefix("xsf");
System.Xml.XmlElement aFile = xsf.CreateElement("xsf","file",prex);
aFile.SetAttribute("name",FileName);
System.Xml.XmlElement xFilePro = xsf.CreateElement("xsf","fileProperties",prex);
System.Xml.XmlElement xPro = xsf.CreateElement("xsf","property",prex);
xPro.SetAttribute("name","fileType");
xPro.SetAttribute("type","string");
xPro.SetAttribute("value","resource");
xFilePro.AppendChild(xPro);
aFile.AppendChild(xFilePro);
e.AppendChild(aFile);
}
/// <summary>
/// 增加设置
/// </summary>
/// <param name="xsf"></param>
private void AppendSet(System.Xml.XmlDocument xsf)
{
string prex = xsf.DocumentElement.GetNamespaceOfPrefix("xsf");
System.Xml.XmlElement aFile = xsf.CreateElement("xsf","taskpane",prex);
aFile.SetAttribute("caption","项目列表");
aFile.SetAttribute("href","TaskPane.htm");
System.Xml.XmlElement xdataObjects = xsf.CreateElement("xsf","dataObjects",prex);
System.Xml.XmlElement xdataObject = xsf.CreateElement("xsf","dataObject",prex);
xdataObject.SetAttribute("name","Help");
xdataObject.SetAttribute("schema","TaskPane.xsd");
xdataObject.SetAttribute("initOnLoad","yes");
System.Xml.XmlElement xquery = xsf.CreateElement("xsf","query",prex);
System.Xml.XmlElement xFileAdapter = xsf.CreateElement("xsf","xmlFileAdapter",prex);
xFileAdapter.SetAttribute("fileUrl","TaskPane.xml");
xFileAdapter.SetAttribute("name","Help");
xquery.AppendChild(xFileAdapter);
xdataObject.AppendChild(xquery);
xdataObjects.AppendChild(xdataObject);
xsf.DocumentElement.AppendChild(aFile);
xsf.DocumentElement.AppendChild(xdataObjects);
}
#endregion
#region 根据业务定义动态生成项目列表选择
/// <summary>
/// 根据业务定义动态生成项目列表选择
/// </summary>
private bool TaskPaneMsg(string Ywid,string SourcePath)
{
string TaskXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
string BodyTxt = "";
TaskXml += "<Help>\r\n";
FlowWebService Fws = new FlowWebService();
DataView dv = Fws.FlowColnums(Ywid).Tables[0].DefaultView;
DataView dvColNam = dsColNam.Tables[0].DefaultView;
for (int i=0;i<dv.Count;i++)
{
if (dv[i]["LB"].ToString().Trim() != string.Empty)
{
dvColNam.RowFilter = "ColNam = '"+dv[i]["ZDZWMC"].ToString().Trim()+"'";
if (dvColNam.Count > 0)
{
BodyTxt += "<Field xpath=\"myFields/dataFields/GetOFDataResponse/GetOFDataResult/NewDataSet/业务流程/"+dv[i]["ZDZWMC"].ToString().Trim()+"\">";
DataSet ds = new DataSet();
string Tab = "<div><strong>"+dv[i]["ZDZWMC"].ToString().Trim()+"列表</strong></div><hr></hr><table cellpadding=\"3\" cellspacing=\"0\" border=\"0\"><tr><td>编号</td><td>名称</td></tr>";
//特殊处理 单位/人员
switch (dv[i]["LB"].ToString().Trim().ToUpper())
{
case "XT_DWXX_M":
ds = Fws.GetDataSet("SELECT DWZBH AS DM,DWMC AS MC FROM XT_DWXX_M");
break;
case "XT_RYXX_M":
ds = Fws.GetDataSet("SELECT RYZBH AS DM,XM AS MC FROM XT_RYXX_M");
break;
default:
ds = Fws.FlowObjectList(Ywid,dv[i]["ZDMC"].ToString());
break;
}
for (int j=0;j<ds.Tables[0].Rows.Count;j++)
{
Tab += "<tr ondblclick=\"InsertingValue(this.cells[1].innerHTML);\" style=\"CURSOR: hand\" title='双击将值插入到"+dv[i]["ZDZWMC"].ToString().Trim()+"中' onmouseover=\"this.style.backgroundColor = '#6699ff'\" onmouseout=\"this.style.backgroundColor = 'white'\"><td>" + ds.Tables[0].Rows[j]["DM"].ToString() + "</td><td>" + ds.Tables[0].Rows[j]["MC"].ToString() + "</td></tr>";
}
Tab += "</table>";
BodyTxt += Tab + "</Field>\r\n";
}
}
}
if (BodyTxt.Trim() != string.Empty)
{
TaskXml += BodyTxt + "</Help>\r\n";
//生成文件
System.IO.FileStream TaskPH = new System.IO.FileStream(@SourcePath + "\\TaskPane.xml", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
System.IO.StreamWriter TaskPHf = new System.IO.StreamWriter(TaskPH,System.Text.Encoding.UTF8);
TaskPHf.WriteLine(TaskXml);
TaskPHf.Close();
return true;
}
else
{
return false;
}
}
#endregion
#region 生成InfoPath的控制文件
/// <summary>
/// 生成样式文件
/// </summary>
private void TaskPaneFile(string SourcePath)
{
//样式文件
System.IO.FileStream TaskPC = new System.IO.FileStream(@SourcePath + "\\TaskPane.css", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
System.IO.StreamWriter TaskPCf = new System.IO.StreamWriter(TaskPC,System.Text.Encoding.UTF8);
TaskPCf.WriteLine("body { font:10pt Verdana; padding:0px; overflow:auto; }");
TaskPCf.WriteLine("hr { height:1px; color:black; margin-top:-.5em; }");
TaskPCf.WriteLine("table { width:100%; }");
TaskPCf.WriteLine("tr { font:9pt 宋体; vertical-align:top; }");
TaskPCf.WriteLine("th { text-align:left; background-color:black; color:white; }");
TaskPCf.Close();
//主文件
System.IO.FileStream TaskPM = new System.IO.FileStream(@SourcePath + "\\TaskPane.htm", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
System.IO.StreamWriter TaskPMf = new System.IO.StreamWriter(TaskPM,System.Text.Encoding.UTF8);
TaskPMf.WriteLine("<html>");
TaskPMf.WriteLine(" <head>");
TaskPMf.WriteLine(" <title>项目列表</title>");
TaskPMf.WriteLine(" <link rel=\"stylesheet\" type=\"text/css\" href=\"TaskPane.css\" />");
TaskPMf.WriteLine(" <script language=\"jscript\" type=\"text/javascript\" src=\"TaskPane.js\"></script>");
TaskPMf.WriteLine(" </head>");
TaskPMf.WriteLine(" <body onLoad=\"Initialize()\">");
TaskPMf.WriteLine(" <div id=\"HelpDIV\"></div>");
TaskPMf.WriteLine(" </body>");
TaskPMf.WriteLine("</html>");
TaskPMf.Close();
//JS文件
System.IO.FileStream TaskPJ = new System.IO.FileStream(@SourcePath + "\\TaskPane.js", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
System.IO.StreamWriter TaskPJf = new System.IO.StreamWriter(TaskPJ,System.Text.Encoding.Default);
TaskPJf.WriteLine("String.prototype.Format = new Function(\"var arg = String.prototype.Format.arguments; var str=this.toString(); var ph,re; for(var i=0;i<arg.length;i++){ph=new RegExp(\'\\{(\'+i+\')\\}','ig'); if(null==arg[i]) re=''; else re=arg[i].toString(); str=str.replace(ph,re);} return str;\");");
TaskPJf.WriteLine("var goXDocument = null;");
TaskPJf.WriteLine("var goHelpDOM = null;");
TaskPJf.WriteLine("var goPollTimer = null;");
TaskPJf.WriteLine("var goPrevFocusNode = null;");
TaskPJf.WriteLine("function Initialize()");
TaskPJf.WriteLine("{");
TaskPJf.WriteLine(" goXDocument = window.external.Window.XDocument;");
TaskPJf.WriteLine(" goHelpDOM = goXDocument.GetDOM(\"Help\");");
TaskPJf.WriteLine(" goPollTimer = window.setInterval(PollingLoop, 250);");
TaskPJf.WriteLine(" }");
TaskPJf.WriteLine(" function PollingLoop()");
TaskPJf.WriteLine(" {");
TaskPJf.WriteLine(" if(null == goXDocument.View)");
TaskPJf.WriteLine(" return;");
TaskPJf.WriteLine(" try");
TaskPJf.WriteLine(" {");
TaskPJf.WriteLine(" var oFocusNode = goXDocument.View.GetContextNodes().Item(0);");
TaskPJf.WriteLine(" if(oFocusNode == goPrevFocusNode)");
TaskPJf.WriteLine(" return;");
TaskPJf.WriteLine(" var sXPath = \"\";");
TaskPJf.WriteLine(" var oPathNode = oFocusNode;");
TaskPJf.WriteLine(" while(null != oPathNode.parentNode)");
TaskPJf.WriteLine(" {");
TaskPJf.WriteLine(" sXPath = \"{0}/{1}\".Format(oPathNode.baseName, sXPath);");
TaskPJf.WriteLine(" oPathNode = oPathNode.parentNode;");
TaskPJf.WriteLine(" }");
TaskPJf.WriteLine(" sXPath = sXPath.substr(0, sXPath.length-1);");
TaskPJf.WriteLine(" var oHelp = null;");
TaskPJf.WriteLine(" if(null != goHelpDOM)");
TaskPJf.WriteLine(" oHelp = goHelpDOM.selectSingleNode( \"//Field[@xpath='{0}']\".Format(sXPath));");
TaskPJf.WriteLine(" HelpDIV.innerHTML = oHelp ? oHelp.xml : \"\";");
TaskPJf.WriteLine(" goPrevFocusNode = oFocusNode;");
TaskPJf.WriteLine(" }");
TaskPJf.WriteLine(" catch (e)");
TaskPJf.WriteLine(" {");
TaskPJf.WriteLine(" }");
TaskPJf.WriteLine("}");
TaskPJf.WriteLine(" function InsertingValue(Val)");
TaskPJf.WriteLine(" {");
TaskPJf.WriteLine(" goXDocument.View.GetContextNodes().Item(0).text = Val;");
TaskPJf.WriteLine(" }");
TaskPJf.Close();
//样式文件
System.IO.FileStream TaskPD = new System.IO.FileStream(@SourcePath + "\\TaskPane.xsd", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
System.IO.StreamWriter TaskPDf = new System.IO.StreamWriter(TaskPD,System.Text.Encoding.UTF8);
TaskPDf.WriteLine("<?xml version=\"1.0\"?>");
TaskPDf.WriteLine("<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">");
TaskPDf.WriteLine(" <xsd:element name=\"Help\">");
TaskPDf.WriteLine(" <xsd:complexType>");
TaskPDf.WriteLine(" <xsd:sequence>");
TaskPDf.WriteLine(" <xsd:element ref=\"Field\" minOccurs=\"0\" maxOccurs=\"unbounded\"></xsd:element>");
TaskPDf.WriteLine(" </xsd:sequence>");
TaskPDf.WriteLine(" </xsd:complexType>");
TaskPDf.WriteLine(" </xsd:element>");
TaskPDf.WriteLine(" <xsd:element name=\"Field\">");
TaskPDf.WriteLine(" <xsd:complexType>");
TaskPDf.WriteLine(" <xsd:simpleContent>");
TaskPDf.WriteLine(" <xsd:extension base=\"xsd:string\">");
TaskPDf.WriteLine(" <xsd:attribute ref=\"xpath\"></xsd:attribute>");
TaskPDf.WriteLine(" </xsd:extension>");
TaskPDf.WriteLine(" </xsd:simpleContent>");
TaskPDf.WriteLine(" </xsd:complexType>");
TaskPDf.WriteLine(" </xsd:element>");
TaskPDf.WriteLine(" <xsd:attribute name=\"xpath\" type=\"xsd:string\"></xsd:attribute>");
TaskPDf.WriteLine("</xsd:schema>");
TaskPDf.Close();
}
#endregion
#region 公用部份
/// <summary>
/// 获取数据
/// </summary>
/// <param name="OFID"></param>
/// <param name="FlowID"></param>
/// <param name="FileID"></param>
/// <returns></returns>
private DataSet GetData()
{
DataSet dsRes = new DataSet();
dsRes = null;
try
{
string Ywid = OperationID;
string SQL = "SELECT ";
//获取业务表名
string TabN = getTableName();
//获取列名
DataSet ds = new DataSet();
FlowWebService Fws = new FlowWebService();
ds = Fws.FlowColnums(Ywid);
//构成SQL语句
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
for (int i=0;i<ds.Tables[0].Rows.Count;i++)
{
//判断是否有类型
if (ds.Tables[0].Rows[i]["LB"].ToString().Trim() != string.Empty)
{
//特殊处理 单位/人员
switch (ds.Tables[0].Rows[i]["LB"].ToString().Trim().ToUpper())
{
case "XT_DWXX_M":
SQL += "(SELECT DWMC FROM XT_DWXX_M WHERE DWDM = t1." + ds.Tables[0].Rows[i]["ZDMC"].ToString() + ") as [" + ds.Tables[0].Rows[i]["ZDZWMC"].ToString().Replace("/","_") + "],";
break;
case "XT_RYXX_M":
SQL += "(SELECT XM FROM XT_RYXX_M WHERE RYDM = t1." + ds.Tables[0].Rows[i]["ZDMC"].ToString() + ") as [" + ds.Tables[0].Rows[i]["ZDZWMC"].ToString().Replace("/","_") + "],";
break;
default:
SQL += "(SELECT MC FROM XT_CODE_CHILD WHERE ID = '"+ds.Tables[0].Rows[i]["LB"].ToString().Trim()+"' AND DM = t1." + ds.Tables[0].Rows[i]["ZDMC"].ToString() + ") as [" + ds.Tables[0].Rows[i]["ZDZWMC"].ToString().Replace("/","_") + "],";
break;
}
}
else
{
SQL += ds.Tables[0].Rows[i]["ZDMC"].ToString() + " as [" + ds.Tables[0].Rows[i]["ZDZWMC"].ToString().Replace("/","_") + "],";
}
}
}
}
if (SQL != "SELECT ")
{
SQL += "'"+FileID+"' as [文件编号],_FileQCR as [起草人],_FILETITLE AS [文件搞要],_ZT AS [文件状态],'"+Ywid+"' AS [业务编号],'"+FlowID+"' as [流程编号] FROM " + TabN +" t1 WHERE " + getTablePkid(TabN) + "='"+FileID+"'";
dsRes = Db.ExeSqlForDataSet(SQL);
try
{
dsRes.Tables[0].TableName = "业务流程";
}
catch
{}
}
}
catch
{}
return dsRes;
}
private string getTableName()
{
return Db.ExeSqlForString("SELECT ZBBM FROM ZDY_YW_M WHERE YW_ID = '"+OperationID+"'");
}
/// <summary>
/// 获取表的主键
/// </summary>
/// <param name="TabNam"></param>
/// <returns></returns>
private string getTablePkid(string TabNam)
{
string pk = Db.ExeSqlForString("SELECT LM_E FROM XT_TABLE WHERE BM='"+TabNam+"' AND ISPK='1'");
if (pk.Trim() == string.Empty)
{
pk = TabNam + "_PKID";
}
return pk;
}
#endregion
}
//获取流程信息
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="FlowWebServiceSoap", Namespace="http://tempuri.org/")]
public class FlowWebService : System.Web.Services.Protocols.SoapHttpClientProtocol
{
#region 对WebService动态实例方法 FlowColnums 和 FlowObjectList
/// <remarks/>
public FlowWebService()
{
this.Url = "http://"+ FlowPublic.WebServiceURL +"/InfoPathWebServiceForMis/FlowWebService.asmx";
}
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/FlowColnums", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public System.Data.DataSet FlowColnums(string Ywid)
{
object[] results = this.Invoke("FlowColnums", new object[] {
Ywid});
return ((System.Data.DataSet)(results[0]));
}
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/FlowObjectList", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public System.Data.DataSet FlowObjectList(string Ywid,string ColNam)
{
object[] results = this.Invoke("FlowObjectList", new object[] {
Ywid,
ColNam});
return ((System.Data.DataSet)(results[0]));
}
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetDataSet", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public System.Data.DataSet GetDataSet(string SQL)
{
object[] results = this.Invoke("GetDataSet", new object[] {
SQL});
return ((System.Data.DataSet)(results[0]));
}
#endregion
}
public class FlowPublic
{
public static string WebServiceURL = "";
}
}