Beispiel #1
0
        private void btnNewDocument_Click(object sender, EventArgs e)
        {
            NuovoDocumento nuovoDoc = new NuovoDocumento();
            DialogResult result = nuovoDoc.ShowDialog(this);
            if (result == DialogResult.OK)
            {
                FileInfo file = new FileInfo(nuovoDoc.DocumentFullPath);
                long numBytes = file.Length;
                FileStream fStream = new FileStream(nuovoDoc.DocumentFullPath, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fStream);
                byte[] data = br.ReadBytes((int)numBytes);
                br.Close();
                fStream.Close();

                string fileName = nuovoDoc.DocumentFullPath.Substring(nuovoDoc.DocumentFullPath.LastIndexOf("\\") + 1);

                ImportazioneDocumento documento;

                // Caricamento finestrella feedback per il salvataggio
                if (_pratica != null)
                    documento = new ImportazioneDocumento(data, fileName, nuovoDoc.DescrizioneDocumento, _pratica);
                else
                    documento = new ImportazioneDocumento(data, fileName, nuovoDoc.DescrizioneDocumento, _attivita);
                
                documento.ShowDialog();

                if (_pratica != null)
                {
                    _pratica = documento.Pratica;
                    lista.DataSource = _pratica.Documenti;
                }
                else
                {
                    _attivita = documento.Attivita;
                    lista.DataSource = _attivita.Documenti;
                }
                
            }

        }
Beispiel #2
0
        private void btnNewDocumentClick(object sender, EventArgs e)
        {
            try
            {
                var nuovoDoc = new NuovoDocumento();
                var result = nuovoDoc.ShowDialog(this);
                if (result == DialogResult.OK)
                {
                    var file = new FileInfo(nuovoDoc.DocumentFullPath);
                    if (file.Exists)
                    {
                        try
                        {
                            var numBytes = file.Length;
                            var fStream = new FileStream(nuovoDoc.DocumentFullPath, FileMode.Open, FileAccess.Read);
                            var br = new BinaryReader(fStream);
                            var data = br.ReadBytes((int) numBytes);
                            br.Close();
                            fStream.Close();

                            var fileName = nuovoDoc.DocumentFullPath.Substring(nuovoDoc.DocumentFullPath.LastIndexOf("\\") + 1);

                            // Caricamento finestrella feedback per il salvataggio
                            var form = new ExecuteLoadDataObjectAsync<DocumentMessages>("Il documento è in corso di salvataggio ....." + Environment.NewLine + "Si prega di attendere.");
                            Func<DocumentMessages> loadDati = () => saveDocument(data, fileName, nuovoDoc.DescrizioneDocumento, nuovoDoc.VisibileCondomino);
                            form.LoadData(loadDati);
                            form.ShowDialog();

                            if (form.DataSourceObject.Documento != null)
                            {
                                var documento = form.DataSourceObject.Documento;
                                documento.VisibileCondomino = nuovoDoc.VisibileCondomino;
                                _fascicolo.Documenti.Add(documento);
                                lista.DataSource = _fascicolo.Documenti;
                            }
                            else
                                CommonMessages.DisplayWarning(string.Format("Si è verificato un errore nel salvataggio del documento.{0}{1}", Environment.NewLine, form.DataSourceObject.Message));

                            form.Dispose();
                        }
                        catch (IOException ex)
                        {
                            _log.WarnFormat("Errore inaspettato nel caricamento del documento - FILE ESISTENTE - {0} - file:{1}", ex, Gipasoft.Library.Utility.GetMethodDescription(), nuovoDoc.DocumentFullPath);
                            CommonMessages.DisplayWarning(string.Format("Il documento non può essere aperto.{0}Verificare se il documento è già aperto in un'altra applicazione", Environment.NewLine));
                        }
                        catch (Exception ex)
                        {
                            _log.ErrorFormat("Errore inaspettato nel caricamento del documento - FILE ESISTENTE - {0} - file:{1}", ex, Gipasoft.Library.Utility.GetMethodDescription(), nuovoDoc.DocumentFullPath);
                            throw;
                        }
                    }
                    else
                    {
                        CommonMessages.DisplayWarning("Il file " + nuovoDoc.DocumentFullPath + " non è stato trovato." + Environment.NewLine + "Si prega di riprovare.");
                    }
                }

                nuovoDoc.Dispose();

            }
            catch (Exception ex)
            {
                _log.ErrorFormat("Errore inaspettato nel caricamento del documento - {0} - azienda:{1}", ex, Gipasoft.Library.Utility.GetMethodDescription(), Security.Login.Instance.CurrentLogin().Azienda);
            }
        }
