-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClienteFormulario.aspx.cs
executable file
·122 lines (101 loc) · 3.54 KB
/
ClienteFormulario.aspx.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ClienteFormulario : System.Web.UI.Page
{
string lat = null;
string lng = null;
protected void Page_Load(object sender, EventArgs e)
{
lat = hiddenLat.Value;
lng = hiddenLng.Value;
if (Request.QueryString["id"] == null)
{
titulo.InnerHtml = "Nuevo Cliente";
}
else
{
titulo.InnerHtml = "Editar Cliente";
PedidosDataContext db = new PedidosDataContext();
var temp = (from cli in db.Cliente
where cli.id_cliente == Convert.ToInt32(Request.QueryString["id"])
select cli).Single();
if (!IsPostBack)
{
txtNombre.Text = temp.razonSocial;
txtCUIT.Text = temp.cuit.ToString();
var dom = (from d in db.Domicilio
where d.id_domicilio == temp.id_cliente
select d).Single();
txtCalle.Text = dom.calle;
txtNro.Text = dom.numero.ToString();
txtLocalidad.Text = dom.localidad;
lat = dom.latitud;
lng = dom.longitud;
}
}
}
protected void btnGuardar_Click(object sender, EventArgs e)
{
PedidosDataContext db = new PedidosDataContext();
lat = hiddenLat.Value;
lng = hiddenLng.Value;
if (Request.QueryString["id"] == null)
{
Cliente cli = new Cliente();
cli.razonSocial = txtNombre.Text;
cli.cuit = txtCUIT.Text;
cli.saldo = 0;
db.Cliente.InsertOnSubmit(cli);
Domicilio dom = new Domicilio();
db.Domicilio.InsertOnSubmit(dom);
dom.calle = txtCalle.Text;
dom.numero = Convert.ToInt32(txtNro.Text);
dom.localidad = txtLocalidad.Text;
dom.latitud = lat;
dom.longitud = lng;
dom.tipo_domicilio = "PERSONAL";
dom.Cliente = cli;
db.SubmitChanges();
}
else
{
var temp = (from cli in db.Cliente
where cli.id_cliente == Convert.ToInt32(Request.QueryString["id"])
select cli).Single();
temp.razonSocial = txtNombre.Text;
temp.cuit = txtCUIT.Text;
db.SubmitChanges();
var dom = (from d in db.Domicilio
where d.id_domicilio == temp.id_cliente
select d).Single();
dom.calle = txtCalle.Text;
dom.numero = Convert.ToInt32(txtNro.Text);
dom.localidad = txtLocalidad.Text;
dom.latitud = lat;
dom.longitud = lng;
dom.tipo_domicilio = "PERSONAL";
dom.Cliente = temp;
db.SubmitChanges();
}
Response.Redirect("Clientes.aspx");
}
protected void btnCancelar_Click(object sender, EventArgs e)
{
Response.Redirect("Clientes.aspx");
}
protected void validaGeo_ServerValidate(object source, ServerValidateEventArgs args)
{
if (lat != null && lng != null)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
}