void CreateTestUnit(string unitdocTpl, string tempdocpath, string unitdocpath) { PackageInfo pi = PackageDao.getPackageInfoByID(tu.Packageid.ToString()); WordDocumentMerger wm = new WordDocumentMerger(); try { wm.Open(unitdocTpl); wm.WriteIntoMarkBook("AdminName", tu.Adminname); wm.WriteIntoMarkBook("BUGLevel", tu.Buglevel); wm.WriteIntoMarkBook("BUGType", tu.Bugtype); wm.WriteIntoMarkBook("UnitNO", tu.Unitno); wm.WriteIntoMarkBook("ModuleName", tu.Modulename); wm.WriteIntoMarkBook("NO", tu.Unitno); wm.WriteIntoMarkBook("PackageName", pi.Packagepath); wm.WriteIntoMarkBook("ProjectName", tu.Projectname); wm.WriteIntoMarkBook("TestTime", tu.Testtime); wm.WriteIntoMarkBook("Title", tu.Testtitle); wm.InsertMerge(new string[] { tempdocpath }, "Content"); wm.Save(unitdocpath); } catch (Exception e) { MessageBox.Show("生成测试单元文档失败!"); } finally { wm.Quit(); } }
void ThreadFunc(object obj) { ReportPara rp = (ReportPara)obj; string begin = rp.Begintime; string end = rp.Endtime; string path = rp.Path; del_do_changetxt delchangetxt = new del_do_changetxt(do_changetxt); this.BeginInvoke(delchangetxt, new object[] { "正在启动WORD", 10 }); WordDocumentMerger wm = new WordDocumentMerger(); try { if (unitDOCpath == null || "".Equals(unitDOCpath)) { unitDOCpath = this.defaultpath; } this.BeginInvoke(delchangetxt, new object[] { "正在打开模版", 20 }); //打开模版 wm.Open(defaultpath + @"\temp\TestReport.doc"); //查询数据库 this.BeginInvoke(delchangetxt, new object[] { "正在查询数据库", 30 }); DataTable table1 = PackageDao.getRePortPack(begin, end); DataTable table2 = TestUnitDao.getRePortTest(begin, end); DataTable packdt = PackageDao.getRePortPackNUM(begin, end); DataTable testbugleveldt = TestUnitDao.getRePortBugLevel(begin, end); DataTable testAllBug = TestUnitDao.getRePortBugLevelAll(begin, end); DataTable testbugnumdt = TestUnitDao.getRePortBugNum(begin, end); DataTable testbugrate = TestUnitDao.getRePortBugRate(begin, end); DataTable testbugtype = TestUnitDao.getRePortBugType(begin, end); //插入标签 this.BeginInvoke(delchangetxt, new object[] { "正在插入数据", 60 }); wm.WriteIntoMarkBook("测试报告名称", "权力运行许可平台"); wm.WriteIntoMarkBook("测试时间起", begin); wm.WriteIntoMarkBook("测试时间至", end); wm.WriteIntoMarkBook("更新包个数", table1.Rows.Count.ToString()); wm.insertTable("成功率表格", packdt); wm.WriteIntoMarkBook("BUG个数", table2.Rows.Count.ToString()); this.BeginInvoke(delchangetxt, new object[] { "正在绘制图表和表格", 80 }); wm.InsertChartFromBK("BUG等级饼图", testAllBug); wm.InsertChartFromBK("BUG趋势折线图", testbugnumdt); wm.InsertChartFromBK("BUG概率估算柱状图", testbugrate); wm.insertTable("BUG等级表格", testbugleveldt); wm.insertTable("BUG类型表格", testbugtype); wm.insertTableForPack("测试对象表格", table1); wm.insertTableForTest("测试缺陷表格", table2); this.BeginInvoke(delchangetxt, new object[] { "完成", 100 }); wm.SaveAs(path.ToString()); MessageBox.Show("保存成功", "提示"); } catch (Exception e1) { MessageBox.Show(e1.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { wm.Quit(); } }