Beispiel #1
0
        void frmVehicleStock_Load(object sender, EventArgs e)
        {
            string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Data//AMDatabase.mdb";
            string tableName        = "VehicleStock";
            string selectQuery      = "SELECT * FROM VehicleStock";

            try
            {
                _vehicleStockData = new VehicleStockData(connectionString, tableName, selectQuery);

                _bindingSource = new BindingSource();

                _bindingSource.DataSource = _vehicleStockData.GetAllRows();

                _bindingSource.Filter = "SoldBy = 0";

                dgvVehicles.DataSource = _bindingSource;

                dgvVehicles.Columns["ID"].Visible = false;

                dgvVehicles.Columns["SoldBy"].Visible = false;

                dgvVehicles.Columns["OptionsPrice"].Visible = false;
            }
            catch (Exception exception)
            {
                MessageBox.Show("An error occurred fetching vehicle stock data.", "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                errorLog(exception);
            }
        }
Beispiel #2
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 #3
0
        /// <summary>
        /// the constructor
        /// </summary>
        /// <param name="currentIndex">the index of current row</param>
        /// <param name="optionsCharge">the option fee</param>
        /// <param name="vehicleStockData">the data retrive form the database</param>
        public frmVehicleSale(int currentIndex, decimal optionsCharge, VehicleStockData vehicleStockData)
        {
            _optionsCharge    = optionsCharge;
            _vehicleStockData = vehicleStockData;
            //_vehicleStockTable = vehicleStockData.GetAllRows();
            _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";
            //_vehicleStockTable = (DataTable)_bindingSource.DataSource;
            //_currentRow = _vehicleStockTable.Rows[currentIndex];
            _currentRow = ((DataTable)_bindingSource.DataSource).Rows[currentIndex];

            InitializeComponent();
            frmVehicleSaleSection_Load();
            frmSalesStaffSection_Load();

            btnFirst.Click    += new EventHandler(btnFirst_Click);
            btnLast.Click     += new EventHandler(btnLast_Click);
            btnPrevious.Click += new EventHandler(btnPrevious_Click);
            btnNext.Click     += new EventHandler(btnNext_Click);
            btnSell.Click     += new EventHandler(btnSell_Click);
        }
Beispiel #4
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);
            }
        }