Exemplo n.º 1
0
        /* *************************************
         * ********** Business Logic ***********
         * ************************************* */

        /* *************************************
         * ****** DDL Refresh Subroutines *******
         * ************************************* */

        private void DdlDriverRefresh(string DriverValue = null, int DriverIndex = 0)
        {
            DriversTableAdapter driverAdapter = new DriversTableAdapter();

            DropDownList ddlDriver = (DropDownList)FvBookingView.FindControl("ddlDriver");

            ddlDriver.DataSource     = driverAdapter.GetDataBasics();
            ddlDriver.DataValueField = "UserID";
            ddlDriver.DataTextField  = "Driver";

            if (DriverValue == "" || DriverValue == null)
            {
                ddlDriver.SelectedIndex = DriverIndex;
            }
            else
            {
                ddlDriver.SelectedValue = DriverValue;
            }

            ddlDriver.DataBind();

            if (IsBlacklisted())
            {
                Response.Write("<script LANGUAGE='JavaScript' >alert('This Driver has been blacklisted for cancelled appointments. Bookings are now only available in person')</script>");
            }
        }
Exemplo n.º 2
0
        private void PageDataRefresh()
        {
            string dID       = txtSearchUserID.Text.Trim();
            string dForename = txtSearchForename.Text.Trim();
            string dSurname  = txtSearchSurname.Text.Trim();
            string dAddress1 = txtSearchAddress1.Text.Trim();
            string dAddress2 = txtSearchAddress2.Text.Trim();
            string dCity     = txtSearchCity.Text.Trim();
            string dCounty   = txtSearchCounty.Text.Trim();
            string dPostCode = txtSearchPostCode.Text.Trim();
            // Force empty strings to nulls?

            // Validity checks
            bool valid_dDobStart = DateTime.TryParse(txtSearchDateOfBirth_Start.Text.Trim(), out DateTime dDobStart);
            bool valid_dDobEnd   = DateTime.TryParse(txtSearchDateOfBirth_End.Text.Trim(), out DateTime dDobEnd);

            if (!valid_dDobStart)
            {
                dDobStart = Convert.ToDateTime("1/1/1753 12:00:00 AM");
            }
            if (!valid_dDobEnd)
            {
                dDobEnd = DateTime.MaxValue;
            }

            DriversTableAdapter driverAdapter = new DriversTableAdapter();

            LvDriverList.DataSource = driverAdapter.GetDataByParameters(dID, dForename, dSurname, dDobStart, dDobEnd, dAddress1, dAddress2, dCity, dCounty, dPostCode);
            LvDriverList.DataBind();
        }
Exemplo n.º 3
0
        protected void FvDriverView_CallInsertOrUpdate(string CallCommand)
        {
            // Code versions of all controls
            DropDownList ddlUser        = (DropDownList)FvDriverView.FindControl("ddlUser");
            TextBox      txtForename    = (TextBox)FvDriverView.FindControl("txtForename");
            TextBox      txtSurname     = (TextBox)FvDriverView.FindControl("txtSurname");
            TextBox      txtDateOfBirth = (TextBox)FvDriverView.FindControl("txtDateOfBirth");
            TextBox      txtAddress1    = (TextBox)FvDriverView.FindControl("txtAddress1");
            TextBox      txtAddress2    = (TextBox)FvDriverView.FindControl("txtAddress2");
            TextBox      txtCity        = (TextBox)FvDriverView.FindControl("txtCity");
            TextBox      txtCounty      = (TextBox)FvDriverView.FindControl("txtCounty");
            TextBox      txtPostCode    = (TextBox)FvDriverView.FindControl("txtPostCode");

            // Assign all text properties of controls to variables
            // Or skip this and assign straight into INSERT/UPDATE parameters
            string currentUserID = ddlUser.SelectedValue;
            string forename      = txtForename.Text;
            string surname       = txtSurname.Text;
            string dateofbirth   = txtDateOfBirth.Text;
            string address1      = txtAddress1.Text;
            string address2      = txtAddress2.Text;
            string city          = txtCity.Text;
            string county        = txtCounty.Text;
            string postCode      = txtPostCode.Text;

            DriversTableAdapter DriverAdapter = new DriversTableAdapter();

            try
            {
                if (CallCommand == "Update")
                {
                    // Perform Update
                    DriverAdapter.UpdateRecord(forename, surname, dateofbirth, address1, address2, city, county, postCode, currentUserID);

                    //Response.Write("<script LANGUAGE='JavaScript' >alert('Record Edited')</script>");
                    ClientScript.RegisterStartupScript(GetType(), "text", "AlertTimeout();", true);

                    // Return to Read Only mode
                    FvDriverView.ChangeMode(FormViewMode.ReadOnly);
                    PageDataRefresh();
                }
                else if (CallCommand == "Insert")
                {
                    //DriverAdapter.InsertRecord(currentUserID, forename, surname, dateofbirth, address1, address2, city, county, postCode);
                    //Response.Write("<script LANGUAGE='JavaScript' >alert('Record Added')</script>");
                    //FvDriverView.ChangeMode(FormViewMode.ReadOnly);

                    // Perform INSERT
                    string newID = DriverAdapter.InsertAndReturnID(currentUserID, forename, surname, dateofbirth, address1, address2, city, county, postCode).ToString();
                    // Display message to user
                    ClientScript.RegisterStartupScript(GetType(), "text", "AlertTimeout();", true);
                    // Redirect User
                    Response.Redirect("~/Management/DriverView.aspx?id=" + newID);
                }
            }
            catch (System.Exception ex)
            {
                Response.Write("<script LANGUAGE='JavaScript' >alert('An ERROR occurred connecting to the database. " + ex.Message + "')</script>");
            }
        }
