public static void ImportaArquivosConfig()
        {
            try
            {
                belConfiguracao objbelConfiguracao = new belConfiguracao();

                DirectoryInfo dPasta = new DirectoryInfo(Pastas.PASTA_XML_CONFIG);
                FileInfo[] finfo = dPasta.GetFiles("*.xml");

                foreach (FileInfo item in finfo)
                {
                    XDocument doc = XDocument.Load(item.FullName);
                    if (doc.Element("nfe_configuracoes") != null)
                    {
                        objbelConfiguracao = new belConfiguracao();
                        XElement e = doc.Element("nfe_configuracoes");

                        objbelConfiguracao.CAMINHO_PADRAO = e.Element("CaminhoPadrao") != null ? e.Element("CaminhoPadrao").Value : null;
                        objbelConfiguracao.CAMINHO_BANCO_DADOS = e.Element("BancoDados") != null ? e.Element("BancoDados").Value : null;
                        objbelConfiguracao.LOGOTIPO = e.Element("Logotipo") != null ? e.Element("Logotipo").Value : null;
                        objbelConfiguracao.QTDE_CASAS_PRODUTOS = e.Element("QtdeCasasProdutos") != null ? e.Element("QtdeCasasProdutos").Value : null;
                        objbelConfiguracao.QTDE_CASAS_VL_UNIT = e.Element("QtdeCasasVlUnit") != null ? e.Element("QtdeCasasVlUnit").Value : null;
                        objbelConfiguracao.GRAVA_NUM_NF_DUPL = e.Element("GravaNumNFseDupl") != null ? e.Element("GravaNumNFseDupl").Value : null;
                        objbelConfiguracao.VISUALIZA_HORA_DANFE = e.Element("VisualizaHoraDanfe") != null ? e.Element("VisualizaHoraDanfe").Value : null;
                        objbelConfiguracao.VISUALIZA_DATA_DANFE = e.Element("VisualizaDataDanfe") != null ? e.Element("VisualizaDataDanfe").Value : null;
                        objbelConfiguracao.USA_DANFE_SIMPLIFICADA = e.Element("UsaDanfeSimplificada") != null ? e.Element("UsaDanfeSimplificada").Value : null;
                        objbelConfiguracao.FUSO = e.Element("Fuso") != null ? e.Element("Fuso").Value : null;
                        objbelConfiguracao.COD_BARRAS_XML = e.Element("CodBarrasXml") != null ? e.Element("CodBarrasXml").Value : null;
                        objbelConfiguracao.TOTALIZA_CFOP = e.Element("TotalizaCFOP") != null ? e.Element("TotalizaCFOP").Value : null;
                        objbelConfiguracao.NM_SERVIDOR = e.Element("Servidor") != null ? e.Element("Servidor").Value : null;
                        objbelConfiguracao.PORTA = e.Element("Porta") != null ? e.Element("Porta").Value : null;
                        objbelConfiguracao.CD_EMPRESA = e.Element("Empresa") != null ? e.Element("Empresa").Value : null;
                        objbelConfiguracao.REQUER_SSL = e.Element("RequerSSL") != null ? e.Element("RequerSSL").Value : null;
                        objbelConfiguracao.DESTACA_IMP_TRIB_MUN = e.Element("DestacaImpTribMun") != null ? e.Element("DestacaImpTribMun").Value : null;
                        objbelConfiguracao.GRUPO_SERVICO = e.Element("GrupoServico") != null ? e.Element("GrupoServico").Value : null;
                        objbelConfiguracao.GRUPO_SCAN = null;
                        objbelConfiguracao.DS_DETALHE = false;
                        objbelConfiguracao.TIPO_IMPRESSAO = e.Element("TipoImpressao") != null ? e.Element("TipoImpressao").Value : null;
                        objbelConfiguracao.HOST_SERVIDOR = e.Element("HostServidor") != null ? e.Element("HostServidor").Value : null;
                        objbelConfiguracao.PORTA_SERVIDOR = e.Element("PortaServidor") != null ? e.Element("PortaServidor").Value : null;
                        objbelConfiguracao.EMAIL_REMETENTE = e.Element("EmailRemetente") != null ? e.Element("EmailRemetente").Value : null;
                        objbelConfiguracao.SENHA_REMETENTE = e.Element("SenhaRemetente") != null ? e.Element("SenhaRemetente").Value : null;
                        objbelConfiguracao.EMAIL_AUTOMATICO = e.Element("EmailAutomatico") != null ? e.Element("EmailAutomatico").Value : null;
                        objbelConfiguracao.TP_EMIS = 1;


                        #region Importa Arquivos

                        string sCaminhoBkp = string.Empty;

                        if (String.IsNullOrEmpty(objbelConfiguracao.CAMINHO_PADRAO))
                        {
                            objbelConfiguracao.CAMINHO_PADRAO = dPasta.FullName + @"\Arquivos\" + item.Name.Replace(".xml", "");

                            Acesso.CAMINHO_PADRAO = objbelConfiguracao.CAMINHO_PADRAO;
                            Pastas.ENVIO.ToString();
                            Pastas.ENVIADOS.ToString();
                            Pastas.CONTINGENCIA.ToString();
                            Pastas.CCe.ToString();
                            Pastas.CBARRAS.ToString();
                            Pastas.CANCELADOS.ToString();
                            Pastas.RETORNO.ToString();
                            Pastas.PROTOCOLOS.ToString();


                            DirectoryInfo dImporta = new DirectoryInfo(objbelConfiguracao.CAMINHO_PADRAO);
                            if (!dImporta.Exists)
                            {
                                dImporta.Create();
                            }
                            DirectoryInfo para;
                            DirectoryInfo deOrigem = null;

                            if (!String.IsNullOrEmpty(e.Element("PastaXmlEnviado").Value))
                            {
                                para = new DirectoryInfo(Pastas.ENVIADOS);
                                deOrigem = new DirectoryInfo(e.Element("PastaXmlEnviado").Value);
                                CopiaArquivos(deOrigem, para);
                                sCaminhoBkp = deOrigem.Parent.FullName + "\\backup\\";
                                if (!Directory.Exists(sCaminhoBkp))
                                {
                                    Directory.CreateDirectory(sCaminhoBkp);
                                }
                                MovePastaParaBkp(sCaminhoBkp, deOrigem);
                            }

                            if (!String.IsNullOrEmpty(e.Element("PastaXmlEnvio").Value))
                            {
                                para = new DirectoryInfo(Pastas.ENVIO);
                                deOrigem = new DirectoryInfo(e.Element("PastaXmlEnvio").Value);
                                CopiaArquivos(deOrigem, para);
                                MovePastaParaBkp(sCaminhoBkp, deOrigem);
                            }

                            if (!String.IsNullOrEmpty(e.Element("PastaXmlCancelados").Value))
                            {
                                para = new DirectoryInfo(Pastas.CANCELADOS);
                                deOrigem = new DirectoryInfo(e.Element("PastaXmlCancelados").Value);
                                CopiaArquivos(deOrigem, para);
                                MovePastaParaBkp(sCaminhoBkp, deOrigem);

                            }

                            if (!String.IsNullOrEmpty(e.Element("PastaProtocolos").Value))
                            {
                                para = new DirectoryInfo(Pastas.PROTOCOLOS);
                                deOrigem = new DirectoryInfo(e.Element("PastaProtocolos").Value);
                                CopiaArquivos(deOrigem, para);
                                MovePastaParaBkp(sCaminhoBkp, deOrigem);
                            }

                            if (!String.IsNullOrEmpty(e.Element("PastaContingencia").Value))
                            {
                                para = new DirectoryInfo(Pastas.CONTINGENCIA);
                                deOrigem = new DirectoryInfo(e.Element("PastaContingencia").Value);
                                CopiaArquivos(deOrigem, para);
                                MovePastaParaBkp(sCaminhoBkp, deOrigem);
                            }

                            if (!String.IsNullOrEmpty(e.Element("PastaCCe").Value))
                            {
                                para = new DirectoryInfo(Pastas.CCe);
                                deOrigem = new DirectoryInfo(e.Element("PastaCCe").Value);
                                CopiaArquivos(deOrigem, para);
                                MovePastaParaBkp(sCaminhoBkp, deOrigem);
                            }
                            if (!String.IsNullOrEmpty(e.Element("CodBarras").Value))
                            {
                                para = new DirectoryInfo(Pastas.CBARRAS);
                                deOrigem = new DirectoryInfo(e.Element("CodBarras").Value);
                                CopiaArquivos(deOrigem, para);
                                MovePastaParaBkp(sCaminhoBkp, deOrigem);
                            }
                        }

                        if (!sCaminhoBkp.Equals(""))
                        {
                            item.MoveTo(sCaminhoBkp + "\\" + item.Name);
                        }

                        #endregion

                    }

                    XmlSerializer s = new XmlSerializer(typeof(belConfiguracao));
                    FileStream f = File.Create(Pastas.PASTA_XML_CONFIG + "\\" + item.Name);
                    s.Serialize(f, objbelConfiguracao);
                    f.Close();
                    f.Dispose();

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #2
0
        private void CarregarDados()
        {
            nudQtd_Vl_unitario.Value = 2;
            nupCasasQtdeProd.Value = 2;

            cbxTpEmiss.DisplayMember = "ds_descvalor";
            cbxTpEmiss.ValueMember = "ds_valor";
            cbxTpEmiss.DataSource = objdaoConfig.CarregaComboModoSistema();
            cbxTpEmiss.cbx.SelectedIndex = 0;

            cbxFormDanfe.cbx.SelectedIndex = 0;
            cbxFusoHorario.cbx.SelectedIndex = 2;

            if (File.Exists(Pastas.PASTA_XML_CONFIG + Acesso.NM_CONFIG_TEMP))
            {
                cbxGruposServico.DisplayMember = "ds_descvalor";
                cbxGruposServico.ValueMember = "ds_valor";
                cbxGruposSCAN.DisplayMember = cbxGruposServico.DisplayMember;
                cbxGruposSCAN.ValueMember = cbxGruposServico.ValueMember;

                cbxGruposServico.cbx.DataSource = objdaoConfig.populaComboGruposFat();
                cbxGruposSCAN.cbx.DataSource = objdaoConfig.populaComboGruposFat();
                cbxGruposSCAN.cbx.SelectedIndex = -1;
                cbxGruposServico.cbx.SelectedIndex = -1;

                XmlSerializer s = new XmlSerializer(typeof(belConfiguracao));
                Stream file = new FileStream(Pastas.PASTA_XML_CONFIG + Acesso.NM_CONFIG_TEMP,
                    FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);

                objbelConfiguracao = new belConfiguracao();
                objbelConfiguracao = (belConfiguracao)s.Deserialize(file);
                file.Dispose();

                this.txtCaminhoPadrao.Text = objbelConfiguracao.CAMINHO_PADRAO;
                this.txtCaminhoPastaRelatorio.Text = objbelConfiguracao.CAMINHO_RELATORIO_ESPECIFICO;
                this.txtPastaEnviados.Text = objbelConfiguracao.CAMINHO_ESPECIFICO_ENVIADOS;
                this.txtBancoDados.Text = objbelConfiguracao.CAMINHO_BANCO_DADOS;
                this.txtCaminhoLogo.Text = objbelConfiguracao.LOGOTIPO;
                this.nupCasasQtdeProd.Value = Convert.ToDecimal(objbelConfiguracao.QTDE_CASAS_PRODUTOS);
                this.nudQtd_Vl_unitario.Value = Convert.ToDecimal(objbelConfiguracao.QTDE_CASAS_VL_UNIT);
                this.chkGravaNumNFseDup.Checked = Convert.ToBoolean(objbelConfiguracao.GRAVA_NUM_NF_DUPL);
                this.hlP_CheckBox1.Checked = Convert.ToBoolean(objbelConfiguracao.VISUALIZA_HORA_DANFE);
                this.ckbDataSaidaDanfe.Checked = Convert.ToBoolean(objbelConfiguracao.VISUALIZA_DATA_DANFE);
                this.ckbDanfeSimplificada.Checked = Convert.ToBoolean(objbelConfiguracao.USA_DANFE_SIMPLIFICADA);
                this.cbxFusoHorario.Text = objbelConfiguracao.FUSO;
                this.chkCodBarras.Checked = Convert.ToBoolean(objbelConfiguracao.COD_BARRAS_XML);
                this.chkTotCfop.Checked = Convert.ToBoolean(objbelConfiguracao.TOTALIZA_CFOP);
                this.txtServerDados.Text = objbelConfiguracao.NM_SERVIDOR;
                this.nudPorta.Text = objbelConfiguracao.PORTA;
                this.txtCodEmpresa.Text = objbelConfiguracao.CD_EMPRESA;
                this.chkDetalheProd.Checked = objbelConfiguracao.DS_DETALHE;
                this.chkNumNotaEntrada.Checked = objbelConfiguracao.IMPRIMI_NUM_NOTA_ENTRADA;
                this.chkNumPedidoVendaItens.Checked = objbelConfiguracao.IMPRIMI_NUM_PEDIDO_VENDA;
                this.chkVisualizaDadosNFe.Checked = objbelConfiguracao.VISUALIZA_DADOS_NFE;
                this.chkNumRevisaoItens.Checked = objbelConfiguracao.IMPRIMI_NUM_REVISAO;
                this.chkImprimeRetorno.Checked = objbelConfiguracao.IMPRIMI_RETORNO;
                this.ckbImprimiFaturaDanfe.Checked = objbelConfiguracao.IMPRIMI_FATURA;
                this.txtSenhaWebNFse.Text = objbelConfiguracao.SENHA_WEB_NFES;
                this.txtCodPrefeitura.Text = objbelConfiguracao.COD_PREFEITURA;

                this.ckbRequerSSL.Checked = Convert.ToBoolean(objbelConfiguracao.REQUER_SSL);
                this.chkTribMunicipio.Checked = Convert.ToBoolean(objbelConfiguracao.DESTACA_IMP_TRIB_MUN);
                if (cbxGruposServico.cbx.Items.Count > 0)
                {
                    if (!String.IsNullOrEmpty(objbelConfiguracao.GRUPO_SERVICO))
                    {
                        cbxGruposServico.SelectedValue = objbelConfiguracao.GRUPO_SERVICO;
                    }
                }
                if (cbxGruposSCAN.cbx.Items.Count > 0)
                {
                    if (!String.IsNullOrEmpty(objbelConfiguracao.GRUPO_SCAN))
                    {
                        cbxGruposSCAN.SelectedValue = objbelConfiguracao.GRUPO_SCAN;
                    }
                }
                this.cbxTransparencia.SelectedIndex = objbelConfiguracao.TRANSPARENCIA;
                this.cbxTpEmiss.cbx.SelectedValue = objbelConfiguracao.TP_EMIS.ToString();
                this.cbxFormDanfe.Text = objbelConfiguracao.TIPO_IMPRESSAO;
                this.hlP_TextBox1.Text = objbelConfiguracao.HOST_SERVIDOR;
                this.nudPortaHostEmail.Value = Convert.ToDecimal(objbelConfiguracao.PORTA_SERVIDOR);
                this.txtEmailRemetente.Text = objbelConfiguracao.EMAIL_REMETENTE;
                this.txtSenhaEmail.Text = objbelConfiguracao.SENHA_REMETENTE;
                this.ckbEmailAutomatico.Checked = Convert.ToBoolean(objbelConfiguracao.EMAIL_AUTOMATICO);

            }

        }
Example #3
0
        private void SalvarXml()
        {
            try
            {
                objbelConfiguracao = new belConfiguracao();
                objbelConfiguracao.CAMINHO_PADRAO = this.txtCaminhoPadrao.Text.ToString().Trim();
                objbelConfiguracao.CAMINHO_RELATORIO_ESPECIFICO = this.txtCaminhoPastaRelatorio.Text;
                objbelConfiguracao.CAMINHO_ESPECIFICO_ENVIADOS = this.txtPastaEnviados.Text;
                objbelConfiguracao.CAMINHO_BANCO_DADOS = this.txtBancoDados.Text;
                objbelConfiguracao.LOGOTIPO = this.txtCaminhoLogo.Text;
                objbelConfiguracao.QTDE_CASAS_PRODUTOS = this.nupCasasQtdeProd.Value.ToString();
                objbelConfiguracao.QTDE_CASAS_VL_UNIT = this.nudQtd_Vl_unitario.Value.ToString();
                objbelConfiguracao.GRAVA_NUM_NF_DUPL = this.chkGravaNumNFseDup.Checked.ToString();
                objbelConfiguracao.VISUALIZA_HORA_DANFE = this.hlP_CheckBox1.Checked.ToString();
                objbelConfiguracao.VISUALIZA_DATA_DANFE = this.ckbDataSaidaDanfe.Checked.ToString();
                objbelConfiguracao.USA_DANFE_SIMPLIFICADA = this.ckbDanfeSimplificada.Checked.ToString();
                if (cbxFusoHorario.Text != "")
                {
                    objbelConfiguracao.FUSO = cbxFusoHorario.Text.ToString();
                }
                else
                {
                    objbelConfiguracao.FUSO = "-02:00";
                }

                if (cbxTransparencia.Text != "")
                {
                    objbelConfiguracao.TRANSPARENCIA = cbxTransparencia.SelectedIndex;
                }
                else
                {
                    objbelConfiguracao.TRANSPARENCIA = 0;
                }

                objbelConfiguracao.COD_BARRAS_XML = this.chkCodBarras.Checked.ToString();
                objbelConfiguracao.TOTALIZA_CFOP = this.chkTotCfop.Checked.ToString();
                objbelConfiguracao.NM_SERVIDOR = this.txtServerDados.Text;
                objbelConfiguracao.PORTA = this.nudPorta.Text.Trim() == "0" ? "3050" : this.nudPorta.Text.Trim();
                objbelConfiguracao.CD_EMPRESA = this.txtCodEmpresa.Text;

                objbelConfiguracao.REQUER_SSL = this.ckbRequerSSL.Checked.ToString();
                objbelConfiguracao.DESTACA_IMP_TRIB_MUN = this.chkTribMunicipio.Checked.ToString();
                objbelConfiguracao.IMPRIMI_NUM_NOTA_ENTRADA = chkNumNotaEntrada.Checked;
                objbelConfiguracao.IMPRIMI_NUM_PEDIDO_VENDA = chkNumPedidoVendaItens.Checked;
                objbelConfiguracao.IMPRIMI_FATURA = ckbImprimiFaturaDanfe.Checked;
                objbelConfiguracao.IMPRIMI_NUM_REVISAO = chkNumRevisaoItens.Checked;
                objbelConfiguracao.IMPRIMI_RETORNO = chkImprimeRetorno.Checked;
                objbelConfiguracao.SENHA_WEB_NFES = this.txtSenhaWebNFse.Text;
                objbelConfiguracao.COD_PREFEITURA = this.txtCodPrefeitura.Text;
                objbelConfiguracao.VISUALIZA_DADOS_NFE = chkVisualizaDadosNFe.Checked;


                if (cbxGruposServico.cbx.Items.Count > 0)
                {
                    if (cbxGruposServico.SelectedValue != null)
                    {
                        objbelConfiguracao.GRUPO_SERVICO = cbxGruposServico.SelectedValue.ToString();
                    }
                }
                if (cbxGruposSCAN.cbx.Items.Count > 0)
                {
                    if (cbxGruposSCAN.SelectedValue != null)
                    {
                        objbelConfiguracao.GRUPO_SCAN = cbxGruposSCAN.SelectedValue.ToString();
                    }
                }
                objbelConfiguracao.DS_DETALHE = chkDetalheProd.Checked;
                objbelConfiguracao.TIPO_IMPRESSAO = cbxFormDanfe.Text.ToString();
                objbelConfiguracao.HOST_SERVIDOR = this.hlP_TextBox1.Text.Trim();
                objbelConfiguracao.PORTA_SERVIDOR = this.nudPortaHostEmail.Value.ToString().Trim();
                objbelConfiguracao.EMAIL_REMETENTE = this.txtEmailRemetente.Text.Trim();
                objbelConfiguracao.SENHA_REMETENTE = this.txtSenhaEmail.Text.Trim();
                objbelConfiguracao.EMAIL_AUTOMATICO = this.ckbEmailAutomatico.Checked.ToString();
                objbelConfiguracao.TP_EMIS = Convert.ToInt16(this.cbxTpEmiss.cbx.SelectedValue);

                try
                {
                    XmlSerializer s = new XmlSerializer(typeof(belConfiguracao));
                    FileStream f = File.Create(Pastas.PASTA_XML_CONFIG + Acesso.NM_CONFIG_TEMP);
                    s.Serialize(f, objbelConfiguracao);
                    f.Close();
                    f.Dispose();
                }
                catch (Exception)
                {
                    throw new Exception("Erro ao serializar a classe.");
                }
                // Cria Todas as Pastas.
                Acesso.CAMINHO_PADRAO = objbelConfiguracao.CAMINHO_PADRAO;
                Pastas.ENVIO.ToString();
                Pastas.ENVIADOS.ToString();
                Pastas.CONTINGENCIA.ToString();
                Pastas.CCe.ToString();
                Pastas.CBARRAS.ToString();
                Pastas.CANCELADOS.ToString();
                Pastas.RETORNO.ToString();
                Pastas.PROTOCOLOS.ToString();
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
Example #4
0
        private void AlteraConfig(int iEmissao)
        {
            XmlSerializer s = new XmlSerializer(typeof(belConfiguracao));
            Stream file = new FileStream(Pastas.PASTA_XML_CONFIG + Acesso.NM_CONFIG,
                FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);

            belConfiguracao objbelConfiguracao = new belConfiguracao();
            objbelConfiguracao = (belConfiguracao)s.Deserialize(file);
            file.Dispose();

            objbelConfiguracao.TP_EMIS = iEmissao;

            s = new XmlSerializer(typeof(belConfiguracao));
            FileStream f = File.Create(Pastas.PASTA_XML_CONFIG + Acesso.NM_CONFIG);
            s.Serialize(f, objbelConfiguracao);
            f.Close();
            f.Dispose();
            Acesso.TP_EMIS = iEmissao;
        }