Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                DateTime oThisDays = DateTime.Now;

                PedidoEnvioLoteRPS oPedidoEnvioLoteRPS = new PedidoEnvioLoteRPS();

                oPedidoEnvioLoteRPS.Cabecalho = new Cabecalho();

                oPedidoEnvioLoteRPS.Cabecalho.CPFCNPJRemetente      = new CabecalhoCPFCNPJRemetente();
                oPedidoEnvioLoteRPS.Cabecalho.CPFCNPJRemetente.CNPJ = Convert.ToUInt64(@"23153425000136");               //tomador

                oPedidoEnvioLoteRPS.Cabecalho.Versao             = 1;                                                    //fixo
                oPedidoEnvioLoteRPS.Cabecalho.transacao          = false;                                                //fixo
                oPedidoEnvioLoteRPS.Cabecalho.dtInicio           = Convert.ToDateTime(oThisDays.ToString("yyyy-MM-dd")); //nf
                oPedidoEnvioLoteRPS.Cabecalho.dtFim              = Convert.ToDateTime(oThisDays.ToString("yyyy-MM-dd")); //nf
                oPedidoEnvioLoteRPS.Cabecalho.QtdRPS             = 2;                                                    //nf
                oPedidoEnvioLoteRPS.Cabecalho.ValorTotalServicos = 2000;                                                 //nf
                oPedidoEnvioLoteRPS.Cabecalho.ValorTotalDeducoes = 200;                                                  //nf

                oPedidoEnvioLoteRPS.RPS            = new RPS();
                oPedidoEnvioLoteRPS.RPS.Assinatura = @" ";

                oPedidoEnvioLoteRPS.RPS.ChaveRPS = new RPSChaveRPS();
                oPedidoEnvioLoteRPS.RPS.ChaveRPS.InscricaoPrestador = 31000000;//tomador
                oPedidoEnvioLoteRPS.RPS.ChaveRPS.SerieRPS           = @"LLLLL";
                oPedidoEnvioLoteRPS.RPS.ChaveRPS.NumeroRPS          = 1;

                oPedidoEnvioLoteRPS.RPS.TipoRPS          = @"RPS-M";                                             //fico
                oPedidoEnvioLoteRPS.RPS.DataEmissao      = Convert.ToDateTime(oThisDays.ToString("yyyy-MM-dd")); //nf
                oPedidoEnvioLoteRPS.RPS.StatusRPS        = "N";                                                  //fixo
                oPedidoEnvioLoteRPS.RPS.TributacaoRPS    = "T";                                                  //
                oPedidoEnvioLoteRPS.RPS.ValorServicos    = 1000;                                                 //nf
                oPedidoEnvioLoteRPS.RPS.ValorDeducoes    = 100;                                                  //nf
                oPedidoEnvioLoteRPS.RPS.CodigoServico    = 2658;                                                 //nf
                oPedidoEnvioLoteRPS.RPS.AliquotaServicos = Convert.ToDecimal(@"0.05");                           //nf
                oPedidoEnvioLoteRPS.RPS.ISSRetido        = false;                                                //nf


                //Base de Clientes
                oPedidoEnvioLoteRPS.RPS.CPFCNPJTomador     = new RPSCPFCNPJTomador();
                oPedidoEnvioLoteRPS.RPS.CPFCNPJTomador.CPF = 21346241830;         //cliente
                oPedidoEnvioLoteRPS.RPS.RazaoSocialTomador = @"RODRIGO DA SILVA"; //cliente

                oPedidoEnvioLoteRPS.RPS.EnderecoTomador = new RPSEnderecoTomador();
                oPedidoEnvioLoteRPS.RPS.EnderecoTomador.TipoLogradouro      = @"R";          //cliente
                oPedidoEnvioLoteRPS.RPS.EnderecoTomador.Logradouro          = @"Guararapes"; //cliente
                oPedidoEnvioLoteRPS.RPS.EnderecoTomador.NumeroEndereco      = @"495 A";      //cliente
                oPedidoEnvioLoteRPS.RPS.EnderecoTomador.ComplementoEndereco = @"ap 102";     //cliente
                oPedidoEnvioLoteRPS.RPS.EnderecoTomador.Bairro = @"BROOKLIN PAULISTA";       //cliente
                oPedidoEnvioLoteRPS.RPS.EnderecoTomador.Cidade = 3550308;                    //cliente
                oPedidoEnvioLoteRPS.RPS.EnderecoTomador.UF     = @"SP";                      //cliente
                oPedidoEnvioLoteRPS.RPS.EnderecoTomador.CEP    = 4561000;                    //cliente

                oPedidoEnvioLoteRPS.RPS.EmailTomador  = @"*****@*****.**";          //cliente
                oPedidoEnvioLoteRPS.RPS.Discriminacao = @"Desenvolvimento de sistema nfs-e";

                XmlSerializer oXmlSerializer = new XmlSerializer(typeof(PedidoEnvioLoteRPS));

                string filename = Environment.CurrentDirectory.Replace(@"\", @"\\")
                                  + @"\\Arquivos\\Nfs\\"
                                  + oPedidoEnvioLoteRPS.Cabecalho.CPFCNPJRemetente.CNPJ
                                  + DateTime.Now.ToString("yyyyMMddhhmmss") + @".xml";

                TextWriter oWriter = new StreamWriter(filename);

                oXmlSerializer.Serialize(oWriter, oPedidoEnvioLoteRPS);

                var msg = MessageBox.Show("Emitido com sucesso", @"NFs!", MessageBoxButtons.OK, MessageBoxIcon.Question);
            }

            catch (Exception ex)
            {
                var msgErros = MessageBox.Show(ex.Message, @"NFs!",
                                               MessageBoxButtons.OK,
                                               MessageBoxIcon.Question);
            }
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string oThisDay = Convert.ToString(DateTime.Now);

                PedidoEnvioLoteRPS oPedidoEnvioLoteRPS = new PedidoEnvioLoteRPS();

                oPedidoEnvioLoteRPS.Cabecalho = new Cabecalho();

                oPedidoEnvioLoteRPS.Cabecalho.CPFCNPJRemetente      = new CabecalhoCPFCNPJRemetente();
                oPedidoEnvioLoteRPS.Cabecalho.CPFCNPJRemetente.CNPJ = Convert.ToUInt64(@"23153425000136");

                oPedidoEnvioLoteRPS.Cabecalho.Versao             = 1;     //fixo
                oPedidoEnvioLoteRPS.Cabecalho.transacao          = false; //fixo
                oPedidoEnvioLoteRPS.Cabecalho.dtInicio           = Convert.ToDateTime(oThisDay);
                oPedidoEnvioLoteRPS.Cabecalho.dtFim              = Convert.ToDateTime(oThisDay);
                oPedidoEnvioLoteRPS.Cabecalho.QtdRPS             = 2;
                oPedidoEnvioLoteRPS.Cabecalho.ValorTotalServicos = 2000;
                oPedidoEnvioLoteRPS.Cabecalho.ValorTotalDeducoes = 200;

                oPedidoEnvioLoteRPS.RPS            = new RPS();
                oPedidoEnvioLoteRPS.RPS.Assinatura = @" ";

                oPedidoEnvioLoteRPS.RPS.ChaveRPS = new RPSChaveRPS();
                oPedidoEnvioLoteRPS.RPS.ChaveRPS.InscricaoPrestador = 31000000;
                oPedidoEnvioLoteRPS.RPS.ChaveRPS.SerieRPS           = @"LLLLL";
                oPedidoEnvioLoteRPS.RPS.ChaveRPS.NumeroRPS          = 1;

                oPedidoEnvioLoteRPS.RPS.TipoRPS          = @"RPS-M";
                oPedidoEnvioLoteRPS.RPS.DataEmissao      = Convert.ToDateTime(@"2018-01-28");
                oPedidoEnvioLoteRPS.RPS.StatusRPS        = "N";
                oPedidoEnvioLoteRPS.RPS.TributacaoRPS    = "T";
                oPedidoEnvioLoteRPS.RPS.ValorServicos    = 1000;
                oPedidoEnvioLoteRPS.RPS.ValorDeducoes    = 100;
                oPedidoEnvioLoteRPS.RPS.CodigoServico    = 2658;
                oPedidoEnvioLoteRPS.RPS.AliquotaServicos = Convert.ToDecimal(@"0.05");
                oPedidoEnvioLoteRPS.RPS.ISSRetido        = false;


                //Base de Clientes
                oPedidoEnvioLoteRPS.RPS.CPFCNPJTomador     = new RPSCPFCNPJTomador();
                oPedidoEnvioLoteRPS.RPS.CPFCNPJTomador.CPF = 21346241830; //cliente
                oPedidoEnvioLoteRPS.RPS.RazaoSocialTomador = @"RODRIGO DA SILVA";

                oPedidoEnvioLoteRPS.RPS.EnderecoTomador = new RPSEnderecoTomador();
                oPedidoEnvioLoteRPS.RPS.EnderecoTomador.TipoLogradouro      = @"R";
                oPedidoEnvioLoteRPS.RPS.EnderecoTomador.Logradouro          = @"Guararapes";
                oPedidoEnvioLoteRPS.RPS.EnderecoTomador.NumeroEndereco      = @"495 A";
                oPedidoEnvioLoteRPS.RPS.EnderecoTomador.ComplementoEndereco = @"ap 102";
                oPedidoEnvioLoteRPS.RPS.EnderecoTomador.Bairro = @"BROOKLIN PAULISTA";
                oPedidoEnvioLoteRPS.RPS.EnderecoTomador.Cidade = 3550308;
                oPedidoEnvioLoteRPS.RPS.EnderecoTomador.UF     = @"SP";
                oPedidoEnvioLoteRPS.RPS.EnderecoTomador.CEP    = 4561000;

                oPedidoEnvioLoteRPS.RPS.EmailTomador  = @"*****@*****.**";
                oPedidoEnvioLoteRPS.RPS.Discriminacao = @"Desenvolvimento de sistema nfs-e";

                XmlSerializer oXmlSerializer = new XmlSerializer(typeof(PedidoEnvioLoteRPS));

                string filename = Environment.CurrentDirectory.Replace(@"\", @"\\")
                                  + @"\\Arquivos\\Nfs\\"
                                  + oPedidoEnvioLoteRPS.Cabecalho.CPFCNPJRemetente.CNPJ + oThisDay.Replace("/", "").Replace(":", "").Replace(" ", "").Trim() + @".xml";

                TextWriter oWriter = new StreamWriter(filename);

                oXmlSerializer.Serialize(oWriter, oPedidoEnvioLoteRPS);

                var msg = MessageBox.Show("Emitido com sucesso", @"NFs!",
                                          MessageBoxButtons.OK,
                                          MessageBoxIcon.Question);
            }
            catch (Exception ex)

            {
                string sErr = Convert.ToString(ex);

                if (sErr.Contains(@"UNIQUE constraint failed"))
                {
                    MessageBox.Show(@"Registro Existente! ", @"NotasFiscais-Erros(Inserção)!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (sErr.Contains(@"Input string was not in a correct format."))
                {
                    MessageBox.Show(@"Dados Em Branco! ", @"NotasFiscais-Erros(Inserção)!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(ex.Message, @"NotasFiscais-Erros(Inserção)!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                txtClientes_CNPJorCPF.Focus();
            }
        }