Esempio n. 1
0
        static public Library.Logon FindLogonById(long idLogon)
        {
            SqlConnection  conexao = null;
            SqlDataAdapter dap     = null;
            DataSet        ds      = null;

            Library.Logon logons = null;
            try
            {
                conexao = new SqlConnection(global::Connection.Connection.String());

                dap = new SqlDataAdapter("SELECT * FROM Logon WHERE id='" + idLogon + "'", conexao);

                ds = new DataSet();

                dap.Fill(ds, "Logon");

                if (ds.Tables["Logon"].Rows.Count == 1)
                {
                    logons             = new Logon();
                    logons.Id          = (long)ds.Tables["Logon"].Rows[0]["id"];
                    logons.Funcionario = Library.FuncionarioBD.FindById((long)ds.Tables["Logon"].Rows[0]["idFuncionario"]);
                    logons.Data        = (DateTime)ds.Tables["Logon"].Rows[0]["data"];
                }
                return(logons);
            }
            catch (Exception ex)
            {
                Library.Diagnostics.Logger.Error(ex);;
            }
            finally
            {
                conexao.Close();
                dap.Dispose();
                ds.Dispose();
            }
            return(null);
        }
Esempio n. 2
0
        static public List <Library.Logon> FindAdvanced(params Library.Classes.QItem[] args)
        {
            SqlDataReader rdr     = null;
            SqlConnection conexao = null;
            SqlCommand    comando = null;

            try
            {
                conexao = new SqlConnection(global::Connection.Connection.String());

                comando = new SqlCommand();

                string query = "SELECT * FROM Logon AS l ";

                int    p   = 0;
                string pre = "";
                foreach (Library.Classes.QItem qi in args)
                {
                    if (p == 0)
                    {
                        pre = "WHERE ";
                    }
                    else
                    {
                        pre = "AND ";
                    }

                    p++;

                    switch (qi.Campo)
                    {
                    case "l.id":
                        query += pre + "l.id = @id";
                        comando.Parameters.AddWithValue("@id", qi.Objeto);
                        break;

                    case "ORDER BY":
                        query += " ORDER BY " + qi.Objeto;
                        break;
                    }
                }

                comando.CommandText = query;

                comando.Connection = conexao;

                conexao.Open();

                rdr = comando.ExecuteReader();

                List <Library.Logon> logonsList = new List <Library.Logon>();

                while (rdr.Read())
                {
                    Library.Logon logons = new Logon();
                    logons.Id          = (long)rdr["id"];
                    logons.Funcionario = Library.FuncionarioBD.FindById((long)rdr["idFuncionario"]);
                    logons.Data        = (DateTime)rdr["data"];

                    logonsList.Add(logons);
                }

                return(logonsList);
            }
            catch (Exception ex)
            {
                Library.Diagnostics.Logger.Error(ex);
            }
            finally
            {
                conexao.Close();
                comando.Dispose();
            }
            return(null);
        }