AttachmentCollection MergeData(AttachmentCollection attachments, AttachmentCollection additionalAttachments) { try { if (attachments == null || attachments.Count <= 0) { return(additionalAttachments); } if (additionalAttachments == null || additionalAttachments.Count <= 0) { return(attachments); } AttachmentCollection result = new AttachmentCollection(); result.AddRange(attachments); result.AddRange(additionalAttachments); return(result); } catch { return(attachments); } }
private void GetAttachments(int postUserID, MessageDisplay msgDisplay, ref AttachmentCollection attachs) { AttachmentCollection attachments = new AttachmentCollection(); DiskFileCollection diskFiles = null; List<int> tempFileIds = new List<int>(), diskFileIds=new List<int>(); string[] attachIndexs = _Request.Get("attachIndex", Method.Post,string.Empty).Split( new string[]{ ","}, StringSplitOptions.RemoveEmptyEntries); foreach (string i in attachIndexs) { if (i == "{index}") continue; int id = _Request.Get<int>("attachid_" + i, Method.Post, 0); int attachType=_Request.Get<int>("attachtype_" + i, Method.Post, 0); if ( attachType == 0) tempFileIds.Add(id); else if( attachType==1 ) diskFileIds.Add(id); } diskFiles = DiskBO.Instance.GetDiskFiles(diskFileIds); Attachment attach; string extendName = string.Empty; foreach (DiskFile file in diskFiles) { attach = new Attachment(); attach.DiskFileID = file.DiskFileID; attach.FileID = file.FileID; attach.FileSize = file.Size; attach.FileName = _Request.Get("filename_1_" + file.DiskFileID, Method.Post, "未命名", false); attach.Price = _Request.Get("price_1_" + file.DiskFileID, Method.Post, 0); extendName = _Request.Get("extname_1_" + file.DiskFileID, Method.Post, string.Empty); attach.AttachType = AttachType.DiskFile; if (!string.IsNullOrEmpty(attach.FileName) && !string.IsNullOrEmpty(extendName)) attach.FileName += "." + extendName; attach.FileType = extendName; attachments.Add(attach); } foreach (int id in tempFileIds) { attach = new Attachment(); attach.AttachmentID = id; attach.FileName = _Request.Get("filename_0_" + id, Method.Post, "未命名", false); attach.Price = _Request.Get("price_0_" + id, Method.Post, 0); attach.AttachType = AttachType.TempAttach; extendName = _Request.Get("extname_0_" + id, Method.Post, string.Empty); if (!string.IsNullOrEmpty(attach.FileName) && !string.IsNullOrEmpty(extendName)) attach.FileName += "." + extendName; attach.FileType = extendName; attachments.Add(attach); } foreach(Attachment att in attachments) { att.PostID = 0; if (IsEditPost || IsEditThread) att.UserID = postUserID; else att.UserID = MyUserID; if (att.Price < 0) { msgDisplay.AddError("附件售价不能小于0"); return; } } attachs.AddRange(attachments); }