/
ArticuloPersist.cs
63 lines (38 loc) · 1.42 KB
/
ArticuloPersist.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Data;
using System.Collections;
using SerpisAd;
namespace PArticulo
{
public class ArticuloPersister
{
public static Articulo load(object id) {
IDbCommand dbCommand = App.Instance.DbConnection.CreateCommand ();
dbCommand.CommandText = "select * from articulo where id = @id";
DbCommandHelper.AddParameter (dbCommand, "id", id);
IDataReader dataReader = dbCommand.ExecuteReader ();
if (!dataReader.Read ())
//TODO throw exception
return artiuclo;
Articulo.nombre = (string)dataReader ["nombre"];
Articulo.categoria = dataReader ["categoria"];
if (Articulo.categoria is DBNull)
Articulo.categoria = null;
Articulo.precio = (decimal)dataReader ["precio"];
dataReader.Close ();
}
private static void insert() {
IDbCommand dbCommand = App.Instance.DbConnection.CreateCommand ();
dbCommand.CommandText = "insert into articulo (nombre, categoria, precio) " +
"values (@nombre, @categoria, @precio)";
nombre = entryNombre.Text;
categoria = ComboBoxHelper.GetId (comboBoxCategoria);
precio = Convert.ToDecimal(spinButtonPrecio.Value);
DbCommandHelper.AddParameter (dbCommand, "nombre", nombre);
DbCommandHelper.AddParameter (dbCommand, "categoria", categoria);
DbCommandHelper.AddParameter (dbCommand, "precio", precio);
dbCommand.ExecuteNonQuery ();
Destroy ();
}
}
}