Exemple #1
0
        public void iniciaprocessamento()
        {
            statusBar1.Text = "Iniciado processamento :" + Convert.ToString(DateTime.Now);
            //System.Threading.Thread.Sleep(200);
            var    configuracao = ConfigurationManager.AppSettings;
            string origem       = configuracao["Origem"];
            string destino      = configuracao["Destino"];
            string dB_Vendas    = configuracao["DB_Vendas"];
            //DirectoryInfo directoryInfo = new DirectoryInfo(@origem);
            var listagem_arquivos = Directory.EnumerateFiles(origem, "*.xml", SearchOption.TopDirectoryOnly);

            string[] ttt     = Directory.GetFiles(origem, "*.xml", SearchOption.TopDirectoryOnly);
            int      tamanho = ttt.Length;

            string[] db_vendas = File.ReadAllLines(dB_Vendas);
            //progressBar1.Minimum = 0;
            //progressBar1.Maximum = tamanho;
            //progressBar1.Value = 0;

            foreach (var path in listagem_arquivos)
            {
                string arquivo    = path.Remove(0, origem.Length + 1);
                bool   achou      = true;
                var    resultados = Array.Find(db_vendas, s => s.Contains(arquivo));
                if (resultados != null)
                {
                    achou = false;
                }

                if (achou)
                {
                    //Testa_arquivo arquivo1 = new Testa_arquivo();
                    ArquivoEmUso arquivo1 = new ArquivoEmUso();
                    arquivo1.Path = path;
                    if (arquivo1.Testar())
                    {
                        lexml(path, arquivo);
                        Movearquivo(path, arquivo, destino);
                    }
                }
            }
            statusBar1.Text = "Último processamento :" + Convert.ToString(DateTime.Now);
        }
Exemple #2
0
        public void lexml(string path, string arquivo)

        {
            XmlTextReader xmlReader = new XmlTextReader(path);

            var    configuracao = ConfigurationManager.AppSettings;
            string dB_Vendas    = configuracao["DB_Vendas"];

            string chave      = null;
            string nCFe       = null;
            string dEmi       = null;
            string hEmi       = null;
            string xProd      = null;
            string vItem      = null;
            string dataVenda  = null;
            string horaVenda  = null;
            double valorVenda = 0;

            while (xmlReader.Read())
            {
                switch (xmlReader.NodeType)
                {
                case XmlNodeType.Element:
                    chave = null;
                    if (xmlReader.Name == "nCFe")
                    {
                        chave = "nCFe";
                    }
                    if (xmlReader.Name == "dEmi")
                    {
                        chave = "dEmi";
                    }
                    if (xmlReader.Name == "hEmi")
                    {
                        chave = "hEmi";
                    }
                    if (xmlReader.Name == "xProd")
                    {
                        chave = "xProd";
                    }
                    if (xmlReader.Name == "vItem")
                    {
                        chave = "vItem";
                    }
                    break;

                case XmlNodeType.Text:
                    if (chave == "nCFe")
                    {
                        nCFe = xmlReader.Value;
                    }
                    if (chave == "dEmi")
                    {
                        dEmi = xmlReader.Value;
                    }
                    if (chave == "hEmi")
                    {
                        hEmi = xmlReader.Value;
                    }
                    if (chave == "xProd")
                    {
                        xProd = xmlReader.Value;
                    }
                    if (chave == "vItem")
                    {
                        vItem      = xmlReader.Value;
                        valorVenda = Convert.ToDouble(vItem) / 100;

                        ArquivoEmUso testadb = new ArquivoEmUso();
                        testadb.Path = dB_Vendas;
                        if (testadb.Testar())
                        {
                            using (StreamWriter sw = File.AppendText(dB_Vendas))
                            {
                                dataVenda = dEmi.Substring(dEmi.Length - 2, 2) + @"/" + dEmi.Substring(dEmi.Length - 4, 2) + @"/" + dEmi.Substring(0, 4);
                                horaVenda = hEmi.Substring(0, 2) + ":" + hEmi.Substring(2, 2) + ":" + hEmi.Substring(4, 2);
                                string dados = arquivo + ";" + nCFe + ";" + dataVenda + ";" + horaVenda + ";" + xProd + ";" + valorVenda;
                                sw.WriteLine(dados);
                                sw.Close();

                                //double valordodia = Calculasoma();
                                ArquivoEmUso diretorio   = new ArquivoEmUso();
                                int          TC          = diretorio.CalculaTC();
                                double       TT          = diretorio.CalculaTT();
                                double       TM          = TT / TC;
                                string       notificacao = "TD=" + TT.ToString("C") + " TC=" + TC + " TM=" + TM.ToString("C") + "-" + xProd + "-" + valorVenda.ToString("C") + "-" + horaVenda;

                                Envianotificação(notificacao);
                            }
                        }


                        xProd = null;
                    }
                    break;
                }
            }



            xmlReader.Close();
        }