Beispiel #3
0
        private void btnNewDocumentClick(object sender, EventArgs e)
        {
            try
            {
                var tipoDoc = string.Empty;
                if (_contratto != null)
                    tipoDoc = "TipoDocumentoContratto";
                else if (_condominio != null)
                    tipoDoc = "TipoDocumentoCondominio";
                else if (_fornitore != null)
                    tipoDoc = "TipoDocumentoFornitore";
                else if (_unitaImmobiliare != null)
                    tipoDoc = "TipoDocumentoUnitaImmobiliare";

                var nuovoDocumento = new NuovoDocumento(tipoDoc);
                if (nuovoDocumento.ShowDialog() == DialogResult.OK)
                {
                    var file = new FileInfo(nuovoDocumento.DocumentFullPath);

                    // Generazione DTO relativo al documento selezionato
                    DocumentoDTO doc;
                    if (_contratto != null)
                        doc = getDocumentoService().GetNew(_contratto);
                    else if (_condominio != null)
                        doc = getDocumentoService().GetNew(_condominio);
                    else if (_fornitore != null)
                        doc = getDocumentoService().GetNew(_fornitore);
                    else if (_unitaImmobiliare != null)
                        doc = getDocumentoService().GetNew(_unitaImmobiliare);
                    else if (_attivita != null)
                        doc = getDocumentoService().GetNew(_attivita);
                    else
                        doc = new DocumentoDTO();

                    doc.DirectoryName = file.DirectoryName;
                    doc.DataCreazione = DateTime.Now;
                    doc.Tipo = nuovoDocumento.TipoDocumento;
                    doc.Descrizione = nuovoDocumento.DescrizioneDocumento;
                    doc.FileName = file.Name;
                    doc.FileExtension = file.Extension;

                    // Lettura File
                    var data = new byte[0];
                    try
                    {
                        var numBytes = file.Length;
                        var fStream = new FileStream(nuovoDocumento.DocumentFullPath, FileMode.Open, FileAccess.Read);
                        var br = new BinaryReader(fStream);
                        data = br.ReadBytes((int) numBytes);
                        br.Close();
                        fStream.Close();
                    }
                    catch (IOException ex)
                    {
                        CommonMessages.DisplayWarning(string.Format("Non è possibile allegare il file '{0}' perchè risulta aperto in un'applicazione", file.Name));
                    }
                    catch (Exception ex)
                    {
                        _log.ErrorFormat("Errore nell'apertura di un documento - {0} - azienda:{1}", ex, Utility.GetMethodDescription(), Login.Instance.CurrentLogin().Azienda);
                        throw;
                    }

                    if (data.Length > 0)
                    {
                        var docInfo = new DocumentInfo { Body = data, FileName = file.Name, FileExtension = file.Extension };

                        // Salvataggio Documento ... solo se sono in update
                        if (_mode == ListMode.Update)
                        {
                            var form = new ExecuteLoadDataObjectAsync<DocumentMessages>("Il documento è in corso di salvataggio ....." + Environment.NewLine + "Si prega di attendere.");
                            Func<DocumentMessages> loadDati = () => saveDocument(doc, docInfo);
                            form.LoadData(loadDati);
                            form.ShowDialog();

                            if (_contratto != null)
                            {
                                if (form.DataSourceObject.Documento != null)
                                {
                                    var docNew = form.DataSourceObject.Documento;
                                    docNew.VisibileCondomino = nuovoDocumento.VisibileCondomino;
                                    _contratto.Documenti.Add(docNew);
                                }
                                else
                                    CommonMessages.DisplayWarning(string.Format("Si è verificato un errore nel salvataggio del documento.{0}{1}", Environment.NewLine, form.DataSourceObject.Message));
                            }
                            else if(!string.IsNullOrEmpty(form.DataSourceObject.Message))
                                CommonMessages.DisplayWarning(string.Format("Si è verificato un errore nel salvataggio del documento:{0}{1}", Environment.NewLine, form.DataSourceObject.Message));
                            else
                                LoadData(false);

                            form.Dispose();
                        }
                        else if (_mode == ListMode.Select)
                        {
                            doc.Body = docInfo.Body;
                            _documentiNuovi.Add(docInfo);
                            docInfo.BodyText = nuovoDocumento.DescrizioneDocumento;
                            doc.Stato = "NEW";
                            documentoBindingSource.Add(doc);
                            
                            // Tutti i documenti nuovi devono essere selezionati
                            foreach (var row in lista.Rows)
                            {
                                var documento = row.ListObject as DocumentoDTO;
                                if (documento != null && documento.Stato == "NEW")
                                {
                                    if (row.Cells.Exists("SelectColumn"))
                                        row.Cells["SelectColumn"].Value = true;
                                }
                            }

                            if(lista.DisplayLayout.Bands[0].Columns.Exists("SelectColumn"))
                                lista.DisplayLayout.Bands[0].Columns["SelectColumn"].SortIndicator = SortIndicator.Descending;
                        }                        
                    }

                }

                lista.DataBind();
                nuovoDocumento.Dispose();
            }
            catch (Exception ex)
            {
                _log.ErrorFormat("Errore nell'upload di un nuovo documento - {0} - azienda:{1}", ex, Utility.GetMethodDescription(), Login.Instance.CurrentLogin().Azienda);
                throw;
            }
        }