Esempio n. 1
0
        private void btnTrova_Click(object sender, EventArgs e)
        {
            try
            {
                string codiceFornitore = verificaRadioButton();
                if (string.IsNullOrEmpty(codiceFornitore))
                {
                    MessageBox.Show("Attenzione indicare l'azienda METALPLUS o TOP FINISH", "ERRORE", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }


                if (dtDal.Value.Date > dtAl.Value.Date)
                {
                    MessageBox.Show("Attenzione la data DAL è successiva alla data AL", "ERRORE", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                using (EDIFornitoriBusiness bEDI = new EDIFornitoriBusiness())
                    using (EDIFornitoriBusinessSQL bEDISQL = new EDIFornitoriBusinessSQL())
                    {
                        _ds = new EDIFornitoriDS();
                        if (rbBusinessCentral.Checked)
                        {
                            bEDISQL.FillBOLLE_VENDITATESTATA(_ds, dtDal.Value, dtAl.Value);
                        }
                        else
                        {
                            bEDI.FillBOLLE_VENDITATESTATA(_ds, dtDal.Value, dtAl.Value, codiceFornitore);
                        }
                        dgvRisultati.DataSource = _ds;
                        dgvRisultati.DataMember = _ds.BOLLE_VENDITA.TableName;
                    }
            }
            catch (Exception ex)
            {
                MostraEccezione(ex, "Errore in trova bolle");
            }
        }
Esempio n. 2
0
        private void btnCreaFiles_Click(object sender, EventArgs e)
        {
            bool riferimentoAssente = false;

            try
            {
                List <string> idTestate = new List <string>();
                foreach (DataGridViewRow riga in dgvRisultati.Rows)
                {
                    object selezione = riga.Cells[SELEZIONATA.Index].Value;
                    if (selezione != null)
                    {
                        bool valore = (bool)selezione;
                        if (valore)
                        {
                            string idTestata = (string)riga.Cells[IDVENDITET.Index].Value;
                            idTestate.Add(idTestata);

                            if (riga.Cells[RIFERIMENTO.Index].Value == DBNull.Value)
                            {
                                riferimentoAssente = true;
                            }
                        }
                    }
                }

                if (idTestate.Count == 0)
                {
                    MessageBox.Show("Nessuna bolla selezionata", "ATTENZIONE", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return;
                }

                if (riferimentoAssente)
                {
                    MessageBox.Show("Sono state selezionate bolle prive di RIFERIMENTO. Impossibile procedere", "ATTENZIONE", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                FolderBrowserDialog fbd = new FolderBrowserDialog();
                if (fbd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                string path = fbd.SelectedPath;

                EDIFornitoriDS ds = new EDIFornitoriDS();
                string         codiceFornitore = verificaRadioButton();

                if (rbRVL.Checked)
                {
                    using (EDIFornitoriBusiness bEDI = new EDIFornitoriBusiness())
                    {
                        bEDI.FillBOLLE_VENDITA(ds, dtDal.Value, dtAl.Value, codiceFornitore);
                        bEDI.FillACCESSORISTI(ds);
                    }
                }
                else
                {
                    using (EDIFornitoriBusinessSQL bEDI = new EDIFornitoriBusinessSQL())
                    {
                        bEDI.FillBOLLE_VENDITA(ds, dtDal.Value, dtAl.Value);
                        bEDI.FillACCESSORISTI(ds);
                    }
                }

                StringBuilder sbMessaggio = new StringBuilder();
                idTestate = idTestate.Distinct().ToList();

                foreach (string testata in idTestate)
                {
                    EDIFornitoriDS.BOLLE_VENDITARow primoDettaglio = ds.BOLLE_VENDITA.Where(x => x.IDVENDITET == testata).FirstOrDefault();
                    string numeroddt    = primoDettaglio.NUMDOC;
                    string nomefile     = creaNomeFile(codiceFornitore, numeroddt);
                    string pathCompleto = path + Path.DirectorySeparatorChar + nomefile;

                    if (File.Exists(pathCompleto))
                    {
                        File.Delete(pathCompleto);
                    }

                    FileStream   fs = new FileStream(pathCompleto, FileMode.Create);
                    StreamWriter sw = new StreamWriter(fs);
                    try
                    {
                        foreach (EDIFornitoriDS.BOLLE_VENDITARow dettaglio in ds.BOLLE_VENDITA.Where(x => x.IDVENDITET == testata))
                        {
                            string AccessoristaNonTrovato;
                            string riga = creaRigaFile(codiceFornitore, dettaglio, ds, out AccessoristaNonTrovato);
                            sw.WriteLine(riga);
                            sbMessaggio.AppendLine(AccessoristaNonTrovato);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        sw.Flush();
                        fs.Flush();
                        fs.Close();
                    }
                }

                if (sbMessaggio.ToString().Trim().Length > 0)
                {
                    sbMessaggio.Insert(0, @"I seguenti ACCESSORISTI non sono stati trovati: " + Environment.NewLine);
                    MessageBox.Show(sbMessaggio.ToString().Trim());
                }
                else
                {
                    MessageBox.Show("Operazione terminata correttamente", "INFORMAZIONI", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MostraEccezione(ex, "Errore in fase di creazione dei file");
            }
        }