/// <summary>
/// 批量导出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void exportWord_Click(object sender, EventArgs e)
{
hfSelectedIDS.Text = Common.SyncSelectedRowIndexArrayToHiddenField(hfSelectedIDS.Text, Grid1);
List<int> ids = Common.GetSelectedRowIndexArrayFromHiddenField(hfSelectedIDS.Text);
if (ids.Count == 0)
{
Alert.Show("至少选择一个委托单!");
return;
}
FileName.Text = DateTime.Now.ToString("yyyyMMddhhmmss") + ".docx";
string SavaFilesPath = Server.MapPath(("~\UploadFiles\") + FileName.Text);
string DotFileName = Server.MapPath("~\dot\") + "JS-41120.docx";
Novacode.DocX wordDocTmp = null;
Novacode.DocX wordDoc = null;
int i = 0;
string SavaFilesPath2 = Server.MapPath(("~\UploadFiles\") + FileName.Text);
string DotFileName2 = Server.MapPath("~\dot\") + "20200710015323.docx";
Novacode.DocX wordDoc2 = null;
foreach (int AID in ids)
{
wordDoc = WordReportDocX.LoadTemplateDocument(DotFileName);
wordDoc2 = WordReportDocX.LoadTemplateDocument(DotFileName2);
try
{
DataTable dt = Govaze.SQLServerDAL.Factory.getDataXmlDAL().ProcDataTable("<root><Type>ApplicationInfo</Type><AID>" + AID.ToString() + "</AID></root>", "DataXmlApplication");
DataTable dtTestItem = Govaze.SQLServerDAL.Factory.getDataXmlDAL().ProcDataTable("<root><Type>SYXM</Type><KeyWord>金属检测</KeyWord></root>", "DataXmlProject");
//涡流、金相检测项目放到其他内;从结果中移除涡流、金相
DataRow[] drS = dtTestItem.Select("ObjectName = '涡流' or ObjectName = '金相'");
foreach (DataRow dr in drS)
{
dtTestItem.Rows.Remove(dr);
}
var rows = dtTestItem.Rows.Cast<DataRow>();
string[] ObjectNames = rows.Select(d => d.Field<string>("ObjectName")).Skip(0).Take(4).ToArray();
StringBuilder p = new StringBuilder();
p.Append("□" + String.Join(" □", ObjectNames));
for (int n = 1; n <= (dtTestItem.Rows.Count / 4); n++)
{
ObjectNames = rows.Select(d => d.Field<string>("ObjectName")).Skip(n * 4).Take(4).ToArray();
p.AppendLine("□" + String.Join(" □", ObjectNames));
}
WordReportDocX.InsertText(wordDoc, "$KeyWord$", dt.Rows[0]["KeyWord"].ToString());
WordReportDocX.InsertText(wordDoc, "$SnID$", dt.Rows[0]["SnID"].ToString());
WordReportDocX.InsertText(wordDoc, "$KeyWord$", dt.Rows[0]["KeyWord"].ToString());
WordReportDocX.InsertText(wordDoc, "$SnID$", dt.Rows[0]["SnID"].ToString());
string EntryType = dt.Rows[0]["EntryType"].ToString();
if (EntryType == "涡流" || EntryType == "金相")
{
EntryType = "其他";
}
WordReportDocX.InsertText(wordDoc, "$EntryType$", p.ToString().Replace("□" + EntryType, "☑" + EntryType));
WordReportDocX.InsertText(wordDoc, "$Text1$", dt.Rows[0]["Text1"].ToString());
WordReportDocX.InsertText(wordDoc, "$Text2$", dt.Rows[0]["Text2"].ToString());
WordReportDocX.InsertText(wordDoc, "$Text3$", dt.Rows[0]["Text3"].ToString());
WordReportDocX.InsertText(wordDoc, "$Text4$", dt.Rows[0]["Text4"].ToString());
WordReportDocX.InsertText(wordDoc, "$Text5$", dt.Rows[0]["Text5"].ToString());
WordReportDocX.InsertText(wordDoc, "$Cperson2$", dt.Rows[0]["Cperson2"].ToString());
WordReportDocX.InsertText(wordDoc, "$CreateTime2$", dt.Rows[0]["CreateTime2"].ToString());
}
catch
{
Alert.Show("加载流程数据失败!");
}
List<d_YWZC_dis_Sample_TestItem_CE_Model> list2 = Govaze.SQLServerDAL.Factory.geta17025DAL().d_YWZC_dis_Report_SYD_bySampleAID_TestItem(AID, getUserName());
if (list2.Count > 10)
{
WordReportDocX.AddRow(wordDoc2, 1, list2.Count - 10);
}
int rowNumber = 6;
foreach (d_YWZC_dis_Sample_TestItem_CE_Model s in list2)
{
if (rowNumber <= 15)
{
WordReportDocX.InsertCell(wordDoc, 1, rowNumber, 1, s.Text001);
WordReportDocX.InsertCell(wordDoc, 1, rowNumber, 2, s.Text002);
WordReportDocX.InsertCell(wordDoc, 1, rowNumber, 3, s.ItemName);
WordReportDocX.InsertCell(wordDoc, 1, rowNumber, 4, s.Text003);
WordReportDocX.InsertCell(wordDoc, 1, rowNumber, 5, s.ItemName1);
WordReportDocX.InsertCell(wordDoc, 2, rowNumber, 1, s.Text001);
WordReportDocX.InsertCell(wordDoc, 2, rowNumber, 2, s.Text002);
WordReportDocX.InsertCell(wordDoc, 2, rowNumber, 3, s.ItemName);
WordReportDocX.InsertCell(wordDoc, 2, rowNumber, 4, s.Text003);
WordReportDocX.InsertCell(wordDoc, 2, rowNumber, 5, s.ItemName1);
WordReportDocX.InsertCell(wordDoc, 3, rowNumber, 1, s.Text001);
WordReportDocX.InsertCell(wordDoc, 3, rowNumber, 2, s.Text002);
WordReportDocX.InsertCell(wordDoc, 3, rowNumber, 3, s.ItemName);
WordReportDocX.InsertCell(wordDoc, 3, rowNumber, 4, s.Text003);
WordReportDocX.InsertCell(wordDoc, 3, rowNumber, 5, s.ItemName1);
}
else
{
WordReportDocX.InsertCell(wordDoc2, 1, rowNumber - 14, 1, s.Text001);
WordReportDocX.InsertCell(wordDoc2, 1, rowNumber - 14, 2, s.Text002);
WordReportDocX.InsertCell(wordDoc2, 1, rowNumber - 14, 3, s.ItemName);
WordReportDocX.InsertCell(wordDoc2, 1, rowNumber - 14, 4, s.Text003);
WordReportDocX.InsertCell(wordDoc2, 1, rowNumber - 14, 5, s.ItemName1);
}
rowNumber++;
}
if (list2.Count > 10)
{
wordDoc.Paragraphs[wordDoc.Paragraphs.Count - 1].InsertPageBreakAfterSelf();
wordDoc.InsertDocument(wordDoc2);
WordReportDocX.AddRow(wordDoc2, 1, list2.Count - 10);
}
if (i == 0)
{
wordDoc.SaveAs(SavaFilesPath);
wordDocTmp = WordReportDocX.LoadTemplateDocument(SavaFilesPath);
}
else
{
wordDocTmp.Paragraphs[wordDocTmp.Paragraphs.Count - 1].InsertPageBreakAfterSelf();
wordDocTmp.InsertDocument(wordDoc);
}
i++;
List<d_YWZC_dis_Main_Attach_Model> list = Govaze.SQLServerDAL.Factory.getCB719DAL().d_YWZC_dis_Main_Attach(AID, getUserName());
if (list.Count > 0)
{
for (int j = 0; j < list.Count; j++)
{
if (list[j].DocPath.Contains("doc") || list[j].DocPath.Contains("docx"))
{
wordDoc2 = WordReportDocX.LoadTemplateDocument(Server.MapPath(("~\UploadFiles\SYLCAttachFile\") + list[j].DocPath));
wordDocTmp.Paragraphs[wordDocTmp.Paragraphs.Count - 1].InsertPageBreakAfterSelf();
wordDocTmp.InsertDocument(wordDoc2);
}
}
}
}
wordDocTmp.SaveAs(SavaFilesPath);
Document Doc = new Document(SavaFilesPath);
Doc.Save(SavaFilesPath, SaveFormat.Docx);
FileName.Text = SavaFilesPath;
WindowWord.Hidden = false;
PageContext.RegisterStartupScript(WindowWord.GetHidePostBackReference());
return;
}