Example #1
0
        public void MostraEccezione(string messaggioLog, Exception ex)
        {
            LogScriviErrore(messaggioLog, ex);
            ExceptionFrm frm = new ExceptionFrm(ex);

            frm.ShowDialog();
        }
Example #2
0
        private void btnApriFile_Click(object sender, EventArgs e)
        {
            try
            {
                lblMessage.Text = string.Empty;
                if (string.IsNullOrEmpty(txtFilePath.Text))
                {
                    lblMessage.Text = "Selezionare un file";
                    return;
                }

                if (!File.Exists(txtFilePath.Text))
                {
                    lblMessage.Text = "Il file specificato non esiste";
                    return;
                }

                ExcelBLL bll    = new ExcelBLL();
                CDCBLL   cdcBll = new CDCBLL();
                string   messaggioErrore;
                if (!bll.LeggiExcelAnalisiPiombo(_DS, txtFilePath.Text, Contesto.Utente.FULLNAMEUSER, out messaggioErrore))
                {
                    string messaggio = string.Format("Errore nel caricamento del file excel. Errore: {0}", messaggioErrore);
                    MessageBox.Show(messaggio, "ERRORE LETTURA FILE", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                lblNumeroRigheExcel.Text = _DS.CDC_CERTIFICATIPIOMBO.Count.ToString();
                if (_DS.CDC_CERTIFICATIPIOMBO.Count == 0)
                {
                    lblMessage.Text = "Il file è vuoto";
                    return;
                }

                dgvExcelCaricato.AutoGenerateColumns = true;
                dgvExcelCaricato.DataSource          = _DS;
                dgvExcelCaricato.DataMember          = _DS.CDC_CERTIFICATIPIOMBO.TableName;
                dgvExcelCaricato.Columns["IDCERTIFICATIPIOMBO"].Visible = false;
                dgvExcelCaricato.Columns["UTENTE"].Visible          = false;
                dgvExcelCaricato.Columns["DATAINSERIMENTO"].Visible = false;

                foreach (DataGridViewRow riga in dgvExcelCaricato.Rows)
                {
                    decimal nPd = (decimal)riga.Cells["PBPPM"].Value;
                    Color   colore;
                    riga.Cells["ESITO"].Value           = cdcBll.CalcolaEsitoAnalisiPiombo(nPd, out colore);
                    riga.Cells["ESITO"].Style.BackColor = colore;
                }
            }
            catch (Exception ex)
            {
                MainForm.LogScriviErrore("ERRORE IN APRI FILE EXCEL", ex);
                ExceptionFrm frm = new ExceptionFrm(ex);
                frm.ShowDialog();
            }
        }
        private void btnSalvaDB_Click(object sender, EventArgs e)

        {
            try
            {
                Cursor.Current  = Cursors.WaitCursor;
                lblMessage.Text = string.Empty;

                ExcelBLL       bll = new ExcelBLL();
                List <decimal> IDPRENOTAZIONE_DUPLICATO = bll.VerificaExcelCaricato(_DS);
                if (IDPRENOTAZIONE_DUPLICATO.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("Ci sono righe che sono già state salvate sul database (doppioni).");
                    sb.AppendLine("Le righe duplicate NON saranno salvate.");

                    MessageBox.Show(sb.ToString(), "RIGHE DUPLICATE", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                    List <CDCDS.CDC_DETTAGLIORow> daCancellare = _DS.CDC_DETTAGLIO.Where(x => x.RowState != DataRowState.Deleted && IDPRENOTAZIONE_DUPLICATO.Contains(x.IDPRENOTAZIONE)).ToList();
                    foreach (CDCDS.CDC_DETTAGLIORow dettaglio in daCancellare)
                    {
                        dettaglio.Delete();
                    }

                    _DS.CDC_DETTAGLIO.AcceptChanges();
                }

                bll.Salva(_DS);

                lblMessage.Text        = "Salvataggio riuscito";
                ddlBrand.SelectedIndex = -1;

                string message = "operazione riuscita";
                MessageBox.Show(message, "INFORMAZIONE", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MainForm.LogScriviErrore("ERRORE IN APRI FILE EXCEL", ex);
                ExceptionFrm frm = new ExceptionFrm(ex);
                frm.ShowDialog();
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Example #4
0
        private void btnCercaFile_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Multiselect = false;
                openFileDialog.Filter      = "Excel files (*.xlsx)|*.xlsx";

                openFileDialog.RestoreDirectory = true;

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    txtFilePath.Text = openFileDialog.FileName;
                }
            }
            catch (Exception ex)
            {
                MainForm.LogScriviErrore("ERRORE IN CERCA FILE EXCEL", ex);
                ExceptionFrm frm = new ExceptionFrm(ex);
                frm.ShowDialog();
            }
        }
Example #5
0
        private void btnCreaPdf_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                foreach (CDCDS.CDC_CERTIFICATIPIOMBORow riga in _DS.CDC_CERTIFICATIPIOMBO)
                {
                    if (string.IsNullOrEmpty(riga.LOTTO))
                    {
                        MessageBox.Show("La colonna LOTTO deve essere valorizzata", "ERRORE", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                Bitmap         firma     = Properties.Resources.logo_tf_autodichiarazione;
                ImageConverter converter = new ImageConverter();
                byte[]         image     = (byte[])converter.ConvertTo(firma, typeof(byte[]));

                CDCBLL bll = new CDCBLL();

                StringBuilder files = new StringBuilder();

                foreach (CDCDS.CDC_CERTIFICATIPIOMBORow riga in _DS.CDC_CERTIFICATIPIOMBO)
                {
                    decimal nPd = riga.PBPPM;
                    Color   colore;
                    bll.CalcolaEsitoAnalisiPiombo(nPd, out colore);
                    string spessore  = string.Empty;
                    string lunghezza = string.Empty;
                    string larghezza = string.Empty;
                    string elemento  = string.Empty;
                    if (!riga.IsELEMENTONull())
                    {
                        elemento = riga.ELEMENTO.ToString();
                    }

                    if (!riga.IsLUNGHEZZANull())
                    {
                        lunghezza = riga.LUNGHEZZA.ToString();
                    }
                    if (!riga.IsLARGHEZZANull())
                    {
                        larghezza = riga.LARGHEZZA.ToString();
                    }

                    if (!riga.IsSPESSORENull())
                    {
                        spessore = riga.SPESSORE.ToString();
                    }
                    string path = bll.CreaPDFCertificatoPiombo(elemento, lunghezza, larghezza, spessore.ToString(), riga.CODICE, riga.LOTTO,
                                                               riga.ESITO, colore, riga.METODO, riga.DATACERTIFICATO, riga.PBPPM, riga.CDPPM, Contesto.PathAnalisiPiombo, image);
                    files.AppendLine(path);
                    riga.PATHFILE = path.Length > 300 ? path.Substring(0, 300) : path;
                }
                //List<CDCDS.CDC_CERTIFICATIPIOMBORow> certificati = _DS.CDC_CERTIFICATIPIOMBO.Where(x => x.IsLUNGHEZZANull()).ToList();
                //foreach (CDCDS.CDC_CERTIFICATIPIOMBORow certificato in certificati)
                //    certificato.Delete();
                bll.SalvaCertificatiPiombo(_DS);

                MessageBox.Show("Operazionbe eseguita con successo", "INFORMAZIONE", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MainForm.LogScriviErrore("ERRORE IN CREA PDF", ex);
                ExceptionFrm frm = new ExceptionFrm(ex);
                frm.ShowDialog();
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
        private void btnApriFile_Click(object sender, EventArgs e)
        {
            try
            {
                btnSalvaDB.Enabled = false;

                lblMessage.Text = string.Empty;
                if (string.IsNullOrEmpty(txtFilePath.Text))
                {
                    lblMessage.Text = "Selezionare un file";
                    return;
                }

                if (!File.Exists(txtFilePath.Text))
                {
                    lblMessage.Text = "Il file specificato non esiste";
                    return;
                }

                if (ddlBrand.SelectedIndex == -1)
                {
                    lblMessage.Text = "Selezionare il brand a cui si riferisce il file EXCEL.";
                    return;
                }
                string brand = (string)ddlBrand.SelectedItem;

                ExcelBLL bll = new ExcelBLL();
                string   messaggioErrore;
                if (!bll.LeggiExcelCDC(_DS, txtFilePath.Text, Contesto.Utente.FULLNAMEUSER, brand, out messaggioErrore))
                {
                    string messaggio = string.Format("Errore nel caricamento del file excel. Errore: {0}", messaggioErrore);
                    MessageBox.Show(messaggio, "ERRORE LETTURA FILE", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                lblNumeroRigheExcel.Text = _DS.CDC_DETTAGLIO.Count.ToString();
                if (_DS.CDC_DETTAGLIO.Count > 0)
                {
                    lblDataExcel.Text = _DS.CDC_DETTAGLIO.FirstOrDefault().DATACOLLAUDO;
                }
                else
                {
                    lblMessage.Text = "Il file è vuoto";
                    return;
                }

                btnSalvaDB.Enabled = true;

                dgvExcelCaricato.AutoGenerateColumns            = true;
                dgvExcelCaricato.DataSource                     = _DS;
                dgvExcelCaricato.DataMember                     = _DS.CDC_DETTAGLIO.TableName;
                dgvExcelCaricato.Columns["IDDETTAGLIO"].Visible = false;
                dgvExcelCaricato.Columns["IDEXCEL"].Visible     = false;

                List <decimal> IDPRENOTAZIONE_DUPLICATO = bll.VerificaExcelCaricato(_DS);
                if (IDPRENOTAZIONE_DUPLICATO.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("Sono state individuate delle righe il cui ID PRENOTAZIONE è già stato acquisito. Si tratta di righe duplicate.");
                    sb.AppendLine("Di seguito gli ID PRENOTAZIONE duplicati:");
                    foreach (decimal id in IDPRENOTAZIONE_DUPLICATO)
                    {
                        sb.AppendLine(id.ToString());
                    }

                    MessageBox.Show(sb.ToString(), "RIGHE DUPLICATE", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                foreach (DataGridViewRow riga in dgvExcelCaricato.Rows)
                {
                    decimal IDPRENOTAZIONE = (decimal)riga.Cells["IDPRENOTAZIONE"].Value;
                    if (IDPRENOTAZIONE_DUPLICATO.Contains(IDPRENOTAZIONE))
                    {
                        riga.Cells["IDPRENOTAZIONE"].Style.BackColor = Color.Yellow;
                    }
                }
            }
            catch (Exception ex)
            {
                MainForm.LogScriviErrore("ERRORE IN APRI FILE EXCEL", ex);
                ExceptionFrm frm = new ExceptionFrm(ex);
                frm.ShowDialog();
            }
        }
        private void btnCreaPDF_Click(object sender, EventArgs e)
        {
            StringBuilder sb    = new StringBuilder();
            bool          esito = true;

            if (ddlElemento.SelectedIndex == -1)
            {
                esito = false;
                sb.AppendLine("Indicare l'elemento da analizzare");
            }

            if (string.IsNullOrEmpty(txtCodice.Text))
            {
                esito = false;
                sb.AppendLine("Indicare il codice campione");
            }

            if (ddlMateriale.SelectedIndex == -1)
            {
                esito = false;
                sb.AppendLine("Indicare il materiale");
            }

            if (string.IsNullOrEmpty(txtLotto.Text))
            {
                esito = false;
                sb.AppendLine("Indicare il lotto");
            }

            if (nLunghezza.Value == 0)
            {
                esito = false;
                sb.AppendLine("Indicare la lunghezza");
            }

            if (ddlElemento.SelectedItem as string == barraTonda && nLarghezza.Value == 0)
            {
                esito = false;
                sb.AppendLine("Indicare il diametro");
            }

            if (ddlElemento.SelectedItem as string != barraTonda && nLarghezza.Value == 0)
            {
                esito = false;
                sb.AppendLine("Indicare la larghezza");
            }

            if (ddlElemento.SelectedItem as string != barraTonda && nSpessore.Value == 0)
            {
                esito = false;
                sb.AppendLine("Indicare lo spessore");
            }
            try
            {
                SalvaCertificatoPiombo();

                Bitmap         firma     = Properties.Resources.logo_tf_autodichiarazione;
                ImageConverter converter = new ImageConverter();
                byte[]         image     = (byte[])converter.ConvertTo(firma, typeof(byte[]));

                CDCBLL bll  = new CDCBLL();
                string path = bll.CreaPDFCertificatoPiombo(ddlElemento.SelectedItem as string, nLunghezza.Value.ToString(), nLarghezza.Value.ToString(), nSpessore.Value.ToString(), txtCodice.Text, txtLotto.Text,
                                                           txtEsito.Text, txtEsito.BackColor, txtMetodo.Text, dtDataCertificato.Value, nPd.Value, nCd.Value, Contesto.PathAnalisiPiombo, image);

                string messaggio = string.Format("Il file {0} è stato creato", path);
                MessageBox.Show(messaggio, "ATTENZIONE", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MainForm.LogScriviErrore("ERRORE IN CREA PDF", ex);
                ExceptionFrm frm = new ExceptionFrm(ex);
                frm.ShowDialog();
            }
        }
        private void btnApriFile_Click(object sender, EventArgs e)
        {
            try
            {
                btnSalvaDB.Enabled = false;

                lblMessage.Text = string.Empty;
                if (string.IsNullOrEmpty(txtFilePath.Text))
                {
                    lblMessage.Text = "Selezionare un file";
                    return;
                }

                if (!File.Exists(txtFilePath.Text))
                {
                    lblMessage.Text = "Il file specificato non esiste";
                    return;
                }



                ExcelBLL bll = new ExcelBLL();
                string   messaggioErrore;
                if (!bll.LeggiExcelCDC(_DS, txtFilePath.Text, Contesto.Utente.FULLNAMEUSER, out messaggioErrore)) //brand,
                {
                    string messaggio = string.Format("Errore nel caricamento del file excel. Errore: {0}", messaggioErrore);
                    MessageBox.Show(messaggio, "ERRORE LETTURA FILE", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                lblNumeroRigheExcel.Text = _DS.CDC_DETTAGLIO_rel.Count.ToString();
                if (_DS.CDC_DETTAGLIO_rel.Count > 0)
                {
                    lblDataExcel.Text = _DS.CDC_DETTAGLIO_rel.FirstOrDefault().DATACOLLAUDO;
                }
                else
                {
                    lblMessage.Text = "Il file è vuoto";
                    return;
                }

                btnSalvaDB.Enabled = true;



                dgvExcelCaricato.AutoGenerateColumns            = true;
                dgvExcelCaricato.DataSource                     = _DS;
                dgvExcelCaricato.DataMember                     = _DS.CDC_DETTAGLIO_rel.TableName;
                dgvExcelCaricato.Columns["IDDETTAGLIO"].Visible = false;
                dgvExcelCaricato.Columns["IDEXCEL"].Visible     = false;
                dgvExcelCaricato.Columns["IDBRAND"].Visible     = false;
                dgvExcelCaricato.ReadOnly = false;
                foreach (DataGridViewColumn col in dgvExcelCaricato.Columns)
                {
                    col.ReadOnly = true;
                }

                if (dgvExcelCaricato.Columns.Contains("BRAND"))
                {
                    dgvExcelCaricato.Columns.Remove("BRAND");
                }

                var comboCol = new DataGridViewComboBoxColumn();
                comboCol.HeaderText       = "BRAND";
                comboCol.Name             = "BRAND";
                comboCol.DataPropertyName = "IDBRAND";
                comboCol.AutoComplete     = true;
                comboCol.Width            = 100;
                comboCol.DropDownWidth    = 100;
                comboCol.DataSource       = _DS.CDC_BRANDS;
                comboCol.DisplayMember    = "CODICE";
                comboCol.ValueMember      = "IDBRAND";
                comboCol.ReadOnly         = false;
                dgvExcelCaricato.Columns.Add(comboCol);



                List <decimal> IDPRENOTAZIONE_DUPLICATO = bll.VerificaExcelCaricato(_DS);

                List <decimal> IDPRENOTAZIONE_NOBRAND = bll.VerificaExcelCaricatoBrand(_DS).ToList();

                if (IDPRENOTAZIONE_DUPLICATO.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("Sono state individuate delle righe il cui ID PRENOTAZIONE è già stato acquisito. Si tratta di righe duplicate.");
                    sb.AppendLine("Di seguito gli ID PRENOTAZIONE duplicati:");
                    foreach (decimal id in IDPRENOTAZIONE_DUPLICATO)
                    {
                        sb.AppendLine(id.ToString());
                    }

                    MessageBox.Show(sb.ToString(), "RIGHE DUPLICATE", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                if (IDPRENOTAZIONE_NOBRAND.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("Sono state individuate delle righe per le quali non è stato possibile attribuire il BRAND.");
                    sb.AppendLine("Di seguito gli ID PRENOTAZIONE:");
                    foreach (decimal id in IDPRENOTAZIONE_NOBRAND)
                    {
                        sb.AppendLine(id.ToString());
                    }

                    MessageBox.Show(sb.ToString(), "RIGHE SENZA BRAND", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }



                ///ALLA FINE
                foreach (DataGridViewRow riga in dgvExcelCaricato.Rows)
                {
                    decimal IDPRENOTAZIONE = (decimal)riga.Cells["IDPRENOTAZIONE"].Value;

                    if (IDPRENOTAZIONE_NOBRAND.Contains(IDPRENOTAZIONE))
                    {
                        riga.Cells["IDPRENOTAZIONE"].Style.BackColor = Color.Orange;
                    }

                    if (IDPRENOTAZIONE_DUPLICATO.Contains(IDPRENOTAZIONE))
                    {
                        riga.Cells["IDPRENOTAZIONE"].Style.BackColor = Color.Yellow;
                    }
                }
            }
            catch (Exception ex)
            {
                MainForm.LogScriviErrore("ERRORE IN APRI FILE EXCEL", ex);
                ExceptionFrm frm = new ExceptionFrm(ex);
                frm.ShowDialog();
            }
        }