コード例 #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);
            }
        }
コード例 #2
0
        /// <summary>
        /// the constructor of this form
        /// </summary>
        /// <param name="editType">the type of how to open this form</param>
        /// <param name="bindingSource">the data source</param>
        /// <param name="vehicleStockData">the data use to connect to the database</param>
        public frmEditVehicleStock(EditType editType, BindingSource bindingSource, VehicleStockData vehicleStockData)
        {
            _bindingSource    = bindingSource;
            _vehicleStockData = vehicleStockData;
            _editType         = editType;

            InitializeComponent();
            frmEditVehicleStock_Load();

            //Validation
            txtStockNumber.Validating += new CancelEventHandler(txtStockNumber_Validating);
            txtStockNumber.Validated  += new EventHandler(txtBox_Validated);

            txtMake.Validating += new CancelEventHandler(txtBoxRequired_Validating);
            txtMake.Validated  += new EventHandler(txtBox_Validated);

            txtModel.Validating += new CancelEventHandler(txtBoxRequired_Validating);
            txtModel.Validated  += new EventHandler(txtBox_Validated);

            txtColour.Validating += new CancelEventHandler(txtBoxRequired_Validating);
            txtColour.Validated  += new EventHandler(txtBox_Validated);

            txtYear.Validating += new CancelEventHandler(txtYear_Validating);
            txtYear.Validated  += new EventHandler(txtBox_Validated);


            txtMileage.Validating += new CancelEventHandler(txtNumeric_Validating);
            txtMileage.Validated  += new EventHandler(txtBox_Validated);

            txtBasePrice.Validating += new CancelEventHandler(txtNumeric_Validating);
            txtBasePrice.Validated  += new EventHandler(txtBox_Validated);

            this.FormClosing += new FormClosingEventHandler(frmEditVehicleStock_FormClosing);
        }
コード例 #3
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);
            }
        }
コード例 #4
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);
        }
コード例 #5
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);
            }
        }