Skip to content

Commit

Permalink
Coreccion de error de base de datos
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff94sl committed Apr 16, 2019
1 parent 321b2d7 commit 82814ab
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 9 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
*.userprefs

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
Expand Down
46 changes: 46 additions & 0 deletions Farmacia/Farmacia/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,52 @@
<setting name="IdGlobal" serializeAs="String">
<value />
</setting>
<setting name="Data" serializeAs="String">
<value>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;</value>
</setting>
</Farmacia.Properties.Settings>
</userSettings>
</configuration>
14 changes: 13 additions & 1 deletion Farmacia/Farmacia/Clases/Conexion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.IO;

namespace Farmacia
{
Expand Down Expand Up @@ -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()
Expand Down
40 changes: 36 additions & 4 deletions Farmacia/Farmacia/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions Farmacia/Farmacia/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,51 @@
<Setting Name="IdGlobal" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="Data" Type="System.String" Scope="User">
<Value Profile="(Default)">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;</Value>
</Setting>
</Settings>
</SettingsFile>

0 comments on commit 82814ab

Please sign in to comment.