Last update for Beta === (+73,-13) CPool/TripOffer.aspx.cs === @@ -19,17 +19,48 @@ UserBL _userBL = new UserBL(); Trip _trip = new Trip(); + + + protected override void OnInit(EventArgs e) + { + txbTripTime.Attributes.Add("onkeypress", "validateNumKey()"); + txbTripTime.Attributes.Add("onblur", "CheckTime(this)"); + txbTripTime.Attributes.Add("onkeyUp", "addDashesTime(this)"); + + base.OnInit(e); + } + protected void Page_Load(object sender, EventArgs e) { + pnlMyTripsLink.Visible = false; - lblToday.Text = DateTime.Today.ToShortDateString(); - lblTime.Text = DateTime.Now.ToShortTimeString(); - - if (!IsPostBack) + if (Page.Request.QueryString.Count > 0) { PopulateDDLDestionation(); PopulateDDLPickupLocation(); + LoadAsPopUp(); } + else + { + lblToday.Text = DateTime.Today.ToShortDateString(); //Replacement unclear definition of the variables change location + lblTime.Text = DateTime.Now.ToShortTimeString(); + + if (!IsPostBack) + { + PopulateDDLDestionation(); + PopulateDDLPickupLocation(); + SetDefultTripInfo(User.Identity.Name); + } + } + } + + private void SetDefultTripInfo(string userID) //Check again the necessity of setting up default variables values + { + User currentUser = _userBL.GetUsersDetails(int.Parse(userID)); + ddlDestinations.SelectedValue = currentUser.DefaultDestination.ToString(); + txbTripTime.Text = currentUser.DefaultTimeSpanFrom.Trim(); + txbNumOfSeats.Text = currentUser.DefaultPlacesAvailble.ToString(); + lblMessage.Text = "Default values were loaded"; } @@ -52,21 +83,48 @@ } + private void LoadAsPopUp() //why private? + { + + _trip = _tripBL.GetTripDetails(int.Parse(Page.Request.QueryString.GetValues(0)[0])); + ddlDestinations.SelectedValue = _trip.TripCodeDestinishion.ToString(); //One could define more clearly the names of variables + ddlPickupLocation.SelectedValue = _trip.TripPickupLocation.ToString(); + txbComment.Text = _trip.TripComments; + txbTripTime.Text = _trip.TripTimeSpanFrom; + txbNumOfSeats.Text = _trip.TripPlacesAvailable.ToString(); + + ddlDestinations.Enabled = false; + ddlPickupLocation.Enabled = false; + txbTripTime.Enabled = false; + txbComment.Enabled = false; + txbNumOfSeats.Enabled = false; + + lblToday.Visible=false ; + lblTime.Visible=false ; + lblHeadDate.Visible = false; + lblHour.Visible = false; + btnCancel.Visible = false; + btnSave.Visible = false; + pnlMyTripsLink.Visible = false; + + + } + protected void btnSave_Click(object sender, EventArgs e) { if (StoreTripFields() && _tripBL.InsertTrip(_trip)) - { - btnCancel.Text = "Close"; - btnSave.Visible = false; - btnCancel.OnClientClick = "window.open('TripsTable.aspx');window.close()"; - lblMessage.Text = "Your data was saved succesfully."; + { + btnCancel.Visible = false; + btnSave.Visible = false; + pnlMyTripsLink.Visible = true; + lblMessage.Text = "Your data was saved succesfully."; } else { btnCancel.OnClientClick = "Cancel"; btnCancel.OnClientClick = "CloseWindow()"; - lblMessage.Text = "Your data wasn't updated."; + lblMessage.Text = "Your data wasn't updated. Please check the data and try again."; } @@ -75,9 +133,11 @@ private bool StoreTripFields() { - Int32 result ; + Int32 result ; + Boolean success = int.TryParse(User.Identity.Name, out result); //You can assign a Boolean variable name with more meaning clear, or choose a different name so as not to replace the existing variable deleted + _trip.TripUserId = result; _trip.TripAction = 1; - Boolean success = int.TryParse(ddlDestinations.SelectedValue,out result); + success = int.TryParse(ddlDestinations.SelectedValue,out result); _trip.TripCodeDestinishion = result ; _trip.TripComments = txbComment.Text; _trip.TripDate = DateTime.Today;