Beispiel #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            recibo = new ReciboVenta();

            recibo.Entrada = decimal.Parse(txtEntrada.Text);
            recibo.Salida  = decimal.Parse(txtSalida.Text);

            decimal sumatoria = 0;

            if (DGV.Rows.Count == 0)
            {
                errorProvider1.SetError(button2, "Debe agregar un registro antes de cerrar el ticket");
            }
            else
            {
                errorProvider1.Clear();
                foreach (DataGridViewRow row in DGV.Rows)
                {
                    sumatoria += Convert.ToDecimal(row.Cells["Importe"].Value);
                }
                txtImportePagar.Text = sumatoria.ToString("0.00");
                DeshabilitarIngreso();
                txtEntrada.SelectAll();
            }
        }
Beispiel #2
0
        internal static List <ReciboVenta> GetLista()
        {
            List <ReciboVenta> listaVenta = new List <ReciboVenta>();

            using (SqlConnection cnn = ConexionBD.GetConexion())
            {
                cnn.Open();
                string     strComando = "SELECT * FROM ReciboVenta ORDER BY IdRecibo desc ";
                SqlCommand comando    = new SqlCommand(strComando, cnn);
                using (SqlDataReader reader = comando.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        ReciboVenta obj = new ReciboVenta();
                        obj.IdRecibo = reader.GetInt32(0);
                        obj.Fecha    = reader.GetDateTime(1);
                        obj.cliente  = reader.GetString(2);
                        obj.producto = reader.GetString(3);
                        obj.Cantidad = reader.GetInt32(4);
                        obj.PrecioU  = reader.GetDecimal(5);
                        obj.Importe  = reader.GetDecimal(6);
                        obj.Entrada  = reader.GetDecimal(7);
                        obj.Salida   = reader.GetDecimal(8);

                        listaVenta.Add(obj);
                    }
                }
            }
            return(listaVenta);
        }
Beispiel #3
0
        private void ReciboCrystalReportViewer_Load(object sender, EventArgs e)
        {
            ReciboVenta ver = new ReciboVenta();

            ver.SetDataSource(Ventas);

            ReciboCrystalReportViewer.ReportSource = ver;
            ReciboCrystalReportViewer.Refresh();
        }
