Esempio n. 1
0
        private bool EstraiValoreCellaDecimal(string cella, string colonna, CDCDS.CDC_DETTAGLIO_relRow dettaglio, out string messaggioErrore)
        {
            messaggioErrore = string.Empty;
            decimal aux;

            if (!decimal.TryParse(cella, out aux))
            {
                messaggioErrore = string.Format("Errore lettura colonna ID {0} il valore non è un numero", colonna);
                return(false);
            }
            else
            {
                dettaglio[colonna] = aux;
            }
            return(true);
        }
Esempio n. 2
0
        public bool ReadCDC(Stream stream, CDCDS ds, decimal IDEXCEL, string utente, out string messaggioErrore)
        {
            messaggioErrore = string.Empty;
            SpreadsheetDocument document          = SpreadsheetDocument.Open(stream, true);
            SharedStringTable   sharedStringTable = document.WorkbookPart.SharedStringTablePart.SharedStringTable;

            WorkbookPart wbPart = document.WorkbookPart;

            WorksheetPart    worksheetPart    = wbPart.WorksheetParts.First();
            SheetData        sheetData        = worksheetPart.Worksheet.Elements <SheetData>().First();
            CellFormats      cellFormats      = wbPart.WorkbookStylesPart.Stylesheet.CellFormats;
            NumberingFormats numberingFormats = wbPart.WorkbookStylesPart.Stylesheet.NumberingFormats;

            int  rowCount          = sheetData.Elements <Row>().Count();
            bool formatoExcelNuovo = false;

            if (rowCount > 0)
            {
                Row  r    = sheetData.Elements <Row>().FirstOrDefault();
                Cell cell = r.Elements <Cell>().FirstOrDefault();

                string cella = EstraiValoreCella(cell, sharedStringTable, cellFormats, numberingFormats);
                if (cella == "ID Prenotazione Collaudo")
                {
                    formatoExcelNuovo = true;
                }
            }


            bool intestazione = true;

            foreach (Row r in sheetData.Elements <Row>())
            {
                if (intestazione)
                {
                    intestazione = false;
                    continue;
                }
                bool esito = true;
                CDCDS.CDC_DETTAGLIO_relRow dettaglio = ds.CDC_DETTAGLIO_rel.NewCDC_DETTAGLIO_relRow();
                dettaglio.IDEXCEL     = IDEXCEL; //- perchè non ammette null
                dettaglio.IDDETTAGLIO = r.RowIndex;

                int  count     = r.Elements <Cell>().Count();
                bool saltaRiga = false;
                foreach (Cell cell in r.Elements <Cell>())
                {
                    string cella = EstraiValoreCella(cell, sharedStringTable, cellFormats, numberingFormats);
                    cella = cella.Trim();
                    string colonna = GetColumnReference(cell);

                    if (saltaRiga)
                    {
                        continue;
                    }

                    switch (colonna)
                    {
                    case "A":     //idprenotazione
                        if (string.IsNullOrEmpty(cella))
                        {
                            saltaRiga = true;
                            continue;
                        }
                        esito = EstraiValoreCellaDecimal(cella, "IDPRENOTAZIONE", dettaglio, out messaggioErrore);
                        break;

                    case "B":     // id_verbale
                    {
                        int lunghezza = 10;
                        dettaglio.IDVERBALE = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                    }
                    break;

                    case "C":     // data_collaudo
                        if (!VerificaData(cella))
                        {
                            messaggioErrore = "La colonna DATA COLLAUDO non è una data nel formato dd/mm/yyyy";
                            esito           = false;
                        }
                        else
                        {
                            int lunghezza = 10;
                            dettaglio.DATACOLLAUDO = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                        }
                        break;

                    case "D":     // accessorista
                    {
                        int lunghezza = 30;
                        dettaglio.ACCESSORISTA = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                    }
                    break;

                    case "E":     // prefisso
                    {
                        int lunghezza = 7;
                        dettaglio.PREFISSO = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                    }
                    break;

                    case "F":     // parte
                    {
                        int lunghezza = 6;
                        dettaglio.PARTE = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                    }
                    break;

                    case "G":     // colore
                    {
                        int lunghezza = 5;
                        dettaglio.COLORE = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella.PadLeft(4, '0');
                    }
                    break;

                    case "H":     // misura
                    {
                        esito = EstraiValoreCellaDecimal(cella, "MISURA", dettaglio, out messaggioErrore);
                    }
                    break;

                    case "I":     // livellodiff
                        if (!string.IsNullOrEmpty(cella))
                        {
                            esito = EstraiValoreCellaDecimal(cella, "LIVELLODIFF", dettaglio, out messaggioErrore);
                        }
                        break;

                    case "J":     // commessaordine
                    {
                        int lunghezza = 18;
                        dettaglio.COMMESSAORDINE = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                    }
                    break;

                    case "K":     // ente
                    {
                        int lunghezza = 5;
                        dettaglio.ENTE = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;

                        CDCDS.CDC_ENTIRow ente = ds.CDC_ENTI.Where(x => x.CODICE == dettaglio.ENTE).FirstOrDefault();

                        if (ente != null)
                        {
                            dettaglio.IDBRAND = ente.IDBRAND;
                        }
                    }
                    break;

                    case "L":     // um
                    {
                        if (formatoExcelNuovo)
                        {
                            dettaglio.UM = string.Empty;
                            esito        = EstraiValoreCellaDecimal(cella, "QUANTITA", dettaglio, out messaggioErrore);
                        }
                        else
                        {           // UM
                            int lunghezza = 2;
                            dettaglio.UM = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                        }
                    }
                    break;

                    case "M":     // qta
                        if (formatoExcelNuovo)
                        {
                            int lunghezza = 6;
                            dettaglio.QUANTITAVALIDITA = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                        }
                        else
                        {
                            esito = EstraiValoreCellaDecimal(cella, "QUANTITA", dettaglio, out messaggioErrore);
                        }
                        break;

                    case "N":     // assegn
                    {
                        if (formatoExcelNuovo)
                        {
                            dettaglio.ASSEGN = string.Empty;
                            int lunghezza = 5;
                            dettaglio.AUTO = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                        }
                        else
                        {
                            int lunghezza = 2;
                            dettaglio.ASSEGN = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                        }
                    }
                    break;

                    case "O":     // auto
                    {
                        if (formatoExcelNuovo)
                        {
                            int lunghezza = 5;
                            dettaglio.COLLTO = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                        }
                        else
                        {
                            int lunghezza = 5;
                            dettaglio.AUTO = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                        }
                    }
                    break;

                    case "P":     // coll_to
                    {
                        if (formatoExcelNuovo)
                        {
                            int lunghezza = 2;
                            dettaglio.LOTTOBLOCCATO = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                        }
                        else
                        {
                            int lunghezza = 5;
                            dettaglio.COLLTO = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                        }
                    }
                    break;

                    case "Q":     // qtavalidita
                    {
                        if (formatoExcelNuovo)
                        {
                            int lunghezza = 2;
                            dettaglio.VERBALEBLOCCATO = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                        }
                        else
                        {
                            int lunghezza = 6;
                            dettaglio.QUANTITAVALIDITA = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                        }
                    }
                    break;

                    case "R":     // lotto_bloccato
                    {
                        if (!formatoExcelNuovo)
                        {
                            int lunghezza = 2;
                            dettaglio.LOTTOBLOCCATO = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                        }
                    }
                    break;

                    case "S":     // verbalebloccato
                    {
                        if (!formatoExcelNuovo)
                        {
                            int lunghezza = 2;
                            dettaglio.VERBALEBLOCCATO = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                        }
                    }
                    break;

                    case "T":     // deroga
                    {
                        if (!formatoExcelNuovo)
                        {
                            int lunghezza = 2;
                            dettaglio.DEROGA = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                        }
                        else
                        {
                            dettaglio.DEROGA = string.Empty;
                        }
                    }
                    break;

                    case "U":     // controllo dimensionale
                    {
                        if (!formatoExcelNuovo)
                        {
                            int lunghezza = 2;
                            dettaglio.CONTROLLODIMENSIONALE = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                        }
                        else
                        {
                            dettaglio.CONTROLLODIMENSIONALE = string.Empty;
                        }
                    }
                    break;

                    case "V":     // controllo estetico
                    {
                        if (!formatoExcelNuovo)
                        {
                            int lunghezza = 2;
                            dettaglio.CONTROLLOESTETICO = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                        }
                        else
                        {
                            dettaglio.CONTROLLOESTETICO = string.Empty;
                        }
                    }
                    break;

                    case "W":     // controllo funzionale
                    {
                        if (!formatoExcelNuovo)
                        {
                            int lunghezza = 2;
                            dettaglio.CONTROLLOFUNZIONALE = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                        }
                        else
                        {
                            dettaglio.CONTROLLOFUNZIONALE = string.Empty;
                        }
                    }
                    break;

                    case "X":     // esitotest chimico
                    {
                        if (!formatoExcelNuovo)
                        {
                            int lunghezza = 2;
                            dettaglio.ESITOTESTCHIMICO = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                        }
                        else
                        {
                            dettaglio.ESITOTESTCHIMICO = string.Empty;
                        }
                    }
                    break;

                    case "Y":     // test fisico
                    {
                        if (!formatoExcelNuovo)
                        {
                            int lunghezza = 2;
                            dettaglio.TESTFISICO = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                        }
                        else
                        {
                            dettaglio.TESTFISICO = string.Empty;
                        }
                    }
                    break;

                    case "Z":     // notecollaudo
                    {
                        if (!formatoExcelNuovo)
                        {
                            int lunghezza = 100;
                            dettaglio.NOTECOLLAUDO = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                        }
                        else
                        {
                            dettaglio.NOTECOLLAUDO = string.Empty;
                        }
                    }
                    break;

                    case "AA":     // assegnazione
                    {
                        if (!formatoExcelNuovo)
                        {
                            int lunghezza = 500;
                            dettaglio.ASSEGNAZIONE = cella.Length > lunghezza?cella.Substring(0, lunghezza) : cella;
                        }
                        else
                        {
                            dettaglio.ASSEGNAZIONE = string.Empty;
                        }
                    }
                    break;
                    }
                    if (!esito)
                    {
                        return(false);
                    }
                }

                //cercare il brand in base ad ente
                //dettaglio.IDBRAND = dettaglio.ENTE;
                // string selezione = ConvertToStringForInCondition(dettaglio.ENTE);
                //string select = @"SELECT * FROM CDC_ENTI WHERE CODICE = '{0}' ";

                //string query = string.Format(select, dettaglio.ENTE.ToString());

                //using (System.Data.Common.DbDataAdapter da = (System.Data.Common.BuildDataAdapter(query))
                //{
                //    da.Fill(ds.CDC_PDF);
                //}

                ///

                ds.CDC_DETTAGLIO_rel.AddCDC_DETTAGLIO_relRow(dettaglio);
            }

            return(true);
        }