protected void DataGrid_Update(object sender, DataGridCommandEventArgs e)
        {
            Page.Validate();

            if (Page.IsValid)
            {
                int index = grid.EditItemIndex;

                if (index >= emails.Count)
                {
                    emails.Add();
                }

                Email email = emails[index];

                DataGridItem item = grid.Items[index];

                email.Value   = ((TextBox)item.FindControl("email")).Text;
                email.UseType = ((TextBox)item.FindControl("useType")).Text;

                entity.Save();

                grid.EditItemIndex = -1;
                CancelEditMode();

                PopulateDataGrid();
            }
        }
        public static EmailCollection GetCollection()
        {
            EmailCollection tempList = null;

            using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("usp_GetEmail", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    myCommand.Parameters.AddWithValue("@QueryId", SelectTypeEnum.GetCollection);

                    myConnection.Open();

                    using (SqlDataReader myReader = myCommand.ExecuteReader())
                    {
                        if (myReader.HasRows)
                        {
                            tempList = new EmailCollection();
                            while (myReader.Read())
                            {
                                tempList.Add(FillDataRecord(myReader));
                            }
                        }
                        myReader.Close();
                    }
                }
            }
            return(tempList);
        }
Exemple #3
0
        public EmailCollection PesquisarEmailPessoa(int IDPessoa)
        {
            EmailCollection emailCollection = new EmailCollection();

            AcessoDados.LimparParametro();
            AcessoDados.AdicionarParametro("@INIDPessoa", IDPessoa);

            using (DataTable dtbRegistro = AcessoDados.GetDataTable("uspPesquisarEmailPessoa", CommandType.StoredProcedure))
            {
                foreach (DataRow dtrItem in dtbRegistro.Rows)
                {
                    emailCollection.Add(CarregarItem(dtrItem));
                }
            }

            return(emailCollection);
        }
        private void AtualizarGrid(Email Email, bool booExcluir)
        {
            try
            {
                object FiltroExcluir = null;

                if (booExcluir)
                {
                    FiltroExcluir         = (LocalizarFiltroExcluir(dgwColecao) as Email).GetChavePrimaria();
                    dgwColecao.DataSource = null;
                    emailCollection.Remove(Email);
                }
                else
                {
                    if (Email != null)
                    {
                        var Item = from p in emailCollection
                                   where p.GetChavePrimaria() == Email.GetChavePrimaria()
                                   select p;

                        if (Item.Count() == 1)
                        {
                            Email EmailSelecionado = Item.First();
                            EmailSelecionado = Email;
                        }
                        else
                        {
                            emailCollection.Add(Email);
                        }
                    }
                    else
                    {
                        while (backgroundWorker1.IsBusy)
                        {
                            Application.DoEvents();
                        }
                        object[] args = new object[2];
                        args[0] = "ConsultarEmailFornecedor";
                        args[1] = this.fornecedor.Pessoa.IDPessoa;
                        backgroundWorker1.RunWorkerAsync(args);
                        while (backgroundWorker1.IsBusy)
                        {
                            Application.DoEvents();
                        }
                    }
                }

                dgwColecao.DataSource = null;
                if (emailCollection.Count() > 0)
                {
                    dgwColecao.DataSource = emailCollection.ToList <Email>();
                }

                txtRegistro.Text = dgwColecao.Rows.Count.ToString();

                //if (objEmail != null)
                //    LocalizarIndexLinha(dgwColecao, FiltroExcluir == null ? objEmail.GetChavePrimaria() : FiltroExcluir);

                dgwColecao.Update();
                dgwColecao.Refresh();

                if (dgwColecao.RowCount > 0)
                {
                    dgwColecao.Focus();
                }
            }
            catch (Exception ex)
            {
                Exceptionerro(ex);
            }
        }