QcmFile.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using Core.Mes.Client.Comm;
  2. using Core.Mes.Client.Comm.Server;
  3. using Core.Mes.Client.Comm.Tool;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Drawing;
  7. using System.Windows.Forms;
  8. namespace Core.StlMes.Client.Qcm
  9. {
  10. public class QcmFile
  11. {
  12. // 123 IShellView
  13. public static string FlileUpload(string sFileName)
  14. {
  15. List<FileBean> list = new List<FileBean>();
  16. string[] slist = new string[100];
  17. FileBean bean = new FileBean();
  18. OpenFileDialog file = new OpenFileDialog();
  19. file.Filter = "图片文件(*.jpg);(*.gif);(*.png);(*.bmp)|*.jpg;*.gif;*.png;*.bmp";
  20. file.Multiselect = false;
  21. string path = "";
  22. //file.RES
  23. if (file.ShowDialog() == DialogResult.OK)
  24. {
  25. bean = new FileBean();
  26. string fileType = file.FileName.Split('.')[file.FileName.Split('.').Length - 1];
  27. string fileName = DateTime.Now.ToString("yyyyMMddHHmmss.") + fileType;
  28. bean.setFileName(fileName);
  29. bean.setPathName(sFileName);
  30. bean.setFile(FileHelper.FileToArray(file.FileName));
  31. list.Add(bean);
  32. path = sFileName + "/" + fileName;
  33. bool isSuccess = Core.Mes.Client.Comm.Server.FileHelper.Upload(list);
  34. if (isSuccess)
  35. {
  36. MessageUtil.ShowTips("上传成功!");
  37. }
  38. else
  39. {
  40. throw new MESException("服务端处理失败!");
  41. }
  42. return path;
  43. }
  44. else
  45. {
  46. return "";
  47. }
  48. }
  49. public static Bitmap FileDownLoad(string path)
  50. {
  51. if (path == "") return null;
  52. try
  53. {
  54. List<FileBean> bean = FileHelper.Download(path);
  55. if (bean.Count == 0) return null;
  56. return FileHelper.BytesToBitmap(bean[0].getFile());
  57. }
  58. catch (Exception ex)
  59. {
  60. return null;
  61. }
  62. }
  63. }
  64. }