Exemple #1
0
        private Library.Cheque[] ReturnCheque(DataGridView dataGrid, long idVendaAtual)
        {
            try
            {
                int chequeCount = dataGrid.Rows.Count;

                Library.Cheque[] chequeArray = new Library.Cheque[chequeCount];

                for (int i = 0; i < chequeCount; i++)
                {
                    chequeArray[i]        = new Library.Cheque();
                    chequeArray[i].Venda  = Library.VendaBD.FindById(idVendaAtual);
                    chequeArray[i].Data   = DateTime.Parse(dataGrid.Rows[i].Cells[2].Value.ToString());
                    chequeArray[i].Numero = dataGrid.Rows[i].Cells[0].Value.ToString();
                    chequeArray[i].Valor  = (decimal)dataGrid.Rows[i].Cells[1].Value;
                }
                return(chequeArray);
            }
            catch (Exception ex)
            {
                Library.Diagnostics.Logger.Error(ex);
            }

            return(null);
        }
Exemple #2
0
        private void AtualizarGrid()
        {
            try
            {
                if (this.dataCB.SelectedIndex != -1)
                {
                    Library.Cheque        cheque  = (Library.Cheque) this.dataCB.SelectedItem;
                    List <Library.Cheque> cheques = Library.ChequeBD.FindAdvanced(new QItem("cq.data varchar", cheque.Data.ToString("dd/MM/yyyy")));

                    this.transacoesDGV.Rows.Clear();
                    foreach (Library.Cheque cq in cheques)
                    {
                        if (cq.Venda != null)
                        {
                            this.transacoesDGV.Rows.Add(cq.Id, cq.Venda.Cliente.Nome, "Venda", cq.Valor, cq.Numero);
                        }
                        else
                        {
                            this.transacoesDGV.Rows.Add(cq.Id, "Indisponível", "Indisponível", cq.Valor, cq.Numero);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Library.Diagnostics.Logger.Error(ex);
            }
        }
Exemple #3
0
        private void transacoesDGV_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow rowSelected = transacoesDGV.SelectedRows[0];

            Library.Cheque cheque = Library.ChequeBD.FindById((long)rowSelected.Cells[0].Value);

            if (cheque != null)
            {
                cq        = new Forms.Cheque.ChequeDetail();
                cq.Cheque = cheque;

                cq.ShowDialog(this);
            }
        }
Exemple #4
0
        static public Library.Cheque FindById(long idCheque)
        {
            SqlConnection  conexao = null;
            SqlDataAdapter dap     = null;
            DataSet        ds      = null;

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

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

                ds = new DataSet();

                dap.Fill(ds, "Cheque");

                if (ds.Tables["Cheque"].Rows.Count == 1)
                {
                    cheque        = new Cheque();
                    cheque.Id     = (long)ds.Tables["Cheque"].Rows[0]["id"];
                    cheque.Data   = (DateTime)ds.Tables["Cheque"].Rows[0]["data"];
                    cheque.Valor  = (decimal)ds.Tables["Cheque"].Rows[0]["valor"];
                    cheque.Numero = ds.Tables["Cheque"].Rows[0]["numero"].ToString();
                    cheque.Pago   = (int)ds.Tables["Cheque"].Rows[0]["pago"];

                    if (!string.IsNullOrEmpty(ds.Tables["Cheque"].Rows[0]["idVenda"].ToString()))
                    {
                        cheque.Venda = Library.VendaBD.FindById((long)ds.Tables["Cheque"].Rows[0]["idVenda"]);
                    }
                    else
                    {
                        cheque.Venda = null;
                    }
                }
                return(cheque);
            }
            catch (Exception ex)
            {
                Library.Diagnostics.Logger.Error(ex);
            }
            finally
            {
                conexao.Close();
                dap.Dispose();
                ds.Dispose();
            }
            return(null);
        }
Exemple #5
0
        static public void Save(Library.Cheque cheque)
        {
            SqlConnection conexao = null;

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

                SqlCommand comando = conexao.CreateCommand();

                comando.CommandText = "INSERT INTO Cheque (data, valor, numero, pago, idVenda) VALUES (@data, @valor, @numero, @pago, @idVenda)"
                                      + "SELECT CAST(scope_identity() AS bigint)";

                comando.Parameters.AddWithValue("@data", cheque.Data);
                comando.Parameters.AddWithValue("@valor", cheque.Valor);
                comando.Parameters.AddWithValue("@numero", cheque.Numero);
                comando.Parameters.AddWithValue("@pago", cheque.Pago);

                if (cheque.Venda != null)
                {
                    comando.Parameters.AddWithValue("@idVenda", cheque.Venda.Id);
                }
                else
                {
                    comando.Parameters.AddWithValue("@idVenda", DBNull.Value);
                }



                conexao.Open();

                //comando.ExecuteNonQuery();
                cheque.Id = (long)comando.ExecuteScalar();
            }
            catch (Exception ex)
            {
                Library.Diagnostics.Logger.Error(ex);
            }
            finally
            {
                conexao.Close();
            }
        }
Exemple #6
0
        static public void Update(Library.Cheque cheque)
        {
            SqlConnection conexao = null;

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

                SqlCommand comando = conexao.CreateCommand();

                comando.CommandText = "UPDATE Cheque SET data = @data, valor = @valor, numero = @numero, pago = @pago, idVenda = @idVenda WHERE (id= " + cheque.Id + ")";

                comando.Parameters.AddWithValue("@data", cheque.Data);
                comando.Parameters.AddWithValue("@valor", cheque.Valor);
                comando.Parameters.AddWithValue("@numero", cheque.Numero);
                comando.Parameters.AddWithValue("@pago", cheque.Pago);

                if (cheque.Venda != null)
                {
                    comando.Parameters.AddWithValue("@idVenda", cheque.Venda.Id);
                }
                else
                {
                    comando.Parameters.AddWithValue("@idVenda", DBNull.Value);
                }

                conexao.Open();

                comando.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Library.Diagnostics.Logger.Error(ex);
            }
            finally
            {
                conexao.Close();
            }
        }
Exemple #7
0
        static public Library.Cheque[] FindLimitAndOrderByDate()
        {
            SqlConnection  conexao = null;
            SqlDataAdapter dap     = null;
            DataSet        ds      = null;

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

                SqlCommand comando = conexao.CreateCommand();

                dap = new SqlDataAdapter("SELECT MAX(id) AS id, pago FROM Cheque WHERE (pago = 0) GROUP BY data, pago", conexao);

                ds = new DataSet();

                dap.Fill(ds, "Cheque");

                Library.Cheque[] ChequeArray = new Library.Cheque[ds.Tables["Cheque"].Rows.Count];

                for (int i = 0; i < ds.Tables["Cheque"].Rows.Count; i++)
                {
                    ChequeArray[i] = Library.ChequeBD.FindById((long)ds.Tables["Cheque"].Rows[i]["id"]);
                }

                return(ChequeArray);
            }
            catch (Exception ex)
            {
                Library.Diagnostics.Logger.Error(ex);
            }
            finally
            {
                conexao.Close();
                dap.Dispose();
                ds.Dispose();
            }
            return(null);
        }
Exemple #8
0
        static public void Delete(Library.Cheque cheque)
        {
            SqlConnection conexao = null;

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

                comando.CommandText = "DELETE FROM Cheque WHERE id='" + cheque.Id + "'";

                conexao.Open();
                comando.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Library.Diagnostics.Logger.Error(ex);
            }
            finally
            {
                conexao.Close();
            }
        }