예제 #1
0
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            try
            {
                bool          band;
                CategoriesDAO oDAO = new CategoriesDAO();
                if (btnAgregar.Text.Equals("Agregar"))
                {
                    categoria = new Categories();
                    PasarObjeto();
                    band = oDAO.Create(categoria);
                }
                else
                {
                    PasarObjeto();
                    band = oDAO.Update(categoria);
                }

                if (band)
                {
                    GetCategorias();
                    LimpiarControles();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error al agregar la categoria: " + ex.Message, "My Store Desktop",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #2
0
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            try {
                Regex match = new Regex(@"^[A-Z]+[a-zA-Z0-9''-'\s]*$");
                if (categoriaTxt.MaxLength <= 15 && match.IsMatch(categoriaTxt.Text))
                {
                    bool          band;
                    CategoriesDAO oDAO = new CategoriesDAO();
                    if (AgregarBtn.Text.Equals("Agregar"))
                    {
                        categoria = new Categories();
                        PasarObjeto();
                        band = oDAO.Create(categoria);
                    }
                    else
                    {
                        PasarObjeto();
                        band = oDAO.Update(categoria);
                    }

                    if (band)
                    {
                        GetCategorias();
                        LimpiarControles();
                    }
                }
                else
                {
                    MessageBox.Show("No se permiten los siguientes aspectos:\n" + "Categoría" + " vacío,\nCapitalización,\nNo empezar con un número,\nMáximo a 15 caracteres.");
                }
            } catch (Exception ex) {
                MessageBox.Show("Error al agregar la categoria: " + ex.Message, "My Store Desktop",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void UpdateTest()
        {
            MemorySQLConnection <Category> connection = new MemorySQLConnection <Category>();
            var categoria = new CategoriesDAO(connection);
            var cat       = new Category()
            {
                Id          = 10,
                Description = "categoria com id 2"
            };
            var result = categoria.Update(cat);


            Assert.AreEqual(2, categoria.Get().Count());
            Assert.AreEqual("categoria com id 2", categoria.Get().First(x => x.Id == 10).Description);
        }
예제 #4
0
        public void UpdateCategories(int id, string name)
        {
            CategoriesDTO dto = new CategoriesDTO();

            dto.cateId   = id;
            dto.cateName = name;
            if (categoriesDAO.Update(dto))
            {
                //do not thing
            }
            else
            {
                throw new Exception("Delete Fail!");
            }
        }
예제 #5
0
        private void AgregarBtn_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(categoriaTxt.Text))
            {
                MessageBox.Show("Inserte una categoria",
                                "ALERTA",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);

                return;
            }
            else
            {
                try {
                    bool          band;
                    CategoriesDAO oDAO = new CategoriesDAO();
                    if (AgregarBtn.Text.Equals("Agregar"))
                    {
                        EliminarBtn.Enabled = true;
                        categoria           = new Categories();
                        PasarObjeto();
                        band = oDAO.Create(categoria);
                    }
                    else
                    {
                        EliminarBtn.Enabled = true;
                        dgvDatos.Enabled    = true;
                        CancelarBtn.Enabled = false;
                        PasarObjeto();
                        band            = oDAO.Update(categoria);
                        AgregarBtn.Text = "Agregar";
                    }

                    if (band)
                    {
                        GetCategorias();
                        LimpiarControles();
                    }
                } catch (Exception ex) {
                    MessageBox.Show("Error al agregar la categoria: " + ex.Message, "My Store Desktop",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }