Example #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     SQLTrans.Restaurantes[] restaurantes = client.GetRestaurantes();
     string[] tipos = client.GetTiposPlatillo();
     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(',');
         ddCategorias.Items.Add(new ListItem(sp[1], sp[0]));
     }
 }
        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>&emsp;");
                    if (ldata != null)
                    {
                        if (ldata.isAdmin)
                        {
                            locales += string.Concat("<a href=Locales.aspx?id=", r.ID, "&action=edit>Editar</a>&emsp;<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>&emsp;");
                    if (ldata != null)
                    {
                        if (ldata.isAdmin)
                        {
                            platillos += string.Concat("<a href=Platos.aspx?id=", p.ID_PLATILLOS, "&action=edit>Editar</a>&emsp;<a href=Platos.aspx?id=", p.ID_PLATILLOS, "&action=delete OnClick=\"if ( ! UserDeleteConfirmation()) return false;\">Eliminar</a></td></tr>\n");
                        }
                    }
                }
                tbody.InnerHtml = platillos;
            }
        }