crea venta pero no imprime
This commit is contained in:
+95
-1
@@ -697,6 +697,90 @@ namespace compabetov2.database
|
||||
return rutaDestino;
|
||||
}
|
||||
|
||||
public static SQLiteDataReader conseguirMermaDAO()
|
||||
{
|
||||
SQLiteDataReader reader = null;
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
{
|
||||
SQLiteConnection conexion = db_conexion.get_connection();
|
||||
|
||||
conexion.Open();
|
||||
|
||||
string sql = "SELECT * FROM Merma";
|
||||
SQLiteCommand command = new SQLiteCommand(sql, conexion);
|
||||
reader = command.ExecuteReader();
|
||||
|
||||
return reader;
|
||||
|
||||
}
|
||||
catch (SQLiteException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
return reader;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool crearVentaDAO(VentaModel venta, List<DetalleVentaModel> detalleVentas)
|
||||
{
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection conexion = db_conexion.get_connection())
|
||||
{
|
||||
conexion.Open();
|
||||
|
||||
using (var transaccion = conexion.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
string sqlVenta = "INSERT INTO venta (fecha, total) VALUES(@fecha, @total);";
|
||||
string sqlDetalle = "INSERT INTO detalle_venta (fk_venta, fk_producto, cantidad) VALUES(@idVenta, @idProducto, @cantidada);";
|
||||
string sqlIdVenta = "SELECT idVenta FROM venta ORDER BY idVenta DESC LIMIT 1";
|
||||
|
||||
|
||||
SQLiteCommand commandVenta = new SQLiteCommand(sqlVenta, conexion);
|
||||
commandVenta.Parameters.AddWithValue("@fecha", DateTime.Now.ToString());
|
||||
commandVenta.Parameters.AddWithValue("@total", venta.total);
|
||||
commandVenta.ExecuteNonQuery();
|
||||
|
||||
SQLiteCommand commandConsulta = new SQLiteCommand(sqlIdVenta, conexion);
|
||||
SQLiteDataReader reader = commandConsulta.ExecuteReader();
|
||||
|
||||
long idVenta = -1;
|
||||
while (reader.Read())
|
||||
{
|
||||
idVenta = reader.GetInt64(0);
|
||||
}
|
||||
|
||||
foreach (DetalleVentaModel detalleVenta in detalleVentas)
|
||||
{
|
||||
SQLiteCommand commandEmpleado = new SQLiteCommand(sqlDetalle, conexion);
|
||||
commandEmpleado.Parameters.AddWithValue("@idVenta", idVenta);
|
||||
commandEmpleado.Parameters.AddWithValue("@idProducto", detalleVenta.producto.idProducto);
|
||||
commandEmpleado.Parameters.AddWithValue("@cantidada", detalleVenta.cantidad);
|
||||
commandEmpleado.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
transaccion.Commit();
|
||||
return true;
|
||||
}
|
||||
catch (SQLiteException ex)
|
||||
{
|
||||
transaccion.Rollback();
|
||||
MessageBox.Show(ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLiteException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void crearDB()
|
||||
{
|
||||
var db_conexion = new Conexion();
|
||||
@@ -708,16 +792,19 @@ namespace compabetov2.database
|
||||
{
|
||||
"DROP TABLE IF EXISTS Empleado",
|
||||
"DROP TABLE IF EXISTS Login",
|
||||
"DROP TABLE IF EXISTS detalle_venta",
|
||||
"DROP TABLE IF EXISTS Producto",
|
||||
"DROP TABLE IF EXISTS Categoria",
|
||||
"DROP TABLE IF EXISTS Cliente",
|
||||
"DROP TABLE IF EXISTS Merma",
|
||||
"DROP TABLE IF EXISTS venta",
|
||||
|
||||
"CREATE TABLE Login (idlogin INTEGER PRIMARY KEY AUTOINCREMENT, tipo TEXT NOT NULL, usuario TEXT NOT NULL, "+
|
||||
"contra TEXT NOT NULL)",
|
||||
|
||||
"CREATE TABLE Empleado (idempleado INTEGER PRIMARY KEY AUTOINCREMENT, nombre TEXT NOT NULL, "+
|
||||
"apellidos TEXT NOT NULL, calle TEXT NOT NULL, fecha_contratacion TEXT NOT NULL,estado TEXT NOT NULL, colonia TEXT NOT NULL, cp TEXT NOT NULL, no_ext TEXT NOT NULL," +
|
||||
"no_int TEXT NOT NULL, referencia TEXT NOT NULL, fecha_nac TEXT NOT NULL, telefono TEXT NOT NULL, fk_idLogin INTEGER," +
|
||||
"no_int TEXT NOT NULL, referencia TEXT NOT NULL, fecha_nac TEXT NOT NULL, telefono TEXT NOT NULL,img TEXT DEFAULT '', fk_idLogin INTEGER," +
|
||||
"FOREIGN KEY (fk_idLogin) REFERENCES Login(idlogin))",
|
||||
|
||||
"CREATE TABLE Categoria (idcategoria INTEGER PRIMARY KEY AUTOINCREMENT, nombre TEXT NOT NULL, descripcion TEXT NOT NULL)",
|
||||
@@ -730,6 +817,13 @@ namespace compabetov2.database
|
||||
"calle TEXT NOT NULL, colonia TEXT NOT NULL, cp TEXT NOT NULL, no_ext TEXT NOT NULL, no_int TEXT NOT NULL, referencia TEXT NOT NULL, " +
|
||||
"telefono TEXT NOT NULL, telefono_extra TEXT NOT NULL)",
|
||||
|
||||
"CREATE TABLE Merma (idmerma INTEGER PRIMARY KEY AUTOINCREMENT, fecha TEXT, responsable TEXT, razon TEXT)",
|
||||
|
||||
"CREATE TABLE venta (idVenta INTEGER PRIMARY KEY AUTOINCREMENT,fecha TEXT, total DECIMAL(10, 2));",
|
||||
|
||||
"CREATE TABLE detalle_venta (fk_venta INTEGER, fk_producto INTEGER, PRIMARY KEY (fk_venta, fk_producto), " +
|
||||
"FOREIGN KEY (fk_venta) REFERENCES venta(idVenta),FOREIGN KEY (fk_producto) REFERENCES producto(idproducto));",
|
||||
|
||||
"INSERT INTO Login ( tipo, usuario, contra) VALUES('admin', 'admin', '12345');",
|
||||
"INSERT INTO Empleado ( nombre, apellidos, calle, fecha_contratacion,estado, colonia, cp, no_ext,no_int, referencia, fecha_nac, telefono,fk_idLogin) VALUES('jefe', '', '', '', '', '', '', '', '', '', '', '',1);",
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace compabetov2.database.modelos
|
||||
{
|
||||
internal class Categoria
|
||||
public class Categoria
|
||||
{
|
||||
public int idCategoria;
|
||||
public string nombre;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace compabetov2.database.modelos
|
||||
{
|
||||
public class DetalleVentaModel
|
||||
{
|
||||
public int id;
|
||||
public int cantidad;
|
||||
public Producto producto;
|
||||
|
||||
public DetalleVentaModel(int cantidad, Producto producto, int id = -1)
|
||||
{
|
||||
this.cantidad = cantidad;
|
||||
this.producto = producto;
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace compabetov2.database.modelos
|
||||
{
|
||||
public class Merma
|
||||
{
|
||||
public long idMerma;
|
||||
public string fecha;
|
||||
public string responsable;
|
||||
public string razon;
|
||||
|
||||
public Merma(long idMerma, string fecha, string responsable, string razon)
|
||||
{
|
||||
this.idMerma = idMerma;
|
||||
this.fecha = fecha;
|
||||
this.responsable = responsable;
|
||||
this.razon = razon;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace compabetov2.database.modelos
|
||||
{
|
||||
internal class Producto
|
||||
public class Producto
|
||||
{
|
||||
public int idProducto;
|
||||
public string nombre;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace compabetov2.database.modelos
|
||||
{
|
||||
public class VentaModel
|
||||
{
|
||||
public int id;
|
||||
public string fecha;
|
||||
public decimal total;
|
||||
|
||||
public VentaModel(decimal total = 0, int id = -1, string fecha = "") {
|
||||
this.id = id;
|
||||
this.fecha = fecha;
|
||||
this.total = total;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -183,5 +183,29 @@ namespace compabetov2.database
|
||||
{
|
||||
return DAO.modificarContraDAO(empleado, contra);
|
||||
}
|
||||
|
||||
public static List<Merma> conseguirMerma()
|
||||
{
|
||||
List<Merma> mermas = new List<Merma>();
|
||||
SQLiteDataReader reader = DAO.conseguirMermaDAO();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
Merma merma = new Merma(
|
||||
reader.GetInt64(0),
|
||||
reader.GetString(1),
|
||||
reader.GetString(2),
|
||||
reader.GetString(3)
|
||||
);
|
||||
mermas.Add(merma);
|
||||
}
|
||||
|
||||
return mermas;
|
||||
}
|
||||
|
||||
public static bool crearVentaDAO(VentaModel venta, List<DetalleVentaModel> detalleVentas)
|
||||
{
|
||||
return DAO.crearVentaDAO(venta, detalleVentas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user