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 servicesComboBox_SelectedValueChanged(object sender, EventArgs e)
        {
            try
            {
                if (servicesComboBox.SelectedIndex != -1)
                {
                    this.currentServiceRow =
                        (SeniorCitizensDataSet.ServiceRow)serviceDataTable.Rows[this.servicesComboBox.SelectedIndex];

                    this.serviceDescriptionTextBox.Text = this.currentServiceRow.ServiceDescription;
                    this.serviceRateHourlyTextBox.Text  = this.currentServiceRow.ServiceRateHourly.ToString();
                    this.serviceRateDailyTextBox.Text   = this.currentServiceRow.ServiceRateDaily.ToString();
                    this.serviceRateWeeklyTextBox.Text  = this.currentServiceRow.ServiceRateWeekly.ToString();
                }
                else
                {
                    this.currentServiceRow =
                        (SeniorCitizensDataSet.ServiceRow)serviceDataTable.Rows[0];

                    this.serviceDescriptionTextBox.Text = this.currentServiceRow.ServiceDescription;
                    this.serviceRateHourlyTextBox.Text  = this.currentServiceRow.ServiceRateHourly.ToString();
                    this.serviceRateDailyTextBox.Text   = this.currentServiceRow.ServiceRateDaily.ToString();
                    this.serviceRateWeeklyTextBox.Text  = this.currentServiceRow.ServiceRateWeekly.ToString();
                }
            }
            catch (System.NullReferenceException ex)
            {
                //ignore
            }

            this.hourlyCheckBox.Checked = false;
            this.dailyCheckBox.Checked  = false;
            this.weeklyCheckBox.Checked = false;
        }
Example #3
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;
            }
        }