Exemplo n.º 1
0
        private void btnLateReturn_Click(object sender, EventArgs e)
        {
            if (cboReturnCar.Text.Equals(""))
            {
                MessageBox.Show("Chose to return", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cboReturnCar.Focus();
                return;
            }

            var today = DateTime.Today.ToString("yyyy-MM-dd");
            //From https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings
            var endDate = DateTime.ParseExact(txtEndDate.Text, "yyyy-MM-dd",
                                              CultureInfo.InvariantCulture);
            var startDate = DateTime.ParseExact(txtStartDate.Text, "yyyy-MM-dd",
                                                CultureInfo.InvariantCulture);
            var todayDate = DateTime.ParseExact(today, "yyyy-MM-dd",
                                                CultureInfo.InvariantCulture);

            if (DateTime.Today < endDate)
            {
                MessageBox.Show("This should be a normal return", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnReturnCar.Focus();
                return;
            }

            var from = startDate.ToString("yyyy-MM-dd");
            var to   = todayDate.ToString("yyyy-MM-dd");

            var ds = new DataSet();

            grdTotalCost.DataSource = Rates.getBookingCost(ds, to, from, txtReg.Text).Tables["book"];
            var    tot   = new Booking();
            string total = grdTotalCost.Rows[0].Cells[0].Value.ToString();

            tot.setTotal(Convert.ToDecimal(total));
            tot.setBookNo(Convert.ToInt32(txtBookingID.Text));
            tot.updateTotal();

            updateBookingCar();
        }
        private void grdSelectCar_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            btnMakeBooking.Visible = true;
            var from = dtpFrom.Value.ToString("yyyy-MM-dd");
            var to   = dtpTo.Value.ToString("yyyy-MM-dd");

            //From https://www.youtube.com/watch?v=SqQAbzDs3jo
            if (e.RowIndex >= 0)
            {
                var view = grdSelectCar.Rows[e.RowIndex];

                reg = view.Cells["RegNo"].Value.ToString();
                txtRegChosen.Text = reg;

                cost         = view.Cells["cost"].Value.ToString();
                txtCost.Text = cost;

                var ds = new DataSet();

                grdTotalCost.DataSource = Rates.getBookingCost(ds, to, from, reg).Tables["book"];
            }
        }
Exemplo n.º 3
0
        public void loadCombo()
        {
            // create instance of data set
            var ds = new DataSet();

            ds = Rates.getCatID(ds);

            //Remove existing items from combo box
            cboCarCategory.Items.Clear();

            //load data from ds
            try
            {
                for (var i = 0; i < ds.Tables["cat"].Rows.Count; i++)
                {
                    cboCarCategory.Items.Add(ds.Tables[0].Rows[i][0].ToString().PadLeft(3, '0'));
                }
            }
            catch (Exception)
            {
                Close();
                parent.Visible = true;
            }
        }
Exemplo n.º 4
0
        private void btnAdd_CLick(object sender, EventArgs e)
        {
            //Validate data
            if (txtCarType.Text.Equals(""))
            {
                MessageBox.Show("Car type field must be entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtCarType.Focus();
                return;
            }

            //check if category already exists
            if (Rates.checkCategoryExists(txtCarType.Text))
            {
                MessageBox.Show("Category ID Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtCarType.Focus();
                return;
            }


            if (!isValidType(txtCarType.Text))
            {
                MessageBox.Show("Car type is invalid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtCarType.Focus();
                return;
            }

            if (!isValidDesc(txtDesc.Text))
            {
                MessageBox.Show("Description field is invalid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtDesc.Focus();
                return;
            }

            if (txtDesc.Text.Equals(""))
            {
                MessageBox.Show("Description field must be entered", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                txtDesc.Focus();
                return;
            }

            if (numericUpRate.Text.Equals(""))
            {
                MessageBox.Show("Rate field must be entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                numericUpRate.Focus();
                return;
            }

            if (numericUpRate.Value < 0)
            {
                MessageBox.Show("Rate field must be greater than zero", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                numericUpRate.Focus();
                return;
            }

            try
            {
                //Save data in rate file

                var myRate = new Rates(txtCarType.Text, txtDesc.Text, Convert.ToDecimal(numericUpRate.Text));



                myRate.addRates();

                //Display confirmation
                MessageBox.Show("Car Type Added", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);


                //Reset UI

                txtCarType.Clear();
                txtDesc.Clear();
                numericUpRate.ResetText();
                txtCarType.Focus();
            }
            catch (Exception)
            {
                Close();
                parent.Visible = true;
            }
        }