Example #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"];
            }
        }