コード例 #1
0
        public static DataTable GetConsultaSQL(string cSql)
        {
            IDataReader   dr         = null;
            DataTable     dt         = null;
            IDbConnection connection = null;

            try
            {
                connection = DAOStarter.GetConexao();
                var cmd = connection.CreateCommand();
                cmd.CommandText = cSql;

                dr = cmd.ExecuteReader();
                dt = new DataTable();
                dt.Load(dr);
            }
            catch (Exception e)
            {
                LogErros.GravaLog(e, MethodBase.GetCurrentMethod().Name);
            }
            finally
            {
                if (dr != null && !dr.IsClosed)
                {
                    dr.Close();
                }
                if (connection != null && connection.State != ConnectionState.Closed)
                {
                    connection.Close();
                }
            }

            return(dt);
        }
コード例 #2
0
        public static bool ExecutaSQL(string sql)
        {
            bool success    = true;
            var  connection = DAOStarter.GetConexao();

            try
            {
                var cmd = connection.CreateCommand();
                cmd.CommandText = sql;
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                success = false;
                LogErros.GravaLog(e, MethodBase.GetCurrentMethod().Name);
            }
            finally
            {
                if (connection != null && connection.State != ConnectionState.Closed)
                {
                    connection.Close();
                }
            }

            return(success);
        }
コード例 #3
0
        internal static int SqlCount(string sql)
        {
            int           total      = 0;
            IDbConnection connection = null;

            try
            {
                connection = DAOStarter.GetConexao();
                var command = connection.CreateCommand();
                command.CommandText = sql;
                try
                {
                    var dr = command.ExecuteReader();

                    try
                    {
                        while (dr.Read())
                        {
                            total = Convert.ToInt32(dr["total"]);
                        }
                    }
                    catch (Exception e)
                    {
                        LogErros.GravaLog(e, "MetodosAuxiliares/SqlCount");
                    }
                    finally
                    {
                        if (!dr.IsClosed)
                        {
                            dr.Close();
                        }
                    }
                }
                catch (Exception e)
                {
                    LogErros.GravaLog(e, "MetodosAuxiliares/SqlCount");
                }
                finally
                {
                    if (connection != null && connection.State != ConnectionState.Closed)
                    {
                        connection.Close();
                    }
                }
            }
            catch (Exception e)
            {
                LogErros.GravaLog(e, "MetodosAuxiliares/SqlCount");
            }
            return(total);
        }
コード例 #4
0
        private void GravaLogObsolete(Empresa empresa)
        {
            StackTrace stackTrace = new StackTrace();

            StackFrame[] stackFrames = stackTrace.GetFrames();
            string       caminho     = "";

            foreach (var item in stackFrames)
            {
                caminho += item.GetMethod().Name + " -> ";
            }
            LogErros.GravaLog(null, "ClasseModeloEstabelecimento/GravaLogObsolete", 0, false, caminho);

            throw new Exception("O campo estabelecimento não foi alimentado");
        }
コード例 #5
0
        public static Usuario UsuarioLogado(ICustomPrincipal user)
        {
            Usuario usuario = null;

            try
            {
                ClasseModeloDAO <Usuario> daoUsuario = ClasseModeloDAO <Usuario> .Create(user);

                usuario = daoUsuario.FindByPrimaryKey(user.IdUsuario);
                daoUsuario.Dispose();
            }
            catch (Exception e)
            {
                LogErros.GravaLog(e, MethodBase.GetCurrentMethod().Name);
            }

            return(usuario);
        }
コード例 #6
0
        public static List <object> GetObjectsFromDataTable(DataTable table, Type tipo)
        {
            List <object> lsObjects = new List <object>();

            PropertyInfo prop;

            try
            {
                foreach (DataRow row in table.Rows)
                {
                    object obj = Activator.CreateInstance(tipo);

                    foreach (DataColumn column in table.Columns)
                    {
                        prop = tipo.GetProperty(column.ColumnName);

                        //se o tipo for uma classe, não pode adicionar porque foi retornado somente o Id na consulta
                        if (!prop.PropertyType.IsClass)
                        {
                            //se a propriedade não é nula e retornou valor do banco
                            if (prop != null && row[column].GetType().Name != "DBNull")
                            {
                                if (row[column].GetType().Name == "Double" && prop.PropertyType == typeof(decimal?))
                                {
                                    prop.SetValue(obj, Convert.ToDecimal(row[column]));
                                }
                                else
                                {
                                    prop.SetValue(obj, row[column]);
                                }
                            }
                        }
                    }

                    lsObjects.Add(obj);
                }
            }
            catch (Exception e)
            {
                LogErros.GravaLog(e, MethodBase.GetCurrentMethod().Name);
            }

            return(lsObjects);
        }
コード例 #7
0
        public static bool ValidaCnpj(string cnpj)
        {
            bool valid = false;

            int[] multiplicador1 = new int[12] {
                5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2
            };
            int[] multiplicador2 = new int[13] {
                6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2
            };
            int    soma;
            int    resto;
            string digito;
            string tempCnpj;

            cnpj = cnpj.Trim();
            cnpj = cnpj.Replace(".", "").Replace("-", "").Replace("/", "");
            if (cnpj.Length != 14)
            {
                return(false);
            }

            try
            {
                tempCnpj = cnpj.Substring(0, 12);
                soma     = 0;
                for (int i = 0; i < 12; i++)
                {
                    soma += int.Parse(tempCnpj[i].ToString()) * multiplicador1[i];
                }
                resto = (soma % 11);
                if (resto < 2)
                {
                    resto = 0;
                }
                else
                {
                    resto = 11 - resto;
                }
                digito   = resto.ToString();
                tempCnpj = tempCnpj + digito;
                soma     = 0;
                for (int i = 0; i < 13; i++)
                {
                    soma += int.Parse(tempCnpj[i].ToString()) * multiplicador2[i];
                }
                resto = (soma % 11);
                if (resto < 2)
                {
                    resto = 0;
                }
                else
                {
                    resto = 11 - resto;
                }

                digito = digito + resto.ToString();

                valid = cnpj.EndsWith(digito);
            }
            catch (Exception e)
            {
                LogErros.GravaLog(e, "MetodosAuxiliares/" + MethodBase.GetCurrentMethod().Name);
            }

            return(valid);
        }