protected void Page_Load(object sender, EventArgs e) { SQLTrans.CrudServiceClient client = new SQLTrans.CrudServiceClient(); SQLTrans.LoginData ldata = (SQLTrans.LoginData)Session["userdata"]; string text = Request["s"]; if (text != "") { string platillos = ""; string tipo = Request["tipo"]; foreach (SQLTrans.Platillos p in client.buscarPlatillo(text)) { if (tipo != null) { if (Convert.ToInt32(tipo) != p.ID_TIPO) { continue; } } platillos += string.Concat("<tr><td><img src='", (p.URL == null || p.URL == "") ? "/images/sin-imagen.gif" : p.URL, "' height='200px' width='200px' /></td><td>", p.NOMBRE, "</td><td>", p.TIPO, "</td><td>", p.RESTAURANTE, "</td><td>$", Math.Round(p.PRECIO, 2), "</td><td><a href=Platos.aspx?id=", p.ID_PLATILLOS, ">Ver</a> "); if (ldata != null) { if (ldata.isAdmin) { platillos += string.Concat("<a href=Platos.aspx?id=", p.ID_PLATILLOS, "&action=edit>Editar</a> <a href=Platos.aspx?id=", p.ID_PLATILLOS, "&action=delete OnClick=\"if ( ! UserDeleteConfirmation()) return false;\">Eliminar</a></td></tr>\n"); } } } tbody.InnerHtml = platillos; } }
protected void Button1_Click(object sender, EventArgs e) { SQLTrans.CrudServiceClient client = new SQLTrans.CrudServiceClient(); DataSet ds = client.sp_ValidarUsuario(txtUser.Text, txtPass.Text); string user = ""; if (ds.Tables[0].Rows.Count > 0) { try { user = ds.Tables[0].Rows[0][0].ToString(); } catch { } if (user != txtUser.Text) { Session.Remove("userdata"); output.Text = "Usuario o Password incorrectos!"; } else { SQLTrans.LoginData linfo = new SQLTrans.LoginData(); linfo.USER = txtUser.Text; linfo.PASS = txtPass.Text; linfo.isAdmin = client.isAdmin(linfo.USER); Session["userdata"] = linfo; Response.Redirect("Default.aspx"); } } }
private void BtnEdit_Click(object sender, EventArgs e) { SQLTrans.LoginData ldata = ((SQLTrans.LoginData)Session["userdata"]); try { int img = -1; string name = ""; string url = ""; if (upload.HasFile) { name = clases.Tools.ImgName(upload.FileName, Server.MapPath("~/images/")); url = "/images/" + name; img = client.sp_AgregarImagen(ldata, url); upload.SaveAs(Server.MapPath(Path.Combine("~/images/", name))); } int id = int.Parse(Request["id"]); client.sp_AlterPlatillo(ldata, id, Convert.ToInt32(ddRestaurantes.SelectedValue), img, Convert.ToInt32(ddTipos.SelectedValue), txtNombre.Text, float.Parse(txtPrecio.Text), txtDescripcion.Text); output.Text = "Transaccion realizada!"; } catch (Exception ex) { Console.WriteLine(ex.Message); output.Text = "Ocurrio un error!"; } }
private void BtnEdit_Click(object sender, EventArgs e) { SQLTrans.LoginData ldata = ((SQLTrans.LoginData)Session["userdata"]); SQLTrans.CrudServiceClient client = new SQLTrans.CrudServiceClient(); try { int img = -1; string name = ""; string url = ""; if (upload.HasFile) { name = clases.Tools.ImgName(upload.FileName, Server.MapPath("~/images/")); url = "/images/" + name; img = client.sp_AgregarImagen(ldata, url); upload.SaveAs(Server.MapPath(Path.Combine("~/images/", name))); } string id = Request["id"].ToString(); if (ldata.isAdmin) { client.sp_AlterUsuario(ldata, id, img, txtNombre.Text, txtApellido.Text, txtCorreo.Text, txtBirth.Text, chkAdmin.Checked, null); } else { client.sp_AlterUsuario(ldata, id, img, txtNombre.Text, txtApellido.Text, txtCorreo.Text, txtBirth.Text, ldata.isAdmin, null); } output.Text = "Transaccion realizada!"; } catch (Exception ex) { Console.WriteLine(ex.Message); output.Text = "Ocurrio un error!"; } }
protected void Page_Load(object sender, EventArgs e) { SQLTrans.LoginData ldata = ((SQLTrans.LoginData)Session["userdata"]); if (ldata == null) { Response.Redirect("Default.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { string[] stipos = new SQLTrans.CrudServiceClient().GetTiposPlatillo(); LiteralControl tipos = new LiteralControl(); SQLTrans.Comentarios[] c = new SQLTrans.CrudServiceClient().GetLastsComentarios(); string lc = ""; foreach (SQLTrans.Comentarios i in c) { string url = i.URL; if (url == "" || url == null) { url = "/images/sin-imagen.gif"; } lc += $"<li><a href=#><img src={url} class='avatar avatar-40 photo' height='40' width='40'></a> <a href='Platos.aspx?id={i.ID_PLATILLOS}'>{i.ID_USUARIO}: </a>{i.COMENTARIOS}<div class=clear></div></li>"; } lastcomments.InnerHtml = lc; foreach (string t in stipos) { string[] sp = t.Split(','); tipos.Text += $"<li id=class='menu-item menu-item-type-taxonomy menu-item-object-category'><a href='Platos.aspx?tipo={sp[0]}'>{sp[1]}</a></li>"; } tipoplatillo.Controls.Add(tipos); if (Request["logout"] != null) { Session.Clear(); } if (Session["userdata"] != null) { SQLTrans.LoginData ldata = ((SQLTrans.LoginData)Session["userdata"]); try { new SQLTrans.CrudServiceClient().sp_AgregarEstadistica(ldata); } catch { } LiteralControl submenu = new LiteralControl(); user.InnerText = ldata.USER; user.HRef = "~/Users.aspx?id=" + ldata.USER; if (ldata.isAdmin) { signin.InnerText = "Crear Usuarios"; } else { signin.Attributes.Add("style", "display:none;"); } submenu.Text = string.Concat("<ul class='sub-menu' style='display: none; visibility: hidden;'>", "<li id = 'menu-item-47' class='menu-item menu-item-type-post_type menu-item-object-page'><a href = 'ARestaurantes.aspx' >Agregar Restaurante</a></li>", "<li id = 'menu-item-43' class='menu-item menu-item-type-post_type menu-item-object-page'><a href = 'APlatos.aspx' >Agregar Platillo</a></li>", "<li id = 'menu-item-142' class='menu-item menu-item-type-custom menu-item-object-custom'><a href = 'AlterPass.aspx' >Cambiar Password</a></li>" , (!ldata.isAdmin) ? $"<li id = 'menu-item-143' class='menu-item menu-item-type-custom menu-item-object-custom'><a href = 'Users.aspx?id={ldata.USER}&edit=true' >Cambiar perfil</a></li>" : "" , (ldata.isAdmin) ? "<li id = 'menu-item-144' class='menu-item menu-item-type-custom menu-item-object-custom'><a href = 'Users.aspx' >Ver usuarios</a></li>" : "" , (ldata.isAdmin) ? "<li id = 'menu-item-145' class='menu-item menu-item-type-custom menu-item-object-custom'><a href = 'History.aspx' >Ver historial</a></li>" : "" , "<li id = 'menu-item-143' class='menu-item menu-item-type-custom menu-item-object-custom'><a href = 'Default.aspx?Logout=true' >Cerrar sesion</a></li></ul>"); usermenu.Controls.Add(submenu); } }
protected void Page_Load(object sender, EventArgs e) { SQLTrans.CrudServiceClient client = new SQLTrans.CrudServiceClient(); int inicio = 1, fin = 10; if (Session["userdata"] != null) { SQLTrans.LoginData ldata = ((SQLTrans.LoginData)Session["userdata"]); if (Request["inicio"] != null && Request["fin"] != null) { try { inicio = Convert.ToInt32(Request["inicio"]); fin = Convert.ToInt32(Request["fin"]); } catch { inicio = 0; fin = 10; output.Text = "Valores no validos en parametros!"; } } string logs = ""; if (!ldata.isAdmin && Request["id"] == null) { output.Text = MSGNOGRANT; } else { foreach (SQLTrans.Logs l in client.GetLogs(ldata, inicio, fin)) { string t = ""; switch (l.TIPO) { case 'C': t = "Creacion"; break; case 'U': t = "Actualizacion"; break; case 'D': t = "Eliminacion"; break; default: t = "Desconocido"; break; } logs += $"<tr><td>{l.ID_USUARIO}</td><td>{t}</td><td>{l.TABLA}</td><td>{DateTime.Parse(l.CREACION).ToShortDateString()}</td></tr>"; } string h = ""; if (inicio - 10 < 0) { h = "display:none;"; } logs += $"<tr><td><a style='text-align:right;{h}' href=History.aspx?inicio={inicio-10}&fin={fin-10}>Anterior</a></td><td></td><td></td><td style='text-align:right;'><a href=History.aspx?inicio={inicio+10}&fin={fin+10}>Siguiente</a></td></tr>"; tbody.InnerHtml = logs; } } }
protected void Page_Load(object sender, EventArgs e) { int.TryParse(Request["id"], out id); ldata = ((SQLTrans.LoginData)Session["userdata"]); if (!IsPostBack) { int v = 0; if (ldata == null) { return; } v = client.GetValoracion(ldata.USER, id); switch (v) { case 1: star1.Checked = true; break; case 2: star2.Checked = true; break; case 3: star3.Checked = true; break; case 4: star4.Checked = true; break; case 5: star5.Checked = true; break; default: star1.Checked = false; star2.Checked = false; star3.Checked = false; star4.Checked = false; star5.Checked = false; break; } } }
protected void btnChange_Click(object sender, EventArgs e) { SQLTrans.LoginData ldata = ((SQLTrans.LoginData)Session["userdata"]); if (ldata.PASS != txtOldPass.Text) { output.Text = "Escriba el password actual correctamente"; return; } else { try { SQLTrans.Usuarios u = client.GetUsuario(ldata.USER)[0]; client.sp_AlterUsuario(ldata, ldata.USER, -1, u.NOMBRE, u.APELLIDO, u.CORREO_ELECTRONICO, u.FECHA_CUMPLE, u.ADMIN, txtPass1.Text); Session.Clear(); Response.Redirect("Login.aspx"); } catch { output.Text = "No se pudo completar la trasaccion"; } } }
protected void btnComment_Click(object sender, EventArgs e) { SQLTrans.LoginData ldata = ((SQLTrans.LoginData)Session["userdata"]); try { if (ldata == null) { output.Text = MSGNOGRANT; return; } if (txtComment.Text.Trim().Length < 5) { output.Text = "No hay nada que comentar, minimo 5 letras!"; return; } client.sp_AgregarComentario(ldata, Request["id"], txtComment.Text); Response.Redirect(Request.RawUrl); } catch { output.Text = "Ocurrio un error en la transaccion!"; } }
private void BtnEdit_Click(object sender, EventArgs e) { SQLTrans.LoginData ldata = ((SQLTrans.LoginData)Session["userdata"]); try { int img = -1; string name = ""; string url = ""; if (upload.HasFile) { name = clases.Tools.ImgName(upload.FileName, Server.MapPath("~/images/")); url = "/images/" + name; img = client.sp_AgregarImagen(ldata, url); upload.SaveAs(Server.MapPath(Path.Combine("~/images/", name))); } int id = int.Parse(Request["id"]); client.sp_AlterRestaurant(ldata, id, img, -1, txtNombre.Text, txtReferencia.Text); output.Text = "Transaccion realizada!"; } catch (Exception) { output.Text = "Ocurrio un error!"; } }
protected void Page_Load(object sender, EventArgs e) { SQLTrans.LoginData ldata = ((SQLTrans.LoginData)Session["userdata"]); bool admin = false; if (ldata != null) { admin = ldata.isAdmin; } if (!admin && (Request["action"] == "edit" || Request["action"] == "delete")) { output.Text = MSGNOGRANT; } else if (Request["id"] != null) { int id = Convert.ToInt32(Request["id"]); if (Request["action"] == "delete") { try { client.sp_Delete(ldata, SQLTrans.DeleteType.Restaurante, id); output.Text = MSGDEL; } catch { output.Text = MSGNODEL; } return; } if (Request["action"] == "edit") { Button btnEdit = new Button(); Button btnDel = new Button(); btnEdit.Text = "Editar"; btnDel.Text = "Eliminar"; btnDel.OnClientClick = "if ( ! UserDeleteConfirmation()) return false;"; btnDel.Click += BtnDel_Click; btnEdit.Click += BtnEdit_Click; editcontrols.Controls.Add(btnEdit); editcontrols.Controls.Add(btnDel); txtNombre.ReadOnly = false; txtReferencia.ReadOnly = false; upload.Enabled = true; upload.CssClass = ""; } portrait.Attributes.Remove("class"); SQLTrans.Restaurantes restaurants; try { restaurants = client.GetRestaurante(id)[0]; } catch { output.Text = MSGNODISH; return; } if (!IsPostBack) { if (restaurants.URL == null || restaurants.URL == "") { img.ImageUrl = "/images/sin-imagen.gif"; } else { img.ImageUrl = restaurants.URL; } txtNombre.Text = restaurants.NOMBRE; txtReferencia.Text = restaurants.REFERENCIA; } } else { userlist.Attributes.Remove("class"); string locales = ""; foreach (SQLTrans.Restaurantes r in client.GetRestaurantes()) { locales += string.Concat("<tr><td><img src='", (r.URL == null || r.URL == string.Empty) ? "/images/sin-imagen.gif" : r.URL, "' height='200px' width='200px' /></td><td>", r.NOMBRE, "</td><td>", r.REFERENCIA, "</td><td>", r.RATE == "" ?"Sin Datos" : Math.Round(double.Parse(r.RATE), 2).ToString(), "</td><td><a href=Locales.aspx?id=", r.ID, ">Ver</a> "); if (ldata != null) { if (ldata.isAdmin) { locales += string.Concat("<a href=Locales.aspx?id=", r.ID, "&action=edit>Editar</a> <a href=Locales.aspx?id=", r.ID, "&action=delete onclick=\"if ( ! UserDeleteConfirmation()) return false;\">Eliminar</a></td></tr>\n"); } } } tbody.InnerHtml = locales; } }
protected void Page_Load(object sender, EventArgs e) { SQLTrans.Restaurantes[] restaurantes = client.GetRestaurantes(); SQLTrans.LoginData ldata = ((SQLTrans.LoginData)Session["userdata"]); bool admin = false; string[] tipos = client.GetTiposPlatillo(); if (ldata != null) { admin = ldata.isAdmin; } if (!admin && (Request["action"] == "edit" || Request["action"] == "delete")) { output.Text = MSGNOGRANT; } else if (Request["id"] != null) { int id = Convert.ToInt32(Request["id"]); if (Request["action"] == "delete") { try { client.sp_Delete(ldata, SQLTrans.DeleteType.Platillo, id); output.Text = MSGDEL; } catch { output.Text = MSGNODEL; } return; } if (Request["commentdelete"] != null) { try { int i = Convert.ToInt32(Request["commentdelete"]); client.sp_Delete(ldata, SQLTrans.DeleteType.Comentario, i); output.Text = "Comentario eliminado!"; } catch (Exception) { output.Text = "Ocurrio un error!"; } } if (Request["action"] == "edit") { Button btnEdit = new Button(); Button btnDel = new Button(); btnEdit.Text = "Editar"; btnDel.Text = "Eliminar"; btnDel.OnClientClick = "if ( ! UserDeleteConfirmation()) return false;"; btnDel.Click += BtnDel_Click; btnEdit.Click += BtnEdit_Click; editcontrols.Controls.Add(btnEdit); editcontrols.Controls.Add(btnDel); ddRestaurantes.Enabled = true; ddTipos.Enabled = true; txtNombre.ReadOnly = false; txtDescripcion.ReadOnly = false; txtPrecio.ReadOnly = false; upload.Enabled = true; upload.CssClass = ""; } foreach (SQLTrans.Restaurantes r in restaurantes) { ddRestaurantes.Items.Add(new ListItem(r.NOMBRE, r.ID.ToString())); } foreach (string t in tipos) { string[] sp = t.Split(','); ddTipos.Items.Add(new ListItem(sp[1], sp[0])); } portrait.Attributes.Remove("class"); SQLTrans.Platillos dish; try { dish = client.GetPlatillo(id)[0]; } catch { output.Text = MSGNOUSER; return; } rate.Controls.Add(LoadControl("rating.ascx")); if (!IsPostBack) { if (dish.URL == null || dish.URL == "") { img.ImageUrl = "/images/sin-imagen.gif"; } else { img.ImageUrl = dish.URL; } cdish.Text = dish.NOMBRE; txtNombre.Text = dish.NOMBRE; txtDescripcion.Text = dish.DESCRIPCION; txtPrecio.Text = Math.Round(dish.PRECIO, 2).ToString(); ddRestaurantes.SelectedValue = dish.ID_RESTAURANTES.ToString(); ddTipos.SelectedValue = dish.ID_TIPO.ToString(); dishrate.Text = dish.RATE == 0 ? "Sin datos" : Math.Round(dish.RATE, 2).ToString(); } SQLTrans.Comentarios[] comments = client.GetComentarios(id); string comentarios = string.Concat(comments.Length, " Comentarios\n<ol class='commentlist'>"); foreach (SQLTrans.Comentarios c in comments) { string url = (c.URL == null || c.URL == string.Empty) ? "/images/sin-imagen.gif" : c.URL; comentarios = string.Concat(comentarios, $"<li class='comment byuser comment-author-demoadmin bypostauthor even thread-even depth-1' id='li-comment-{c.ID_COMENTARIOS}'>", $"<div id='comment-{c.ID_COMENTARIOS}'><div class='comment-author vcard'>", $"<img src='{url}' clas='avatar avatar-48 photo' height='48' width='48'>", "<cite class='fn'>", "<a href='Users.aspx?id=", c.ID_USUARIO, "'>", c.ID_USUARIO, "</a> <small><br/>", c.FECHA, "</small></div><div class='comment-body'><p>", c.COMENTARIOS, "</p></div><div class='reply'><a href='Platos.aspx?id=", id, "&commentdelete=", c.ID_COMENTARIOS, "'", (!admin) ? " class=hidden " : "", ">Eliminar</a></div></div></li>"); } comentarios = string.Concat(comentarios, "</ol>"); divcomments.InnerHtml = comentarios; if (ldata != null) { commentform.Attributes.Remove("class"); } } else { userlist.Attributes.Remove("class"); string platillos = ""; string tipo = Request["tipo"]; foreach (SQLTrans.Platillos p in client.GetPlatillos()) { if (tipo != null) { if (Convert.ToInt32(tipo) != p.ID_TIPO) { continue; } } platillos += string.Concat("<tr><td><img src='", (p.URL == null || p.URL == "") ? "/images/sin-imagen.gif" : p.URL, "' height='200px' width='200px' /></td><td>", p.NOMBRE, "</td><td>", p.TIPO, "</td><td>", p.RESTAURANTE, "</td><td>$", Math.Round(p.PRECIO, 2), "</td><td><a href=Platos.aspx?id=", p.ID_PLATILLOS, ">Ver</a> "); if (ldata != null) { if (ldata.isAdmin) { platillos += string.Concat("<a href=Platos.aspx?id=", p.ID_PLATILLOS, "&action=edit>Editar</a> <a href=Platos.aspx?id=", p.ID_PLATILLOS, "&action=delete OnClick=\"if ( ! UserDeleteConfirmation()) return false;\">Eliminar</a></td></tr>\n"); } } } tbody.InnerHtml = platillos; } }
protected void Page_Load(object sender, EventArgs e) { SQLTrans.CrudServiceClient client = new SQLTrans.CrudServiceClient(); if (Session["userdata"] != null) { SQLTrans.LoginData ldata = ((SQLTrans.LoginData)Session["userdata"]); if (!ldata.isAdmin && Request["id"] == null) { output.Text = MSGNOGRANT; } else if (Request["id"] != null) { portrait.Attributes.Remove("class"); string id = Request["id"]; if (Request["action"] == "edit" && ldata.isAdmin) { Button btnEdit = new Button(); btnEdit.Text = "Editar"; btnEdit.Click += BtnEdit_Click; editcontrols.Controls.Add(btnEdit); txtApellido.ReadOnly = false; txtBirth.ReadOnly = false; txtCorreo.ReadOnly = false; txtNombre.ReadOnly = false; chkAdmin.Enabled = true; } else if (Request["edit"] == "true" && ldata.USER == Request["id"]) { Button btnEdit = new Button(); btnEdit.Text = "Editar"; btnEdit.Click += BtnEdit_Click; editcontrols.Controls.Add(btnEdit); txtApellido.ReadOnly = false; txtBirth.ReadOnly = false; txtCorreo.ReadOnly = false; txtNombre.ReadOnly = false; } SQLTrans.Usuarios user; try { user = client.GetUsuario(id)[0]; } catch { output.Text = MSGNOUSER; return; } username.Text = id; if (!IsPostBack) { if (user.URL == null || user.URL == "") { img.ImageUrl = "/images/sin-imagen.gif"; } else { img.ImageUrl = user.URL; } chkAdmin.Checked = client.isAdmin(id); txtNombre.Text = user.NOMBRE; txtApellido.Text = user.APELLIDO; txtBirth.Text = Convert.ToDateTime(user.FECHA_CUMPLE).ToShortDateString(); txtCorreo.Text = user.CORREO_ELECTRONICO; lcount.Text = user.VISITAS.ToString(); } } else { userlist.Attributes.Remove("class"); string users = ""; foreach (SQLTrans.Usuarios u in client.GetUsuarios()) { users += string.Concat("<tr><td>", u.ID_USUARIO, "</td><td>", u.ADMIN ? "Admin" : "Usuario", "</td><td>", u.CORREO_ELECTRONICO, "</td><td><a href=Users.aspx?id=", u.ID_USUARIO, ">Ver</a> <a href=Users.aspx?id=", u.ID_USUARIO, "&action=edit>Editar</a></td></tr>\n"); } tbody.InnerHtml = users; } } else { output.Text = MSGNOGRANT; } }