Ejemplo n.º 1
0
        private void CompararXlsProcessado(object sender, EventArgs e)
        {
            Filiais     temp = new Filiais();
            List <Nota> listaNotas;

            try
            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog
                {
                    InitialDirectory = @"C:\",
                    Title            = "Abrir arquivo XLS",

                    CheckFileExists = true,
                    CheckPathExists = true,
                    Multiselect     = false,

                    DefaultExt       = "xls",
                    Filter           = "Arquivos Excel (*.xls)|*.xls| Arquivos Excel (*.xlsx)|*.xlsx | Todos (*)|*.*",
                    FilterIndex      = 1,
                    RestoreDirectory = true,

                    ReadOnlyChecked = true,
                    ShowReadOnly    = true
                };

                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    foreach (string name in openFileDialog1.FileNames)
                    {
                        listaNotas   = new List <Nota>();
                        baseDiretory = Path.GetDirectoryName(name);
                        var file = new LinqToExcel.ExcelQueryFactory(@"" + name);
                        if (file != null)
                        {
                            var querry =
                                from row in file.Worksheet("Sheet")
                                let item = new
                            {
                                dsFantasia = row["dsFantasia"].Cast <String>(),
                                nmCNPJ     = row["nmCNPJ"].Cast <String>(),
                                nmArquivo  = row["nmArquivo"].Cast <String>(),
                                dtNota     = row["dtNota"].Cast <DateTime>(),
                                descricao  = row["descricao"].Cast <String>(),
                            }
                            select item;
                            foreach (var g in querry)
                            {
                                if (!g.descricao.Equals("ok"))
                                {
                                    listaNotas.Add(new Nota
                                    {
                                        dsFantasia   = g.dsFantasia,
                                        nmCNPJ       = g.nmCNPJ,
                                        nmArquivo    = g.nmArquivo,
                                        dtNota       = g.dtNota.ToString("yyyyMMdd"),
                                        descricao    = "",
                                        vlAtos       = 0,
                                        vlContabil   = 0,
                                        vlMercadoria = 0
                                    });
                                }
                            }

                            try
                            {
                                listaNotas           = Nota.notasAgrupadasPorChave(listaNotas, dateTimePicker1.Value);
                                label2.Text          = "Comparando Arquivo: ";
                                progressBar2.Maximum = listaNotas.Count();
                                progressBar2.Minimum = 0;
                                progressBar2.Value   = 0;
                                progressBar2.Step    = 1;
                            }
                            catch (Exception err)
                            {
                                MessageBox.Show(err.Message);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
        private void CompararDiaErro(object sender, EventArgs e)
        {
            Filiais        temp    = new Filiais();
            List <Filiais> filiais = temp.listarFiliais();
            List <Nota>    listaNotas;

            try
            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog
                {
                    InitialDirectory = @"C:\",
                    Title            = "Abrir arquivo XLS",

                    CheckFileExists = true,
                    CheckPathExists = true,
                    Multiselect     = false,

                    DefaultExt       = "xls",
                    Filter           = "Arquivos Excel (*.xls)|*.xls| Arquivos Excel (*.xlsx)|*.xlsx | Todos (*)|*.*",
                    FilterIndex      = 1,
                    RestoreDirectory = true,

                    ReadOnlyChecked = true,
                    ShowReadOnly    = true
                };

                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    foreach (string name in openFileDialog1.FileNames)
                    {
                        listaNotas   = new List <Nota>();
                        baseDiretory = Path.GetDirectoryName(name);
                        string nameArqv = Path.GetFileNameWithoutExtension(name);
                        nameArqv = RemoveDiacritics(nameArqv);
                        try
                        {
                            temp = null;
                            temp = filiais.Find(x => x.ds_fantasia.Contains(nameArqv));
                            if (temp == null)
                            {
                                MessageBox.Show("Nome do Arquivo não refere a uma Filial");
                                break;
                            }
                        }
                        catch (Exception exe)
                        {
                            MessageBox.Show(exe.Message);
                        }
                        var file = new LinqToExcel.ExcelQueryFactory(@"" + name);
                        if (file != null)
                        {
                            var querry =
                                from row in file.Worksheet("Sheet")
                                let item = new
                            {
                                cdChave      = row["Chave acesso"].Cast <String>(),
                                vlMercadoria = row["Valor mercadorias"].Cast <float>(),
                                vlContabil   = row["Valor contábil"].Cast <float>(),
                                dtNota       = row["Data do doc#"].Cast <DateTime>(),
                            }
                            select item;
                            foreach (var g in querry)
                            {
                                listaNotas.Add(new Nota
                                {
                                    cdChave      = g.cdChave,
                                    dsFantasia   = temp.ds_fantasia,
                                    nmCNPJ       = temp.nu_cnpj,
                                    nmArquivo    = nameArqv,
                                    vlMercadoria = g.vlMercadoria,
                                    vlContabil   = g.vlContabil,
                                    dtNota       = g.dtNota.ToString("yyyyMMdd"),
                                    descricao    = "",
                                    vlAtos       = 0
                                });
                            }

                            try
                            {
                                listaNotas           = Nota.notasAgrupadasPorChave(listaNotas, dateTimePicker1.Value);
                                label2.Text          = "Comparando Arquivo: ";
                                progressBar2.Maximum = listaNotas.Count();
                                progressBar2.Minimum = 0;
                                progressBar2.Value   = 0;
                                progressBar2.Step    = 1;
                                CompararNotas(listaNotas);
                            }
                            catch (Exception err)
                            {
                                MessageBox.Show(err.Message);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }