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(); } }
private void UpdateProgressBarMethod(object pb) { ProgressBar pp = (ProgressBar)pb; if (pp.Value == pp.Maximum) { pp.Value = 0; } del_do_update delupdate = new del_do_update(do_update); for (int i = pp.Value; i < pp.Maximum; i++) { pp.BeginInvoke(delupdate, new object[] { pp }); Thread.Sleep(10); } ListViewItem item = (ListViewItem)pp.Tag; LinkLabel l = ((LinkLabel)((EXControlListViewSubItem)item.SubItems[4]).MyControl); del_do_changetxt delchangetxt = new del_do_changetxt(ChangeTextMethod); l.BeginInvoke(delchangetxt, new object[] { l, "OK" }); }
private void UpdateProgressBarMethod(object pb) { ProgressBar pp = (ProgressBar) pb; if (pp.Value == pp.Maximum) pp.Value = 0; del_do_update delupdate = new del_do_update(do_update); for (int i = pp.Value; i < pp.Maximum; i++) { pp.BeginInvoke(delupdate, new object[] {pp}); Thread.Sleep(10); } ListViewItem item = (ListViewItem) pp.Tag; LinkLabel l = ((LinkLabel) ((EXControlListViewSubItem) item.SubItems[4]).MyControl); del_do_changetxt delchangetxt = new del_do_changetxt(ChangeTextMethod); l.BeginInvoke(delchangetxt, new object[] {l, "OK"}); }
/// <summary> /// 上传具体方法,根据关联的项目数循环上传至FTP /// </summary> /// <param name="filename">被上传的文件路径</param> /// <param name="serverpath">上传的项目所在的相对路径</param> /// <param name="pp">进度条控件</param> private void Upload1(string filename, string serverpath, ProgressBar pp) { //读取区间大小 int buffLength = 2048; byte[] buffer; FtpWebRequest reqFTP; FtpWebResponse uploadResponse = null; //上传数据流 Stream strm = null; //本地文件流 FileStream fs = null; //获取文件信息 FileInfo fileInf = new FileInfo(filename); try { if (!fileInf.Exists) { MessageBox.Show("文件不存在", "提示"); return; } } catch (Exception e1) { MessageBox.Show(e1.ToString(), "提示"); return; } ListViewItem item = (ListViewItem)pp.Tag; LinkLabel l = ((LinkLabel)((EXControlListViewSubItem)item.SubItems[4]).MyControl); del_do_update delupdate = new del_do_update(do_update); del_do_changetxt delchangetxt = new del_do_changetxt(ChangeTextMethod); //查询要上传至服务器的项目数 List <ProjectInfo> _prjlist = new List <ProjectInfo>(); if (!string.IsNullOrEmpty(item.SubItems[5].Text)) { _prjlist = ProjectInfoDao.getAllProjectInfoByPackID(new string[] { item.SubItems[5].Text }); } for (int i = 0; i < _prjlist.Count; i++) { if (!bool.Parse(item.Tag as string)) //中断 { break; } try { this.MakeDirectory(ftphost + _prjlist[i].Ftppath + serverpath); } catch (Exception) { MessageBox.Show("创建文件夹错误,可能目标文件夹已经存在", "提示"); } string uri = ftphost + _prjlist[i].Ftppath + serverpath + fileInf.Name; try { // 根据uri创建FtpWebRequest对象 reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri)); // ftp用户名和密码 reqFTP.Credentials = new NetworkCredential(this.username, this.password); reqFTP.Proxy = GlobalProxySelection.GetEmptyWebProxy(); // 默认为true,连接不会被关闭 // 在一个命令之后被执行 reqFTP.KeepAlive = false; // 指定执行什么命令 reqFTP.Method = WebRequestMethods.Ftp.UploadFile; // 指定数据传输类型 reqFTP.UseBinary = true; // 上传文件时通知服务器文件的大小 reqFTP.ContentLength = fileInf.Length; // 缓冲大小设置为2kb buffer = new byte[buffLength]; // 打开一个文件流 (System.IO.FileStream) 去读上传的文件 fs = fileInf.OpenRead(); strm = reqFTP.GetRequestStream(); int bytesRead; int hasread = 0; pp.BeginInvoke(delupdate, new object[] { pp, hasread, (int)fileInf.Length, i + 1, _prjlist.Count, _prjlist[i].Projectname }); while (bool.Parse(item.Tag as string)) //中断 { //Thread.Sleep(300); bytesRead = fs.Read(buffer, 0, buffer.Length); hasread += bytesRead; if (bytesRead == 0) { break; } strm.Write(buffer, 0, bytesRead); pp.BeginInvoke(delupdate, new object[] { pp, hasread, (int)fileInf.Length, i + 1, _prjlist.Count, _prjlist[i].Projectname }); } fs.Close(); strm.Close(); uploadResponse = (FtpWebResponse)reqFTP.GetResponse(); } catch (Exception e) { MessageBox.Show("上传到" + uri + "发生错误:" + e.ToString(), "提示"); pp.BeginInvoke(delupdate, new object[] { pp, (int)fileInf.Length, (int)fileInf.Length, i + 1, _prjlist.Count, _prjlist[i].Projectname }); } } l.BeginInvoke(delchangetxt, new object[] { l, "重传" }); if (uploadResponse != null) { uploadResponse.Close(); } if (fs != null) { fs.Close(); } if (strm != null) { strm.Close(); } }
private void Upload1(string filename, string serverpath, ProgressBar pp) { //读取区间大小 int buffLength = 2048; byte[] buffer; del_do_update delupdate = new del_do_update(do_update); FtpWebRequest reqFTP; FtpWebResponse uploadResponse = null; //上传数据流 Stream strm = null; //本地文件流 FileStream fs = null; FileInfo fileInf = new FileInfo(filename); string uri = serverpath + fileInf.Name; ListViewItem item = (ListViewItem)pp.Tag; LinkLabel l = ((LinkLabel)((EXControlListViewSubItem)item.SubItems[4]).MyControl); del_do_changetxt delchangetxt = new del_do_changetxt(ChangeTextMethod); try { // 根据uri创建FtpWebRequest对象 reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri)); // ftp用户名和密码 reqFTP.Credentials = new NetworkCredential(this.username, this.password); // 默认为true,连接不会被关闭 // 在一个命令之后被执行 reqFTP.KeepAlive = false; // 指定执行什么命令 reqFTP.Method = WebRequestMethods.Ftp.UploadFile; // 指定数据传输类型 reqFTP.UseBinary = true; // 上传文件时通知服务器文件的大小 reqFTP.ContentLength = fileInf.Length; //pp.Value=0; //pp.Maximum = (int)fileInf.Length; // 缓冲大小设置为2kb buffer = new byte[buffLength]; // 打开一个文件流 (System.IO.FileStream) 去读上传的文件 fs = fileInf.OpenRead(); strm = reqFTP.GetRequestStream(); int bytesRead; int hasread = 0; while (true) { bytesRead = fs.Read(buffer, 0, buffer.Length); hasread += bytesRead; if (bytesRead == 0) { break; } strm.Write(buffer, 0, bytesRead); pp.BeginInvoke(delupdate, new object[] { pp, hasread, (int)fileInf.Length }); } fs.Close(); strm.Close(); uploadResponse = (FtpWebResponse)reqFTP.GetResponse(); l.BeginInvoke(delchangetxt, new object[] { l, "重传" }); } catch (Exception) { l.BeginInvoke(delchangetxt, new object[] { l, "重传" }); } finally { if (uploadResponse != null) { uploadResponse.Close(); } if (fs != null) { fs.Close(); } if (strm != null) { strm.Close(); } } }