Beispiel #1
0
        /// <summary>
        /// event handler when click sell button, update the vehicle table
        /// </summary>
        void btnSell_Click(object sender, EventArgs e)
        {
            try
            {
                _currentRow["OptionsPrice"] = _optionsCharge;
                _currentRow["SoldBy"]       = ((DataRowView)_salesStaffBindingSource.Current).Row["ID"];


                _vehicleStockData.Update();

                this.Close();
            }
            catch (Exception ex)
            {
                // Display an error message
                AutomotiveManager.ShowMessage("An error occurred while attempting to sell the vehicle.",
                                              "Database Error",
                                              MessageBoxButtons.OK,
                                              MessageBoxIcon.Error);

                AutomotiveManager.recordError(ex);
                //close the form
                this.Shown += new EventHandler(frmVehicleSale_Shown);
            }
        }
Beispiel #2
0
        void txtTradeInAllowance_Validating(object sender, CancelEventArgs e)
        {
            //declare a errorMessage string and set it's default value to empty string
            string errorMessage = string.Empty;

            //invoke the IsNumber in the AutomotiveManager class to check if the text of TradeInAllowance could be parse to a number
            if (!AutomotiveManager.IsNumber(txtTradeInAllowance.Text))
            {
                //set error message
                errorMessage = "Please enter a numeric value.";
            }
            //parse the text of the TradeInAllowance textbox to decimal and check if it less than 0
            else if (Decimal.Parse(txtTradeInAllowance.Text) < 0)
            {
                //set error message
                errorMessage = "Please enter a value greater than or equal to zero.";
            }

            //check if the errorMessage is not an empty string
            if (!errorMessage.Equals(string.Empty))
            {
                //set the CancelEventArgs' Cancel property to true
                e.Cancel = true;

                //invoke SetError method in errorProvider control and set the errorMessage to TradeInAllowance textbox
                errorProvider.SetError(txtTradeInAllowance, errorMessage);

                //set focus to TradeInAllowance textbox
                txtTradeInAllowance.Focus();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Handles the Load event of the form.
        /// </summary>
        private void frmEditVehicleStock_Load()
        {
            if (_editType == EditType.Eidt)
            {
                // Set the title of the form
                this.Text = "Edit Vehicle";

                try
                {
                    // Bind data source to the form controls
                    bindControls();
                }
                catch (Exception ex)
                {
                    // Display an error message
                    AutomotiveManager.ShowMessage("Could not load record.", "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    AutomotiveManager.recordError(ex);

                    this.Shown += new EventHandler(delegate(object s, EventArgs evt)
                    {
                        this.Close();
                    });
                }
            }
            else
            {
                // Set the title of the form
                this.Text            = "New Vehicle";
                radAutomatic.Checked = true;
            }
        }
Beispiel #4
0
        private void updateMonthlyPayment()
        {
            //invoke the Payment method in AutomotiveManager class use the parameter to calculate the value of MonthlyPayment lable
            lblMonthlyPayment.Text = (AutomotiveManager.Payment((Decimal)hsbInterestRate.Value / 10000m / 12m,
                                                                hsbNoOfYear.Value * 12m,
                                                                Decimal.Parse(lblAmountDue.Text.Substring(1, lblAmountDue.Text.Length - 1)))).ToString("c");

            //set focus to VehicleSalePrice textbox
            txtVehicleSalePrice.Focus();
        }
Beispiel #5
0
        /// <summary>
        /// the method to save the current insert
        /// </summary>
        /// <returns>ture if SuccessfulSaved, false when failed</returns>
        private bool saveCurrentRecord()
        {
            _errorFocus = false;

            bool isSuccessfulSaved = false;

            if (this.ValidateChildren())
            {
                try
                {
                    // When the edit mode of the form is new
                    if (_editType == EditType.New)
                    {
                        // Get a reference to the data table from the bind source object
                        DataTable dataTable = (DataTable)_bindingSource.DataSource;

                        // Add a new row to the data table
                        DataRow row = dataTable.NewRow();

                        // Define all the columns and values in the row
                        row["StockNumber"]      = txtStockNumber.Text.Trim();
                        row["ManufacturedYear"] = txtYear.Text.Trim();
                        row["Make"]             = txtMake.Text.Trim();
                        row["Model"]            = txtModel.Text.Trim();
                        row["Mileage"]          = txtMileage.Text.Trim();
                        row["Automatic"]        = radAutomatic.Checked;
                        row["Colour"]           = txtColour.Text.Trim();
                        row["BasePrice"]        = txtBasePrice.Text.Trim();

                        // Add the new row to the data table
                        dataTable.Rows.Add(row);
                    }

                    // Update the data set to the data source
                    _vehicleStockData.Update();

                    isSuccessfulSaved = true;
                }
                catch (Exception ex)
                {
                    // Display an error message
                    AutomotiveManager.ShowMessage("An error occured while saving the contact.", "Save Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    AutomotiveManager.recordError(ex);
                }
            }

            return(isSuccessfulSaved);
        }
Beispiel #6
0
        /// <summary>
        /// load the salses staff information form the database
        /// </summary>
        private void frmSalesStaffSection_Load()
        {
            try
            {
                string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=AMDatabase.mdb";

                string tableName   = "SalesStaff";
                string selectQuery =
                    string.Format("SELECT * FROM {0}", tableName);

                // Construct an instance of the DataTier
                _salesStaffData = new SalesStaffData(connectionString, tableName, selectQuery);

                _salesStaffBindingSource = new BindingSource();

                _salesStaffBindingSource.PositionChanged += new EventHandler(_salesStaffBindingSource_PositionChanged);

                _salesStaffBindingSource.DataSource = _salesStaffData.GetAllRows();

                bindControls();

                updateUI();
            }
            catch (DbException dbex)
            {
                // Display an error message
                AutomotiveManager.ShowMessage("An error occurred fetching sales staff data.",
                                              "Database Error",
                                              MessageBoxButtons.OK,
                                              MessageBoxIcon.Error);

                AutomotiveManager.recordError(dbex);
                //close the form
                this.Shown += new EventHandler(frmVehicleSale_Shown);
            }
            catch (NullReferenceException nuex)
            {
                // Display an error message
                AutomotiveManager.ShowMessage("There are currently no sales staff entered in the system.",
                                              "Vehicle Sale",
                                              MessageBoxButtons.OK,
                                              MessageBoxIcon.Exclamation);

                AutomotiveManager.recordError(nuex);
                //close the form
                this.Shown += new EventHandler(frmVehicleSale_Shown);
            }
        }
Beispiel #7
0
        /// <summary>
        /// the event handler to check if the value of textbox is a year value(4 digits)
        /// </summary>
        void txtYear_Validating(object sender, CancelEventArgs e)
        {
            if (!AutomotiveManager.IsNumber(txtYear.Text.Trim()) || txtYear.Text.Trim().Length != 4)
            {
                // Prevents the validated event from being triggered
                e.Cancel = true;

                if (!_errorFocus)
                {
                    ((TextBox)sender).Focus();
                    _errorFocus = true;
                }

                // Show the error icon beside the control
                errorProvider.SetError(txtYear, "Please enter a valid four digit year. Eg. 1977");
            }
        }
Beispiel #8
0
        /// <summary>
        /// the event handler to check if the value of textbox is a numeric value
        /// </summary>
        void txtNumeric_Validating(object sender, CancelEventArgs e)
        {
            if (!AutomotiveManager.IsNumber(((TextBox)sender).Text.Trim()))
            {
                // Prevents the validated event from being triggered
                e.Cancel = true;

                if (!_errorFocus)
                {
                    ((TextBox)sender).Focus();
                    _errorFocus = true;
                }

                // Show the error icon beside the control
                errorProvider.SetError(((Control)sender), "Please enter a numeric value for this field.");
            }
        }
Beispiel #9
0
        /// <summary>
        /// Handles the Load event of the form.
        /// </summary>
        private void frmVehicleStock_Load()
        {
            // Get string data from the Resources.resx file
            string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=AMDatabase.mdb";
            string tableName        = "VehicleStock";
            string selectQuery      =
                string.Format("SELECT ID, StockNumber, ManufacturedYear, Make, Model, Mileage, Automatic, Colour, BasePrice, SoldBy, OptionsPrice FROM {0} WHERE SoldBy = 0", tableName);

            try
            {
                // Construct an instance of the DataTier
                _vehicleStockData = new VehicleStockData(connectionString, tableName, selectQuery);

                // Constructs a BindingSource object
                // BindingSource - defines the data source of the form.
                _bindingSource = new BindingSource();

                // Set the data source of the form to the data table from the DataTier
                _bindingSource.DataSource = _vehicleStockData.GetAllRows();

                // Set the data source of the DataGridView to the binding source
                dgvVehicles.DataSource = _bindingSource;

                // Hides the ID column in the datagrid view
                dgvVehicles.Columns["ID"].Visible = false;

                // Hides the SoldBy column in the datagrid view
                dgvVehicles.Columns["SoldBy"].Visible = false;

                // Hides the OptionsPrice column in the datagrid view
                dgvVehicles.Columns["OptionsPrice"].Visible = false;
            }
            catch (Exception ex)
            {
                // Display an error message
                AutomotiveManager.ShowMessage("An error occurred fetching vehicle stock data.",
                                              "Database Error",
                                              MessageBoxButtons.OK,
                                              MessageBoxIcon.Error);

                AutomotiveManager.recordError(ex);

                this.Shown += new EventHandler(frmVehicleStock_Shown);
            }
        }
Beispiel #10
0
        /// <summary>
        /// the event handler when click the remove context menu in vehicle data grid view
        /// </summary>
        private void mnuRemove_Click(object sender, EventArgs e)
        {
            // Get a reference to the selected row
            DataGridViewRow selectedRow = dgvVehicles.CurrentRow;

            DialogResult result = AutomotiveManager.ShowMessage(String.Format("Are you sure you want to remove {0} {1} {2}",
                                                                              selectedRow.Cells["ManufacturedYear"].Value,
                                                                              selectedRow.Cells["Make"].Value,
                                                                              selectedRow.Cells["Model"].Value),
                                                                "Remove Vehicle",
                                                                MessageBoxButtons.YesNo,
                                                                MessageBoxIcon.Warning,
                                                                MessageBoxDefaultButton.Button2);

            if (result == DialogResult.Yes)
            {
                try
                {
                    // Remove the row from the datagridview's row collection
                    dgvVehicles.Rows.Remove(selectedRow);

                    // Update the data source bound to the datagridview
                    this._vehicleStockData.Update();

                    // When rows still exist in the data grid view
                    if (dgvVehicles.Rows.Count > 0)
                    {
                        // Select the last row
                        dgvVehicles.Rows[dgvVehicles.Rows.Count - 1].Selected = true;
                    }
                }
                catch (Exception ex)
                {
                    // Display an error message
                    AutomotiveManager.ShowMessage(String.Format("An error occurred removing {0} {1} {2}",
                                                                selectedRow.Cells["ManufacturedYear"].Value,
                                                                selectedRow.Cells["Make"].Value,
                                                                selectedRow.Cells["Model"].Value),
                                                  "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    AutomotiveManager.recordError(ex);
                }
            }
        }
Beispiel #11
0
        void lnkResetForm_Click(object sender, EventArgs e)
        {
            //declare a DialogResult and invoke ShowMessage method in the AutomotiveManager class to set the default value
            DialogResult result =
                AutomotiveManager.ShowMessage("Do you want to reset this sales quote?", "Sales Quote", MessageBoxButtons.YesNo);

            //check if the user click the yes button
            if (result == DialogResult.Yes)
            {
                //invoke unwrapEventHandlerForRadChk method to unwrap the EventHandler from the checkbox and radio buttons
                unwrapEventHandlerForRadChk();
                //invoke clearForm method
                clearForm();
            }
            else
            {
                //set focus to VehicleSalePrice textbox
                txtVehicleSalePrice.Focus();
            }
        }
Beispiel #12
0
        public frmCarWash()
        {
            InitializeComponent();
            //initial the CobListLoad
            CobListLoad = true;

            try
            {
                loadData();

                //set the data to the combom box
                foreach (DropDownItem item in _packageItems)
                {
                    cboPackage.Items.Add(item.Description);
                }

                foreach (DropDownItem item in _fragranceItems)
                {
                    cboFragrance.Items.Add(item.Description);
                }
            }
            catch (FileNotFoundException fileNotFoundException)
            {
                AutomotiveManager.ShowMessage("An error occurred while loading car wash data.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //when occour the error print the error file
                AutomotiveManager.recordError(fileNotFoundException);
                //when occour the error set to false
                CobListLoad = false;
            }

            cboPackage.SelectedValueChanged   += new EventHandler(cboPackage_SelectedValueChanged);
            cboFragrance.SelectedValueChanged += new EventHandler(cboFragrance_SelectedValueChanged);
            mnuCarWashGenerateInvoice.Click   += new EventHandler(mnuCarWashGenerateInvoice_Click);

            //check if the cobom box have load the items
            if (cboPackage.Items.Count * cboFragrance.Items.Count > 0)
            {
                cboPackage.SelectedIndex   = 0;
                cboFragrance.SelectedIndex = 2;
            }
        }
Beispiel #13
0
        /// <summary>
        /// the event handler when close the form
        /// </summary>
        void frmEditVehicleStock_FormClosing(object sender, FormClosingEventArgs e)
        {
            // Applies pending changes to the binding source
            _bindingSource.EndEdit();

            // When the edit mode is new or current row has changes
            if (_editType == EditType.New || ((DataRowView)_bindingSource.Current).Row.RowState == DataRowState.Modified)
            {
                // When this event is not triggered from the btnSave_Click event
                if (_result == DialogResult.None)
                {
                    // Ask the user if they wish to save the changes
                    _result = AutomotiveManager.ShowMessage("Save changes?", "New Vehicle Stock or Edit Vehicle Stock", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button3);
                }

                // Evaluate the users choice
                switch (_result)
                {
                case DialogResult.Yes:
                    // Cancels the form close when the record cannot be saved
                    e.Cancel = !saveCurrentRecord();
                    break;

                case DialogResult.No:
                    // Rollback changes made to the data source
                    ((DataTable)_bindingSource.DataSource).RejectChanges();
                    break;

                case DialogResult.Cancel:
                    // Cancels the form close
                    e.Cancel = true;
                    break;
                }
            }

            // Reset the dialog result
            _result = DialogResult.None;
        }
Beispiel #14
0
        /// <summary>
        /// Cost textbox validating
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void txtCost_Validating(object sender, CancelEventArgs e)
        {
            string errorMessage = string.Empty;

            if (!AutomotiveManager.IsNumber(txtCost.Text))
            {
                errorMessage = "Please enter a numeric value.";
            }
            else if (Decimal.Parse(txtCost.Text) < 0)
            {
                errorMessage = "Please enter a value greater than zero.";
            }

            if (!errorMessage.Equals(string.Empty))
            {
                //set the CancelEventArgs' Cancel property to true
                e.Cancel = true;
                //invoke SetError method in errorProvider control and set the errorMessage to Cost textbox
                errorProvider.SetError(txtCost, errorMessage);
                //set focus to Cost textbox
                txtCost.Focus();
            }
        }
Beispiel #15
0
        /// <summary>
        /// the method to load the VehicleStock combo box
        /// </summary>
        private void frmQuote_Load(int selectedIndex = 0)
        {
            try
            {
                string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=AMDatabase.mdb";

                string tableName   = "VehicleStock";
                string selectQuery = string.Format("SELECT * FROM {0} WHERE SoldBy = 0", tableName);
                //string selectQuery = string.Format("SELECT * FROM {0}", tableName);

                // Construct an instance of the DataTier
                _vehicleStockData = new VehicleStockData(connectionString, tableName, selectQuery);

                _bindingSource            = new BindingSource();
                _bindingSource.DataSource = _vehicleStockData.GetAllRows();

                //Filters the data source to only show rows that have a value of 0 in column SoldBy
                //_bindingSource.Filter = "SoldBy = 0";

                cboVehicleStock.DataSource = _bindingSource;

                cboVehicleStock.DisplayMember = "StockNumber";
                cboVehicleStock.ValueMember   = "BasePrice";

                //cboVehicleStock.DataBindings.Add("Text", _bindingSource, "StockNumber");

                cboVehicleStock.SelectedValueChanged += new EventHandler(btnCalculateQuote_Click);

                if (cboVehicleStock.Items.Count > selectedIndex)
                {
                    cboVehicleStock.SelectedIndex = selectedIndex;
                }
                else
                {
                    cboVehicleStock.SelectedIndex = selectedIndex - 1;
                }

                if (this.ValidateChildren() && cboVehicleStock.Items.Count != 0)
                {
                    //invoke bindEventHandlerForRadChk method to bind functions to radio buttons and checkboxes
                    bindEventHandlerForRadChk();

                    //invoke UpdateSummaryFinance method to update summary and finance section
                    UpdateSummaryFinance();
                }
            }
            catch (DbException dbex)
            {
                // Display an error message
                AutomotiveManager.ShowMessage("An error occurred fetching vehicle stock data.",
                                              "Database Error",
                                              MessageBoxButtons.OK,
                                              MessageBoxIcon.Error);

                AutomotiveManager.recordError(dbex);
                //close the form
                this.Shown += new EventHandler(frmQuote_Shown);
            }
            catch (NullReferenceException nuex)
            {
                // Display an error message
                AutomotiveManager.ShowMessage("There are currently no vehicles in stock to sell.",
                                              "Vehicle Sale",
                                              MessageBoxButtons.OK,
                                              MessageBoxIcon.Warning);

                AutomotiveManager.recordError(nuex);
                //close the form
                this.Shown += new EventHandler(frmQuote_Shown);
            }
        }