Пример #1
0
        private void btn_mod_Click(object sender, RoutedEventArgs e)
        {
            bool idrec  = true;
            bool nomb   = true;
            bool habili = true;
            bool selec  = true;
            bool canti  = true;
            bool prec   = true;
            bool cat    = true;
            bool des    = true;

            lb1.Content = "";
            lb2.Content = "";
            lb3.Content = "";
            lb4.Content = "";
            lb5.Content = "";
            lb6.Content = "";
            lb7.Content = "";

            PlatoBLL ub = new PlatoBLL();


            if (txt_id_rec.Text.Trim() == "")
            {
                idrec       = false;
                lb1.Content = "Debe ingresar la ID";
            }
            if (txt_nom_rec.Text.Trim() == "")
            {
                nomb        = false;
                lb2.Content = "Debe ingresar el Nombre del Plato";
            }

            if (cbb_habili.Text == "")
            {
                habili      = false;
                lb3.Content = "Debe ingresar el Estado del Plato";
            }
            if (rb_cons.IsChecked == false)
            {
                if (cbb_ingres.Text == "")
                {
                    selec       = false;
                    lb4.Content = "Debe Seleccionar el/los Ingredientes del Plato";
                }
                if (txt_cant_ing.Text.Trim() == "")
                {
                    canti       = false;
                    lb5.Content = "Debe ingresar la Cantidad del Ingrediente a ingresar";
                }
            }


            if (txt_prec.Text.Trim() == "")
            {
                prec        = false;
                lb6.Content = "Debe ingresar el Precio del Plato";
            }
            if (cbb_catego.Text.Trim() == "")
            {
                cat         = false;
                lb7.Content = "Debe ingresar la Categoria del Plato";
            }
            if (txt_desc_mod.Text.Trim() == "")
            {
                des         = false;
                lb8.Content = "Debe ingresar la Descripcion del Plato";
            }



            if (idrec && nomb && habili && selec && canti && prec && cat && des)
            {
                ub.Id_plato     = Int32.Parse(txt_id_rec.Text);
                ub.Nombre_plato = txt_nom_rec.Text;
                /*ub.cantidad = Int32.Parse(txt_cant_ing.Text);*/
                ub.Precio      = Int32.Parse(txt_prec.Text);
                ub.Categoria   = cbb_catego.Text;
                ub.descripcion = txt_desc_mod.Text;
                ub.Habilitado  = cbb_habili.Text;

                bool existe = ub.Getplatobyid(Int32.Parse(txt_id_rec.Text));


                if (existe)
                {
                    ub.Eliminar_Ing(ub);
                    ub.alter_plato(ub);

                    PopupNotifier popup = new PopupNotifier();
                    popup.TitleText         = "Aviso";
                    popup.Image             = Properties.Resources.delete;
                    popup.ContentText       = "Plato modificado correctamente";
                    popup.AnimationDuration = 500;
                    popup.Delay             = 2500;
                    popup.Popup();
                    Close();
                }
                else
                {
                    MessageBox.Show("La id del plato ingresado no existe");
                }

                if (rb_elim.IsChecked == true)
                {
                    foreach (DataRow line in dtl.Rows)
                    {
                        int idplato = Int32.Parse(txt_id_rec.Text);
                        int id      = int.Parse(line["id"].ToString());
                        int cant    = int.Parse(line["cantidad"].ToString());

                        PlatoBLL ptbll = new PlatoBLL();
                        try
                        {
                            ptbll.Modifica_relacion_ing(idplato, id, cant);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("" + ex);
                        }
                    }
                }
            }
        }