// Code to execute when the application is launching (eg, from Start) // This code will not execute when the application is reactivated private void Application_Launching(object sender, LaunchingEventArgs e) { //string startPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);// System.IO.Directory.GetCurrentDirectory(); //var filepath = startPath + "\\" + "Database.sdf"; // Specify the local database connection string. string DBConnectionString = "Data Source=isostore:/Places.sdf"; // Create the data context. //string DBConnectionString = "Data Source = 'appdata:/mydb.sdf'; File Mode = read only;"; //https://msdn.microsoft.com/en-us/library/windows/apps/hh286411(v=vs.105).aspx // Create the database if it does not exist. using (PlaceDataContext db = new PlaceDataContext(DBConnectionString)) { if (db.DatabaseExists() == false) { // Create the local database. db.CreateDatabase(); // Prepopulate the places. db.Places.InsertOnSubmit(new PlaceDetails { PlaceName = "Miejsce nr 1" }); // Jakiś tam opis tego miejsca | Miejscowość, ulica | /PictureOfPlaces/p1.jpg // Save categories to the database. db.SubmitChanges(); // Set the new database version. DatabaseSchemaUpdater dbUpdater = db.CreateDatabaseSchemaUpdater(); dbUpdater.DatabaseSchemaVersion = APP_VERSION; dbUpdater.Execute(); } else { // Check whether a database update is needed. DatabaseSchemaUpdater dbUpdater = db.CreateDatabaseSchemaUpdater(); /*if (dbUpdater.DatabaseSchemaVersion < APP_VERSION) * { * // Add the Priority column (added in version 2). * dbUpdater.AddColumn<ToDoItem>("Priority"); * * // Add the new database version. * dbUpdater.DatabaseSchemaVersion = 2; * * // Perform the database update in a single transaction. * dbUpdater.Execute(); * }*/ } } // Create the ViewModel object. viewModel = new PlaceViewModel(DBConnectionString); // Query the local database and load observable collections. viewModel.LoadCollectionsFromDatabase(); }
public void DeletePlace(String id) //delete place by id { using (PlaceDataContext context = new PlaceDataContext(PlaceDataContext.DBConnectionString)) { IQueryable <PlaceDetails> entityQuery = from c in context.Places where c.PlaceId.Equals(id) select c; PlaceDetails entityToDelete = entityQuery.FirstOrDefault(); context.Places.DeleteOnSubmit(entityToDelete); context.SubmitChanges(); } }
public void DeleteAllPlaces() { using (PlaceDataContext context = new PlaceDataContext(PlaceDataContext.DBConnectionString)) { IQueryable <PlaceDetails> entityQuery = from c in context.Places select c; IList <PlaceDetails> entityToDelete = entityQuery.ToList(); context.Places.DeleteAllOnSubmit(entityToDelete); context.SubmitChanges(); } }
////////////////////////// /////PUBLIC FUNCTIONS///// ////////////////////////// #region /// <summary> /// Constructor /// </summary> /// <param name="sqlDatas">The database handler</param> /// <param name="commitDB">The interface permitting to modify the database</param> /// <param name="linkName">The interface permitting to add link into a text based on already known name (character names, place names, etc.)</param> /// <param name="selectedTree"></param> public WindowData(DBHandler sqlDatas, ICommitDatabase commitDB, ILinkName linkName, ISelectedTree selectedTree) { m_dbHandler = sqlDatas; m_commitDB = commitDB; m_linkName = linkName; m_selectedTree = selectedTree; m_newResources = new Dictionary <String, DBResource>(); m_loadedResources = new Dictionary <String, DBResource>(); m_CharacterDatas = new CharacterDataContext(this); m_placeDatas = new PlaceDataContext(this); }
public void UpdatePlace(int id, String name, String description, String city, String street, String house_number) { using (PlaceDataContext context = new PlaceDataContext(PlaceDataContext.DBConnectionString)) { IQueryable <PlaceDetails> entityQuery = from c in context.Places where c.PlaceId == id select c; PlaceDetails entityToUpdate = entityQuery.FirstOrDefault(); entityToUpdate.PlaceName = name; entityToUpdate.place_description = description; entityToUpdate.place_city = city; entityToUpdate.place_street = street; entityToUpdate.place_house_number = house_number; context.SubmitChanges(); } }
public void AddPlace(String name, String description, String city, String street, String house_number) { using (PlaceDataContext context = new PlaceDataContext(PlaceDataContext.DBConnectionString)) { PlaceDetails pd = new PlaceDetails(); pd.PlaceName = name; pd.place_description = description; pd.place_city = city; pd.place_street = street; pd.place_house_number = house_number; context.Places.InsertOnSubmit(pd); context.SubmitChanges(); } }
// Class constructor, create the data context object. public PlaceViewModel(string placeDBConnectionString) { placeDB = new PlaceDataContext(placeDBConnectionString); }