/
mediosdepago.aspx.cs
189 lines (177 loc) · 8.1 KB
/
mediosdepago.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Newtonsoft.Json;
using System.Net.Sockets;
using System.Net;
namespace MasTicket
{
public partial class mediosdepago : basepage
{
wsac.IsacClient ws;
TarjetasViewModel tvm;
RecargasViewModel rvm;
protected void Page_Load(object sender, EventArgs e)
{
//--------------------------------------------------------------------------------------------------
int idusr = 0;
if (!IsPostBack)
{
divMenu.InnerHtml = check.GeneraMenu();
ws = Session["wsac"] as wsac.IsacClient;
int hab = ws.GetMonederoHab();
if (hab == 1)
tbMonedero.Visible = true;
else
tbMonedero.Visible = false;
if (Session["idusrlogged"] != null)
{
if (int.TryParse(Session["idusrlogged"].ToString(), out idusr))
{
if (idusr > 0)
{
ws = Session["wsac"] as wsac.IsacClient;
string json = ws.GetUser(idusr, "", "");
List<Usuario> lu = JsonConvert.DeserializeObject<List<Usuario>>(json);
if (lu.Count > 0)
{
Session["usrlogged"] = lu.FirstOrDefault();
lblCtaNom.Text = lu.FirstOrDefault().name;
if (!String.IsNullOrEmpty(lu.FirstOrDefault().picture))
imgFoto.ImageUrl = lu.FirstOrDefault().picture;
else
imgFoto.ImageUrl = "assets/images/icono_app.png";
}
else
Response.Redirect("index.aspx");
}
else
Response.Redirect("index.aspx");
}
else
Response.Redirect("index.aspx");
}
}
else
{
if (Request["__EVENTTARGET"] == "lnkSalir")
{
Session["idusrlogged"] = 0;
Session["usrlogged"] = null;
Response.Redirect("index.aspx");
Session.Abandon();
Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));
}
}
//--------------------------------------------------------------------------------------------------
if (!IsPostBack)
{
ws = Session["wsac"] as wsac.IsacClient;
if (tvm == null)
{
tvm = new TarjetasViewModel();
Session["tvm"] = tvm;
}
tvm.WS = ws;
tvm.Inicia();
if (Session["rvm"] == null)
Response.Redirect("datosrecarga.aspx");
else
Refresh();
}
else
{
if (Request.Form["__EVENTTARGET"] == "selcard")
{
RecargasViewModel rvm = Session["rvm"] as RecargasViewModel;
rvm.IdTarjeta = int.Parse(Request.Form["__EVENTARGUMENT"].ToString());
rvm.TipoTrans = TipoTransaccion.SegundaVez;
rvm.idFormaPago = 2; //tarjeta
Session["rvm"] = rvm;
Response.Redirect("confir_recarga.aspx");
}
if (Request.Form["__EVENTTARGET"] == "delcard")
{
int idt = int.Parse(Request.Form["__EVENTARGUMENT"].ToString());
ws = Session["wsac"] as wsac.IsacClient;
if (ws.EliminaTarjeta(idt))
{
Response.Redirect("mediosdepago.aspx");
}
}
}
btnUsarMon.Click += (s, ea) =>
{
RecargasViewModel rvm = Session["rvm"] as RecargasViewModel;
rvm.idFormaPago = 1; //monedero
Session["rvm"] = rvm;
SaldoMonedero mon = Session["SaldoMonedero"] as SaldoMonedero;
ws = Session["wsac"] as wsac.IsacClient;
string jsonPq = ws.GetCatalogo(3, "");
List<catPaquete> lspq = JsonConvert.DeserializeObject<List<catPaquete>>(jsonPq);
if (lspq.Where(x => x.idpaquete == rvm.idpaquete).FirstOrDefault().monto > mon.saldo)
{
spnJS.Text = "<script>msgError('No tiene suficiente saldo');</script>";
Refresh();
}
else
Response.Redirect("confir_recarga.aspx");
};
btnNvaTarjeta.Click += (s, ea) =>
{
Response.Redirect("nuevatarjeta.aspx");
};
}
private void Refresh()
{
string json = "";
tvm = Session["tvm"] as TarjetasViewModel;
// monedero
json = ws.GetCatalogo(12, "where idusuario = " + Session["idusrlogged"].ToString());
List<SaldoMonedero> lsMon = JsonConvert.DeserializeObject<List<SaldoMonedero>>(json);
if (lsMon.Count() > 0)
{
Session["SaldoMonedero"] = lsMon.FirstOrDefault();
if (lsMon.FirstOrDefault().saldo > 0M)
{
lblSaldoMon.Text = lsMon.FirstOrDefault().saldo.ToString("c");
btnUsarMon.CssClass = "btn default btn-xs btn-primary white";
}
else
{
lblSaldoMon.Text = (0M).ToString("c");
btnUsarMon.CssClass = "btn disabled default btn-xs btn-primary white";
}
}
else
{
Session["SaldoMonedero"] = new SaldoMonedero();
lblSaldoMon.Text = (0M).ToString("c");
btnUsarMon.CssClass = "btn disabled default btn-xs btn-primary white";
}
json = "";
json = ws.GetCatalogo(9, "where idusuario = " + Session["idusrlogged"].ToString());
List<Tarjeta> lsTar = JsonConvert.DeserializeObject<List<Tarjeta>>(json);
foreach (Tarjeta t in lsTar)
{
HtmlTableRow row = new HtmlTableRow();
row.Cells.Add(new HtmlTableCell() { Width = "20%;", InnerHtml = "<img src='" + tvm.LsEmisores().Where(x => x.idemisor == t.idemisor).FirstOrDefault().img + "' />" });
row.Cells.Add(new HtmlTableCell() { Width = "30%;", InnerHtml = tvm.LsEmisores().Where(x => x.idemisor == t.idemisor).FirstOrDefault().emisor + " " + t.last4 });
//row.Cells.Add(new HtmlTableCell() { Width = "35%;", InnerHtml = tvm.LsEmisores().Where(x => x.idemisor == t.idemisor).FirstOrDefault().emisor + " " + t.last4 });
Label lbl = new Label();
lbl.Text = "<a id=\"sel" + t.idtarjeta.ToString() + "\" class=\"btn default btn-xs btn-primary white\" href=\"javascript:__doPostBack('selcard','" + t.idtarjeta.ToString() + "');\"><i class=\"fa fa-credit-card\"></i> Usar esta tarjeta</a> ";
Label lbldel = new Label();
lbldel.Text = "<a id=\"del" + t.idtarjeta.ToString() + "\" class=\"btn default btn-xs bg-black white\" href=\"javascript:borratarjeta(" + t.idtarjeta.ToString() + ");\"><i class=\"fa fa-trash\"></i> Borrar tarjeta</a>";
row.Cells.Add(new HtmlTableCell() { Width = "60%;" });
row.Cells[2].Controls.Add(lbl);
row.Cells[2].Controls.Add(lbldel);
row.Cells.Add(new HtmlTableCell() { Width = "15%;", InnerHtml = "" });
tbTarjetas.Rows.Add(row);
}
}
}
}