//获取图片线程操作 private void getImageThread() { //初始化 sftp.Connect(); //与服务器建立连接 MemoryStream ms; //内存区域的流,用来读取截图 MyInvoke mi = new MyInvoke(UpdateForm); //窗体控件的线程间安全调用 arr = sftp.GetFileList("/root/img", filename); //获取文件列表 progressbar = 10; //判断如果没有相应的截图时,则报错 if (arr.Count == 0) { MessageBox.Show("没有该日期的数据!"); progressbar = 0; error = true; return; } //先读取出第一个截图 ms = new MemoryStream(sftp.Get("/root/img/" + arr[0])); images = new Image[arr.Count]; images[0] = Image.FromStream(ms); pictureBox1.Image = images[0]; flag = 0; ms.Close(); progressbar = 12; //如果有更多图片,则一一读取 if (arr.Count > 1) { for (int i = 1; i < arr.Count; i++) { Console.WriteLine(arr[i]); ms = new MemoryStream(sftp.Get("/root/img/" + arr[i])); images[i] = Image.FromStream(ms); ms.Close(); if (progressbar >= 92) { progressbar = 92; } else { progressbar = progressbar + 4; } } } sftp.Disconnect(); //断开服务器连接 this.BeginInvoke(mi); //调用控件的安全线程 progressbar = 100; }
//委托函数,进行更新richTextBox1的操作 public void updateText(string filename) { //先将文件保存下来,再用sr读取数据 File.WriteAllBytes(cacheUrl, sftp.Get("/root/netrecord/" + filename + ".txt")); sr = new StreamReader(cacheUrl, System.Text.Encoding.UTF8); //使用StreamReader类来读取文件 sr.BaseStream.Seek(0, SeekOrigin.Begin); // 从数据流中读取每一行,直到文件的最后一行,并在richTextBox1中显示出内容 this.richTextBox1.Text = ""; string strLine = sr.ReadLine(); while (strLine != null) { this.richTextBox1.Text += strLine + "\n";//读取换行 strLine = sr.ReadLine(); if (progressbar < 90) { progressbar = progressbar + 6; } else { progressbar = 90; } } //关闭此StreamReader对象 sr.Close(); }
private void WelCome_Load(object sender, EventArgs e) { MemoryStream ms = null;//内存区域的流,用来读取截图 try { UserInfo userInfo = db.getUserInfo(Cat.userName.ToString(), Cat.Department.ToString()); this.label7.Text = userInfo.user; this.label8.Text = userInfo.id.ToString(); this.label9.Text = userInfo.positions; this.label10.Text = userInfo.department; this.label11.Text = userInfo.employeement_date; this.label17.Text = Cat.Ip; this.label18.Text = Cat.computer_id.ToString(); this.label19.Text = userInfo.violation.ToString(); progressbar = 50; ms = new MemoryStream(sftp.Get("/root/employeePic/" + userInfo.user + ".jpg")); this.pictureBox1.Image = Image.FromStream(ms); ms.Close(); progressbar = 100; } catch { MessageBox.Show("没有相应员工信息!"); } finally { ms.Close(); } }