Пример #1
0
        private void Button1_Click_1(object sender, EventArgs e)
        {
            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                //openFileDialog.Filter = "Excel files (*.xlsx)|*.xlsx|All files (*.*)|*.*";
                openFileDialog.Filter = "Txt files (*.txt)|*.txt|All files (*.*)|*.*";
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    lVipp               = null;
                    tipoArquivo         = "csv";
                    path                = openFileDialog.FileName;
                    nomeArquivo         = System.IO.Path.GetFileNameWithoutExtension(openFileDialog.FileName);
                    caminhoArquivo      = System.IO.Path.GetDirectoryName(openFileDialog.FileName);
                    labelPath.Text      = path;
                    labelProgresso.Text = "Importando o Arquivo";
                    #region Processa o Arquivo
                    lVipp = ProcessaPlanilha.ListaDePostagem(path, this, tipoArquivo);
                    #endregion

                    if (lVipp == null)
                    {
                        labelProgresso.Text = "";
                        labelPath.Text      = "";
                        path = null;
                    }
                    else
                    {
                        labelProgresso.Text = "Arquivo importado!";
                        btnEnviar.Enabled   = true;
                        comboPerfil.Focus();
                    }
                }
            }
        }
Пример #2
0
        void BtnSelecione_Click(object sender, EventArgs e)
        {
            #region Serialização do arquivo XML

            /*
             * XmlSerializer xsSubmit = new XmlSerializer(typeof(List<FormatacaoPlanilha>));
             * var subReq = new List<FormatacaoPlanilha>();
             *
             * using (var sww = new StringWriter())
             * {
             * using (XmlWriter writer = XmlWriter.Create(sww))
             * {
             *     xsSubmit.Serialize(writer, lFormatacao);
             *     var plainTextBytes = Encoding.UTF8.GetBytes(sww.ToString());
             *     string x = Convert.ToBase64String(plainTextBytes);
             * }
             * }
             */
            #endregion

            #region Abre o Arquivo
            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.Filter = "Excel files (*.csv)|*.csv|All files (*.*)|*.*";
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    path                = openFileDialog.FileName;
                    nomeArquivo         = System.IO.Path.GetFileNameWithoutExtension(openFileDialog.FileName);
                    caminhoArquivo      = System.IO.Path.GetDirectoryName(openFileDialog.FileName);
                    labelPath.Text      = path;
                    labelProgresso.Text = "Importando o Arquivo";
                    lVipp               = ProcessaPlanilha.ListaDePostagem(path, this);
                    labelProgresso.Text = "Arquivo importado!";

                    #region Chama o metodo para Postar Objeto
                    VIPP.PostarObjeto.Postagem(lVipp, this);
                    #endregion

                    labelProgresso.Text = "Salvando o arquivo processado...";
                    GravaRetornoExcel.GravaRetorno();
                    MessageBox.Show("Importação finalizada!");
                }
                else
                {
                    Hide();
                    new Form1().ShowDialog();
                }
            }

            #endregion
            //GC.Collect();
            //Close();
        }
        public List <Postagem> CarregaArquivos()
        {
            IniFile         oIniFile = new IniFile("Config");
            List <Postagem> lVipp    = new List <Postagem>();
            string          path     = oIniFile.IniReadString("Entrada");


            if (!Directory.Exists(string.Concat(path, @"\\TEMP")))
            {
                Directory.CreateDirectory(string.Concat(path, @"\\TEMP"));
            }
            string[] arquivos = Directory.GetFiles(path, "*.txt", SearchOption.AllDirectories);

            foreach (string arq in arquivos)
            {
                FileInfo fileInfo = new FileInfo(arq);
                string   fileName = fileInfo.Name;
                if (!File.Exists(string.Concat(path, @"\\TEMP\\", fileName)))
                {
                    Postar(ProcessaPlanilha.ListaDePostagem(arq, null, "txt"), fileName);
                    GravaRetorno.GravaRetornoTxt(fileName);
                    File.Move(arq, string.Concat(path, @"\\TEMP\\", fileName));
                }
                else
                {
                    if (!Directory.Exists(@"C:\Visualset.IntegradorWebService"))
                    {
                        Directory.CreateDirectory(@"C:\Visualset.IntegradorWebService");
                    }
                    using (StreamWriter vWriter = new StreamWriter(@"C:\Visualset.IntegradorWebService\LogServico.txt", true))
                    {
                        vWriter.WriteLine(string.Concat(DateTime.Now.ToString(), " | | O arquivo ", fileName, " já foi importado"));
                        vWriter.Flush();
                        vWriter.Close();
                    }
                }
            }
            return(lVipp);
        }