Ejemplo n.º 1
0
        private void OnQuitarFamiliaDialogResponse(object sender, ResponseArgs args)
        {
            switch (args.ResponseId)
            {
            case ResponseType.Accept:
                Gtk.TreeIter iter;
                this.FamiliaProductosTreeview.Selection.GetSelected(out iter);

                FamiliaProducto bod = new FamiliaProducto(this.familiaModel.GetValue(iter, 0).ToString());

                if (!this.db.ExisteFamiliaBd(bod))
                {
                    Dialog dialog = new Dialog("No se pudo quitar la familia", this, Gtk.DialogFlags.DestroyWithParent);
                    dialog.Modal = true;
                    dialog.Resizable = false;
                    Gtk.Label etiqueta = new Gtk.Label();
                    etiqueta.Markup = "No se pudo quitar la familia porque no existe en la base de datos.\nIntente recargar la lista de familias.";
                    dialog.BorderWidth = 8;
                    dialog.VBox.BorderWidth = 8;
                    dialog.VBox.PackStart(etiqueta, false, false, 0);
                    dialog.AddButton ("Cerrar", ResponseType.Close);
                    dialog.ShowAll();
                    dialog.Run ();
                    dialog.Destroy ();
                }
                else
                {
                    if (this.db.QuitarFamilia(bod))
                    {
                        Console.WriteLine(this.familias.Count);

                        this.familias.RemoveAt(this.familiaModel.GetPath(iter).Indices[0]);
                        Console.WriteLine(this.familias.Count);
                        this.familiaModel.Remove(ref iter);

                        this.actualizar_button.Sensitive = false;
                        this.FamiliaProductosTreeview.Selection.UnselectAll();

                        this.cambiado = true;
                    }
                    else
                    {
                        Dialog dialog = new Dialog("No se pudo quitar la familia", this, Gtk.DialogFlags.DestroyWithParent);
                        dialog.Modal = true;
                        dialog.Resizable = false;
                        Gtk.Label etiqueta = new Gtk.Label();
                        etiqueta.Markup = "No se pudo quitar la familia, ha ocurrido un error al quitarla de la base de datos.";
                        dialog.BorderWidth = 8;
                        dialog.VBox.BorderWidth = 8;
                        dialog.VBox.PackStart(etiqueta, false, false, 0);
                        dialog.AddButton ("Cerrar", ResponseType.Close);
                        dialog.ShowAll();
                        dialog.Run ();
                        dialog.Destroy ();
                    }
                }
                break;
                default:

                break;
            }
        }
Ejemplo n.º 2
0
        protected virtual void OnActualizarButtonClicked(object sender, System.EventArgs e)
        {
            Gtk.TreeIter iter;
            this.FamiliaProductosTreeview.Selection.GetSelected(out iter);

            FamiliaProducto familia_vieja = new FamiliaProducto(this.familiaModel.GetValue(iter, 0).ToString());
            FamiliaProducto familia_nueva = new FamiliaProducto(entryFamilia.Text.Trim());

            if (!this.db.ExisteFamiliaBd(familia_vieja))
            {
                Dialog dialog = new Dialog("No se pudo actualizar la familia", this, Gtk.DialogFlags.DestroyWithParent);
                dialog.Modal = true;
                dialog.Resizable = false;
                Gtk.Label etiqueta = new Gtk.Label();
                etiqueta.Markup = "No se pudo actualizar la familia porque no existe una en la base de datos.\nIntente recargar la lista de familias.";
                dialog.BorderWidth = 8;
                dialog.VBox.BorderWidth = 8;
                dialog.VBox.PackStart(etiqueta, false, false, 0);
                dialog.AddButton ("Cerrar", ResponseType.Close);
                dialog.ShowAll();
                dialog.Run ();
                dialog.Destroy ();
            }

            else
            {
                if (this.db.ActualizarFamilia(familia_vieja, familia_nueva))
                {
                    this.familias.RemoveAt(this.familiaModel.GetPath(iter).Indices[0]);
                    this.familias.Insert(this.familiaModel.GetPath(iter).Indices[0], familia_nueva);

                    this.familiaModel.SetValue(iter, 0, familia_nueva.Nombre);

                    this.entryFamilia.Text = "";
                    this.quitar_button.Sensitive = false;
                    this.actualizar_button.Sensitive = false;
                    this.FamiliaProductosTreeview.Selection.UnselectAll();
                    //Console.WriteLine("Actualizado");

                    this.cambiado = true;
                }
                else
                {
                    Dialog dialog = new Dialog("No se pudo actualizar la familia", this, Gtk.DialogFlags.DestroyWithParent);
                    dialog.Modal = true;
                    dialog.Resizable = false;
                    Gtk.Label etiqueta = new Gtk.Label();
                    etiqueta.Markup = "No se pudo actualizar la familia, ha ocurrido un error al actualizar en la base de datos.";
                    dialog.BorderWidth = 8;
                    dialog.VBox.BorderWidth = 8;
                    dialog.VBox.PackStart(etiqueta, false, false, 0);
                    dialog.AddButton ("Cerrar", ResponseType.Close);
                    dialog.ShowAll();
                    dialog.Run ();
                    dialog.Destroy ();
                }
            }
        }
