Example #1
0
        private void DoRefresh()
        {
            if (oSrv != null)
            {
                ClientEnvironment manager = null;
                try
                {
                    manager = Conexao.CreateManager(Program.ConAux);
                    oSrv    = (ServicoPendente)ServicoPendenteDAL.Instance.Find(oSrv.keyString, manager);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    Conexao.DisposeManager(manager);
                }

                txLote.Text   = oSrv.numeroLote.ToString();
                txCodSit.Text = oSrv.codigoSituacao.ToString();
                txDatSit.Text = oSrv.dataSituacao.ToString();
                txRecNum.Text = oSrv.numeroRecibo;

                if (oSrv.xmlRecibo != String.Empty)
                {
                    System.Xml.XmlDocument xmlRec = new System.Xml.XmlDocument();
                    xmlRec.LoadXml(oSrv.xmlRecibo);
                    NFeUtils.PopulaTreeView(xmlRec, tvSPeRec, true);
                }
                else
                {
                    tvSPeRec.Nodes.Clear();
                    tvSPeRec.Nodes.Add("Problema ao carregar o arquivo.");
                }

                if (oSrv.xmlRetConsulta != String.Empty)
                {
                    System.Xml.XmlDocument xmlRec = new System.Xml.XmlDocument();
                    xmlRec.LoadXml(oSrv.xmlRetConsulta);
                    NFeUtils.PopulaTreeView(xmlRec, tvSPeCons, true);
                }
                else
                {
                    tvSPeRec.Nodes.Clear();
                    tvSPeRec.Nodes.Add("Problema ao carregar o arquivo.");
                }

                btAtualizarLote.Enabled = true;//(oSrv.codigoSituacao == TipoSituacaoServico.ProblemaNoEnvio);

                btnAbort.Enabled = oSrv.codigoSituacao == TipoSituacaoServico.AguardandoEnvio ||
                                   oSrv.codigoSituacao == TipoSituacaoServico.AguardandoRetornoAprovacao ||
                                   oSrv.codigoSituacao == TipoSituacaoServico.Processado;
            }
        }
        private void btExcluir_Click(object sender, EventArgs e)
        {
            int indice;

            if (dgvFilaDeServicos.SelectedRows.Count > 0)
            {
                indice = dgvFilaDeServicos.SelectedRows[0].Index;//o activated atualiza o grid e o index fica null
                if (MessageBox.Show("Deseja realmente excluir o serviço pendente ?", "Exclusão de serviço.", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    ClientEnvironment manager = null;
                    try
                    {
                        manager = Conexao.CreateManager(Program.ConAux);

                        ServicoPendente oSrv = (ServicoPendente)ListaParam[indice];
                        oSrv = (ServicoPendente)ServicoPendenteDAL.Instance.Find(oSrv.keyString, manager);
                        oSrv.codigoSituacao = TipoSituacaoServico.Excluido;

                        //buscar no banco as notas aprovadas desse ServicoPendente
                        NotaFiscalQry oNFeQry = new NotaFiscalQry();
                        oNFeQry.empresa    = oSrv.empresa;
                        oNFeQry.numeroLote = oSrv.numeroLote.ToString();

                        ArrayList notas = NotaFiscalDAL.Instance.GetInstances(oNFeQry, manager);
                        foreach (NotaFiscal oNFe in notas)
                        {
                            oNFe.codigoSituacao    = TipoSituacaoNota.SerivcoExcluido;// 99;
                            oNFe.descricaoSituacao = "Serviço excluido";
                            oNFe.Save(manager);
                        }

                        oSrv.Save(manager);
                        MessageBox.Show("Serviço excluido com sucesso.", "Exclusão de serviço.", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    finally
                    {
                        Conexao.DisposeManager(manager);
                    }
                }
            }
            else
            {
                MessageBox.Show("Selecione um serviço para ser excluido.", "Exclusão de serviço.", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            Refresh(sender, e);
        }
Example #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            ClientEnvironment manager = null;

            try
            {
                manager = Conexao.CreateManager(Program.ConAux);

                ServicoPendente oServicoPendente = (ServicoPendente)ServicoPendenteDAL.Instance.Find(oSrv.keyString, manager);

                bool canAbort = oSrv.codigoSituacao == TipoSituacaoServico.AguardandoEnvio ||
                                oSrv.codigoSituacao == TipoSituacaoServico.AguardandoRetornoAprovacao ||
                                oSrv.codigoSituacao == TipoSituacaoServico.Processado;

                if (!canAbort)
                {
                    throw new Exception("Serviço não pode ser cancelado.");
                }

                oServicoPendente.codigoSituacao = TipoSituacaoServico.EnvioCancelado;
                oServicoPendente.Save(manager);

                Log oLogSrv = new Log();
                oLogSrv.codigoSituacao    = 998;
                oLogSrv.descricaoSituacao = "Envio foi cancelado.";
                oLogSrv.nota           = new NotaFiscal();
                oLogSrv.nota.chaveNota = String.Empty;
                oLogSrv.data           = DateTime.Now;
                oLogSrv.empresa        = oServicoPendente.empresa;
                oLogSrv.Save(manager);

                MessageBox.Show("Lote atualizado com sucesso.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Conexao.DisposeManager(manager);
            }
        }
Example #4
0
        void oFrm_DoOnOkClick(object sender, EventArgs e)
        {
            ClientEnvironment manager = null;

            try
            {
                //FrmInfNRec oFrm = (FrmInfNRec)((Button)sender).Parent;
                String nRec = oFrm.TextResposta.Text;


                if (String.IsNullOrEmpty(nRec))
                {
                    throw new Exception("Informe o número do Recibo.");
                }

                manager = Conexao.CreateManager(Program.ConAux);

                ServicoPendente oServicoPendente = (ServicoPendente)ServicoPendenteDAL.Instance.Find(oSrv.keyString, manager);
                Parametro       oParam           = Program.GetParametro(oServicoPendente.empresa, manager);

                //criar o recibo no disco
                RDI.NFe2.SchemaXML.NFe_v200.TRetEnviNFe oRetEnviNFe = new RDI.NFe2.SchemaXML.NFe_v200.TRetEnviNFe();
                oRetEnviNFe.tpAmb    = oServicoPendente.tipoAmbiente;
                oRetEnviNFe.verAplic = "2.00";
                oRetEnviNFe.cUF      = oServicoPendente.UF;
                oRetEnviNFe.cStat    = "103";
                oRetEnviNFe.xMotivo  = "Lote recebido com sucesso";
                oRetEnviNFe.dhRecbto = DateTime.Now;
                oRetEnviNFe.infRec   = new RDI.NFe2.SchemaXML.NFe_v200.TRetEnviNFeInfRec();

                oRetEnviNFe.infRec.nRec = nRec;
                oRetEnviNFe.infRec.tMed = "1";
                XMLUtils.SaveXML(oParam.pastaRecibo + oServicoPendente.numeroLote.ToString() + "-rec.xml", oRetEnviNFe, oServicoPendente.versao);

                oServicoPendente.xmlRecibo = XMLUtils.GetXML(oRetEnviNFe, oServicoPendente.versao);

                oServicoPendente.numeroRecibo = nRec;

                oServicoPendente.dataSituacao   = DateTime.Now;
                oServicoPendente.codigoSituacao = TipoSituacaoServico.AguardandoRetornoAprovacao;
                //setar todas as notas desse servico como enviadas.

                NotaFiscalQry oNFeQry = new NotaFiscalQry();
                oNFeQry.empresa    = oServicoPendente.empresa;
                oNFeQry.numeroLote = oServicoPendente.numeroLote.ToString();

                //somente as que foram assinadas e inseridas no lote.
                oNFeQry.codigoSituacao = TipoSituacaoNota.Assinada;// "0";

                ArrayList notasProcessadas = NotaFiscalDAL.Instance.GetInstances(oNFeQry, manager);
                foreach (NotaFiscal oNFeProc in notasProcessadas)
                {
                    oNFeProc.codigoSituacao    = TipoSituacaoNota.Enviada;// 12; //Enviada
                    oNFeProc.descricaoSituacao = "Nota enviada";
                    oNFeProc.dataSituacao      = oServicoPendente.dataSituacao;
                    oNFeProc.Save(manager);

                    Log oLog = new Log();
                    oLog.codigoSituacao    = 13;
                    oLog.descricaoSituacao = "Nota Enviada";
                    oLog.nota           = new NotaFiscal();
                    oLog.nota.chaveNota = oNFeProc.chaveNota;
                    oLog.data           = DateTime.Now;
                    oLog.empresa        = oServicoPendente.empresa;
                    oLog.Save(manager);
                }
                oServicoPendente.Save(manager);

                Log oLogSrv = new Log();
                oLogSrv.codigoSituacao    = 998;
                oLogSrv.descricaoSituacao = "Recibo informado pelo usuario.";
                oLogSrv.nota           = new NotaFiscal();
                oLogSrv.nota.chaveNota = String.Empty;
                oLogSrv.data           = DateTime.Now;
                oLogSrv.empresa        = oServicoPendente.empresa;
                oLogSrv.Save(manager);

                MessageBox.Show("Lote atualizado com sucesso.");
                oFrm.Close();
                oFrm.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Conexao.DisposeManager(manager);
            }
        }