Esempio n. 1
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();
        }
Esempio n. 2
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);
     }
 }
Esempio n. 3
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);
     }
 }