Ejemplo n.º 3
0
        protected virtual void OnAgregarButtonClicked(object sender, System.EventArgs e)
        {
            FamiliaProducto prod = new FamiliaProducto(this.entryFamilia.Text.Trim());

            if (this.db.ExisteFamiliaBd(prod))
            {
                Dialog dialog = new Dialog("FAMILIA YA EXISTE", this, Gtk.DialogFlags.DestroyWithParent);
                dialog.Modal = true;
                dialog.Resizable = false;
                Gtk.Label etiqueta = new Gtk.Label();
                etiqueta.Markup = "La Familia que intenta agregar ya existe en la Base de Datos";
                dialog.BorderWidth = 8;
                dialog.VBox.BorderWidth = 8;
                dialog.VBox.PackStart(etiqueta, false, false, 0);
                dialog.AddButton ("Cerrar", ResponseType.Close);
                dialog.ShowAll();
                dialog.Run ();
                dialog.Destroy ();
            }
            else
            {
                if (this.db.AgregarFamiliaBd(prod))
                {
                    this.familias.Add(prod);
                    this.familiaModel.AppendValues(prod.Nombre);

                    this.entryFamilia.Text = "";
                    this.FamiliaProductosTreeview.Selection.UnselectAll();
                    this.añadir_button.Sensitive = false;

                    añadir_button.Sensitive = true;

                    this.cambiado = true;
                }
                else
                {
                    Dialog dialog = new Dialog("ERROR AL AGREGAR FAMILIA", this, Gtk.DialogFlags.DestroyWithParent);
                    dialog.Modal = true;
                    dialog.Resizable = false;
                    Gtk.Label etiqueta = new Gtk.Label();
                    etiqueta.Markup = "Ha ocurrido un error al agregar la Familia a la Base de Datos";
                    dialog.BorderWidth = 8;
                    dialog.VBox.BorderWidth = 8;
                    dialog.VBox.PackStart(etiqueta, false, false, 0);
                    dialog.AddButton ("Cerrar", ResponseType.Close);
                    dialog.ShowAll();
                    dialog.Run ();
                    dialog.Destroy ();
                    añadir_button.Sensitive = true;

                }
            }
        }
Ejemplo n.º 4
0
        public bool ExisteFamiliaBd(FamiliaProducto Familia)
        {
            IDbConnection dbcon = this.ConectarBd();

            IDbCommand dbcmd = dbcon.CreateCommand();
            string sql =
                "SELECT nombre " +
                    "FROM familia_prod " +
                    "WHERE nombre='"+Familia.Nombre+"'";
            dbcmd.CommandText = sql;
            IDataReader reader = dbcmd.ExecuteReader();
            bool existe = reader.Read();

            reader.Close();
            reader = null;
            dbcmd.Dispose();
            dbcmd = null;

            this.DesconectarBd(dbcon);

            return existe;
        }
Ejemplo n.º 5
0
        public bool AgregarFamiliaBd(FamiliaProducto familia)
        {
            if (!this.ExisteFamiliaBd(familia))
            {
                IDbConnection dbcon = this.ConectarBd();

                IDbCommand dbcmd = dbcon.CreateCommand();

                string sql =
                    "INSERT INTO familia_prod (nombre)" +
                        "VALUES ('"+familia.Nombre+"')";

                dbcmd.CommandText = sql;
                IDataReader reader = dbcmd.ExecuteReader();

                dbcmd.Dispose();
                dbcmd = null;

                this.DesconectarBd(dbcon);

                return true;
            }
            return false;
        }
Ejemplo n.º 6
0
        public bool ActualizarFamilia(FamiliaProducto familia_vieja, FamiliaProducto familia_nueva)
        {
            if ( this.ExisteFamiliaBd(familia_vieja) &&
                (!this.ExisteFamiliaBd(familia_nueva) || (this.ExisteFamiliaBd(familia_nueva) && familia_vieja.Nombre==familia_nueva.Nombre)))
            {
                IDbConnection dbcon = this.ConectarBd();

                IDbCommand dbcmd = dbcon.CreateCommand();
                string sql =
                    "UPDATE familia_prod " +
                        "SET nombre='"+familia_nueva.Nombre+"' " +
                        "WHERE nombre='"+familia_vieja.Nombre+"' ";
                dbcmd.CommandText = sql;

                int res = dbcmd.ExecuteNonQuery();

                dbcmd.Dispose();
                dbcmd = null;

                this.DesconectarBd(dbcon);

                return true;
            }
            return false;
        }
Ejemplo n.º 7
0
        public bool QuitarFamilia(FamiliaProducto famili)
        {
            if (this.ExisteFamiliaBd(famili))
            {
                IDbConnection dbcon = this.ConectarBd();

                IDbCommand dbcmd = dbcon.CreateCommand();
                string sql =
                    "DELETE FROM familia_prod "+
                        "WHERE nombre='"+famili.Nombre+"';";
                dbcmd.CommandText = sql;
                int res = dbcmd.ExecuteNonQuery();

                // clean up
                dbcmd.Dispose();
                dbcmd = null;

                this.DesconectarBd(dbcon);

                return true;
            }
            return false;
        }