示例#1
0
 static void download_DownloadFinishedSingle(KellFileTransfer.FileDownloadClient sender, string fileFullPath)
 {
     if (File.Exists(fileFullPath))
     {
         SaveFileDialog sfd = new SaveFileDialog();
         sfd.Title = "附件另存为...";
         string ext = Path.GetExtension(fileFullPath);
         sfd.Filter = "文件(*" + ext + ")|*" + ext;
         if (sfd.ShowDialog() == DialogResult.OK)
         {
             try
             {
                 File.Move(fileFullPath, sfd.FileName);
             }
             catch (Exception e)
             {
                 MessageBox.Show("下载成功,但移动文件到目录[" + sfd.FileName + "]失败:" + e.Message);
             }
         }
         sfd.Dispose();
     }
     else
     {
         MessageBox.Show("下载附件到本地后,却找不到该文件[" + fileFullPath + "]!");
     }
 }
示例#2
0
 private void DownloadClient_Load(object sender, EventArgs e)
 {
     //ipep = KellFileTransfer.Common.GetDownloadIPEndPoint();
     client = new KellFileTransfer.FileDownloadClient();
     client.DownloadBegined     += new KellFileTransfer.DownloadHandler(client_DownloadBegined);
     client.DownloadAllFinished += new EventHandler(client_DownloadAllFinished);
     client.DownloadFinished    += new KellFileTransfer.DownloadHandler(client_DownloadFinished);
     client.DownloadingError    += new KellFileTransfer.DownloadErrorHandler(client_DownloadingError);
 }
示例#3
0
        private void DownloadAttachments(List <Attachment> attachs)
        {
            selectedCount = attachs.Count;
            IPEndPoint ipep = KellFileTransfer.Common.GetDownloadIPEndPoint();

            KellFileTransfer.FileDownloadClient client = new KellFileTransfer.FileDownloadClient();
            client.DownloadFinishedSingle += new KellFileTransfer.DownloadSingleHandler(client_DownloadFinishedSingle);
            client.DownloadingError       += new KellFileTransfer.DownloadErrorHandler(client_DownloadingError);
            foreach (Attachment attach in attachs)
            {
                User user = attach.Uploader;
                //以下为禁止非原上传用户下载附件的代码,由于现在运行所有用户下载查看附件,所以屏蔽!
                //int index = attach.AttachmentFilename.IndexOf("\\");// 322\123.abc
                //if (index > 0 && user != null)
                //{
                //    string userId = attach.AttachmentFilename.Substring(0, index);
                //    int R;
                //    if (int.TryParse(userId, out R))
                //    {
                //        if (user.ID != R)
                //        {
                //            continue;//非法用户
                //        }
                //    }
                //}
                KellFileTransfer.FILELIST file = new KellFileTransfer.FILELIST();
                if (user != null)
                {
                    file.文件路径 = user.ID + "\\" + Path.GetFileName(attach.AttachmentFilename);
                }
                else
                {
                    file.文件路径 = Path.GetFileName(attach.AttachmentFilename);
                }
                file.文件大小 = attach.Size;
                bool f = client.DownloadFileFromServer(file, ipep.Address, ipep.Port);
                if (!f)
                {
                    MessageBox.Show("下载附件失败!很有可能连接到附件服务器的网络已断开。");
                }
            }
            button1.Refresh();
            //SolidBrush Backbrush = new SolidBrush(SystemColors.Control);
            //SolidBrush Forebrush = new SolidBrush(SystemColors.ControlText);
            //Rectangle rect = new Rectangle(0, 0, button1.Width, button1.Height);
            //using (Graphics g = button1.CreateGraphics())
            //{
            //    g.FillRectangle(Backbrush, rect);
            //    SizeF size = g.MeasureString("下载附件",button1.Font);
            //    PointF point = new PointF(button1.Width / 2 - size.Width / 2, button1.Height / 2 - size.Height / 2);
            //    g.DrawString("下载附件", button1.Font, Forebrush, point);
            //}
            //Backbrush.Dispose();
            //Forebrush.Dispose();
        }
示例#4
0
 static void download_DownloadFinishedSingle(KellFileTransfer.FileDownloadClient sender, string fileFullPath)
 {
     if (File.Exists(fileFullPath))
     {
         ThreadPool.QueueUserWorkItem(new WaitCallback(Finish), fileFullPath);
     }
     else
     {
         MessageBox.Show("下载附件到本地后,却找不到该文件[" + fileFullPath + "]!");
     }
 }
示例#5
0
        void client_DownloadingError(KellFileTransfer.FileDownloadClient sender, Exception e)
        {
            SolidBrush errBrush = new SolidBrush(Color.FromArgb(100, Color.Red));
            int        size     = button1.Width / selectedCount;
            Rectangle  rect     = new Rectangle(0, 0, size, button1.Height);

            using (Graphics g = button1.CreateGraphics())
            {
                g.FillRectangle(errBrush, rect);
            }
            errBrush.Dispose();
            MessageBox.Show("下载附件[" + sender.FileName + "]时出错:" + e.Message);
        }
