예제 #1
0
        private void tsbCadastrar_Click(object sender, EventArgs e)
        {
            expandiForm();

            //Botão cadastrar novo evento
            if (tsbCadastrar.Text == "Adicionar")
            {
                Clean();
                tsbCadastrar.Text      = "Cadastrar";
                lblResponsavel.Visible = false;
                txtResponsavel.Visible = false;
            }

            //Função salvar
            else if (tsbCadastrar.Text == "Salvar")
            {
                try
                {
                    //Salvando alterações do evento
                    evento.Id          = Convert.ToInt32(txtCodigoEvento.Text);
                    evento.Titulo      = txtNomeEvento.Text;
                    evento.Responsavel = Convert.ToInt32(txtResponsavel.Text);
                    evento.DataInicio  = Convert.ToDateTime(dtpInicio.Text);
                    evento.DataFim     = Convert.ToDateTime(dtpFinal.Text);

                    if (dgvItensEvento.RowCount == 0)
                    {
                        evento.Obra = "";
                    }
                    else
                    {
                        evento.Obra = dgvItensEvento[1, dgvItensEvento.CurrentCell.RowIndex].Value.ToString();

                        int cont = 0;
                        int i;
                        int j;

                        for (i = 0; i < dgvObras.Rows.Count - 1; i++)
                        {
                            for (j = 0; j < dgvObras.Columns.Count; j++)
                            {
                                if (dgvObras.Rows[i].Cells[j].Value.ToString() == cbxObras.Text)
                                {
                                    //MessageBox.Show(string.Format("Encontrados: {0}", cont), "Resultado", MessageBoxButtons.OK, MessageBoxIcon.Information);

                                    dgvObras.ClearSelection();
                                    dgvObras.Rows[i].Cells[j].Selected = true;
                                    cont++;

                                    //Salvando alterações das Obras
                                    obra.Id     = int.Parse(dgvObras.Rows[i].Cells[0].Value.ToString());
                                    obra.Local  = "Evento: " + txtNomeEvento.Text;
                                    obra.Status = "Em exposição";
                                    bll.UpdateObra(obra);
                                }
                            }
                        }
                    }

                    bll.Update(evento);
                    Clean();
                    UpdateForm();
                    UpdateGrid();
                    lblMsgErro.Visible = false;
                }
                catch (Exception ex)
                {
                    lblMsgErro.Visible = true;
                    lblMsgErro.Text    = "Erro: " + ex.Message;
                }
            }

            //Função cadastrar/salvar novo evento
            else
            {
                try
                {
                    bll.Create(new Evento(txtNomeEvento.Text, funcionario.Id, Convert.ToDateTime(dtpInicio.Text), Convert.ToDateTime(dtpFinal.Text)));
                    Clean();
                    UpdateForm();
                    UpdateGrid();
                    lblMsgErro.Visible = false;
                }
                catch (Exception ex)
                {
                    lblMsgErro.Visible = true;
                    lblMsgErro.Text    = "Erro: " + ex.Message;
                }
            }
        }
예제 #2
0
        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;
            }
        }