Example #1
0
        private void btnDone_Click(object sender, EventArgs e)
        {
            btnDone.Visible = false;
            lblStatus.Text  = "Analizando o Arquivo...";
            lblStatus.Refresh();

            if (txtPath.Text == "")
            {
                MessageBox.Show("Precisa informar o caminho do arquivo primeiro.", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnDone.Visible = true;
                lblStatus.Text  = "";
            }
            else
            {
                FileStream stream = File.Open(txtPath.Text, FileMode.Open, FileAccess.Read);
                var        reader = ExcelReaderFactory.CreateOpenXmlReader(stream);

                ProdutosBLL bll     = new ProdutosBLL();
                Produtos    produto = new Produtos();

                reader.Read();
                lblStatus.Text = "Carregando...";
                lblStatus.Refresh();

                while (reader.Read())
                {
                    int progress = (int)Math.Ceiling((decimal)reader.Depth / (decimal)reader.RowCount * (decimal)100);
                    ProgressBar.Visible = true;
                    ProgressBar.Value   = progress;
                    ProgressBar.Refresh();

                    lblProgress.Visible = true;
                    lblProgress.Text    = progress.ToString() + "%";
                    lblProgress.Refresh();

                    produto.codigo     = (reader[0] != null) ? Convert.ToInt32(reader[0]) : 0;
                    produto.descricao  = (reader[1] != null) ? reader[1].ToString() : "";
                    produto.quantidade = (reader[2] != null) ? Convert.ToDouble(reader[2].ToString()) : 0;
                    produto.valor      = (reader[3] != null) ? Convert.ToDouble(reader[3].ToString()) : 0;
                    produto.isQuarto   = false;
                    produto.isServico  = false;

                    string remover = (reader[4] != null) ? reader[4].ToString() : "N";

                    if (remover.ToLower() == "s")
                    {
                        bll.Delete(produto);
                    }
                    else
                    {
                        bll.VerificaProduto(produto);
                    }
                }
                MessageBox.Show("Importado com êxito!", "Alerta!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
        }