| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Windows.Forms;
- using Core.Mes.Client.Comm.Tool;
- using Core.StlMes.Client.LgResMgt.Mcms.entity;
- using CoreFS.CA06;
- using Infragistics.Win.UltraWinGrid;
- using System.Net;
- using System.Reflection;
- using System.IO;
- using System.Threading;
- namespace Core.StlMes.Client.LgResMgt.Mcms
- {
- public partial class frmLocalTruckImageShow : FrmBase
- {
- public frmLocalTruckImageShow(OpeBase _ob)
- {
- InitializeComponent();
- ob = _ob;
- }
- FtpWebRequest reqFTP;
- private static object sync = new object();
- private static frmLocalTruckImageShow instance;
- private static readonly string _path = Environment.CurrentDirectory + "\\imgShort\\picture";
- // 有参数
- private CmmWeightResultEntity parame;
- private CmmBaseSpotInfoEntity spot;
- Dictionary<string, List<string>> dic = new Dictionary<string, List<string>>();
- Dictionary<string, string> dicPic;
- int ipic = 0;
- public static frmLocalTruckImageShow GetSingleton(OpeBase _ob, CmmWeightResultEntity parame, CmmBaseSpotInfoEntity spot)
- {
- lock (sync)
- {
- ;
- if (instance == null || instance.IsDisposed)
- instance = new frmLocalTruckImageShow(_ob);
- instance.parame = parame;
- instance.spot = spot;
- }
- return instance;
- }
- void ftpDown( string picName)
- {
- string[] files = picName.Split(new char[] { '/' });
- try
- {
- //①读取FTP上的文件
- // FileStream outputStream = new FileStream(LocalDir, FileMode.Create);//建立FTP链接
- if (File.Exists(_path + "\\" + files[files.Length - 1]))
- {
- File.Delete(_path + "\\" + files[files.Length - 1]);
- }
- FileStream outputStream = new FileStream(_path + "\\" + files[files.Length-1], FileMode.Create);
- reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://"+spot.FtpIp + spot.Ftppath + picName));//读取FTP上的文件
- reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;//FTP下载协议
- reqFTP.UseBinary = true;//指定文件传输类型
- reqFTP.Credentials = new NetworkCredential(spot.FtpUserName, spot.FtpPassword);//FTP通信凭证(即登录ftp)
- FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();//登录成功
- //②将FTP上的文件内容转化成数据流
- Stream ftpStream = response.GetResponseStream();//将FTP上的文件转化为数据流
- int bufferSize = 2048;//缓冲大小,单位byte
- byte[] buffer = new byte[bufferSize];//数据包
- int readCount;//循环次数
- readCount = ftpStream.Read(buffer, 0, bufferSize);//计算循环次数
- //③将FTP文件内容写入到本地空文件中去
- while (readCount > 0)
- {
- outputStream.Write(buffer, 0, readCount);//写入每一次读取的数据流
- readCount = ftpStream.Read(buffer, 0, bufferSize);//重新计算次数
- }
- //④关闭IO
- ftpStream.Close();
- outputStream.Close();
- response.Close();
- setPicBoxSet(_path + "\\" + files[files.Length - 1]);
- }
- catch (Exception ex)
- {
-
- }
-
- }
- /// <summary>
- /// 加载
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void frmLocalTruckImageShow_Load(object sender, EventArgs e)
- {
- if (!Directory.Exists(_path))
- {
- Directory.CreateDirectory(_path);
- }
- try
- {
- DirectoryInfo dir = new DirectoryInfo(_path);
- FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录
- foreach (FileSystemInfo i in fileinfo)
- {
- if (i is DirectoryInfo) //判断是否文件夹
- {
- DirectoryInfo subdir = new DirectoryInfo(i.FullName);
- subdir.Delete(true); //删除子目录和文件
- }
- else
- {
- File.Delete(i.FullName); //删除指定文件
- }
- }
- cmbRecordNo.Items.Add(parame.RecordNo1);
- cmbRecordNo.Items.Add(parame.RecordNo2);
- GetImgeNme();
- cmbRecordNo.SelectedIndex = 0;
- textBox1.Text = _path;
- }
- catch(Exception ee)
- {
- }
- }
- /// <summary>
- /// 获取图片名称
- /// </summary>
- void GetImgeNme()
- {
- foreach (var pp in cmbRecordNo.Items)
- {
- string ss = pp.ToString();
- if (ss != null)
- {
- string no = pp.ToString();
- var loadinfo = EntityHelper.GetData<CmmWorkImageEntity>(
- "com.steering.Mcms.CmmWorkImageServer.doQuery",
- new object[] { no },
- ob);
- foreach (var p in loadinfo)
- {
- List<string> aa = new List<string>();
- string num = null;
- foreach (PropertyInfo t in p.GetType().GetProperties())
- {
- string name = t.Name.ToString();//字段名称
- var value = t.GetValue(p, null);//字段值
- var type = t.PropertyType.Name;//字段类型
- if (name.Contains("ImageFile") && value != null)
- {
- aa.Add(value.ToString());
- }
- if (name == "ActualFirstNo")
- {
- num = value.ToString();
- }
- }
- dic.Add(num, aa);
- }
- }
- }
- }
- private void cmbRecordNo_SelectedIndexChanged(object sender, EventArgs e)
- {
- dicPic = new Dictionary<string, string>();
- try
- {
- setPanelRemoveMsg(pnlpic2);
- ipic = 0;
-
- foreach (var p in dic[cmbRecordNo.Text])
- {
- ftpDown(p);
- }
- }
- catch
- { }
- }
- private void setPicBoxSet(string path)
- {
- PictureBox pb = new PictureBox();
- pb.Name = "pb" + ipic;
- pb.Dock = DockStyle.Top;
- pb.Height = 134;
- pb.DoubleClick += new EventHandler(PictureBoxDoubleClick);
- pb.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- pnlpic2.Controls.Add(pb);
- pb.ImageLocation = path;
- pb.SizeMode = PictureBoxSizeMode.Zoom;
- dicPic.Add(pb.Name, path);
- ipic++;
- }
- private void PictureBoxDoubleClick(object sender, EventArgs e)
- {
- PictureBox picture = (PictureBox)sender;
- picMax.ImageLocation = dicPic[picture.Name];
- pnlpicMax.Visible = true;
- }
- private int iPic = 0;
- /// <summary>
- /// 不显示大图
- /// </summary>
- private void pictureShow_DoubleClick(object sender, EventArgs e)
- {
- pnlpicMax.Visible = false;
-
- }
- private void setPanelRemoveMsg(Panel p)
- {
- if (p.InvokeRequired)
- {
- Action<Panel> action = new Action<Panel>(setPanelRemovenfo);
- Invoke(action, new object[] { p });
- }
- else
- {
- for (int i = p.Controls.Count - 1; i >= 0; i--)
- {
- p.Controls.RemoveAt(i);
- }
- }
- }
- public void setPanelRemovenfo(Panel control)
- {
- setPanelRemoveMsg(control);
- }
- }
- }
|