// key listener for ctrl+z and ctrl+y
 private void Form1_KeyDown(object sender, KeyEventArgs e)
 {
     if ((e.KeyCode == Keys.Y && e.Modifiers == Keys.Control) || (e.KeyCode == Keys.Z && e.Modifiers == Keys.Control))
     {
         if (e.KeyCode == Keys.Y && e.Modifiers == Keys.Control)
         {
             user.Redo();
         }
         else if (e.KeyCode == Keys.Z && e.Modifiers == Keys.Control)
         {
             user.Undo();
         }
         var factory = new Factory() as Ifactory;
         listim = factory.Getproduct(classcb.SelectedItem.ToString());
         groupBox1.Controls.Clear();
         groupBox1.Controls.Add(listim.list);
     }
 }
        private void addBtn_Click(object sender, EventArgs e)
        {
            // making sure a class's been selected
            if (classcb.SelectedIndex == -1)
            {
                return;
            }
            // using strategy class
            CreateClassForm strategy = new CreateClassForm();

            strategy.SetStrategyForm(classcb.SelectedItem.ToString());
            Add addform = new Add();

            // getting the list of controls created
            addform.Controls.AddRange(strategy._list.ToArray());
            addform.ShowDialog();
            // after adding the object the list will be refreshed
            var factory = new Factory() as Ifactory;

            listim = factory.Getproduct(classcb.SelectedItem.ToString());
            groupBox1.Controls.Clear();
            groupBox1.Controls.Add(listim.list);
        }
 public void updateBtn_Click(object sender, EventArgs e)
 {
     if (classcb.SelectedIndex == -1)
     {
         return;
     }
     className = classcb.SelectedItem.ToString();
     if (((ListView)groupBox1.Controls[0]).SelectedItems.Count != 0)
     {
         var             o        = ((ListView)groupBox1.Controls[0]).SelectedItems[0].Tag;
         UpdateClassForm strategy = new UpdateClassForm();
         strategy.SetUpdateStrategyForm(o);
         Add addform = new Add();
         addform.Controls.AddRange(strategy._list.ToArray());
         addform.ShowDialog();
         object oldObject = strategy.getobject();
         // telling the command there is an object's been updated
         user.Compute(oldObject, o);
         var factory = new Factory() as Ifactory;
         listim = factory.Getproduct(className);
         groupBox1.Controls.Clear();
         groupBox1.Controls.Add(listim.list);
     }
 }