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(); } }
void Button2Click(object sender, EventArgs e) { if (this.textBox1.Text == null || this.textBox1.Text.Equals("")) { MessageBox.Show("请选择保存路径", "提示"); return; } string begin = this.dateTimePicker1.Value.ToShortDateString() + " 00:00:00"; string end = this.dateTimePicker2.Value.ToShortDateString() + " 23:59:59"; Thread th = new Thread(new ParameterizedThreadStart(ThreadFunc)); ReportPara rp = new ReportPara(); rp.Path = this.textBox1.Text; rp.Begintime = begin; rp.Endtime = end; th.Start(rp); }