コード例 #1
0
ファイル: Query.cs プロジェクト: LucasW4C/grpdlv
        public DataTable ExecuteSelect()
        {
            try
            {
                if (_connection == null || _connection.State != ConnectionState.Open)
                {
                    throw ErroMessage.Operation(EErrosCode.WithOutConnection);
                }

                MySqlCommand _command = new MySqlCommand();
                _command.Connection = _connection;

                MySqlDataReader dataReader = _command.ExecuteReader();

                if (dataReader != null)
                {
                    DataTable table = new DataTable();
                    table.Load(dataReader);

                    return(table);
                }

                return(null);
            }
            catch (System.Exception ex)
            {
                throw ErroMessage.ProgramException("ExecuteSelect", ex);
            }
        }
コード例 #2
0
ファイル: ModeloNegocio.cs プロジェクト: LucasW4C/grpdlv
        public Modelo SelectModeloById(Int32 id)
        {
            Connection con = null;

            try
            {
                con = new Connection();
                con.OpenConnection();

                using (ModeloDAO modeloDao = new ModeloDAO(con))
                {
                    DataTable table = modeloDao.SelectModelo(id);
                    if (table != null)
                    {
                        return(Modelo.FixDataTable(table).FirstOrDefault());
                    }

                    return(null);
                }
            }
            catch (System.Exception ex)
            {
                throw ErroMessage.ProgramException("SelectModeloById", ex);
            }
            finally
            {
                if (con != null)
                {
                    con.CloseConnection();
                }
            }
        }
コード例 #3
0
ファイル: Query.cs プロジェクト: LucasW4C/grpdlv
        public void Execute()
        {
            try
            {
                if (_connection == null || _connection.State != ConnectionState.Open)
                {
                    throw ErroMessage.Operation(EErrosCode.WithOutConnection);
                }

                MySqlCommand _command = new MySqlCommand();
                _command.Connection = _connection;

                if (_transaction != null)
                {
                    _command.Transaction = _transaction;
                }

                if (_parameters != null && _parameters.Any())
                {
                    foreach (var p in _parameters)
                    {
                        _command.Parameters.AddWithValue(p.Key, p.Value);
                    }
                }

                _command.ExecuteNonQuery();
            }
            catch (System.Exception ex)
            {
                throw ErroMessage.ProgramException("Execute", ex);
            }
        }
コード例 #4
0
        public void InsertModelo(Modelo modelo)
        {
            try
            {
                if (con == null)
                {
                    throw ErroMessage.Operation(EErrosCode.WithOutConnection);
                }

                Query query = new Query(con);
                query.AddQuery($"INSERT INTO {mTabelaModelo} ( ");
                query.AddQuery($"   {mDescricaoModelo}, ");
                query.AddQuery($",   {mInteiro64Modelo} ");
                query.AddQuery($",   {mStatusModelo} ");
                query.AddQuery($",   {mPrecoModelo} ");
                query.AddQuery($" ) VALUES ( ");
                query.AddQuery($"   {pDescricaoModelo} ");
                query.AddQuery($",   {pInteiro64Modelo} ");
                query.AddQuery($",   {pStatusModelo} ");
                query.AddQuery($",   {pPrecoModelo} ");
                query.AddQuery($");");

                query.AddParam(pDescricaoModelo, modelo.DescricaoModelo);
                query.AddParam(pInteiro64Modelo, modelo.Inteiro64Modelo);
                query.AddParam(pStatusModelo, modelo.StatusModelo);
                query.AddParam(pPrecoModelo, modelo.PrecoModelo);

                query.Execute();
            }
            catch (System.Exception ex)
            {
                throw ErroMessage.ProgramException("InsertModelo", ex);
            }
        }
コード例 #5
0
 public void CloseConnection()
 {
     try
     {
         _connection.Close();
         _connection.Dispose();
         _connection = null;
     }
     catch (Exception ex)
     {
         throw ErroMessage.ProgramException("CloseConnection", ex);
     }
 }
