public void createCreateEventClickHandler(View v) { EditText eventTitle = v.FindViewById<EditText> (Resource.Id.editText3); EditText description = v.FindViewById<EditText> (Resource.Id.editText6); EditText category = v.FindViewById<EditText> (Resource.Id.editText5); // Create New Event Event newEvent = new Event(eventTitle.Text, description.Text); newEvent.EvtCategory = (Category) Enum.Parse (typeof(Category), category.Text); // send to database newEvent.SaveEvent (); // preserve event id FragmentTransaction ft = this.FragmentManager.BeginTransaction (); EventInfoFragment eif = new EventInfoFragment (); ft.Replace (Resource.Id.frameLayout1, eif); ft.Commit (); }
public static Event getFromEventID(int eventid) { Event model = new Event(); SqlConnection db = Configuration.getConnection(); SqlCommand query = new SqlCommand (); query.CommandText = "SELECT * FROM Events WHERE EventID = @EVENTID"; query.Parameters.Add ("@EVENTID", SqlDbType.Int); query.Parameters ["@EVENTID"].Value = eventid; try { db.Open(); SqlDataReader data = query.ExecuteReader(); model.id = data.GetInt32(data.GetOrdinal("EventID")); model.name = data.GetString(data.GetOrdinal("EventName")); model.description = data.GetString(data.GetOrdinal("EventDescription")); model.hostid = data.GetInt32(data.GetOrdinal("HostID")); model.EvtCategory = (Category)data.GetInt32(data.GetOrdinal("EventType")); model.Location = new Tuple<float, float>(data.GetFloat(data.GetOrdinal("Latitude")), data.GetFloat(data.GetOrdinal("Longitude"))); model.StartTime = data.GetDateTime(data.GetOrdinal("EventStartTime")); model.EndTime = data.GetDateTime(data.GetOrdinal("EventEndTime")); // Retrieve Attendees List query.CommandText = "SELECT UserID FROM Events_Users WHERE EventID = @EVENTID"; query.Parameters.Add ("@EVENTID", SqlDbType.Int); query.Parameters ["@EVENTID"].Value = model.id; try{ db.Open(); SqlDataReader eventList = query.ExecuteReader(); // Add id to list do{ model.attendees.Add(eventList.GetInt32(eventList.GetOrdinal("UserID"))); } while (eventList.NextResult()); } catch (Exception attendErr) { Console.WriteLine(attendErr.Message); } } catch (Exception err){ Console.WriteLine(err.Message); } return new Event(); }
public static List<Event> GrabLocalEvents(float myLat, float myLong, float radius) { List<Event> events = new List<Event>(); // Convert degrees for lat & long float degreesDeviance = radius * 1.0f/69; // HaHa 69 // Establish Connection SqlConnection db = Configuration.getConnection(); SqlCommand query = new SqlCommand (); query.CommandText = "SELECT * " + "FROM Events" + "WHERE Longitude > @MINLONGIT" + "AND Longitude < @MAXLONGIT" + "AND Latitude > @MINLATIT" + "AND Latitude < @MAXLATIT;"; query.Parameters.Add ("@MINLONGIT", SqlDbType.Decimal); query.Parameters.Add ("@MAXLONGIT", SqlDbType.Decimal); query.Parameters.Add ("@MINLATIT", SqlDbType.Decimal); query.Parameters.Add ("@MAXLATIT", SqlDbType.Decimal); // query.Parameters.Add ("@CURDATE", SqlDbType.DateTime); // query.Parameters.Add ("@CURDATE", SqlDbType.DateTime); query.Parameters ["@MINLONGIT"].Value = myLong - degreesDeviance; query.Parameters ["@MAXLONGIT"].Value = myLong + degreesDeviance; query.Parameters ["@MINLATIT"].Value = myLat - degreesDeviance; query.Parameters ["@MAXLATIT"].Value = myLat + degreesDeviance; try { db.Open(); SqlDataReader data = query.ExecuteReader(); do { Event model = new Event(); model.id = data.GetInt32(data.GetOrdinal("EventID")); model.name = data.GetString(data.GetOrdinal("EventName")); model.description = data.GetString(data.GetOrdinal("EventDescription")); model.hostid = data.GetInt32(data.GetOrdinal("HostID")); model.EvtCategory = (Category)data.GetInt32(data.GetOrdinal("EventType")); model.Location = new Tuple<float, float>(data.GetFloat(data.GetOrdinal("Latitude")), data.GetFloat(data.GetOrdinal("Longitude"))); model.StartTime = data.GetDateTime(data.GetOrdinal("EventStartTime")); model.EndTime = data.GetDateTime(data.GetOrdinal("EventEndTime")); // Retrieve Attendees List query.CommandText = "SELECT UserID FROM Events_Users WHERE EventID = @EVENTID"; query.Parameters.Add ("@EVENTID", SqlDbType.Int); query.Parameters ["@EVENTID"].Value = model.id; try{ db.Open(); SqlDataReader eventList = query.ExecuteReader(); do{ model.attendees.Add(eventList.GetInt32(eventList.GetOrdinal("UserID"))); } while (eventList.NextResult()); } catch (Exception attendErr) { Console.WriteLine(attendErr.Message); } events.Add(model); } while (data.NextResult()); } catch (Exception err){ Console.WriteLine (err.Message); } return events; }