コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Stack <Pallet> aux = new Stack <Pallet>();

            while (pilha.Count > 0)
            {
                Pallet p = new Pallet();
                p = pilha.Peek(); // pegando o pallet que esta no topo
                if (p.Nome.Equals(txtProd.Text))
                {
                    int qtd = Convert.ToInt32(txtQtd.Text);
                    if (p.Quantidade > qtd)
                    {
                        p.Quantidade = p.Quantidade - qtd;
                        MessageBox.Show(p.Nome + ": ouve remoção de " + qtd + " produtos");
                    }
                    else
                    {
                        pilha.Pop();
                        MessageBox.Show(p.Nome + ": ouve remoção de " + p.Quantidade + " produtos");
                    }
                    break;
                }
                else
                {
                    aux.Push(p);
                    pilha.Pop();
                    MessageBox.Show(p.Nome + " movido para pilha auxiliar");
                }
            }// fim while

            foreach (Pallet p in aux)
            {
                pilha.Push(p);
            }// fim foreach

            mostraPilha();
            limpar();
        }
コード例 #2
0
 void carregar()
 {
     if (File.Exists("pallets.txt"))
     {
         Stack <Pallet> aux = new Stack <Pallet>();
         using (BinaryReader reader = new BinaryReader(File.Open("pallets.txt", FileMode.Open)))
         {
             int qtd = reader.ReadInt32();
             for (int i = 0; i < qtd; i++)
             {
                 Pallet p = new Pallet();
                 p.Nome       = reader.ReadString();
                 p.Quantidade = reader.ReadInt32();
                 aux.Push(p);
             }// fim for
         }
         foreach (Pallet p in aux)
         {
             pilha.Push(p);
         }// fim foreach
         mostraPilha();
     }
 }