private LIS_CAIXACollection BuscaMovCentroCusto(int IDCENTROCUSTO) { LIS_CAIXACollection LIS_CAIXAColl_4 = new LIS_CAIXACollection(); RowRelatorio.Clear(); string DataInicial = Util.ConverStringDateSearch(msktDataInicial.Text); string DataFinal = Util.ConverStringDateSearch(msktDataFinal.Text); RowRelatorio.Add(new RowsFiltro("IDCENTROCUSTOS", "System.Int32", "=", IDCENTROCUSTO.ToString())); if (Convert.ToInt32(cbTipo.SelectedValue) > 0) { RowRelatorio.Add(new RowsFiltro("IDTIPODUPLICATA", "System.Int32", "=", Convert.ToInt32(cbTipo.SelectedValue).ToString())); } RowRelatorio.Add(new RowsFiltro("DATAMOV", "System.DateTime", ">=", DataInicial)); RowRelatorio.Add(new RowsFiltro("DATAMOV", "System.DateTime", "<=", DataFinal)); LIS_CAIXAColl_4 = LIS_CAIXAP.ReadCollectionByParameter(RowRelatorio, "NOMETIPODUPLICATA"); return(LIS_CAIXAColl_4); }
private static LIS_CAIXACollection ExecuteReader(ref LIS_CAIXACollection collection, ref FbDataReader dataReader, FbCommand dbCommand) { using (dataReader = dbCommand.ExecuteReader()) { collection = new LIS_CAIXACollection(); if (dataReader.HasRows) { while (dataReader.Read()) { collection.Add(FillEntityObject(ref dataReader)); } } if (!(dataReader.IsClosed)) { dataReader.Close(); } dataReader.Dispose(); } return(collection); }
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(cbCentroCustos.SelectedValue) > 0) { RowRelatorio.Add(new RowsFiltro("IDCENTROCUSTOS", "System.Int32", "=", Convert.ToInt32(cbCentroCustos.SelectedValue).ToString())); } if (Convert.ToInt32(cbTipo.SelectedValue) > 0) { RowRelatorio.Add(new RowsFiltro("IDTIPODUPLICATA", "System.Int32", "=", Convert.ToInt32(cbTipo.SelectedValue).ToString())); } RowRelatorio.Add(new RowsFiltro("DATAMOV", "System.DateTime", ">=", DataInicial)); RowRelatorio.Add(new RowsFiltro("DATAMOV", "System.DateTime", "<=", DataFinal)); LIS_CAIXAColl = LIS_CAIXAP.ReadCollectionByParameter(RowRelatorio, "DATAMOV"); PreencheGrid(); } catch (Exception EX) { MessageBox.Show("Erro na pesquisa!"); MessageBox.Show("Erro técnico: " + EX.Message); } } }
private void PreencheGrid() { SubTotalCredito = 0; SubTotalDebito = 0; TotalGeralCredito = 0; TotalGeralDebito = 0; CreaterCursor Cr = new CreaterCursor(); this.Cursor = Cr.CreateCursor(Cr.btmap, 0, 0); DataGriewDados.Rows.Clear(); //Remove os centros de custos Repetidos LIS_CAIXACollection LIS_CAIXAColl2 = new LIS_CAIXACollection(); foreach (LIS_CAIXAEntity item in LIS_CAIXAColl) { if (LIS_CAIXAColl2.Find(delegate(LIS_CAIXAEntity item2) { return(item2.IDCENTROCUSTOS == item.IDCENTROCUSTOS); }) == null) { LIS_CAIXAColl2.Add(item); } } //Cabeçalho Centro de Custo DataGridViewRow row1 = new DataGridViewRow(); row1.CreateCells(DataGriewDados, "Centro de Custos", "Crédito", "Débito"); row1.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold); DataGriewDados.Rows.Add(row1); foreach (var LIS_CAIXATy in LIS_CAIXAColl2) { SubTotalCredito = 0; //Busca Movimentaça por centro de custo LIS_CAIXACollection LIS_CAIXAColl3 = new LIS_CAIXACollection(); LIS_CAIXAColl3 = BuscaMovCentroCusto(Convert.ToInt32(LIS_CAIXATy.IDCENTROCUSTOS)); DataGridViewRow row2 = new DataGridViewRow(); row2.CreateCells(DataGriewDados, LIS_CAIXATy.CENTROCUSTO, "", ""); row2.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold); DataGriewDados.Rows.Add(row2); foreach (var LIS_CAIXATy2 in LIS_CAIXAColl3) { DataGridViewRow row3 = new DataGridViewRow(); if (LIS_CAIXATy2.IDTIPOMOVCAIXA == 1) //Credito { row3.CreateCells(DataGriewDados, LIS_CAIXATy2.NOMETIPODUPLICATA, Convert.ToDecimal(LIS_CAIXATy2.VALOR).ToString("n2"), "0,00"); } else { row3.CreateCells(DataGriewDados, LIS_CAIXATy2.NOMETIPODUPLICATA, "0,00", Convert.ToDecimal(LIS_CAIXATy2.VALOR).ToString("n2")); } row3.DefaultCellStyle.Font = new Font("Arial", 8); DataGriewDados.Rows.Add(row3); if (LIS_CAIXATy2.IDTIPOMOVCAIXA == 1) //Credito { SubTotalCredito += Convert.ToDecimal(LIS_CAIXATy2.VALOR); TotalGeralCredito += Convert.ToDecimal(LIS_CAIXATy2.VALOR); } else { SubTotalDebito += Convert.ToDecimal(LIS_CAIXATy2.VALOR); TotalGeralDebito += Convert.ToDecimal(LIS_CAIXATy2.VALOR); } } //Subtotal do Centro de Custo DataGridViewRow row4 = new DataGridViewRow(); row4.CreateCells(DataGriewDados, "SubTotal: ", SubTotalCredito.ToString("n2"), SubTotalDebito.ToString("n2")); row4.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold); DataGriewDados.Rows.Add(row4); //Subtotal do Centro de Custo DataGridViewRow row4_1 = new DataGridViewRow(); row4_1.CreateCells(DataGriewDados, "=========================", "=============", "============="); row4_1.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold); DataGriewDados.Rows.Add(row4_1); } DataGridViewRow rowLinha = new DataGridViewRow(); rowLinha.CreateCells(DataGriewDados, "Total Geral: ", TotalGeralCredito.ToString("n2"), TotalGeralDebito.ToString("n2")); rowLinha.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold); DataGriewDados.Rows.Add(rowLinha); DataGridViewRow rowLinha_1 = new DataGridViewRow(); rowLinha_1.CreateCells(DataGriewDados, "=========================", "=============", "============="); rowLinha_1.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold); DataGriewDados.Rows.Add(rowLinha_1); DataGridViewRow rowLinha2 = new DataGridViewRow(); rowLinha2.CreateCells(DataGriewDados, "Saldo: ", (TotalGeralCredito - TotalGeralDebito).ToString("n2"), ""); rowLinha2.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold); DataGriewDados.Rows.Add(rowLinha2); this.Cursor = Cursors.Default; }
public LIS_CAIXACollection ReadCollectionByParameter(List <RowsFiltro> RowsFiltro, string FieldOrder) { FbDataReader dataReader = null; string strSqlCommand = String.Empty; LIS_CAIXACollection collection = null; try { if (RowsFiltro != null) { if (RowsFiltro.Count > 0) { strSqlCommand = "SELECT * FROM LIS_CAIXA 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_CAIXA order by " + FieldOrder; } } else { strSqlCommand = "SELECT * FROM LIS_CAIXA 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_CAIXACollection ReadCollection() { FbDataReader dataReader = null; try { LIS_CAIXACollection 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_CAIXA", 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_CAIXA", 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; } }