private void buttonActivatePromo_Click(object sender, EventArgs e)
 {
     if (TextIdPromo.Text == null || TextIdPromo.Text == "")
     {
         MessageBox.Show("Debe seleccionar una promoción para marcar como disponible", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     DialogResult res = MessageBox.Show("¿Realmente desea marcar como disponible la promoción?", "Confirmar actualización", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
     if (res == DialogResult.OK)
     {
         PromocionesOperations po = new PromocionesOperations();
         try
         {
             Promocion p = new Promocion();
             p.Id = Convert.ToUInt32(TextIdPromo.Text);
             po.Activate(p);
         }
         catch (Exception ex)
         {
             MessageBox.Show("No se puede marcar como disponible una promoción con platos no disponibles", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         ReloadGridPromos();
         ReloadGridPromos();
         ClearAllPromo();
     }
 }
 private void ButtonBuscarPromo_Click(object sender, EventArgs e)
 {
     if (TextBuscarPromo.Text == null || TextBuscarPromo.Text == "")
     {
         ReloadGridPromos();
         return;
     }
     try
     {
         PromocionesOperations po = new PromocionesOperations();
         var platos = po.SearchByDesc(TextBuscarPromo.Text);
         DataGridPromos.DataSource = platos;
         DataGridPromos.ClearSelection();
     }
     catch (Exception ex)
     {
         //TODO:
     }
 }
 private void ReloadGridPromos()
 {
     try
     {
         PromocionesOperations po = new PromocionesOperations();
         var promos = po.GetAll();
         var newDataSource = new List<Promocion>();
         newDataSource.AddRange(promos);
         DataGridPromos.DataSource = newDataSource;
         DataGridPromos.ClearSelection();
         buttonAddPlatoPromo.Enabled = false;
         buttonRemovePlatoPromo.Enabled = false;
         buttonActivatePromo.Enabled = false;
         ButtonDeletePromo.Enabled = false;
     }
     catch (Exception ex)
     {
         //TODO:
     }
 }
        private void DataGridPromos_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0) return;

            //ReloadCheckListPromos();

            var list = (IEnumerable<Promocion>)DataGridPromos.DataSource;
            var elem = list.ElementAt(e.RowIndex);

            PromocionesOperations po = new PromocionesOperations();
            PlatoOperations plo = new PlatoOperations();
            var platos = po.GetPlatosByPromo(elem);

            List<Plato> platosDataSource = new List<Plato>();
            float suma = 0;
            foreach (var pl in platos)
            {
                Plato p = plo.GetOne(pl.Plato_Id);
                suma += p.Precio_Venta;
                platosDataSource.Add(p);
            }
            dataGridPlatosPromo.DataSource = platosDataSource;

            labelPP.Text = "" + suma;
            TextDescPromo.Text = "" + elem.Descripcion;
            TextPricePromo.Text = "" + elem.Precio;
            TextIdPromo.Text = "" + elem.Id;

            buttonAddPlatoPromo.Enabled = true;
            buttonRemovePlatoPromo.Enabled = true;
            if (elem.Estado == "DISPONIBLE")
            {
                buttonActivatePromo.Enabled = false;
                ButtonDeletePromo.Enabled = true;
            }
            else
            {
                buttonActivatePromo.Enabled = true;
                ButtonDeletePromo.Enabled = false;
            }
        }
        private void ButtonSavePromo_Click(object sender, EventArgs e)
        {
            if (dataGridPlatosPromo.DataSource == null || ((List<Plato>)dataGridPlatosPromo.DataSource).Count == 0)
            {
                MessageBox.Show("Debe ingresar un plato a la promoción", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (TextDescPromo.Text == "")
            {
                MessageBox.Show("Debe ingresar una descripción", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (TextPricePromo.Text == "")
            {
                MessageBox.Show("Debe ingresar un precio", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            DialogResult res = MessageBox.Show("¿Realmente desea actualizar la promoción?", "Confirmar actualización", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            if (res == DialogResult.OK)
            {
                Promocion p = new Promocion();
                p.Id = Convert.ToUInt32(TextIdPromo.Text);
                p.Descripcion = TextDescPromo.Text;
                try
                {
                    p.Precio = (float)(Convert.ToDouble(TextPricePromo.Text));
                }
                catch (FormatException ex)
                {
                    MessageBox.Show("Debe ingresar un valor numérico en el precio", "Error numérico", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                PromocionesOperations po = new PromocionesOperations();
                try
                {
                    po.Update(p, (List<Plato>)dataGridPlatosPromo.DataSource);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error inesperado en actualización", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                ReloadGridPromos();
                ClearAllPromo();
            }
        }
        private void ButtonDeletePromo_Click(object sender, EventArgs e)
        {
            DialogResult res = MessageBox.Show("¿Realmente desea marcar como no disponible la promoción?", "Confirmar actualización", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            if (res == DialogResult.OK)
            {
                Promocion p = new Promocion();
                p.Id = Convert.ToUInt32(TextIdPromo.Text);

                PromocionesOperations po = new PromocionesOperations();
                try
                {
                    po.Inactivate(p);
                }
                catch (Exception ex)
                {
                    //TODO:
                }

                ReloadGridPromos();
                ClearAllPromo();
            }
        }