Ejemplo n.º 1
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            AddWorkerForm addWorkerForm = new AddWorkerForm();

            addWorkerForm.ShowDialog();
            if (addWorkerForm.newWorker != null)
            {
                WorkerList.Add(addWorkerForm.newWorker);
                WorkersGridView.Rows.Add(
                    addWorkerForm.newWorker.Firstname,
                    addWorkerForm.newWorker.Surname,
                    addWorkerForm.newWorker.GetSalaryValue());
            }
        }
Ejemplo n.º 2
0
        private void EditButton_Click(object sender, EventArgs e)
        {
            Worker selectedWorker = null;

            try
            {
                foreach (Worker worker in WorkerList)
                {
                    if (worker.Firstname
                        == WorkersGridView.CurrentRow.Cells[0].Value.ToString() &&
                        worker.Surname
                        == WorkersGridView.CurrentRow.Cells[1].Value.ToString() &&
                        worker.GetSalaryValue().ToString()
                        == WorkersGridView.CurrentRow.Cells[2].Value.ToString())
                    {
                        selectedWorker = worker;
                        break;
                    }
                }
            }
            catch (ArgumentNullException)
            {
                MessageBox.Show("Wrong");
            }
            if (selectedWorker != null)
            {
                AddWorkerForm EditWorkerForm = new AddWorkerForm(selectedWorker);
                EditWorkerForm.Text = "Edit worker";
                EditWorkerForm.ShowDialog();
                if (EditWorkerForm.newWorker != null)
                {
                    WorkerList.Remove(selectedWorker);
                    WorkerList.Add(EditWorkerForm.newWorker);
                    WorkersGridView.CurrentRow.SetValues(EditWorkerForm.newWorker.Firstname,
                                                         EditWorkerForm.newWorker.Surname,
                                                         EditWorkerForm.newWorker.GetSalaryValue());
                }
            }
        }