|
|
using System;
|
|
|
using System.Collections;
|
|
|
using System.Text;
|
|
|
using System.IO;
|
|
|
using System.Data;
|
|
|
using BP.En;
|
|
|
using BP.DA;
|
|
|
using BP.Port;
|
|
|
using BP.Sys;
|
|
|
using BP.Web;
|
|
|
using System.Drawing;
|
|
|
using BP.Difference;
|
|
|
using Spire.Doc;
|
|
|
using Spire.Doc.Fields;
|
|
|
using System.Drawing;
|
|
|
using System.Linq;
|
|
|
using System.Collections.Generic;
|
|
|
using Spire.Doc.Documents;
|
|
|
using NPOI.SS.Formula.Functions;
|
|
|
using System.Diagnostics;
|
|
|
using NPOI.SS.Formula.Eval;
|
|
|
using static Mono.Security.X509.X509Stores;
|
|
|
|
|
|
|
|
|
namespace BP.Pub
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// WebRtfReport 的摘要说明。
|
|
|
/// </summary>
|
|
|
public class RTFEngine
|
|
|
{
|
|
|
#region 数据实体
|
|
|
private Entities _HisEns = null;
|
|
|
public Entities HisEns
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
if (_HisEns == null)
|
|
|
_HisEns = new Emps();
|
|
|
|
|
|
return _HisEns;
|
|
|
}
|
|
|
}
|
|
|
#endregion 数据实体
|
|
|
#region 模板数据
|
|
|
public string _rtfStr = "";
|
|
|
#endregion 模板数据
|
|
|
|
|
|
#region 数据明细实体
|
|
|
private System.Text.Encoding _encoder = System.Text.Encoding.GetEncoding("GB2312");
|
|
|
|
|
|
public string GetCode(string str)
|
|
|
{
|
|
|
if (DataType.IsNullOrEmpty(str))
|
|
|
return "";
|
|
|
|
|
|
string rtn = "";
|
|
|
byte[] rr = _encoder.GetBytes(str);
|
|
|
foreach (byte b in rr)
|
|
|
{
|
|
|
if (b > 122)
|
|
|
rtn += "\\'" + b.ToString("x");
|
|
|
else
|
|
|
rtn += (char)b;
|
|
|
}
|
|
|
return rtn.Replace("\n", " \\par ");
|
|
|
}
|
|
|
//明细表数据
|
|
|
private ArrayList _EnsDataDtls = null;
|
|
|
public ArrayList EnsDataDtls
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
if (_EnsDataDtls == null)
|
|
|
_EnsDataDtls = new ArrayList();
|
|
|
return _EnsDataDtls;
|
|
|
}
|
|
|
}
|
|
|
//多附件数据
|
|
|
private Hashtable _EnsDataAths = null;
|
|
|
public Hashtable EnsDataAths
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
if (_EnsDataAths == null)
|
|
|
_EnsDataAths = new Hashtable();
|
|
|
return _EnsDataAths;
|
|
|
}
|
|
|
}
|
|
|
//明细表对应的附件
|
|
|
private FrmAttachments _EnsDataDtlOfAths = null;
|
|
|
public FrmAttachments EnsDataDtlOfAths
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
if (_EnsDataDtlOfAths == null)
|
|
|
_EnsDataDtlOfAths = new FrmAttachments();
|
|
|
return _EnsDataDtlOfAths;
|
|
|
}
|
|
|
}
|
|
|
#endregion 数据明细实体
|
|
|
|
|
|
/// <summary>
|
|
|
/// 增加一个数据实体
|
|
|
/// </summary>
|
|
|
/// <param name="en"></param>
|
|
|
public void AddEn(Entity en)
|
|
|
{
|
|
|
this.HisEns.AddEntity(en);
|
|
|
}
|
|
|
/// <summary>5
|
|
|
/// 增加一个Ens
|
|
|
/// </summary>
|
|
|
/// <param name="ens"></param>
|
|
|
public void AddDtlEns(Entities dtlEns)
|
|
|
{
|
|
|
this.EnsDataDtls.Add(dtlEns);
|
|
|
}
|
|
|
public void AddDtlOfAthEns(Entities AthEns)
|
|
|
{
|
|
|
this.EnsDataDtlOfAths.AddEntities(AthEns);
|
|
|
}
|
|
|
public string CyclostyleFilePath = "";
|
|
|
public string TempFilePath = "";
|
|
|
|
|
|
#region 获取特殊要处理的流程节点信息.
|
|
|
public string GetValueByKeyOfCheckNode(string[] strs)
|
|
|
{
|
|
|
foreach (Entity en in this.HisEns)
|
|
|
{
|
|
|
string val = en.GetValStringByKey(strs[2]);
|
|
|
switch (strs.Length)
|
|
|
{
|
|
|
case 1:
|
|
|
case 2:
|
|
|
throw new Exception("step1参数设置错误" + strs.ToString());
|
|
|
case 3: // S.9001002.Rec
|
|
|
return val;
|
|
|
case 4: // S.9001002.RDT.Year
|
|
|
switch (strs[3])
|
|
|
{
|
|
|
case "Text":
|
|
|
if (val.Equals("0"))
|
|
|
return "否";
|
|
|
else
|
|
|
return "是";
|
|
|
case "YesNo":
|
|
|
if (val.Equals("1"))
|
|
|
return "[√]";
|
|
|
else
|
|
|
return "[×]";
|
|
|
case "Year":
|
|
|
return val.Substring(0, 4);
|
|
|
case "Month":
|
|
|
return val.Substring(5, 2);
|
|
|
case "Day":
|
|
|
return val.Substring(8, 2);
|
|
|
case "NYR":
|
|
|
return DataType.ParseSysDate2DateTime(val).ToString("yyyy年MM月dd日");
|
|
|
case "RMB":
|
|
|
return float.Parse(val).ToString("0.00");
|
|
|
case "RMBDX":
|
|
|
return DataType.ParseFloatToCache(float.Parse(val));
|
|
|
default:
|
|
|
throw new Exception("step2参数设置错误" + strs);
|
|
|
}
|
|
|
default:
|
|
|
throw new Exception("step3参数设置错误" + strs);
|
|
|
}
|
|
|
}
|
|
|
throw new Exception("step4参数设置错误" + strs);
|
|
|
}
|
|
|
public static string GetImgHexString(System.Drawing.Image img, System.Drawing.Imaging.ImageFormat ext)
|
|
|
{
|
|
|
StringBuilder imgs = new StringBuilder();
|
|
|
MemoryStream stream = new MemoryStream();
|
|
|
img.Save(stream, ext);
|
|
|
stream.Close();
|
|
|
|
|
|
byte[] buffer = stream.ToArray();
|
|
|
|
|
|
for (int i = 0; i < buffer.Length; i++)
|
|
|
{
|
|
|
if ((i % 32) == 0)
|
|
|
{
|
|
|
imgs.AppendLine();
|
|
|
}
|
|
|
//else if ((i % 8) == 0)
|
|
|
//{
|
|
|
// imgs.Append(" ");
|
|
|
//}
|
|
|
byte num2 = buffer[i];
|
|
|
int num3 = (num2 & 240) >> 4;
|
|
|
int num4 = num2 & 15;
|
|
|
imgs.Append("0123456789abcdef"[num3]);
|
|
|
imgs.Append("0123456789abcdef"[num4]);
|
|
|
}
|
|
|
return imgs.ToString();
|
|
|
}
|
|
|
public Entity HisGEEntity = null;
|
|
|
/// <summary>
|
|
|
/// 获取ICON图片的数据。
|
|
|
/// </summary>
|
|
|
/// <param name="key"></param>
|
|
|
/// <returns></returns>
|
|
|
public string GetValueImgStrs(string key)
|
|
|
{
|
|
|
key = key.Replace(" ", "");
|
|
|
key = key.Replace("\r\n", "");
|
|
|
|
|
|
/*说明是图片文件.*/
|
|
|
string path = key.Replace("OID.Img@AppPath", SystemConfig.PathOfWebApp);
|
|
|
|
|
|
//定义rtf中图片字符串
|
|
|
StringBuilder pict = new StringBuilder();
|
|
|
//获取要插入的图片
|
|
|
System.Drawing.Image img = System.Drawing.Image.FromFile(path);
|
|
|
|
|
|
//将要插入的图片转换为16进制字符串
|
|
|
string imgHexString;
|
|
|
key = key.ToLower();
|
|
|
|
|
|
if (key.Contains(".png"))
|
|
|
imgHexString = GetImgHexString(img, System.Drawing.Imaging.ImageFormat.Png);
|
|
|
else if (key.Contains(".jp"))
|
|
|
imgHexString = GetImgHexString(img, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
else if (key.Contains(".gif"))
|
|
|
imgHexString = GetImgHexString(img, System.Drawing.Imaging.ImageFormat.Gif);
|
|
|
else if (key.Contains(".ico"))
|
|
|
imgHexString = GetImgHexString(img, System.Drawing.Imaging.ImageFormat.Icon);
|
|
|
else
|
|
|
imgHexString = GetImgHexString(img, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
|
|
|
//生成rtf中图片字符串
|
|
|
pict.AppendLine();
|
|
|
pict.Append(@"{\pict");
|
|
|
pict.Append(@"\jpegblip");
|
|
|
pict.Append(@"\picscalex100");
|
|
|
pict.Append(@"\picscaley100");
|
|
|
pict.Append(@"\picwgoal" + img.Size.Width * 15);
|
|
|
pict.Append(@"\pichgoal" + img.Size.Height * 15);
|
|
|
pict.Append(imgHexString + "}");
|
|
|
pict.AppendLine();
|
|
|
return pict.ToString();
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 输入轨迹表.
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public string GetFlowTrackTable()
|
|
|
{
|
|
|
|
|
|
//定义表头.
|
|
|
string title = @"\trowd\trgaph108\trleft5\trbrdrl\brdrs\brdrw10 \trbrdrt\brdrs\brdrw10 \trbrdrr\brdrs\brdrw10 \trbrdrb\brdrs\brdrw10 \trpaddl108\trpaddr108\trpaddfl3\trpaddfr3
|
|
|
\clbrdrl\brdrw10\brdrs\clbrdrt\brdrw10\brdrs\clbrdrr\brdrw10\brdrs\clbrdrb\brdrw10\brdrs \cellx1065\clbrdrl\brdrw10\brdrs\clbrdrt\brdrw10\brdrs\clbrdrr\brdrw10\brdrs\clbrdrb\brdrw10\brdrs \cellx2126\clbrdrl\brdrw10\brdrs\clbrdrt\brdrw10\brdrs\clbrdrr\brdrw10\brdrs\clbrdrb\brdrw10\brdrs \cellx3187\clbrdrl\brdrw10\brdrs\clbrdrt\brdrw10\brdrs\clbrdrr\brdrw10\brdrs\clbrdrb\brdrw10\brdrs \cellx4248\clbrdrl\brdrw10\brdrs\clbrdrt\brdrw10\brdrs\clbrdrr\brdrw10\brdrs\clbrdrb\brdrw10\brdrs \cellx5309\clbrdrl\brdrw10\brdrs\clbrdrt\brdrw10\brdrs\clbrdrr\brdrw10\brdrs\clbrdrb\brdrw10\brdrs \cellx6370\clbrdrl\brdrw10\brdrs\clbrdrt\brdrw10\brdrs\clbrdrr\brdrw10\brdrs\clbrdrb\brdrw10\brdrs \cellx7431\clbrdrl\brdrw10\brdrs\clbrdrt\brdrw10\brdrs\clbrdrr\brdrw10\brdrs\clbrdrb\brdrw10\brdrs \cellx8492\pard\intbl\qj\lang2052\kerning2\f1\fs21\'d0\'f2\'ba\'c5\lang1033\f0\cell\lang2052\f1\'d6\'b4\'d0\'d0\'bb\'b7\'bd\'da\lang1033\f0\cell\lang2052\f1\'b0\'ec\'c0\'ed\'c7\'e9\'bf\'f6\lang1033\f0\cell\lang2052\f1\'d7\'b4\'cc\'ac\lang1033\f0\cell\lang2052\f1\'d6\'b4\'d0\'d0\'c8\'cb\lang1033\f0\cell\lang2052\f1\'bf\'aa\'ca\'bc\'ca\'b1\'bc\'e4\lang1033\f0\cell\lang2052\f1\'bd\'e1\'ca\'f8\'ca\'b1\'bc\'e4\lang1033\f0\cell\lang2052\f1\'c0\'fa\'ca\'b1TTT\lang1033\f0\cell\row";
|
|
|
|
|
|
//内容行部分.
|
|
|
string row = @"\trowd\
|
|
|
trgaph108\trleft5\trbrdrl\brdrs\brdrw10 \trbrdrt\brdrs\brdrw10 \trbrdrr\brdrs\brdrw10 \trbrdrb\brdrs\brdrw10 \trpaddl108\trpaddr108\trpaddfl3\trpaddfr3
|
|
|
\clbrdrl\brdrw10\brdrs\clbrdrt\brdrw10\brdrs\clbrdrr\brdrw10\brdrs\clbrdrb\brdrw10\brdrs \cellx1065\clbrdrl\brdrw10\brdrs\clbrdrt\brdrw10\brdrs\clbrdrr\brdrw10\brdrs\clbrdrb\brdrw10\brdrs \cellx2126\clbrdrl\brdrw10\brdrs\clbrdrt\brdrw10\brdrs\clbrdrr\brdrw10\brdrs\clbrdrb\brdrw10\brdrs \cellx3187\clbrdrl\brdrw10\brdrs\clbrdrt\brdrw10\brdrs\clbrdrr\brdrw10\brdrs\clbrdrb\brdrw10\brdrs \cellx4248\clbrdrl\brdrw10\brdrs\clbrdrt\brdrw10\brdrs\clbrdrr\brdrw10\brdrs\clbrdrb\brdrw10\brdrs \cellx5309\clbrdrl\brdrw10\brdrs\clbrdrt\brdrw10\brdrs\clbrdrr\brdrw10\brdrs\clbrdrb\brdrw10\brdrs \cellx6370\clbrdrl\brdrw10\brdrs\clbrdrt\brdrw10\brdrs\clbrdrr\brdrw10\brdrs\clbrdrb\brdrw10\brdrs \cellx7431\clbrdrl\brdrw10\brdrs\clbrdrt\brdrw10\brdrs\clbrdrr\brdrw10\brdrs\clbrdrb\brdrw10\brdrs \cellx8492\pard\intbl\qj\f2 <Idx>\f0\cell\f2 <NDFromT> \f0\cell\f2 <State> \f0\cell\f2 <ActionTypeTex> \f0\cell\f2 <EmpFromT> \f0\cell\f2 <StartTime> \f0\cell\f2 <EndTime> \f0\cell\f2 <PassTime> \f0\cell\row\";
|
|
|
|
|
|
|
|
|
string str = "";
|
|
|
int idx = 0;
|
|
|
foreach (DataRow dr in dtTrack.Rows)
|
|
|
{
|
|
|
idx++;
|
|
|
string dataRow = row.Clone() as string;
|
|
|
|
|
|
dataRow = dataRow.Replace("<Idx>", idx.ToString());
|
|
|
dataRow = dataRow.Replace("<NDFromT>", dr["NDFromT"].ToString());
|
|
|
str += dataRow;
|
|
|
}
|
|
|
return title + str;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获取ICON图片的数据。
|
|
|
/// </summary>
|
|
|
/// <param name="key"></param>
|
|
|
/// <returns></returns>
|
|
|
public string GetValueImgStrsOfQR(string billUrl)
|
|
|
{
|
|
|
/*说明是图片文件.*/
|
|
|
string path = SystemConfig.PathOfTemp + Guid.NewGuid() + ".png"; // key.Replace("OID.Img@AppPath", BP.Difference.SystemConfig.PathOfWebApp);
|
|
|
|
|
|
#region 生成二维码.
|
|
|
ThoughtWorks.QRCode.Codec.QRCodeEncoder qrc = new ThoughtWorks.QRCode.Codec.QRCodeEncoder();
|
|
|
qrc.QRCodeEncodeMode = ThoughtWorks.QRCode.Codec.QRCodeEncoder.ENCODE_MODE.BYTE;
|
|
|
qrc.QRCodeScale = 4;
|
|
|
qrc.QRCodeVersion = 7;
|
|
|
qrc.QRCodeErrorCorrect = ThoughtWorks.QRCode.Codec.QRCodeEncoder.ERROR_CORRECTION.M;
|
|
|
System.Drawing.Bitmap btm = qrc.Encode(billUrl, System.Text.Encoding.UTF8);
|
|
|
btm.Save(path);
|
|
|
#endregion
|
|
|
|
|
|
//定义rtf中图片字符串
|
|
|
StringBuilder pict = new StringBuilder();
|
|
|
//获取要插入的图片
|
|
|
System.Drawing.Image img = System.Drawing.Image.FromFile(path);
|
|
|
|
|
|
//将要插入的图片转换为16进制字符串.
|
|
|
string imgHexString;
|
|
|
imgHexString = GetImgHexString(img, System.Drawing.Imaging.ImageFormat.Png);
|
|
|
|
|
|
//生成rtf中图片字符串
|
|
|
pict.AppendLine();
|
|
|
pict.Append(@"{\pict");
|
|
|
pict.Append(@"\jpegblip");
|
|
|
pict.Append(@"\picscalex100");
|
|
|
pict.Append(@"\picscaley100");
|
|
|
pict.Append(@"\picwgoal" + img.Size.Width * 15);
|
|
|
pict.Append(@"\pichgoal" + img.Size.Height * 15);
|
|
|
pict.Append(imgHexString + "}");
|
|
|
pict.AppendLine();
|
|
|
return pict.ToString();
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获取M2M数据并输出
|
|
|
/// </summary>
|
|
|
/// <param name="key"></param>
|
|
|
/// <returns></returns>
|
|
|
public string GetValueM2MStrs(string key)
|
|
|
{
|
|
|
return "";
|
|
|
|
|
|
//string[] strs = key.Split('.');
|
|
|
//string sql = "SELECT ValsName FROM SYS_M2M WHERE FK_MapData='" + strs[0] + "' AND M2MNo='" + strs[2] + "' AND EnOID='" + this.HisGEEntity.PKVal + "'";
|
|
|
//string vals = DBAccess.RunSQLReturnStringIsNull(sql, null);
|
|
|
//if (vals == null)
|
|
|
// return "无数据";
|
|
|
|
|
|
//vals = vals.Replace("@", " ");
|
|
|
//vals = vals.Replace("<font color=green>", "");
|
|
|
//vals = vals.Replace("</font>", "");
|
|
|
//return vals;
|
|
|
|
|
|
//string val = "";
|
|
|
//string[] objs = vals.Split('@');
|
|
|
//foreach (string obj in objs)
|
|
|
//{
|
|
|
// string[] noName = obj.Split(',');
|
|
|
// val += noName[1];
|
|
|
//}
|
|
|
//return val;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获取写字版的数据
|
|
|
/// </summary>
|
|
|
/// <param name="key"></param>
|
|
|
/// <returns></returns>
|
|
|
public string GetValueBPPaintStrs(string key)
|
|
|
{
|
|
|
key = key.Replace(" ", "");
|
|
|
key = key.Replace("\r\n", "");
|
|
|
|
|
|
string[] strs = key.Split('.');
|
|
|
string filePath = "";
|
|
|
try
|
|
|
{
|
|
|
filePath = DBAccess.RunSQLReturnString("SELECT Tag2 From Sys_FrmEleDB WHERE RefPKVal=" + this.HisGEEntity.PKVal + " AND EleID='" + strs[2].Trim() + "'");
|
|
|
if (filePath == null)
|
|
|
return "";
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
//定义rtf中图片字符串
|
|
|
StringBuilder pict = new StringBuilder();
|
|
|
//获取要插入的图片
|
|
|
System.Drawing.Image img = System.Drawing.Image.FromFile(filePath);
|
|
|
|
|
|
//将要插入的图片转换为16进制字符串
|
|
|
string imgHexString;
|
|
|
filePath = filePath.ToLower();
|
|
|
|
|
|
if (filePath.Contains(".png"))
|
|
|
imgHexString = GetImgHexString(img, System.Drawing.Imaging.ImageFormat.Png);
|
|
|
else if (filePath.Contains(".jp"))
|
|
|
imgHexString = GetImgHexString(img, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
else if (filePath.Contains(".gif"))
|
|
|
imgHexString = GetImgHexString(img, System.Drawing.Imaging.ImageFormat.Gif);
|
|
|
else if (filePath.Contains(".ico"))
|
|
|
imgHexString = GetImgHexString(img, System.Drawing.Imaging.ImageFormat.Icon);
|
|
|
else
|
|
|
imgHexString = GetImgHexString(img, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
|
|
|
//生成rtf中图片字符串
|
|
|
pict.AppendLine();
|
|
|
pict.Append(@"{\pict");
|
|
|
pict.Append(@"\jpegblip");
|
|
|
pict.Append(@"\picscalex100");
|
|
|
pict.Append(@"\picscaley100");
|
|
|
pict.Append(@"\picwgoal" + img.Size.Width * 15);
|
|
|
pict.Append(@"\pichgoal" + img.Size.Height * 15);
|
|
|
pict.Append(imgHexString + "}");
|
|
|
pict.AppendLine();
|
|
|
return pict.ToString();
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获取类名+@+字段格式的数据.
|
|
|
/// 比如:
|
|
|
/// Demo_Inc@ABC
|
|
|
/// Emp@Name
|
|
|
/// </summary>
|
|
|
/// <param name="key"></param>
|
|
|
/// <returns></returns>
|
|
|
public string GetValueByAtKey(string key)
|
|
|
{
|
|
|
foreach (Entity en in this.HisEns)
|
|
|
{
|
|
|
string enKey = en.ToString();
|
|
|
|
|
|
//有可能是 BP.Port.Emp
|
|
|
if (enKey.Contains("."))
|
|
|
enKey = en.GetType().Name;
|
|
|
|
|
|
//如果不包含.
|
|
|
if (key.Contains(enKey + "@") == false)
|
|
|
continue;
|
|
|
|
|
|
// 如果不包含 . 就说明,不需要转意。
|
|
|
if (key.Contains(".") == false)
|
|
|
return en.GetValStringByKey(key.Substring(key.IndexOf('@') + 1));
|
|
|
|
|
|
//把实体名去掉
|
|
|
key = key.Replace(enKey + "@", "");
|
|
|
//把数据破开.
|
|
|
string[] strs = key.Split('.');
|
|
|
if (strs.Length == 2)
|
|
|
{
|
|
|
if (strs[1].Trim().Equals("ImgAth"))
|
|
|
{
|
|
|
string path1 = SystemConfig.PathOfDataUser + "ImgAth/Data/" + strs[0].Trim() + "_" + en.PKVal + ".png";
|
|
|
//定义rtf中图片字符串.
|
|
|
StringBuilder mypict = new StringBuilder();
|
|
|
//获取要插入的图片
|
|
|
System.Drawing.Image imgAth = System.Drawing.Image.FromFile(path1);
|
|
|
|
|
|
//将要插入的图片转换为16进制字符串
|
|
|
string imgHexStringImgAth = GetImgHexString(imgAth, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
//生成rtf中图片字符串
|
|
|
mypict.AppendLine();
|
|
|
mypict.Append(@"{\pict");
|
|
|
mypict.Append(@"\jpegblip");
|
|
|
mypict.Append(@"\picscalex100");
|
|
|
mypict.Append(@"\picscaley100");
|
|
|
mypict.Append(@"\picwgoal" + imgAth.Size.Width * 15);
|
|
|
mypict.Append(@"\pichgoal" + imgAth.Size.Height * 15);
|
|
|
mypict.Append(imgHexStringImgAth + "}");
|
|
|
mypict.AppendLine();
|
|
|
return mypict.ToString();
|
|
|
}
|
|
|
|
|
|
string val = en.GetValStringByKey(strs[0].Trim());
|
|
|
switch (strs[1].Trim())
|
|
|
{
|
|
|
case "Text":
|
|
|
if (val.Equals("0"))
|
|
|
return "否";
|
|
|
else
|
|
|
return "是";
|
|
|
case "Year":
|
|
|
return val.Substring(0, 4);
|
|
|
case "Month":
|
|
|
return val.Substring(5, 2);
|
|
|
case "Day":
|
|
|
return val.Substring(8, 2);
|
|
|
case "NYR":
|
|
|
return DataType.ParseSysDate2DateTime(val).ToString("yyyy年MM月dd日");
|
|
|
case "RMB":
|
|
|
return float.Parse(val).ToString("0.00");
|
|
|
case "RMBDX":
|
|
|
return DataType.ParseFloatToCache(float.Parse(val));
|
|
|
case "ImgAth":
|
|
|
string path1 = SystemConfig.PathOfDataUser + "ImgAth/Data/" + strs[0].Trim() + "_" + this.HisGEEntity.PKVal + ".png";
|
|
|
|
|
|
//定义rtf中图片字符串.
|
|
|
StringBuilder mypict = new StringBuilder();
|
|
|
//获取要插入的图片
|
|
|
System.Drawing.Image imgAth = System.Drawing.Image.FromFile(path1);
|
|
|
|
|
|
//将要插入的图片转换为16进制字符串
|
|
|
string imgHexStringImgAth = GetImgHexString(imgAth, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
//生成rtf中图片字符串
|
|
|
mypict.AppendLine();
|
|
|
mypict.Append(@"{\pict");
|
|
|
mypict.Append(@"\jpegblip");
|
|
|
mypict.Append(@"\picscalex100");
|
|
|
mypict.Append(@"\picscaley100");
|
|
|
mypict.Append(@"\picwgoal" + imgAth.Size.Width * 15);
|
|
|
mypict.Append(@"\pichgoal" + imgAth.Size.Height * 15);
|
|
|
mypict.Append(imgHexStringImgAth + "}");
|
|
|
mypict.AppendLine();
|
|
|
return mypict.ToString();
|
|
|
case "Siganture":
|
|
|
string path = SystemConfig.PathOfDataUser + "Siganture/" + val + ".jpg";
|
|
|
//定义rtf中图片字符串.
|
|
|
StringBuilder pict = new StringBuilder();
|
|
|
//获取要插入的图片
|
|
|
System.Drawing.Image img = System.Drawing.Image.FromFile(path);
|
|
|
|
|
|
//将要插入的图片转换为16进制字符串
|
|
|
string imgHexString = GetImgHexString(img, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
//生成rtf中图片字符串
|
|
|
pict.AppendLine();
|
|
|
pict.Append(@"{\pict");
|
|
|
pict.Append(@"\jpegblip");
|
|
|
pict.Append(@"\picscalex100");
|
|
|
pict.Append(@"\picscaley100");
|
|
|
pict.Append(@"\picwgoal" + img.Size.Width * 15);
|
|
|
pict.Append(@"\pichgoal" + img.Size.Height * 15);
|
|
|
pict.Append(imgHexString + "}");
|
|
|
pict.AppendLine();
|
|
|
return pict.ToString();
|
|
|
//替换rtf模板文件中的签名图片标识为图片字符串
|
|
|
// str = str.Replace(imgMark, pict.ToString());
|
|
|
default:
|
|
|
throw new Exception("参数设置错误,特殊方式取值错误:" + key);
|
|
|
}
|
|
|
}
|
|
|
} // 实体循环。
|
|
|
|
|
|
throw new Exception("参数设置错误 GetValueByKey :" + key);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获得所所有的审核人员信息.
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public string GetValueCheckWorks()
|
|
|
{
|
|
|
string html = "";
|
|
|
|
|
|
//获得当前待办的人员,把当前审批的人员排除在外,不然就有默认同意的意见可以打印出来.
|
|
|
string sql = "SELECT FK_Emp, FK_Node FROM WF_GenerWorkerlist WHERE IsPass!=1 AND WorkID=" + this.HisGEEntity.PKVal;
|
|
|
DataTable dtOfTodo = DBAccess.RunSQLReturnTable(sql);
|
|
|
|
|
|
foreach (DataRow dr in dtTrack.Rows)
|
|
|
{
|
|
|
#region 排除正在审批的人员.
|
|
|
string nodeID = dr["NDFrom"].ToString();
|
|
|
string empFrom = dr["EmpFrom"].ToString();
|
|
|
if (dtOfTodo.Rows.Count != 0)
|
|
|
{
|
|
|
bool isHave = false;
|
|
|
foreach (DataRow mydr in dtOfTodo.Rows)
|
|
|
{
|
|
|
if (mydr["FK_Node"].ToString() != nodeID)
|
|
|
continue;
|
|
|
|
|
|
if (mydr["FK_Emp"].ToString() != empFrom)
|
|
|
continue;
|
|
|
isHave = true;
|
|
|
}
|
|
|
|
|
|
if (isHave == true)
|
|
|
continue;
|
|
|
}
|
|
|
#endregion 排除正在审批的人员.
|
|
|
|
|
|
|
|
|
html += "<tr>";
|
|
|
html += " <td valign=middle >" + dr["NDFromT"] + "</td>";
|
|
|
|
|
|
string msg = dr["Msg"].ToString();
|
|
|
|
|
|
msg += "<br>";
|
|
|
msg += "<br>";
|
|
|
|
|
|
string empStrs = "";
|
|
|
if (dtTrack == null)
|
|
|
{
|
|
|
empStrs = dr["EmpFromT"].ToString();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string singType = "0";
|
|
|
foreach (DataRow drTrack in dtTrack.Rows)
|
|
|
{
|
|
|
if (drTrack["No"].ToString().Equals(dr["EmpFrom"].ToString()))
|
|
|
{
|
|
|
singType = drTrack["SignType"].ToString();
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (singType.Equals("0") || singType.Equals("2"))
|
|
|
{
|
|
|
empStrs = dr["EmpFromT"].ToString();
|
|
|
}
|
|
|
|
|
|
|
|
|
if (singType.Equals("1"))
|
|
|
{
|
|
|
empStrs = "<img src='../../../../../DataUser/Siganture/" + dr["EmpFrom"] + ".jpg' title='" + dr["EmpFromT"] + "' style='height:60px;' border=0 onerror=\"src='../../../../../DataUser/Siganture/UnName.jpg'\" /> " + dr["EmpFromT"];
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
msg += "审核人:" + empStrs + " 日期:" + dr["RDT"].ToString();
|
|
|
|
|
|
html += " <td colspan=3 valign=middle >" + msg + "</td>";
|
|
|
html += " </tr>";
|
|
|
}
|
|
|
|
|
|
return html;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获得审核组件的信息.
|
|
|
/// </summary>
|
|
|
/// <param name="key"></param>
|
|
|
/// <returns></returns>
|
|
|
public string GetValueCheckWorkByKey(string key)
|
|
|
{
|
|
|
key = key.Replace(" ", "");
|
|
|
key = key.Replace("\r\n", "");
|
|
|
|
|
|
string[] strs = key.Split('.');
|
|
|
if (strs.Length == 3)
|
|
|
{
|
|
|
/*
|
|
|
* 是一个节点一个审核人的模式. <WorkCheck.RDT.101>
|
|
|
*/
|
|
|
if (dtTrack == null)
|
|
|
throw new Exception("@您设置了获取审核组件里的规则,但是你没有给审核组件数据源dtTrack赋值。");
|
|
|
|
|
|
string nodeID = strs[2];
|
|
|
foreach (DataRow dr in dtTrack.Rows)
|
|
|
{
|
|
|
if (dr["NDFrom"].ToString() != nodeID)
|
|
|
continue;
|
|
|
|
|
|
switch (strs[1])
|
|
|
{
|
|
|
case "RDT":
|
|
|
return dr["RDT"].ToString(); //审核日期.
|
|
|
case "RDT-NYR":
|
|
|
string rdt = dr["RDT"].ToString(); //审核日期.
|
|
|
DateTime dt = Convert.ToDateTime(rdt);
|
|
|
return dt.Year + "\\'c4\\'ea" + dt.Month + "\\'d4\\'c2" + dt.Day + "\\'c8\\'d5";
|
|
|
return Convert.ToDateTime(rdt).ToString("yyyy年MM月dd日");
|
|
|
case "Rec":
|
|
|
return dr["EmpFrom"].ToString(); //记录人.
|
|
|
case "RecName":
|
|
|
string recName = dr["EmpFromT"].ToString(); //审核人.
|
|
|
recName = this.GetCode(recName);
|
|
|
return recName;
|
|
|
case "Msg":
|
|
|
case "Note":
|
|
|
string text = dr["Msg"].ToString();
|
|
|
text = text.Replace("\\", "\\\\");
|
|
|
text = this.GetCode(text);
|
|
|
return text;
|
|
|
|
|
|
//return System.Text.Encoder //审核信息.
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return "无";
|
|
|
}
|
|
|
|
|
|
private string GetValueCheckWorkByKey(DataRow row, string key)
|
|
|
{
|
|
|
key = key.Replace(" ", "");
|
|
|
key = key.Replace("\r\n", "");
|
|
|
|
|
|
switch (key)
|
|
|
{
|
|
|
case "RDT":
|
|
|
return row["RDT"].ToString(); //审核日期.
|
|
|
case "RDT-NYR":
|
|
|
string rdt = row["RDT"].ToString(); //审核日期.
|
|
|
DateTime dt = Convert.ToDateTime(rdt);
|
|
|
return dt.Year + "\\'c4\\'ea" + dt.Month + "\\'d4\\'c2" + dt.Day + "\\'c8\\'d5";
|
|
|
return Convert.ToDateTime(rdt).ToString("yyyy年MM月dd日");
|
|
|
case "Rec":
|
|
|
return row["EmpFrom"].ToString(); //记录人.
|
|
|
case "RecName":
|
|
|
string recName = row["EmpFromT"].ToString(); //审核人.
|
|
|
recName = this.GetCode(recName);
|
|
|
return recName;
|
|
|
case "Msg":
|
|
|
case "Note":
|
|
|
string text = row["Msg"].ToString();
|
|
|
text = text.Replace("\\", "\\\\");
|
|
|
text = this.GetCode(text);
|
|
|
return text;
|
|
|
case "Siganture":
|
|
|
string empNo = row["EmpFrom"].ToString(); //记录人.
|
|
|
return empNo;//审核人的签名.
|
|
|
case "WriteDB":
|
|
|
return row["WriteDB"].ToString();
|
|
|
default:
|
|
|
return row[key] as string;
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 审核节点的表示方法是 节点ID.Attr.
|
|
|
/// </summary>
|
|
|
/// <param name="key"></param>
|
|
|
/// <returns></returns>
|
|
|
public string GetValueByKey(string key)
|
|
|
{
|
|
|
key = key.Replace(" ", "");
|
|
|
key = key.Replace("\r\n", "");
|
|
|
|
|
|
//获取参数代码.
|
|
|
if (key.Contains("@"))
|
|
|
return GetValueByAtKey(key);
|
|
|
|
|
|
string[] strs = key.Split('.');
|
|
|
|
|
|
// 如果不包含 . 就说明他是从Rpt中取数据。
|
|
|
//if (this.HisGEEntity != null && key.Contains("ND") == false)
|
|
|
if (this.HisGEEntity != null)
|
|
|
{
|
|
|
if (strs.Length == 1)
|
|
|
return this.HisGEEntity.GetValStringByKey(key);
|
|
|
|
|
|
if (strs[1].Trim().Equals("Checkboxs"))
|
|
|
{
|
|
|
//获取复选框多选的值
|
|
|
string content = this.HisGEEntity.GetValStringByKey(strs[0]);
|
|
|
//转换成文本
|
|
|
Attr attr = this.HisGEEntity.EnMap.Attrs.GetAttrByKeyOfEn(strs[0]);
|
|
|
if (DataType.IsNullOrEmpty(attr.UIBindKey) == true)
|
|
|
return content;
|
|
|
SysEnums enums = new SysEnums(attr.UIBindKey);
|
|
|
string str = "";
|
|
|
foreach (SysEnum en in enums)
|
|
|
{
|
|
|
if ((content + ",").Contains(en.IntKey + ",") == true)
|
|
|
str += en.Lab + ",";
|
|
|
}
|
|
|
if (str != "") str = str.Substring(0, str.Length - 1);
|
|
|
return str;
|
|
|
}
|
|
|
if (strs[1].Trim().Equals("Editor"))
|
|
|
{
|
|
|
//获取富文本的内容
|
|
|
string content = this.HisGEEntity.GetValStringByKey(strs[0]);
|
|
|
content = content.Replace("img+", "img ");
|
|
|
string contentHtml = "<html><head></head><body>" + content + "</body></html>";
|
|
|
string StrNohtml = System.Text.RegularExpressions.Regex.Replace(contentHtml, "<[^>]+>", "");
|
|
|
StrNohtml = System.Text.RegularExpressions.Regex.Replace(StrNohtml, "&[^;]+;", "");
|
|
|
|
|
|
return this.GetCode(StrNohtml);
|
|
|
|
|
|
|
|
|
string htmlpath = SystemConfig.PathOfDataUser + "Bill/Temp/EditorHtm.html";
|
|
|
if (File.Exists(htmlpath) == false)
|
|
|
File.Create(htmlpath);
|
|
|
using (StreamWriter sw = new StreamWriter(htmlpath))
|
|
|
{
|
|
|
sw.Write(contentHtml);
|
|
|
}
|
|
|
|
|
|
//如何写入到word
|
|
|
string html = File.ReadAllText(htmlpath, Encoding.UTF8);
|
|
|
|
|
|
//byte[] array = Encoding.ASCII.GetBytes(content);
|
|
|
//StringBuilder editors = new StringBuilder();
|
|
|
//for (int i = 0; i < array.Length; i++)
|
|
|
//{
|
|
|
|
|
|
// editors.Append(array[i]);
|
|
|
|
|
|
//}
|
|
|
//MemoryStream stream = new MemoryStream(array); //convert stream 2 string
|
|
|
|
|
|
//System.IO.StreamReader readStream = new System.IO.StreamReader(contentHtml, Encoding.UTF8);
|
|
|
return html;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (strs[1].Trim().Equals("ImgAth"))
|
|
|
{
|
|
|
string path1 = SystemConfig.PathOfDataUser + "ImgAth/Data/" + strs[0].Trim() + "_" + this.HisGEEntity.PKVal + ".png";
|
|
|
if (!File.Exists(path1))
|
|
|
{
|
|
|
return path1;
|
|
|
}
|
|
|
//定义rtf中图片字符串.
|
|
|
StringBuilder mypict = new StringBuilder();
|
|
|
//获取要插入的图片
|
|
|
System.Drawing.Image imgAth = System.Drawing.Image.FromFile(path1);
|
|
|
//图片附件描述属性
|
|
|
FrmImgAth frmImgAth = new FrmImgAth();
|
|
|
frmImgAth.RetrieveByAttr(FrmImgAthAttr.MyPK, strs[0].Trim());
|
|
|
//图片高宽
|
|
|
float iWidth = imgAth.Size.Width * 15;
|
|
|
float iHeight = imgAth.Size.Height * 15;
|
|
|
if (frmImgAth != null && !DataType.IsNullOrEmpty(frmImgAth.FrmID))
|
|
|
{
|
|
|
iWidth = frmImgAth.W * 15;
|
|
|
iHeight = frmImgAth.H * 15;
|
|
|
}
|
|
|
|
|
|
//将要插入的图片转换为16进制字符串
|
|
|
string imgHexStringImgAth = GetImgHexString(imgAth, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
//生成rtf中图片字符串
|
|
|
mypict.AppendLine();
|
|
|
mypict.Append(@"{\pict");
|
|
|
mypict.Append(@"\jpegblip");
|
|
|
mypict.Append(@"\picscalex100");
|
|
|
mypict.Append(@"\picscaley100");
|
|
|
mypict.Append(@"\picwgoal" + iWidth);
|
|
|
mypict.Append(@"\pichgoal" + iHeight);
|
|
|
mypict.Append(imgHexStringImgAth + "}");
|
|
|
mypict.AppendLine();
|
|
|
return mypict.ToString();
|
|
|
}
|
|
|
|
|
|
if (strs[1].Trim().Equals("BPPaint"))
|
|
|
{
|
|
|
string path1 = DBAccess.RunSQLReturnString("SELECT Tag2 FROM Sys_FrmEleDB WHERE REFPKVAL=" + this.HisGEEntity.PKVal + " AND EleID='" + strs[0].Trim() + "'");
|
|
|
// string path1 = BP.Difference.SystemConfig.PathOfDataUser + "\\BPPaint\\" + this.HisGEEntity.ToString().Trim() + "\\" + this.HisGEEntity.PKVal + ".png";
|
|
|
//定义rtf中图片字符串.
|
|
|
StringBuilder mypict = new StringBuilder();
|
|
|
//获取要插入的图片
|
|
|
System.Drawing.Image myBPPaint = System.Drawing.Image.FromFile(path1);
|
|
|
|
|
|
//将要插入的图片转换为16进制字符串
|
|
|
string imgHexStringImgAth = GetImgHexString(myBPPaint, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
//生成rtf中图片字符串
|
|
|
mypict.AppendLine();
|
|
|
mypict.Append(@"{\pict");
|
|
|
mypict.Append(@"\jpegblip");
|
|
|
mypict.Append(@"\picscalex100");
|
|
|
mypict.Append(@"\picscaley100");
|
|
|
mypict.Append(@"\picwgoal" + myBPPaint.Size.Width * 15);
|
|
|
mypict.Append(@"\pichgoal" + myBPPaint.Size.Height * 15);
|
|
|
mypict.Append(imgHexStringImgAth + "}");
|
|
|
mypict.AppendLine();
|
|
|
return mypict.ToString();
|
|
|
}
|
|
|
|
|
|
//根据枚举值返回选中符号
|
|
|
if (strs[1].Contains("-EnumYes") == true)
|
|
|
{
|
|
|
string relVal = this.HisGEEntity.GetValStringByKey(strs[0]);
|
|
|
string[] checkVal = strs[1].Split('-');
|
|
|
if (checkVal.Length == 1)
|
|
|
return relVal;
|
|
|
if (relVal.Equals(checkVal[0]))
|
|
|
return "[√]";
|
|
|
else
|
|
|
return "[×]";
|
|
|
}
|
|
|
|
|
|
if (strs.Length == 2)
|
|
|
{
|
|
|
string val = this.HisGEEntity.GetValStringByKey(strs[0].Trim());
|
|
|
switch (strs[1].Trim())
|
|
|
{
|
|
|
|
|
|
case "Text":
|
|
|
if (val.Equals("0"))
|
|
|
return "否";
|
|
|
else
|
|
|
return "是";
|
|
|
case "Year":
|
|
|
return val.Substring(0, 4);
|
|
|
case "Month":
|
|
|
return val.Substring(5, 2);
|
|
|
case "Day":
|
|
|
return val.Substring(8, 2);
|
|
|
case "NYR":
|
|
|
return DataType.ParseSysDate2DateTime(val).ToString("yyyy年MM月dd日");
|
|
|
case "RMB":
|
|
|
decimal md = Math.Round(decimal.Parse(val), 2);
|
|
|
return md.ToString();
|
|
|
case "RMBDX":
|
|
|
return this.GetCode(DataType.ParseFloatToCache(float.Parse(val)));
|
|
|
case "Siganture":
|
|
|
string path = SystemConfig.PathOfDataUser + "Siganture/" + val + ".jpg";
|
|
|
//获取要插入的图片
|
|
|
if (File.Exists(path) == true)
|
|
|
{
|
|
|
//定义rtf中图片字符串
|
|
|
StringBuilder pict = new StringBuilder();
|
|
|
System.Drawing.Image img = System.Drawing.Image.FromFile(path);
|
|
|
|
|
|
//将要插入的图片转换为16进制字符串
|
|
|
string imgHexString = GetImgHexString(img, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
//生成rtf中图片字符串
|
|
|
pict.AppendLine();
|
|
|
pict.Append(@"{\pict");
|
|
|
pict.Append(@"\jpegblip");
|
|
|
pict.Append(@"\picscalex100");
|
|
|
pict.Append(@"\picscaley100");
|
|
|
pict.Append(@"\picwgoal" + img.Size.Width * 15);
|
|
|
pict.Append(@"\pichgoal" + img.Size.Height * 15);
|
|
|
pict.Append(imgHexString + "}");
|
|
|
pict.AppendLine();
|
|
|
return pict.ToString();
|
|
|
}
|
|
|
//图片不存在显示中文名,否则显示原值
|
|
|
string empName = DBAccess.RunSQLReturnStringIsNull("SELECT Name FROM Port_Emp WHERE No='" + val + "'", val);
|
|
|
return this.GetCode(empName);
|
|
|
//替换rtf模板文件中的签名图片标识为图片字符串
|
|
|
// str = str.Replace(imgMark, pict.ToString());
|
|
|
case "BoolenText":
|
|
|
if (val.Equals("0"))
|
|
|
return "否";
|
|
|
else
|
|
|
return "是";
|
|
|
case "Boolen":
|
|
|
if (val.Equals("1"))
|
|
|
return "[√]";
|
|
|
else
|
|
|
return "[×]";
|
|
|
break;
|
|
|
case "YesNo":
|
|
|
if (val.Equals("1"))
|
|
|
return "[√]";
|
|
|
else
|
|
|
return "[×]";
|
|
|
break;
|
|
|
case "Yes":
|
|
|
if (val.Equals("1"))
|
|
|
return "[√]";
|
|
|
else
|
|
|
return "[×]";
|
|
|
case "No":
|
|
|
if (val.Equals("0"))
|
|
|
return "[√]";
|
|
|
else
|
|
|
return "[×]";
|
|
|
default:
|
|
|
throw new Exception("参数设置错误,特殊方式取值错误:" + key);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
throw new Exception("参数设置错误,特殊方式取值错误:" + key);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
foreach (Entity en in this.HisEns)
|
|
|
{
|
|
|
string enKey = en.ToString();
|
|
|
if (enKey.Contains("."))
|
|
|
enKey = en.GetType().Name;
|
|
|
if (key.Contains(en.ToString() + ".") == false)
|
|
|
continue;
|
|
|
|
|
|
/*说明就在这个字段内*/
|
|
|
if (strs.Length == 1)
|
|
|
throw new Exception("参数设置错误,strs.length=1 。" + key);
|
|
|
|
|
|
if (strs.Length == 2)
|
|
|
return en.GetValStringByKey(strs[1].Trim());
|
|
|
|
|
|
if (strs.Length == 3)
|
|
|
{
|
|
|
if (strs[2].Trim().Equals("ImgAth"))
|
|
|
{
|
|
|
string path1 = SystemConfig.PathOfDataUser + "ImgAth/Data/" + strs[1].Trim() + "_" + en.PKVal + ".png";
|
|
|
//定义rtf中图片字符串.
|
|
|
StringBuilder mypict = new StringBuilder();
|
|
|
//获取要插入的图片
|
|
|
System.Drawing.Image imgAth = System.Drawing.Image.FromFile(path1);
|
|
|
|
|
|
//将要插入的图片转换为16进制字符串
|
|
|
string imgHexStringImgAth = GetImgHexString(imgAth, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
//生成rtf中图片字符串
|
|
|
mypict.AppendLine();
|
|
|
mypict.Append(@"{\pict");
|
|
|
mypict.Append(@"\jpegblip");
|
|
|
mypict.Append(@"\picscalex100");
|
|
|
mypict.Append(@"\picscaley100");
|
|
|
mypict.Append(@"\picwgoal" + imgAth.Size.Width * 15);
|
|
|
mypict.Append(@"\pichgoal" + imgAth.Size.Height * 15);
|
|
|
mypict.Append(imgHexStringImgAth + "}");
|
|
|
mypict.AppendLine();
|
|
|
return mypict.ToString();
|
|
|
}
|
|
|
|
|
|
|
|
|
string val = en.GetValStringByKey(strs[1].Trim());
|
|
|
switch (strs[2].Trim())
|
|
|
{
|
|
|
case "Text":
|
|
|
if (val.Equals("0"))
|
|
|
return "否";
|
|
|
else
|
|
|
return "是";
|
|
|
case "Year":
|
|
|
return val.Substring(0, 4);
|
|
|
case "Month":
|
|
|
return val.Substring(5, 2);
|
|
|
case "Day":
|
|
|
return val.Substring(8, 2);
|
|
|
case "NYR":
|
|
|
return DataType.ParseSysDate2DateTime(val).ToString("yyyy年MM月dd日");
|
|
|
case "RMB":
|
|
|
return float.Parse(val).ToString("0.00");
|
|
|
case "RMBDX":
|
|
|
return DataType.ParseFloatToCache(float.Parse(val));
|
|
|
case "ImgAth":
|
|
|
string path1 = SystemConfig.PathOfDataUser + "ImgAth/Data/" + strs[0].Trim() + "_" + this.HisGEEntity.PKVal + ".png";
|
|
|
|
|
|
//定义rtf中图片字符串.
|
|
|
StringBuilder mypict = new StringBuilder();
|
|
|
//获取要插入的图片
|
|
|
System.Drawing.Image imgAth = System.Drawing.Image.FromFile(path1);
|
|
|
|
|
|
//将要插入的图片转换为16进制字符串
|
|
|
string imgHexStringImgAth = GetImgHexString(imgAth, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
//生成rtf中图片字符串
|
|
|
mypict.AppendLine();
|
|
|
mypict.Append(@"{\pict");
|
|
|
mypict.Append(@"\jpegblip");
|
|
|
mypict.Append(@"\picscalex100");
|
|
|
mypict.Append(@"\picscaley100");
|
|
|
mypict.Append(@"\picwgoal" + imgAth.Size.Width * 15);
|
|
|
mypict.Append(@"\pichgoal" + imgAth.Size.Height * 15);
|
|
|
mypict.Append(imgHexStringImgAth + "}");
|
|
|
mypict.AppendLine();
|
|
|
return mypict.ToString();
|
|
|
case "Siganture":
|
|
|
string path = SystemConfig.PathOfDataUser + "Siganture/" + val + ".jpg";
|
|
|
//定义rtf中图片字符串.
|
|
|
StringBuilder pict = new StringBuilder();
|
|
|
//获取要插入的图片
|
|
|
System.Drawing.Image img = System.Drawing.Image.FromFile(path);
|
|
|
|
|
|
//将要插入的图片转换为16进制字符串
|
|
|
string imgHexString = GetImgHexString(img, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
//生成rtf中图片字符串
|
|
|
pict.AppendLine();
|
|
|
pict.Append(@"{\pict");
|
|
|
pict.Append(@"\jpegblip");
|
|
|
pict.Append(@"\picscalex100");
|
|
|
pict.Append(@"\picscaley100");
|
|
|
pict.Append(@"\picwgoal" + img.Size.Width * 15);
|
|
|
pict.Append(@"\pichgoal" + img.Size.Height * 15);
|
|
|
pict.Append(imgHexString + "}");
|
|
|
pict.AppendLine();
|
|
|
return pict.ToString();
|
|
|
//替换rtf模板文件中的签名图片标识为图片字符串
|
|
|
// str = str.Replace(imgMark, pict.ToString());
|
|
|
default:
|
|
|
throw new Exception("参数设置错误,特殊方式取值错误:" + key);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
throw new Exception("参数设置错误 GetValueByKey :" + key);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 生成单据
|
|
|
/// <summary>
|
|
|
/// 生成单据
|
|
|
/// </summary>
|
|
|
/// <param name="cfile">模板文件</param>
|
|
|
public void MakeDoc(string cfile)
|
|
|
{
|
|
|
string file = PubClass.GenerTempFileName("doc");
|
|
|
this.MakeDoc(cfile, SystemConfig.PathOfTemp, file);
|
|
|
}
|
|
|
public string ensStrs = "";
|
|
|
/// <summary>
|
|
|
/// 轨迹表(用于输出打印审核轨迹,审核信息.)
|
|
|
/// </summary>
|
|
|
public DataTable dtTrack = null;
|
|
|
public DataTable wks = null;
|
|
|
public DataTable subFlows = null;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 替换三维表单@BKGY
|
|
|
/// </summary>
|
|
|
/// <param name="data">多维表单数据集</param>
|
|
|
/// <param name="D1">一级表头</param>
|
|
|
/// <param name="D2">二级表头</param>
|
|
|
/// <param name="D3">三级表头</param>
|
|
|
/// <param name="TextName">替换字符串</param>
|
|
|
/// <param name ="path"> 文件路径 </ param >
|
|
|
public void MDFORMDoc(DataTable data, string D1, String D2, String D3, string TextName, string path)
|
|
|
{
|
|
|
string rtf = string.Empty;
|
|
|
if (data.Rows.Count > 0)
|
|
|
{
|
|
|
string D1date = "", D2date = "", D3date = "";
|
|
|
///循环拿到牌号,
|
|
|
///循环拿到项目,
|
|
|
///循环拿到元素
|
|
|
for (int i = 0; i < data.Rows.Count; i++)
|
|
|
{
|
|
|
if (data.Rows[i][D1].ToString() != "-1")
|
|
|
{
|
|
|
if (!D1date.Contains(data.Rows[i][D1].ToString()))
|
|
|
{
|
|
|
D1date = D1date + data.Rows[i][D1].ToString() + ",";
|
|
|
}
|
|
|
}
|
|
|
if (data.Rows[i][D2].ToString() != "-1")
|
|
|
{
|
|
|
if (!D2date.Contains(data.Rows[i][D2 + "Text"].ToString()))
|
|
|
{
|
|
|
D2date = D2date + data.Rows[i][D2 + "Text"].ToString() + ",";
|
|
|
}
|
|
|
}
|
|
|
if (data.Rows[i][D3].ToString() != "-1")
|
|
|
{
|
|
|
if (!D3date.Contains(data.Rows[i][D3 + "Text"].ToString()))
|
|
|
{
|
|
|
D3date = D3date + data.Rows[i][D3 + "Text"].ToString() + ",";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (D1date.Length > 0 && D2date.Length > 0 && D3date.Length > 0)
|
|
|
{
|
|
|
D1date = D1date.Substring(0, D1date.Length - 1);
|
|
|
|
|
|
D2date = D2date.Substring(0, D2date.Length - 1);
|
|
|
|
|
|
D3date = D3date.Substring(0, D3date.Length - 1);
|
|
|
|
|
|
/*在这里判断是否需要循环D2date把标准上限标准下限合并成标准,内控上限内控下限合并成内控,如果需要循环之后生成一个新的D2date字符串*/
|
|
|
|
|
|
//创建一个Document类实例,并添加section
|
|
|
//Document document = new Document();
|
|
|
//Section section = document.AddSection();
|
|
|
|
|
|
Document doc = new Document();
|
|
|
doc.LoadFromFile(path);
|
|
|
|
|
|
//查找关键字符串文本
|
|
|
Section section = doc.Sections[0];
|
|
|
TextSelection selection = doc.FindString(TextName, true, true);
|
|
|
|
|
|
//获取关键字符串所在段落的索引
|
|
|
TextRange range = selection.GetAsOneRange();
|
|
|
Paragraph paragraph = range.OwnerParagraph;
|
|
|
Body body = paragraph.OwnerTextBody;
|
|
|
int index = body.ChildObjects.IndexOf(paragraph);
|
|
|
body.ChildObjects.Remove(paragraph);
|
|
|
|
|
|
|
|
|
//根据元素个数判断需要拆成几个表格
|
|
|
int num = D3date.Split(',').Count() / 13;
|
|
|
if (D3date.Split(',').Count() % 13 > 0)
|
|
|
{
|
|
|
num = num + 1;
|
|
|
}
|
|
|
//循环每个牌号
|
|
|
for (int j = 0; j < D1date.Split(',').Count(); j++)
|
|
|
{
|
|
|
|
|
|
//把一个表格拆成所需要的多个表格
|
|
|
for (int k = 0; k < num; k++)
|
|
|
{
|
|
|
//添加表格指定表格的行数和列数(2行,5列)
|
|
|
Table table = section.AddTable(true);
|
|
|
table.ResetCells(D2date.Split(',').Count() + 1, 15);
|
|
|
//把第一列从第一行到所有项目的所有列全部合并
|
|
|
table.ApplyVerticalMerge(0, 1, D2date.Split(',').Count());
|
|
|
//如果需要合并行使用下面的例子(把第一行的第一列到第三列合并)
|
|
|
//table.ApplyHorizontalMerge(0, 0, 2);
|
|
|
int D2Num = D2date.Split(',').Count();
|
|
|
//string NN = "牌号";
|
|
|
//获取单元格(第1行第1个单元格)并添加文本内容,设置字体字号颜色等(单元格中内容及个性化设置可以根据需要来进行调整)
|
|
|
//Encoding NN = System.Text.Encoding.GetEncoding("GB2312");
|
|
|
//TextRange range = table[0, 0].AddParagraph().AppendText("牌号");
|
|
|
range = table[0, 0].AddParagraph().AppendText("牌号");
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[0, 0].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[0, 0].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
|
|
|
//获取单元格(第1行第2个单元格)并添加文本
|
|
|
range = table[0, 1].AddParagraph().AppendText("元素");
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[0, 1].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[0, 1].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
|
|
|
int D3Num = 0;
|
|
|
//此处循环元素
|
|
|
for (int Q = 2; Q < 15; Q++)
|
|
|
{
|
|
|
D3Num = k * 9 + Q - 2;
|
|
|
//判断是否是最后一个表,如果是最后一个表只需要加载剩余的元素数据,其余的表格全部为"";
|
|
|
if (k == num - 1)
|
|
|
{
|
|
|
//用当前第几个表格乘与每个表格的元素个数加上当前循环的元素个数判断是否超过总元素个数如果超过给表格空如果没有超过则给对应的数据值
|
|
|
if (k * 13 + Q - 2 < D3date.Split(',').Count())
|
|
|
{
|
|
|
string MM = D3date.Split(',')[D3Num];
|
|
|
//获取单元格(第1行第Q个单元格)并添加文本
|
|
|
range = table[0, Q].AddParagraph().AppendText(MM); //D3date.Split(',')[D3Num]
|
|
|
range.CharacterFormat.FontName = "Times New Roman";
|
|
|
range.CharacterFormat.FontSize = 10;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[0, Q].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[0, Q].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
|
|
|
}
|
|
|
//else
|
|
|
//{
|
|
|
// //获取单元格(第1行第Q个单元格)并添加文本
|
|
|
// range = table[0, Q].AddParagraph().AppendText("");
|
|
|
// range.CharacterFormat.FontName = "Arial";
|
|
|
// range.CharacterFormat.FontSize = 12;
|
|
|
// range.CharacterFormat.TextColor = Color.Brown;
|
|
|
// range.CharacterFormat.Bold = true;
|
|
|
//}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string MM = D3date.Split(',')[D3Num];
|
|
|
//获取单元格(第1行第Q个单元格)并添加文本
|
|
|
range = table[0, Q].AddParagraph().AppendText(MM);//D3date.Split(',')[D3Num]
|
|
|
range.CharacterFormat.FontName = "Times New Roman";
|
|
|
range.CharacterFormat.FontSize = 10;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[0, Q].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[0, Q].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
}
|
|
|
}//循环表头结束
|
|
|
|
|
|
//这里循环行
|
|
|
for (int W = 0; W < D2Num; W++)
|
|
|
{
|
|
|
//因为牌号单元格合并了所以这里判断只有第一次循环的时候给牌号赋值
|
|
|
if (W == 0)
|
|
|
{
|
|
|
//获取单元格(第W+1行第1个单元格)并添加文本
|
|
|
range = table[W + 1, 0].AddParagraph().AppendText(D1date.Split(',')[j]);//D1date.Split(',')[j]
|
|
|
range.CharacterFormat.FontName = "Times New Roman";
|
|
|
range.CharacterFormat.FontSize = 10;
|
|
|
table[W + 1, 0].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[W + 1, 0].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
|
|
|
//range.CharacterFormat.TextColor = Color.Black;
|
|
|
//range.CharacterFormat.Bold = false;
|
|
|
}
|
|
|
|
|
|
string D2SS = D2date.Split(',')[W];
|
|
|
//获取单元格(第W+1行第2个单元格)并添加文本
|
|
|
range = table[W + 1, 1].AddParagraph().AppendText(D2SS);//D2date.Split(',')[W]
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[W + 1, 1].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[W + 1, 1].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
|
|
|
int d3Knum = 0;
|
|
|
//此处循环元素
|
|
|
for (int Q = 2; Q < 15; Q++)
|
|
|
{
|
|
|
d3Knum = k * 13 + Q - 2;
|
|
|
//判断是否是最后一个表,如果是最后一个表只需要加载剩余的元素数据,其余的表格全部为"";
|
|
|
if (k == num - 1)
|
|
|
{
|
|
|
|
|
|
/*用当前第几个表格乘与每个表格的元素个数加上当前循环的元素个数判断是否超过总元素个数如果超过给表格空如果没有超过则给对应的数据值*/
|
|
|
if (k * 13 + Q - 2 < D3date.Split(',').Count())
|
|
|
{
|
|
|
string D3names = D3 + "Text";
|
|
|
string D2names = D2 + "Text";
|
|
|
string sql = D3names + "='" + D3date.Split(',')[d3Knum] + "' and " + D2names + "='" + D2date.Split(',')[W] + "' and " + D1 + "='" + D1date.Split(',')[j] + "'";
|
|
|
string ds = data.Select(sql)[0]["SZ"].ToString();
|
|
|
//if (string.IsNullOrEmpty(ds))
|
|
|
//{
|
|
|
// ds = "W";
|
|
|
//}
|
|
|
//获取单元格(第W+1行第Q个单元格)并添加文本
|
|
|
range = table[W + 1, Q].AddParagraph().AppendText(ds);
|
|
|
//此处应该是元素对应的值
|
|
|
range.CharacterFormat.FontName = "Times New Roman";
|
|
|
range.CharacterFormat.FontSize = 10;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[W + 1, Q].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[W + 1, Q].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string D3names = D3 + "Text";
|
|
|
string D2names = D2 + "Text";
|
|
|
string sql = D3names + "='" + D3date.Split(',')[d3Knum] + "' and " + D2names + "='" + D2date.Split(',')[W] + "' and " + D1 + "='" + D1date.Split(',')[j] + "'";
|
|
|
string ds = data.Select(sql)[0]["SZ"].ToString();
|
|
|
//if (string.IsNullOrEmpty(ds))
|
|
|
//{
|
|
|
// ds = "W";
|
|
|
//}
|
|
|
// D2names == D2date.Split(',')[W] , D1 == D1date.Split(',')[j]
|
|
|
range = table[W + 1, Q].AddParagraph().AppendText(ds);//此处获取元素得SZ
|
|
|
//此处应该是元素对应的值
|
|
|
range.CharacterFormat.FontName = "Times New Roman";
|
|
|
range.CharacterFormat.FontSize = 10;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[W + 1, Q].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[W + 1, Q].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
}
|
|
|
}//循环元素值结束
|
|
|
|
|
|
}//循环行结束
|
|
|
table.TableFormat.HorizontalAlignment = RowAlignment.Center;//整个表格居中
|
|
|
//移除段落,插入表格
|
|
|
body.ChildObjects.Insert(index + k, table);
|
|
|
}//循环拆分表格结束
|
|
|
}
|
|
|
//保存文档
|
|
|
doc.SaveToFile(path, FileFormat.Doc);
|
|
|
BP.DA.Log.DebugWriteError("开始去除新3D文档水印。");
|
|
|
//Microsoft.Office.Interop.Word.Application
|
|
|
try
|
|
|
{
|
|
|
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
|
|
|
Microsoft.Office.Interop.Word.Document docs = null;
|
|
|
object unknow = Type.Missing;
|
|
|
app.Visible = true;
|
|
|
object file = path;
|
|
|
docs = app.Documents.Open(ref file, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow);
|
|
|
docs.Paragraphs[1].Range.Delete();
|
|
|
docs.SaveAs2(path);
|
|
|
docs.Close();
|
|
|
Process[] current = Process.GetProcesses();
|
|
|
//遍历与当前进程名称相同的进程列表
|
|
|
foreach (Process process in current)
|
|
|
{
|
|
|
//如果实例已经存在则kill当前进程
|
|
|
if (process.ProcessName.ToUpper().Equals("WINWORD"))
|
|
|
{
|
|
|
process.Kill(); break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
BP.DA.Log.DebugWriteError(ex.Message);
|
|
|
|
|
|
}
|
|
|
//docs.Paragraphs.Application;
|
|
|
|
|
|
|
|
|
//保存文档
|
|
|
//string path = "C:\\Users\\lenovo\\Desktop\\Table2.rtf";
|
|
|
//document.SaveToFile(path, FileFormat.Rtf);
|
|
|
//StreamReader read = new StreamReader(path, System.Text.Encoding.ASCII); // 文件流.
|
|
|
//rtf = read.ReadToEnd(); //读取完毕。
|
|
|
//read.Close(); // 关闭。
|
|
|
//int numssss = rtf.IndexOf("Evaluation ");
|
|
|
//string rtf1 = rtf.Substring(0, numssss);
|
|
|
//string rtf2 = rtf.Substring(numssss + 69, rtf.Length - numssss - 69);
|
|
|
//rtf = rtf1 + rtf2;
|
|
|
//byte[] inputBytes = Encoding.ASCII.GetBytes(rtf); //System.Convert.FromBase64String(rtf);
|
|
|
//FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
|
|
|
//fs.Write(inputBytes, 0, inputBytes.Length);
|
|
|
//fs.Close();
|
|
|
////Document replaceDocument = new Document("C:\\Users\\lenovo\\Desktop\\Table1.rtf");
|
|
|
//Document documents = new Document("C:\\Users\\lenovo\\Desktop\\管材类质量要点模板02.rtf");
|
|
|
|
|
|
////加载用于替换文本的文档
|
|
|
|
|
|
|
|
|
////使用该文档替换模板中的指定文本
|
|
|
//documents.Replace("<BP.3D.Frm_GCLZLYDHXCFB>", document, false, true);
|
|
|
//Section sectionS = documents.Sections[0];
|
|
|
//Table table1 = sectionS.Tables[1] as Table;
|
|
|
//table1.TableFormat.Borders.Horizontal.BorderType = Spire.Doc.Documents.BorderStyle.Dot;
|
|
|
//table1.TableFormat.Borders.Horizontal.LineWidth = 2.0f;
|
|
|
//table1.TableFormat.Borders.Horizontal.Color = Color.Black;
|
|
|
//保存文档
|
|
|
//documents.SaveToFile("C:\\Users\\lenovo\\Desktop\\Table3.rtf", FileFormat.Rtf);
|
|
|
|
|
|
//rtf = Cache.GetBillStr("Table2.rtf", false).Substring(0);
|
|
|
//System.Diagnostics.Process.Start("Table2.rtf");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 替换二维表单@BKGY工艺卡
|
|
|
/// </summary>
|
|
|
/// <param name="data">多维表单数据集</param>
|
|
|
/// <param name="D1">一级表头</param>
|
|
|
/// <param name="D2">二级表头</param>
|
|
|
/// <param name="D3">三级表头</param>
|
|
|
/// <param name="TextName">替换字符串</param>
|
|
|
/// <param name ="path"> 文件路径 </ param >
|
|
|
public void FORMDoc(DataTable data, string D1, String D2, String D3, string TextName, string path)
|
|
|
{
|
|
|
int TableNum = 16;//一行显示多少个元素
|
|
|
int TableNums = TableNum + 2;//显示多少列2表示签名加一列牌号和项目
|
|
|
string rtf = string.Empty;
|
|
|
if (data.Rows.Count > 0)
|
|
|
{
|
|
|
string D1date = "", D2date = "", D3date = "";
|
|
|
///循环拿到牌号,
|
|
|
///循环拿到项目,
|
|
|
///循环拿到元素
|
|
|
for (int i = 0; i < data.Rows.Count; i++)
|
|
|
{
|
|
|
//拿到牌号得数据
|
|
|
if (data.Rows[i][D1].ToString() != "-1")
|
|
|
{
|
|
|
bool d1dd = true;
|
|
|
foreach (var item in D1date.Split(','))
|
|
|
{
|
|
|
if (item == data.Rows[i][D1].ToString())
|
|
|
{
|
|
|
d1dd = false; break;
|
|
|
}
|
|
|
}
|
|
|
if (d1dd) { D1date = D1date + data.Rows[i][D1].ToString() + ","; }
|
|
|
|
|
|
}
|
|
|
//拿到项目名称
|
|
|
if (data.Rows[i][D2].ToString() != "-1")
|
|
|
{
|
|
|
bool d1dds = true;
|
|
|
foreach (var item in D2date.Split(','))
|
|
|
{
|
|
|
if (item == data.Rows[i][D2 + "Text"].ToString())
|
|
|
{
|
|
|
d1dds = false; break;
|
|
|
}
|
|
|
}
|
|
|
if (d1dds) { D2date = D2date + data.Rows[i][D2 + "Text"].ToString() + ","; }
|
|
|
}
|
|
|
//if (data.Rows[i][D3].ToString() != "-1")
|
|
|
//{
|
|
|
// if (!D3date.Contains(data.Rows[i][D3].ToString()))
|
|
|
// {
|
|
|
// 拿到每一个元素是否都有值
|
|
|
// D3date = D3date + data.Rows[i][D3].ToString() + ",";
|
|
|
// }
|
|
|
//}
|
|
|
}
|
|
|
if (D3.Length > 0)
|
|
|
{
|
|
|
D3 = D3.Substring(0, D3.Length - 1);
|
|
|
}
|
|
|
//循环拿到每个元素得所有项判断是否都有值
|
|
|
for (int i = 0; i < D3.Split(',').Count(); i++)
|
|
|
{
|
|
|
bool D3tite = false;
|
|
|
for (int j = 0; j < data.Rows.Count; j++)
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(data.Rows[j][D3.Split(',')[i].ToString()].ToString()) && data.Rows[j][D3.Split(',')[i].ToString()].ToString() != "/")
|
|
|
{
|
|
|
D3tite = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (D3tite)
|
|
|
{
|
|
|
string name = D3.Split(',')[i].ToString();
|
|
|
if (name.Length > 1)
|
|
|
{
|
|
|
name = name.Substring(0, 1).ToUpper() + name.Substring(1).ToLower();
|
|
|
#region 显示元素替换 20231229
|
|
|
if (name == "Asys")
|
|
|
{
|
|
|
name = "As";
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
//如果都没有值择把这个元素移除
|
|
|
D3date = D3date + name + ","; //D3.Split(',')[i].ToString() + ",";
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (D2date.Length > 0 && D3date.Length > 0)
|
|
|
{
|
|
|
if (D1date.Length > 0)
|
|
|
{
|
|
|
D1date = D1date.Substring(0, D1date.Length - 1);
|
|
|
}
|
|
|
|
|
|
D2date = D2date.Substring(0, D2date.Length - 1);
|
|
|
|
|
|
D3date = D3date.Substring(0, D3date.Length - 1);
|
|
|
|
|
|
/*在这里判断是否需要循环D2date把标准上限标准下限合并成标准,内控上限内控下限合并成内控,如果需要循环之后生成一个新的D2date字符串*/
|
|
|
|
|
|
//创建一个Document类实例,并添加section
|
|
|
//Document document = new Document();
|
|
|
//Section section = document.AddSection();
|
|
|
|
|
|
Document doc = new Document();
|
|
|
doc.LoadFromFile(path);
|
|
|
|
|
|
//查找关键字符串文本
|
|
|
Section section = doc.Sections[0];
|
|
|
TextSelection selection = doc.FindString(TextName, true, true);
|
|
|
|
|
|
//获取关键字符串所在段落的索引
|
|
|
TextRange range = selection.GetAsOneRange();
|
|
|
Paragraph paragraph = range.OwnerParagraph;
|
|
|
Body body = paragraph.OwnerTextBody;
|
|
|
int index = body.ChildObjects.IndexOf(paragraph);
|
|
|
body.ChildObjects.Remove(paragraph);
|
|
|
|
|
|
if (D1date.Length == 0)
|
|
|
{
|
|
|
TableNum = TableNum + 1;
|
|
|
}
|
|
|
//根据元素个数判断需要拆成几个表格
|
|
|
int num = D3date.Split(',').Count() / TableNum;
|
|
|
if (D3date.Split(',').Count() % TableNum > 0)
|
|
|
{
|
|
|
num = num + 1;
|
|
|
}
|
|
|
int D1dateNum = D1date.Split(',').Count();
|
|
|
if (D1dateNum == 0)
|
|
|
{
|
|
|
D1dateNum = 1;
|
|
|
}
|
|
|
//循环每个牌号
|
|
|
for (int j = 0; j < D1dateNum; j++)
|
|
|
{
|
|
|
int tanum = 2;
|
|
|
//元素从第几列开始
|
|
|
|
|
|
//把一个表格拆成所需要的多个表格
|
|
|
for (int k = 0; k < num; k++)
|
|
|
{
|
|
|
//添加表格指定表格的行数和列数(2行,5列)
|
|
|
Table table = section.AddTable(true);
|
|
|
//在此次判断是否是最后一个表格,如果是根据实际剩余得元素个数生成列
|
|
|
if (num == 1)
|
|
|
{
|
|
|
int TableNumsS = TableNums- (TableNum - D3date.Split(',').Count());
|
|
|
table.ResetCells(D2date.Split(',').Count() + 1, TableNumsS);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
table.ResetCells(D2date.Split(',').Count() + 1, TableNums);
|
|
|
}
|
|
|
|
|
|
|
|
|
//把第一列从第一行到所有项目的所有列全部合并
|
|
|
//如果需要合并行使用下面的例子(把第一行的第一列到第三列合并)
|
|
|
//table.ApplyHorizontalMerge(0, 0, 2);
|
|
|
int D2Num = D2date.Split(',').Count();
|
|
|
//string NN = "牌号";
|
|
|
//获取单元格(第1行第1个单元格)并添加文本内容,设置字体字号颜色等(单元格中内容及个性化设置可以根据需要来进行调整)
|
|
|
//Encoding NN = System.Text.Encoding.GetEncoding("GB2312");
|
|
|
//TextRange range = table[0, 0].AddParagraph().AppendText("牌号");
|
|
|
if (!string.IsNullOrEmpty(D1date))
|
|
|
{
|
|
|
table.ApplyVerticalMerge(0, 1, D2date.Split(',').Count());
|
|
|
range = table[0, 0].AddParagraph().AppendText("牌号");
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[0, 0].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[0, 0].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
|
|
|
//获取单元格(第1行第2个单元格)并添加文本
|
|
|
range = table[0, 1].AddParagraph().AppendText("元素");
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[0, 1].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[0, 1].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
tanum = 1;
|
|
|
//获取单元格(第1行第2个单元格)并添加文本
|
|
|
range = table[0, 0].AddParagraph().AppendText("元素");
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[0, 0].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[0, 0].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
}
|
|
|
|
|
|
|
|
|
int D3Num = 0;
|
|
|
//此处循环元素
|
|
|
for (int Q = tanum; Q < TableNums; Q++)
|
|
|
{
|
|
|
D3Num = k * TableNum + Q - tanum;
|
|
|
//判断是否是最后一个表,如果是最后一个表只需要加载剩余的元素数据,其余的表格全部为"";
|
|
|
if (k == num - 1)
|
|
|
{
|
|
|
//用当前第几个表格乘与每个表格的元素个数加上当前循环的元素个数判断是否超过总元素个数如果超过给表格空如果没有超过则给对应的数据值
|
|
|
if (k * TableNum + Q - tanum < D3date.Split(',').Count())
|
|
|
{
|
|
|
string MM = D3date.Split(',')[D3Num];
|
|
|
//获取单元格(第1行第Q个单元格)并添加文本
|
|
|
range = table[0, Q].AddParagraph().AppendText(MM); //D3date.Split(',')[D3Num]
|
|
|
range.CharacterFormat.FontName = "Times New Roman";
|
|
|
range.CharacterFormat.FontSize = 10;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[0, Q].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[0, Q].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
|
|
|
}
|
|
|
//else
|
|
|
//{
|
|
|
// //获取单元格(第1行第Q个单元格)并添加文本
|
|
|
// range = table[0, Q].AddParagraph().AppendText("");
|
|
|
// range.CharacterFormat.FontName = "Arial";
|
|
|
// range.CharacterFormat.FontSize = 12;
|
|
|
// range.CharacterFormat.TextColor = Color.Brown;
|
|
|
// range.CharacterFormat.Bold = true;
|
|
|
//}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string MM = D3date.Split(',')[D3Num];
|
|
|
//获取单元格(第1行第Q个单元格)并添加文本
|
|
|
range = table[0, Q].AddParagraph().AppendText(MM);//D3date.Split(',')[D3Num]
|
|
|
range.CharacterFormat.FontName = "Times New Roman";
|
|
|
range.CharacterFormat.FontSize = 10;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[0, Q].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[0, Q].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
}
|
|
|
}//循环表头结束
|
|
|
|
|
|
//这里循环行
|
|
|
for (int W = 0; W < D2Num; W++)
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(D1date))
|
|
|
{
|
|
|
//因为牌号单元格合并了所以这里判断只有第一次循环的时候给牌号赋值
|
|
|
if (W == 0)
|
|
|
{
|
|
|
//获取单元格(第W+1行第1个单元格)并添加文本
|
|
|
range = table[W + 1, 0].AddParagraph().AppendText(D1date.Split(',')[j]);//D1date.Split(',')[j]
|
|
|
range.CharacterFormat.FontName = "Times New Roman";
|
|
|
range.CharacterFormat.FontSize = 10;
|
|
|
table[W + 1, 0].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[W + 1, 0].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
|
|
|
//range.CharacterFormat.TextColor = Color.Black;
|
|
|
//range.CharacterFormat.Bold = false;
|
|
|
}
|
|
|
|
|
|
string D2SS = D2date.Split(',')[W];
|
|
|
//获取单元格(第W+1行第2个单元格)并添加文本
|
|
|
range = table[W + 1, 1].AddParagraph().AppendText(D2SS);//D2date.Split(',')[W]
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[W + 1, 1].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[W + 1, 1].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string D2SS = D2date.Split(',')[W];
|
|
|
//获取单元格(第W+1行第2个单元格)并添加文本
|
|
|
range = table[W + 1, 0].AddParagraph().AppendText(D2SS);//D2date.Split(',')[W]
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[W + 1, 0].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[W + 1, 0].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
}
|
|
|
int d3Knum = 0;
|
|
|
//此处循环元素
|
|
|
for (int Q = tanum; Q < TableNums; Q++)
|
|
|
{
|
|
|
d3Knum = k * TableNum + Q - tanum;
|
|
|
//判断是否是最后一个表,如果是最后一个表只需要加载剩余的元素数据,其余的表格全部为"";
|
|
|
if (k == num - 1)
|
|
|
{
|
|
|
|
|
|
/*用当前第几个表格乘与每个表格的元素个数加上当前循环的元素个数判断是否超过总元素个数如果超过给表格空如果没有超过则给对应的数据值*/
|
|
|
if (k * TableNum + Q - tanum < D3date.Split(',').Count())
|
|
|
{
|
|
|
string D2names = D2 + "Text";
|
|
|
string sql = D2names + "='" + D2date.Split(',')[W] + "' ";
|
|
|
if (!string.IsNullOrEmpty(D1date) && D1date.Split(',').Count() > 1)
|
|
|
{
|
|
|
sql += "and " + D1 + "='" + D1date.Split(',')[j] + "'";
|
|
|
}
|
|
|
string named3 = D3date.Split(',')[d3Knum].ToString();
|
|
|
#region (无牌号)赋值时换回元素 20231229
|
|
|
if (named3 == "As")
|
|
|
{
|
|
|
named3 = "ASYS";
|
|
|
}
|
|
|
#endregion
|
|
|
int ss = data.Select(sql).Count();
|
|
|
string ds = data.Select(sql)[0][named3].ToString();
|
|
|
//if (string.IsNullOrEmpty(ds))
|
|
|
//{
|
|
|
// ds = "W";
|
|
|
//}
|
|
|
//获取单元格(第W+1行第Q个单元格)并添加文本
|
|
|
range = table[W + 1, Q].AddParagraph().AppendText(ds);
|
|
|
//此处应该是元素对应的值
|
|
|
range.CharacterFormat.FontName = "Times New Roman";
|
|
|
range.CharacterFormat.FontSize = 10;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[W + 1, Q].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[W + 1, Q].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string ds = "";
|
|
|
string D2names = D2 + "Text";
|
|
|
string sql = D2names + "='" + D2date.Split(',')[W] + "' ";
|
|
|
if (!string.IsNullOrEmpty(D1date) && D1date.Split(',').Count() > 1)
|
|
|
{
|
|
|
sql += "and " + D1 + "='" + D1date.Split(',')[j] + "'";
|
|
|
}
|
|
|
#region (有牌号)赋值时换回元素 20231229
|
|
|
if (D3date.Split(',')[d3Knum].ToString() == "As")
|
|
|
{
|
|
|
string name = "ASYS";
|
|
|
ds = data.Select(sql)[0][name].ToString();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ds = data.Select(sql)[0][D3date.Split(',')[d3Knum].ToString()].ToString();
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
//if (string.IsNullOrEmpty(ds))
|
|
|
//{
|
|
|
// ds = "W";
|
|
|
//}
|
|
|
// D2names == D2date.Split(',')[W] , D1 == D1date.Split(',')[j]
|
|
|
range = table[W + 1, Q].AddParagraph().AppendText(ds);//此处获取元素得SZ
|
|
|
//此处应该是元素对应的值
|
|
|
range.CharacterFormat.FontName = "Times New Roman";
|
|
|
range.CharacterFormat.FontSize = 10;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[W + 1, Q].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[W + 1, Q].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
}
|
|
|
}//循环元素值结束
|
|
|
|
|
|
}//循环行结束
|
|
|
table.TableFormat.HorizontalAlignment = RowAlignment.Center;//整个表格居中
|
|
|
//移除段落,插入表格
|
|
|
body.ChildObjects.Insert(index + k, table);
|
|
|
}//循环拆分表格结束
|
|
|
}
|
|
|
//保存文档
|
|
|
doc.SaveToFile(path, FileFormat.Doc);
|
|
|
BP.DA.Log.DebugWriteError("开始去除新3D文档水印。");
|
|
|
//Microsoft.Office.Interop.Word.Application
|
|
|
try
|
|
|
{
|
|
|
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
|
|
|
Microsoft.Office.Interop.Word.Document docs = null;
|
|
|
object unknow = Type.Missing;
|
|
|
app.Visible = true;
|
|
|
object file = path;
|
|
|
docs = app.Documents.Open(ref file, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow);
|
|
|
docs.Paragraphs[1].Range.Delete();
|
|
|
docs.SaveAs2(path);
|
|
|
docs.Close();
|
|
|
Process[] current = Process.GetProcesses();
|
|
|
//遍历与当前进程名称相同的进程列表
|
|
|
foreach (Process process in current)
|
|
|
{
|
|
|
//如果实例已经存在则kill当前进程
|
|
|
if (process.ProcessName.ToUpper().Equals("WINWORD"))
|
|
|
{
|
|
|
process.Kill(); break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
BP.DA.Log.DebugWriteError(ex.Message);
|
|
|
|
|
|
}
|
|
|
//docs.Paragraphs.Application;
|
|
|
|
|
|
|
|
|
//保存文档
|
|
|
//string path = "C:\\Users\\lenovo\\Desktop\\Table2.rtf";
|
|
|
//document.SaveToFile(path, FileFormat.Rtf);
|
|
|
//StreamReader read = new StreamReader(path, System.Text.Encoding.ASCII); // 文件流.
|
|
|
//rtf = read.ReadToEnd(); //读取完毕。
|
|
|
//read.Close(); // 关闭。
|
|
|
//int numssss = rtf.IndexOf("Evaluation ");
|
|
|
//string rtf1 = rtf.Substring(0, numssss);
|
|
|
//string rtf2 = rtf.Substring(numssss + 69, rtf.Length - numssss - 69);
|
|
|
//rtf = rtf1 + rtf2;
|
|
|
//byte[] inputBytes = Encoding.ASCII.GetBytes(rtf); //System.Convert.FromBase64String(rtf);
|
|
|
//FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
|
|
|
//fs.Write(inputBytes, 0, inputBytes.Length);
|
|
|
//fs.Close();
|
|
|
////Document replaceDocument = new Document("C:\\Users\\lenovo\\Desktop\\Table1.rtf");
|
|
|
//Document documents = new Document("C:\\Users\\lenovo\\Desktop\\管材类质量要点模板02.rtf");
|
|
|
|
|
|
////加载用于替换文本的文档
|
|
|
|
|
|
|
|
|
////使用该文档替换模板中的指定文本
|
|
|
//documents.Replace("<BP.3D.Frm_GCLZLYDHXCFB>", document, false, true);
|
|
|
//Section sectionS = documents.Sections[0];
|
|
|
//Table table1 = sectionS.Tables[1] as Table;
|
|
|
//table1.TableFormat.Borders.Horizontal.BorderType = Spire.Doc.Documents.BorderStyle.Dot;
|
|
|
//table1.TableFormat.Borders.Horizontal.LineWidth = 2.0f;
|
|
|
//table1.TableFormat.Borders.Horizontal.Color = Color.Black;
|
|
|
//保存文档
|
|
|
//documents.SaveToFile("C:\\Users\\lenovo\\Desktop\\Table3.rtf", FileFormat.Rtf);
|
|
|
|
|
|
//rtf = Cache.GetBillStr("Table2.rtf", false).Substring(0);
|
|
|
//System.Diagnostics.Process.Start("Table2.rtf");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 替换二维表单@BKGY工艺卡项目不固定
|
|
|
/// </summary>
|
|
|
/// <param name="data">多维表单数据集</param>
|
|
|
/// <param name="D1">一级表头</param>
|
|
|
/// <param name="D2">二级表头</param>
|
|
|
/// <param name="D3">三级表头</param>
|
|
|
/// <param name="TextName">替换字符串</param>
|
|
|
/// <param name ="path"> 文件路径 </ param >
|
|
|
public void FORMDocs(DataTable data, string D1, String D2, String D3, string TextName, string path)
|
|
|
{
|
|
|
int TableNum = 13;//一行显示多少个元素
|
|
|
int TableNums = TableNum + 2;//显示多少列2表示签名加一列牌号和项目
|
|
|
string rtf = string.Empty;
|
|
|
if (data.Rows.Count > 0)
|
|
|
{
|
|
|
string D1date = "", D2date = "", D3date = "";
|
|
|
///循环拿到牌号,
|
|
|
///循环拿到项目,
|
|
|
///循环拿到元素
|
|
|
for (int i = 0; i < data.Rows.Count; i++)
|
|
|
{
|
|
|
//拿到牌号得数据
|
|
|
if (data.Rows[i][D1].ToString() != "-1")
|
|
|
{
|
|
|
bool d1dd = true;
|
|
|
foreach (var item in D1date.Split(','))
|
|
|
{
|
|
|
if (item == data.Rows[i][D1].ToString())
|
|
|
{
|
|
|
d1dd = false; break;
|
|
|
}
|
|
|
}
|
|
|
if (d1dd) { D1date = D1date + data.Rows[i][D1].ToString() + ","; }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (D3.Length > 0)
|
|
|
{
|
|
|
D3 = D3.Substring(0, D3.Length - 1);
|
|
|
}
|
|
|
//循环拿到每个元素得所有项判断是否都有值
|
|
|
for (int i = 0; i < D3.Split(',').Count(); i++)
|
|
|
{
|
|
|
bool D3tite = false;
|
|
|
for (int j = 0; j < data.Rows.Count; j++)
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(data.Rows[j][D3.Split(',')[i].ToString()].ToString()) && data.Rows[j][D3.Split(',')[i].ToString()].ToString() != "/")
|
|
|
{
|
|
|
D3tite = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (D3tite)
|
|
|
{
|
|
|
string name = D3.Split(',')[i].ToString();
|
|
|
if (name.Length > 1)
|
|
|
{
|
|
|
name = name.Substring(0, 1).ToUpper() + name.Substring(1).ToLower();
|
|
|
#region 显示元素替换 20231229
|
|
|
if (name == "Asys")
|
|
|
{
|
|
|
name = "As";
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
//如果都没有值择把这个元素移除
|
|
|
D3date = D3date + name + ","; //D3.Split(',')[i].ToString() + ",";
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (D3date.Length > 0)
|
|
|
{
|
|
|
if (D1date.Length > 0)
|
|
|
{
|
|
|
D1date = D1date.Substring(0, D1date.Length - 1);
|
|
|
}
|
|
|
|
|
|
D3date = D3date.Substring(0, D3date.Length - 1);
|
|
|
|
|
|
Document doc = new Document();
|
|
|
doc.LoadFromFile(path);
|
|
|
|
|
|
//查找关键字符串文本
|
|
|
Section section = doc.Sections[0];
|
|
|
TextSelection selection = doc.FindString(TextName, true, true);
|
|
|
|
|
|
//获取关键字符串所在段落的索引
|
|
|
TextRange range = selection.GetAsOneRange();
|
|
|
Paragraph paragraph = range.OwnerParagraph;
|
|
|
Body body = paragraph.OwnerTextBody;
|
|
|
int index = body.ChildObjects.IndexOf(paragraph);
|
|
|
body.ChildObjects.Remove(paragraph);
|
|
|
|
|
|
if (D1date.Length == 0)
|
|
|
{
|
|
|
TableNum = TableNum + 1;
|
|
|
}
|
|
|
//根据元素个数判断需要拆成几个表格
|
|
|
int num = D3date.Split(',').Count() / TableNum;
|
|
|
if (D3date.Split(',').Count() % TableNum > 0)
|
|
|
{
|
|
|
num = num + 1;
|
|
|
}
|
|
|
int D1dateNum = D1date.Split(',').Count();
|
|
|
if (D1dateNum == 0)
|
|
|
{
|
|
|
D1dateNum = 1;
|
|
|
}
|
|
|
int rows = 0;
|
|
|
int d2DATANUM = 0;//记录当前牌号数据条数
|
|
|
int tanum = 2; //元素从第几列开始
|
|
|
|
|
|
//把一个表格拆成所需要的多个表格
|
|
|
for (int k = 0; k < num; k++)
|
|
|
{
|
|
|
rows = 0;
|
|
|
int row = 0;
|
|
|
//查询当前牌号又多少行--D2date
|
|
|
|
|
|
//添加表格指定表格的行数和列数(2行,5列)
|
|
|
Table table = section.AddTable(true);
|
|
|
//在此次判断是否是最后一个表格,如果是根据实际剩余得元素个数生成列
|
|
|
if (num == 1)
|
|
|
{
|
|
|
int TableNumsS = TableNums - (TableNum - D3date.Split(',').Count());
|
|
|
table.ResetCells(data.Rows.Count + 1, TableNumsS);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
table.ResetCells(data.Rows.Count + 1, TableNums);
|
|
|
}
|
|
|
////添加表格指定表格的行数和列数(2行,5列)
|
|
|
//Table table = section.AddTable(true);
|
|
|
////创建一个指定行和列得表格
|
|
|
//table.ResetCells(data.Rows.Count + 1, TableNums);
|
|
|
|
|
|
//循环牌号
|
|
|
//循环每个牌号
|
|
|
for (int j = 0; j < D1dateNum; j++)
|
|
|
{
|
|
|
|
|
|
D2date = "";
|
|
|
|
|
|
if (j == 0)
|
|
|
{
|
|
|
row = 1;
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
row = rows + 1;
|
|
|
}
|
|
|
string sqls = String.Empty;
|
|
|
if (!string.IsNullOrEmpty(D1date) && D1date.Split(',').Count() > 1)
|
|
|
{
|
|
|
sqls = D1 + "='" + D1date.Split(',')[j] + "'";
|
|
|
}
|
|
|
//拿到当前牌号得数据条数
|
|
|
d2DATANUM = 0;
|
|
|
d2DATANUM = data.Select(sqls).Count();
|
|
|
////拿到项目名称
|
|
|
if (d2DATANUM > 0)
|
|
|
{
|
|
|
for (int i = 0; i < data.Select(sqls).Count(); i++)
|
|
|
{
|
|
|
bool d1dds = true;
|
|
|
foreach (var item in D2date.Split(','))
|
|
|
{
|
|
|
if (item == data.Select(sqls)[i][D2 + "Text"].ToString())
|
|
|
{
|
|
|
d1dds = false; break;
|
|
|
}
|
|
|
}
|
|
|
if (d1dds) { D2date = D2date + data.Select(sqls)[i][D2 + "Text"].ToString() + ","; }
|
|
|
}
|
|
|
}
|
|
|
if (D2date.Length > 0)
|
|
|
{
|
|
|
D2date = D2date.Substring(0, D2date.Length - 1);
|
|
|
}
|
|
|
int D2Num = D2date.Split(',').Count();
|
|
|
if (j == 0)
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(D1date))
|
|
|
{
|
|
|
//table.ApplyVerticalMerge(0, 1, D2date.Split(',').Count());
|
|
|
range = table[0, 0].AddParagraph().AppendText("牌号");
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[0, 0].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[0, 0].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
|
|
|
//获取单元格(第1行第2个单元格)并添加文本
|
|
|
range = table[0, 1].AddParagraph().AppendText("元素");
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[0, 1].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[0, 1].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
tanum = 1;
|
|
|
//获取单元格(第1行第2个单元格)并添加文本
|
|
|
range = table[0, 0].AddParagraph().AppendText("元素");
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[0, 0].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[0, 0].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
}
|
|
|
|
|
|
|
|
|
int D3Num = 0;
|
|
|
//此处循环元素
|
|
|
for (int Q = tanum; Q < TableNums; Q++)
|
|
|
{
|
|
|
D3Num = k * TableNum + Q - tanum;
|
|
|
//判断是否是最后一个表,如果是最后一个表只需要加载剩余的元素数据,其余的表格全部为"";
|
|
|
if (k == num - 1)
|
|
|
{
|
|
|
//用当前第几个表格乘与每个表格的元素个数加上当前循环的元素个数判断是否超过总元素个数如果超过给表格空如果没有超过则给对应的数据值
|
|
|
if (k * TableNum + Q - tanum < D3date.Split(',').Count())
|
|
|
{
|
|
|
string MM = D3date.Split(',')[D3Num];
|
|
|
//获取单元格(第1行第Q个单元格)并添加文本
|
|
|
range = table[0, Q].AddParagraph().AppendText(MM); //D3date.Split(',')[D3Num]
|
|
|
range.CharacterFormat.FontName = "Times New Roman";
|
|
|
range.CharacterFormat.FontSize = 10;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[0, Q].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[0, Q].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string MM = D3date.Split(',')[D3Num];
|
|
|
//获取单元格(第1行第Q个单元格)并添加文本
|
|
|
range = table[0, Q].AddParagraph().AppendText(MM);//D3date.Split(',')[D3Num]
|
|
|
range.CharacterFormat.FontName = "Times New Roman";
|
|
|
range.CharacterFormat.FontSize = 10;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[0, Q].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[0, Q].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
}
|
|
|
}//循环表头结束
|
|
|
}
|
|
|
|
|
|
//这里循环行
|
|
|
for (int W = 0; W < D2Num; W++)
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(D1date))
|
|
|
{
|
|
|
//因为牌号单元格合并了所以这里判断只有第一次循环的时候给牌号赋值
|
|
|
if (W == 0)
|
|
|
{
|
|
|
int merge = D2date.Split(',').Count();
|
|
|
if (row > 1)
|
|
|
{
|
|
|
merge = row - 1 + merge;
|
|
|
}
|
|
|
|
|
|
table.ApplyVerticalMerge(0, row, merge);
|
|
|
//获取单元格(第W+1行第1个单元格)并添加文本
|
|
|
range = table[row, 0].AddParagraph().AppendText(D1date.Split(',')[j]);//D1date.Split(',')[j]
|
|
|
range.CharacterFormat.FontName = "Times New Roman";
|
|
|
range.CharacterFormat.FontSize = 9;
|
|
|
table[row, 0].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[row, 0].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
}
|
|
|
|
|
|
string D2SS = D2date.Split(',')[W];
|
|
|
//获取单元格(第W+1行第2个单元格)并添加文本
|
|
|
range = table[row, 1].AddParagraph().AppendText(D2SS);//D2date.Split(',')[W]
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[row, 1].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[row, 1].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
//row = row + 1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string D2SS = D2date.Split(',')[W];
|
|
|
//获取单元格(第W+1行第2个单元格)并添加文本
|
|
|
range = table[row, 0].AddParagraph().AppendText(D2SS);//D2date.Split(',')[W]
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[row, 0].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[row, 0].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
//row = row + 1;
|
|
|
}
|
|
|
int d3Knum = 0;
|
|
|
//此处循环元素
|
|
|
for (int Q = tanum; Q < TableNums; Q++)
|
|
|
{
|
|
|
d3Knum = k * TableNum + Q - tanum;
|
|
|
//判断是否是最后一个表,如果是最后一个表只需要加载剩余的元素数据,其余的表格全部为"";
|
|
|
if (k == num - 1)
|
|
|
{
|
|
|
|
|
|
/*用当前第几个表格乘与每个表格的元素个数加上当前循环的元素个数判断是否超过总元素个数如果超过给表格空如果没有超过则给对应的数据值*/
|
|
|
if (k * TableNum + Q - tanum < D3date.Split(',').Count())
|
|
|
{
|
|
|
string D2names = D2 + "Text";
|
|
|
string sql = D2names + "='" + D2date.Split(',')[W] + "' ";
|
|
|
if (!string.IsNullOrEmpty(D1date) && D1date.Split(',').Count() > 1)
|
|
|
{
|
|
|
sql += "and " + D1 + "='" + D1date.Split(',')[j] + "'";
|
|
|
}
|
|
|
string named3 = D3date.Split(',')[d3Knum].ToString();
|
|
|
#region (无牌号)赋值时换回元素 20231229
|
|
|
if (named3 == "As")
|
|
|
{
|
|
|
named3 = "ASYS";
|
|
|
}
|
|
|
#endregion
|
|
|
int ss = data.Select(sql).Count();
|
|
|
string ds = data.Select(sql)[0][named3].ToString();
|
|
|
//if (string.IsNullOrEmpty(ds))
|
|
|
//{
|
|
|
// ds = "W";
|
|
|
//}
|
|
|
//获取单元格(第W+1行第Q个单元格)并添加文本
|
|
|
range = table[row, Q].AddParagraph().AppendText(ds);
|
|
|
//此处应该是元素对应的值
|
|
|
range.CharacterFormat.FontName = "Times New Roman";
|
|
|
range.CharacterFormat.FontSize = 10;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[row, Q].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[row, Q].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string ds = "";
|
|
|
string D2names = D2 + "Text";
|
|
|
string sql = D2names + "='" + D2date.Split(',')[W] + "' ";
|
|
|
if (!string.IsNullOrEmpty(D1date) && D1date.Split(',').Count() > 1)
|
|
|
{
|
|
|
sql += "and " + D1 + "='" + D1date.Split(',')[j] + "'";
|
|
|
}
|
|
|
#region (有牌号)赋值时换回元素 20231229
|
|
|
if (D3date.Split(',')[d3Knum].ToString() == "As")
|
|
|
{
|
|
|
string name = "ASYS";
|
|
|
ds = data.Select(sql)[0][name].ToString();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ds = data.Select(sql)[0][D3date.Split(',')[d3Knum].ToString()].ToString();
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
range = table[row, Q].AddParagraph().AppendText(ds);//此处获取元素得SZ
|
|
|
//此处应该是元素对应的值
|
|
|
range.CharacterFormat.FontName = "Times New Roman";
|
|
|
range.CharacterFormat.FontSize = 10;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[row, Q].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[row, Q].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
}
|
|
|
}//循环元素值结束
|
|
|
row = row + 1;
|
|
|
|
|
|
}//循环行结束
|
|
|
|
|
|
rows = rows + d2DATANUM;
|
|
|
}//循环牌号结束
|
|
|
|
|
|
table.TableFormat.HorizontalAlignment = RowAlignment.Center;//整个表格居中
|
|
|
//移除段落,插入表格
|
|
|
body.ChildObjects.Insert(index + k, table);
|
|
|
|
|
|
}//循环拆分表格结束
|
|
|
//保存文档
|
|
|
doc.SaveToFile(path, FileFormat.Doc);
|
|
|
BP.DA.Log.DebugWriteError("开始去除新3D文档水印。");
|
|
|
//Microsoft.Office.Interop.Word.Application
|
|
|
try
|
|
|
{
|
|
|
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
|
|
|
Microsoft.Office.Interop.Word.Document docs = null;
|
|
|
object unknow = Type.Missing;
|
|
|
app.Visible = true;
|
|
|
object file = path;
|
|
|
docs = app.Documents.Open(ref file, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow);
|
|
|
docs.Paragraphs[1].Range.Delete();
|
|
|
docs.SaveAs2(path);
|
|
|
docs.Close();
|
|
|
Process[] current = Process.GetProcesses();
|
|
|
//遍历与当前进程名称相同的进程列表
|
|
|
foreach (Process process in current)
|
|
|
{
|
|
|
//如果实例已经存在则kill当前进程
|
|
|
if (process.ProcessName.ToUpper().Equals("WINWORD"))
|
|
|
{
|
|
|
process.Kill(); break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
BP.DA.Log.DebugWriteError(ex.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
#region
|
|
|
/// <summary>
|
|
|
/// 替换二维表单@BKGY质量要点
|
|
|
/// </summary>
|
|
|
/// <param name="data">多维表单数据集</param>
|
|
|
/// <param name="D1">一级表头</param>
|
|
|
/// <param name="D2">二级表头</param>
|
|
|
/// <param name="D3">三级表头</param>
|
|
|
/// <param name="D4">四级表头</param>
|
|
|
/// <param name="TextName">替换字符串</param>
|
|
|
/// <param name ="path"> 文件路径 </ param >
|
|
|
public void ZLYDFORMDoc(DataTable data, string D1, string D2, string D3, string D4, string TextName, string path)
|
|
|
{
|
|
|
int TableNum = 13;//一行显示多少个元素
|
|
|
int TableNums = TableNum + 3;//显示多少列2表示签名加一列牌号、坯型和项目
|
|
|
string rtf = string.Empty;
|
|
|
if (data.Rows.Count > 0)
|
|
|
{
|
|
|
string D1date = "", D2date = "", D3date = "", D4date="";
|
|
|
///循环拿到牌号,
|
|
|
///循环拿到项目,
|
|
|
///循环拿到元素
|
|
|
for (int i = 0; i < data.Rows.Count; i++)
|
|
|
{
|
|
|
//拿到牌号得数据
|
|
|
if (data.Rows[i][D1].ToString() != "-1")
|
|
|
{
|
|
|
bool d1dd = true;
|
|
|
foreach (var item in D1date.Split(','))
|
|
|
{
|
|
|
if (item == data.Rows[i][D1].ToString())
|
|
|
{
|
|
|
d1dd = false; break;
|
|
|
}
|
|
|
}
|
|
|
if (d1dd) { D1date = D1date + data.Rows[i][D1].ToString() + ","; }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (D3.Length > 0)
|
|
|
{
|
|
|
D3 = D3.Substring(0, D3.Length - 1);
|
|
|
}
|
|
|
//循环拿到每个元素得所有项判断是否都有值
|
|
|
for (int i = 0; i < D3.Split(',').Count(); i++)
|
|
|
{
|
|
|
bool D3tite = false;
|
|
|
for (int j = 0; j < data.Rows.Count; j++)
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(data.Rows[j][D3.Split(',')[i].ToString()].ToString()) && data.Rows[j][D3.Split(',')[i].ToString()].ToString() != "/")
|
|
|
{
|
|
|
D3tite = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (D3tite)
|
|
|
{
|
|
|
string name = D3.Split(',')[i].ToString();
|
|
|
if (name.Length > 1)
|
|
|
{
|
|
|
name = name.Substring(0, 1).ToUpper() + name.Substring(1).ToLower();
|
|
|
#region 显示元素替换 20231229
|
|
|
if (name == "Asys")
|
|
|
{
|
|
|
name = "As";
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
//如果都没有值择把这个元素移除
|
|
|
D3date = D3date + name + ","; //D3.Split(',')[i].ToString() + ",";
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (D3date.Length > 0)
|
|
|
{
|
|
|
if (D1date.Length > 0)
|
|
|
{
|
|
|
D1date = D1date.Substring(0, D1date.Length - 1);
|
|
|
}
|
|
|
|
|
|
D3date = D3date.Substring(0, D3date.Length - 1);
|
|
|
|
|
|
Document doc = new Document();
|
|
|
doc.LoadFromFile(path);
|
|
|
|
|
|
//查找关键字符串文本
|
|
|
Section section = doc.Sections[0];
|
|
|
TextSelection selection = doc.FindString(TextName, true, true);
|
|
|
|
|
|
//获取关键字符串所在段落的索引
|
|
|
TextRange range = selection.GetAsOneRange();
|
|
|
Paragraph paragraph = range.OwnerParagraph;
|
|
|
Body body = paragraph.OwnerTextBody;
|
|
|
int index = body.ChildObjects.IndexOf(paragraph);
|
|
|
body.ChildObjects.Remove(paragraph);
|
|
|
|
|
|
if (D1date.Length == 0)
|
|
|
{
|
|
|
TableNum = TableNum + 1;
|
|
|
}
|
|
|
//根据元素个数判断需要拆成几个表格
|
|
|
int num = D3date.Split(',').Count() / TableNum;
|
|
|
if (D3date.Split(',').Count() % TableNum > 0)
|
|
|
{
|
|
|
num = num + 1;
|
|
|
}
|
|
|
int D1dateNum = D1date.Split(',').Count();
|
|
|
if (D1dateNum == 0)
|
|
|
{
|
|
|
D1dateNum = 1;
|
|
|
}
|
|
|
int rows = 0;
|
|
|
int d2DATANUM = 0;
|
|
|
int tanum = 3; //元素从第几列开始
|
|
|
|
|
|
//把一个表格拆成所需要的多个表格
|
|
|
for (int k = 0; k < num; k++)
|
|
|
{
|
|
|
rows = 0;
|
|
|
int row = 0;
|
|
|
//查询当前牌号又多少行--D2date
|
|
|
|
|
|
//添加表格指定表格的行数和列数(2行,5列)
|
|
|
Table table = section.AddTable(true);
|
|
|
//在此次判断是否是最后一个表格,如果是根据实际剩余得元素个数生成列
|
|
|
if (num == 1)
|
|
|
{
|
|
|
int TableNumsS = TableNums - (TableNum - D3date.Split(',').Count());
|
|
|
table.ResetCells(data.Rows.Count + 1, TableNumsS);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
table.ResetCells(data.Rows.Count + 1, TableNums);
|
|
|
}
|
|
|
////添加表格指定表格的行数和列数(2行,5列)
|
|
|
//Table table = section.AddTable(true);
|
|
|
////创建一个指定行和列得表格
|
|
|
//table.ResetCells(data.Rows.Count + 1, TableNums);
|
|
|
//bool d1dds = true;
|
|
|
//循环牌号
|
|
|
//循环每个牌号
|
|
|
int arrange = 0;
|
|
|
for (int j = 0; j < D1dateNum; j++)
|
|
|
{
|
|
|
arrange = 0;
|
|
|
D2date = "";
|
|
|
D4date="";
|
|
|
if (j == 0)
|
|
|
{
|
|
|
row = 1;
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
row = rows + 1;
|
|
|
}
|
|
|
string sqls = String.Empty;
|
|
|
if (!string.IsNullOrEmpty(D1date) && D1date.Split(',').Count() > 1)
|
|
|
{
|
|
|
sqls = D1 + "='" + D1date.Split(',')[j] + "'";
|
|
|
}
|
|
|
if (data.Select(sqls).Count() > 0)
|
|
|
{
|
|
|
bool d1dds = true;
|
|
|
//拿到当前牌号下的所有数据然后循环
|
|
|
for (int ii = 0; ii < data.Select(sqls).Count(); ii++)
|
|
|
{
|
|
|
///循环拿到当前牌号的每一条数据的坯型
|
|
|
string NameD4 = data.Select(sqls)[ii][D4].ToString();
|
|
|
///循环坯型判定当前坯型如果不在数组中就追加到数组中
|
|
|
foreach (var item in D4date.Split(','))
|
|
|
{
|
|
|
d1dds = true;
|
|
|
if (item == NameD4)
|
|
|
{
|
|
|
d1dds = false; break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (d1dds) { D4date = D4date + NameD4 + ","; }
|
|
|
///此处拿到有多少项目
|
|
|
string NameD2 = data.Select(sqls)[ii][D2 + "Text"].ToString();
|
|
|
foreach (var item in D2date.Split(','))
|
|
|
{
|
|
|
d1dds = true;
|
|
|
if (item == NameD2)
|
|
|
{
|
|
|
d1dds = false; break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (d1dds) { D2date = D2date + NameD2 + ","; }
|
|
|
|
|
|
}
|
|
|
}
|
|
|
//拿到当前牌号得数据条数
|
|
|
d2DATANUM = 0;
|
|
|
d2DATANUM = data.Select(sqls).Count();
|
|
|
//////拿到项目名称
|
|
|
//if (d2ss > 0)
|
|
|
//{
|
|
|
// for (int i = 0; i < data.Select(sqls).Count(); i++)
|
|
|
// {
|
|
|
// d1dds = true;
|
|
|
// foreach (var item in D2date.Split(','))
|
|
|
// {
|
|
|
// if (item == data.Select(sqls)[i][D2 + "Text"].ToString())
|
|
|
// {
|
|
|
// d1dds = false; break;
|
|
|
// }
|
|
|
// }
|
|
|
// if (d1dds) { D2date = D2date + data.Select(sqls)[i][D2 + "Text"].ToString() + ","; }
|
|
|
// }
|
|
|
//}
|
|
|
if (D2date.Length > 0)
|
|
|
{
|
|
|
D2date = D2date.Substring(0, D2date.Length - 1);
|
|
|
}
|
|
|
if (D4date.Length > 0)
|
|
|
{
|
|
|
D4date = D4date.Substring(0, D4date.Length - 1);
|
|
|
}
|
|
|
int D2Num = D2date.Split(',').Count();
|
|
|
int D4Num = D4date.Split(',').Count();
|
|
|
|
|
|
if (j == 0)
|
|
|
{
|
|
|
arrange = 0;
|
|
|
if (!string.IsNullOrEmpty(D1date))
|
|
|
{
|
|
|
//table.ApplyVerticalMerge(0, 1, D2date.Split(',').Count());
|
|
|
range = table[0, arrange].AddParagraph().AppendText("牌号");
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[0, arrange].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[0, arrange].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
|
|
|
if (D4Num > 0)
|
|
|
{
|
|
|
arrange = arrange + 1;
|
|
|
//获取单元格(第1行第2个单元格)并添加文本
|
|
|
range = table[0, arrange].AddParagraph().AppendText("坯型");
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[0, arrange].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[0, arrange].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
}
|
|
|
|
|
|
arrange = arrange + 1;
|
|
|
//获取单元格(第1行第2个单元格)并添加文本
|
|
|
range = table[0, arrange].AddParagraph().AppendText("元素");
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[0, arrange].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[0, arrange].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
tanum = 2;
|
|
|
|
|
|
if (D4Num > 0)
|
|
|
{
|
|
|
arrange = arrange + 1;
|
|
|
tanum = 3;
|
|
|
//获取单元格(第1行第2个单元格)并添加文本
|
|
|
range = table[0, arrange].AddParagraph().AppendText("锭坯型");
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[0, arrange].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[0, arrange].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
}
|
|
|
|
|
|
//获取单元格(第1行第2个单元格)并添加文本
|
|
|
range = table[0, arrange].AddParagraph().AppendText("元素");
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[0, arrange].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[0, arrange].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
}
|
|
|
|
|
|
|
|
|
int D3Num = 0;
|
|
|
//此处循环元素
|
|
|
for (int Q = tanum; Q < TableNums; Q++)
|
|
|
{
|
|
|
D3Num = k * TableNum + Q - tanum;
|
|
|
//判断是否是最后一个表,如果是最后一个表只需要加载剩余的元素数据,其余的表格全部为"";
|
|
|
if (k == num - 1)
|
|
|
{
|
|
|
//用当前第几个表格乘与每个表格的元素个数加上当前循环的元素个数判断是否超过总元素个数如果超过给表格空如果没有超过则给对应的数据值
|
|
|
if (k * TableNum + Q - tanum < D3date.Split(',').Count())
|
|
|
{
|
|
|
string MM = D3date.Split(',')[D3Num];
|
|
|
//获取单元格(第1行第Q个单元格)并添加文本
|
|
|
range = table[0, Q].AddParagraph().AppendText(MM); //D3date.Split(',')[D3Num]
|
|
|
range.CharacterFormat.FontName = "Times New Roman";
|
|
|
range.CharacterFormat.FontSize = 10;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[0, Q].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[0, Q].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string MM = D3date.Split(',')[D3Num];
|
|
|
//获取单元格(第1行第Q个单元格)并添加文本
|
|
|
range = table[0, Q].AddParagraph().AppendText(MM);//D3date.Split(',')[D3Num]
|
|
|
range.CharacterFormat.FontName = "Times New Roman";
|
|
|
range.CharacterFormat.FontSize = 10;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[0, Q].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[0, Q].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
}
|
|
|
}//循环表头结束
|
|
|
arrange = 0;
|
|
|
}
|
|
|
int numD4 = 0;
|
|
|
int ford4 = 0;
|
|
|
int d4datanum = 0;//记录循环到第几个锭坯型
|
|
|
|
|
|
//这里循环行
|
|
|
for (int W = 0; W < D2Num; W++)
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(D1date))
|
|
|
{
|
|
|
//因为牌号单元格合并了所以这里判断只有第一次循环的时候给牌号赋值
|
|
|
if (W == 0)
|
|
|
{
|
|
|
d4datanum = 1;
|
|
|
//获取合并的牌号行数
|
|
|
int merge = D2date.Split(',').Count();
|
|
|
if (row > 1)
|
|
|
{
|
|
|
merge = row - 1 + merge;
|
|
|
}
|
|
|
table.ApplyVerticalMerge(arrange, row, merge);
|
|
|
//获取单元格(第W+1行第1个单元格)并添加文本
|
|
|
range = table[row, arrange].AddParagraph().AppendText(D1date.Split(',')[j]);//D1date.Split(',')[j]
|
|
|
range.CharacterFormat.FontName = "Times New Roman";
|
|
|
range.CharacterFormat.FontSize = 9;
|
|
|
table[row, arrange].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[row, arrange].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
if (D4Num > 0)
|
|
|
{
|
|
|
arrange = arrange + 1;
|
|
|
if (W == 0)
|
|
|
{
|
|
|
|
|
|
string D4SS = D4date.Split(',')[ford4];
|
|
|
string d4sssql;
|
|
|
//拿到当前牌号有多少条数据然后合并行
|
|
|
//通过牌号和坯型去查数据条数
|
|
|
if (sqls != "")
|
|
|
{
|
|
|
d4sssql = sqls + " and " + D4 + "='" + D4SS + "'";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
d4sssql = sqls + D4 + "='" + D4SS + "'";
|
|
|
}
|
|
|
|
|
|
//data.Select(d4sssql).Count();
|
|
|
numD4 = numD4 + data.Select(d4sssql).Count();
|
|
|
//合并单元格
|
|
|
table.ApplyVerticalMerge(arrange, row, data.Select(d4sssql).Count()-1+ row);
|
|
|
range = table[row, arrange].AddParagraph().AppendText(D4SS);//D2date.Split(',')[W]
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[row, arrange].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[row, arrange].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
ford4 = ford4 + 1;
|
|
|
}
|
|
|
else if (W == numD4)
|
|
|
{
|
|
|
string D4SS = D4date.Split(',')[ford4];
|
|
|
string d4sssql;
|
|
|
//拿到当前牌号有多少条数据然后合并行
|
|
|
//通过牌号和坯型去查数据条数
|
|
|
if (sqls != "")
|
|
|
{
|
|
|
d4sssql = sqls + " and " + D4 + "='" + D4SS + "'";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
d4sssql = sqls + D4 + "='" + D4SS + "'";
|
|
|
}
|
|
|
//data.Select(d4sssql).Count();
|
|
|
numD4 = numD4 + data.Select(d4sssql).Count();
|
|
|
//合并单元格
|
|
|
table.ApplyVerticalMerge(arrange, row, data.Select(d4sssql).Count()-1+ row);
|
|
|
range = table[row, arrange].AddParagraph().AppendText(D4SS);//D2date.Split(',')[W]
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[row, arrange].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[row, arrange].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
ford4 = ford4 + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
//}
|
|
|
|
|
|
if (W == 0)
|
|
|
{
|
|
|
arrange = arrange + 1;
|
|
|
}
|
|
|
string D2SS = D2date.Split(',')[W];
|
|
|
//获取单元格(第W+1行第2个单元格)并添加文本
|
|
|
range = table[row, arrange].AddParagraph().AppendText(D2SS);//D2date.Split(',')[W]
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[row, arrange].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[row, arrange].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
//row = row + 1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
///判断坯型是否为空如果不为空则合并当前坯型的行然后第一次的时候输入
|
|
|
if (D4Num > 0)
|
|
|
{
|
|
|
|
|
|
//arrange = arrange + 1;
|
|
|
if (W == 0)
|
|
|
{
|
|
|
arrange = arrange - 1;
|
|
|
string D4SS = D4date.Split(',')[ford4];
|
|
|
string d4sssql;
|
|
|
//拿到当前牌号有多少条数据然后合并行
|
|
|
//通过牌号和坯型去查数据条数
|
|
|
if (sqls != "")
|
|
|
{
|
|
|
d4sssql = sqls + " and " + D4 + "='" + D4SS + "'";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
d4sssql = sqls + D4 + "='" + D4SS + "'";
|
|
|
}
|
|
|
//data.Select(d4sssql).Count();
|
|
|
numD4 = numD4 + data.Select(d4sssql).Count();
|
|
|
//合并单元格
|
|
|
table.ApplyVerticalMerge(arrange, row, data.Select(d4sssql).Count() - 1 + row);
|
|
|
range = table[row, arrange].AddParagraph().AppendText(D4SS);//D2date.Split(',')[W]
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[row, arrange].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[row, arrange].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
ford4 = ford4 + 1;
|
|
|
arrange = arrange + 1;
|
|
|
}
|
|
|
else if (W == numD4)
|
|
|
{
|
|
|
arrange = arrange - 1;
|
|
|
string D4SS = D4date.Split(',')[ford4];
|
|
|
string d4sssql;
|
|
|
//拿到当前牌号有多少条数据然后合并行
|
|
|
//通过牌号和坯型去查数据条数
|
|
|
if (sqls != "")
|
|
|
{
|
|
|
d4sssql = sqls + " and " + D4 + "='" + D4SS + "'";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
d4sssql = sqls + D4 + "='" + D4SS + "'";
|
|
|
}
|
|
|
//data.Select(d4sssql).Count();
|
|
|
numD4 = numD4 + data.Select(d4sssql).Count();
|
|
|
//合并单元格
|
|
|
table.ApplyVerticalMerge(arrange, row, data.Select(d4sssql).Count() - 1 + row);
|
|
|
range = table[row, arrange].AddParagraph().AppendText(D4SS);//D2date.Split(',')[W]
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[row, arrange].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[row, arrange].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
ford4 = ford4 + 1;
|
|
|
arrange = arrange + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (W == 0)
|
|
|
{
|
|
|
arrange = arrange + 1;
|
|
|
}
|
|
|
|
|
|
string D2SS = D2date.Split(',')[W];
|
|
|
//获取单元格(第W+1行第2个单元格)并添加文本
|
|
|
range = table[row, arrange].AddParagraph().AppendText(D2SS);//D2date.Split(',')[W]
|
|
|
range.CharacterFormat.FontName = "宋体";
|
|
|
range.CharacterFormat.FontSize = 12;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[row, arrange].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[row, arrange].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
//row = row + 1;
|
|
|
}
|
|
|
}
|
|
|
int d3Knum = 0;
|
|
|
//此处循环元素
|
|
|
for (int Q = tanum; Q < TableNums; Q++)
|
|
|
{
|
|
|
d3Knum = k * TableNum + Q - tanum;
|
|
|
//判断是否是最后一个表,如果是最后一个表只需要加载剩余的元素数据,其余的表格全部为"";
|
|
|
if (k == num - 1)
|
|
|
{
|
|
|
|
|
|
/*用当前第几个表格乘与每个表格的元素个数加上当前循环的元素个数判断是否超过总元素个数如果超过给表格空如果没有超过则给对应的数据值*/
|
|
|
if (k * TableNum + Q - tanum < D3date.Split(',').Count())
|
|
|
{
|
|
|
string D2names = D2 + "Text";
|
|
|
string sql = D2names + "='" + D2date.Split(',')[W] + "' ";
|
|
|
if (!string.IsNullOrEmpty(D1date) && D1date.Split(',').Count() > 1)
|
|
|
{
|
|
|
sql += "and " + D1 + "='" + D1date.Split(',')[j] + "'";
|
|
|
}
|
|
|
string named3 = D3date.Split(',')[d3Knum].ToString();
|
|
|
#region (无牌号)赋值时换回元素 20231229
|
|
|
if (named3 == "As")
|
|
|
{
|
|
|
named3 = "ASYS";
|
|
|
}
|
|
|
#endregion
|
|
|
int ss = data.Select(sql).Count();
|
|
|
string ds = data.Select(sql)[0][named3].ToString();
|
|
|
//if (string.IsNullOrEmpty(ds))
|
|
|
//{
|
|
|
// ds = "W";
|
|
|
//}
|
|
|
//获取单元格(第W+1行第Q个单元格)并添加文本
|
|
|
range = table[row, Q].AddParagraph().AppendText(ds);
|
|
|
//此处应该是元素对应的值
|
|
|
range.CharacterFormat.FontName = "Times New Roman";
|
|
|
range.CharacterFormat.FontSize = 10;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[row, Q].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[row, Q].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string ds = "";
|
|
|
string D2names = D2 + "Text";
|
|
|
string sql = D2names + "='" + D2date.Split(',')[W] + "' ";
|
|
|
if (!string.IsNullOrEmpty(D1date) && D1date.Split(',').Count() > 1)
|
|
|
{
|
|
|
sql += "and " + D1 + "='" + D1date.Split(',')[j] + "'";
|
|
|
}
|
|
|
#region (有牌号)赋值时换回元素 20231229
|
|
|
if (D3date.Split(',')[d3Knum].ToString() == "As")
|
|
|
{
|
|
|
string name = "ASYS";
|
|
|
ds = data.Select(sql)[0][name].ToString();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ds = data.Select(sql)[0][D3date.Split(',')[d3Knum].ToString()].ToString();
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
range = table[row, Q].AddParagraph().AppendText(ds);//此处获取元素得SZ
|
|
|
//此处应该是元素对应的值
|
|
|
range.CharacterFormat.FontName = "Times New Roman";
|
|
|
range.CharacterFormat.FontSize = 10;
|
|
|
range.CharacterFormat.TextColor = Color.Black;
|
|
|
range.CharacterFormat.Bold = false;
|
|
|
table[row, Q].Paragraphs[0].Format.HorizontalAlignment = HorizontalAlignment.Center;
|
|
|
table[row, Q].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
|
|
|
}
|
|
|
}//循环元素值结束
|
|
|
row = row + 1;
|
|
|
|
|
|
}//循环行结束
|
|
|
|
|
|
rows = rows + d2DATANUM;
|
|
|
}//循环牌号结束
|
|
|
|
|
|
table.TableFormat.HorizontalAlignment = RowAlignment.Center;//整个表格居中
|
|
|
//移除段落,插入表格
|
|
|
body.ChildObjects.Insert(index + k, table);
|
|
|
|
|
|
}//循环拆分表格结束
|
|
|
//保存文档
|
|
|
doc.SaveToFile(path, FileFormat.Doc);
|
|
|
BP.DA.Log.DebugWriteError("开始去除新3D文档水印。");
|
|
|
//Microsoft.Office.Interop.Word.Application
|
|
|
try
|
|
|
{
|
|
|
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
|
|
|
Microsoft.Office.Interop.Word.Document docs = null;
|
|
|
object unknow = Type.Missing;
|
|
|
app.Visible = true;
|
|
|
object file = path;
|
|
|
docs = app.Documents.Open(ref file, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow);
|
|
|
docs.Paragraphs[1].Range.Delete();
|
|
|
docs.SaveAs2(path);
|
|
|
docs.Close();
|
|
|
Process[] current = Process.GetProcesses();
|
|
|
//遍历与当前进程名称相同的进程列表
|
|
|
foreach (Process process in current)
|
|
|
{
|
|
|
//如果实例已经存在则kill当前进程
|
|
|
if (process.ProcessName.ToUpper().Equals("WINWORD"))
|
|
|
{
|
|
|
process.Kill(); break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
BP.DA.Log.DebugWriteError(ex.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
/// <summary>
|
|
|
/// 单据生成
|
|
|
/// </summary>
|
|
|
/// <param name="cfile">模板文件</param>
|
|
|
/// <param name="path">生成路径</param>
|
|
|
/// <param name="file">生成文件</param>
|
|
|
/// <param name="isOpen">要打开的url用于生成二维码</param>
|
|
|
public void MakeDoc(string templateRtfFile, string path, string file, string billUrl = null)
|
|
|
{
|
|
|
templateRtfFile = templateRtfFile.Replace(".rtf.rtf", ".rtf");
|
|
|
|
|
|
if (System.IO.Directory.Exists(path) == false)
|
|
|
System.IO.Directory.CreateDirectory(path);
|
|
|
|
|
|
string str = this._rtfStr;
|
|
|
if (this.HisEns.Count == 0)
|
|
|
if (this.HisGEEntity == null)
|
|
|
throw new Exception("@您没有为报表设置数据源...");
|
|
|
|
|
|
this.ensStrs = "";
|
|
|
if (this.HisEns.Count != 0)
|
|
|
{
|
|
|
foreach (Entity en in this.HisEns)
|
|
|
ensStrs += en.ToString();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ensStrs = this.HisGEEntity.ToString();
|
|
|
}
|
|
|
|
|
|
string error = "";
|
|
|
string[] paras = null;
|
|
|
if (this.HisGEEntity != null)
|
|
|
paras = Cache.GetBillParas(templateRtfFile, ensStrs, this.HisGEEntity);
|
|
|
else
|
|
|
paras = Cache.GetBillParas(templateRtfFile, ensStrs, this.HisEns);
|
|
|
|
|
|
this.TempFilePath = path + file;
|
|
|
try
|
|
|
{
|
|
|
string key = "";
|
|
|
string ss = "";
|
|
|
|
|
|
#region 替换主表标记
|
|
|
foreach (string para in paras)
|
|
|
{
|
|
|
if (DataType.IsNullOrEmpty(para))
|
|
|
continue;
|
|
|
|
|
|
//如果包含,时间表.
|
|
|
if (para.Contains("FlowTrackTable") == true && dtTrack != null)
|
|
|
{
|
|
|
str = str.Replace("<FlowTrackTable>", this.GetFlowTrackTable());
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
try
|
|
|
{
|
|
|
if (para.Contains("Editor"))
|
|
|
str = str.Replace("<" + para + ">", this.GetValueByKey(para));
|
|
|
else if (para.Contains("ImgAth") && para.Contains("Ath.") == false)
|
|
|
str = str.Replace("<" + para + ">", this.GetValueByKey(para));
|
|
|
else if (para.Contains("Siganture"))
|
|
|
str = str.Replace("<" + para + ">", this.GetValueByKey(para));
|
|
|
else if (para.Contains("Img@AppPath"))
|
|
|
str = str.Replace("<" + para + ">", this.GetValueImgStrs(para));
|
|
|
else if (para.Contains("Img@QR"))
|
|
|
str = str.Replace("<" + para + ">", this.GetValueImgStrsOfQR(billUrl));
|
|
|
else if (para.Contains(".BPPaint"))
|
|
|
str = str.Replace("<" + para + ">", this.GetValueBPPaintStrs(para));
|
|
|
else if (para.Contains(".M2M"))
|
|
|
str = str.Replace("<" + para + ">", this.GetValueM2MStrs(para));
|
|
|
else if (para.Contains(".RMBDX"))
|
|
|
str = str.Replace("<" + para + ">", this.GetValueByKey(para));
|
|
|
else if (para.Contains(".RMB"))
|
|
|
str = str.Replace("<" + para + ">", this.GetValueByKey(para));
|
|
|
else if (para.Contains(".Boolen"))
|
|
|
str = str.Replace("<" + para + ">", this.GetValueByKey(para));
|
|
|
else if (para.Contains(".BoolenText"))
|
|
|
str = str.Replace("<" + para + ">", this.GetValueByKey(para));
|
|
|
else if (para.Contains(".NYR"))
|
|
|
str = str.Replace("<" + para + ">", this.GetCode(this.GetValueByKey(para)));
|
|
|
else if (para.Contains(".Year"))
|
|
|
str = str.Replace("<" + para + ">", this.GetValueByKey(para));
|
|
|
else if (para.Contains(".Month"))
|
|
|
str = str.Replace("<" + para + ">", this.GetValueByKey(para));
|
|
|
else if (para.Contains(".Day"))
|
|
|
str = str.Replace("<" + para + ">", this.GetValueByKey(para));
|
|
|
else if (para.Contains(".Yes") == true)
|
|
|
str = str.Replace("<" + para + ">", this.GetCode(this.GetValueByKey(para)));
|
|
|
else if (para.Contains("-EnumYes") == true)
|
|
|
str = str.Replace("<" + para + ">", this.GetCode(this.GetValueByKey(para)));
|
|
|
else if (para.Contains(".Checkboxs") == true)
|
|
|
str = str.Replace("<" + para + ">", this.GetCode(this.GetValueByKey(para)));
|
|
|
else if ((para.Contains("WorkCheck.RDT") == true && para.Contains("WorkCheck.RDT.") == false)
|
|
|
|| (para.Contains("WorkCheck.Rec") == true && para.Contains("WorkCheck.Rec.") == false)
|
|
|
|| (para.Contains("WorkCheck.RecName") == true && para.Contains("WorkCheck.RecName.") == false)
|
|
|
|| (para.Contains("WorkCheck.Note") == true && para.Contains("WorkCheck.Note.") == false)) // 审核组件的审核日期.
|
|
|
str = str.Replace("<" + para + ">", this.GetValueCheckWorkByKey(para));
|
|
|
else if (para.Contains("WorkChecks") == true) //为烟台增加审核人员的信息,把所有的审核人员信息都输入到这里.
|
|
|
str = str.Replace("<" + para + ">", this.GetValueCheckWorks());
|
|
|
else if (para.Contains(".") == true)
|
|
|
continue; /*有可能是明细表数据.*/
|
|
|
else
|
|
|
{
|
|
|
string val = this.GetValueByKey(para);
|
|
|
if (val == "")
|
|
|
{
|
|
|
str = GetRtfStr(str, "<" + para + ">");
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
|
|
|
//@BKGY 工艺卡的被隐藏的编制字段,打印赋值
|
|
|
val = val.Replace("@WebUser.No", WebUser.No);
|
|
|
val = val.Replace("@WebUser.Name", WebUser.Name);
|
|
|
val = val.Replace("@WebUser.FK_DeptName", WebUser.DeptName);
|
|
|
val = val.Replace("@WebUser.FK_Dept", WebUser.DeptNo);
|
|
|
val = val.Replace("@WebUser.OrgNo", WebUser.OrgNo);
|
|
|
val = val.Replace("@RDT", DataType.CurrentDateTime);
|
|
|
|
|
|
val = val.Replace("\\", "\\\\");
|
|
|
val = this.GetCode(val);
|
|
|
str = str.Replace("<" + para + ">", val);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
error += "@替换主表标记取参数[" + para + "]出现错误:有以下情况导致此错误;1你用Text取值时间,此属性不是外键。2,类无此属性。3,该字段是明细表字段但是丢失了明细表标记.<br>更详细的信息:<br>" + ex.Message;
|
|
|
if (SystemConfig.isDebug)
|
|
|
throw new Exception(error);
|
|
|
BP.DA.Log.DebugWriteError(error);
|
|
|
}
|
|
|
}
|
|
|
#endregion 替换主表标记
|
|
|
|
|
|
#region 从表
|
|
|
string shortName = "";
|
|
|
ArrayList al = this.EnsDataDtls;
|
|
|
DataTable dt3D = new DataTable();
|
|
|
string d1 = "";
|
|
|
string d2 = "";
|
|
|
string d3 = "";
|
|
|
string d4 = "";
|
|
|
string dtlEnName3D = "";
|
|
|
for (int K = 0; K < 2; K++)
|
|
|
{
|
|
|
foreach (Entities dtls in al)
|
|
|
{
|
|
|
Entity dtl = dtls.GetNewEntity;
|
|
|
string dtlEnName = dtl.ToString();
|
|
|
shortName = dtlEnName.Substring(dtlEnName.LastIndexOf(".") + 1);
|
|
|
if (str.IndexOf("<" + shortName + ".") != -1)
|
|
|
{
|
|
|
|
|
|
|
|
|
if (str.IndexOf(shortName) == -1)
|
|
|
continue;
|
|
|
|
|
|
int pos_rowKey = str.IndexOf("<" + shortName + ".") + 1;
|
|
|
int row_start = -1, row_end = -1;
|
|
|
if (pos_rowKey != -1)
|
|
|
{
|
|
|
row_start = str.Substring(0, pos_rowKey).LastIndexOf("\\nestrow");
|
|
|
if (row_start == -1)
|
|
|
row_start = str.Substring(0, pos_rowKey).LastIndexOf("\\row");
|
|
|
|
|
|
|
|
|
row_end = str.Substring(pos_rowKey).IndexOf("\\nestrow");
|
|
|
if (row_end == -1)
|
|
|
row_end = str.Substring(pos_rowKey).IndexOf("\\row");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (row_start == -1 || row_end == -1)
|
|
|
continue; //如果没有发现标记.
|
|
|
|
|
|
//获得row的数据.
|
|
|
string row = str.Substring(row_start, (pos_rowKey - row_start) + row_end);
|
|
|
str = str.Replace(row, "");
|
|
|
|
|
|
Map map = dtls.GetNewEntity.EnMap;
|
|
|
int i = dtls.Count;
|
|
|
MapDtl mapDtl = new MapDtl(dtlEnName);
|
|
|
if (dtls.Count == 0 && mapDtl.RowsOfList != 0)
|
|
|
{
|
|
|
for (int j = 0; i < mapDtl.RowsOfList; i++)
|
|
|
{
|
|
|
GEDtl geDtl = new GEDtl(mapDtl.No);
|
|
|
dtls.AddEntity(geDtl);
|
|
|
}
|
|
|
}
|
|
|
while (i > 0)
|
|
|
{
|
|
|
i--;
|
|
|
string rowData = row.Clone() as string;
|
|
|
dtl = dtls[i];
|
|
|
//替换序号
|
|
|
int rowIdx = i + 1;
|
|
|
rowData = rowData.Replace("<IDX>", rowIdx.ToString());
|
|
|
|
|
|
foreach (Attr attr in map.Attrs)
|
|
|
{
|
|
|
switch (attr.MyDataType)
|
|
|
{
|
|
|
case DataType.AppDouble:
|
|
|
case DataType.AppFloat:
|
|
|
rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", dtl.GetValStringByKey(attr.Key));
|
|
|
break;
|
|
|
case DataType.AppMoney:
|
|
|
rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", dtl.GetValDecimalByKey(attr.Key).ToString("0.00"));
|
|
|
break;
|
|
|
case DataType.AppInt:
|
|
|
|
|
|
if (attr.MyDataType == DataType.AppBoolean)
|
|
|
{
|
|
|
rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", dtl.GetValStrByKey(attr.Key));
|
|
|
int v = dtl.GetValIntByKey(attr.Key);
|
|
|
if (v == 1)
|
|
|
rowData = rowData.Replace("<" + shortName + "." + attr.Key + "Text>", "是");
|
|
|
else
|
|
|
rowData = rowData.Replace("<" + shortName + "." + attr.Key + "Text>", "否");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (attr.ItIsEnum)
|
|
|
rowData = rowData.Replace("<" + shortName + "." + attr.Key + "Text>", GetCode(dtl.GetValRefTextByKey(attr.Key)));
|
|
|
else
|
|
|
rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", dtl.GetValStrByKey(attr.Key));
|
|
|
}
|
|
|
break;
|
|
|
case DataType.AppString:
|
|
|
if (attr.UIContralType == UIContralType.AthShow)
|
|
|
{
|
|
|
FrmAttachment ath = this.EnsDataDtlOfAths.GetEntityByKey(mapDtl.No + "_" + attr.Key) as FrmAttachment;
|
|
|
if (ath != null)
|
|
|
{
|
|
|
|
|
|
FrmAttachmentDBs dbs = new FrmAttachmentDBs();
|
|
|
dbs.Retrieve(FrmAttachmentDBAttr.NoOfObj, ath.NoOfObj, FrmAttachmentDBAttr.RefPKVal, dtl.GetValIntByKey("OID"), FrmAttachmentDBAttr.RDT);
|
|
|
if (ath.FileType == 0)
|
|
|
{
|
|
|
rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", GetCode("附件(" + dbs.Count + ")"));
|
|
|
break;
|
|
|
}
|
|
|
StringBuilder picStr = new StringBuilder();
|
|
|
foreach (FrmAttachmentDB db in dbs)
|
|
|
{
|
|
|
if (File.Exists(db.FileFullName) == false)
|
|
|
continue;
|
|
|
//获取要插入的图片
|
|
|
System.Drawing.Image imgAth = System.Drawing.Image.FromFile(db.FileFullName);
|
|
|
|
|
|
//将要插入的图片转换为16进制字符串
|
|
|
string imgHexStringImgAth = GetImgHexString(imgAth, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
//生成rtf中图片字符串
|
|
|
picStr.AppendLine();
|
|
|
picStr.Append(@"{\pict");
|
|
|
picStr.Append(@"\jpegblip");
|
|
|
picStr.Append(@"\picscalex100");
|
|
|
picStr.Append(@"\picscaley100");
|
|
|
picStr.Append(@"\picwgoal" + imgAth.Size.Width * 3);
|
|
|
picStr.Append(@"\pichgoal" + imgAth.Size.Height * 3);
|
|
|
picStr.Append(imgHexStringImgAth + "}");
|
|
|
picStr.AppendLine();
|
|
|
}
|
|
|
rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", picStr.ToString());
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (attr.UIContralType == UIContralType.DDL)
|
|
|
{
|
|
|
string val = dtl.GetValStrByKey(attr.Key + "Text");
|
|
|
if (DataType.IsNullOrEmpty(val))
|
|
|
val = dtl.GetValStrByKey(attr.Key + "T");
|
|
|
if (DataType.IsNullOrEmpty(val))
|
|
|
val = dtl.GetValStrByKey(attr.Key);
|
|
|
rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", GetCode(val));
|
|
|
break;
|
|
|
}
|
|
|
rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", GetCode(dtl.GetValStrByKey(attr.Key)));
|
|
|
break;
|
|
|
default:
|
|
|
rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", GetCode(dtl.GetValStrByKey(attr.Key)));
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
str = str.Insert(row_start, rowData);
|
|
|
}
|
|
|
}
|
|
|
else if (str.IndexOf("BP.3D") != -1)
|
|
|
{
|
|
|
if (str.IndexOf("BP.3D." + dtlEnName + ">") != -1)
|
|
|
{
|
|
|
GEEntity mainEn = null;
|
|
|
MapDtl mdtl = new MapDtl(dtlEnName);
|
|
|
mainEn = mdtl.GenerGEMainEntity(this.HisGEEntity.PKVal.ToString());
|
|
|
dt3D = CCFormAPI.GetDtlInfo(mdtl, mainEn, this.HisGEEntity.PKVal.ToString());
|
|
|
d1 = mdtl.GetParaString("D1");
|
|
|
d2 = mdtl.GetParaString("D2");
|
|
|
d3 = mdtl.GetParaString("D3");
|
|
|
d4 = mdtl.GetParaString("D4");
|
|
|
dtlEnName3D = dtlEnName;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
else if (str.IndexOf("BP.2D") != -1)
|
|
|
{
|
|
|
if (str.IndexOf("BP.2D." + dtlEnName + ">") != -1)
|
|
|
{
|
|
|
GEEntity mainEn = null;
|
|
|
MapDtl mdtl = new MapDtl(dtlEnName);
|
|
|
mainEn = mdtl.GenerGEMainEntity(this.HisGEEntity.PKVal.ToString());
|
|
|
dt3D = CCFormAPI.GetDtlInfo(mdtl, mainEn, this.HisGEEntity.PKVal.ToString());
|
|
|
Map map = dtls.GetNewEntity.EnMap;
|
|
|
int i = 0;
|
|
|
foreach (Attr item in map.Attrs)
|
|
|
{
|
|
|
if (item.UIVisible)
|
|
|
{
|
|
|
if (i == 0)
|
|
|
{
|
|
|
d1 = item.Key;
|
|
|
}
|
|
|
else if (i == 1)
|
|
|
{
|
|
|
d2 = item.Key;
|
|
|
}
|
|
|
//20240205注释
|
|
|
//else if (i == 2)
|
|
|
//{
|
|
|
// d4 = item.Key;
|
|
|
//}
|
|
|
else
|
|
|
{
|
|
|
bool d1dd = true;
|
|
|
foreach (var items in d3.Split(','))
|
|
|
{
|
|
|
if (items == item.Key)
|
|
|
{
|
|
|
d1dd = false; break;
|
|
|
}
|
|
|
}
|
|
|
if (d1dd) { d3 = d3 + item.Key + ","; }
|
|
|
}
|
|
|
i = i + 1;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
d3.Substring(0, d3.Length - 1);
|
|
|
|
|
|
//d2= d3.Split(',')[1].ToString();
|
|
|
|
|
|
//mainEn1 = mdt2.GenerGEMainEntity(this.HisGEEntity.PKVal.ToString());
|
|
|
//DataTable dt1 = CCFormAPI.GetDtlInfo(mdt2, mainEn1, this.HisGEEntity.PKVal.ToString());
|
|
|
//d1 = mdtl.GetParaString("D1");
|
|
|
//d2 = mdtl.GetParaString("D2");
|
|
|
//d3 = mdtl.GetParaString("D3");
|
|
|
dtlEnName3D = dtlEnName;
|
|
|
//string rtfFor3D = MDFORMDoc(dt, d1, d2, d3);
|
|
|
//str = str.Replace("<BP.3D." + dtlEnName + ">", rtfFor3D);
|
|
|
}
|
|
|
}
|
|
|
else if (str.IndexOf("BP.s2D") != -1)
|
|
|
{
|
|
|
if (str.IndexOf("BP.s2D." + dtlEnName + ">") != -1)
|
|
|
{
|
|
|
GEEntity mainEn = null;
|
|
|
MapDtl mdtl = new MapDtl(dtlEnName);
|
|
|
mainEn = mdtl.GenerGEMainEntity(this.HisGEEntity.PKVal.ToString());
|
|
|
dt3D = CCFormAPI.GetDtlInfo(mdtl, mainEn, this.HisGEEntity.PKVal.ToString());
|
|
|
Map map = dtls.GetNewEntity.EnMap;
|
|
|
int i = 0;
|
|
|
foreach (Attr item in map.Attrs)
|
|
|
{
|
|
|
if (item.UIVisible)
|
|
|
{
|
|
|
if (i == 0)
|
|
|
{
|
|
|
d1 = item.Key;
|
|
|
}
|
|
|
else if (i == 1)
|
|
|
{
|
|
|
d2 = item.Key;
|
|
|
}
|
|
|
//else if (i == 2)
|
|
|
//{
|
|
|
// d4 = item.Key;
|
|
|
//}
|
|
|
else
|
|
|
{
|
|
|
bool d1dd = true;
|
|
|
foreach (var items in d3.Split(','))
|
|
|
{
|
|
|
if (items == item.Key)
|
|
|
{
|
|
|
d1dd = false; break;
|
|
|
}
|
|
|
}
|
|
|
if (d1dd) { d3 = d3 + item.Key + ","; }
|
|
|
}
|
|
|
i = i + 1;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
d3.Substring(0, d3.Length - 1);
|
|
|
|
|
|
//d2= d3.Split(',')[1].ToString();
|
|
|
|
|
|
//mainEn1 = mdt2.GenerGEMainEntity(this.HisGEEntity.PKVal.ToString());
|
|
|
//DataTable dt1 = CCFormAPI.GetDtlInfo(mdt2, mainEn1, this.HisGEEntity.PKVal.ToString());
|
|
|
//d1 = mdtl.GetParaString("D1");
|
|
|
//d2 = mdtl.GetParaString("D2");
|
|
|
//d3 = mdtl.GetParaString("D3");
|
|
|
dtlEnName3D = dtlEnName;
|
|
|
//string rtfFor3D = MDFORMDoc(dt, d1, d2, d3);
|
|
|
//str = str.Replace("<BP.3D." + dtlEnName + ">", rtfFor3D);
|
|
|
}
|
|
|
}
|
|
|
else if (str.IndexOf("BP.B2D") != -1)
|
|
|
{
|
|
|
if (str.IndexOf("BP.B2D." + dtlEnName + ">") != -1)
|
|
|
{
|
|
|
GEEntity mainEn = null;
|
|
|
MapDtl mdtl = new MapDtl(dtlEnName);
|
|
|
mainEn = mdtl.GenerGEMainEntity(this.HisGEEntity.PKVal.ToString());
|
|
|
dt3D = CCFormAPI.GetDtlInfo(mdtl, mainEn, this.HisGEEntity.PKVal.ToString());
|
|
|
Map map = dtls.GetNewEntity.EnMap;
|
|
|
int i = 0;
|
|
|
foreach (Attr item in map.Attrs)
|
|
|
{
|
|
|
if (item.UIVisible)
|
|
|
{
|
|
|
if (i == 0)
|
|
|
{
|
|
|
d1 = item.Key;
|
|
|
}
|
|
|
else if (i == 1)
|
|
|
{
|
|
|
d4 = item.Key;
|
|
|
}
|
|
|
else if (i == 2)
|
|
|
{
|
|
|
d2 = item.Key;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
bool d1dd = true;
|
|
|
foreach (var items in d3.Split(','))
|
|
|
{
|
|
|
if (items == item.Key)
|
|
|
{
|
|
|
d1dd = false; break;
|
|
|
}
|
|
|
}
|
|
|
if (d1dd) { d3 = d3 + item.Key + ","; }
|
|
|
}
|
|
|
i = i + 1;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
d3.Substring(0, d3.Length - 1);
|
|
|
|
|
|
//d2= d3.Split(',')[1].ToString();
|
|
|
|
|
|
//mainEn1 = mdt2.GenerGEMainEntity(this.HisGEEntity.PKVal.ToString());
|
|
|
//DataTable dt1 = CCFormAPI.GetDtlInfo(mdt2, mainEn1, this.HisGEEntity.PKVal.ToString());
|
|
|
//d1 = mdtl.GetParaString("D1");
|
|
|
//d2 = mdtl.GetParaString("D2");
|
|
|
//d3 = mdtl.GetParaString("D3");
|
|
|
dtlEnName3D = dtlEnName;
|
|
|
//string rtfFor3D = MDFORMDoc(dt, d1, d2, d3);
|
|
|
//str = str.Replace("<BP.3D." + dtlEnName + ">", rtfFor3D);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion 从表
|
|
|
|
|
|
|
|
|
|
|
|
#region 明细 合计信息。
|
|
|
al = this.EnsDataDtls;
|
|
|
foreach (Entities dtls in al)
|
|
|
{
|
|
|
Entity dtl = dtls.GetNewEntity;
|
|
|
string dtlEnName = dtl.ToString();
|
|
|
shortName = dtlEnName.Substring(dtlEnName.LastIndexOf(".") + 1);
|
|
|
//shortName = dtls.ToString().Substring(dtls.ToString().LastIndexOf(".") + 1);
|
|
|
Map map = dtl.EnMap;
|
|
|
foreach (Attr attr in map.Attrs)
|
|
|
{
|
|
|
switch (attr.MyDataType)
|
|
|
{
|
|
|
case DataType.AppDouble:
|
|
|
case DataType.AppFloat:
|
|
|
case DataType.AppMoney:
|
|
|
key = "<" + shortName + "." + attr.Key + ".SUM>";
|
|
|
if (str.IndexOf(key) != -1)
|
|
|
str = str.Replace(key, dtls.GetSumFloatByKey(attr.Key).ToString());
|
|
|
|
|
|
key = "<" + shortName + "." + attr.Key + ".SUM.RMB>";
|
|
|
if (str.IndexOf(key) != -1)
|
|
|
str = str.Replace(key, dtls.GetSumFloatByKey(attr.Key).ToString("0.00"));
|
|
|
|
|
|
key = "<" + shortName + "." + attr.Key + ".SUM.RMBDX>";
|
|
|
if (str.IndexOf(key) != -1)
|
|
|
str = str.Replace(key,
|
|
|
GetCode(DataType.ParseFloatToCache(dtls.GetSumFloatByKey(attr.Key))));
|
|
|
break;
|
|
|
case DataType.AppInt:
|
|
|
key = "<" + shortName + "." + attr.Key + ".SUM>";
|
|
|
if (str.IndexOf(key) != -1)
|
|
|
str = str.Replace(key, dtls.GetSumIntByKey(attr.Key).ToString());
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion 从表合计
|
|
|
|
|
|
#region 审核组件组合信息,added by liuxc,2016-12-16
|
|
|
|
|
|
//节点单个审核人
|
|
|
// 根据track表获取审核的节点
|
|
|
if (dtTrack != null && str.Contains("<WorkCheckBegin>") == false
|
|
|
&& str.Contains("<WorkCheckEnd>") == false)
|
|
|
{
|
|
|
if (this.wks != null && this.wks.Rows.Count != 0)
|
|
|
{
|
|
|
foreach (DataRow nd in this.wks.Rows)
|
|
|
{
|
|
|
int nodeID = nd[0] != null ? int.Parse(nd[0].ToString()) : 0;
|
|
|
//判断是否存在一个节点多个签批意见,需要循环显示,第一个意见替换,其余的节点追加在后面
|
|
|
bool isHaveNote = str.IndexOf("WorkCheck.Note." + nodeID) != -1 ? true : false;
|
|
|
bool isHaveRec = str.IndexOf("WorkCheck.Rec." + nodeID) != -1 ? true : false;
|
|
|
bool isHaveRecName = str.IndexOf("WorkCheck.RecName." + nodeID) != -1 ? true : false;
|
|
|
bool isHaveRDT = str.IndexOf("WorkCheck.RDT." + nodeID) != -1 ? true : false;
|
|
|
bool isHaveWriteDB = str.IndexOf("WorkCheck.WriteDB." + nodeID) != -1 ? true : false;
|
|
|
if (isHaveNote == false && isHaveRec == false && isHaveRecName == false && isHaveRDT == false && isHaveWriteDB == false)
|
|
|
continue;
|
|
|
//把track信息分组
|
|
|
DataRow[] tracks = tracks = dtTrack.Select("NDFrom=" + nodeID);
|
|
|
if (tracks.Length == 0)
|
|
|
{ //该节点没有签名,替换签名的内容
|
|
|
string wkKey = "<WorkCheck.Note." + nodeID + ">";
|
|
|
str = str.Replace(wkKey, "");
|
|
|
wkKey = "<WorkCheck.Rec." + nodeID + ">";
|
|
|
str = str.Replace(wkKey, "");
|
|
|
wkKey = "<WorkCheck.RecName." + nodeID + ">";
|
|
|
str = str.Replace(wkKey, "");
|
|
|
wkKey = "<WorkCheck.RDT." + nodeID + ">";
|
|
|
str = str.Replace(wkKey, "");
|
|
|
wkKey = "<WorkCheck.RDT-NYR." + nodeID + ">";
|
|
|
str = str.Replace(wkKey, "");
|
|
|
wkKey = "<WorkCheck.Siganture." + nodeID + ">";
|
|
|
str = str.Replace(wkKey, "");
|
|
|
wkKey = "<WorkCheck.WriteDB." + nodeID + ">";
|
|
|
str = str.Replace(wkKey, "");
|
|
|
continue;
|
|
|
}
|
|
|
string workCheckStr = "";
|
|
|
|
|
|
int idx = 0;
|
|
|
foreach (DataRow row in tracks)
|
|
|
{
|
|
|
int acType = int.Parse(row["ActionType"].ToString());
|
|
|
if (acType != 22)
|
|
|
continue;
|
|
|
string empNo = row["EmpFrom"] == null ? "" : row["EmpFrom"].ToString();
|
|
|
//if (idx == 0)
|
|
|
//{
|
|
|
// //替换,如果还有审核意见的时候需要追加在最后面
|
|
|
// str = WorkCheckReplace(str, row, nodeID);
|
|
|
// if (isHaveWriteDB == true)
|
|
|
// {
|
|
|
// string wkVal = this.GetValueCheckWorkByKey(row, "WriteDB");
|
|
|
// string RDT = this.GetValueCheckWorkByKey(row, "RDT").Replace("-", "");
|
|
|
// RDT = RDT.Replace(":", "");
|
|
|
// RDT = RDT.Replace(" ", "");
|
|
|
// Int64 rdttime = Int64.Parse(RDT);
|
|
|
// if (DataType.IsNullOrEmpty(wkVal) == true)
|
|
|
// wkVal = "";
|
|
|
|
|
|
// //定义rtf中图片字符串.
|
|
|
// StringBuilder mypict = new StringBuilder();
|
|
|
// //将要插入的图片转换为16进制字符串
|
|
|
// byte[] buffer = Convert.FromBase64String(wkVal);
|
|
|
// MemoryStream ms = new MemoryStream(buffer);
|
|
|
// Bitmap bmpt = new Bitmap(ms);
|
|
|
// Image image = bmpt;
|
|
|
// if (image != null)
|
|
|
// {
|
|
|
// int width = image.Width;
|
|
|
// int height = image.Height;
|
|
|
// StringBuilder imgs = new StringBuilder();
|
|
|
// for (int i = 0; i < buffer.Length; i++)
|
|
|
// {
|
|
|
// if ((i % 32) == 0)
|
|
|
// {
|
|
|
// imgs.AppendLine();
|
|
|
// }
|
|
|
|
|
|
// byte num2 = buffer[i];
|
|
|
// int num3 = (num2 & 240) >> 4;
|
|
|
// int num4 = num2 & 15;
|
|
|
// imgs.Append("0123456789abcdef"[num3]);
|
|
|
// imgs.Append("0123456789abcdef"[num4]);
|
|
|
// }
|
|
|
// //转换
|
|
|
// //生成rtf中图片字符串
|
|
|
// mypict.AppendLine();
|
|
|
// mypict.Append(@"{\pict");
|
|
|
// mypict.Append(@"\jpegblip");
|
|
|
// mypict.Append(@"\picscalex100");
|
|
|
// mypict.Append(@"\picscaley100");
|
|
|
// mypict.Append(@"\picwgoal" + width * 3);
|
|
|
// mypict.Append(@"\pichgoal" + height * 3);
|
|
|
// mypict.Append(imgs.ToString() + "}");
|
|
|
// mypict.Append("\n");
|
|
|
// workCheckStr += mypict.ToString() + "\\par";
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// string md = "";
|
|
|
// if (row["RDT"]!= null)
|
|
|
// {
|
|
|
// string rdt = row["RDT"].ToString();
|
|
|
// DateTime date = DataType.ParseSysDate2DateTime(rdt);
|
|
|
// md = date.ToString("yyyy-MM-dd");
|
|
|
// }
|
|
|
|
|
|
// workCheckStr += row["EmpFromT"].ToString() + md + "\\par";
|
|
|
// }
|
|
|
// }
|
|
|
// idx++;
|
|
|
// continue;
|
|
|
|
|
|
//}
|
|
|
|
|
|
if (isHaveNote)
|
|
|
workCheckStr += this.GetValueCheckWorkByKey(row, "Msg") + "\\par";
|
|
|
if (isHaveRec)
|
|
|
workCheckStr += this.GetValueCheckWorkByKey(row, "EmpFrom") + "\\par";
|
|
|
if (isHaveRecName)
|
|
|
workCheckStr += this.GetValueCheckWorkByKey(row, "EmpFromT") + "\\par";
|
|
|
if (isHaveRDT)
|
|
|
workCheckStr += this.GetValueCheckWorkByKey(row, "RDT") + "\\par";
|
|
|
if (isHaveWriteDB)
|
|
|
{
|
|
|
string wkVal = this.GetValueCheckWorkByKey(row, "WriteDB");
|
|
|
string RDT = this.GetValueCheckWorkByKey(row, "RDT").Replace("-", "");
|
|
|
RDT = RDT.Replace(":", "");
|
|
|
RDT = RDT.Replace(" ", "");
|
|
|
Int64 rdttime = Int64.Parse(RDT);
|
|
|
if (DataType.IsNullOrEmpty(wkVal) == true)
|
|
|
wkVal = "";
|
|
|
|
|
|
//定义rtf中图片字符串.
|
|
|
StringBuilder mypict = new StringBuilder();
|
|
|
//将要插入的图片转换为16进制字符串
|
|
|
byte[] buffer = Convert.FromBase64String(wkVal);
|
|
|
MemoryStream ms = new MemoryStream(buffer);
|
|
|
Bitmap bmpt = new Bitmap(ms);
|
|
|
Image image = bmpt;
|
|
|
if (image != null)
|
|
|
{
|
|
|
int width = image.Width;
|
|
|
int height = image.Height;
|
|
|
StringBuilder imgs = new StringBuilder();
|
|
|
for (int i = 0; i < buffer.Length; i++)
|
|
|
{
|
|
|
if ((i % 32) == 0)
|
|
|
{
|
|
|
imgs.AppendLine();
|
|
|
}
|
|
|
|
|
|
byte num2 = buffer[i];
|
|
|
int num3 = (num2 & 240) >> 4;
|
|
|
int num4 = num2 & 15;
|
|
|
imgs.Append("0123456789abcdef"[num3]);
|
|
|
imgs.Append("0123456789abcdef"[num4]);
|
|
|
}
|
|
|
//转换
|
|
|
//生成rtf中图片字符串
|
|
|
mypict.AppendLine();
|
|
|
mypict.Append(@"{\pict");
|
|
|
mypict.Append(@"\jpegblip");
|
|
|
mypict.Append(@"\picscalex100");
|
|
|
mypict.Append(@"\picscaley100");
|
|
|
mypict.Append(@"\picwgoal" + width * 3);
|
|
|
mypict.Append(@"\pichgoal" + height * 3);
|
|
|
mypict.Append(imgs.ToString() + "}");
|
|
|
mypict.Append("\n");
|
|
|
workCheckStr += mypict.ToString() + "\\par";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string md = "";
|
|
|
if (row["RDT"] != null)
|
|
|
{
|
|
|
string rdt = row["RDT"].ToString();
|
|
|
DateTime date = DataType.ParseSysDate2DateTime(rdt);
|
|
|
md = date.ToString("yyyy-MM-dd");
|
|
|
}
|
|
|
|
|
|
workCheckStr += row["EmpFromT"].ToString() + md + "\\par";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
idx++;
|
|
|
}
|
|
|
if (workCheckStr.Equals(""))
|
|
|
{
|
|
|
string wkKey = "<WorkCheck.Note." + nodeID + ">";
|
|
|
str = str.Replace(wkKey, "");
|
|
|
wkKey = "<WorkCheck.Rec." + nodeID + ">";
|
|
|
str = str.Replace(wkKey, "");
|
|
|
wkKey = "<WorkCheck.RecName." + nodeID + ">";
|
|
|
str = str.Replace(wkKey, "");
|
|
|
wkKey = "<WorkCheck.RDT." + nodeID + ">";
|
|
|
str = str.Replace(wkKey, "");
|
|
|
wkKey = "<WorkCheck.RDT-NYR." + nodeID + ">";
|
|
|
str = str.Replace(wkKey, "");
|
|
|
wkKey = "<WorkCheck.Siganture." + nodeID + ">";
|
|
|
str = str.Replace(wkKey, "");
|
|
|
wkKey = "<WorkCheck.WriteDB." + nodeID + ">";
|
|
|
str = str.Replace(wkKey, "");
|
|
|
continue;
|
|
|
}
|
|
|
if (isHaveNote == true || isHaveRec == true || isHaveRecName == true || isHaveRDT == true || isHaveWriteDB == true)
|
|
|
{
|
|
|
bool isHaveChange = false;
|
|
|
if (isHaveNote == true)
|
|
|
{
|
|
|
str = str.Replace("<WorkCheck.Note." + nodeID + ">", workCheckStr);
|
|
|
isHaveChange = true;
|
|
|
}
|
|
|
|
|
|
if (isHaveRec == true && isHaveChange == false)
|
|
|
{
|
|
|
str = str.Replace("<WorkCheck.Rec." + nodeID + ">", workCheckStr);
|
|
|
isHaveChange = true;
|
|
|
}
|
|
|
|
|
|
if (isHaveRecName == true && isHaveChange == false)
|
|
|
{
|
|
|
str = str.Replace("<WorkCheck.RecName." + nodeID + ">", workCheckStr);
|
|
|
isHaveChange = true;
|
|
|
}
|
|
|
|
|
|
if (isHaveRDT == true && isHaveChange == false)
|
|
|
{
|
|
|
str = str.Replace("<WorkCheck.RDT." + nodeID + ">", workCheckStr);
|
|
|
isHaveChange = true;
|
|
|
}
|
|
|
|
|
|
if (isHaveWriteDB == true && isHaveChange == false)
|
|
|
{
|
|
|
str = str.Replace("<WorkCheck.WriteDB." + nodeID + ">", workCheckStr);
|
|
|
isHaveChange = true;
|
|
|
}
|
|
|
|
|
|
string wkKey = "<WorkCheck.Note." + nodeID + ">";
|
|
|
str = str.Replace(wkKey, "");
|
|
|
wkKey = "<WorkCheck.Rec." + nodeID + ">";
|
|
|
str = str.Replace(wkKey, "");
|
|
|
wkKey = "<WorkCheck.RecName." + nodeID + ">";
|
|
|
str = str.Replace(wkKey, "");
|
|
|
wkKey = "<WorkCheck.RDT." + nodeID + ">";
|
|
|
str = str.Replace(wkKey, "");
|
|
|
wkKey = "<WorkCheck.RDT-NYR." + nodeID + ">";
|
|
|
str = str.Replace(wkKey, "");
|
|
|
wkKey = "<WorkCheck.Siganture." + nodeID + ">";
|
|
|
str = str.Replace(wkKey, "");
|
|
|
wkKey = "<WorkCheck.WriteDB." + nodeID + ">";
|
|
|
str = str.Replace(wkKey, "");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
//if (dtTrack != null && str.Contains("<WorkCheckBegin>") == false && str.Contains("<WorkCheckEnd>") == false)
|
|
|
//{
|
|
|
// foreach (DataRow row in dtTrack.Rows) //此处的22是ActionType.WorkCheck的值,此枚举位于BP.WF项目中,此处暂写死此值
|
|
|
// {
|
|
|
// int acType = int.Parse(row["ActionType"].ToString());
|
|
|
// if (acType != 22)
|
|
|
// continue;
|
|
|
|
|
|
// //节点从.
|
|
|
// string nfFrom = row["NDFrom"].ToString();
|
|
|
|
|
|
// string wkKey = "<WorkCheck.Msg." + nfFrom + ">";
|
|
|
// string wkVal = this.GetCode(this.GetValueCheckWorkByKey(row, "Msg"));
|
|
|
// str = str.Replace(wkKey, wkVal);
|
|
|
|
|
|
// wkKey = "<WorkCheck.Rec." + nfFrom + ">";
|
|
|
// wkVal = this.GetCode(this.GetValueCheckWorkByKey(row, "EmpFromT"));
|
|
|
// str = str.Replace(wkKey, wkVal);
|
|
|
|
|
|
// wkKey = "<WorkCheck.RDT." + nfFrom + ">";
|
|
|
// wkVal = this.GetCode(this.GetValueCheckWorkByKey(row, "RDT"));
|
|
|
// str = str.Replace(wkKey, wkVal);
|
|
|
|
|
|
// wkKey = "<WorkCheck.RDT-NYR." + nfFrom + ">";
|
|
|
// wkVal = this.GetValueCheckWorkByKey(row, "RDT-NYR");
|
|
|
// str = str.Replace(wkKey, wkVal);
|
|
|
|
|
|
// //审核人的签名. 2020.11.28 by zhoupeng
|
|
|
// wkKey = "<WorkCheck.Siganture." + nfFrom + ">";
|
|
|
// if (str.Contains(wkKey) == true)
|
|
|
// {
|
|
|
// wkVal = this.GetCode(this.GetValueCheckWorkByKey(row, "EmpFrom"));
|
|
|
// String filePath = BP.Difference.SystemConfig.PathOfDataUser + "/Siganture/" + wkVal + ".jpg";
|
|
|
// //定义rtf中图片字符串.
|
|
|
// StringBuilder mypict = new StringBuilder();
|
|
|
// //获取要插入的图片
|
|
|
// System.Drawing.Image imgAth = System.Drawing.Image.FromFile(filePath);
|
|
|
|
|
|
// //将要插入的图片转换为16进制字符串
|
|
|
// string imgHexStringImgAth = GetImgHexString(imgAth, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
// //生成rtf中图片字符串
|
|
|
// mypict.AppendLine();
|
|
|
// mypict.Append(@"{\pict");
|
|
|
// mypict.Append(@"\jpegblip");
|
|
|
// mypict.Append(@"\picscalex100");
|
|
|
// mypict.Append(@"\picscaley100");
|
|
|
// mypict.Append(@"\picwgoal" + imgAth.Width * 15);
|
|
|
// mypict.Append(@"\pichgoal" + imgAth.Height * 15);
|
|
|
// mypict.Append(imgHexStringImgAth + "}");
|
|
|
// mypict.AppendLine();
|
|
|
// str = str.Replace(wkKey, mypict.ToString()); ;
|
|
|
// }
|
|
|
|
|
|
// //审核人的手写签名. 2020.11.28 by zhoupeng
|
|
|
// wkKey = "<WorkCheck.WriteDB." + nfFrom + ">";
|
|
|
// if (str.Contains(wkKey) == true)
|
|
|
// {
|
|
|
// wkVal = this.GetCode(this.GetValueCheckWorkByKey(row, "WriteDB"));
|
|
|
|
|
|
// //定义rtf中图片字符串.
|
|
|
// StringBuilder mypict = new StringBuilder();
|
|
|
|
|
|
// //将要插入的图片转换为16进制字符串
|
|
|
// byte[] buffer = Convert.FromBase64String(wkVal);
|
|
|
// StringBuilder imgs = new StringBuilder();
|
|
|
// for (int i = 0; i < buffer.Length; i++)
|
|
|
// {
|
|
|
// if ((i % 32) == 0)
|
|
|
// {
|
|
|
// imgs.AppendLine();
|
|
|
// }
|
|
|
// //else if ((i % 8) == 0)
|
|
|
// //{
|
|
|
// // imgs.Append(" ");
|
|
|
// //}
|
|
|
// byte num2 = buffer[i];
|
|
|
// int num3 = (num2 & 240) >> 4;
|
|
|
// int num4 = num2 & 15;
|
|
|
// imgs.Append("0123456789abcdef"[num3]);
|
|
|
// imgs.Append("0123456789abcdef"[num4]);
|
|
|
// }
|
|
|
// //生成rtf中图片字符串
|
|
|
// mypict.AppendLine();
|
|
|
// mypict.Append(@"{\pict");
|
|
|
// mypict.Append(@"\jpegblip");
|
|
|
// mypict.Append(@"\picscalex100");
|
|
|
// mypict.Append(@"\picscaley100");
|
|
|
// mypict.Append(@"\picwgoal" + 45 * 15);
|
|
|
// mypict.Append(@"\pichgoal" + 40 * 15);
|
|
|
// mypict.Append(imgs.ToString() + "}");
|
|
|
// mypict.AppendLine();
|
|
|
// str = str.Replace(wkKey, mypict.ToString()); ;
|
|
|
// }
|
|
|
|
|
|
|
|
|
// }
|
|
|
//}
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 多附件
|
|
|
foreach (string athObjEnsName in this.EnsDataAths.Keys)
|
|
|
{
|
|
|
string athName = "Ath." + athObjEnsName;
|
|
|
string athFilesName = "";
|
|
|
if (str.IndexOf(athName) == -1)
|
|
|
continue;
|
|
|
|
|
|
FrmAttachmentDBs athDbs = this.EnsDataAths[athObjEnsName] as FrmAttachmentDBs;
|
|
|
if (athDbs == null)
|
|
|
continue;
|
|
|
|
|
|
if (str.IndexOf("Ath." + athObjEnsName + ".ImgAth") != -1)
|
|
|
{
|
|
|
string wkKey = "<Ath." + athObjEnsName + ".ImgAth>";
|
|
|
string athImgs = "";
|
|
|
// 定义rtf中图片字符串
|
|
|
StringBuilder mypict = new StringBuilder();
|
|
|
System.Drawing.Image imgAth;
|
|
|
foreach (FrmAttachmentDB athDb in athDbs)
|
|
|
{
|
|
|
|
|
|
if (athFilesName.Length > 0)
|
|
|
{
|
|
|
athFilesName += " , ";
|
|
|
}
|
|
|
int i = athDb.FileFullName.LastIndexOf("UploadFile/");
|
|
|
athDb.FileFullName = athDb.FileFullName.Substring(i);
|
|
|
//String filePath = SystemConfig.PathOfDataUser + "UploadFile/" + athDb.FrmID + "/" + this.HisGEEntity.PKVal + "/" + athDb.FileName;
|
|
|
String filePath = SystemConfig.PathOfDataUser + athDb.FileFullName;
|
|
|
if (File.Exists(filePath) == false)
|
|
|
continue;
|
|
|
imgAth = System.Drawing.Image.FromFile(filePath);
|
|
|
System.Drawing.Image bmp = new System.Drawing.Bitmap(imgAth);
|
|
|
//imgAth.Dispose();
|
|
|
//将要插入的图片转换为16进制字符串
|
|
|
string imgHexStringImgAth = GetImgHexString(bmp, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
//生成rtf中图片字符串
|
|
|
mypict.AppendLine();
|
|
|
mypict.Append(@"{\pict");
|
|
|
mypict.Append(@"\jpegblip");
|
|
|
mypict.Append(@"\picscalex100");
|
|
|
mypict.Append(@"\picscaley100");
|
|
|
mypict.Append(@"\picwgoal" + bmp.Width * 16);
|
|
|
mypict.Append(@"\pichgoal" + bmp.Height * 12);
|
|
|
mypict.Append(imgHexStringImgAth + "}");
|
|
|
mypict.Append("\n");
|
|
|
athImgs = mypict.ToString();
|
|
|
|
|
|
}
|
|
|
if (athDbs.Count == 0)
|
|
|
athImgs = "";
|
|
|
str = str.Replace(wkKey, athImgs);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
foreach (FrmAttachmentDB athDb in athDbs)
|
|
|
{
|
|
|
if (athFilesName.Length > 0)
|
|
|
athFilesName += " , ";
|
|
|
|
|
|
athFilesName += athDb.FileName;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
str = str.Replace("<" + athName + ">", this.GetCode(athFilesName));
|
|
|
}
|
|
|
|
|
|
|
|
|
FrmAttachments ens = new FrmAttachments(ensStrs);
|
|
|
foreach (FrmAttachment en in ens)
|
|
|
{
|
|
|
if (str.IndexOf("Ath." + en.NoOfObj + ".ImgAth>") != -1)
|
|
|
{
|
|
|
str = str.Replace("<Ath." + en.NoOfObj + ".ImgAth>", "\\par");
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 要替换的字段
|
|
|
//if (replaceVals != null && replaceVals.Contains("@"))
|
|
|
//{
|
|
|
// string[] vals = replaceVals.Split('@');
|
|
|
// foreach (string val in vals)
|
|
|
// {
|
|
|
// if (val == null || val == "")
|
|
|
// continue;
|
|
|
|
|
|
// if (val.Contains("=") == false)
|
|
|
// continue;
|
|
|
|
|
|
// string myRep = val.Clone() as string;
|
|
|
|
|
|
// myRep = myRep.Trim();
|
|
|
// myRep = myRep.Replace("null", "");
|
|
|
// string[] myvals = myRep.Split('=');
|
|
|
// str = str.Replace("<" + myvals[0] + ">", "<" + myvals[1] + ">");
|
|
|
// }
|
|
|
//}
|
|
|
#endregion
|
|
|
|
|
|
StreamWriter wr = new StreamWriter(this.TempFilePath, false, Encoding.ASCII);
|
|
|
BP.DA.Log.DebugWriteError("第一次生成功word。");
|
|
|
|
|
|
str = str.Replace("<", "");
|
|
|
str = str.Replace(">", "");
|
|
|
wr.Write(str);
|
|
|
wr.Close();
|
|
|
|
|
|
//打印三维从表@ForBKGY
|
|
|
if (str.IndexOf("BP.3D") != -1)
|
|
|
{
|
|
|
string strAtpara = DBAccess.RunSQLReturnString("SELECT ATPARA FROM " + ensStrs + " WHERE OID ='" + this.HisGEEntity.PKVal.ToString() + "'");
|
|
|
AtPara at = new AtPara(strAtpara);
|
|
|
foreach (string strAtPara in at.HisHT.Keys)
|
|
|
{
|
|
|
if (dtlEnName3D.Equals(strAtPara) == false)
|
|
|
continue;
|
|
|
|
|
|
string valPara = at.GetValStrByKey(dtlEnName3D);
|
|
|
if (valPara != "")
|
|
|
{
|
|
|
string[] objs = valPara.Split(';');
|
|
|
foreach (string obj in objs)
|
|
|
{
|
|
|
string[] noName = obj.Split(':');
|
|
|
if (d3 == noName[0])
|
|
|
{
|
|
|
DataTable foundKEY = BP.DA.DBAccess.RunSQLReturnTable("SELECT INTKEY FROM SYS_ENUM where ENUMKEY ='" + d3 + "' and INTKEY not in(" + noName[1] + ")");
|
|
|
foreach (DataRow dr in foundKEY.Rows)
|
|
|
{
|
|
|
DataRow[] foundRow;
|
|
|
string sql3 = d3 + " IN (" + dr[0] + ")";
|
|
|
foundRow = dt3D.Select(sql3);
|
|
|
foreach (DataRow row in foundRow)
|
|
|
{
|
|
|
dt3D.Rows.Remove(row);
|
|
|
}
|
|
|
dt3D.AcceptChanges();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
BP.DA.Log.DebugWriteError("开始打印3dword。");
|
|
|
MDFORMDoc(dt3D, d1, d2, d3, dtlEnName3D, this.TempFilePath);
|
|
|
|
|
|
}
|
|
|
else if (str.IndexOf("BP.2D") != -1)
|
|
|
{
|
|
|
FORMDoc(dt3D, d1, d2, d3, dtlEnName3D, this.TempFilePath);
|
|
|
}
|
|
|
else if (str.IndexOf("BP.s2D") != -1)
|
|
|
{
|
|
|
FORMDocs(dt3D, d1, d2, d3, dtlEnName3D, this.TempFilePath);
|
|
|
}
|
|
|
else if (str.IndexOf("BP.B2D") != -1)
|
|
|
{
|
|
|
ZLYDFORMDoc(dt3D, d1, d2, d3,d4, dtlEnName3D, this.TempFilePath);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
string msg = "";
|
|
|
if (SystemConfig.isDebug)
|
|
|
{ // 异常可能与单据的配置有关系。
|
|
|
try
|
|
|
{
|
|
|
this.CyclostyleFilePath = SystemConfig.PathOfDataUser + "CyclostyleFile/" + templateRtfFile;
|
|
|
str = Cache.GetBillStr(templateRtfFile, false);
|
|
|
msg = "@已经成功的执行修复线 RepairLineV2,您重新发送一次或者,退后重新在发送一次,是否可以解决此问题";
|
|
|
}
|
|
|
catch (Exception ex1)
|
|
|
{
|
|
|
msg = "执行修复线失败. RepairLineV2 " + ex1.Message;
|
|
|
}
|
|
|
}
|
|
|
throw new Exception("生成文档失败:单据名称[" + this.CyclostyleFilePath + "] 异常信息:" + ex.Message + " @自动修复单据信息:" + msg);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
private string GetRtfStr(string rtfStr, string tag)
|
|
|
{
|
|
|
//移除这个分组标签
|
|
|
if (tag.Contains(".End"))
|
|
|
{
|
|
|
return rtfStr.Replace(tag, "");
|
|
|
}
|
|
|
|
|
|
if (BP.Difference.SystemConfig.CustomerNo.Equals("BKGY") == true)
|
|
|
{
|
|
|
string formID = this.HisGEEntity.EnDesc;
|
|
|
if (formID.IndexOf("工艺卡") == -1)
|
|
|
{
|
|
|
//技术协议和质量要点单独判断
|
|
|
int pos_rowKey = rtfStr.IndexOf(tag) + 1;
|
|
|
int row_start = -1, row_end = -1;
|
|
|
if (pos_rowKey > 0)
|
|
|
{
|
|
|
row_start = rtfStr.Substring(0, pos_rowKey).LastIndexOf("\\pard");
|
|
|
//int idx1 = rtfStr.Substring(pos_rowKey).IndexOf("\\par \\ltrrow");
|
|
|
int idx2 = rtfStr.Substring(pos_rowKey).IndexOf("\\par");
|
|
|
row_end = idx2 + 4;
|
|
|
/*if (idx2 != -1)
|
|
|
{
|
|
|
if(idx1 == idx2)
|
|
|
row_end = idx1 + 13;
|
|
|
if(idx2<idx1)
|
|
|
row_end = idx2 + 6;
|
|
|
}*/
|
|
|
}
|
|
|
if (row_start != -1 && row_end != -1)
|
|
|
rtfStr = rtfStr.Substring(0, row_start) + rtfStr.Substring(pos_rowKey).Substring(row_end);
|
|
|
|
|
|
return rtfStr;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
rtfStr = rtfStr.Replace(tag, "");
|
|
|
|
|
|
return rtfStr;
|
|
|
}
|
|
|
|
|
|
#region 生成单据
|
|
|
#region 生成单据
|
|
|
/// <summary>
|
|
|
/// 生成单据根据
|
|
|
/// </summary>
|
|
|
/// <param name="templeteFile">模板文件</param>
|
|
|
/// <param name="saveToFile"></param>
|
|
|
/// <param name="mainDT"></param>
|
|
|
/// <param name="dtls"></param>
|
|
|
public void MakeDocByDataSet(string templeteFile, string saveToPath,
|
|
|
string saveToFileName, DataTable mainDT, DataSet dtlsDS)
|
|
|
{
|
|
|
string valMain = DBAccess.RunSQLReturnString("SELECT NO FROM SYS_MapData");
|
|
|
this.HisGEEntity = new GEEntity(valMain);
|
|
|
this.HisGEEntity.Row.LoadDataTable(mainDT, mainDT.Rows[0]);
|
|
|
this.AddEn(this.HisGEEntity); //增加一个主表。
|
|
|
if (dtlsDS != null)
|
|
|
{
|
|
|
foreach (DataTable dt in dtlsDS.Tables)
|
|
|
{
|
|
|
string dtlID = DBAccess.RunSQLReturnString("SELECT NO FROM SYS_MapDtl ");
|
|
|
BP.Sys.GEDtls dtls = new BP.Sys.GEDtls(dtlID);
|
|
|
foreach (DataRow dr in dt.Rows)
|
|
|
{
|
|
|
BP.Sys.GEDtl dtl = dtls.GetNewEntity as BP.Sys.GEDtl;
|
|
|
dtl.Row.LoadDataTable(dt, dr);
|
|
|
dtls.AddEntity(dtl);
|
|
|
}
|
|
|
this.AddDtlEns(dtls); //增加一个明晰。
|
|
|
}
|
|
|
}
|
|
|
|
|
|
this.MakeDoc(templeteFile, saveToPath, saveToFileName);
|
|
|
}
|
|
|
#endregion
|
|
|
#endregion
|
|
|
private string WorkCheckReplace(string str, DataRow row, int nodeID)
|
|
|
{
|
|
|
string wkKey = "<WorkCheck.Note." + nodeID + ">";
|
|
|
string wkVal;
|
|
|
if (row != null && !"null".Equals(this.GetValueCheckWorkByKey(row, "Msg")))
|
|
|
{
|
|
|
wkVal = this.GetValueCheckWorkByKey(row, "Msg");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
wkVal = "";
|
|
|
}
|
|
|
str = str.Replace(wkKey, wkVal);
|
|
|
wkKey = "<WorkCheck.Rec." + nodeID + ">";
|
|
|
if (row != null)
|
|
|
{
|
|
|
wkVal = this.GetValueCheckWorkByKey(row, "EmpFrom");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
wkVal = "";
|
|
|
}
|
|
|
str = str.Replace(wkKey, wkVal);
|
|
|
wkKey = "<WorkCheck.RecName." + nodeID + ">";
|
|
|
if (row != null)
|
|
|
{
|
|
|
wkVal = this.GetValueCheckWorkByKey(row, "EmpFromT");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
wkVal = "";
|
|
|
}
|
|
|
str = str.Replace(wkKey, wkVal);
|
|
|
wkKey = "<WorkCheck.RDT." + nodeID + ">";
|
|
|
if (row != null)
|
|
|
{
|
|
|
wkVal = this.GetValueCheckWorkByKey(row, "RDT");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
wkVal = "";
|
|
|
}
|
|
|
str = str.Replace(wkKey, wkVal);
|
|
|
wkKey = "<WorkCheck.RDT-NYR." + nodeID + ">";
|
|
|
wkKey = "<WorkCheck.Siganture." + nodeID + ">";
|
|
|
if (str.IndexOf(wkKey) != -1)
|
|
|
{
|
|
|
if (row != null)
|
|
|
{
|
|
|
wkVal = this.GetCode(this.GetValueCheckWorkByKey(row, "EmpFrom"));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
wkVal = "";
|
|
|
}
|
|
|
String filePath = SystemConfig.PathOfDataUser + "/Siganture/" + wkVal + ".jpg";
|
|
|
if (File.Exists(filePath) == true)
|
|
|
{
|
|
|
// 定义rtf中图片字符串
|
|
|
StringBuilder mypict = new StringBuilder();
|
|
|
// 获取要插入的图片
|
|
|
// System.Drawing.Image img =
|
|
|
// System.Drawing.Image.FromFile(path);
|
|
|
//获取要插入的图片
|
|
|
System.Drawing.Image imgAth = System.Drawing.Image.FromFile(filePath);
|
|
|
|
|
|
//将要插入的图片转换为16进制字符串
|
|
|
string imgHexStringImgAth = GetImgHexString(imgAth, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
//生成rtf中图片字符串
|
|
|
mypict.AppendLine();
|
|
|
mypict.Append(@"{\pict");
|
|
|
mypict.Append(@"\jpegblip");
|
|
|
mypict.Append(@"\picscalex100");
|
|
|
mypict.Append(@"\picscaley100");
|
|
|
mypict.Append(@"\picwgoal" + imgAth.Width * 15);
|
|
|
mypict.Append(@"\pichgoal" + imgAth.Height * 15);
|
|
|
mypict.Append(imgHexStringImgAth + "}");
|
|
|
mypict.Append("\n");
|
|
|
str = str.Replace(wkKey, mypict.ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
str = "";
|
|
|
}
|
|
|
|
|
|
}
|
|
|
return str;
|
|
|
}
|
|
|
#region 方法
|
|
|
/// <summary>
|
|
|
/// RTFEngine
|
|
|
/// </summary>
|
|
|
public RTFEngine()
|
|
|
{
|
|
|
this._EnsDataDtls = null;
|
|
|
this._HisEns = null;
|
|
|
}
|
|
|
|
|
|
public RTFEngine(string rtfFile)
|
|
|
{
|
|
|
this._EnsDataDtls = null;
|
|
|
this._HisEns = null;
|
|
|
this._rtfStr = Cache.GetBillStr(rtfFile, false).Substring(0);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 传入的是单个实体
|
|
|
/// </summary>
|
|
|
/// <param name="en"></param>
|
|
|
public RTFEngine(Entity en)
|
|
|
{
|
|
|
this._EnsDataDtls = null;
|
|
|
this._HisEns = null;
|
|
|
this.HisGEEntity = en;
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
}
|