public static void CreateNewProject(Project newProject) { try { string projectsPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); using (SQLiteConnection Conn = new SQLiteConnection()) { Conn.ConnectionString = "Data Source=" + projectsPath + @"\\Projects\\" + newProject.Name + ".db;Version=3;New=True;Compress=True;Synchronous=Off"; Conn.Open(); SQLiteCommand CreateCmd = new SQLiteCommand(); CreateCmd = Conn.CreateCommand(); CreateCmd.CommandText = "CREATE TABLE [project] ([id_project] INTEGER NOT NULL PRIMARY KEY,[project_base64] TEXT NULL)"; CreateCmd.ExecuteNonQuery(); CreateCmd.CommandText = "CREATE TABLE [images] ( [guid_images] TEXT NOT NULL PRIMARY KEY, [image_base64] TEXT NOT NULL)"; CreateCmd.ExecuteNonQuery(); CreateCmd.Dispose(); SQLiteParameter idproject = new SQLiteParameter("@idproject", DbType.Int64) { Value = 1 }; SQLiteParameter newproject = new SQLiteParameter("@project", DbType.String) { Value = ConversionUtilities.SerializeBase64(newProject) }; SQLiteCommand InsertCmd = new SQLiteCommand(); InsertCmd = Conn.CreateCommand(); InsertCmd.Parameters.Add(idproject); InsertCmd.Parameters.Add(newproject); InsertCmd.CommandText = "INSERT INTO project (id_project, project_base64) VALUES(@idproject, @project)"; InsertCmd.ExecuteNonQuery(); InsertCmd.Dispose(); } } catch (Exception ex) { throw ex; } }
public static void UpdateProject(string oldProjectName, Project updatedProject) { try { string projectsPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); using (SQLiteConnection Conn = new SQLiteConnection()) { Conn.ConnectionString = "Data Source=" + projectsPath + @"\\Projects\\" + oldProjectName + ".db;New=False;Compress=True;Synchronous=Off"; Conn.Open(); SQLiteCommand DeleteCmd = new SQLiteCommand(); DeleteCmd = Conn.CreateCommand(); DeleteCmd.CommandText = "DELETE FROM project WHERE id_project=1"; DeleteCmd.ExecuteNonQuery(); DeleteCmd.Dispose(); SQLiteParameter idproject = new SQLiteParameter("@idproject", DbType.Int64) { Value = 1 }; SQLiteParameter newproject = new SQLiteParameter("@project", DbType.String) { Value = ConversionUtilities.SerializeBase64(updatedProject) }; SQLiteCommand InsertCmd = new SQLiteCommand(); InsertCmd = Conn.CreateCommand(); InsertCmd.Parameters.Add(idproject); InsertCmd.Parameters.Add(newproject); InsertCmd.CommandText = "INSERT INTO project (id_project, project_base64) VALUES(@idproject, @project)"; InsertCmd.ExecuteNonQuery(); InsertCmd.Dispose(); } } catch (Exception ex) { throw ex; } }