public bool exists(string fileID) { DatabaseEntities _database = null; try { _database = new DatabaseEntities(); _database.Database.Connection.Open(); var file = _database.CloudManagers; foreach (CloudManager item in file) { if (item.File_ID.Equals(fileID)) //path ( da jetzt primary key? ) { return true; } } } catch(Exception) { return false; } finally { _database.Database.Connection.Close(); } return false; }
public static void RefreshDatabasePathSettings() { string filePath = "attachdbfilename=" + Directory.GetCurrentDirectory().ToString() + @"Bin\Debug\Database\Database.mdf"; //SqlConnection cn = new SqlConnection(global::DBTestCM.Properties.Settings.Default.DatabaseConnectionString); try { DatabaseEntities _database = new DatabaseEntities(); string s = ConfigurationManager.ConnectionStrings["DatabaseEntities"].ConnectionString; if (!s.Contains(filePath)) { int index = -1; if (s.Contains("attachdbfilename")) { index = s.IndexOf("attachdbfilename"); } else if (!s.Contains("attachdbfilename")) { string path = Environment.CurrentDirectory; string[] splits = path.Split('\\'); string totalResult = ""; for (int i = 0; i < splits.Length - 2; i++) { totalResult += splits[i] + "\\"; } totalResult += "Database.mdf"; index = s.ToLower().IndexOf(totalResult.ToLower()); } string _result = s.Replace(s.Substring(index, s.IndexOf(";", index) - index), filePath); var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.ConnectionStrings.ConnectionStrings["DatabaseEntities"].ConnectionString = _result; config.Save(ConfigurationSaveMode.Modified, true); ConfigurationManager.RefreshSection("connectionStrings"); Console.WriteLine(_result); } } catch (Exception) { } }
public void execEntry(string fileID, string cloudID, string fileName, string filePath, DateTime lastUpdated, bool isDeleted, bool isFolder, bool isInRoot, string cloudPath) { DatabaseEntities _database = null; try { _database = new DatabaseEntities(); _database.Database.Connection.Open(); CloudManager entry = new CloudManager(); var data = _database.CloudManagers; foreach(CloudManager cm in data) { if(cm.File_Path.Equals(filePath)) { _database.CloudManagers.Remove(cm); } } entry.File_ID = fileID; entry.Cloud_ID = cloudID; entry.File_Name = fileName; entry.File_Path = filePath; entry.File_LastChanged = lastUpdated; entry.File_IsDeleted = isDeleted; entry.IsFolder = isFolder; entry.File_IsInRoot = isInRoot; entry.Cloud_Path = cloudPath; _database.CloudManagers.Add(entry); _database.SaveChanges(); } catch (Exception) { _database.Database.Connection.Close(); } finally { _database.Database.Connection.Close(); } }
public void execEntry(string fileName, string filePath, bool isFolder,string cloudname) { DatabaseEntities _database = null; try { _database = new DatabaseEntities(); _database.Database.Connection.Open(); CloudManager entry = new CloudManager(); var data = _database.CloudManagers; foreach (CloudManager cm in data) { if (cm.File_Path.Equals(filePath)) { _database.CloudManagers.Remove(cm); } } entry.File_ID = String.Empty; entry.Cloud_ID = cloudname; entry.File_Name = fileName; entry.File_Path = filePath; entry.File_LastChanged = null; entry.IsFolder = isFolder; entry.Cloud_Path = String.Empty; _database.CloudManagers.Add(entry); _database.SaveChanges(); } catch (Exception) { _database.Database.Connection.Close(); } finally { _database.Database.Connection.Close(); } }