public static void UploadAttachment(string localFilename, User user) { try { KellFileTransfer.FILELIST file = KellFileTransfer.Common.GetFILE(localFilename); if (KellFileTransfer.FileUploader.SendFile(localFilename, KellFileTransfer.Common.GetUploadIPEndPoint())) { Attachment attch = new Attachment(); attch.AttachmentFilename = file.文件路径; attch.Size = file.文件大小; attch.Uploader = user; int r = AttachmentLogic.GetInstance().AddAttachment(attch); string s = r > 0 ? "":",但保存到数据库失败!"; MessageBox.Show("上传成功!" + s); } else { MessageBox.Show("上传失败!"); } } catch (Exception e) { MessageBox.Show("上传时出错:" + e.Message); } }
public static AttachmentLogic GetInstance() { if (instance == null) { instance = new AttachmentLogic(); } return(instance); }
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); } }
public static Attachment UploadAttachment(User user, string localFilename) { try { string dir = null; if (user != null) { dir = user.ID.ToString(); } KellFileTransfer.FILELIST file = KellFileTransfer.Common.GetFILE(localFilename, dir); if (KellFileTransfer.FileUploader.SendFile(localFilename, KellFileTransfer.Common.GetUploadIPEndPoint(), user.ID.ToString())) { Attachment attch = new Attachment(); attch.AttachmentFilename = file.文件路径; attch.Size = file.文件大小; attch.Uploader = user; int r = AttachmentLogic.GetInstance().AddAttachment(attch); string s = ""; if (r > 0) { attch.ID = r; return(attch); } else { s = "但保存到数据库失败!"; } MessageBox.Show("上传成功!" + s); } else { MessageBox.Show("上传失败!"); } } catch (Exception e) { MessageBox.Show("上传时出错:" + e.Message); } return(null); }
public bool DeleteDocObject(DocObject element, User user) { if (user == null) { return(false); } string s = "(1>1)"; int adminId = Common.AdminId; if (user.ID == adminId) { s = "(1=1)"; } string sql = "delete from TF_DocObject where ID=" + element.ID + " and (Owner=" + user.ID + " or " + s + ")"; int r = sqlHelper.ExecuteSql(sql); if (r > 0) { FormItemLogic.GetInstance().DeleteFormItems(FormItemLogic.GetItemString(element.DocItems));//删除字段信息 AttachmentLogic al = AttachmentLogic.GetInstance(); foreach (FormItem item in element.DocItems) { if (item.ItemType == "System.Object")//是附件,顺带把附件记录也删除 { string[] ss = item.ItemValue.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (ss.Length > 1) { int id; if (int.TryParse(ss[0], out id)) { al.DeleteAttachment(id); } } } } } return(r > 0); }
public static Attachment GetAttachmentForDownload(int id) { return(AttachmentLogic.GetInstance().GetAttachment(id)); }
private void UploadAttachments(List <Attachment> attachs) { if (attachs != null && attachs.Count > 0) { AttachmentLogic al = AttachmentLogic.GetInstance(); SolidBrush brush = new SolidBrush(Color.FromArgb(100, Color.Green)); SolidBrush errBrush = new SolidBrush(Color.FromArgb(100, Color.Red)); int count = attachs.Count; int size = label1.Width / count; Rectangle rect = new Rectangle(0, 0, size, label1.Height); int err = 0; for (int i = 0; i < attachs.Count; i++) { rect.X = size * i; Attachment attach = attachs[i]; string dir = ""; if (attach.Uploader != null) { dir = attach.Uploader.ID.ToString(); } if (KellFileTransfer.FileUploader.SendFile(attach.AttachmentFilename, KellFileTransfer.Common.GetUploadIPEndPoint(), dir)) { string filename = Path.GetFileName(attach.AttachmentFilename); Attachment a = new Attachment(); a.AttachmentFilename = dir + "\\" + filename; a.Size = attach.Size; a.Uploader = attach.Uploader; int id = al.AddAttachment(a); if (id > 0) { attach.ID = id; attach.AttachmentFilename = a.AttachmentFilename; using (Graphics g = label1.CreateGraphics()) { g.FillRectangle(brush, rect); } } else { err++; using (Graphics g = label1.CreateGraphics()) { g.FillRectangle(errBrush, rect); } } } else { err++; using (Graphics g = label1.CreateGraphics()) { g.FillRectangle(errBrush, rect); } } } brush.Dispose(); errBrush.Dispose(); string errStr = ""; if (err > 0) { errStr = "但是有1个或多个附件上传失败。可能是保存附件记录到数据库失败,也可能是主机终结点[" + KellFileTransfer.Common.GetUploadIPEndPoint().ToString() + "]尚未开始服务..."; } MessageBox.Show("上传完毕!" + errStr); } }