Пример #1
0
        private void btnCompactar_Click(object sender, EventArgs e)
        {
            if (txtArquivo.Text == "")
            {
                MessageBox.Show("Selecione o arquivo a ser enviado.");
                btnAbrir.Focus();
                return;
            }

            if (MessageBox.Show("Confirma envio de arquivo para Anvisa?",
                                "Enviar Arquivo para Anvisa", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
            {
                return;
            }

            txtEncoded.Text = "";
            // Apagar arquivo zip anterior
            if (System.IO.File.Exists(@"SNGPC01.zip"))
            {
                System.IO.File.Delete(("SNGPC01.zip"));
            }


            using (ZipFile zip = new ZipFile())
            {
                zip.AddFile(txtArquivo.Text, "");
                //zip.AddDirectory(txtArquivo.Text, "Files");
                zip.Save("SNGPC01.zip");
                zip.Dispose();
            };

            MemoryStream ms   = new MemoryStream();
            FileStream   file = new FileStream("SNGPC01.zip", FileMode.Open, FileAccess.Read);

            byte[] bytes = new byte[file.Length];
            file.Read(bytes, 0, (int)file.Length);
            ms.Write(bytes, 0, (int)file.Length);
            //
            file.Read(bytes, 0, Convert.ToInt32(file.Length));
            string encodedData =
                Convert.ToBase64String(bytes,
                                       Base64FormattingOptions.InsertLineBreaks);

            //
            //txtEncoded.Text = encodedData;
            //
            file.Close();
            ms.Close();


            int hambiente = GetHambiente();

            btnCompactar.Enabled = false;
            btnConsulta.Enabled  = false;
            //
            slbMensagem.Text = "Aguarde, transmitindo arquivo para anvisa...";

            try
            {
                try
                {
                    if (hambiente == 0)
                    {
                        ServiceReference1.sngpcSoapClient wssngpc = new ServiceReference1.sngpcSoapClient();

                        comp = wssngpc.EnviaArquivoSNGPC(txtEmail.Text, txtSenha.Text.TrimEnd(), bytes, lblHash.Text);
                    }
                    else
                    {
                        Sngpc.sngpcSoapClient wssngpc = new Sngpc.sngpcSoapClient();

                        comp = wssngpc.EnviaArquivoSNGPC(txtEmail.Text, txtSenha.Text.TrimEnd(), bytes, lblHash.Text);
                    }

                    txtEncoded.Text = comp;
                    //
                    AddArquivoGerado(txtArquivo.Text, txtHash.Text);
                }
                catch (Exception err)
                {
                    MessageBox.Show("Ocorreu um problema ao tentar acessar serviço.");
                    MessageBox.Show(err.Message);
                }
            }
            finally
            {
                btnCompactar.Enabled = true;
                btnConsulta.Enabled  = true;
                slbMensagem.Text     = "";
            }
        }
Пример #2
0
        private void btnConsulta_Click(object sender, EventArgs e)
        {
            if (txtArquivo.Text == "")
            {
                MessageBox.Show("Selecione o arquivo a ser consultado.");
                btnAbrir.Focus();
                return;
            }

            btnConsulta.Enabled  = false;
            btnCompactar.Enabled = false;
            txtEncoded.Text      = "";
            slbMensagem.Text     = "Aguarde, consultando arquivo...";

            try
            {
                string hashArquivo = GetMd5Arquivo(txtArquivo.Text);

                txtHash.Text = hashArquivo;

                int hambiente = GetHambiente();
                //
                try
                {
                    if (hambiente == 0)
                    {
                        ServiceReference1.sngpcSoapClient wssngpc = new ServiceReference1.sngpcSoapClient();

                        comp = wssngpc.ConsultaDadosArquivoSNGPC(txtEmail.Text, txtSenha.Text.TrimEnd(), txtCnpj.Text, txtHash.Text);
                    }
                    else
                    {
                        Sngpc.sngpcSoapClient wssngpc = new Sngpc.sngpcSoapClient();

                        comp = wssngpc.ConsultaDadosArquivoSNGPC(txtEmail.Text, txtSenha.Text.TrimEnd(), txtCnpj.Text, txtHash.Text);
                    }

                    txtEncoded.Text = comp;

                    string dataValidacao = getBetween(comp, "<DATAVALIDACAO>", "</DATAVALIDACAO>");

                    if (dataValidacao != "")
                    {
                        if (AtualizarDataUltimoArquivo(dataValidacao))
                        {
                            MessageBox.Show("Arquivo válidado com sucesso.");
                        }
                    }
                }
                catch (Exception err)
                {
                    MessageBox.Show("Ocorreu um problema ao tentar acessar serviço.");
                    MessageBox.Show(err.Message);
                }
            }
            finally
            {
                btnConsulta.Enabled  = true;
                btnCompactar.Enabled = true;
                slbMensagem.Text     = "";
            }
        }