示例#1
0
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                BackgroundWorker w = sender as BackgroundWorker;
                for (int i = 0; i < lLotes.Count; i++)
                {
                    try
                    {
                        lLotes[i].xStatus = "Carregando dados ...";
                        this.Invoke(new MethodInvoker(delegate()
                        {
                            dgvLotes.CurrentCell = dgvLotes.Rows[i].Cells[0];
                            dgvLotes.CurrentRow.DefaultCellStyle.BackColor = Color.Aquamarine;
                            progressBar1.Maximum = lLotes.Count();
                            dgvLotes.Refresh();
                        }));

                        lLotes[i].objDados.CarregaDados();
                        w.ReportProgress(lLotes.Count() / 100);

                        if (!Acesso.VISUALIZA_DADOS_NFE)
                        {
                            lLotes[i].xStatus = "Preparando para envio...";
                            this.Invoke(new MethodInvoker(delegate()
                            {
                                dgvLotes.CurrentCell = dgvLotes.Rows[i].Cells[0];
                                dgvLotes.Refresh();
                            }));


                            // Inicia rotina de envio das notas.
                            ParameterizedThreadStart p = new ParameterizedThreadStart(TransmiteLote);
                            Thread t = new Thread(p);
                            t.Start(lLotes[i]);
                        }
                        else
                        {
                            lLotes[i].xStatus = "Dados carregados na memória...";
                            this.Invoke(new MethodInvoker(delegate()
                            {
                                dgvLotes.CurrentCell = dgvLotes.Rows[i].Cells[0];
                                dgvLotes.Refresh();
                            }));
                        }
                    }
                    catch (Exception ex)
                    {
                        lLotes[i].xStatus = ex.Message;
                        this.Invoke(new MethodInvoker(delegate()
                        {
                            dgvLotes.Refresh();
                        }));
                    }
                }

                if (Acesso.VISUALIZA_DADOS_NFE)
                {
                    List<belInfNFe> objListaNFs = new List<belInfNFe>();

                    foreach (lotes lote in lLotes)
                    {
                        objListaNFs.AddRange(lote.objDados.lNotas);
                    }

                    if (objListaNFs.Count > 0)
                    {
                        this.Invoke(new MethodInvoker(delegate()
                      {
                          frmVisualizaNFe objFrmVisualizaDados = new frmVisualizaNFe(objListaNFs);
                          objFrmVisualizaDados.ShowDialog();
                          if (objFrmVisualizaDados.Cancelado)
                          {
                              throw new Exception("cancelado.");
                          }


                          foreach (lotes lote in lLotes)
                          {
                              lote.xStatus = "Lote sendo transmitido...";
                              this.Invoke(new MethodInvoker(delegate()
                              {
                                  dgvLotes.Refresh();
                              }));
                              // Inicia rotina de envio das notas.
                              ParameterizedThreadStart p = new ParameterizedThreadStart(TransmiteLote);
                              Thread t = new Thread(p);
                              t.Start(lote);
                          }
                      }));
                    }
                }
            }
            catch (Exception ex)
            {
//                new HLPexception(ex);
                bCancelado = true;
                //async_work.CancelAsync();
                //timer1.Start();
                this.Invoke(new MethodInvoker(delegate()
                {
                    this.Close();
                }));
            }

        }
示例#2
0
        private void btnContingencia_Click(object sender, EventArgs e)
        {
            List<belPesquisaNotas> objSelect = BuscaNotasSelecionadas().Where(c =>
                                                                  c.bEnviado == false &&
                                                                  c.bDenegada == false &&
                                                                  c.bCancelado == false &&
                                                               c.sRECIBO_NF == "").ToList<belPesquisaNotas>();
            try
            {
                if (objSelect.Count() > 0)
                {

                    if (objSelect.Where(c => c.sCD_NOTAFIS == "").Count() > 0)
                    {
                        belNumeroNF objbelNumeracao = new belNumeroNF(objSelect.Where(c => c.sCD_NOTAFIS == "").ToList());
                        frmGeraNumeracaoNFe objfrmGeraNumeracao = new frmGeraNumeracaoNFe(objbelNumeracao, false);
                        objfrmGeraNumeracao.ShowDialog();
                        if (!objfrmGeraNumeracao.bGerou)
                        {
                            throw new Exception("Transmissão de Notas abortada");
                        }
                    }
                    belCarregaDados objbelCarregaDados = new belCarregaDados(objSelect);
                    objbelCarregaDados.CarregaDados();
                    frmVisualizaNFe objfrmVisualizaNFe = new frmVisualizaNFe(objbelCarregaDados.lNotas);
                    objfrmVisualizaNFe.ShowDialog();
                    if (objfrmVisualizaNFe.Cancelado)
                    {
                        throw new Exception("Envio da(s) Nota(s) Cancelado");
                    }
                    objbelCarregaDados.objbelCriaXml.GeraLoteXmlEnvio();

                    foreach (belPesquisaNotas item in objSelect)
                    {
                        item.AlteraStatusNotaParaContingenciaFS();
                    }
                    KryptonMessageBox.Show(belTrataMensagemNFe.RetornaMensagem(objSelect, belTrataMensagemNFe.Tipo.ContingenciaFS), Mensagens.CHeader, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    PesquisaNotas();
                }
            }
            catch (Exception ex)
            {
                new HLPexception(ex);
            }

        }