private void loadContaCaixa(ConsultarReportHabil model) { DataTable ContaCaixa = new DataTable(); ReportHabilDAO report = new ReportHabilDAO(); ContaCaixa = report.ListaContaCaixa(model); var listContaCaixa = new List <ContaCaixa>(); row = ContaCaixa.NewRow(); row["ID_Conta_Caixa"] = 0; row["Descrição"] = "Todos"; ContaCaixa.Rows.Add(row); foreach (DataRow dr in ContaCaixa.Rows) { listContaCaixa.Add(new ContaCaixa { ID = Convert.ToInt32(dr["ID_Conta_Caixa"].ToString()), Nome = dr["Descrição"].ToString() }); } model.listContaCaixa = listContaCaixa; }
private void loadFornecedor(ConsultarReportHabil model) { DataTable Fornecedor = new DataTable(); ReportHabilDAO report = new ReportHabilDAO(); Fornecedor = report.ListaFornecedores(model); var listFornecedor = new List <Fornecedor>(); row = Fornecedor.NewRow(); row["ID_Fornecedor"] = 0; row["Nome_Fantasia"] = "Todos"; Fornecedor.Rows.Add(row); foreach (DataRow dr in Fornecedor.Rows) { listFornecedor.Add(new Fornecedor { ID = Convert.ToInt32(dr["ID_Fornecedor"].ToString()), Nome = dr["Nome_Fantasia"].ToString() }); } model.listFornecedor = listFornecedor; }
private void loadRelatorio(ConsultarReportHabil model) { DataTable Relatorio = new DataTable(); ReportHabilDAO report = new ReportHabilDAO(); Relatorio = report.ListaRelatorio(); var listRelatorio = new List <Relatorio>(); listRelatorio.Add(new Relatorio { ID = 0, Nome = "Selecione Relatorio" }); foreach (DataRow dr in Relatorio.Rows) { listRelatorio.Add(new Relatorio { ID = Convert.ToInt32(dr["ID"].ToString()), Nome = dr["Nome"].ToString() }); } model.DataUltimoUpdate = report.ConsultaUltimaAtualizacao(); model.listRelatorio = listRelatorio; }
private void loadContaBancaria(ConsultarReportHabil model) { DataTable ContaBancaria = new DataTable(); ReportHabilDAO reporte = new ReportHabilDAO(); if (model.ID_Relatorio != 1) // verifica qual relarotio { model.ID_Empresa = string.Join(",", model.ID_Empresa_Get); } ContaBancaria = reporte.ListaContaBancaria(model); // passar o model para fazer a consulta e retornar o datatable com var listaContaBancaria = new List <ContaBancaria>(); foreach (DataRow dr in ContaBancaria.Rows) { listaContaBancaria.Add(new ContaBancaria { ID = Convert.ToInt32(dr["ID_ContaBancaria"].ToString()), ID_Empresa = dr["Empresa"].ToString(), Nome = dr["Descrição"].ToString() }); } model.listContaBancaria = listaContaBancaria; // model.listContaBancaria = listaContaBancaria.Where(prop => prop.ID_Empresa == model.ID_Empresa).ToList(); }
private void loadCliente(ConsultarReportHabil model) { DataTable Cliente = new DataTable(); ReportHabilDAO report = new ReportHabilDAO(); Cliente = report.ListaCliente(model); var listCliente = new List <Cliente>(); row = Cliente.NewRow(); row["ID_Cliente"] = 0; row["Cliente_Nome"] = "Todos"; Cliente.Rows.Add(row); foreach (DataRow dr in Cliente.Rows) { listCliente.Add(new Cliente { ID = Convert.ToInt32(dr["ID_Cliente"].ToString()), Nome = dr["Cliente_Nome"].ToString() }); } model.listCliente = listCliente; }
private void loadCentroCusto(ConsultarReportHabil model) { DataTable CentroCusto = new DataTable(); ReportHabilDAO report = new ReportHabilDAO(); CentroCusto = report.ListaCentroCusto(model); var listCentroCusto = new List <CentroCusto>(); row = CentroCusto.NewRow(); row["ID_Centro_Custo"] = 0; row["Descrição"] = "Todos"; CentroCusto.Rows.Add(row); foreach (DataRow dr in CentroCusto.Rows) { listCentroCusto.Add(new CentroCusto { ID = Convert.ToInt32(dr["ID_Centro_Custo"].ToString()), Nome = dr["Descrição"].ToString() }); } model.listCentroCusto = listCentroCusto; }
public DataTable ListaFornecedores(ConsultarReportHabil model) { SqlCommand command = new SqlCommand(); command.Connection = con; command.CommandText = "select ID_Fornecedor,Nome_Fantasia from Fornecedor where Empresa in (SELECT * FROM STRING_SPLIT(@Empresa, ',')) order by Nome_Fantasia"; command.Parameters.AddWithValue("@Empresa", model.ID_Empresa); DataTable Fornecedor = new DataTable(); con.Open(); Fornecedor.Load(command.ExecuteReader()); con.Close(); return(Fornecedor); }
public string NomeRelatorioHabil(ConsultarReportHabil model) { SqlCommand command = new SqlCommand(); command.Connection = con; command.CommandText = "select Nome from Relatorio where ID = @ID"; command.Parameters.AddWithValue("@ID", model.ID_Relatorio); con.Open(); string Relatorio = (string)command.ExecuteScalar(); con.Close(); return(Relatorio); }
public DataTable ListaCliente(ConsultarReportHabil model) { SqlCommand command = new SqlCommand(); command.Connection = con; command.CommandText = "select ID_Cliente,Cliente_Nome from Cliente where Empresa in (SELECT * FROM STRING_SPLIT(@Empresa, ',')) order by Cliente_Nome"; command.Parameters.AddWithValue("@Empresa", model.ID_Empresa); DataTable Relatorio = new DataTable(); con.Open(); Relatorio.Load(command.ExecuteReader()); con.Close(); return(Relatorio); }
public DataTable ListaContaCaixa(ConsultarReportHabil model) { SqlCommand command = new SqlCommand(); command.Connection = con; command.CommandText = "select ID_Conta_Caixa,Código_Conta+ ' ' + Descrição as Descrição from Caixa_Contas where empresa = 1 order by Código_Conta"; // command.Parameters.AddWithValue("@Empresa", model.ID_Empresa); DataTable ContaCaixa = new DataTable(); con.Open(); ContaCaixa.Load(command.ExecuteReader()); con.Close(); return(ContaCaixa); }
public DataTable ListaCentroCusto(ConsultarReportHabil model) { SqlCommand command = new SqlCommand(); command.Connection = con; command.CommandText = "select ID_Centro_Custo,Descrição from Centros_Custos where Empresa = 1 order by Codigo"; //command.Parameters.AddWithValue("@Empresa", model.ID_Empresa); DataTable CentroCusto = new DataTable(); con.Open(); CentroCusto.Load(command.ExecuteReader()); con.Close(); return(CentroCusto); }
public DataTable ListaContaBancaria(ConsultarReportHabil model) { SqlCommand command = new SqlCommand(); command.Connection = con; // command.CommandText = "select Codigo,Empresa,Descrição from Contas_Bancarias"; command.CommandText = "select ID_ContaBancaria,Empresa,Descrição from Contas_Bancarias where Empresa in (SELECT * FROM STRING_SPLIT(@Empresa, ','))"; command.Parameters.AddWithValue("@Empresa", model.ID_Empresa); DataTable Conta = new DataTable(); con.Open(); Conta.Load(command.ExecuteReader()); con.Close(); return(Conta); }
public ActionResult ReportHabilView() { if (Request.IsAuthenticated) { try { ConsultarReportHabil listaEmpresa = new ConsultarReportHabil(); loadEmpresa(listaEmpresa); loadRelatorio(listaEmpresa); return(View(listaEmpresa)); } catch (Exception ex) { return(View("Error")); } } return(RedirectToAction("Index", "Home")); }
private void loadEmpresa(ConsultarReportHabil model) { //carrega empresas e ultima data de Update DataTable Empresa = new DataTable(); ReportHabilDAO report = new ReportHabilDAO(); Empresa = report.ListaEmpresa(); var listEmpresa = new List <Empresa>(); foreach (DataRow dr in Empresa.Rows) { listEmpresa.Add(new Empresa { ID = Convert.ToInt32(dr["Codigo"].ToString()), Nome = dr["Nome_Fantasia"].ToString() }); } model.listEmpresa = listEmpresa; }
public ActionResult ReportHabilView(ConsultarReportHabil model, string button) { if (button == "Pesquisa") { var tela = HabilReportView(model); ViewBag.ReportCabecalho = tela.ReportCabecalho; ViewBag.ReportCorpo = tela.ReportCorpo; ViewBag.Report_Total = tela.Report_Total; return(View("HabilReportView")); } else if (button == "Exportar") { var excel = ExportReport(model); return(File(excel.ArrayExcell, System.Net.Mime.MediaTypeNames.Application.Octet, excel.NomeArquivo)); } else { if (button != "Carregar") { model.ID_Empresa = null; loadEmpresa(model); loadRelatorio(model); return(View(model)); } else { loadEmpresa(model); loadContaBancaria(model); loadFornecedor(model); loadContaCaixa(model); loadCentroCusto(model); loadRelatorio(model); loadCliente(model); } } return(View(model)); }
//public ActionResult ExportReport(ConsultarReportHabil model) public RelatorioTelaExelHabil ExportReport(ConsultarReportHabil model) { ReportHabilDAO relatorio = new ReportHabilDAO(); RelatorioTelaExelHabil excel = new RelatorioTelaExelHabil(); DataTable tabela = new DataTable(); try { if (model.ID_Relatorio != 1) // Se nao for Extrato Carregar a lista de empresa e Conta Bancaria { model.ID_Empresa = string.Join(",", model.ID_Empresa_Get); model.ID_ContaBancaria = string.Join(",", model.ID_ContaBancaria_Get); } // model.ID_Fornecedor = string.Join(",", model.ID_Fornecedor_Get); // model.ID_Conta_Caixa = string.Join(",", model.ID_Conta_Caixa_Get); // model.ID_Centro_Custo = string.Join(",", model.ID_Centro_Custo_Get); tabela = relatorio.RelatorioHabil(model); string NomeRelatorio = relatorio.NomeRelatorioHabil(model); // captura o tamanho da tabela para formatar int coluna = 0; int linha = 3; string LetraValor = ""; string LetraDebito = ""; string LetraCredito = ""; string LetraSaldo = ""; int NumeroValor = 0; int NumeroDebito = 0; int NumeroCredito = 0; int NumeroSaldo = 0; foreach (DataColumn dtc in tabela.Columns) { if (dtc.ColumnName == "Valor") { LetraValor = RetornarCaractere(coluna); NumeroValor = coluna; } if (dtc.ColumnName == "Debito") { LetraDebito = RetornarCaractere(coluna); NumeroDebito = coluna; } if (dtc.ColumnName == "Credito") { LetraCredito = RetornarCaractere(coluna); NumeroCredito = coluna; } if (dtc.ColumnName == "Saldo") { LetraSaldo = RetornarCaractere(coluna); NumeroSaldo = coluna; } coluna++; } coluna++; foreach (DataRow dtl in tabela.Rows) { linha++; } // Cria arquivo em memoria byte[] byteArray = null; using (var package = new ExcelPackage()) { var ws = package.Workbook.Worksheets.Add("Sheet1"); // Coloca cabeçalho no formato ws.Cells["A1"].Value = NomeRelatorio; ws.Cells["A1"].Style.Font.Bold = true; ws.Cells["A1"].Style.Font.Size = 25; ws.Cells[1, 1, 1, 3].Merge = true; // Coloca Corpo no formato Tamanho e Font ws.Cells[4, 1, linha, coluna].Style.Font.Name = "Tahoma"; ws.Cells[4, 1, linha, coluna].Style.Font.Size = 8; //carrega tabela no excell ws.Cells[3, 1].LoadFromDataTable(tabela, true); //Formata Campo de Saldo if (NumeroSaldo != 0) { ws.Cells[(LetraSaldo + 4) + ":" + (LetraSaldo + linha)].Style.Numberformat.Format = @"_-R$ * #,##0.00_-;-R$ * #,##0.00_-;_-R$ * "" - ""??_-;_-@_-"; } //Verifica se tem Campo Valor para calcular total if ((NumeroValor != 0) && (linha != 3)) { //Variaveis para fazer calculo string colFormIni = LetraValor + 4;// 4 onde começa na tabela Execel string colFormFim = LetraValor + linha; //formato para todos os campos ws.Cells[colFormIni + ":" + colFormFim].Style.Numberformat.Format = @"_-R$ * #,##0.00_-;-R$ * #,##0.00_-;_-R$ * "" - ""??_-;_-@_-"; // Formulas para ultimo campo ws.Cells[LetraValor + (linha + 1)].Formula = "=SUM(" + colFormIni + ":" + colFormFim + ")"; ws.Cells[LetraValor + (linha + 1)].Style.Numberformat.Format = @"_-R$ * #,##0.00_-;-R$ * #,##0.00_-;_-R$ * "" - ""??_-;_-@_-"; } //Calculo Total para Debito if (NumeroDebito != 0) { ws.Cells[(LetraDebito + 4) + ":" + (LetraDebito + linha)].Style.Numberformat.Format = @"_-R$ * #,##0.00_-;-R$ * #,##0.00_-;_-R$ * "" - ""??_-;_-@_-"; // Formulas para ultimo campo ws.Cells[LetraDebito + (linha + 1)].Formula = "=SUM(" + (LetraDebito + 4) + ":" + (LetraDebito + linha) + ")"; ws.Cells[LetraDebito + (linha + 1)].Style.Numberformat.Format = @"_-R$ * #,##0.00_-;-R$ * #,##0.00_-;_-R$ * "" - ""??_-;_-@_-"; } //Calculo Total para Credito if (NumeroCredito != 0) { ws.Cells[(LetraCredito + 4) + ":" + (LetraCredito + linha)].Style.Numberformat.Format = @"_-R$ * #,##0.00_-;-R$ * #,##0.00_-;_-R$ * "" - ""??_-;_-@_-"; // Formulas para ultimo campo ws.Cells[LetraCredito + (linha + 1)].Formula = "=SUM(" + (LetraCredito + 4) + ":" + (LetraCredito + linha) + ")"; ws.Cells[LetraCredito + (linha + 1)].Style.Numberformat.Format = @"_-R$ * #,##0.00_-;-R$ * #,##0.00_-;_-R$ * "" - ""??_-;_-@_-"; } //Cestraliza o nome e o cabeçalho da tabela ws.Cells[1, 1, 3, coluna].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; //Alinha as informações do relatorio a esquerda ws.Cells[4, 1, linha + 1, coluna].Style.HorizontalAlignment = ExcelHorizontalAlignment.Left; //Ajusta tabela para se auto ajustar o tamanho ws.Cells[3, 1, linha + 1, coluna - 1].AutoFitColumns(); //Borda fina toda tabela ws.Cells[3, 1, linha, coluna].Style.Border.Top.Style = ExcelBorderStyle.Thin; ws.Cells[3, 1, linha, coluna].Style.Border.Left.Style = ExcelBorderStyle.Thin; ws.Cells[3, 1, linha, coluna].Style.Border.Right.Style = ExcelBorderStyle.Thin; ws.Cells[3, 1, linha, coluna].Style.Border.Bottom.Style = ExcelBorderStyle.Thin; // Ajusta bordas media cabeçalho ws.Cells[3, 1, 3, coluna].Style.Border.Top.Style = ExcelBorderStyle.Medium; ws.Cells[3, 1, 3, coluna].Style.Border.Bottom.Style = ExcelBorderStyle.Medium; //Borda media geral ws.Cells[3, 1, linha, 1].Style.Border.Left.Style = ExcelBorderStyle.Medium; ws.Cells[linha, 1, linha, coluna].Style.Border.Bottom.Style = ExcelBorderStyle.Medium; ws.Cells[3, coluna, linha, coluna].Style.Border.Right.Style = ExcelBorderStyle.Medium; ws.Cells[3, coluna, linha, coluna].Style.Border.Left.Style = ExcelBorderStyle.Medium; //tamanho da ultima celula ws.Column(coluna).Width = 3; //byteArray = package.GetAsByteArray(); // string fileName = NomeRelatorio + ".xlsx"; excel.ArrayExcell = package.GetAsByteArray(); excel.NomeArquivo = NomeRelatorio + ".xlsx"; //return File(byteArray, System.Net.Mime.MediaTypeNames.Application.Octet, fileName); } } catch (Exception ex) { RedirectToAction("Erro", ex.ToString()); } return(excel); }
//public ActionResult HabilReportView(ConsultarReportHabil model) public RelatorioTelaExelHabil HabilReportView(ConsultarReportHabil model) { ReportHabilDAO relatorio = new ReportHabilDAO(); RelatorioTelaExelHabil Tela = new RelatorioTelaExelHabil(); DataTable tabela = new DataTable(); StringBuilder htmlCabecalho = new StringBuilder(); StringBuilder htmlCorpo = new StringBuilder(); if (model.ID_Relatorio != 1) { model.ID_Empresa = string.Join(",", model.ID_Empresa_Get); model.ID_ContaBancaria = string.Join(",", model.ID_ContaBancaria_Get); } try { tabela = relatorio.RelatorioHabil(model); // monta o cabeçalho // htmlCabecalho.Append("<thead>"); htmlCabecalho.Append("<tr>"); foreach (DataColumn coluna in tabela.Columns) { htmlCabecalho.Append("<th>"); htmlCabecalho.Append(coluna.ColumnName); htmlCabecalho.Append("</th>"); } htmlCabecalho.Append("</tr>"); // htmlCabecalho.Append("</thead>"); // Preenche com os dados // htmlCorpo.Append("<tbody>"); double Total = 0.00; foreach (DataRow row in tabela.Rows) { htmlCorpo.Append("<tr>"); foreach (DataColumn coluna in tabela.Columns) { htmlCorpo.Append("<td>"); htmlCorpo.Append(row[coluna.ColumnName]); htmlCorpo.Append("</td>"); // Calcula o Valor Total da pequisa if (coluna.ColumnName == "Valor") { Total += Convert.ToDouble(row[coluna.ColumnName]); } } htmlCorpo.Append("</tr>"); } // htmlCorpo.Append("</tbody>"); //ViewBag.ReportCabecalho = htmlCabecalho.ToString(); //ViewBag.ReportCorpo = htmlCorpo.ToString(); Tela.Report_Total = Total.ToString("C"); Tela.ReportCabecalho = htmlCabecalho.ToString(); Tela.ReportCorpo = htmlCorpo.ToString(); } catch (Exception ex) { // return View(); RedirectToAction("Erro", ex.ToString()); } return(Tela); }
public DataTable RelatorioHabil(ConsultarReportHabil model) { //List<RetornoRelatorioHabil> relatorio = new List<RetornoRelatorioHabil>(); DataTable Relatorio = new DataTable(); DataTable Empresa = new DataTable(); DataTable ContaBancaria = new DataTable(); DataTable Fornecedor = new DataTable(); DataTable CentroCustro = new DataTable(); DataTable ContaCaixa = new DataTable(); DataTable Cliente = new DataTable(); Empresa.Columns.Add("Valor", typeof(int)); ContaBancaria.Columns.Add("Valor", typeof(int)); Fornecedor.Columns.Add("Valor", typeof(int)); CentroCustro.Columns.Add("Valor", typeof(int)); ContaCaixa.Columns.Add("Valor", typeof(int)); Cliente.Columns.Add("Valor", typeof(int)); if (model.ID_Relatorio == 1) // se o relatorio for extrato { // model.ID_Empresa = model.ID_Empresa_Get[0].ToString(); // model.ID_ContaBancaria = model.ID_ContaBancaria_Get[0].ToString(); Empresa.Rows.Add(0); ContaBancaria.Rows.Add(0); Fornecedor.Rows.Add(0); CentroCustro.Rows.Add(0); ContaCaixa.Rows.Add(0); Cliente.Rows.Add(0); } else { foreach (string dr in model.ID_Empresa_Get) { Empresa.Rows.Add(Convert.ToInt32(dr.ToString())); } foreach (string dr in model.ID_ContaBancaria_Get) { ContaBancaria.Rows.Add(Convert.ToInt32(dr.ToString())); } //Analisar Fonecedor if ((model.ID_Relatorio != 1) && (model.ID_Relatorio != 5)) { model.ID_Fornecedor = "1"; foreach (string dr in model.ID_Fornecedor_Get) { if (Convert.ToInt32(dr.ToString()) == 0) { model.ID_Fornecedor = dr.ToString(); break; } } if (string.IsNullOrEmpty(model.ID_Fornecedor) || model.ID_Fornecedor == "1") { foreach (string dr in model.ID_Fornecedor_Get) { Fornecedor.Rows.Add(Convert.ToInt32(dr.ToString())); } } } //Analisar Centro de Custo model.ID_Centro_Custo = "1"; foreach (string dr in model.ID_Centro_Custo_Get) { if (Convert.ToUInt32(dr.ToString()) == 0) { model.ID_Centro_Custo = dr.ToString(); break; } } if (string.IsNullOrEmpty(model.ID_Centro_Custo) || model.ID_Centro_Custo == "1") { foreach (string dr in model.ID_Centro_Custo_Get) { CentroCustro.Rows.Add(Convert.ToInt32(dr.ToString())); } } //Analise de Conta Caixa model.ID_Conta_Caixa = "1"; foreach (string dr in model.ID_Conta_Caixa_Get) { if (Convert.ToInt32(dr.ToString()) == 0) { model.ID_Conta_Caixa = dr.ToString(); break; } } if (string.IsNullOrEmpty(model.ID_Conta_Caixa) || model.ID_Conta_Caixa == "1") { foreach (string dr in model.ID_Conta_Caixa_Get) { ContaCaixa.Rows.Add(Convert.ToInt32(dr.ToString())); } } //Analise de Cliente if ((model.ID_Relatorio != 4) && (model.ID_Relatorio != 3) && (model.ID_Relatorio != 1)) { model.ID_Cliente = "1"; foreach (string dr in model.ID_Cliente_Get) { if (Convert.ToInt32(dr.ToString()) == 0) { model.ID_Cliente = dr.ToString(); break; } } //if (string.IsNullOrEmpty(model.ID_Cliente)) if (model.ID_Cliente == "1") { foreach (string dr in model.ID_Cliente_Get) { Cliente.Rows.Add(Convert.ToInt32(dr.ToString())); } } } } SqlCommand command = new SqlCommand(); command.Connection = con; command.CommandType = CommandType.StoredProcedure; command.CommandText = "C#_Relatorio_Habil"; command.Parameters.AddWithValue("@ID_RELATORIO", model.ID_Relatorio); command.Parameters.AddWithValue("@DATAIN", model.Datainicio); command.Parameters.AddWithValue("@DATAFIM", model.Datafim); command.Parameters.AddWithValue("@ID_EMPRESA_EX", model.ID_Empresa); command.Parameters.AddWithValue("ID_CONTABANCARIA_EX", model.ID_ContaBancaria); command.Parameters.AddWithValue("@ID_FORNECEDOR_EX", Convert.ToInt32(model.ID_Fornecedor)); command.Parameters.AddWithValue("@ID_CLIENTE_EX", Convert.ToInt32(model.ID_Cliente)); command.Parameters.AddWithValue("@ID_CONTACAIXA_EX", Convert.ToInt32(model.ID_Conta_Caixa)); command.Parameters.AddWithValue("@ID_CENTROCUSTO_EX", Convert.ToInt32(model.ID_Centro_Custo)); command.Parameters.Add("ID_EMPRESA", SqlDbType.Structured, -1).Value = Empresa; command.Parameters.Add("ID_CONTABANCARIA", SqlDbType.Structured, -1).Value = ContaBancaria; command.Parameters.Add("ID_FORNECEDOR", SqlDbType.Structured, -1).Value = Fornecedor; command.Parameters.Add("ID_CENTROCUSTO", SqlDbType.Structured, -1).Value = CentroCustro; command.Parameters.Add("ID_CONTACAIXA", SqlDbType.Structured, -1).Value = ContaCaixa; command.Parameters.Add("ID_CLIENTE", SqlDbType.Structured, -1).Value = Cliente; //SqlDataReader ler = command.ExecuteReader(); con.Open(); Relatorio.Load(command.ExecuteReader()); con.Close(); return(Relatorio); }