Exemplo n.º 1
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(txtCustomerId.Text);

            using (AdventureEntities context = new AdventureEntities()) {
                IQueryable <Customer> cliente = from q in context.Customer
                                                where q.CustomerID == id
                                                select q;
                List <Customer> lista = cliente.ToList();

                var oCliente = lista[0];

                ckbNameStyle.Checked = oCliente.NameStyle;
                txtTitle.Text        = oCliente.Title;
                txtFirstName.Text    = oCliente.FirstName;
                txtMiddleName.Text   = oCliente.MiddleName;
                txtLastName.Text     = oCliente.LastName;
                txtSuflix.Text       = oCliente.Suffix;
                txtCompany.Text      = oCliente.CompanyName;
                txtSalePerson.Text   = oCliente.SalesPerson;
                txtEmail.Text        = oCliente.EmailAddress;
                txtPhone.Text        = oCliente.Phone;
                txtPassHash.Text     = oCliente.PasswordHash;
                txtPassSalt.Text     = oCliente.PasswordSalt;
            }
        }
Exemplo n.º 2
0
        private void Actualizar()
        {
            int id = Convert.ToInt32(txtCustomerId.Text);

            using (AdventureEntities context = new AdventureEntities()) {
                Customer oCliente = context.Customer.SingleOrDefault(p => p.CustomerID == id);

                //MessageBox.Show(oCliente.LastName);

                oCliente.NameStyle    = ckbNameStyle.Checked;
                oCliente.Title        = txtTitle.Text;
                oCliente.FirstName    = txtFirstName.Text;
                oCliente.MiddleName   = txtMiddleName.Text;
                oCliente.LastName     = txtLastName.Text;
                oCliente.Suffix       = txtSuflix.Text;
                oCliente.CompanyName  = txtCompany.Text;
                oCliente.SalesPerson  = txtSalePerson.Text;
                oCliente.EmailAddress = txtEmail.Text;
                oCliente.Phone        = txtPhone.Text;
                oCliente.PasswordHash = txtPassHash.Text;
                oCliente.PasswordSalt = txtPassSalt.Text;

                context.SaveChanges();
            }
        }
Exemplo n.º 3
0
        private void CargarGrid()
        {
            using (AdventureEntities context = new AdventureEntities())
            {
                /*
                 *  IQueryable: Proporciona funcionalidad para evaluar consultas con
                 *  respecto a un origen de datos concreto en el que se especifica el tipo de los datos.
                 *  Util para aplicar consultas LINQ
                 */
                IQueryable <Customer> cliente = from q in context.Customer
                                                select q;

                List <Customer> lista = cliente.ToList();

                dgvCustomer.DataSource = lista;
                dgvCustomer.Refresh();
            }
        }
Exemplo n.º 4
0
        private void Insertar()
        {
            try
            {
                using (AdventureEntities context = new AdventureEntities()) {
                    Customer oCliente = new Customer
                    {
                        NameStyle    = ckbNameStyle.Checked,
                        Title        = txtTitle.Text,
                        FirstName    = txtFirstName.Text,
                        MiddleName   = txtMiddleName.Text,
                        LastName     = txtLastName.Text,
                        Suffix       = txtSuflix.Text,
                        CompanyName  = txtCompany.Text,
                        SalesPerson  = txtSalePerson.Text,
                        EmailAddress = txtEmail.Text,
                        Phone        = txtPhone.Text,
                        PasswordHash = txtPassHash.Text,
                        PasswordSalt = txtPassSalt.Text,
                        ModifiedDate = DateTime.Now
                    };

                    context.Customer.Add(oCliente);
                    context.SaveChanges();
                }
            }
            catch (DbEntityValidationException ex) {
                foreach (var validationErrors in ex.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        MessageBox.Show(string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally {
                CargarGrid();
            }
        }
Exemplo n.º 5
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(txtCustomerId.Text);

            using (AdventureEntities context = new AdventureEntities())
            {
                //Ejemplo 1:
                //Customer oCliente = context.Customer.SingleOrDefault(p => p.CustomerID == id);

                //Ejemplo 2:
                Customer oCliente = (from q in context.Customer
                                     where q.CustomerID == id
                                     select q).First();

                try {
                    context.Customer.Remove(oCliente);
                    context.SaveChanges();

                    CargarGrid();
                } catch (Exception ex) {
                    MessageBox.Show(ex.Message);
                }
            }
        }