Beispiel #1
0
        /// <summary>
        /// Updates an existing series
        /// </summary>
        /// <param name="DBC">The controller through which series update will be done</param>
        public bool UpdateSeries(databaseController DBC)
        {
            string sqlstr;

            try
            {
                sqlstr = "UPDATE Series SET ";
                sqlstr = sqlstr + "PID = " + this.pid + " ,";
                sqlstr = sqlstr + "FolderPath = '" + this.path + "' ";
                sqlstr = sqlstr + "WHERE SID =" + this.id + " ;";

                if (DBC.IsConnected)
                {
                    DBC.CommandText = sqlstr;
                    if (DBC.ExecuteNonQuery() > 0)
                    {
                        DBC.CommandText = "DELETE FROM Series_Notes WHERE SID = " + this.id + " ;";
                        DBC.ExecuteNonQuery();
                        if (InsertNotes(DBC))
                        {
                            DBC.CommandText = "DELETE FROM Series_Cats WHERE SID = " + this.id + " ;";
                            DBC.ExecuteNonQuery();
                            if (InsertCats(DBC))
                            {
                                return(true);
                            }
                            else
                            {
                                throw new Exception("Failed to modify categories of series !");
                            }
                        }
                        else
                        {
                            throw new Exception("Failed to modify notes of series !");
                        }
                    }
                    else
                    {
                        throw new Exception("Failed to modify series !");
                    }
                }
                else
                {
                    throw new Exception("The database is not connected!");
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Updates image's features in the database
        /// </summary>
        /// <param name="DBC">The controller through which features update will be done</param>
        private bool UpdateImageFeatures(databaseController DBC)
        {
            //Declarations
            string sqlstr;

            try
            {
                sqlstr = "UPDATE FeaturesVector SET ";
                foreach (Feature f in featureVector)
                {
                    sqlstr = sqlstr + f.FeatureName + " = " + f.FeatureValue.ToString() + " ,";
                }
                //sqlstr = sqlstr + "Tags ='" + this.tags + "' ,";
                //sqlstr = sqlstr + "ImagePath ='" + this.url + "',";
                //sqlstr = sqlstr + "Category = " + this.cat.ID + " ,";
                //sqlstr = sqlstr + "Size = " + this.imageInfo[0] + " ,";
                //sqlstr = sqlstr + "Dimensions = '" + this.imageInfo[1] + "' ,";
                sqlstr = sqlstr.Trim(',');
                sqlstr = sqlstr + " WHERE ImageID =" + this.id + " ;";

                if (DBC.IsConnected)
                {
                    DBC.CommandText = sqlstr;
                    return(DBC.ExecuteNonQuery() > 0);
                }
                else
                {
                    throw new Exception("The database is not connected!");
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Beispiel #3
0
 /// <summary>
 /// Inserts image's features into the database
 /// </summary>
 /// <param name="DBC">The controller through which features insertion will be done</param>
 private bool InsertImageFeatures(databaseController DBC)
 {
     try
     {
         string f_insert = "INSERT INTO FeaturesVector VALUES ( " + this.id;
         foreach (Feature f in featureVector)
         {
             f_insert += "," + f.FeatureValue;
         }
         f_insert += " );";
         f_insert  = f_insert.ToLower().Replace("nan", "0");
         if (DBC.IsConnected)
         {
             DBC.CommandText = f_insert;
             return(DBC.ExecuteNonQuery() > 0);
         }
         else
         {
             throw new Exception("The database is not connected!");
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Beispiel #4
0
        /// <summary>
        /// Deletes the categories of the series
        /// </summary>
        /// <param name="DBC">The controller through which categories deletion will be done</param>
        private bool DeleteCats(databaseController DBC)
        {
            string sqlstr;

            if (catList.Count < 1)
            {
                return(true);
            }
            try
            {
                sqlstr = "DELETE FROM Series_Cats WHERE (SID = " + this.id + " ) ;";

                if (DBC.IsConnected)
                {
                    DBC.CommandText = sqlstr;
                    return(DBC.ExecuteNonQuery() > 0);
                }
                else
                {
                    throw new Exception("The database is not connected!");
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Inserts the notes of this series
        /// </summary>
        /// <param name="DBC">The controller through which notes insertion will be done</param>
        private bool InsertNotes(databaseController DBC)
        {
            string sqlstr = "";

            if (this.notes == "")
            {
                return(true);
            }
            try
            {
                sqlstr  = "INSERT INTO Series_Notes VALUES ( " + this.id;
                sqlstr += " , '" + this.notes;
                sqlstr += "' );";

                if (DBC.IsConnected)
                {
                    DBC.CommandText = sqlstr;
                    return(DBC.ExecuteNonQuery() > 0);
                }
                else
                {
                    throw new Exception("The database is not connected!");
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Updates an existing patiant
        /// </summary>
        /// <param name="DBC">The controller through which patiant update will be done</param>
        public bool UpdatePatiant(databaseController DBC)
        {
            //Declarations
            string sqlstr;

            try
            {
                sqlstr = "UPDATE Patiant SET ";
                sqlstr = sqlstr + "Name ='" + this.name + "',";
                sqlstr = sqlstr + "Age = " + this.age + " ,";
                sqlstr = sqlstr + "Info = '" + this.info + "' ";
                sqlstr = sqlstr + "WHERE PID =" + this.id + " ;";

                if (DBC.IsConnected)
                {
                    DBC.CommandText = sqlstr;
                    return(DBC.ExecuteNonQuery() > 0);
                }
                else
                {
                    throw new Exception("The database is not connected!");
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Inserts new series to the system
        /// </summary>
        /// <param name="DBC">The controller through which series insertion will be done</param>
        public bool InsertSeries(databaseController DBC)
        {
            string sqlstr;

            try
            {
                sqlstr = "INSERT INTO Series VALUES ( " +
                         this.id + " , " + this.pid + " , '" + this.Path + "' );";
                if (DBC.IsConnected)
                {
                    DBC.CommandText = sqlstr;
                    if (DBC.ExecuteNonQuery() > 0)
                    {
                        if (InsertCats(DBC))
                        {
                            if (InsertNotes(DBC))
                            {
                                return(true);
                            }
                            else
                            {
                                throw new Exception("Failed to insert the note of series !");
                            }
                        }
                        else
                        {
                            throw new Exception("Failed to insert the categories of series !");
                        }
                    }
                    else
                    {
                        throw new Exception("Failed to insert the series !");
                    }
                }
                else
                {
                    throw new Exception("The database is not connected!");
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Deletes an existing series
        /// </summary>
        /// <param name="DBC">The controller through which series deletion will be done</param>
        public bool DeleteSeries(databaseController DBC)
        {
            string sqlstr;

            try
            {
                if (DeleteCats(DBC))
                {
                    if (DeleteNotes(DBC))
                    {
                        if (DBC.IsConnected)
                        {
                            sqlstr          = "DELETE FROM Series WHERE SID = " + this.id + " ;";
                            DBC.CommandText = sqlstr;
                            if (DBC.ExecuteNonQuery() > 0)
                            {
                                return(true);
                            }
                            else
                            {
                                throw new Exception("Failed to delete the series !");
                            }
                        }
                        else
                        {
                            throw new Exception("The database is not connected!");
                        }
                    }
                    else
                    {
                        throw new Exception("Failed to delete the notes of series !");
                    }
                }
                else
                {
                    throw new Exception("Failed to delete the categories of series !");
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Beispiel #9
0
        /// <summary>
        /// Modifies an image in the database
        /// </summary>
        /// <param name="DBC">The controller through which the modification will be done</param>
        public bool ModifyImage(databaseController DBC)
        {
            //Declarations
            string sqlstr;

            try
            {
                sqlstr = "UPDATE Image SET ";
                sqlstr = sqlstr + "FileName ='" + this.fileName + "',";
                sqlstr = sqlstr + "Size = " + this.imageInfo[0] + " ,";
                sqlstr = sqlstr + "Dimensions = '" + this.imageInfo[1] + "' ";
                sqlstr = sqlstr + "WHERE ImageID =" + this.id + " ;";

                if (DBC.IsConnected)
                {
                    DBC.CommandText = sqlstr;
                    if (DBC.ExecuteNonQuery() > 0)
                    {
                        if (UpdateImageFeatures(DBC))
                        {
                            return(true);
                        }
                        else
                        {
                            throw new Exception("Failed to modify the image !");
                        }
                    }
                    else
                    {
                        throw new Exception("Failed to modify the image !");
                    }
                }
                else
                {
                    throw new Exception("The database is not connected!");
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Beispiel #10
0
        /// <summary>
        /// Inserts an image into the database
        /// </summary>
        /// <param name="DBC">The controller through which the insertion will be done</param>
        public bool InsertImage(databaseController DBC)
        {
            //Declarations
            string sqlstr;

            try
            {
                sqlstr = "INSERT INTO Image VALUES ( " +
                         this.id + " , '" + this.fileName + "' , " + this.imageInfo[0]
                         + " , '" + this.imageInfo[1] + "' );";
                if (DBC.IsConnected)
                {
                    DBC.CommandText = sqlstr;
                    if (DBC.ExecuteNonQuery() > 0)
                    {
                        if (InsertImageFeatures(DBC))
                        {
                            return(true);
                        }
                        else
                        {
                            throw new Exception("Failed to insert the features of image !");
                        }
                    }
                    else
                    {
                        throw new Exception("Failed to insert the image !");
                    }
                }
                else
                {
                    throw new Exception("The database is not connected!");
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Deletes an existing patiant from the database
        /// </summary>
        /// <param name="DBC">The controller through which patiant deletion will be done</param>
        public bool DeletePatiant(databaseController DBC)
        {
            string sqlstr;

            try
            {
                if (DBC.IsConnected)
                {
                    sqlstr          = "DELETE FROM Patiant WHERE PID= " + this.id + " ;";
                    DBC.CommandText = sqlstr;
                    return(DBC.ExecuteNonQuery() > 0);
                }
                else
                {
                    throw new Exception("The database is not connected!");
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Beispiel #12
0
        /// <summary>
        /// Deletes image's features from the database
        /// </summary>
        /// <param name="DBC">The controller through which features deletion will be done</param>
        private bool DeleteImageFeatures(databaseController DBC)
        {
            //Declarations
            string sqlstr;

            try
            {
                sqlstr = "DELETE FROM FeaturesVector WHERE ImageID= " + this.id + " ;";
                if (DBC.IsConnected)
                {
                    DBC.CommandText = sqlstr;
                    return(DBC.ExecuteNonQuery() > 0);
                }
                else
                {
                    throw new Exception("The database is not connected!");
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Beispiel #13
0
        /// <summary>
        /// Deletes an image category from the database
        /// </summary>
        /// <param name="dbc">The controller through which the insertion will be done</param>
        /// <param name="DBC">The controller through which the deletion will be done</param>
        public bool DeleteCategory(databaseController DBC)
        {
            //Declarations
            string sqlstr;

            try
            {
                sqlstr = "DELETE FROM Category WHERE CatID= " + this.id + " ;";
                if (DBC.IsConnected)
                {
                    DBC.CommandText = sqlstr;
                    return(DBC.ExecuteNonQuery() > 0);
                }
                else
                {
                    throw new Exception("The database is not connected!");
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Beispiel #14
0
        /// <summary>
        /// Deletes an image from the database.
        /// </summary>
        /// <param name="DBC">The controller through which the deletion will be done</param>
        public bool DeleteImage(databaseController DBC)
        {
            //Declarations
            string sqlstr;

            try
            {
                if (DeleteImageFeatures(DBC))
                {
                    if (DBC.IsConnected)
                    {
                        sqlstr          = "DELETE FROM Image WHERE ImageID= " + this.id + " ;";
                        DBC.CommandText = sqlstr;
                        if (DBC.ExecuteNonQuery() > 0)
                        {
                            return(true);
                        }
                        else
                        {
                            throw new Exception("Failed to delete the image !");
                        }
                    }
                    else
                    {
                        throw new Exception("The database is not connected!");
                    }
                }
                else
                {
                    throw new Exception("Failed to delete the image !");
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Beispiel #15
0
        /// <summary>
        /// Inserts the categories of this series
        /// </summary>
        /// <param name="DBC">The controller through which categories insertion will be done</param>
        private bool InsertCats(databaseController DBC)
        {
            string sqlstr = "";

            if (catList.Count < 1)
            {
                return(true);
            }
            int inserted_cats = 0;

            try
            {
                if (DBC.IsConnected)
                {
                    foreach (category c in catList)
                    {
                        sqlstr          = "INSERT INTO Series_Cats VALUES ( " + this.id;
                        sqlstr         += " , " + c.ID;
                        sqlstr         += " );";
                        DBC.CommandText = sqlstr;
                        if (DBC.ExecuteNonQuery() > 0)
                        {
                            inserted_cats++;
                        }
                    }
                    return(inserted_cats == catList.Count);
                }
                else
                {
                    throw new Exception("The database is not connected!");
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Beispiel #16
0
        /// <summary>
        /// Inserts new patiant into the database
        /// </summary>
        /// <param name="DBC">The controller through which patiant insertion will be done</param>
        public bool InsertPatiant(databaseController DBC)
        {
            string sqlstr;

            try
            {
                sqlstr = "INSERT INTO Patiant VALUES ( " +
                         this.id + " , '" + this.name + "' , " + this.age + " , '" + this.info + "' );";

                if (DBC.IsConnected)
                {
                    DBC.CommandText = sqlstr;
                    return(DBC.ExecuteNonQuery() > 0);
                }
                else
                {
                    throw new Exception("The database is not connected!");
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }