private void SalvaCertificatoPiombo() { CDCDS ds = new CDCDS(); CDCDS.CDC_CERTIFICATIPIOMBORow cPiombo = ds.CDC_CERTIFICATIPIOMBO.NewCDC_CERTIFICATIPIOMBORow(); cPiombo.ELEMENTO = ddlElemento.SelectedItem as string; cPiombo.CODICE = txtCodice.Text; Materiale materiale = ddlMateriale.SelectedItem as Materiale; cPiombo.MATERIALE = materiale.Nome; cPiombo.LOTTO = txtLotto.Text; cPiombo.LUNGHEZZA = nLunghezza.Value; cPiombo.LARGHEZZA = nLarghezza.Value; cPiombo.SPESSORE = nSpessore.Value; cPiombo.METODO = txtMetodo.Text; cPiombo.PESOCAMPIONE = nPesoCampione.Value; cPiombo.MATRACCIOLO = nMatracciolo.Value; cPiombo.CONCENTRAZIONE = nConcentrazione.Value; cPiombo.PBPPM = nPd.Value; cPiombo.CDPPM = nCd.Value; cPiombo.ESITO = txtEsito.Text; cPiombo.DATACERTIFICATO = dtDataCertificato.Value; cPiombo.UTENTE = Contesto.Utente.FULLNAMEUSER; cPiombo.DATAINSERIMENTO = DateTime.Now; ds.CDC_CERTIFICATIPIOMBO.AddCDC_CERTIFICATIPIOMBORow(cPiombo); CDCBLL bll = new CDCBLL(); bll.SalvaCertificatiPiombo(ds); }
private bool EstraiValoreCellaDecimal(string cella, string colonna, CDCDS.CDC_CERTIFICATIPIOMBORow 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); }
private string EstraiPathFileDaCopiare(CertificatoPiombo cp) { CDCBLL bll = new CDCBLL(); string cartella, nomeCampione; string fileDaCopiare = cp.path; if (string.IsNullOrEmpty(cp.path)) { CDCDS.CDC_CERTIFICATIPIOMBORow certificato = _DS.CDC_CERTIFICATIPIOMBO.Where(x => x.IDCERTIFICATIPIOMBO == cp.IDCERTIFICATIPIOMBO).FirstOrDefault(); if (certificato == null) { return string.Empty; } fileDaCopiare = bll.CreaNomefileCertificatiAnalisiPiombo(certificato.ELEMENTO, certificato.LUNGHEZZA.ToString(), certificato.LARGHEZZA.ToString(), string.Empty, certificato.CODICE, certificato.DATACERTIFICATO, Contesto.PathAnalisiPiombo, out cartella, out nomeCampione); } return fileDaCopiare; }
public bool ReadAnalisiPiombo(Stream stream, CDCDS ds, string utente, out string messaggioErrore) { messaggioErrore = string.Empty; SpreadsheetDocument document = SpreadsheetDocument.Open(stream, true); SharedStringTable sharedStringTable = document.WorkbookPart.SharedStringTablePart.SharedStringTable; WorkbookPart wbPart = document.WorkbookPart; Sheet foglio = EstraiSheetPerNome(wbPart, "Calcolo Pb+Cd"); WorksheetPart worksheetPart = (WorksheetPart)wbPart.GetPartById(foglio.Id); 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(); int scartaRighe = 11; int indiceRighe = 0; foreach (Row r in sheetData.Elements <Row>()) { if (indiceRighe < scartaRighe) { indiceRighe++; continue; } bool esito = true; if (r.FirstChild.InnerText == string.Empty) { continue; } CDCDS.CDC_CERTIFICATIPIOMBORow cPiombo = ds.CDC_CERTIFICATIPIOMBO.NewCDC_CERTIFICATIPIOMBORow(); cPiombo.MATERIALE = "OTTONE CON PIOMBO"; string elemento = string.Empty; foreach (Cell cell in r.Elements <Cell>()) { string cella = EstraiValoreCella(cell, sharedStringTable, cellFormats, numberingFormats); cella = cella.Trim(); string colonna = GetColumnReference(cell); switch (colonna) { case "A": if (string.IsNullOrEmpty(cella)) { continue; } cPiombo.CODICE = EstraiStringaDaCella(cella, ds.CDC_CERTIFICATIPIOMBO.Columns[2].MaxLength); //esito = EstraiValoreCellaDecimal(cella, "IDPRENOTAZIONE", cPiombo, out messaggioErrore); break; case "B": { cPiombo.LOTTO = EstraiStringaDaCella(cella, ds.CDC_CERTIFICATIPIOMBO.Columns[4].MaxLength); } break; case "C": //if (!VerificaData(cella)) //{ // messaggioErrore = "La colonna DATA COLLAUDO non è una data nel formato yyyy/mm/dd"; // esito = false; //} //else //{ // int lunghezza = 10; // cPiombo.DATACOLLAUDO = cella.Length > lunghezza ? cella.Substring(0, lunghezza) : cella; //} break; case "D": { esito = EstraiValoreCellaDecimal(cella.Replace('.', ','), "PESOCAMPIONE", cPiombo, out messaggioErrore); } break; case "E": { esito = EstraiValoreCellaDecimal(cella.Replace('.', ','), "MATRACCIOLO", cPiombo, out messaggioErrore); } break; case "F": { esito = EstraiValoreCellaDecimal(cella.Replace('.', ','), "CONCENTRAZIONE", cPiombo, out messaggioErrore); } break; case "G": { esito = EstraiValoreCellaDecimal(cell.CellValue.InnerText.Replace('.', ','), "PBPPM", cPiombo, out messaggioErrore); } break; case "H": { } break; case "I": esito = EstraiValoreCellaDecimal(cell.CellValue.InnerText.Replace('.', ','), "CDPPM", cPiombo, out messaggioErrore); break; case "J": { cPiombo.ELEMENTO = EstraiStringaDaCella(cella, ds.CDC_CERTIFICATIPIOMBO.Columns[1].MaxLength); switch (cPiombo.ELEMENTO.Trim().ToUpper()) { case "BARRA": cPiombo.ELEMENTO = barraTonda; break; case "PIATTO": cPiombo.ELEMENTO = piatto; break; default: cPiombo.ELEMENTO = "ALTRO"; break; } } break; case "K": { if (cella.Length == 0) { cPiombo.MATERIALE = "OTTONE CON PIOMBO"; } else { cPiombo.MATERIALE = "OTTONE SENZA PIOMBO"; } } break; case "L": { if (!string.IsNullOrEmpty(cella)) { esito = EstraiValoreCellaDecimal(cella, "LUNGHEZZA", cPiombo, out messaggioErrore); } } break; case "M": if (!string.IsNullOrEmpty(cella)) { esito = EstraiValoreCellaDecimal(cella, "LARGHEZZA", cPiombo, out messaggioErrore); } break; case "N": { if (!string.IsNullOrEmpty(cella)) { esito = EstraiValoreCellaDecimal(cella, "SPESSORE", cPiombo, out messaggioErrore); } } break; } if (!esito) { return(false); } } if (cPiombo[2] == DBNull.Value) { continue; } cPiombo.ESITO = (cPiombo.PBPPM >= 80) ? "FAIL" : "PASS"; cPiombo.DATACERTIFICATO = DateTime.Today; cPiombo.DATAINSERIMENTO = DateTime.Today; cPiombo.UTENTE = utente; cPiombo.METODO = "XRF"; cPiombo.PBPPM = Math.Round(cPiombo.PBPPM); cPiombo.CDPPM = Math.Round(cPiombo.CDPPM); ds.CDC_CERTIFICATIPIOMBO.AddCDC_CERTIFICATIPIOMBORow(cPiombo); } return(true); }