Exemplo n.º 1
0
 // After add new employee display the information at list
 private void AddButton_Click(object sender, EventArgs e)
 {
     using (frmEmployeesInformation InfoForm = new frmEmployeesInformation(true)
     {
         newEmployee = new clsEmployee()
     })
     {
         if (InfoForm.ShowDialog() == DialogResult.OK && InfoForm.validValue)
         {
             string[] addRow = new string[3];
             addRow[0] = InfoForm.newEmployee.ID.ToString();
             addRow[1] = InfoForm.newEmployee.Name;
             addRow[2] = InfoForm.newEmployee.Birthdate.ToShortDateString();
             ListViewItem addItems = new ListViewItem(addRow);
             lstEmployeesListView.Items.Add(addItems);
         }
     }
 }
Exemplo n.º 2
0
        // Get information about employee to edit
        private void EditButton_Click(object sender, EventArgs e)
        {
            ListViewItem item         = lstEmployeesListView.Items[lstEmployeesListView.SelectedIndices[0]];
            clsEmployee  editEmployee = new clsEmployee();

            editEmployee.ID = (Convert.ToInt32(item.SubItems[0].Text));
            editEmployee.Read();

            using (frmEmployeesInformation InfoForm = new frmEmployeesInformation(false)
            {
                newEmployee = editEmployee
            })
            {
                InfoForm.txtNameBox.Text       = editEmployee.Name;
                InfoForm.txtNationalIDBox.Text = editEmployee.NationalID.ToString();
                InfoForm.txtHeightBox.Text     = editEmployee.Height.ToString();
                InfoForm.txtWeightBox.Text     = editEmployee.Weight.ToString();
                InfoForm.BirthDatePicker.Value = editEmployee.Birthdate.Date;

                if (InfoForm.ShowDialog() == DialogResult.OK)
                {
                    if (InfoForm.validValue)
                    {
                        editEmployee.Name       = InfoForm.txtNameBox.Text;
                        editEmployee.NationalID = Convert.ToInt32(InfoForm.txtNationalIDBox.Text);
                        editEmployee.Height     = Convert.ToDouble(InfoForm.txtHeightBox.Text);
                        editEmployee.Weight     = Convert.ToDouble(InfoForm.txtWeightBox.Text);
                        editEmployee.Birthdate  = InfoForm.BirthDatePicker.Value.Date;
                        editEmployee.Update();

                        lstEmployeesListView.SelectedItems[0].SubItems[1].Text = editEmployee.Name;
                        lstEmployeesListView.SelectedItems[0].SubItems[2].Text = editEmployee.Birthdate.ToShortDateString();
                    }
                }
            }
        }