protected void gvItens_PreRender(object sender, EventArgs e) { cpEntities db = new cpEntities(); foreach (GridViewRow row in gvItens.Rows) { int codigo = int.TryParse(row.Cells[0].Text, out codigo) ? codigo : 0; var stat = (from i in db.item where i.id.Equals(codigo) select i.status).FirstOrDefault(); if (stat.Equals("T")) { ((ImageButton)row.Cells[2].FindControl("btnStatus")).ImageUrl = "~/Imagens/sold.png"; ((ImageButton)row.Cells[2].FindControl("btnStatus")).Enabled = false; ((Label)row.Cells[2].FindControl("lblStatus")).Text = @"Alguém já marcou este presente. Eba! Eu vou adorar :D"; } else { ((ImageButton)row.Cells[2].FindControl("btnStatus")).ImageUrl = "~/Imagens/gift.png"; ((ImageButton)row.Cells[2].FindControl("btnStatus")).Enabled = true; ((Label)row.Cells[2].FindControl("lblStatus")).Text = "Quero dar este presente"; } } }
protected void gvItens_PreRender(object sender, EventArgs e) { cpEntities db = new cpEntities(); foreach(GridViewRow row in gvItens.Rows) { int codigo = int.TryParse(row.Cells[0].Text, out codigo) ? codigo : 0; var stat = (from i in db.item where i.id.Equals(codigo) select i.status).FirstOrDefault(); if (stat.Equals("T")) { ((ImageButton)row.Cells[2].FindControl("btnStatus")).ImageUrl = "~/Imagens/sold.png"; ((ImageButton)row.Cells[2].FindControl("btnStatus")).Enabled = false; ((Label)row.Cells[2].FindControl("lblStatus")).Text = @"Alguém já marcou este presente. Eba! Eu vou adorar :D"; } else { ((ImageButton)row.Cells[2].FindControl("btnStatus")).ImageUrl = "~/Imagens/gift.png"; ((ImageButton)row.Cells[2].FindControl("btnStatus")).Enabled = true; ((Label)row.Cells[2].FindControl("lblStatus")).Text = "Quero dar este presente"; } } }
private void bindarGrid() { cpEntities db = new cpEntities(); var listas = (from l in db.lista orderby l.descricao select l).ToList(); gvLista.DataSource = listas; gvLista.DataBind(); }
private void bindarGrid() { cpEntities db = new cpEntities(); var itens = (from i in db.item orderby i.descricao select i).ToList(); gvItens.DataSource = itens; gvItens.DataBind(); }
private void bindarListas() { cpEntities db = new cpEntities(); var listas = (from l in db.lista orderby l.descricao select l).ToList(); ddlLista.DataSource = listas; ddlLista.DataTextField = "descricao"; ddlLista.DataValueField = "id"; ddlLista.DataBind(); }
private void alterar() { cpEntities db = new cpEntities(); int id = int.Parse(hfID.Value); var lista = (from l in db.lista where l.id.Equals(id) select l).FirstOrDefault(); lista.descricao = txtDescricao.Text; db.SaveChanges(); }
private void alterar() { cpEntities db = new cpEntities(); int id = int.Parse(hfID.Value); var item = (from i in db.item where i.id.Equals(id) select i).FirstOrDefault(); item.descricao = txtDescricao.Text; item.idLista = int.Parse(ddlLista.SelectedValue); item.status = chkStatus.Checked.Equals(true) ? "T" : "F"; db.SaveChanges(); }
private void bindarGrid() { cpEntities db = new cpEntities(); var itens = (from i in db.item join l in db.lista on i.idLista equals l.id orderby i.descricao select new { id = i.id, descricao = i.descricao, lista = l.descricao }).ToList(); gvItens.DataSource = itens; gvItens.DataBind(); }
protected void gvItens_RowCommand(object sender, GridViewCommandEventArgs e) { if(e.CommandName.Equals("status")) { cpEntities db = new cpEntities(); int index = int.TryParse(e.CommandArgument.ToString(), out index) ? index : 0; int id = int.TryParse(gvItens.Rows[index].Cells[0].Text, out id) ? id : 0; var edit = (from i in db.item where i.id.Equals(id) select i).FirstOrDefault(); if(edit.status.Equals("F")) edit.status = "T"; db.SaveChanges(); bindarGrid(); } }
private void salvar() { cpEntities db = new cpEntities(); item objItem = new item(); int lista = int.TryParse(ddlLista.SelectedValue, out lista) ? lista : lista; int id = (from i in db.item orderby i.id descending select i.id).FirstOrDefault(); id++; objItem.id = id; objItem.descricao = txtDescricao.Text; objItem.idLista = lista; objItem.status = chkStatus.Checked.Equals(true) ? "T" : "F"; db.item.Add(objItem); db.SaveChanges(); }
protected void gvItens_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("Editar")) { hfOperacao.Value = "E"; cpEntities db = new cpEntities(); int index = int.TryParse(e.CommandArgument.ToString(), out index) ? index : 0; int id = int.TryParse(gvItens.Rows[index].Cells[2].Text, out id) ? id : 0; var item = (from i in db.item where i.id.Equals(id) select i).FirstOrDefault(); txtDescricao.Text = item.descricao; ddlLista.SelectedValue = item.idLista.ToString(); chkStatus.Checked = item.status.Equals("T") ? true : false; hfID.Value = item.id.ToString(); mvItem.SetActiveView(vwCadastro); } else if (e.CommandName.Equals("Excluir")) { cpEntities db = new cpEntities(); int index = int.TryParse(e.CommandArgument.ToString(), out index) ? index : 0; int id = int.TryParse(gvItens.Rows[index].Cells[2].Text, out id) ? id : 0; var item = (from i in db.item where i.id.Equals(id) select i).FirstOrDefault(); db.item.Remove(item); db.SaveChanges(); bindarGrid(); } }
protected void gvItens_RowCommand(object sender, GridViewCommandEventArgs e) { if(e.CommandName.Equals("Editar")) { hfOperacao.Value = "E"; cpEntities db = new cpEntities(); int index = int.TryParse(e.CommandArgument.ToString(), out index) ? index : 0; int id = int.TryParse(gvItens.Rows[index].Cells[2].Text, out id) ? id : 0; var item = (from i in db.item where i.id.Equals(id) select i).FirstOrDefault(); txtDescricao.Text = item.descricao; ddlLista.SelectedValue = item.idLista.ToString(); chkStatus.Checked = item.status.Equals("T") ? true : false; hfID.Value = item.id.ToString(); mvItem.SetActiveView(vwCadastro); } else if(e.CommandName.Equals("Excluir")) { cpEntities db = new cpEntities(); int index = int.TryParse(e.CommandArgument.ToString(), out index) ? index : 0; int id = int.TryParse(gvItens.Rows[index].Cells[2].Text, out id) ? id : 0; var item = (from i in db.item where i.id.Equals(id) select i).FirstOrDefault(); db.item.Remove(item); db.SaveChanges(); bindarGrid(); } }
private void salvar() { cpEntities db = new cpEntities(); lista objLista = new lista(); int id = (from l in db.lista orderby l.id descending select l.id).FirstOrDefault(); if (id > 0) { objLista.id = id; } else { objLista.id = 1; } objLista.descricao = txtDescricao.Text; db.lista.Add(objLista); db.SaveChanges(); }
protected void gvLista_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("Editar")) { cpEntities db = new cpEntities(); hfTipoOperacao.Value = "E"; int index = int.TryParse(e.CommandArgument.ToString(), out index) ? index : 0; int id = int.TryParse(gvLista.Rows[index].Cells[2].Text, out id) ? id : 0; var lista = (from l in db.lista where l.id.Equals(id) select l).FirstOrDefault(); hfID.Value = lista.id.ToString(); txtDescricao.Text = lista.descricao; mvLista.SetActiveView(vwCadastro); } else if (e.CommandName.Equals("Excluir")) { cpEntities db = new cpEntities(); int index = int.TryParse(e.CommandArgument.ToString(), out index) ? index : 0; int id = int.TryParse(gvLista.Rows[index].Cells[2].Text, out id) ? id : 0; var lista = (from l in db.lista where l.id.Equals(id) select l).FirstOrDefault(); db.lista.Remove(lista); db.SaveChanges(); bindarGrid(); } }
protected void gvLista_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("Editar")) { cpEntities db = new cpEntities(); hfTipoOperacao.Value = "E"; int index = int.TryParse(e.CommandArgument.ToString(), out index) ? index : 0; int id = int.TryParse(gvLista.Rows[index].Cells[2].Text, out id) ? id : 0; var lista = (from l in db.lista where l.id.Equals(id) select l).FirstOrDefault(); hfID.Value = lista.id.ToString(); txtDescricao.Text = lista.descricao; mvLista.SetActiveView(vwCadastro); } else if(e.CommandName.Equals("Excluir")) { cpEntities db = new cpEntities(); int index = int.TryParse(e.CommandArgument.ToString(), out index) ? index : 0; int id = int.TryParse(gvLista.Rows[index].Cells[2].Text, out id) ? id : 0; var lista = (from l in db.lista where l.id.Equals(id) select l).FirstOrDefault(); db.lista.Remove(lista); db.SaveChanges(); bindarGrid(); } }
protected void gvItens_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("status")) { cpEntities db = new cpEntities(); int index = int.TryParse(e.CommandArgument.ToString(), out index) ? index : 0; int id = int.TryParse(gvItens.Rows[index].Cells[0].Text, out id) ? id : 0; var edit = (from i in db.item where i.id.Equals(id) select i).FirstOrDefault(); if (edit.status.Equals("F")) { edit.status = "T"; } db.SaveChanges(); bindarGrid(); } }
private void salvar() { cpEntities db = new cpEntities(); lista objLista = new lista(); int id = (from l in db.lista orderby l.id descending select l.id).FirstOrDefault(); if (id > 0) objLista.id = id; else objLista.id = 1; objLista.descricao = txtDescricao.Text; db.lista.Add(objLista); db.SaveChanges(); }