From 82814ab6e310dbb51f6aafad31e88828bd5b4ffa Mon Sep 17 00:00:00 2001 From: Jeff94sl Date: Tue, 16 Apr 2019 11:29:39 -0600 Subject: [PATCH] Coreccion de error de base de datos --- .gitignore | 4 -- Farmacia/Farmacia/App.config | 46 +++++++++++++++++++ Farmacia/Farmacia/Clases/Conexion.cs | 14 +++++- .../Farmacia/Properties/Settings.Designer.cs | 40 ++++++++++++++-- .../Farmacia/Properties/Settings.settings | 46 +++++++++++++++++++ 5 files changed, 141 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index f6a51c7..069d989 100644 --- a/.gitignore +++ b/.gitignore @@ -17,10 +17,6 @@ *.userprefs # Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ x64/ x86/ bld/ diff --git a/Farmacia/Farmacia/App.config b/Farmacia/Farmacia/App.config index c1f94c6..0a4ff92 100644 --- a/Farmacia/Farmacia/App.config +++ b/Farmacia/Farmacia/App.config @@ -29,6 +29,52 @@ + + BEGIN TRANSACTION; +CREATE TABLE IF NOT EXISTS "Venta" ( + "Id_Venta" int NOT NULL, + "Producto" text NOT NULL, + "Cantidad" int NOT NULL, + "Id_Vendedor" int NOT NULL, + "Fecha_de_Venta" text NOT NULL, + "Total_Vendido" decimal(0 , 5) NOT NULL, + FOREIGN KEY("Id_Vendedor") REFERENCES "Usuario"("Id"), + PRIMARY KEY("Id_Venta") +); +CREATE TABLE IF NOT EXISTS "Inventario" ( + "Id" int NOT NULL, + "Producto" text NOT NULL, + "Tipo" text NOT NULL, + "Cantidad" int NOT NULL, + "Precio_Compra" decimal(0 , 5) NOT NULL, + "Precio_Unitario" decimal(0 , 5) NOT NULL, + "Fecha_Compra" text NOT NULL, + "Fecha_Vencimiento" text NOT NULL, + PRIMARY KEY("Id") +); +CREATE TABLE IF NOT EXISTS "Costos_TP" ( + "Id_Costo" int NOT NULL, + "Id_Producto" int NOT NULL, + "Total_CP" decimal(0 , 5) NOT NULL, + PRIMARY KEY("Id_Costo"), + FOREIGN KEY("Id_Producto") REFERENCES "Inventario"("Id") +); +CREATE TABLE IF NOT EXISTS "Usuario" ( + "Id" int NOT NULL, + "Nombre" text NOT NULL, + "Apellido" text NOT NULL, + "Telefono" int NOT NULL, + "Direccion" text NOT NULL, + "Contrasena" text NOT NULL, + "Administrador" bool NOT NULL, + PRIMARY KEY("Id") +); +INSERT INTO "Usuario" VALUES (1,'root','root',0,'Nicaragua','dc76e9f0c0006e8f919e0c515c66dbba3982f785','true'); +CREATE VIEW Costo +As +Select Id_Producto,Inventario.Producto as Producto, Inventario.Cantidad as Cantidad,Inventario.Fecha_Compra as Fecha_Compra, Costos_TP.Total_CP as Total_Costo, (Select (Select Precio_Unitario From Inventario Where Id=Id_Producto)*(Select Cantidad From Inventario Where Id=Id_Producto)) As Total_Venta From Costos_TP inner join Inventario on Inventario.Id = Costos_TP.Id_Producto; +COMMIT; + \ No newline at end of file diff --git a/Farmacia/Farmacia/Clases/Conexion.cs b/Farmacia/Farmacia/Clases/Conexion.cs index a9ac538..10b748b 100644 --- a/Farmacia/Farmacia/Clases/Conexion.cs +++ b/Farmacia/Farmacia/Clases/Conexion.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Data.SQLite; +using System.IO; namespace Farmacia { @@ -30,7 +31,18 @@ public class Conexion public Conexion() { - Cadena = new SQLiteConnection("Data Source=DB.db;Version=3;New=false;Compress=true,Read Only=false"); + if (File.Exists("DB.db")) + { + Cadena = new SQLiteConnection("Data Source=DB.db;Version=3;New=false;Compress=true,Read Only=false"); + } + else + { + Cadena = new SQLiteConnection("Data Source=DB.db;Version=3;New=false;Compress=true,Read Only=false"); + Cadena.Open(); + Command = new SQLiteCommand(Properties.Settings.Default.Data,Cadena); + Command.ExecuteNonQuery(); + Cadena.Close(); + } } public void Conectar() diff --git a/Farmacia/Farmacia/Properties/Settings.Designer.cs b/Farmacia/Farmacia/Properties/Settings.Designer.cs index 9b92d1a..a7568f2 100644 --- a/Farmacia/Farmacia/Properties/Settings.Designer.cs +++ b/Farmacia/Farmacia/Properties/Settings.Designer.cs @@ -1,10 +1,10 @@ //------------------------------------------------------------------------------ // -// Este código fue generado por una herramienta. -// Versión de runtime:4.0.30319.42000 +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 // -// Los cambios en este archivo podrían causar un comportamiento incorrecto y se perderán si -// se vuelve a generar el código. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. // //------------------------------------------------------------------------------ @@ -34,5 +34,37 @@ public string IdGlobal { this["IdGlobal"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("BEGIN TRANSACTION;\r\nCREATE TABLE IF NOT EXISTS \"Venta\" (\r\n\t\"Id_Venta\"\tint NOT NUL" + + "L,\r\n\t\"Producto\"\ttext NOT NULL,\r\n\t\"Cantidad\"\tint NOT NULL,\r\n\t\"Id_Vendedor\"\tint NO" + + "T NULL,\r\n\t\"Fecha_de_Venta\"\ttext NOT NULL,\r\n\t\"Total_Vendido\"\tdecimal(0 , 5) NOT N" + + "ULL,\r\n\tFOREIGN KEY(\"Id_Vendedor\") REFERENCES \"Usuario\"(\"Id\"),\r\n\tPRIMARY KEY(\"Id_" + + "Venta\")\r\n);\r\nCREATE TABLE IF NOT EXISTS \"Inventario\" (\r\n\t\"Id\"\tint NOT NULL,\r\n\t\"P" + + "roducto\"\ttext NOT NULL,\r\n\t\"Tipo\"\ttext NOT NULL,\r\n\t\"Cantidad\"\tint NOT NULL,\r\n\t\"Pr" + + "ecio_Compra\"\tdecimal(0 , 5) NOT NULL,\r\n\t\"Precio_Unitario\"\tdecimal(0 , 5) NOT NUL" + + "L,\r\n\t\"Fecha_Compra\"\ttext NOT NULL,\r\n\t\"Fecha_Vencimiento\"\ttext NOT NULL,\r\n\tPRIMAR" + + "Y KEY(\"Id\")\r\n);\r\nCREATE TABLE IF NOT EXISTS \"Costos_TP\" (\r\n\t\"Id_Costo\"\tint NOT N" + + "ULL,\r\n\t\"Id_Producto\"\tint NOT NULL,\r\n\t\"Total_CP\"\tdecimal(0 , 5) NOT NULL,\r\n\tPRIMA" + + "RY KEY(\"Id_Costo\"),\r\n\tFOREIGN KEY(\"Id_Producto\") REFERENCES \"Inventario\"(\"Id\")\r\n" + + ");\r\nCREATE TABLE IF NOT EXISTS \"Usuario\" (\r\n\t\"Id\"\tint NOT NULL,\r\n\t\"Nombre\"\ttext " + + "NOT NULL,\r\n\t\"Apellido\"\ttext NOT NULL,\r\n\t\"Telefono\"\tint NOT NULL,\r\n\t\"Direccion\"\tt" + + "ext NOT NULL,\r\n\t\"Contrasena\"\ttext NOT NULL,\r\n\t\"Administrador\"\tbool NOT NULL,\r\n\tP" + + "RIMARY KEY(\"Id\")\r\n);\r\nINSERT INTO \"Usuario\" VALUES (1,\'root\',\'root\',0,\'Nicaragua" + + "\',\'dc76e9f0c0006e8f919e0c515c66dbba3982f785\',\'true\');\r\nCREATE VIEW Costo \r\nAs \r\n" + + "Select Id_Producto,Inventario.Producto as Producto, Inventario.Cantidad as Canti" + + "dad,Inventario.Fecha_Compra as Fecha_Compra, Costos_TP.Total_CP as Total_Costo, " + + "(Select (Select Precio_Unitario From Inventario Where Id=Id_Producto)*(Select Ca" + + "ntidad From Inventario Where Id=Id_Producto)) As Total_Venta From Costos_TP inne" + + "r join Inventario on Inventario.Id = Costos_TP.Id_Producto;\r\nCOMMIT;")] + public string Data { + get { + return ((string)(this["Data"])); + } + set { + this["Data"] = value; + } + } } } diff --git a/Farmacia/Farmacia/Properties/Settings.settings b/Farmacia/Farmacia/Properties/Settings.settings index 02e2fbf..fc4ea62 100644 --- a/Farmacia/Farmacia/Properties/Settings.settings +++ b/Farmacia/Farmacia/Properties/Settings.settings @@ -5,5 +5,51 @@ + + BEGIN TRANSACTION; +CREATE TABLE IF NOT EXISTS "Venta" ( + "Id_Venta" int NOT NULL, + "Producto" text NOT NULL, + "Cantidad" int NOT NULL, + "Id_Vendedor" int NOT NULL, + "Fecha_de_Venta" text NOT NULL, + "Total_Vendido" decimal(0 , 5) NOT NULL, + FOREIGN KEY("Id_Vendedor") REFERENCES "Usuario"("Id"), + PRIMARY KEY("Id_Venta") +); +CREATE TABLE IF NOT EXISTS "Inventario" ( + "Id" int NOT NULL, + "Producto" text NOT NULL, + "Tipo" text NOT NULL, + "Cantidad" int NOT NULL, + "Precio_Compra" decimal(0 , 5) NOT NULL, + "Precio_Unitario" decimal(0 , 5) NOT NULL, + "Fecha_Compra" text NOT NULL, + "Fecha_Vencimiento" text NOT NULL, + PRIMARY KEY("Id") +); +CREATE TABLE IF NOT EXISTS "Costos_TP" ( + "Id_Costo" int NOT NULL, + "Id_Producto" int NOT NULL, + "Total_CP" decimal(0 , 5) NOT NULL, + PRIMARY KEY("Id_Costo"), + FOREIGN KEY("Id_Producto") REFERENCES "Inventario"("Id") +); +CREATE TABLE IF NOT EXISTS "Usuario" ( + "Id" int NOT NULL, + "Nombre" text NOT NULL, + "Apellido" text NOT NULL, + "Telefono" int NOT NULL, + "Direccion" text NOT NULL, + "Contrasena" text NOT NULL, + "Administrador" bool NOT NULL, + PRIMARY KEY("Id") +); +INSERT INTO "Usuario" VALUES (1,'root','root',0,'Nicaragua','dc76e9f0c0006e8f919e0c515c66dbba3982f785','true'); +CREATE VIEW Costo +As +Select Id_Producto,Inventario.Producto as Producto, Inventario.Cantidad as Cantidad,Inventario.Fecha_Compra as Fecha_Compra, Costos_TP.Total_CP as Total_Costo, (Select (Select Precio_Unitario From Inventario Where Id=Id_Producto)*(Select Cantidad From Inventario Where Id=Id_Producto)) As Total_Venta From Costos_TP inner join Inventario on Inventario.Id = Costos_TP.Id_Producto; +COMMIT; + \ No newline at end of file