示例#6
0
 public static void DownloadAttachment(bool open, User user, int attachId, string attachmentFileName, long size, IPEndPoint ipep = null)
 {
     if (string.IsNullOrEmpty(attachmentFileName))
     {
         return;
     }
     //以下为禁止非原上传用户下载附件的代码,由于现在运行所有用户下载查看附件,所以屏蔽!
     //int index = attachmentFileName.IndexOf("\\");// 322\123.abc
     //if (index > 0 && user != null)
     //{
     //    string userId = attachmentFileName.Substring(0, index);
     //    int R;
     //    if (int.TryParse(userId, out R))
     //    {
     //        if (user.ID != R)
     //        {
     //            return;//非法用户
     //        }
     //    }
     //}
     try
     {
         KellFileTransfer.FileDownloadClient download = new KellFileTransfer.FileDownloadClient();
         if (open)
         {
             download.DownloadFinishedSingle += new KellFileTransfer.DownloadSingleHandler(download_DownloadFinishedSingle);
         }
         KellFileTransfer.FILELIST attachment = new KellFileTransfer.FILELIST();
         attachment.文件路径 = attachmentFileName;
         attachment.文件大小 = size;
         if (ipep == null)
         {
             ipep = KellFileTransfer.Common.GetDownloadIPEndPoint();
         }
         if (download.DownloadFileFromServer(attachment, ipep.Address, ipep.Port))
         {
             AttachmentLogic.GetInstance().AfterDownload(attachId);
         }
         else
         {
             MessageBox.Show("下载附件失败!很有可能连接到附件服务器的网络已断开。");
         }
     }
     catch (Exception e)
     {
         MessageBox.Show("下载附件时出错:" + e.Message);
     }
 }
示例#7
0
        void client_DownloadFinishedSingle(KellFileTransfer.FileDownloadClient sender, string fileFullPath)
        {
            using (SaveFileDialog sfd = new SaveFileDialog())
            {
                sfd.Title = "确定将附件保存到指定位置,取消就立即打开...";
                string ext = Path.GetExtension(fileFullPath);
                if (!string.IsNullOrEmpty(ext))
                {
                    sfd.Filter = "文件(*" + ext + ")|*" + ext;
                }
                else
                {
                    sfd.Filter = "文件(*.*)|*.*";
                }
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        File.Move(fileFullPath, sfd.FileName);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("下载成功,但另存附件到目录[" + sfd.FileName + "]失败:" + e.Message);
                    }
                }
                else
                {
                    try
                    {
                        Process.Start(fileFullPath);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("下载附件成功,但打开附件[" + fileFullPath + "]时出错:" + e.Message);
                    }
                }
            }
            SolidBrush brush = new SolidBrush(Color.FromArgb(100, Color.Green));
            int        size  = button1.Width / selectedCount;
            Rectangle  rect  = new Rectangle(0, 0, size, button1.Height);

            using (Graphics g = button1.CreateGraphics())
            {
                g.FillRectangle(brush, rect);
            }
            brush.Dispose();
        }
示例#8
0
 public static void DownloadAttachment(string attachmentFileName, long size, IPEndPoint ipep = null)
 {
     try
     {
         KellFileTransfer.FileDownloadClient download = new KellFileTransfer.FileDownloadClient();
         download.DownloadFinishedSingle += new KellFileTransfer.DownloadSingleHandler(download_DownloadFinishedSingle);
         KellFileTransfer.FILELIST attachment = new KellFileTransfer.FILELIST();
         attachment.文件路径 = attachmentFileName;
         attachment.文件大小 = size;
         if (ipep == null)
         {
             ipep = KellFileTransfer.Common.GetDownloadIPEndPoint();
         }
         if (!download.DownloadFileFromServer(attachment, ipep.Address, ipep.Port))
         {
             MessageBox.Show("下载失败!");
         }
     }
     catch (Exception e)
     {
         MessageBox.Show("下载时出错:" + e.Message);
     }
 }
示例#9
0
 void client_DownloadFinished(KellFileTransfer.FileDownloadClient sender, string filename)
 {
     toolStripStatusLabel1.Text = "文件[" + filename + "]下载完毕!";
 }
示例#10
0
 void client_DownloadingError(KellFileTransfer.FileDownloadClient sender, Exception e)
 {
     toolStripStatusLabel1.Text += "出错:" + e.Message;
     MessageBox.Show("下载时出错:" + e.Message);
 }
示例#11
0
 void client_DownloadBegined(KellFileTransfer.FileDownloadClient sender, string filename)
 {
     toolStripStatusLabel1.Text = "正在下载文件[" + filename + "]...";
 }