コード例 #6
0
        public void RollBack()
        {
            try
            {
                if (_transaction == null)
                {
                    throw ErroMessage.Operation(EErrosCode.WithOutTransaction);
                }

                _transaction.Rollback();
            }
            catch (System.Exception ex)
            {
                throw ErroMessage.ProgramException("RollBack", ex);
            }
        }
コード例 #7
0
        public void Commit()
        {
            try
            {
                if (_transaction == null)
                {
                    throw ErroMessage.Operation(EErrosCode.WithOutTransaction);
                }

                _transaction.Commit();
            }
            catch (System.Exception ex)
            {
                throw ErroMessage.ProgramException("Commit", ex);
            }
        }
コード例 #8
0
        public void BeginTransaction()
        {
            try
            {
                if (_connection == null || _connection.State != ConnectionState.Open)
                {
                    throw ErroMessage.Operation(EErrosCode.WithOutConnection);
                }

                _transaction = _connection.BeginTransaction();
            }
            catch (Exception ex)
            {
                throw ErroMessage.ProgramException("BeginTransaction", ex);
            }
        }
コード例 #9
0
ファイル: ModeloNegocio.cs プロジェクト: LucasW4C/grpdlv
        public void InsertModelo(Modelo modelo)
        {
            Connection con = null;

            try
            {
                con = new Connection();
                con.OpenConnection();
                con.BeginTransaction();

                using (ModeloDAO modeloDao = new ModeloDAO(con))
                {
                    if (modelo.IdModelo > 0)
                    {
                        throw ErroMessage.Operation("O Id do Modelo não pode ser Atribuido a um novo registro!");
                    }
                    if (modelo.PrecoModelo <= 0)
                    {
                        throw ErroMessage.Operation("O Preço do Modelo não pode ser Negativo ou Ígual a 0.00!");
                    }
                    if (String.IsNullOrWhiteSpace(modelo.DescricaoModelo))
                    {
                        throw ErroMessage.Operation("A Descrição do Modelo deve conter um valor!");
                    }

                    modeloDao.InsertModelo(modelo);
                }

                con.Commit();
            }
            catch (System.Exception ex)
            {
                if (con != null)
                {
                    con.RollBack();
                }

                throw ErroMessage.ProgramException("InsertModelo", ex);
            }
            finally
            {
                if (con != null)
                {
                    con.CloseConnection();
                }
            }
        }
コード例 #10
0
        public void OpenConnection()
        {
            try
            {
                if (_connection != null && _connection.State != ConnectionState.Open)
                {
                    throw ErroMessage.Operation(EErrosCode.ConnectionIsOpen);
                }
#warning  CRIAR UM HOST PARA CONECTAR-SE
                _connection = new MySqlConnection("");
                _connection.Open();
            }
            catch (Exception ex)
            {
                throw ErroMessage.ProgramException("OpenConnection", ex);
            }
        }
コード例 #11
0
ファイル: Query.cs プロジェクト: LucasW4C/grpdlv
        public Dictionary <String, Object> AddParam(String key, Object value)
        {
            try
            {
                if (_parameters == null)
                {
                    _parameters = new Dictionary <String, Object>();
                }

                _parameters.Add(key, value);

                return(_parameters);
            }
            catch (System.Exception ex)
            {
                throw ErroMessage.ProgramException("AddParam", ex);
            }
        }
コード例 #12
0
        public DataTable SelectModelo(Int32 id)
        {
            try
            {
                if (con == null)
                {
                    throw ErroMessage.Operation(EErrosCode.WithOutConnection);
                }

                Query query = new Query(con);

                query.AddQuery($"SELECT * FROM {mTabelaModelo} WHERE {mId} = {pId};");

                query.AddParam(pId, id);

                return(query.ExecuteSelect());
            }
            catch (System.Exception ex)
            {
                throw ErroMessage.ProgramException("SelectModelo", ex);
            }
        }