Example #1
0
        public void HeapifyBottomToTop(int index)
        {
            int parent = index / 2;

            if (index <= 1)
            {
                return;
            }


            if (arr[index].peso < arr[parent].peso)
            {
                Turno tmp = arr[index];
                arr[index]  = arr[parent];
                arr[parent] = tmp;
            }
            HeapifyBottomToTop(parent);
        }
Example #2
0
 //Extract head of heap
 public Turno extractHeadOfHeap()
 {
     if (sizeOfTree == 0)
     {
         Console.WriteLine("El montículo está vacío");
         return(null);
     }
     else
     {
         Console.WriteLine("La cabeza del montículo es: " + arr[1].numero);
         Console.WriteLine("Extrayéndola...");
         Turno extractedValue = arr[1];
         arr[1] = arr[sizeOfTree];
         sizeOfTree--;
         HeapifyTopToBottom(1);
         Console.WriteLine("Valor extraído del montículo!");
         levelOrder();
         return(extractedValue);
     }
 }
Example #3
0
        public Turno listarTurnos()
        {
            string        cadena = source + db + user + pass;
            SqlConnection conx   = new SqlConnection(cadena);
            SqlConnection conx2  = new SqlConnection(cadena);

            string com  = "select top 1 * from turno where estado=2";
            string com2 = "update turno set estado = 3 where id=@id;";

            conx.Open();

            SqlCommand cmd  = new SqlCommand(com, conx);
            SqlCommand cmd2 = new SqlCommand(com2, conx2);

            SqlDataReader rd = cmd.ExecuteReader();

            if (rd.Read())
            {
                Turno turno = new Turno();
                turno.numero = int.Parse(rd[0].ToString());
                turno.peso   = int.Parse(rd[1].ToString());
                turno.mesa   = int.Parse(rd[3].ToString());

                cmd2.Parameters.AddWithValue("@id", int.Parse(turno.numero.ToString()));

                conx2.Open();

                cmd2.ExecuteNonQuery();
                conx2.Close();

                conx.Close();
                return(turno);
            }

            else
            {
                conx.Close();
                return(null);
            }
        }
Example #4
0
        public void HeapifyTopToBottom(int index)
        {
            int left          = index * 2;
            int right         = (index * 2) + 1;
            int smallestChild = 0;

            if (sizeOfTree < left)
            {
                return;
            }

            else if (sizeOfTree == left)
            {
                if (arr[index].peso > arr[left].peso)
                {
                    Turno tmp = arr[index];
                    arr[index] = arr[left];
                    arr[left]  = tmp;
                }
                return;
            }
            else
            {
                if (arr[left].peso < arr[right].peso)
                {
                    smallestChild = left;
                }
                else
                {
                    smallestChild = right;
                }
                if (arr[index].peso > arr[smallestChild].peso)
                {
                    Turno tmp = arr[index];
                    arr[index]         = arr[smallestChild];
                    arr[smallestChild] = tmp;
                }
            }
            HeapifyTopToBottom(smallestChild);
        }
Example #5
0
 private void btnLlamar_Click(object sender, EventArgs e)
 {
     if (txtMesa.Text == "")
     {
         MessageBox.Show("Debe colocar un número de mesa o " +
                         "ventana de atención", "Aviso",
                         MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     else
     {
         Conexion cnn = new Conexion();
         try
         {
             Turno temp = cola.PeekOfHeap();
             cola.extractHeadOfHeap();
             cnn.llamarCliente(int.Parse(txtMesa.Text), temp.numero);
         }
         catch
         {
             MessageBox.Show("Se produjo un error, intente nuevamente",
                             "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Example #6
0
        private void actualizarDatos()
        {
            Conexion cn = new Conexion();

            Turno t = cn.listarTurnos();

            if (t != null)
            {
                lista.Reverse();
                lista.Add(t);
                lista.Reverse();

                notificacion();
                actualizarTabla();
            }

            else
            {
            }

            if (lista.Count > 6)
            {
                int max = lista.Count;

                for (int i = 5; i < max; i++)
                {
                    if (i == 6)
                    {
                    }
                    else
                    {
                        lista.RemoveAt(i);
                    }
                }
            }
        }
Example #7
0
        void actualizar()
        {
            Conexion cn = new Conexion();

            string cadena = cn.source + cn.db + cn.user + cn.pass;

            SqlConnection conx  = new SqlConnection(cadena);
            SqlConnection conx2 = new SqlConnection(cadena);
            SqlConnection conx3 = new SqlConnection(cadena);

            string com1 = "select * from turno where estado=0";
            string com2 = "update turno set estado=1 where id=@id";
            string com3 = "select * from turno;";


            //Se crea el lector para realizar la búsqueda de tickets de clientes
            //no colocados en la cola de prioridad

            SqlDataReader rd;

            conx.Open();
            SqlCommand cmd1 = new SqlCommand(com1, conx);


            rd = cmd1.ExecuteReader();

            while (rd.Read())
            {
                Turno turno = new Turno();

                turno.peso   = int.Parse(rd[1].ToString());
                turno.numero = int.Parse(rd[0].ToString());

                //Cada turno se añade a la cola de prioridad
                cola.InsertElementInHeap(turno);

                SqlCommand cmd2 = new SqlCommand(com2, conx2);
                conx2.Open();


                //Se cambia el estado del turno en la BD
                //para que no vuelva a ser agregado a la cola

                cmd2.Parameters.Add(new SqlParameter("@id", SqlDbType.Int));
                cmd2.Parameters["@id"].Value = turno.numero;

                cmd2.ExecuteNonQuery();

                conx2.Close();
            }
            conx.Close();

            Turno turnoMuestra = null;

            if (cola != null)
            {
                turnoMuestra = cola.PeekOfHeap();
            }

            string next = "";

            if (turnoMuestra != null)
            {
                if (turnoMuestra.peso == 1)
                {
                    next += "CP";
                }

                if (turnoMuestra.peso == 2)
                {
                    next += "CM";
                }

                if (turnoMuestra.peso == 3)
                {
                    next += "CN";
                }

                next += turnoMuestra.numero;
            }

            if (next == "")
            {
                lbTurno.Text = "-En Espera-";
            }
            else
            {
                lbTurno.Text = next;
            }

            SqlCommand cmd3 = new SqlCommand(com3, conx3);

            conx3.Open();
            SqlDataReader rd3 = cmd3.ExecuteReader();

            if (rd3.Read())
            {
                conx3.Close();
            }
            else
            {
                cola = null;
                cola = new Heap();
                conx3.Close();
                lbTurno.Text = "-En Espera-";
            }
        }