示例#1
0
        protected void btnCadastrarObra_Click(object sender, EventArgs e)
        {
            obra.Titulo    = txtObra.Text;
            obra.Autor     = txtAutor.Text;
            obra.Aquisicao = Convert.ToDateTime(txtAquisicao.Text);
            obra.Local     = txtLocal.Text;
            obra.Status    = cbxStatus.Text;
            obra.Condicoes = cbxCondicoes.Text;
            obra.Valor     = txtSeguro.Text;
            obra.Descricao = txtDescricao.Text;

            bll.Create(obra);
            Clean();

            painelObras.Visible = false;
            panelTable.Visible  = true;
            GridObras.DataBind();
        }
        protected void btnAdicionarItem_Click(object sender, EventArgs e)
        {
            /*int i;
             * int linhasSelecionadas = 0;
             * for (i = 0; i < GridObras.Rows.Count - 1; i++)
             * {
             *  if (GridObras.SelectedRow == null)
             *  {
             *      Label1.Visible = true;
             *      Label1.Text = "por favor, selecione uma obra";
             *  }
             *  else
             *  if (GridObras.SelectedRow.RowState == DataControlRowState.Selected)
             *  {
             *      linhasSelecionadas++;
             *
             *      obra.Id = int.Parse(GridObras.Rows[i].Cells[0].ToString());
             *      obra.Local = "Evento: " + GridEventos.SelectedRow.Cells[1].ToString();
             *      obra.Status = "Em exposição";
             *
             *      bll.UpdateObra(obra);
             *      GridObras.DataBind();
             *
             *      GridEventos.SelectedRow.Cells[6].Text = GridObras.SelectedRow.Cells[1].Text;
             *
             *  }
             *  else
             *  {
             *      Label1.Visible = true;
             *      Label1.Text = "erro";
             *  }
             *
             * }*/

            foreach (GridViewRow rows in GridObras.Rows)
            {
                DropDownList cbx = (DropDownList)rows.FindControl("cbxObra");
            }



            int i;
            int j;

            try
            {
                //Saber se a obra selecionada pelo comboBox já está em atuando em evento
                for (i = 0; i < GridObras.Rows.Count - 1; i++)
                {
                    for (j = 0; j < GridObras.Columns.Count - 1; j++)
                    {
                        if (GridObras.Rows[i].Cells[j].Equals(cbxObra))
                        {
                            //dgvObras.ClearSelection();
                            //GridObras.Rows[i].Cells[j].Selected = true;
                            if (GridObras.Rows[i].Cells[5].ToString() == "Em exposição")
                            {
                                Label1.Visible = true;
                                Label1.Text    = "Obra em exposição.";
                                cbxObra.Text   = null;
                            }
                            else if (GridObras.Rows[i].Cells[5].ToString() != "Em exposição")
                            {
                                //Contagem de linhas na tabela itens

                                /*if (dgvItemEventos.Rows.Count == 1)
                                 * {
                                 *  //MessageBox.Show("Evento já possui obra alugada.");
                                 *  cbxObra.Text = null;
                                 * }
                                 *
                                 * //Se a obra estiver disponível e não houver obras alugadas no evento o qual está sendo criado ou editado
                                 * //Cria-se item/obra para evento
                                 * else
                                 * {*/
                                obra.Id     = int.Parse(GridObras.Rows[i].Cells[0].ToString());
                                obra.Local  = "Evento: " + txtNomeEvento.Text;
                                obra.Status = "Em exposição";

                                bll.UpdateObra(obra);
                                GridObras.DataBind();
                                //itemBll.Create(int.Parse(GridObras.Rows[i].Cells[0].ToString()), evento.Id);
                                //dgvItemEventos.DataBind();
                                //}
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Label1.Visible = true;
                Label1.Text    = "Erro: " + ex.Message;
            }
        }