FileUploadcomm.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using System.Collections;
  7. using Core.Mes.Client.Comm.Server;
  8. using System.Data;
  9. using Core.Mes.Client.Comm;
  10. using System.Net;
  11. using Core.Mes.Client.Comm.Tool;
  12. namespace Core.Mes.Client.Comm.Server
  13. {
  14. public partial class FlileUploadcomm
  15. {
  16. /// <summary>
  17. /// 静态上传方法
  18. /// </summary>
  19. /// <param name="sFileName"></param>
  20. /// <returns></returns>
  21. public static bool FlileUpload(string sFileName)
  22. {
  23. List<FileBean> list = new List<FileBean>();
  24. FileBean bean = new FileBean();
  25. OpenFileDialog file = new OpenFileDialog();
  26. file.Multiselect = true;
  27. file.Title = "选择需要上传的文件";
  28. DialogResult drStat; //LX 修改
  29. drStat = file.ShowDialog(); //LX 修改
  30. if (drStat == DialogResult.OK) //|| file.ShowDialog() == DialogResult.Yes ---LX 修改
  31. {
  32. foreach (string fileName in file.FileNames)
  33. {
  34. bean = new FileBean();
  35. string filena = System.IO.Path.GetFileName(fileName);
  36. bean.setFileName(filena);
  37. bean.setPathName(sFileName);
  38. bean.setFile(FileHelper.FileToArray(fileName));
  39. list.Add(bean);
  40. }
  41. bool isSuccess = Core.Mes.Client.Comm.Server.FileHelper.Upload(list);
  42. if (isSuccess)
  43. {
  44. MessageBox.Show("上传成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
  45. return true;
  46. }
  47. else
  48. {
  49. return false;
  50. }
  51. }
  52. else
  53. return false;
  54. }
  55. /// <summary>
  56. /// 静态上传方法,只传一次,并返回文件名称
  57. /// </summary>
  58. /// <param name="sFileName"></param>
  59. /// <returns></returns>
  60. public static string FlileUploadOnce(string sFileName)
  61. {
  62. List<FileBean> list = new List<FileBean>();
  63. FileBean bean = new FileBean();
  64. OpenFileDialog file = new OpenFileDialog();
  65. file.Multiselect = false;
  66. DialogResult drStat; //LX 修改
  67. drStat = file.ShowDialog(); //LX 修改
  68. if (drStat == DialogResult.OK) //|| file.ShowDialog() == DialogResult.Yes ---LX 修改
  69. {
  70. string fileName = file.FileName;
  71. bean = new FileBean();
  72. string filena = System.IO.Path.GetFileName(fileName);
  73. bean.setFileName(filena);
  74. bean.setPathName(sFileName);
  75. bean.setFile(FileHelper.FileToArray(fileName));
  76. list.Add(bean);
  77. bool isSuccess = Core.Mes.Client.Comm.Server.FileHelper.Upload(list);
  78. if (isSuccess)
  79. {
  80. MessageBox.Show("上传成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
  81. return filena;
  82. }
  83. else
  84. {
  85. return "";
  86. }
  87. }
  88. else
  89. return "";
  90. }
  91. public static List<FileBean> ChoiceFiles()
  92. {
  93. List<FileBean> fileList = new List<FileBean>();
  94. OpenFileDialog file = new OpenFileDialog();
  95. file.Multiselect = true;
  96. DialogResult drStat = file.ShowDialog();
  97. if (drStat == DialogResult.OK) //|| file.ShowDialog() == DialogResult.Yes ---LX 修改
  98. {
  99. foreach (string fileName in file.FileNames)
  100. {
  101. FileBean bean = new FileBean();
  102. string filena = System.IO.Path.GetFileName(fileName);
  103. bean.setFileName(filena);
  104. bean.setFile(FileHelper.FileToArray(fileName));
  105. fileList.Add(bean);
  106. }
  107. }
  108. return fileList;
  109. }
  110. /// <summary>
  111. /// 上传FileBean集合
  112. /// </summary>
  113. /// <param name="fileList"></param>
  114. /// <param name="filePath"></param>
  115. /// <returns></returns>
  116. public static bool FlileUpload2(List<FileBean> fileList, string filePath)
  117. {
  118. foreach (FileBean file in fileList)
  119. {
  120. file.setPathName(filePath);
  121. }
  122. return FileHelper.Upload(fileList);
  123. }
  124. /// <summary>
  125. /// FineReport创建PDF文件保存
  126. /// </summary>
  127. /// <param name="reportPath">报表路径</param>
  128. /// <param name="savePath">保存路径</param>
  129. /// <param name="pdfName">文件名</param>
  130. /// <returns></returns>
  131. public static bool CreatePdfToFtp(string reportPath, string savePath, string pdfName)
  132. {
  133. WebClient webClient = new WebClient();
  134. List<FileBean> listPdf = new List<FileBean>();
  135. string filePathNew = savePath;
  136. string filePath = filePathNew + pdfName + ".pdf";
  137. //string strurl = "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=RepTechOrderLineCraft.cpt&bypagesize=false&format=pdf&embed=true"
  138. // + "&desgin_key=" + "640b567c9327406091ab757a38dfcdd7" + "&lnpk=" + "DA6638B13DE10148E053AC10026C978F006";
  139. //string strurl = reportPath;
  140. byte[] pdf = webClient.DownloadData(reportPath);
  141. if (pdf.Length <= 10000)
  142. {
  143. MessageUtil.ShowError("生成PDF出错,请重新生成!");
  144. return false;
  145. }
  146. FileBean fileBean = new FileBean();
  147. fileBean.setFile(pdf);
  148. fileBean.setFileName(pdfName + ".pdf");
  149. fileBean.setPathName(filePathNew);
  150. listPdf.Add(fileBean);
  151. webClient.Dispose();
  152. return FileHelper.Upload(listPdf);
  153. }
  154. }
  155. }