private LIS_PEDIDO3Collection BuscaPedidoPelaCidade(int COD_MUN_IBGE) { LIS_PEDIDO3Collection LIS_PEDIDO5COLL = new LIS_PEDIDO3Collection(); RowRelatorio.Clear(); string DataInicial = Util.ConverStringDateSearch(msktDataInicial.Text); string DataFinal = Util.ConverStringDateSearch(msktDataFinal.Text); RowRelatorio.Add(new RowsFiltro("COD_MUN_IBGE", "System.Int32", "=", COD_MUN_IBGE.ToString())); if (Convert.ToInt32(cbFuncionario.SelectedValue) > 0) { RowRelatorio.Add(new RowsFiltro("IDVENDEDOR", "System.Int32", "=", Convert.ToInt32(cbFuncionario.SelectedValue).ToString())); } if (Convert.ToInt32(cbTransportador.SelectedValue) > 0) { RowRelatorio.Add(new RowsFiltro("IDTRANSPORTES", "System.Int32", "=", Convert.ToInt32(cbTransportador.SelectedValue).ToString())); } RowRelatorio.Add(new RowsFiltro("DTEMISSAO", "System.DateTime", ">=", DataInicial)); RowRelatorio.Add(new RowsFiltro("DTEMISSAO", "System.DateTime", "<=", DataFinal)); if (txtCidade1.Text.Trim() != string.Empty) { RowRelatorio.Add(new RowsFiltro("COD_MUN_IBGE", "System.Int32", "=", _COD_MUN_IBGE.ToString())); } if (rbOrcamentoPesquisa.Checked) { RowRelatorio.Add(new RowsFiltro("FLAGORCAMENTO", "System.String", "=", "S")); } else if (rbVendasPesquisa.Checked) { RowRelatorio.Add(new RowsFiltro("FLAGORCAMENTO", "System.String", "=", "N")); } if (Convert.ToInt32(cbStatus.SelectedValue) > 0) { RowRelatorio.Add(new RowsFiltro("IDSTATUS", "System.Int32", "=", Convert.ToInt32(cbStatus.SelectedValue).ToString())); } if (Convert.ToInt32(cbFuncionario.SelectedValue) > 0) { LIS_PEDIDO5COLL = LIS_PEDIDOP3.ReadCollectionByParameter(RowRelatorio, "IDTRANSPORTES, IDPEDIDO"); } else { LIS_PEDIDO5COLL = LIS_PEDIDOP3.ReadCollectionByParameter(RowRelatorio); } return(LIS_PEDIDO5COLL); }
private void btnPesquisa_Click(object sender, EventArgs e) { if (Validacoes()) { try { RowRelatorio.Clear(); string DataInicial = Util.ConverStringDateSearch(msktDataInicial.Text); string DataFinal = Util.ConverStringDateSearch(msktDataFinal.Text); if (Convert.ToInt32(cbFuncionario.SelectedValue) > 0) { RowRelatorio.Add(new RowsFiltro("IDVENDEDOR", "System.Int32", "=", Convert.ToInt32(cbFuncionario.SelectedValue).ToString())); } RowRelatorio.Add(new RowsFiltro("DTEMISSAO", "System.DateTime", ">=", DataInicial)); RowRelatorio.Add(new RowsFiltro("DTEMISSAO", "System.DateTime", "<=", DataFinal)); if (txtCidade1.Text.Trim() != string.Empty) { RowRelatorio.Add(new RowsFiltro("COD_MUN_IBGE", "System.Int32", "=", _COD_MUN_IBGE.ToString())); } if (Convert.ToInt32(cbStatus.SelectedValue) > 0) { RowRelatorio.Add(new RowsFiltro("IDSTATUS", "System.Int32", "=", Convert.ToInt32(cbStatus.SelectedValue).ToString())); } if (rbOrcamentoPesquisa.Checked) { RowRelatorio.Add(new RowsFiltro("FLAGORCAMENTO", "System.String", "=", "S")); } else if (rbVendasPesquisa.Checked) { RowRelatorio.Add(new RowsFiltro("FLAGORCAMENTO", "System.String", "=", "N")); } LIS_PEDIDO3Coll = LIS_PEDIDO3P.ReadCollectionByParameter(RowRelatorio, "DTEMISSAO"); PreencheGrid2(); } catch (Exception EX) { MessageBox.Show("Erro na pesquisa!"); MessageBox.Show("Erro técnico: " + EX.Message); } } }
private static LIS_PEDIDO3Collection ExecuteReader(ref LIS_PEDIDO3Collection collection, ref FbDataReader dataReader, FbCommand dbCommand) { using (dataReader = dbCommand.ExecuteReader()) { collection = new LIS_PEDIDO3Collection(); if (dataReader.HasRows) { while (dataReader.Read()) { collection.Add(FillEntityObject(ref dataReader)); } } if (!(dataReader.IsClosed)) { dataReader.Close(); } dataReader.Dispose(); } return(collection); }
private void PreencheGrid2() { TotalGeral = 0; TotalQuantidade = 0; SubTotal = 0; CreaterCursor Cr = new CreaterCursor(); this.Cursor = Cr.CreateCursor(Cr.btmap, 0, 0); DataGriewDados.Rows.Clear(); //Remove as Cidades Repetidas LIS_PEDIDO3Collection LIS_PEDIDO3Coll_2 = new LIS_PEDIDO3Collection(); foreach (LIS_PEDIDO3Entity item in LIS_PEDIDO3Coll) { if (LIS_PEDIDO3Coll_2.Find(delegate(LIS_PEDIDO3Entity item2) { return(item2.COD_MUN_IBGE == item.COD_MUN_IBGE); }) == null) { LIS_PEDIDO3Coll_2.Add(item); } } //Cabeçalho Nome Cidade DataGridViewRow row1_2 = new DataGridViewRow(); row1_2.CreateCells(DataGriewDados, "CIDADE/UF", "", "", "", ""); row1_2.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold); DataGriewDados.Rows.Add(row1_2); foreach (var LIS_PEDIDO3ty in LIS_PEDIDO3Coll_2) { //Busca Dados do produto por cidade LIS_PRODUTOSPEDIDOCollection LIS_PRODUTOSPEDIDOColl_3 = new LIS_PRODUTOSPEDIDOCollection(); LIS_PRODUTOSPEDIDOColl_3 = BuscaProdutoPedidoPelaCidade(Convert.ToInt32(LIS_PEDIDO3ty.COD_MUN_IBGE)); if (LIS_PRODUTOSPEDIDOColl_3.Count > 0) { TotalQuantidade = 0; SubTotal = 0; LIS_MUNICIPIOSCollection LIS_MUNICIPIOSColl = new LIS_MUNICIPIOSCollection(); LIS_MUNICIPIOSProvider LIS_MUNICIPIOSP = new LIS_MUNICIPIOSProvider(); RowRelatorio.Clear(); RowRelatorio.Add(new RowsFiltro("COD_MUN_IBGE", "System.Int32", "=", LIS_PEDIDO3ty.COD_MUN_IBGE.ToString())); LIS_MUNICIPIOSColl = LIS_MUNICIPIOSP.ReadCollectionByParameter(RowRelatorio); DataGridViewRow row1_3 = new DataGridViewRow(); row1_3.CreateCells(DataGriewDados, LIS_MUNICIPIOSColl[0].MUNIUF, "", "", "", ""); row1_3.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold); DataGriewDados.Rows.Add(row1_3); DataGridViewRow row1_4 = new DataGridViewRow(); row1_4.CreateCells(DataGriewDados, "PRODUTO", "QUANT.", "DATA", "PEDIDO", "TOTAL"); row1_4.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold); DataGriewDados.Rows.Add(row1_4); } foreach (var LIS_PRODUTOSPEDIDOTy_3 in LIS_PRODUTOSPEDIDOColl_3) { CLIENTEEntity CLIENTEtY = new CLIENTEEntity(); CLIENTEProvider CLIENTEP = new CLIENTEProvider(); CLIENTEtY = CLIENTEP.Read(Convert.ToInt32(LIS_PRODUTOSPEDIDOTy_3.IDCLIENTE)); string DataEmissao = Convert.ToDateTime(LIS_PRODUTOSPEDIDOTy_3.DTEMISSAO).ToString("dd/MM/yyyy"); if (chkAgruparProduto.Checked) { DataEmissao = string.Empty; } string NomeProduto = LIS_PRODUTOSPEDIDOTy_3.NOMEPRODUTO; string QuantProduto = LIS_PRODUTOSPEDIDOTy_3.QUANTIDADE.ToString(); if (chkAgruparProduto.Checked) { QuantProduto = TotalQuantProdutoAgrupado(Convert.ToInt32(LIS_PRODUTOSPEDIDOTy_3.IDPRODUTO), Convert.ToInt32(LIS_PRODUTOSPEDIDOTy_3.COD_MUN_IBGE)).ToString(); TotalQuantidade += Convert.ToDecimal(QuantProduto); } else { TotalQuantidade += Convert.ToDecimal(LIS_PRODUTOSPEDIDOTy_3.QUANTIDADE); } string NUMPEDIDO = LIS_PRODUTOSPEDIDOTy_3.IDPEDIDO.ToString().PadLeft(6, '0'); if (chkAgruparProduto.Checked) { NUMPEDIDO = string.Empty; } string TotalProduto = Convert.ToDecimal(LIS_PRODUTOSPEDIDOTy_3.VALORTOTAL).ToString("n2"); if (chkAgruparProduto.Checked) { TotalProduto = TotalValorProdutoAgrupado(Convert.ToInt32(LIS_PRODUTOSPEDIDOTy_3.IDPRODUTO), Convert.ToInt32(LIS_PRODUTOSPEDIDOTy_3.COD_MUN_IBGE)).ToString("n2"); SubTotal += Convert.ToDecimal(TotalProduto); TotalGeral += Convert.ToDecimal(TotalProduto); } else { SubTotal += Convert.ToDecimal(LIS_PRODUTOSPEDIDOTy_3.VALORTOTAL); TotalGeral += Convert.ToDecimal(LIS_PRODUTOSPEDIDOTy_3.VALORTOTAL); } string TELEFONE1 = CLIENTEtY.TELEFONE1; DataGridViewRow row2 = new DataGridViewRow(); row2.CreateCells(DataGriewDados, NomeProduto, QuantProduto, DataEmissao, NUMPEDIDO, TotalProduto); row2.DefaultCellStyle.Font = new Font("Arial", 8); DataGriewDados.Rows.Add(row2); } if (LIS_PRODUTOSPEDIDOColl_3.Count > 0) { DataGridViewRow row1_5 = new DataGridViewRow(); row1_5.CreateCells(DataGriewDados, "-------------------------------------------------------", TotalQuantidade.ToString(), "---------", "Sub-Total", SubTotal.ToString("n2")); row1_5.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold); DataGriewDados.Rows.Add(row1_5); } } DataGridViewRow rowLinha = new DataGridViewRow(); rowLinha.CreateCells(DataGriewDados, "-------------------------------------------------------", "---------", "---------", "Total geral:", TotalGeral.ToString("n2")); rowLinha.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold); DataGriewDados.Rows.Add(rowLinha); this.Cursor = Cursors.Default; }
public LIS_PEDIDO3Collection ReadCollectionByParameter(List <RowsFiltro> RowsFiltro, string FieldOrder) { FbDataReader dataReader = null; string strSqlCommand = String.Empty; LIS_PEDIDO3Collection collection = null; try { if (RowsFiltro != null) { if (RowsFiltro.Count > 0) { strSqlCommand = "SELECT * FROM LIS_PEDIDO3 WHERE ("; ArrayList _rowsFiltro = new ArrayList(); RowsFiltro.ForEach(delegate(RowsFiltro i) { string[] item = { i.Condicao.ToString(), i.Campo.ToString(), i.Tipo.ToString(), i.Operador.ToString(), i.Valor.ToString() }; _rowsFiltro.Add(item); }); int _count = 1; foreach (string[] item in _rowsFiltro) { strSqlCommand += "(" + item[1] + " " + item[3]; switch (item[2]) { case ("System.String"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " '" + item[4] + "')"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Int16"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " " + item[4] + ")"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Int32"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " " + item[4] + ")"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Int64"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " " + item[4] + ")"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Double"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " " + item[4] + ")"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Decimal"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " " + item[4] + ")"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Float"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " " + item[4] + ")"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Byte"): strSqlCommand += " " + item[4] + ")"; break; case ("System.SByte"): strSqlCommand += " " + item[4] + ")"; break; case ("System.Char"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " '" + item[4] + "')"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.DateTime"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " '" + item[4] + "')"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Guid"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " '" + item[4] + "')"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Boolean"): strSqlCommand += " " + item[4] + ")"; break; } if (_rowsFiltro.Count > 1) { if (_count < _rowsFiltro.Count) { strSqlCommand += " " + item[0] + " "; } _count++; } } strSqlCommand += ") order by " + FieldOrder; } else { strSqlCommand = "SELECT * FROM LIS_PEDIDO3 order by " + FieldOrder; } } else { strSqlCommand = "SELECT * FROM LIS_PEDIDO3 order by " + FieldOrder; } //Verificando a existência de um transação aberta if (dbTransaction != null) { if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand(strSqlCommand, dbCnn); dbCommand.CommandType = CommandType.Text; dbCommand.Transaction = ((FbTransaction)(dbTransaction)); } else { if (dbCnn == null) { dbCnn = new FbConnection(connectionString); } if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand(strSqlCommand, dbCnn); dbCommand.CommandType = CommandType.Text; dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted); } collection = ExecuteReader(ref collection, ref dataReader, dbCommand); if (dataReader != null) { dataReader.Close(); dataReader.Dispose(); } if (dbTransaction == null) { dbCommand.Transaction.Commit(); dbCnn.Close(); } return(collection); } catch (Exception ex) { // Deleta reader if (dataReader != null) { dataReader.Close(); dataReader.Dispose(); } if (dbTransaction != null) { this.RollbackTransaction(); } else { if (dbCommand.Transaction != null) { dbCommand.Transaction.Rollback(); } if (dbCnn.State == ConnectionState.Open) { dbCnn.Close(); } } throw ex; } }
public LIS_PEDIDO3Collection ReadCollection() { FbDataReader dataReader = null; try { LIS_PEDIDO3Collection collection = null; //Verificando a existência de um transação aberta if (dbTransaction != null) { if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("SELECT * FROM LIS_PEDIDO3", dbCnn); dbCommand.Transaction = ((FbTransaction)(dbTransaction)); } else { if (dbCnn == null) { dbCnn = ((FbConnection)GetConnectionDB()); } if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("SELECT * FROM LIS_PEDIDO3", dbCnn); dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted); } // Tipo do comando de banco Procedure ou SQL dbCommand.CommandType = CommandType.Text; collection = ExecuteReader(ref collection, ref dataReader, dbCommand); if (dataReader != null) { dataReader.Close(); dataReader.Dispose(); } if (dbTransaction == null) { dbCommand.Transaction.Commit(); dbCnn.Close(); } return(collection); } catch (Exception ex) { // Deleta reader if (dataReader != null) { dataReader.Close(); dataReader.Dispose(); } if (dbTransaction != null) { this.RollbackTransaction(); } else { if (dbCommand.Transaction != null) { dbCommand.Transaction.Rollback(); } if (dbCnn.State == ConnectionState.Open) { dbCnn.Close(); } } throw ex; } }
private void PreencheGrid2() { TotalGeral = 0; CreaterCursor Cr = new CreaterCursor(); this.Cursor = Cr.CreateCursor(Cr.btmap, 0, 0); DataGriewDados.Rows.Clear(); //Remove as Cidades Repetidas LIS_PEDIDO3Collection LIS_PEDIDO3Coll_2 = new LIS_PEDIDO3Collection(); foreach (LIS_PEDIDO3Entity item in LIS_PEDIDO3Coll) { if (LIS_PEDIDO3Coll_2.Find(delegate(LIS_PEDIDO3Entity item2) { return(item2.COD_MUN_IBGE == item.COD_MUN_IBGE); }) == null) { LIS_PEDIDO3Coll_2.Add(item); } } //Cabeçalho Nome Cidade DataGridViewRow row1_2 = new DataGridViewRow(); row1_2.CreateCells(DataGriewDados, "CIDADE/UF", "", "", "", ""); row1_2.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold); DataGriewDados.Rows.Add(row1_2); foreach (var LIS_PEDIDOTy in LIS_PEDIDO3Coll_2) { LIS_PEDIDO3Collection LIS_PEDIDO3Coll_4 = new LIS_PEDIDO3Collection(); LIS_PEDIDO3Coll_4 = BuscaPedidoPelaCidade(Convert.ToInt32(LIS_PEDIDOTy.COD_MUN_IBGE)); LIS_MUNICIPIOSCollection LIS_MUNICIPIOSColl = new LIS_MUNICIPIOSCollection(); LIS_MUNICIPIOSProvider LIS_MUNICIPIOSP = new LIS_MUNICIPIOSProvider(); RowRelatorio.Clear(); RowRelatorio.Add(new RowsFiltro("COD_MUN_IBGE", "System.Int32", "=", LIS_PEDIDOTy.COD_MUN_IBGE.ToString())); LIS_MUNICIPIOSColl = LIS_MUNICIPIOSP.ReadCollectionByParameter(RowRelatorio); DataGridViewRow row1_3 = new DataGridViewRow(); row1_3.CreateCells(DataGriewDados, LIS_MUNICIPIOSColl[0].MUNIUF, "", "", "", ""); row1_3.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold); DataGriewDados.Rows.Add(row1_3); DataGridViewRow row1_4 = new DataGridViewRow(); row1_4.CreateCells(DataGriewDados, "CLIENTE", "TELEFONE", "DATA", "NOTA FISCAL", "TOTAL"); row1_4.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold); DataGriewDados.Rows.Add(row1_4); foreach (var LIS_PEDIDOTy_4 in LIS_PEDIDO3Coll_4) { CLIENTEEntity CLIENTEtY = new CLIENTEEntity(); CLIENTEProvider CLIENTEP = new CLIENTEProvider(); CLIENTEtY = CLIENTEP.Read(Convert.ToInt32(LIS_PEDIDOTy_4.IDCLIENTE)); string DataEmissao = Convert.ToDateTime(LIS_PEDIDOTy_4.DTEMISSAO).ToString("dd/MM/yyyy"); string NomeCliente = LIS_PEDIDOTy_4.NOMECLIENTE; string NumPedido = LIS_PEDIDOTy_4.IDPEDIDO.ToString().PadLeft(6, '0');; string TotalPedido = Convert.ToDecimal(LIS_PEDIDOTy_4.TOTALPEDIDO).ToString("n2"); string TELEFONE1 = CLIENTEtY.TELEFONE1; DataGridViewRow row2 = new DataGridViewRow(); row2.CreateCells(DataGriewDados, NomeCliente, TELEFONE1, DataEmissao, NumPedido, TotalPedido); row2.DefaultCellStyle.Font = new Font("Arial", 8); DataGriewDados.Rows.Add(row2); TotalGeral += Convert.ToDecimal(LIS_PEDIDOTy_4.TOTALPEDIDO); } DataGridViewRow row1_5 = new DataGridViewRow(); row1_5.CreateCells(DataGriewDados, "-------------------------------------------------------", "---------", "---------", "---------", "---------"); row1_5.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold); DataGriewDados.Rows.Add(row1_5); } DataGridViewRow rowLinha = new DataGridViewRow(); rowLinha.CreateCells(DataGriewDados, "-------------------------------------------------------", "---------", "---------", "Total geral:", TotalGeral); rowLinha.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold); DataGriewDados.Rows.Add(rowLinha); this.Cursor = Cursors.Default; }