Esempio n. 1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (tabDepartment.TabPages.Count <= 1)
            {
                MessageBox.Show("No Departments entered! You cannot add Employee without one Department created",
                                "Cannot add Employee", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                AddEditEmployee addEmp = new AddEditEmployee(true);
                addEmp.Text = "Add new Employee";
                addEmp.ShowDialog();

                // refresh
                LoadEmployees();
            }
        }
Esempio n. 2
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (lvEmployees.Items.Count > 0)
            {
                // ukoliko se pritisne botun edit, a na listi nije nista selektirano.
                if (lvEmployees.SelectedItems.Count < 1)
                {
                    MessageBox.Show("Please select an item", "Cannot edit item", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                else
                {
                    AddEditEmployee editEmp = new AddEditEmployee(false);
                    DataRow         dr      = sqlProcedures.GetEmployee(Convert.ToInt32(lvEmployees.SelectedItems[0].Text));

                    editEmp.txtEmpId.Text     = Validator.ConvertFromDBVal <int>(dr["EmployeeID"]).ToString();
                    editEmp.txtFirstName.Text = Validator.ConvertFromDBVal <string>(dr["FirstName"]);
                    editEmp.txtLastName.Text  = Validator.ConvertFromDBVal <string>(dr["LastName"]);
                    editEmp.txtJobTitle.Text  = Validator.ConvertFromDBVal <string>(dr["JobTitle"]);
                    editEmp.txtEmail.Text     = Validator.ConvertFromDBVal <string>(dr["EmailAddress"]);
                    editEmp.txtNotes.Text     = Validator.ConvertFromDBVal <string>(dr["Notes"]);

                    DateTime?birthDate = Validator.ConvertFromDBVal <DateTime?>(dr["BirthDate"]);
                    if (birthDate != null)
                    {
                        editEmp.txtBirthDate.Text  = Convert.ToDateTime(birthDate).ToString("d");
                        editEmp.dtpBirthDate.Value = Convert.ToDateTime(birthDate);
                    }

                    DateTime?dateHired = Validator.ConvertFromDBVal <DateTime?>(dr["DateHired"]);
                    if (dateHired != null)
                    {
                        editEmp.txtDateHired.Text  = Convert.ToDateTime(dateHired).ToString("d");
                        editEmp.dtpDateHired.Value = Convert.ToDateTime(dateHired);
                    }

                    // department
                    editEmp.cmbDepartment.SelectedValue = Validator.ConvertFromDBVal <int>(dr["DepartmentID"]);

                    // phone numbers
                    editEmp.txtBussPhone.Text   = Validator.ConvertFromDBVal <string>(dr["BusinessPhone"]);
                    editEmp.txtHomePhone.Text   = Validator.ConvertFromDBVal <string>(dr["HomePhone"]);
                    editEmp.txtMobilePhone.Text = Validator.ConvertFromDBVal <string>(dr["MobilePhone"]);
                    editEmp.txtFaxNumber.Text   = Validator.ConvertFromDBVal <string>(dr["FaxNumber"]);

                    // address
                    editEmp.txtAddress.Text       = Validator.ConvertFromDBVal <string>(dr["Address"]);
                    editEmp.txtCity.Text          = Validator.ConvertFromDBVal <string>(dr["City"]);
                    editEmp.txtStateProvince.Text = Validator.ConvertFromDBVal <string>(dr["StateProvince"]);
                    editEmp.txtPostalCode.Text    = Validator.ConvertFromDBVal <string>(dr["PostalCode"]);
                    editEmp.txtCountry.Text       = Validator.ConvertFromDBVal <string>(dr["Country"]);

                    editEmp.Text = "Edit Employee";
                    editEmp.ShowDialog();

                    // refresh
                    LoadEmployees();
                }
            }
            else
            {
                MessageBox.Show("No Employees found", "Unable to edit", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }