Esempio n. 1
0
        private void Bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            StringBuilder sbMessaggio = new StringBuilder();
            DataSet       ds          = e.Argument as DataSet;

            CDCBLL bll = new CDCBLL();
            int    numeroTotaleEtichette = 0;

            foreach (DataRow riga in ds.Tables[tableName].Rows)
            {
                string numeroEtichette = string.Empty;
                if (riga[12] != System.DBNull.Value)
                {
                    numeroEtichette = (string)riga[12];
                }


                string prefisso    = (string)riga[3];
                string parte       = (string)riga[4];
                string colore      = (string)riga[5];
                string linea       = (string)riga[9];
                string descrizione = (string)riga[10];

                string messaggioVerifica;
                List <Tuple <int, int> > SC_QTA;

                if (bll.verificaNumeroEtichette(numeroEtichette, out messaggioVerifica, out SC_QTA))
                {
                    foreach (Tuple <int, int> tupla in SC_QTA)
                    {
                        string etichetta = string.Format("{0} {1} {2} {3}   da {4} pezzi IN CORSO", prefisso, parte, colore, linea, tupla.Item2);

                        for (int i = 0; i < tupla.Item1; i++)
                        {
                            numeroTotaleEtichette++;
                            ZebraHelper.EseguiStampaEtichetta(printer, riga, tupla.Item2.ToString());
                            Thread.Sleep(150);
                            string messaggio = string.Format(@"{0}{1}", sbMessaggio.ToString(), etichetta);
                            bgw.ReportProgress(numeroTotaleEtichette, messaggio);

                            if (bgw.CancellationPending)
                            {
                                e.Cancel = true;
                                return;
                            }
                        }
                    }
                    sbMessaggio.AppendLine(string.Format("{0} {1} {2} {3}   numero etichette: {4} STAMPATE", prefisso, parte, colore, linea, numeroEtichette));
                }
                ZebraHelper.EseguiStampaEtichettaSeparatore(printer);
            }
            bgw.ReportProgress(numeroTotaleEtichette, sbMessaggio.ToString());
        }
Esempio n. 2
0
        public StampaEtichetteFrm(DataSet ds, string zebraPrinter)
        {
            CDCBLL bll = new CDCBLL();

            printer = zebraPrinter;
            InitializeComponent();
            bgw.DoWork                    += Bgw_DoWork;
            bgw.ProgressChanged           += Bgw_ProgressChanged;
            bgw.RunWorkerCompleted        += Bgw_RunWorkerCompleted;
            bgw.WorkerReportsProgress      = true;
            bgw.WorkerSupportsCancellation = true;
            progressBar1.Maximum           = 0;
            foreach (DataRow riga in ds.Tables[tableName].Rows)
            {
                string messaggioVerifica;
                List <Tuple <int, int> > SC_QTA;

                string numeroEtichette = string.Empty;
                if (riga[12] != System.DBNull.Value)
                {
                    numeroEtichette = (string)riga[12];
                }

                if (bll.verificaNumeroEtichette(numeroEtichette, out messaggioVerifica, out SC_QTA))
                {
                    foreach (Tuple <int, int> tupla in SC_QTA)
                    {
                        int sc  = tupla.Item1;
                        int qta = tupla.Item2;
                        progressBar1.Maximum += sc * qta;
                    }
                }
            }

            bgw.RunWorkerAsync(ds);
        }
Esempio n. 3
0
        private void btnVerificaEtichette_Click(object sender, EventArgs e)
        {
            btnStampaEtichette.Enabled = false;;
            StringBuilder messaggioErrore = new StringBuilder();

            StringBuilder messaggioBuono        = new StringBuilder();
            bool          mostraMessaggioErrore = false;

            if (ddlStampanti.SelectedIndex == -1)
            {
                mostraMessaggioErrore = true;
                messaggioErrore.AppendLine(string.Format("Selezionare una stampamnte"));
            }

            CDCBLL bll = new CDCBLL();

            try
            {
                lblMessaggio.Text = string.Empty;
                if (_dsServizio.Tables[tableName].Rows.Count == 0)
                {
                    lblMessaggio.Text = "NESSUNA ETICHETTA DA STAMPARE";
                    return;
                }
                int indiceRiga = 1;
                foreach (DataRow riga in _dsServizio.Tables[tableName].Rows)
                {
                    string linea = string.Empty;
                    if (riga[9] != System.DBNull.Value)
                    {
                        linea = (string)riga[9];
                    }
                    string descrizione = string.Empty;
                    if (riga[10] != System.DBNull.Value)
                    {
                        descrizione = (string)riga[10];
                    }
                    string destinazione = string.Empty;
                    if (riga[11] != System.DBNull.Value)
                    {
                        destinazione = (string)riga[11];
                    }
                    string numeroEtichette = string.Empty;
                    if (riga[12] != System.DBNull.Value)
                    {
                        numeroEtichette = (string)riga[12];
                    }

                    descrizione     = descrizione.Trim();
                    destinazione    = destinazione.Trim();
                    numeroEtichette = numeroEtichette.Replace(" ", string.Empty).ToUpper();

                    string finitura = (string)riga[5];
                    finitura = finitura.ToUpper().Trim();
                    if ((!string.IsNullOrEmpty(finitura) || !(finitura == "NULL")) && string.IsNullOrEmpty(linea))
                    {
                        mostraMessaggioErrore = true;
                        messaggioErrore.AppendLine(string.Format("Riga {0}: Inserire la linea", indiceRiga));
                    }
                    if (string.IsNullOrEmpty(descrizione))
                    {
                        mostraMessaggioErrore = true;
                        messaggioErrore.AppendLine(string.Format("Riga {0}: Inserire la descrizione", indiceRiga));
                    }
                    if (string.IsNullOrEmpty(destinazione))
                    {
                        mostraMessaggioErrore = true;
                        messaggioErrore.AppendLine(string.Format("Riga {0}: Inserire la destinazione", indiceRiga));
                    }

                    if (string.IsNullOrEmpty(numeroEtichette))
                    {
                        mostraMessaggioErrore = true;
                        messaggioErrore.AppendLine(string.Format("Riga {0}: Inserire il numero di etichette", indiceRiga));
                    }
                    indiceRiga++;

                    string messaggio;
                    List <Tuple <int, int> > SC_QTA;
                    if (!bll.verificaNumeroEtichette(numeroEtichette, out messaggio, out SC_QTA))
                    {
                        mostraMessaggioErrore = true;
                        messaggioErrore.AppendLine(string.Format("Riga {0}: numero etichette errato", indiceRiga));
                    }
                    else
                    {
                        string prefisso = (string)riga[3];
                        string parte    = (string)riga[4];
                        string colore   = (string)riga[5];
                        string commessa = (string)riga[6];
                        messaggioBuono.AppendLine(string.Format("{0}-{1}-{2}  {3}", prefisso, parte, colore, commessa));
                        messaggioBuono.AppendLine(messaggio);
                    }
                }

                if (mostraMessaggioErrore)
                {
                    MessageBox.Show(messaggioErrore.ToString(), "ATTENZIONE", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                string zebraPrinter = ddlStampanti.SelectedItem.ToString();

                foreach (DataRow riga in _dsServizio.Tables[tableName].Rows)
                {
                    ZebraHelper.EseguiStampaEtichetta(zebraPrinter, riga, "1");
                }

                MessageBox.Show(messaggioBuono.ToString(), "ATTENZIONE", MessageBoxButtons.OK, MessageBoxIcon.Information);

                btnStampaEtichette.Enabled = true;
            }

            catch (Exception ex)
            {
                btnStampaEtichette.Enabled = false;
                MostraEccezione(ex, "Errore nella verifica etichette");
            }
        }