Example #1
0
        public bool AgregarFamilia(familiap familia)
        {
            if (!this.ExisteFamilia(familia))
            {
                IDbConnection dbcon = this.Conectar();

                IDbCommand dbcmd = dbcon.CreateCommand();
                string sql =
                    "INSERT INTO familia_prod (nombre)" +
                        "VALUES ('"+familia.Nombre+"')";
                dbcmd.CommandText = sql;
                int res = dbcmd.ExecuteNonQuery();

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

                this.Desconectar(dbcon);

                return true;
            }
            return false;
        }
Example #2
0
        protected virtual void OnAgregarButtonClicked(object sender, System.EventArgs e)
        {
            familiap bod = new familiap(this.entry.Text.Trim());
            //			familiap bod = new familiap("leña");

            if (this.db.ExisteFamilia(bod))
            {
                Dialog dialog = new Dialog("OK", this, Gtk.DialogFlags.DestroyWithParent);
                dialog.Modal = true;
                dialog.Resizable = false;
                Gtk.Label etiqueta = new Gtk.Label();
                etiqueta.Markup = "No se pudo agregar la bodega porque ya existe una con el mismo código.\nIntente agregar uno diferente.";
                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.AgregarFamilia(bod))
                {
                    this.familias.Add(bod);
                    this.bodegasmodel.AppendValues(bod.Nombre);

                    this.entry.Text = "";
                    this.familiaplantastreeview.Selection.UnselectAll();
                    this.agregar_button.Sensitive = false;
                    //Console.WriteLine("Agregado");
                    agregar_button.Sensitive = true;

                    this.cambiado = true;
                }
                else
                {
                    Dialog dialog = new Dialog("No se pudo agregar la bodega", this, Gtk.DialogFlags.DestroyWithParent);
                    dialog.Modal = true;
                    dialog.Resizable = false;
                    Gtk.Label etiqueta = new Gtk.Label();
                    etiqueta.Markup = "No se pudo agregar la bodega, ha ocurrido un error al agregarla 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 ();
                    agregar_button.Sensitive = true;

                }
            }
        }
Example #3
0
        public bool ExisteFamilia(familiap Familia)
        {
            IDbConnection dbcon = this.Conectar();

            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();
            // clean up
            reader.Close();
            reader = null;
            dbcmd.Dispose();
            dbcmd = null;

            this.Desconectar(dbcon);

            return existe;
        }