/// <summary> /// ��ȡ��Ϣ����ͼƬ������������ʽ���� /// </summary> /// <param name="moduleName">ģ������</param> /// <param name="infoId">��ϢId</param> /// <returns>��Ϣ����ͼƬ(������ʽ����)</returns> protected string[] GetImages(object moduleName, object infoId) { if (moduleName == null || infoId == null) return new string[] { }; string descTabName = Business.Attachment.GetDescTabNameByModuleName(moduleName.ToString()); if (descTabName.Equals("")) return new string[] { }; long _infoId = Core.MyConvert.GetInt64(infoId.ToString()); List<Model.AttachmentInfo> infos = new Business.Attachment().GetItems(_infoId, descTabName); string temp = ""; foreach (Model.AttachmentInfo info in infos) { if (temp.Equals("")) temp = info.Server.S_URL + info.At_Path; else temp += "|" + info.Server.S_URL + info.At_Path; } return temp.Split('|'); }
public string StoreDocument(Guid systemId, string managedItemNumber, string filePath) { ILog log = LogManager.GetLogger(this.GetType()); log.Debug(string.Format("Entering StoreDocument(\"{0}\", \"{1}\", \"{2}\").", systemId, managedItemNumber, filePath)); string displayedFileName = "Document Scanned " + Utility.DateHelper.FormatDate(DateTime.Now, "MMM dd, yyyy hh:mm tt"); string contentType = System.IO.Path.GetExtension(filePath).TrimStart('.'); // contentType = file extension without the "." Business.ITATSystem itatSystem = null; try { itatSystem = Business.ITATSystem.Get(systemId); if (itatSystem == null) { string msg = string.Format("Business.ITATSystem.Get() returned null -- systemId=\"{0}\"", systemId); ThrowAndLogException(msg, new Exception(msg), log); } } catch (Exception ex) { ThrowAndLogException(string.Format("Error calling Business.ITATSystem.Get() -- systemId=\"{0}\"", systemId), ex, log); } Utility.DocumentStorage documentStorageObject = null; try { documentStorageObject = Utility.DocumentStorage.GetDocumentStorageObject(itatSystem.DocumentStorageType); } catch (Exception ex) { ThrowAndLogException("Error calling Utility.DocumentStorage.GetDocumentStorageObject()", ex, log); } documentStorageObject.RootPath = itatSystem.DocumentStorageRootPath; string filename = System.IO.Path.GetFileName(filePath); string fileExt = System.IO.Path.GetExtension(filename).ToLowerInvariant(); string fileNameWithoutExt = System.IO.Path.GetFileNameWithoutExtension(filename); byte[] bytes = System.IO.File.ReadAllBytes(filePath); string documentStoreId = null; try { documentStoreId = documentStorageObject.SaveDocument(fileNameWithoutExt, fileExt, bytes); if (string.IsNullOrEmpty(documentStoreId)) { string msg = string.Format("Utility.DocumentStorage.SaveDocument() returned null -- ManagedItem=\"{0}\", FilePath=\"{1}\".", managedItemNumber, filePath); ThrowAndLogException(msg, new Exception(msg), log); } } catch (Exception ex) { ThrowAndLogException(string.Format("Error calling Utility.DocumentStorage.SaveDocument() -- ManagedItem=\"{0}\", FilePath=\"{1}\"", managedItemNumber, filePath), ex, log); } DataSet ds = null; Guid managedItemId = Guid.Empty; try { ds = Data.ManagedItem.FindByNumber(systemId, managedItemNumber, null); if (ds.Tables.Count == 0) { string msg = string.Format("Data.ManagedItem.FindByNumber() returned no tables -- ManagedItem=\"{0}\".", managedItemNumber); ThrowAndLogException(msg, new Exception(msg), log); } if (ds.Tables[0].Rows.Count == 0) { string msg = string.Format("Data.ManagedItem.FindByNumber() returned no rows -- ManagedItem=\"{0}\".", managedItemNumber); ThrowAndLogException(msg, new Exception(msg), log); } managedItemId = (Guid)ds.Tables[0].Rows[0][Data.DataNames._C_ManagedItemID]; } catch (Exception ex) { ThrowAndLogException(string.Format("Error calling Data.ManagedItem.FindByNumber() -- ManagedItem=\"{0}\"", managedItemNumber), ex, log); } Business.ManagedItem mi = null; try { mi = Business.ManagedItem.Get(managedItemId, false); } catch (Exception ex) { ThrowAndLogException(string.Format("Error calling Business.ManagedItem.Get() -- managedItemId=\"{0}\"", managedItemId), ex, log); } Business.Attachment att = null; try { att = new Business.Attachment(Guid.NewGuid(), displayedFileName, "", documentStoreId, new Kindred.Knect.ITAT.Business.DocumentType(""), true); mi.Attachments.Add(att); mi.SaveAttachments(); } catch (Exception ex) { ThrowAndLogException(string.Format("Error saving attachment -- managedItemId=\"{0}\", documentStoreId=\"{1}\".", managedItemId, documentStoreId), ex, log); } try { System.IO.File.Delete(filePath); } catch (Exception ex) { ThrowAndLogException(string.Format("Error deleting temp file \"{0}\".", filePath), ex, log); } return documentStoreId; }