示例#1
0
        // Método para insertar subcategoría

        private void btInsertSubcategory_Click(object sender, EventArgs e)
        {
            bool isValid = ValidateField();

            if (isValid)
            {
                string      categoryId  = this.comboInsert.SelectedValue.ToString();
                Subcategory subcategory = new Subcategory
                {
                    SubcategoryName        = this.txtInsertarSubcategoria.Text,
                    SubcategoryDescription = this.txtInsertarSubDescripcion.Text,
                    SubcategoryId          = Guid.NewGuid(),
                    CategoryId             = new Guid(categoryId)
                };

                bool hasBeenInserted = BusinessSubcategory.InsertSubcategory(subcategory);

                if (hasBeenInserted)
                {
                    RefreshDataGridView();
                    this.txtInsertarSubcategoria.Text   = string.Empty;
                    this.txtInsertarSubDescripcion.Text = string.Empty;
                    MessageBox.Show("Subcategoría insertada correctamente");
                }
                else
                {
                    MessageBox.Show("Error al insertar subcategoria");
                }
            }
        }
示例#2
0
        // Método que carga campos

        private void Products_Load(object sender, EventArgs e)
        {
            RefreshDataGridView();
            IEnumerable <DataAccess.Entities.Subcategory> subcategories = BusinessSubcategory.GetAllSubcategories().ToList();

            comboInsertSubcategory.DataSource    = subcategories;
            comboInsertSubcategory.DisplayMember = "SubcategoryName";
            comboInsertSubcategory.ValueMember   = "SubcategoryId";
        }
示例#3
0
        //Método para Refrescar la información de la tabla

        private void RefreshDataGridView()
        {
            List <Subcategory> subcategories = BusinessSubcategory.GetAllSubcategories().ToList();

            this.dtgridSubcatgory.DataSource = subcategories;
            for (int i = 0; i < dtgridSubcatgory.Rows.Count; i++)
            {
                dtgridSubcatgory.Rows[i].Cells["Category"].Value = subcategories[i].Category.CategoryName;
            }

            DisabledFields();
        }
示例#4
0
        // Método para buscar subcategoría

        private void SearchSucategory(object sender, EventArgs e)
        {
            this.dtgridSubcatgory.DataSource = BusinessSubcategory.SearchSubcategory(this.txtSubcatgorySearch.Text);
            List <Subcategory> subcategories = BusinessSubcategory.GetAllSubcategories().ToList();

            foreach (DataGridViewRow item in dtgridSubcatgory.Rows)
            {
                foreach (var subitem in subcategories)
                {
                    item.Cells["Category"].Value = subitem.Category.CategoryName;
                }
            }
        }
示例#5
0
        // Método para actualizar la subcategoría

        private void button1_Click(object sender, EventArgs e)
        {
            Subcategory subcategory = new Subcategory
            {
                SubcategoryName        = this.txtSubcategoryName.Text,
                SubcategoryDescription = this.txtSubcategoryDescripcion.Text,
                SubcategoryId          = new Guid(this.lbId.Text),
                CategoryId             = new Guid(this.comboSubcategory.SelectedValue.ToString())
            };
            bool isUpdated = BusinessSubcategory.UpdateSubcategory(subcategory);

            if (isUpdated)
            {
                RefreshDataGridView();
                CleanFields();
                MessageBox.Show("Subcategoría actualizada correctamente");
            }
            else
            {
                MessageBox.Show("Ha ocurrido un error actualizando los campos de la subcategoría");
            }
        }
示例#6
0
        // Método que hace los campos editables

        private void ClickProduct(object sender, DataGridViewCellEventArgs e)
        {
            EnabledFields();
            IEnumerable <DataAccess.Entities.Subcategory> subcategories = BusinessSubcategory.GetAllSubcategories().ToList();

            comboProduct.DataSource    = subcategories;
            comboProduct.DisplayMember = "SubcategoryName";
            comboProduct.ValueMember   = "SubcategoryId";
            var rows = this.dtgridProduct.CurrentRow;

            if (rows != null)
            {
                this.txtProductName.Text        = rows.Cells["ProductName"].Value.ToString();;
                this.txtProductDescripcion.Text = rows.Cells["ProductDescription"].Value.ToString();;
                this.lbId.Text              = rows.Cells["ProductId"].Value.ToString();
                this.txtEarns.Text          = rows.Cells["Earns"].Value.ToString();
                this.txtPrecioProducto.Text = rows.Cells["Price"].Value.ToString();
                this.comboProduct.Text      = rows.Cells["SubcategoryName"].Value.ToString();
            }
            else
            {
                MessageBox.Show("Selecciona una fila");
            }
        }
示例#7
0
        // Método para eliminar subcategoría

        private void button3_Click(object sender, EventArgs e)
        {
            var rows = this.dtgridSubcatgory.CurrentRow;

            if (rows != null)
            {
                var isDeleted = BusinessSubcategory.DeleteSubcategory(new Guid(rows.Cells["SubcategoryId"].Value.ToString()));

                if (isDeleted)
                {
                    RefreshDataGridView();
                    CleanFields();
                    MessageBox.Show("Subcategoría borrada correctamente");
                }
                else
                {
                    MessageBox.Show("Error borrando subcategoría");
                }
            }
            else
            {
                MessageBox.Show("Debe seleccionar una fila que borrar");
            }
        }