Example #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            this.loadClient();

            if (clientComboBox.Items.Count > 0)
            {
                this.employeeTableAdapter = new SeniorCitizensDataSetTableAdapters.EmployeeTableAdapter();
                this.employeeTableAdapter.ClearBeforeFill = true;
                this.employeeDataTable = new SeniorCitizensDataSet.EmployeeDataTable();

                this.employeeTableAdapter.Fill(employeeDataTable);
                this.currentEmployeePosition = 0;
                this.currentEmployeeRow      =
                    (SeniorCitizensDataSet.EmployeeRow)employeeDataTable.Rows[currentEmployeePosition];

                this.serviceTableAdapter = new SeniorCitizensDataSetTableAdapters.ServiceTableAdapter();
                this.serviceTableAdapter.ClearBeforeFill = true;
                this.serviceDataTable = new SeniorCitizensDataSet.ServiceDataTable();

                this.serviceTableAdapter.Fill(serviceDataTable);
                this.currentServicePosition = 0;
                this.currentServiceRow      =
                    (SeniorCitizensDataSet.ServiceRow)serviceDataTable.Rows[currentServicePosition];

                this.loadEmployee();
                this.loadServices();
                this.setNavButtonEnabledToFalse();
            }
        }
Example #2
0
        private void deleteButton_Click(object sender, EventArgs e)
        {
            this.currentEmployeeRow.Delete();

            try
            {
                this.employeeTableAdapter.Update(
                    this.employeeDataTable);

                this.currentEmployeePosition = currentEmployeePosition - 1;
                this.currentEmployeeRow      =
                    (SeniorCitizensDataSet.EmployeeRow)employeeDataTable.Rows[currentEmployeePosition];

                this.loadEmployee();
                this.loadServices();
            }
            catch (DBConcurrencyException ex)
            {
                MessageBox.Show("Error: " +
                                "\nMessage: " + ex.Message,
                                "deleteButton_Click() " + ex.GetType().ToString());
            }
            catch (SqlException ex)
            {
                MessageBox.Show("Error: " +
                                "\nMessage: " + ex.Message,
                                "deleteButton_Click() " + ex.GetType().ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " +
                                "\nMessage: " + ex.Message,
                                "deleteButton_Click() " + ex.GetType().ToString());
            }
        }
Example #3
0
        private void navButton_Click(object sender, EventArgs e)
        {
            switch (((Button)sender).Name)
            {
            case "moveFirstButton":
                this.currentEmployeePosition = 0;
                break;

            case "movePreviousButton":
                this.currentEmployeePosition -= 1;
                break;

            case "moveNextButton":
                this.currentEmployeePosition += 1;
                break;

            case "moveLastButton":
                this.currentEmployeePosition = this.employeeDataTable.Count - 1;
                break;
            }

            try
            {
                if (this.currentEmployeePosition == 0)
                {
                    this.setNavButtonEnabledToFalse();
                }
                else
                {
                    this.setNavButtonEnabledToTrue();
                }

                if (this.currentEmployeePosition == this.employeeDataTable.Count - 1)
                {
                    this.setNavButtonLastEnabledToFalse();
                    this.setButtonsEnabled(true);
                }
                else
                {
                    this.setNavButtonLastEnabledToTrue();
                }
            }
            catch (System.NullReferenceException ex)
            {
                //ignore
            }

            this.currentEmployeeRow =
                (SeniorCitizensDataSet.EmployeeRow)employeeDataTable.Rows[currentEmployeePosition];
            this.loadEmployee();

            this.empFirstNameTextBox.Focus();
            this.hourlyCheckBox.Checked = false;
            this.dailyCheckBox.Checked  = false;
            this.weeklyCheckBox.Checked = false;
        }
Example #4
0
        private void newButton_Click(object sender, EventArgs e)
        {
            //Create copies of the initial row values. Helpful incase anything blows up within the try block. Program can revert back to original data.
            SeniorCitizensDataSet.EmployeeRow bakEmployeeRow =
                this.currentEmployeeRow;
            SeniorCitizensDataSet.ServiceRow bakServiceRow =
                this.currentServiceRow;

            try
            {
                //Create the new row object
                this.currentEmployeeRow =
                    this.employeeDataTable.NewEmployeeRow();

                //initialize the fields
                this.currentEmployeeRow.EmployeeID     = this.currentEmployeeRow.EmployeeID + 1;
                this.currentEmployeeRow.EmpFirstName   = string.Empty;
                this.currentEmployeeRow.EmpLastName    = string.Empty;
                this.currentEmployeeRow.EmpAge         = 0;
                this.currentEmployeeRow.EmpGender      = string.Empty;
                this.currentEmployeeRow.EmpDateOfBirth = System.DateTime.Today;
                this.currentEmployeeRow.EmpPhone       = "123-111-1111";

                //Add the row to the data table
                this.employeeDataTable.AddEmployeeRow(this.currentEmployeeRow);

                //Use table adapter to perform the update
                int countNew = this.employeeTableAdapter.Update(this.employeeDataTable);

                this.addingNew = true;
                this.currentEmployeePosition = this.employeeDataTable.Count - 1;
                this.loadEmployee();
                this.loadServices();
                this.setNavButtonLastEnabledToFalse();
                this.setButtonsEnabled(false);
            }
            catch (SqlException ex)
            {
                MessageBox.Show("Error: " +
                                "\nMessage: " + ex.Message,
                                "newButton_Click() " + ex.GetType().ToString());
                //revert back to original row data if error in try block occurs
                this.currentEmployeeRow = bakEmployeeRow;
                this.currentServiceRow  = bakServiceRow;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " +
                                "\nMessage: " + ex.Message,
                                "newButton_Click() " + ex.GetType().ToString());
                this.currentEmployeeRow = bakEmployeeRow;
                this.currentServiceRow  = bakServiceRow;
            }
        }