private string BuscaAgenda(string hora, string nomefuncionario) { string result = string.Empty; try { LIS_AGENDACollection LIS_AGENDAColl3 = new LIS_AGENDACollection(); string DataAtual = Convert.ToDateTime(dateTimePicker1.Text).ToString("dd/MM/yyyy"); string Date = Util.ConverStringDateSearch(DataAtual); RowRelatorio.Clear(); RowRelatorio.Add(new RowsFiltro("DATA", "System.DateTime", "=", Date.ToString())); RowRelatorio.Add(new RowsFiltro("HORA", "System.String", "=", hora)); RowRelatorio.Add(new RowsFiltro("NOMEFUNCIONARIO", "System.String", "=", nomefuncionario)); LIS_AGENDAColl3.Clear(); LIS_AGENDAColl3 = LIS_AGENDAP.ReadCollectionByParameter(RowRelatorio, "NOMEFUNCIONARIO, HORA"); if (LIS_AGENDAColl3.Count > 0) { CLIENTEProvider CLIENTEP = new CLIENTEProvider(); CLIENTEEntity CLIENTETy = new CLIENTEEntity(); CLIENTETy = CLIENTEP.Read(Convert.ToInt32(LIS_AGENDAColl3[0].IDCLIENTE)); if (CLIENTETy != null) { if (CLIENTETy.TELEFONE1.Trim() != string.Empty && CLIENTETy.TELEFONE2.Trim() != string.Empty) { result = CLIENTETy.NOME + "Telefone(s): " + CLIENTETy.TELEFONE1 + " / " + CLIENTETy.TELEFONE2 + " - C:" + LIS_AGENDAColl3[0].IDAGENDA; } else { result = CLIENTETy.NOME + " C:" + LIS_AGENDAColl3[0].IDAGENDA; } } } return(result); } catch (Exception ex) { return(result); MessageBox.Show("Erro técnico: " + ex.Message); } }
private void FiltraAgendaDia(int Dias) { try { DateTime Datual = Convert.ToDateTime(dateTimePicker1.Text).AddDays(Dias); dateTimePicker1.Text = Datual.ToLongDateString(); string Date = Util.ConverStringDateSearch(Datual.ToString("dd/MM/yyyy")); RowRelatorio.Clear(); RowRelatorio.Add(new RowsFiltro("DATA", "System.DateTime", "=", Date.ToString())); LIS_AGENDAColl1 = LIS_AGENDAP.ReadCollectionByParameter(RowRelatorio, "NOMEFUNCIONARIO, HORA"); PreencheGrid(); } catch (Exception ex) { MessageBox.Show("Erro técnico: " + ex.Message); } }
private static LIS_AGENDACollection ExecuteReader(ref LIS_AGENDACollection collection, ref FbDataReader dataReader, FbCommand dbCommand) { using (dataReader = dbCommand.ExecuteReader()) { collection = new LIS_AGENDACollection(); if (dataReader.HasRows) { while (dataReader.Read()) { collection.Add(FillEntityObject(ref dataReader)); } } if (!(dataReader.IsClosed)) { dataReader.Close(); } dataReader.Dispose(); } return(collection); }
public LIS_AGENDACollection ReadCollectionByParameter(List <RowsFiltro> RowsFiltro, string FieldOrder) { FbDataReader dataReader = null; string strSqlCommand = String.Empty; LIS_AGENDACollection collection = null; try { if (RowsFiltro != null) { if (RowsFiltro.Count > 0) { strSqlCommand = "SELECT * FROM LIS_AGENDA 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_AGENDA order by " + FieldOrder; } } else { strSqlCommand = "SELECT * FROM LIS_AGENDA 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_AGENDACollection ReadCollection() { FbDataReader dataReader = null; try { LIS_AGENDACollection 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_AGENDA", 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_AGENDA", 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; } }