public static bool ValidAmostra(Amostra amostra)
 {
     if (String.IsNullOrEmpty(amostra.Complemento))
     {
         return(false);
     }
     if (String.IsNullOrEmpty(amostra.GeoReferencia))
     {
         return(false);
     }
     if (amostra.IdCliente <= 0)
     {
         return(false);
     }
     if (amostra.IdSolicitante <= 0)
     {
         return(false);
     }
     if (String.IsNullOrEmpty(amostra.Status))
     {
         return(false);
     }
     if (String.IsNullOrEmpty(amostra.TipoAnalise))
     {
         return(false);
     }
     return(true);
 }
        public override string Edit(Object obj)
        {
            factory    = DbProviderFactories.GetFactory(provider);
            connection = factory.CreateConnection();
            connection.ConnectionString = connectionString;
            Amostra amostra = (Amostra)obj;
            var     sql     = @"UPDATE  Amostra Set Status = @param1 Where id = @id";

            using (DbConnection conn = connection)
            {
                conn.Open();
                using (var tran = conn.BeginTransaction())
                {
                    using (DbCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = sql;
                        cmd.CommandType = CommandType.Text;
                        try
                        {
                            cmd.Transaction = tran;
                            var parameter = cmd.CreateParameter();
                            parameter.ParameterName = "@id";
                            parameter.Value         = amostra.Id;
                            cmd.Parameters.Add(parameter);
                            parameter = cmd.CreateParameter();
                            parameter.ParameterName = "@param1";
                            parameter.Value         = amostra.Status;
                            cmd.Parameters.Add(parameter);
                            cmd.ExecuteNonQuery();
                            tran.Commit();
                            return(Messages.SuccesssDB);
                        }
                        catch (DbException ex)
                        {
                            tran.Rollback();
                            return(Messages.ErrorDB(ex));
                        }
                        finally
                        {
                            cmd.Dispose();
                            if (conn.State.Equals("Open"))
                            {
                                conn.Close();
                            }
                        }
                    }
                }
            }
        }
        public override string Insert(Object obj)
        {
            factory    = DbProviderFactories.GetFactory(provider);
            connection = factory.CreateConnection();
            connection.ConnectionString = connectionString;
            Amostra amostra = (Amostra)obj;
            var     sql     = @"INSERT INTO Amostra(tipoAnalise,geoReferencia,complemento,idCliente,idSolicitante,status) VALUES(@param1, @param2, @param3, @param4, @param5,@param6)";

            using (DbConnection conn = connection)
            {
                conn.Open();
                using (var tran = conn.BeginTransaction())
                {
                    using (DbCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = sql;
                        cmd.CommandType = CommandType.Text;
                        try
                        {
                            cmd.Transaction = tran;
                            var parameter = cmd.CreateParameter();
                            parameter.ParameterName = "@param1";
                            parameter.Value         = amostra.TipoAnalise;
                            cmd.Parameters.Add(parameter);
                            parameter = cmd.CreateParameter();
                            parameter.ParameterName = "@param2";
                            parameter.Value         = amostra.GeoReferencia;
                            cmd.Parameters.Add(parameter);
                            parameter = cmd.CreateParameter();
                            parameter.ParameterName = "@param3";
                            parameter.Value         = amostra.Complemento;
                            cmd.Parameters.Add(parameter);
                            parameter = cmd.CreateParameter();
                            parameter.ParameterName = "@param4";
                            parameter.Value         = amostra.IdCliente;
                            cmd.Parameters.Add(parameter);
                            parameter = cmd.CreateParameter();
                            parameter.ParameterName = "@param5";
                            parameter.Value         = amostra.IdSolicitante;
                            cmd.Parameters.Add(parameter);
                            parameter = cmd.CreateParameter();
                            parameter.ParameterName = "@param6";
                            parameter.Value         = amostra.Status;
                            cmd.Parameters.Add(parameter);
                            cmd.ExecuteNonQuery();
                            tran.Commit();
                            return(Messages.SuccesssDB);
                        }
                        catch (DbException ex)
                        {
                            tran.Rollback();
                            return(Messages.ErrorDB(ex));
                        }
                        finally
                        {
                            cmd.Dispose();
                            if (conn.State.Equals("Open"))
                            {
                                conn.Close();
                            }
                        }
                    }
                }
            }
        }