예제 #1
0
        public T Get <T>(long?TakerId = 0)
        {
            try
            {
                SQL = new StringBuilder();
                SQL.AppendLine(" Select ");
                SQL.AppendLine("    TakerId, ");
                SQL.AppendLine("    CompanyId, ");
                SQL.AppendLine("    IM, ");
                SQL.AppendLine("    CPF_CNPJ, ");
                SQL.AppendLine("    RG_IE, ");
                SQL.AppendLine("    Name, ");
                SQL.AppendLine("    NameFantasy, ");
                SQL.AppendLine("    TypePerson, ");
                SQL.AppendLine("    CEP, ");
                SQL.AppendLine("    Street, ");
                SQL.AppendLine("    Number, ");
                SQL.AppendLine("    Neighborhood, ");
                SQL.AppendLine("    City, ");
                SQL.AppendLine("    State, ");
                SQL.AppendLine("    Telephone, ");
                SQL.AppendLine("    Email, ");
                SQL.AppendLine("    Active, ");
                SQL.AppendLine("    DateInsert, ");
                SQL.AppendLine("    DateUpdate ");
                SQL.AppendLine(" From Takers ");
                SQL.AppendLine(" Where Active = 1 ");
                SQL.AppendLine(" And CompanyId = " + SessionDomain.GetCompanySession().CompanyId);
                if (TakerId > 0)
                {
                    SQL.AppendLine(" And TakerId = " + TakerId);
                }

                DataTable data = Functions.Conn.GetDataTable(SQL.ToString(), "Takers");
                if (data != null && data.Rows.Count > 0)
                {
                    if (typeof(T) == typeof(List <Takers>))
                    {
                        List <Takers> lTakers = new List <Takers>();
                        foreach (DataRow row in data.Rows)
                        {
                            lTakers.Add(Fill(row));
                        }
                        return((T)Convert.ChangeType(lTakers, typeof(T)));
                    }
                    else if (typeof(T) == typeof(Takers))
                    {
                        return((T)Convert.ChangeType(Fill(data.AsEnumerable().First()), typeof(T)));
                    }
                }
                throw new InternalProgramException("Não foram encontrados registros!");
            }catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
        public T Get <T>(long Id = 0)
        {
            try
            {
                SQL = new StringBuilder();

                SQL.AppendLine(" Select ");
                SQL.AppendLine(" 	NumeroNota As 'NumberNF', ");
                SQL.AppendLine(" 	ChaveValidacao As 'KeyValidation', ");
                SQL.AppendLine(" 	ValorTotalNota As 'Total', ");
                SQL.AppendLine(" 	ISSQNTotal As 'TotalISS', ");
                SQL.AppendLine(" 	ClienteNomeRazaoSocial As 'Name', ");
                SQL.AppendLine(" 	ClienteNomeFantasia As 'NameFantasy', ");
                SQL.AppendLine(" 	ClienteCNPJCPF As 'CPF_CNPJ', ");
                SQL.AppendLine(" 	ClienteInscricaoEstadual As 'IE', ");
                SQL.AppendLine(" 	ClienteInscricaoMunicipal As 'IM', ");
                SQL.AppendLine(" 	DataEmissao As 'DateEmission', ");
                SQL.AppendLine(" 	Observacao As 'Note', ");
                SQL.AppendLine(" 	NotaFiscalPDF As 'PDF', ");
                SQL.AppendLine(" 	URL as 'URL', ");
                SQL.AppendLine(" 	URLAutenticidade As 'URLAuthenticity' ");
                SQL.AppendLine(" From NFeS ");
                SQL.AppendLine(" Where Active = 1 ");
                SQL.AppendLine(" And CompanyId = " + SessionDomain.GetCompanySession().CompanyId);
                if (Id > 0)
                {
                    SQL.AppendLine(" And NFeSId = " + Id);
                }

                DataTable data = Functions.Conn.GetDataTable(SQL.ToString(), "NFeS");

                if (data != null && data.Rows.Count > 0)
                {
                    if (typeof(T) == typeof(List <NFeSRequestQuery>))
                    {
                        List <NFeSRequestQuery> lRequestQuery = new List <NFeSRequestQuery>();
                        foreach (DataRow row in data.Rows)
                        {
                            lRequestQuery.Add(Fill(row));
                        }
                        return((T)Convert.ChangeType(lRequestQuery, typeof(T)));
                    }
                    else if (typeof(T) == typeof(NFeSRequestQuery))
                    {
                        return((T)Convert.ChangeType(Fill(data.AsEnumerable().First()), typeof(T)));
                    }
                }
                throw new InternalProgramException("Não foram encontrados registros!");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #3
0
        public T Get <T>(long?ServicesId)
        {
            try
            {
                SQL = new StringBuilder();
                SQL.AppendLine(" Select ");
                SQL.AppendLine("    ServicesId, ");
                SQL.AppendLine("    CompanyId, ");
                SQL.AppendLine("    Unity, ");
                SQL.AppendLine("    Value, ");
                SQL.AppendLine("    Description, ");
                SQL.AppendLine("    IRRF, ");
                SQL.AppendLine("    PIS, ");
                SQL.AppendLine("    CSLL, ");
                SQL.AppendLine("    INSS, ");
                SQL.AppendLine("    COFINS, ");
                SQL.AppendLine("    Active, ");
                SQL.AppendLine("    DateInsert, ");
                SQL.AppendLine("    DateUpdate ");
                SQL.AppendLine(" From Services ");
                SQL.AppendLine(" Where Active = 1 ");
                SQL.AppendLine(" And CompanyId = " + SessionDomain.GetCompanySession().CompanyId);
                if (ServicesId > 0)
                {
                    SQL.AppendLine(" And ServicesId = " + ServicesId);
                }

                DataTable data = Functions.Conn.GetDataTable(SQL.ToString(), "Services");
                if (data != null && data.Rows.Count > 0)
                {
                    if (typeof(T) == typeof(List <Services>))
                    {
                        List <Services> lServices = new List <Services>();
                        foreach (DataRow row in data.Rows)
                        {
                            lServices.Add(Fill(row));
                        }
                        return((T)Convert.ChangeType(lServices, typeof(T)));
                    }
                    else if (typeof(T) == typeof(Services))
                    {
                        return((T)Convert.ChangeType(Fill(data.AsEnumerable().First()), typeof(T)));
                    }
                }
                throw new InternalProgramException("Não foram encontrados registros!");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #4
0
        public Users Login(string Email, string Password)
        {
            try
            {
                if (string.IsNullOrEmpty(Email) || string.IsNullOrEmpty(Password))
                {
                    throw new InternalProgramException("Email ou senha não informado!");
                }

                SQL = new StringBuilder();
                SQL.AppendLine(" Select * From Users ");
                SQL.AppendLine(" Where Active = 1 ");
                SQL.AppendLine(" And Email Like '" + Functions.NoQuote(Email) + "'");
                SQL.AppendLine(" And Password Like '" + Functions.Encript(Functions.NoQuote(Password)) + "'");

                DataTable data = Functions.Conn.GetDataTable(SQL.ToString(), "Users");
                if (data != null && data.Rows.Count > 0)
                {
                    DataRow  row     = data.AsEnumerable().First();
                    Sessions session = SessionDomain.NewSession(row.Field <long>("UserId"));
                    if (session.SessionId > 0)
                    {
                        Users users = new Users();
                        users.UserId      = row.Field <long>("UserId");
                        users.Name        = row.Field <string>("Name");
                        users.LastName    = row.Field <string>("LastName");
                        users.CPF         = row.Field <string>("CPF");
                        users.Email       = row.Field <string>("Email");
                        users.Password    = Functions.Desencript(row.Field <string>("Password"));
                        users.SessionHash = session.SessionHash;
                        users.Active      = row.Field <bool>("Active");
                        users.DateInsert  = row.Field <DateTime>("DateInsert").ToString("dd-MM-yyyy");
                        users.DateUpdate  = row.Field <DateTime>("DateUpdate").ToString("dd-MM-yyyy");
                        return(users);
                    }
                    throw new InternalProgramException("Não foi possivel gerar uma sessão para o usuário!");
                }

                throw new InternalProgramException("Email ou senha inválidos!");
            }catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #5
0
        public Users Post(Users users)
        {
            try
            {
                Validate(users);

                SQL = new StringBuilder();
                SQL.AppendLine(" Insert Into Users ");
                SQL.AppendLine("   (Name, ");
                SQL.AppendLine("    LastName, ");
                SQL.AppendLine("    CPF, ");
                SQL.AppendLine("    Email, ");
                SQL.AppendLine("    Password, ");
                SQL.AppendLine("    Active, ");
                SQL.AppendLine("    DateInsert, ");
                SQL.AppendLine("    DateUpdate) ");
                SQL.AppendLine(" Values( ");
                SQL.AppendLine("    '" + Functions.NoQuote(users.Name) + "',");
                SQL.AppendLine("    '" + Functions.NoQuote(users.LastName) + "',");
                SQL.AppendLine("    '" + Functions.RemoveCharSpecial(Functions.NoQuote(users.CPF)) + "',");
                SQL.AppendLine("    '" + Functions.NoQuote(users.Email) + "',");
                SQL.AppendLine("    '" + Functions.Encript(Functions.NoQuote(users.Password)) + "',");
                SQL.AppendLine("    1,");
                SQL.AppendLine("    GetDate(),");
                SQL.AppendLine("    GetDate() ");
                SQL.AppendLine(" ) ");

                users.UserId = Functions.Conn.Insert(SQL.ToString());
                Sessions session = SessionDomain.NewSession(users.UserId);
                if (users.UserId > 0 && session.SessionId > 0)
                {
                    users.SessionHash = session.SessionHash;
                    users.Active      = true;
                    users.DateInsert  = DateTime.Now.ToString("yyyy-MM-dd");
                    users.DateUpdate  = DateTime.Now.ToString("yyyy-MM-dd");
                    return(users);
                }
                throw new InternalProgramException("Houve um problema ao cadastrar o usuário.");
            }catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #6
0
        public static Sessions NewSession(long UserId)
        {
            try
            {
                if (UserId <= 0)
                {
                    throw new InternalProgramException("Usuario não encontrado!");
                }

                Users users = new UsersDomain().Get(UserId);
                if (users.UserId <= 0)
                {
                    throw new InternalProgramException("Usuario não cadastrado na base de dados!");
                }

                DataTable data;

                SQL = new StringBuilder();
                SQL.AppendLine(" Select Top 1 ");
                SQL.AppendLine("    SessionId ");
                SQL.AppendLine(" From Session ");
                SQL.AppendLine(" Where Active = 1 ");
                SQL.AppendLine(" And DateDiff(MI, DateStart, Getdate()) <= " + Timeout);
                SQL.AppendLine(" And Session.UserId = " + UserId);

                data = Functions.Conn.GetDataTable(SQL.ToString(), "Session");
                if (data != null && data.Rows.Count > 0 && data.AsEnumerable().First().Field <long>("SessionId") > 0)
                {
                    return(SessionDomain.GetSessionById(data.AsEnumerable().First().Field <long>("SessionId")));
                }

                string Hash = SessionDomain.GenerateHash(users.UserId.ToString() + users.Password.ToString());

                SQL = new StringBuilder();
                SQL.AppendLine(" Insert Into Session ");
                SQL.AppendLine("    (UserId, ");
                SQL.AppendLine("     SessionHash,");
                SQL.AppendLine("     DateStart, ");
                SQL.AppendLine("     DateEnd, ");
                SQL.AppendLine("     Active, ");
                SQL.AppendLine("     DateInsert, ");
                SQL.AppendLine("     DateUpdate)");
                SQL.AppendLine(" Values ");
                SQL.AppendLine("    ( " + UserId + ",");
                SQL.AppendLine("     '" + Hash + "',");
                SQL.AppendLine("     GetDate(),");
                SQL.AppendLine("     DateAdd(MI," + Timeout + ",GetDate()),");
                SQL.AppendLine("     1, ");
                SQL.AppendLine("     GetDate(), ");
                SQL.AppendLine("     GetDate()) ");

                Sessions session = new Sessions();
                session.SessionId = Functions.Conn.Insert(SQL.ToString());

                if (session.SessionId > 0)
                {
                    return(SessionDomain.GetSessionById(session.SessionId));
                }
                throw new InternalProgramException("Não foi possivel criar uma sessão para o usuário!");
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }