Example #1
0
 public ENMenu(ENMenu producto)
 {
     this.id     = producto.id;
     this.nombre = producto.nombre;
     this.precio = producto.precio;
     this.pedido = producto.pedido;
 }
Example #2
0
        public bool update(ENMenu en)

        {
            SqlConnection conn = new SqlConnection(constring);

            string comando = "UPDATE [dbo].[Menu] " + "SET nombre = '" + en.Nombre + "',  precio = '" + en.Precio + "',  pedido = '" + en.Pedido + "'where id ='" + en.Id + "'";

            try

            {
                conn.Open();

                SqlCommand cmd = new SqlCommand(comando, conn);

                cmd.ExecuteNonQuery();
            }

            catch (Exception e)

            {
                Console.WriteLine("Error: " + e);
                conn.Close();

                return(false);
            }

            finally

            {
                conn.Close();
            }

            return(true);
        }
Example #3
0
        public bool create(ENMenu en)

        {
            SqlConnection conn = new SqlConnection(constring);

            string comando = "Insert Into [dbo].[Menu] (id, nombre, precio) " + "VALUES ('" + en.Id + "', '" + en.Nombre + "', '" + en.Precio + "')";

            try

            {
                conn.Open();

                SqlCommand cmd = new SqlCommand(comando, conn);

                cmd.ExecuteNonQuery();

                conn.Close();
            }

            catch (Exception e)

            {
                conn.Close();

                Console.WriteLine("Error: " + e);

                return(false);
            }

            return(true);
        }
Example #4
0
        public bool delete(ENMenu en)

        {
            SqlConnection conn = new SqlConnection(constring);;

            string comando = "Delete from [dbo].[Menu] where id = '" + en.Id + "'";

            try

            {
                conn.Open();

                SqlCommand cmd = new SqlCommand(comando, conn);

                cmd.ExecuteNonQuery();
            }

            catch (Exception)

            {
                conn.Close();

                return(false);
            }

            finally

            {
                conn.Close();
            }

            return(true);
        }
Example #5
0
        public bool read(ENMenu en)

        {
            SqlConnection conn = new SqlConnection(constring);

            String comando = "select * from [dbo].[Menu] where id='" + en.Id + "'";

            try

            {
                conn.Open();

                SqlCommand cmd = new SqlCommand(comando, conn);

                SqlDataReader dr = cmd.ExecuteReader();

                dr.Read();

                if (int.Parse(dr["id"].ToString()) == en.Id)

                {
                    en.Id = int.Parse(dr["id"].ToString());

                    en.Nombre = dr["nombre"].ToString();

                    en.Precio = float.Parse(dr["precio"].ToString());

                    dr.Close();

                    conn.Close();

                    return(true);
                }

                return(false);
            }

            catch (Exception)

            {
                conn.Close();

                return(false);
            }
        }