Beispiel #4
0
        internal static void Guardar(ReciboVenta recibo)
        {
            try
            {
                using (SqlConnection cnn = ConexionBD.GetConexion())
                {
                    cnn.Open();
                    SqlTransaction tran = cnn.BeginTransaction();

                    string     insertComando = "INSERT INTO RECIBOVENTA(Fecha, Cliente, Producto, Cantidad, PrecioU, Importe, Entrada, Salida) values (@fec, @cliente, @producto, @cant, @preciou, @importe, @ent, @sal)";
                    SqlCommand comando       = new SqlCommand(insertComando, cnn, tran);
                    comando.Parameters.AddWithValue("@fec", recibo.Fecha);
                    comando.Parameters.AddWithValue("@cliente", recibo.cliente);
                    comando.Parameters.AddWithValue("@producto", recibo.producto);
                    comando.Parameters.AddWithValue("@cant", recibo.Cantidad);
                    comando.Parameters.AddWithValue("@preciou", recibo.PrecioU);
                    comando.Parameters.AddWithValue("@importe", recibo.Importe);
                    comando.Parameters.AddWithValue("@ent", recibo.Entrada);
                    comando.Parameters.AddWithValue("@sal", recibo.Salida);

                    try
                    {
                        comando.ExecuteNonQuery();

                        insertComando = "SELECT @@IDENTITY";
                        comando       = new SqlCommand(insertComando, cnn, tran);
                        int id = (int)(decimal)comando.ExecuteScalar();
                        recibo.IdRecibo = id;

                        string updateStatement =
                            "UPDATE Productos SET Stock=Stock-@cant " +
                            "WHERE CodigoBarra + ' - ' + DescripcionProducto=@id";
                        SqlCommand updateCommand = new SqlCommand(updateStatement, cnn, tran);
                        updateCommand.Parameters.AddWithValue("@cant", recibo.Cantidad);
                        updateCommand.Parameters.AddWithValue("@id", recibo.producto);
                        updateCommand.ExecuteNonQuery();
                        tran.Commit();
                    }
                    catch (Exception ex)
                    {
                        tran.Rollback();
                        ex.Message.ToString();
                    }
                    finally
                    {
                        cnn.Close();
                        tran.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #5
0
        internal static List <ReciboVenta> GetVentasxFecha(DateTime desde, DateTime hasta)
        {
            using (SqlConnection cnn = ConexionBD.GetConexion())
            {
                List <ReciboVenta> listaFiltrada = new List <ReciboVenta>();
                cnn.Open();

                string filterCommand = @"SELECT *
                        FROM ReciboVenta
                        WHERE CAST(CONVERT(CHAR(8), Fecha, 112) AS INT) BETWEEN CAST(CONVERT(CHAR(8), @desde, 112) AS INT) 
                                    AND CAST(CONVERT(CHAR(8), @hasta, 112) AS INT)";


                SqlCommand comando = new SqlCommand(filterCommand, cnn);
                comando.Parameters.AddWithValue("@desde", desde);
                comando.Parameters.AddWithValue("@hasta", hasta);

                try
                {
                    SqlDataReader reader = comando.ExecuteReader();

                    while (reader.Read())
                    {
                        ReciboVenta obj = new ReciboVenta();
                        obj.IdRecibo = reader.GetInt32(0);
                        obj.Fecha    = reader.GetDateTime(1);
                        obj.cliente  = reader.GetString(2);
                        obj.producto = reader.GetString(3);
                        obj.Cantidad = reader.GetInt32(4);
                        obj.PrecioU  = reader.GetDecimal(5);
                        obj.Importe  = reader.GetDecimal(6);
                        obj.Entrada  = reader.GetDecimal(7);
                        obj.Salida   = reader.GetDecimal(8);

                        listaFiltrada.Add(obj);
                    }
                    reader.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error al intentar una busqueda", ex.Message);
                }
                finally
                {
                    cnn.Close();
                }
                return(listaFiltrada);
            }
        }
Beispiel #6
0
        private void SetearFilas(DataGridViewRow r, ReciboVenta v1)
        {
            r.Cells[cmnFecha.Index].Value    = v1.Fecha.ToShortDateString();
            r.Cells[cmnCliente.Index].Value  = v1.cliente;
            r.Cells[cmnProducto.Index].Value = v1.producto;
            r.Cells[cmnCantidad.Index].Value = v1.Cantidad;
            r.Cells[cmnPrecioU.Index].Value  = v1.PrecioU;
            r.Cells[cmnImporte.Index].Value  = v1.Importe;
            r.Cells[cmnPago.Index].Value     = v1.Entrada;
            r.Cells[cmnDebe.Index].Value     = v1.Salida;



            r.Tag = v1;
        }
Beispiel #7
0
        private void txtEntrada_TextChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtEntrada.Text.Trim()))
            {
                txtEntrada.Text = " ";
            }
            else
            {
                recibo         = new ReciboVenta();
                recibo.Entrada = decimal.Parse(txtEntrada.Text);
                recibo.Salida  = decimal.Parse(txtSalida.Text);
                decimal sumatoria = 0;

                foreach (DataGridViewRow row in DGV.Rows)
                {
                    sumatoria += Convert.ToDecimal(row.Cells["Importe"].Value);
                }



                if (sumatoria == recibo.Entrada)
                {
                    recibo.Salida  = 0;
                    txtSalida.Text = recibo.Salida.ToString("0.00");
                }
                else if (sumatoria > recibo.Entrada)
                {
                    recibo.Salida  = (sumatoria - recibo.Entrada);
                    txtSalida.Text = recibo.Salida.ToString("0.00");
                }
                else if (recibo.Entrada > sumatoria)
                {
                    txtSuVuelto.Text = (recibo.Entrada - sumatoria).ToString();
                    txtSalida.Text   = "0.00";
                }
                else if (recibo.Entrada < sumatoria)
                {
                    txtSuVuelto.Text = "0.00";
                    txtSalida.Text   = (sumatoria - recibo.Entrada).ToString();
                }
            }
        }
Beispiel #8
0
        private void bORRARToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dgVentas.SelectedRows.Count > 0)
            {
                DataGridViewRow r  = dgVentas.SelectedRows[0];
                ReciboVenta     v  = (ReciboVenta)r.Tag;
                DialogResult    dr = MessageBox.Show(string.Format("¿Desea borrar la venta?"), "Confirmar", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (dr == DialogResult.Yes)
                {
                    try
                    {
                        ReciboVtaBD.Borrar(v);


                        dgVentas.Rows.Remove(r);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }
Beispiel #9
0
        internal static void Borrar(ReciboVenta v)
        {
            SqlTransaction tran = null;

            using (SqlConnection cnn = ConexionBD.GetConexion())
            {
                cnn.Open();
                tran = ConexionBD.CNN.BeginTransaction();
                string     deleteString  = "DELETE FROM RECIBOVENTA WHERE IdRecibo=@id";
                SqlCommand deleteCommand = new SqlCommand(deleteString, cnn, tran);
                deleteCommand.Parameters.AddWithValue("@id", v.IdRecibo);

                string updateString = "UPDATE Productos SET Stock=Stock+@cant " +
                                      "WHERE CodigoBarra + ' - ' + DescripcionProducto=@id";
                SqlCommand updateCommand = new SqlCommand(updateString, cnn, tran);
                updateCommand.Parameters.AddWithValue("@cant", v.Cantidad);
                updateCommand.Parameters.AddWithValue("@id", v.producto);
                updateCommand.ExecuteNonQuery();
                tran.Commit();

                try
                {
                    deleteCommand.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    MessageBox.Show("Error", ex.Message);
                }
                finally
                {
                    cnn.Close();
                    tran.Dispose();
                }
            }
        }