Example #1
0
        /// <summary>
        /// Save Attachment
        /// </summary>
        protected virtual DocsPaWR.Allegato SaveAttachment()
        {
            Allegato                 attachment  = DocumentManager.GetSelectedAttachment();
            SchedaDocumento          documentTab = DocumentManager.getSelectedRecord();
            List <DocsPaWR.Allegato> attachments = new List <DocsPaWR.Allegato>(documentTab.allegati);

            if (attachment == null)
            {
                // Modalità di inserimento
                attachment                 = new DocsPaWR.Allegato();
                attachment.descrizione     = AttachmentDescription.Text;
                attachment.numeroPagine    = AttachmentPagesCount.Text.Length > 0 ? Convert.ToInt32(AttachmentPagesCount.Text) : 0;
                attachment.docNumber       = documentTab.docNumber;
                attachment.dataInserimento = DateTime.Today.ToString();
                attachment.version         = "1";
                attachment.TypeAttachment  = 1;
                string idPeopleDelegato = "0";
                if (UserManager.GetInfoUser().delegato != null)
                {
                    idPeopleDelegato = UserManager.GetInfoUser().delegato.idPeople;
                }
                attachment.idPeopleDelegato = idPeopleDelegato;

                // Impostazione del repositoryContext associato al documento
                attachment.repositoryContext = documentTab.repositoryContext;
                attachment.position          = (documentTab.allegati.Length + 1);
                if (attachment.version != null && attachment.version.Equals("0"))
                {
                    attachment.version = "1";
                }
                try
                {
                    attachment = DocumentManager.AddAttachment(attachment);
                }
                catch (NttDataWAException ex)
                {
                    throw new NttDataWAException(ex.Message, "");
                }
                //calcolo a runtime il versionLabel dell'allegato appena creato
                attachment.versionLabel = string.Format("A{0:0#}", DocumentManager.getSelectedRecord().allegati.Count() + 1);
                // Inserimento dell'allegato nella scheda documento
                attachments.Add(attachment);
                documentTab.allegati = attachments.ToArray();
                DocumentManager.setSelectedRecord(documentTab);
                // Aggiornamento grid index
                this.SelectedPage = (int)Math.Round((attachments.Count / this.PageSize) + 0.49);
            }
            else
            {
                // Modifica dati
                attachment.descrizione  = AttachmentDescription.Text;
                attachment.numeroPagine = AttachmentPagesCount.Text.Length > 0 ? Convert.ToInt32(AttachmentPagesCount.Text) : 0;
                documentTab.allegati    = attachments.ToArray();
                ProxyManager.GetWS().DocumentoModificaAllegato(UserManager.GetInfoUser(), attachment, documentTab.docNumber);
                if (documentTab != null && documentTab.systemId != null && !(documentTab.systemId.Equals(documentTab.systemId)))
                {
                    FileManager.removeSelectedFile();
                }
            }

            return(attachment);
        }
        protected override string Upload(HttpPostedFile file, string fileName)
        {
            string       result = String.Empty;
            MemoryStream _ms    = null;

            try
            {
                SchedaDocumento          documentTab = DocumentManager.getSelectedRecord();
                List <DocsPaWR.Allegato> attachments = new List <DocsPaWR.Allegato>(documentTab.allegati);
                DocumentManager.setSelectedAttachId(null);
                Allegato attachment = new DocsPaWR.Allegato()
                {
                    descrizione       = Path.GetFileNameWithoutExtension(file.FileName), //file.FileName,
                    numeroPagine      = 1,
                    docNumber         = documentTab.docNumber,
                    dataInserimento   = DateTime.Today.ToString(),
                    version           = "1",
                    TypeAttachment    = 1,
                    idPeopleDelegato  = UserManager.GetInfoUser().delegato != null?UserManager.GetInfoUser().delegato.idPeople : "0",
                    repositoryContext = documentTab.repositoryContext,
                    position          = (documentTab.allegati.Length + 1)
                };

                attachment = DocumentManager.AddAttachment(attachment);
                attachment.versionLabel = string.Format("A{0:0#}", DocumentManager.getSelectedRecord().allegati.Count() + 1);

                attachments.Add(attachment);
                documentTab.allegati = attachments.ToArray();
                DocumentManager.setSelectedRecord(documentTab);

                System.Web.HttpContext.Current.Session["selectedAttachmentId"] = attachment.versionId;

                // aggiungi file all'allegato
                //FileRequest attachFileReq = FileManager.GetFileRequest(attachment.versionId);


                // File DOcumento...
                string path = this._context.Server.MapPath(@"Uploads");
                NttDataWA.DocsPaWR.FileDocumento fileDoc = new NttDataWA.DocsPaWR.FileDocumento();
                fileDoc.name        = fileName;
                fileDoc.fullName    = Path.Combine(path, fileName);
                fileDoc.contentType = NttDataWA.UIManager.FileManager.GetMimeType(fileName);
                fileDoc.length      = file.ContentLength;

                byte[] buffer = new byte[16 * 1024];
                _ms = new MemoryStream();

                int read;
                while ((read = file.InputStream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    _ms.Write(buffer, 0, read);
                }
                fileDoc.content = _ms.ToArray();

                bool _pdf   = "1".Equals((string)System.Web.HttpContext.Current.Session["UploadMassivoConversionePDF"]);
                bool _paper = "1".Equals((string)System.Web.HttpContext.Current.Session["UploadMassivoCartaceo"]);
                bool _pdfConversionSynchronousLC = false;
                if (HttpContext.Current.Session["PdfConversionSynchronousLC"] != null)
                {
                    _pdfConversionSynchronousLC = (bool)HttpContext.Current.Session["PdfConversionSynchronousLC"];
                }

                result = FileManager.uploadFile(null, fileDoc, _paper, _pdf, _pdfConversionSynchronousLC);

                if (!String.IsNullOrWhiteSpace(result))
                {
                    // rimuove l'allegato ocreato
                    attachments.Remove(attachment);
                    bool resultRemove = DocumentManager.RemoveAttachment(1, 1, attachment);
                    DocumentManager.RemoveSelectedAttachId();
                    if (resultRemove)
                    {
                        documentTab.allegati = attachments.ToArray();
                        DocumentManager.setSelectedRecord(documentTab);
                    }
                }


                //if (String.IsNullOrWhiteSpace(documentTab.docNumber))
                //{
                //    var filereq = FileManager.uploadFile(null, fileDoc, false);
                //}
                //else
                //{
                //    error = FileManager.uploadFile(null, fileDoc, _paper, _pdf, _pdfConversionSynchronousLC);
                //}
            }
            catch (Exception ex)
            {
                result = ex.Message;
                _logger.Error(ex.Message, ex);
            }
            return(result);
        }