Exemplo n.º 4
0
        private void PageDataRefresh()
        {
            string id = Request.QueryString["id"];

            if (id == null || id == "0")
            {
                id = "0";
                FvDriverView.ChangeMode(FormViewMode.Insert);
            }

            /* *********** Configure DAL *********** */
            DriversTableAdapter driverAdapter = new DriversTableAdapter();

            FvDriverView.DataSource = driverAdapter.GetDataById(id);
            FvDriverView.DataBind();


            /* ****** Refresh Drop Down Lists ****** */

            if (FvDriverView.CurrentMode == FormViewMode.Insert)
            {
                DdlUserRefresh();
            }
            else if (FvDriverView.CurrentMode == FormViewMode.Edit || FvDriverView.CurrentMode == FormViewMode.ReadOnly)
            {
                DdlUserRefresh(id);
            }
        }
Exemplo n.º 5
0
        private bool IsDriver()
        {
            DriversTableAdapter driverAdapter = new DriversTableAdapter();
            DataTable           drivers       = driverAdapter.GetDataById(User.Identity.GetUserId());

            if (drivers.Rows.Count > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 6
0
        private void PageDataRefresh()
        {
            string id = id = User.Identity.GetUserId();

            if (id == null)
            {
                Response.Redirect("~/Account/Login.aspx");
            }

            /* *********** Configure DAL *********** */
            DriversTableAdapter driverAdapter = new DriversTableAdapter();

            FvDriverView.DataSource = driverAdapter.GetDataById(id);
            FvDriverView.DataBind();
        }
Exemplo n.º 7
0
        private void DdlVehicleRefresh(string VehicleValue = null)
        {
            VehiclesTableAdapter vehicleAdapter = new VehiclesTableAdapter();
            DriversTableAdapter  driverAdapter  = new DriversTableAdapter();

            // ************************************************
            // Determine age from selected driver date of birth
            DropDownList ddlDriver = (DropDownList)FvBookingView.FindControl("ddlDriver");
            DateTime     dob       = Convert.ToDateTime(driverAdapter.GetDataById(ddlDriver.SelectedValue)[0]["DateOfBirth"]);
            int          age       = DateTime.Now.Year - dob.Year;

            if (DateTime.Now.DayOfYear < dob.DayOfYear)
            {
                age = age - 1;
            }

            // ************************************************
            // Determine date range for vehicle availability
            TextBox txtDateFrom = (TextBox)FvBookingView.FindControl("txtDateFrom");
            TextBox txtDateDue  = (TextBox)FvBookingView.FindControl("txtDateDue");
            bool    isDateFrom  = DateTime.TryParse(txtDateFrom.Text, out DateTime dateFrom);
            bool    isDateDue   = DateTime.TryParse(txtDateDue.Text, out DateTime dateDue);

            //if (!isDateFrom)
            //{
            //	dateFrom = DateTime.Today;
            //}
            //if (!isDateDue)
            //{
            //	dateDue = DateTime.Today.AddDays(14);
            //}



            //Set end of dateDue
            dateDue = dateDue.AddMinutes(1439);
            // ************************************************


            TextBox txtBookingID = (TextBox)FvBookingView.FindControl("txtBookingID");

            int.TryParse(txtBookingID.Text, out int bookingid);

            DropDownList ddlVehicle = (DropDownList)FvBookingView.FindControl("ddlVehicle");

            if (isDateFrom && isDateDue)
            {
                ddlVehicle.DataSource = vehicleAdapter.GetDataByAgeAndRange(Convert.ToByte(age), dateFrom, dateDue, bookingid);
            }
            else
            {
                ddlVehicle.DataSource = vehicleAdapter.GetDataAboveAge(Convert.ToByte(age));
            }
            ddlVehicle.DataValueField = "ID";
            ddlVehicle.DataTextField  = "Details";

            ddlVehicle.ClearSelection();
            ddlVehicle.DataBind();

            if ((VehicleValue == "" || VehicleValue == null) && ddlVehicle.Items.Count > 0)
            {
                VehicleValue             = ddlVehicle.SelectedValue;
                ddlVehicle.SelectedValue = VehicleValue;
                ddlVehicle.SelectedIndex = 0;
            }

            // Revert DDL if previous SelectedValue in new list (must be done after a DataBind)
            if (ddlVehicle.Items.FindByValue(VehicleValue) != null)
            {
                ddlVehicle.SelectedValue = VehicleValue;
            }

            ddlVehicle.DataBind();

            // if DailyRateCharged not set (but a value exists in DDL), set it initially
            TextBox txtDailyRate = (TextBox)FvBookingView.FindControl("txtDailyRateCharged");

            if (txtDailyRate.Text == "" && ddlVehicle.SelectedIndex >= 0)
            {
                Decimal dailyRate = Convert.ToDecimal(vehicleAdapter.GetDataById(Convert.ToInt32(ddlVehicle.SelectedValue))[0]["DailyRate"].ToString());
                txtDailyRate.Text = dailyRate.ToString("C");
            }
        }