Beispiel #1
0
        public void RunSQLScript(string SQLScriptName)
        {
            string sqlScript = null;

            if (SQLScriptName.ToLower().Equals("reset"))
            {
                //To Do: This scripts need to be relative, but for now its local..
                sqlScript = File.ReadAllText(@"C:\Users\Chris\Source\Repos\UCN-4-Semester-Project---Group-7\TrashDetector\TrainingDatabase\Scripts\Reset.sql");
            }

            if (sqlScript != null)
            {
                using (var db = new TrainingDBContext())
                {
                    db.ExecuteCommand(sqlScript);
                }
            }
        }
Beispiel #2
0
        public int InsertSingleImageFile(string filePath)
        {
            int       startIndexOfFilename = filePath.LastIndexOf('\\') + 1;
            string    fileName             = filePath.Substring(startIndexOfFilename);
            ImageFile imageFile            = new ImageFile();

            imageFile.FilePath = filePath;
            imageFile.FileName = fileName;

            try
            {
                using (var db = new TrainingDBContext())
                {
                    db.imageFiles.InsertOnSubmit(imageFile);
                    db.SubmitChanges();
                }
            }
            catch (System.Data.SqlClient.SqlException)
            {
                Console.WriteLine("Cannot Insert " + fileName + " Into database. " +
                                  "Most likely is a violation of unique key constraint " +
                                  "because the file allready exisits in the database");
            }

            if (filePath.Contains("non_cigarettes"))
            {
                using (var db = new TrainingDBContext())
                {
                    db.ExecuteCommand("UPDATE ImageFiles SET IsCig = 0 WHERE ID = " + imageFile.ID);
                }
            }
            else
            {
                using (var db = new TrainingDBContext())
                {
                    db.ExecuteCommand("UPDATE ImageFiles SET IsCig = 1 WHERE ID = " + imageFile.ID);
                }
            }

            return(0);
        }