protected bool Autenticar(string usuario, string pass) { using (dbLQDataContext db = new dbLQDataContext()) { try { int user = (from c in db.usuarios where c.idusuario == usuario where c.clave == pass select c).Count(); if (user != 0) { bool admin = (from c in db.usuarios where c.idusuario == usuario where c.clave == pass select c.admin).First(); Session["idUsuario"] = usuario; Session["admin"] = admin; return(true); } else { return(false); } } catch { return(false); } } }
protected void lsvDatos_ItemDeleting(object sender, ListViewDeleteEventArgs e) { ListViewItem it = lsvDatos.Items[e.ItemIndex]; int usado; using (dbLQDataContext db = new dbLQDataContext()) { usado = (from c in db.disenos where c.idcrema == int.Parse(e.Keys[0].ToString()) select c).Count(); } if (usado > 0) { ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('El item no puede eliminarse debido a que está siendo utilizado en un diseño');", true); //Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert", "", true); e.Cancel = true; } else { Image img = (Image)it.FindControl("imagenLabel"); try { System.IO.File.Delete(Server.MapPath("~/Materiales/cremas/" + System.IO.Path.GetFileName(img.ImageUrl))); } catch { } } }
protected int AgregarDiseño() { using (dbLQDataContext db = new dbLQDataContext()) { diseno nuevo_diseno = new diseno { nombre = txtNombre.Text.Trim(), idbase = int.Parse(lsvMasas.SelectedDataKey.Value.ToString()), idcrema = int.Parse(lsvCrema.SelectedDataKey.Value.ToString()), idtopping = int.Parse(lsvtopping.SelectedDataKey.Value.ToString()), }; if (User.Identity.IsAuthenticated) { nuevo_diseno.idusuario = User.Identity.Name; } else { nuevo_diseno.idusuario = "anonimo"; } db.disenos.InsertOnSubmit(nuevo_diseno); db.SubmitChanges(); return(nuevo_diseno.iddiseno); } }
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e) { if (!HttpContext.Current.User.Identity.IsAuthenticated) { FormsAuthentication.RedirectToLoginPage(); e.Cancel = true; } else if ((dtpCalendario.SelectedDate < DateTime.Now.AddDays(1)) || (txtDirEntrega.Text.Trim() == "") || (txtDirFactura.Text.Trim() == "")) { lblValidar.Visible = true; e.Cancel = true; } else //Guardando Pedido { using (dbLQDataContext db = new dbLQDataContext()) { pedido nuevo_pedido = new pedido { idusuario = HttpContext.Current.User.Identity.Name, fecha = DateTime.Now, fecha_entrega = dtpCalendario.SelectedDate, dir_entrega = txtDirEntrega.Text.Trim(), dir_factura = txtDirFactura.Text.Trim(), subtotal = precioTotal, iva = precioTotal * decimal.Parse("0.13"), total = precioTotal * decimal.Parse("0.13") + precioTotal }; List <ListaCompras> listado = (List <ListaCompras>)Session["ListaCompras"]; foreach (ListaCompras item in listado) { pedido_detalle cupcake = new pedido_detalle { iddiseno = item.iddiseno, cantidad = item.cantidad, precio = item.precio, }; nuevo_pedido.pedido_detalles.Add(cupcake); } db.pedidos.InsertOnSubmit(nuevo_pedido); try { db.SubmitChanges(); } catch (ChangeConflictException) { db.ChangeConflicts.ResolveAll(RefreshMode.KeepCurrentValues); db.SubmitChanges(); } //Response.Redirect("~/Clientes/Pedidos.aspx"); } } }
protected void btnRegistrar_Click(object sender, EventArgs e) { if (Page.IsValid) { using (dbLQDataContext db = new dbLQDataContext()) { try { int usua = (from c in db.usuarios where c.idusuario == UserName.Text.Trim() select c.idusuario).Count(); if (usua > 0) { ErrorMessage1.Text = "El usuario ya existe."; } else { usuario nuevo = new usuario { idusuario = UserName.Text.Trim(), correo = Email.Text.Trim(), clave = Password.Text.Trim(), }; db.usuarios.InsertOnSubmit(nuevo); db.SubmitChanges(); bool admin = (from c in db.usuarios where c.idusuario == UserName.Text.Trim() where c.clave == Password.Text.Trim() select c.admin).First(); Session["idUsuario"] = UserName.Text.Trim(); Session["admin"] = admin; FormsAuthentication.RedirectFromLoginPage(UserName.Text, false); } } catch (ChangeConflictException) { db.ChangeConflicts.ResolveAll(RefreshMode.KeepCurrentValues); db.SubmitChanges(); } catch (Exception) { ErrorMessage1.Text = "Ha ocurrido un problema. El proceso de registro no pudo completarse satisfactoriamente. Por favor, intentelo en otro momento."; //throw; } } //FormsAuthentication.SetAuthCookie(UserName.Text, false /* createPersistentCookie */); } else { ErrorMessage1.Text = "(*) Campos obligatorios"; } }
public ListaCompras(int ID, int idDiseno, int cant) { this.id = ID; this.iddiseno = idDiseno; this.cantidad = cant; using (dbLQDataContext db = new dbLQDataContext()) { diseno dis = (from c in db.disenos where c.iddiseno == this.iddiseno select c).First(); this.precio = decimal.Parse(([email protected] + dis.crema.precio + dis.topping.precio).ToString()); this.nombre = dis.nombre; urlbase = "~/Materiales/masas/" + [email protected]; urlcrema = "~/Materiales/cremas/" + dis.crema.imagen; urltop = "~/Materiales/topping/" + dis.topping.imagen; } }