protected void SelectedBookingObjectDataSource_Updating(object sender, ObjectDataSourceMethodEventArgs e) { if (User.IsInRole("Admin")) SelectedBookingObjectDataSource.UpdateMethod = "UpdateBooking"; DateTime date = new DateTime((long)0); DateTime startTime = new DateTime((long)0); DateTime endTime = new DateTime((long)0); TextBox starttimeTextBox = new TextBox(); TextBox endtimeTextBox = new TextBox(); KMobile.Web.UI.WebControls.DateTimePicker dateTimePicker = new KMobile.Web.UI.WebControls.DateTimePicker(); try { dateTimePicker = (KMobile.Web.UI.WebControls.DateTimePicker)SelectedBookingFormView.Row.FindControl("DateTimePicker1"); date = DateTime.Parse(dateTimePicker.Text); } catch (Exception exception) { UpdateBookingExceptionLabel.Visible = true; UpdateBookingExceptionLabel.Text = "Det uppstod ett problem när bokningen skulle uppdateras: \n"; UpdateBookingExceptionLabel.Text += String.Format("{0} är inte ett giltigt datum.", dateTimePicker.Text); e.Cancel = true; } try { starttimeTextBox = (TextBox)SelectedBookingFormView.Row.FindControl("starttimeTextBox"); startTime = DateTime.Parse(starttimeTextBox.Text); } catch (Exception exception) { UpdateBookingExceptionLabel.Visible = true; UpdateBookingExceptionLabel.Text = "Det uppstod ett problem när bokningen skulle uppdateras: \n"; UpdateBookingExceptionLabel.Text += String.Format("{0} är inte ett giltigt klockslag", starttimeTextBox.Text); e.Cancel = true; } DateTime startDateTime = new DateTime(date.Year, date.Month, date.Day, startTime.Hour, startTime.Minute, 0); DateTime endDateTime = new DateTime((long)0); if (User.IsInRole("Admin")) { try { endtimeTextBox = (TextBox)SelectedBookingFormView.Row.FindControl("endtimeTextBox"); endTime = DateTime.Parse(endtimeTextBox.Text); endDateTime = new DateTime(date.Year, date.Month, date.Day, endTime.Hour, endTime.Minute, 0); } catch (Exception exception) { UpdateBookingExceptionLabel.Visible = true; UpdateBookingExceptionLabel.Text = "Det uppstod ett problem när bokningen skulle läggas till: \n"; UpdateBookingExceptionLabel.Text += String.Format("{0} är inte ett giltigt klockslag", endtimeTextBox.Text); e.Cancel = true; } } else endDateTime = startDateTime.AddMinutes(30.0); e.InputParameters["startdatetime"] = startDateTime.ToString(); e.InputParameters["enddatetime"] = endDateTime.ToString(); /*DropDownList drpBookingtype = (DropDownList)SelectedBookingFormView.FindControl("drpBookingtype"); if (drpBookingtype != null) e.InputParameters["bookingtypeid"] = drpBookingtype.SelectedValue;*/ }
protected void SelectedPatientObjectDataSource_Updating(object sender, ObjectDataSourceMethodEventArgs e) { DateTime date = new DateTime((long)0); KMobile.Web.UI.WebControls.DateTimePicker dateTimePicker = new KMobile.Web.UI.WebControls.DateTimePicker(); if (!String.IsNullOrEmpty(dateTimePicker.Text)) { try { dateTimePicker = (KMobile.Web.UI.WebControls.DateTimePicker)SelectedPatientFormView.FindControl("DateTimePicker1"); date = DateTime.Parse(dateTimePicker.Text); } catch (Exception exception) { UpdatePatientExceptionLabel.Visible = true; UpdatePatientExceptionLabel.Text = "Det uppstod ett problem när patienten skulle uppdateras: \n"; UpdatePatientExceptionLabel.Text += String.Format("{0} är inte ett giltigt datum.", dateTimePicker.Text); e.Cancel = true; } } }
protected void NewBookingObjectDataSource_Inserting(object sender, ObjectDataSourceMethodEventArgs e) { //TODO: Use try and catch over the hole function if (User.IsInRole("Admin")) NewBookingObjectDataSource.InsertMethod = "AddBooking"; DateTime date = new DateTime((long)0); DateTime startTime = new DateTime((long)0); DateTime endTime = new DateTime((long)0); TextBox starttimeTextBox = new TextBox() ; TextBox endtimeTextBox = new TextBox(); booking = new Booking(); KMobile.Web.UI.WebControls.DateTimePicker dateTimePicker = new KMobile.Web.UI.WebControls.DateTimePicker(); try { dateTimePicker = (KMobile.Web.UI.WebControls.DateTimePicker)NewBookingFormView.Row.FindControl("DateTimePicker1"); date = DateTime.Parse(dateTimePicker.Text); } catch (Exception exception) { InsertBookingExceptionLabel.Visible = true; InsertBookingExceptionLabel.Text = "Det uppstod ett problem när bokningen skulle läggas till: \n"; InsertBookingExceptionLabel.Text += "Datumet som angivits är inte giltigt."; e.Cancel = true; } try { starttimeTextBox = (TextBox)NewBookingFormView.Row.FindControl("starttimeTextBox"); startTime = DateTime.Parse(starttimeTextBox.Text); } catch (Exception exception) { InsertBookingExceptionLabel.Visible = true; InsertBookingExceptionLabel.Text = "Det uppstod ett problem när bokningen skulle läggas till: \n"; InsertBookingExceptionLabel.Text += String.Format("{0} är inte ett giltigt klockslag", starttimeTextBox.Text); e.Cancel = true; } DateTime startDateTime = new DateTime(date.Year, date.Month, date.Day, startTime.Hour, startTime.Minute, 0); DateTime endDateTime = new DateTime((long)0); if (User.IsInRole("Admin")) { try { endtimeTextBox = (TextBox)NewBookingFormView.Row.FindControl("endtimeTextBox"); endTime = DateTime.Parse(endtimeTextBox.Text); endDateTime = new DateTime(date.Year, date.Month, date.Day, endTime.Hour, endTime.Minute, 0); } catch (Exception exception) { InsertBookingExceptionLabel.Visible = true; InsertBookingExceptionLabel.Text = "Det uppstod ett problem när bokningen skulle läggas till: \n"; InsertBookingExceptionLabel.Text += String.Format("{0} är inte ett giltigt klockslag", endtimeTextBox.Text); e.Cancel = true; } } else endDateTime = startDateTime.AddMinutes(30.0); e.InputParameters["startdatetime"] = startDateTime.ToString(); e.InputParameters["enddatetime"] = endDateTime.ToString(); booking.Startdatetime = startDateTime; booking.Enddatetime = endDateTime; try { e.InputParameters["patientid"] = SelectedPatientId; TextBox titleTextBox = (TextBox)NewBookingFormView.Row.FindControl("titleTextBox"); e.InputParameters["title"] = titleTextBox.Text; } catch (Exception exception) { //TODO: Show an error text e.Cancel = true; } /*DropDownList drpBookingtype = (DropDownList)NewBookingFormView.FindControl("drpBookingtype"); if (drpBookingtype != null) e.InputParameters["bookingtypeid"] = drpBookingtype.SelectedValue;*/ }