예제 #1
0
        private void GerarArquivo()
        {
            if (cbEmpresa.SelectedItem == null)
            {
                MessageBox.Show("Obrigatorio informar empresa.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cbEmpresa.Focus();
                return;
            }
            if (string.IsNullOrEmpty(path_sped.Text))
            {
                MessageBox.Show("Obrigatorio informar path para salvar arquivo.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                path_sped.Focus();
                return;
            }
            ThreadEspera tEspera = new ThreadEspera("Iniciando procedimento gerar SPED FISCAL...");

            try
            {
                if (!System.IO.Directory.Exists(path_sped.Text))
                {
                    System.IO.Directory.CreateDirectory(path_sped.Text);
                }
                string arq = CamadaNegocio.Fiscal.SPED_FISCAL.TCN_SpedFiscal.ProcessarSpedFiscal(cbEmpresa.SelectedValue.ToString(),
                                                                                                 new DateTime(int.Parse(cbAno.Text), int.Parse(cbMes.SelectedValue.ToString()), 1),
                                                                                                 new DateTime(int.Parse(cbAno.Text), int.Parse(cbMes.SelectedValue.ToString()), DateTime.DaysInMonth(int.Parse(cbAno.Text), int.Parse(cbMes.SelectedValue.ToString())), 23, 59, 59),
                                                                                                 rb_Original.Checked ? "O" : rb_Substituto.Checked ? "S" : string.Empty,
                                                                                                 tEspera);
                using (System.IO.StreamWriter sw = new System.IO.StreamWriter(path_sped.Text + "\\efd" +
                                                                              cbEmpresa.SelectedValue.ToString().Trim() +
                                                                              cbMes.SelectedValue.ToString() +
                                                                              cbAno.Text + ".txt",
                                                                              false,
                                                                              System.Text.Encoding.Default))
                {
                    sw.Write(arq + "\r\n");
                    sw.Close();
                    MessageBox.Show("Arquivo Sped Fiscal gerado com sucesso.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            catch (Exception ex)
            { MessageBox.Show(ex.Message.Trim(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); }
            finally
            {
                tEspera.Fechar();
                tEspera = null;
            }
        }
예제 #2
0
        private void GerarArquivo()
        {
            if (cbEmpresa.SelectedValue == null)
            {
                MessageBox.Show("Obrigatorio informar empresa.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cbEmpresa.Focus();
                return;
            }
            if (string.IsNullOrEmpty(dt_ini.Text.SoNumero()))
            {
                MessageBox.Show("Obrigatório informar data inicial.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                dt_ini.Focus();
                return;
            }
            if (string.IsNullOrEmpty(dt_fin.Text.SoNumero()))
            {
                MessageBox.Show("Obrigatório informar data final.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                dt_fin.Focus();
                return;
            }
            if (cbDRE.SelectedValue == null)
            {
                MessageBox.Show("Obrigatório informar DRE.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cbDRE.Focus();
                return;
            }
            if (string.IsNullOrEmpty(path_sped.Text))
            {
                MessageBox.Show("Obrigatorio informar path para salvar arquivo.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                path_sped.Focus();
                return;
            }

            ThreadEspera tEspera = new ThreadEspera("Iniciando procedimento gerar SPED CONTABIL...");

            try
            {
                if (!System.IO.Directory.Exists(path_sped.Text))
                {
                    System.IO.Directory.CreateDirectory(path_sped.Text);
                }
                string arq = CamadaNegocio.Contabil.SPED_CONTABIL.TCN_SpedContabil.ProcessarSpedContabil(cbEmpresa.SelectedValue.ToString(),
                                                                                                         DateTime.Parse(dt_ini.Text),
                                                                                                         DateTime.Parse(dt_fin.Text),
                                                                                                         decimal.Parse(cbDRE.SelectedValue.ToString()),
                                                                                                         tEspera);
                using (System.IO.StreamWriter sw = new System.IO.StreamWriter(path_sped.Text + "\\ecd" +
                                                                              cbEmpresa.SelectedValue.ToString() +
                                                                              dt_ini.Text.Substring(6, 4) + ".txt",
                                                                              false,
                                                                              System.Text.Encoding.Default))
                {
                    sw.Write(arq + "\r\n");
                    sw.Close();
                    MessageBox.Show("Arquivo Sped CONTABIL gerado com sucesso.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message.Trim(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); }
            finally
            {
                tEspera.Fechar();
                tEspera = null;
            }
        }