private Boolean VerificaPlanos() { Boolean result = true; try { if (BmsSoftware.ConfigSistema1.Default.FlagPlanos.Trim() == "S") { USUARIOCollection USUARIOColl_Total = new USUARIOCollection(); USUARIOColl_Total = USUARIOP.ReadCollectionByParameter(null); RECURSOSPLANOProvider RECURSOSPLANOP = new RECURSOSPLANOProvider(); PLANOSProvider PLANOSP = new PLANOSProvider(); RECURSOSPLANOEntity RECURSOSPLANOTy = new RECURSOSPLANOEntity(); RECURSOSPLANOTy = RECURSOSPLANOP.Read(Convert.ToInt32(BmsSoftware.ConfigSistema1.Default.IdPlanos)); if (RECURSOSPLANOTy != null) { int QuantUsuarios = Convert.ToInt32(RECURSOSPLANOTy.USUARIOS); if (USUARIOColl_Total.Count < QuantUsuarios) { result = true; } else { MessageBox.Show("Limite de usuários atingido pelo plano: " + PLANOSP.Read(Convert.ToInt32(RECURSOSPLANOTy.IDPLANO)).NOME, ConfigSistema1.Default.NomeEmpresa, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); result = false; } } } return(result); } catch (Exception ex) { MessageBox.Show("Erro técnico: " + ex.Message); return(result); } }
private static RECURSOSPLANOEntity FillEntityObject(ref FbDataReader DataReader) { RECURSOSPLANOEntity entity = new RECURSOSPLANOEntity(); FirebirdGetDbData getData = new FirebirdGetDbData(); entity.IDRECURSOSPLANO = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("IDRECURSOSPLANO")); entity.IDPLANO = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDPLANO")); entity.CLIENTES = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("CLIENTES")); entity.PRODUTOS = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("PRODUTOS")); entity.NOTAFISCAL = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("NOTAFISCAL")); entity.USUARIOS = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("USUARIOS")); entity.BOLETOBANCARIOS = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("BOLETOBANCARIOS")); entity.SPEDSINTEGRA = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("SPEDSINTEGRA")); entity.ORDEMSERVICO = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("ORDEMSERVICO")); entity.PEDIDO = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("PEDIDO")); return(entity); }
public RECURSOSPLANOEntity Read(int IDRECURSOSPLANO) { FbDataReader reader = null; try { //Verificando a existência de um transação aberta if (dbTransaction != null) { if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Rea_RECURSOSPLANO", dbCnn); dbCommand.Transaction = ((FbTransaction)(dbTransaction)); } else { if (dbCnn == null) { dbCnn = ((FbConnection)GetConnectionDB()); } if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Rea_RECURSOSPLANO", dbCnn); dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted); } dbCommand.CommandType = CommandType.StoredProcedure; dbCommand.Parameters.AddWithValue("@IDRECURSOSPLANO", IDRECURSOSPLANO); //PrimaryKey reader = dbCommand.ExecuteReader(); RECURSOSPLANOEntity entity = null; if (reader.HasRows) { while (reader.Read()) { entity = FillEntityObject(ref reader); } } // Deleta reader if (reader != null) { reader.Close(); reader.Dispose(); } // Fecha conexão if (dbTransaction == null) { dbCommand.Transaction.Commit(); if (dbCnn.State == ConnectionState.Open) { dbCnn.Close(); } } return(entity); } catch (Exception ex) { // Deleta reader if (reader != null) { reader.Close(); reader.Dispose(); } if (dbTransaction != null) { this.RollbackTransaction(); } else { if (dbCommand.Transaction != null) { dbCommand.Transaction.Rollback(); } if (dbCnn.State == ConnectionState.Open) { dbCnn.Close(); } } throw ex; } }
public int Save(RECURSOSPLANOEntity Entity) { int result = 0; try { //Verificando a existência de um transação aberta if (dbTransaction != null) { if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Sav_RECURSOSPLANO", dbCnn); dbCommand.Transaction = ((FbTransaction)(dbTransaction)); } else { if (dbCnn == null) { dbCnn = ((FbConnection)GetConnectionDB()); } if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Sav_RECURSOSPLANO", dbCnn); dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted); } dbCommand.CommandType = CommandType.StoredProcedure; if (Entity.IDRECURSOSPLANO != -1) { dbCommand.Parameters.AddWithValue("@IDRECURSOSPLANO", Entity.IDRECURSOSPLANO); //PrimaryKey } else { dbCommand.Parameters.AddWithValue("@IDRECURSOSPLANO", DBNull.Value); //PrimaryKey } if (Entity.IDPLANO != null) { dbCommand.Parameters.AddWithValue("@IDPLANO", Entity.IDPLANO); //ForeignKey } else { dbCommand.Parameters.AddWithValue("@IDPLANO", DBNull.Value); //ForeignKey 5 } dbCommand.Parameters.AddWithValue("@CLIENTES", Entity.CLIENTES); //Coluna dbCommand.Parameters.AddWithValue("@PRODUTOS", Entity.PRODUTOS); //Coluna dbCommand.Parameters.AddWithValue("@NOTAFISCAL", Entity.NOTAFISCAL); //Coluna dbCommand.Parameters.AddWithValue("@USUARIOS", Entity.USUARIOS); //Coluna dbCommand.Parameters.AddWithValue("@BOLETOBANCARIOS", Entity.BOLETOBANCARIOS); //Coluna dbCommand.Parameters.AddWithValue("@SPEDSINTEGRA", Entity.SPEDSINTEGRA); //Coluna dbCommand.Parameters.AddWithValue("@ORDEMSERVICO", Entity.ORDEMSERVICO); //Coluna //Retorno da Procedure FbParameter returnValue; returnValue = dbCommand.CreateParameter(); dbCommand.Parameters["@IDRECURSOSPLANO"].Direction = ParameterDirection.InputOutput; //Executando consulta dbCommand.ExecuteNonQuery(); result = int.Parse(dbCommand.Parameters["@IDRECURSOSPLANO"].Value.ToString()); if (dbTransaction == null) { dbCommand.Transaction.Commit(); dbCnn.Close(); } } catch (Exception ex) { if (dbTransaction != null) { this.RollbackTransaction(); } else { if (dbCommand.Transaction != null) { dbCommand.Transaction.Rollback(); } if (dbCnn.State == ConnectionState.Open) { dbCnn.Close(); } } throw ex; } return(result); }