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
{
///
/// 静态上传方法
///
///
///
public static bool FlileUpload(string sFileName)
{
List list = new List();
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;
}
///
/// 静态上传方法,只传一次,并返回文件名称
///
///
///
public static string FlileUploadOnce(string sFileName)
{
List list = new List();
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 ChoiceFiles()
{
List fileList = new List();
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;
}
///
/// 上传FileBean集合
///
///
///
///
public static bool FlileUpload2(List fileList, string filePath)
{
foreach (FileBean file in fileList)
{
file.setPathName(filePath);
}
return FileHelper.Upload(fileList);
}
///
/// FineReport创建PDF文件保存
///
/// 报表路径
/// 保存路径
/// 文件名
///
public static bool CreatePdfToFtp(string reportPath, string savePath, string pdfName)
{
WebClient webClient = new WebClient();
List listPdf = new List();
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);
}
}
}