Example #1
0
        private void btnSaveServiceType_Click(object sender, EventArgs e)
        {
            lblServiceTypeID.Text = null;
            DataRow newServiceTypeRow = DM.dtServiceType.NewRow();

            if ((txtAddDescription.Text == "") || (txtAddHourlyRate.Text == ""))
            {
                MessageBox.Show("You must type in a Service type description and hourly rate.", "Error");
            }
            else
            {
                try
                {
                    newServiceTypeRow["Description"] = txtAddDescription.Text;
                    newServiceTypeRow["HourlyRate"]  = Convert.ToDouble(txtAddHourlyRate.Text);
                    DM.dtServiceType.Rows.Add(newServiceTypeRow);
                    MessageBox.Show("Service Type added successfully.", "Success");
                    DM.UpdateServiceType();
                }
                catch (FormatException ex)
                {
                    MessageBox.Show("Please enter a value for hourly rate.", "Error");
                }
            }
            return;
        }
Example #2
0
        private void btnDeleteServiceType_Click(object sender, EventArgs e)
        {
            DataRow deleteServiceTypeRow = DM.dtServiceType.Rows[currencyManager.Position];

            DataRow[] ServiceRow   = DM.dtService.Select("ServiceTypeID =" + txtServiceTypeID.Text);
            DataRow[] EquipmentRow = DM.dtServiceTypeEquipment.Select("ServiceTypeID =" + txtServiceTypeID.Text);
            if (ServiceRow.Length == 0 && EquipmentRow.Length == 0)
            {
                if (MessageBox.Show("Are you sure want to delete this record?", "Warning", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    deleteServiceTypeRow.Delete();
                    DM.UpdateServiceType();
                    MessageBox.Show("Service type deleted successfully", "Success");
                    return;
                }
            }
            else
            {
                if (ServiceRow.Length != 0)
                {
                    MessageBox.Show("You may only delete Service Types that are not assigned to services");
                    return;
                }

                if (EquipmentRow.Length != 0)
                {
                    MessageBox.Show("You may only delete Service Types who are not allocated equipment");
                    return;
                }
            }
        }