| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Collections;
- using Core.Mes.Client.Comm.Server;
- using System.Data;
- using Core.Mes.Client.Comm;
- using System.Net;
- using Core.Mes.Client.Comm.Tool;
- namespace Core.Mes.Client.Comm.Server
- {
- public partial class FlileUploadcomm
- {
- /// <summary>
- /// 静态上传方法
- /// </summary>
- /// <param name="sFileName"></param>
- /// <returns></returns>
- public static bool FlileUpload(string sFileName)
- {
- List<FileBean> list = new List<FileBean>();
- FileBean bean = new FileBean();
- OpenFileDialog file = new OpenFileDialog();
- file.Multiselect = true;
- file.Title = "选择需要上传的文件";
- DialogResult drStat; //LX 修改
- drStat = file.ShowDialog(); //LX 修改
- if (drStat == DialogResult.OK) //|| file.ShowDialog() == DialogResult.Yes ---LX 修改
- {
- foreach (string fileName in file.FileNames)
- {
- bean = new FileBean();
- string filena = System.IO.Path.GetFileName(fileName);
- bean.setFileName(filena);
- bean.setPathName(sFileName);
- bean.setFile(FileHelper.FileToArray(fileName));
- list.Add(bean);
- }
- bool isSuccess = Core.Mes.Client.Comm.Server.FileHelper.Upload(list);
- if (isSuccess)
- {
- MessageBox.Show("上传成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- return false;
-
- }
- /// <summary>
- /// 静态上传方法,只传一次,并返回文件名称
- /// </summary>
- /// <param name="sFileName"></param>
- /// <returns></returns>
- public static string FlileUploadOnce(string sFileName)
- {
- List<FileBean> list = new List<FileBean>();
- FileBean bean = new FileBean();
- OpenFileDialog file = new OpenFileDialog();
- file.Multiselect = false;
- DialogResult drStat; //LX 修改
- drStat = file.ShowDialog(); //LX 修改
- if (drStat == DialogResult.OK) //|| file.ShowDialog() == DialogResult.Yes ---LX 修改
- {
- string fileName = file.FileName;
- bean = new FileBean();
- string filena = System.IO.Path.GetFileName(fileName);
- bean.setFileName(filena);
- bean.setPathName(sFileName);
- bean.setFile(FileHelper.FileToArray(fileName));
- list.Add(bean);
- bool isSuccess = Core.Mes.Client.Comm.Server.FileHelper.Upload(list);
- if (isSuccess)
- {
- MessageBox.Show("上传成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
- return filena;
- }
- else
- {
- return "";
- }
- }
- else
- return "";
- }
- public static List<FileBean> ChoiceFiles()
- {
- List<FileBean> fileList = new List<FileBean>();
- OpenFileDialog file = new OpenFileDialog();
- file.Multiselect = true;
- DialogResult drStat = file.ShowDialog();
- if (drStat == DialogResult.OK) //|| file.ShowDialog() == DialogResult.Yes ---LX 修改
- {
- foreach (string fileName in file.FileNames)
- {
- FileBean bean = new FileBean();
- string filena = System.IO.Path.GetFileName(fileName);
- bean.setFileName(filena);
- bean.setFile(FileHelper.FileToArray(fileName));
- fileList.Add(bean);
- }
- }
- return fileList;
- }
- /// <summary>
- /// 上传FileBean集合
- /// </summary>
- /// <param name="fileList"></param>
- /// <param name="filePath"></param>
- /// <returns></returns>
- public static bool FlileUpload2(List<FileBean> fileList, string filePath)
- {
- foreach (FileBean file in fileList)
- {
- file.setPathName(filePath);
- }
- return FileHelper.Upload(fileList);
- }
- /// <summary>
- /// FineReport创建PDF文件保存
- /// </summary>
- /// <param name="reportPath">报表路径</param>
- /// <param name="savePath">保存路径</param>
- /// <param name="pdfName">文件名</param>
- /// <returns></returns>
- public static bool CreatePdfToFtp(string reportPath, string savePath, string pdfName)
- {
- WebClient webClient = new WebClient();
- List<FileBean> listPdf = new List<FileBean>();
- string filePathNew = savePath;
- string filePath = filePathNew + pdfName + ".pdf";
- //string strurl = "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=RepTechOrderLineCraft.cpt&bypagesize=false&format=pdf&embed=true"
- // + "&desgin_key=" + "640b567c9327406091ab757a38dfcdd7" + "&lnpk=" + "DA6638B13DE10148E053AC10026C978F006";
- //string strurl = reportPath;
- byte[] pdf = webClient.DownloadData(reportPath);
- if (pdf.Length <= 10000)
- {
- MessageUtil.ShowError("生成PDF出错,请重新生成!");
- return false;
- }
- FileBean fileBean = new FileBean();
- fileBean.setFile(pdf);
- fileBean.setFileName(pdfName + ".pdf");
- fileBean.setPathName(filePathNew);
- listPdf.Add(fileBean);
- webClient.Dispose();
- return FileHelper.Upload(listPdf);
- }
- }
- }
|