コード例 #1
0
        static public Library.CaixaTransacao FindCaixaTransacaoById(long idCaixaTransacao)
        {
            SqlConnection  conexao = null;
            SqlDataAdapter dap     = null;
            DataSet        ds      = null;

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

                dap = new SqlDataAdapter("SELECT * FROM CaixaTransacao WHERE id=" + idCaixaTransacao + "", conexao);

                ds = new DataSet();

                dap.Fill(ds, "CaixaTransacao");

                if (ds.Tables["CaixaTransacao"].Rows.Count == 1)
                {
                    caixaTransacao       = new CaixaTransacao();
                    caixaTransacao.Id    = (long)ds.Tables["CaixaTransacao"].Rows[0]["id"];
                    caixaTransacao.Caixa = Library.CaixaBD.FindCaixaById((long)ds.Tables["CaixaTransacao"].Rows[0]["idCaixa"]);
                    caixaTransacao.Hora  = (TimeSpan)ds.Tables["CaixaTransacao"].Rows[0]["hora"];
                    caixaTransacao.Tipo  = ds.Tables["CaixaTransacao"].Rows[0]["tipo"].ToString();
                    caixaTransacao.Valor = (decimal)ds.Tables["CaixaTransacao"].Rows[0]["valor"];

                    if (!string.IsNullOrEmpty(ds.Tables["CaixaTransacao"].Rows[0]["idDespesa"].ToString()))
                    {
                        caixaTransacao.Despesa = Library.DespesaBD.FindDespesaById((long)ds.Tables["CaixaTransacao"].Rows[0]["idDespesa"]);
                    }
                    else
                    {
                        caixaTransacao.Despesa = null;
                    }

                    if (!string.IsNullOrEmpty(ds.Tables["CaixaTransacao"].Rows[0]["idVenda"].ToString()))
                    {
                        caixaTransacao.Venda = Library.VendaBD.FindVendaById((long)ds.Tables["CaixaTransacao"].Rows[0]["idVenda"]);
                    }
                    else
                    {
                        caixaTransacao.Venda = null;
                    }

                    if (!string.IsNullOrEmpty(ds.Tables["CaixaTransacao"].Rows[0]["idVendaParcela"].ToString()))
                    {
                        caixaTransacao.VendaParcela = Library.VendaParcelaBD.FindVendaParcelaById((long)ds.Tables["CaixaTransacao"].Rows[0]["idVendaParcela"]);
                    }
                    else
                    {
                        caixaTransacao.VendaParcela = null;
                    }

                    if (!string.IsNullOrEmpty(ds.Tables["CaixaTransacao"].Rows[0]["idComissao"].ToString()))
                    {
                        caixaTransacao.Comissao = Library.ComissaoBD.FindComissaoById((long)ds.Tables["CaixaTransacao"].Rows[0]["idComissao"]);
                    }
                    else
                    {
                        caixaTransacao.Comissao = null;
                    }

                    if (!string.IsNullOrEmpty(ds.Tables["CaixaTransacao"].Rows[0]["idCheque"].ToString()))
                    {
                        caixaTransacao.Cheque = Library.ChequeBD.FindChequeById((long)ds.Tables["CaixaTransacao"].Rows[0]["idCheque"]);
                    }
                    else
                    {
                        caixaTransacao.Cheque = null;
                    }

                    if (!string.IsNullOrEmpty(ds.Tables["CaixaTransacao"].Rows[0]["idCartao"].ToString()))
                    {
                        caixaTransacao.Cartao = Library.CartaoBD.FindCartaoById((long)ds.Tables["CaixaTransacao"].Rows[0]["idCartao"]);
                    }
                    else
                    {
                        caixaTransacao.Cartao = null;
                    }
                }
                return(caixaTransacao);
            }
            catch (Exception ex)
            {
                Library.Diagnostics.Logger.Error(ex);
            }
            finally
            {
                conexao.Close();
                dap.Dispose();
                ds.Dispose();
            }
            return(null);
        }
コード例 #2
0
        static public List <Library.CaixaTransacao> FindAdvanced(params Library.Classes.QItem[] args)
        {
            SqlDataReader rdr     = null;
            SqlConnection conexao = null;

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

                using (SqlCommand comando = new SqlCommand())
                {
                    string query = "SELECT * FROM CaixaTransacao AS ct " +
                                   " LEFT JOIN Venda AS v ON v.id = ct.idVenda ";

                    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 "ct.id":
                            query += pre + "ct.id = @id";
                            comando.Parameters.AddWithValue("@id", qi.Objeto);
                            break;

                        case "ct.idCaixa":
                            query += pre + "ct.idCaixa = @idCaixa";
                            comando.Parameters.AddWithValue("@idCaixa", qi.Objeto);
                            break;

                        case "ct.hora":
                            query += pre + "ct.hora = @hora";
                            comando.Parameters.AddWithValue("@hora", qi.Objeto);
                            break;

                        case "ct.tipo":
                            query += pre + "ct.tipo = @tipo";
                            comando.Parameters.AddWithValue("@tipo", qi.Objeto);
                            break;

                        case "ct.valor":
                            query += pre + "ct.valor = @valor";
                            comando.Parameters.AddWithValue("@valor", qi.Objeto);
                            break;

                        case "v.id":
                            query += pre + "v.id = @idVenda";
                            comando.Parameters.AddWithValue("@idVenda", 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.CaixaTransacao> caixaTransacoes = new List <Library.CaixaTransacao>();

                while (rdr.Read())
                {
                    Library.CaixaTransacao caixaTransacao = new CaixaTransacao();
                    caixaTransacao.Id    = (long)rdr["id"];
                    caixaTransacao.Caixa = Library.CaixaBD.FindCaixaById((long)rdr["idCaixa"]);
                    caixaTransacao.Hora  = (TimeSpan)rdr["hora"];
                    caixaTransacao.Tipo  = rdr["tipo"].ToString();
                    caixaTransacao.Valor = (decimal)rdr["valor"];

                    if (!string.IsNullOrEmpty(rdr["idDespesa"].ToString()))
                    {
                        caixaTransacao.Despesa = Library.DespesaBD.FindDespesaById((long)rdr["idDespesa"]);
                    }
                    else
                    {
                        caixaTransacao.Despesa = null;
                    }

                    if (!string.IsNullOrEmpty(rdr["idVenda"].ToString()))
                    {
                        caixaTransacao.Venda = Library.VendaBD.FindVendaById((long)rdr["idVenda"]);
                    }
                    else
                    {
                        caixaTransacao.Venda = null;
                    }

                    if (!string.IsNullOrEmpty(rdr["idVendaParcela"].ToString()))
                    {
                        caixaTransacao.VendaParcela = Library.VendaParcelaBD.FindVendaParcelaById((long)rdr["idVendaParcela"]);
                    }
                    else
                    {
                        caixaTransacao.VendaParcela = null;
                    }

                    if (!string.IsNullOrEmpty(rdr["idComissao"].ToString()))
                    {
                        caixaTransacao.Comissao = Library.ComissaoBD.FindComissaoById((long)rdr["idComissao"]);
                    }
                    else
                    {
                        caixaTransacao.Comissao = null;
                    }

                    if (!string.IsNullOrEmpty(rdr["idCheque"].ToString()))
                    {
                        caixaTransacao.Cheque = Library.ChequeBD.FindChequeById((long)rdr["idCheque"]);
                    }
                    else
                    {
                        caixaTransacao.Cheque = null;
                    }

                    if (!string.IsNullOrEmpty(rdr["idCartao"].ToString()))
                    {
                        caixaTransacao.Cartao = Library.CartaoBD.FindCartaoById((long)rdr["idCartao"]);
                    }
                    else
                    {
                        caixaTransacao.Cartao = null;
                    }

                    caixaTransacoes.Add(caixaTransacao);
                }

                return(caixaTransacoes);
            }
            catch (Exception ex)
            {
                Library.Diagnostics.Logger.Error(ex);
            }
            finally
            {
                if (conexao != null)
                {
                    conexao.Close();
                }
            }
            return(null);
        }